예제 #1
0
 def on_remote_game_activate(self, widget):
     url = getUserTextDialog(mainwindow(), _('Load a remote game'),
                             _('Paste the link to download:'))
     create_task(get_internet_game(url))
예제 #2
0
    def on_drag_received(self, widget, context, x, y, selection, target_type,
                         timestamp):
        if target_type == TARGET_TYPE_URI_LIST:
            NOTPROC, PARTIAL, FULL = range(3)
            status = NOTPROC
            uris = selection.get_uris()
            for uri in uris:
                fn, fext = os.path.splitext(uri.lower())
                b = False

                # Chess position
                if fext == '.fen':
                    b = newGameDialog.loadFileAndRun(uri)

                # Shortcut
                elif fext in ['.url', '.desktop']:
                    # Preconf
                    if fext == '.url':
                        sectname = 'InternetShortcut'
                        typeok = True
                    elif fext == '.desktop':
                        sectname = 'Desktop Entry'
                        typeok = False
                    else:
                        assert (False)

                    # Read the shortcut
                    filename = splitUri(uri)[1]
                    with open(filename, 'r') as file:
                        content = file.read()
                    lines = content.replace("\r", '').split("\n")

                    # Extract the link
                    section = False
                    link = ''
                    for item in lines:
                        # Header
                        if item.startswith('['):
                            if section:
                                break
                            section = item.startswith('[%s]' % sectname)
                        if not section:
                            continue

                        # Item
                        if item.startswith('URL='):
                            link = item[4:]
                        if item.startswith('Type=Link') and fext == '.desktop':
                            typeok = True

                    # Load the link
                    if typeok and link != '':
                        create_task(get_internet_game(link))
                        b = True

                # Database
                else:
                    perspective = perspective_manager.get_perspective(
                        "database")
                    perspective.open_chessfile(uri)
                    b = True

                # Update the global status
                if b:
                    if status == NOTPROC:
                        status = FULL
                else:
                    if status != NOTPROC:
                        status = PARTIAL

            # Feedback about the load
            msg = ''
            if status == NOTPROC:
                msg = _(
                    'All the links failed to fetch a relevant chess content.')
                msgtype = Gtk.MessageType.ERROR
            elif status == PARTIAL:
                msg = _('Some links were invalid.')
                msgtype = Gtk.MessageType.WARNING
            if msg != '':
                dlg = Gtk.MessageDialog(mainwindow(),
                                        type=msgtype,
                                        buttons=Gtk.ButtonsType.OK,
                                        message_format=msg)
                dlg.run()
                dlg.destroy()