Esempio n. 1
0
    def __init__(self, *args, **kwargs):
        Gtk.Dialog.__init__(self,
                            title=_('Preferences'),
                            buttons=(Gtk.STOCK_CLOSE, Gtk.ResponseType.CLOSE),
                            *args,
                            **kwargs)
        LoggingMixin.__init__(self)

        self.preferences = {}

        ### Content Area
        content_area = self.get_content_area()

        notebook = Gtk.Notebook()
        content_area.add(notebook)

        ## General Page
        label = Gtk.Label(_('General'))
        vbox = Box(VERTICAL, border_width=5)
        notebook.append_page(vbox, label)

        ## Download Page
        label = Gtk.Label(_('Download'))
        vbox = Box(VERTICAL, border_width=5)
        notebook.append_page(vbox, label)

        grid = Grid()
        vbox.pack_start(grid, expand=False)

        label = RightAlignedLabel(_('Max Concurrent Tasks:'))
        grid.attach(label, 0, 0)

        adjustment = Gtk.Adjustment(lower=1, upper=64, step_increment=1)
        spin_button = Gtk.SpinButton(adjustment=adjustment, numeric=True)
        grid.attach(spin_button, 1, 0)
        self._preferences['max-concurrent-downloads'] = _Option(
            spin_button, 'value', _Option.int_mapper)

        label = RightAlignedLabel(_('Global Upload Limit(KiB/s):'))
        grid.attach(label, 0, 1)

        adjustment = Gtk.Adjustment(lower=0, upper=4096, step_increment=1)
        spin_button = Gtk.SpinButton(adjustment=adjustment, numeric=True)
        grid.attach(spin_button, 1, 1)
        self._preferences['max-overall-upload-limit'] = _Option(
            spin_button, 'value', _Option.kib_mapper)

        label = RightAlignedLabel(_('Global Download Limit(KiB/s):'))
        grid.attach(label, 0, 2)

        adjustment = Gtk.Adjustment(lower=0, upper=4096, step_increment=1)
        spin_button = Gtk.SpinButton(adjustment=adjustment, numeric=True)
        grid.attach(spin_button, 1, 2)
        self._preferences['max-overall-download-limit'] = _Option(
            spin_button, 'value', _Option.kib_mapper)

        self.show_all()
Esempio n. 2
0
    def __init__(self, *args, **kwargs):
        Gtk.Dialog.__init__(self,
                            title=_('Preferences'),
                            buttons=(Gtk.STOCK_CLOSE, Gtk.ResponseType.CLOSE),
                            *args, **kwargs)
        LoggingMixin.__init__(self)

        self.preferences = {}

        ### Content Area
        content_area = self.get_content_area()

        notebook = Gtk.Notebook()
        content_area.add(notebook)

        ## General Page
        label = Gtk.Label(_('General'))
        vbox = Box(VERTICAL, border_width=5)
        notebook.append_page(vbox, label)

        ## Download Page
        label = Gtk.Label(_('Download'))
        vbox = Box(VERTICAL, border_width=5)
        notebook.append_page(vbox, label)

        grid = Grid()
        vbox.pack_start(grid, expand=False)

        label = RightAlignedLabel(_('Max Concurrent Tasks:'))
        grid.attach(label, 0, 0)

        adjustment = Gtk.Adjustment(lower=1, upper=64, step_increment=1)
        spin_button = Gtk.SpinButton(adjustment=adjustment, numeric=True)
        grid.attach(spin_button, 1, 0)
        self._preferences['max-concurrent-downloads'] = _Option(
            spin_button, 'value', _Option.int_mapper)

        label = RightAlignedLabel(_('Global Upload Limit(KiB/s):'))
        grid.attach(label, 0, 1)

        adjustment = Gtk.Adjustment(lower=0, upper=4096, step_increment=1)
        spin_button = Gtk.SpinButton(adjustment=adjustment, numeric=True)
        grid.attach(spin_button, 1, 1)
        self._preferences['max-overall-upload-limit'] = _Option(
            spin_button, 'value', _Option.kib_mapper)

        label = RightAlignedLabel(_('Global Download Limit(KiB/s):'))
        grid.attach(label, 0, 2)

        adjustment = Gtk.Adjustment(lower=0, upper=4096, step_increment=1)
        spin_button = Gtk.SpinButton(adjustment=adjustment, numeric=True)
        grid.attach(spin_button, 1, 2)
        self._preferences['max-overall-download-limit'] = _Option(
            spin_button, 'value', _Option.kib_mapper)

        self.show_all()
Esempio n. 3
0
    def __init__(self, task_options):
        _TaskNewUI.__init__(self,
                            task_options,
                            expander_label=_('<b>URI(s)</b>'))

        box = self._content_box

        tooltip = _('Specify HTTP(S)/FTP URI:\n'
                    '\thttp://www.example.com/bar.iso\n\n'
                    'Add some mirrors for that file:\n'
                    '\thttps://www.mirror1.com/foo/bar.iso\n'
                    '\tftp://www.mirror2.com/foo/bar.iso\n\n'
                    'Or use Magnet URI(<b>Does not support mirrors</b>):\n'
                    '\tmagnet:?xt=urn:sha1:YNCKHTQCWBTRNJIV4WNAE52SJUQCZO5C\n')
        uris_view = URIsView(tooltip_markup=tooltip)
        uris_view.set_size_request(350, 70)
        box.pack_start(uris_view)
        self._task_options['uris'] = _Option(uris_view, 'uris',
                                             _Option.default_mapper)

        hbox = Box(HORIZONTAL)
        box.pack_start(hbox)

        # Rename
        tooltip = _('Rename the downloaded file to this name.')

        label = RightAlignedLabel(_('Rename:'), tooltip_text=tooltip)
        hbox.pack_start(label, expand=False)

        entry = Gtk.Entry(tooltip_text=tooltip, activates_default=True)
        hbox.pack_start(entry)
        self._task_options['out'] = _Option(entry, 'text',
                                            _Option.string_mapper)

        # Connections
        tooltip = _('The max connections to download the file.')

        label = RightAlignedLabel(_('Connections:'), tooltip_text=tooltip)
        hbox.pack_start(label, expand=False)

        adjustment = Gtk.Adjustment(lower=1, upper=1024, step_increment=1)
        spin_button = Gtk.SpinButton(adjustment=adjustment,
                                     numeric=True,
                                     tooltip_text=tooltip)
        hbox.pack_start(spin_button)
        self._task_options['split'] = _Option(spin_button, 'value',
                                              _Option.int_mapper)

        self._uris_view = uris_view
Esempio n. 4
0
    def __init__(self, task_options):
        _TaskNewUI.__init__(self, task_options,
                            expander_label=_('<b>URI(s)</b>')
                           )

        box = self._content_box

        tooltip = _('Specify HTTP(S)/FTP URI:\n'
                    '\thttp://www.example.com/bar.iso\n\n'
                    'Add some mirrors for that file:\n'
                    '\thttps://www.mirror1.com/foo/bar.iso\n'
                    '\tftp://www.mirror2.com/foo/bar.iso\n\n'
                    'Or use Magnet URI(<b>Does not support mirrors</b>):\n'
                    '\tmagnet:?xt=urn:sha1:YNCKHTQCWBTRNJIV4WNAE52SJUQCZO5C\n'
                   )
        uris_view = URIsView(tooltip_markup=tooltip)
        uris_view.set_size_request(350, 70)
        box.pack_start(uris_view)
        self._task_options['uris'] = _Option(uris_view, 'uris',
                                             _Option.default_mapper)

        hbox = Box(HORIZONTAL)
        box.pack_start(hbox)

        # Rename
        tooltip = _('Rename the downloaded file to this name.')

        label = RightAlignedLabel(_('Rename:'), tooltip_text=tooltip)
        hbox.pack_start(label, expand=False)

        entry = Gtk.Entry(tooltip_text=tooltip, activates_default=True)
        hbox.pack_start(entry)
        self._task_options['out'] = _Option(entry, 'text', _Option.string_mapper)

        # Connections
        tooltip = _('The max connections to download the file.')

        label = RightAlignedLabel(_('Connections:'), tooltip_text=tooltip)
        hbox.pack_start(label, expand=False)

        adjustment = Gtk.Adjustment(lower=1, upper=1024, step_increment=1)
        spin_button = Gtk.SpinButton(adjustment=adjustment, numeric=True,
                                     tooltip_text=tooltip)
        hbox.pack_start(spin_button)
        self._task_options['split'] = _Option(spin_button, 'value',
                                              _Option.int_mapper)

        self._uris_view = uris_view
Esempio n. 5
0
    def __init__(self, pool_model, *args, **kwargs):
        Gtk.Dialog.__init__(self, title=_('Create New Task'), *args, **kwargs)
        LoggingMixin.__init__(self)

        self._ui = None
        self._default_ui = None
        self._normal_ui = None
        self._bt_ui = None
        self._ml_ui = None

        self._task_options = {}

        ### Action Area
        action_area = self.get_action_area()
        action_area.set_layout(Gtk.ButtonBoxStyle.START)

        button = Gtk.Button.new_from_stock(Gtk.STOCK_CANCEL)
        self.add_action_widget(button, Gtk.ResponseType.CANCEL)
        action_area.set_child_secondary(button, True)

        image = Gtk.Image.new_from_stock(Gtk.STOCK_GO_DOWN, Gtk.IconSize.BUTTON)
        button = Gtk.Button(_('_Download'), image=image, use_underline=True)
        self.add_action_widget(button, Gtk.ResponseType.OK)
        action_area.set_child_secondary(button, True)

        advanced_buttons = []

        image = Gtk.Image.new_from_stock(Gtk.STOCK_UNDO, Gtk.IconSize.BUTTON)
        button = Gtk.Button(_('_Reset Settings'), image=image, use_underline=True)
        button.set_no_show_all(True)
        self.add_action_widget(button, _RESPONSE_RESET)
        advanced_buttons.append(button)

        image = Gtk.Image.new_from_stock(Gtk.STOCK_SAVE, Gtk.IconSize.BUTTON)
        button = Gtk.Button(_('_Save Settings'), image=image, use_underline=True)
        button.set_no_show_all(True)
        self.add_action_widget(button, _RESPONSE_SAVE)
        advanced_buttons.append(button)

        ### Content Area
        content_area = self.get_content_area()

        vbox = Box(VERTICAL)
        content_area.add(vbox)
        self._main_vbox = vbox

        ## Save to
        expander = AlignedExpander(_('<b>Save to...</b>'))
        expander.connect_after('activate', self.update_size)
        vbox.pack_start(expander)
        self.save_expander = expander

        hbox = Box(HORIZONTAL)
        expander.add(hbox)

        # Directory
        tooltip = _('Select the directory to save files')
        entry = FileChooserEntry(_('Select download directory'),
                                 self,
                                 Gtk.FileChooserAction.SELECT_FOLDER,
                                 tooltip_text=tooltip
                                )
        hbox.pack_end(entry)
        self._task_options['dir'] = _Option(entry, 'text', _Option.string_mapper)

        model = CategoryFilterModel(pool_model)
        combo_box = CategoryComboBox(model, self)
        combo_box.connect('changed', self._on_category_cb_changed, entry)
        combo_box.set_active(0)
        hbox.pack_start(combo_box)
        self._task_options['category'] = _Option(combo_box, 'category',
                                                 _Option.default_mapper)

        ## Advanced
        expander = AlignedExpander(_('<b>Advanced</b>'), expanded=False)
        expander.connect_after('activate',
                               self._on_advanced_expander_activated,
                               advanced_buttons)
        expander.connect_after('activate', self.update_size)
        vbox.pack_end(expander)
        self.advanced_expander = expander

        notebook = Gtk.Notebook()
        expander.add(notebook)

        ## Normal Task Page
        label = Gtk.Label(_('Normal Task'))
        vbox = Box(VERTICAL, border_width=5)
        notebook.append_page(vbox, label)

        grid = Grid()
        vbox.pack_start(grid, expand=False)

        # Speed Limit
        tooltip = _('Upload speed limit, in KiB/s.')

        label = RightAlignedLabel(_('Upload Limit:'), tooltip_text=tooltip)
        grid.attach(label, 0, 0)

        adjustment = Gtk.Adjustment(lower=0, upper=4096, step_increment=10)
        spin_button = Gtk.SpinButton(adjustment=adjustment, numeric=True,
                                     tooltip_text=tooltip)
        grid.attach(spin_button, 1, 0)
        self._task_options['max-upload-limit'] = _Option(spin_button, 'value',
                                                         _Option.kib_mapper)

        tooltip = _('Download speed limit, in KiB/s.')

        label = RightAlignedLabel(_('Download Limit:'), tooltip_text=tooltip)
        grid.attach(label, 2, 0)

        adjustment = Gtk.Adjustment(lower=0, upper=4096, step_increment=10)
        spin_button = Gtk.SpinButton(adjustment=adjustment, numeric=True,
                                     tooltip_text=tooltip)
        grid.attach(spin_button, 3, 0)
        self._task_options['max-download-limit'] = _Option(spin_button, 'value',
                                                           _Option.kib_mapper)

        # Retry
        tooltip = _('Number of retries.')

        label = RightAlignedLabel(_('Max Retries:'), tooltip_text=tooltip)
        grid.attach(label, 0, 1)

        adjustment = Gtk.Adjustment(lower=0, upper=60, step_increment=1)
        spin_button = Gtk.SpinButton(adjustment=adjustment, numeric=True,
                                     tooltip_text=tooltip)
        grid.attach(spin_button, 1, 1)
        self._task_options['max-tries'] = _Option(spin_button, 'value',
                                                  _Option.int_mapper)

        tooltip = _('Time to wait before retries, in seconds.')

        label = RightAlignedLabel(_('Retry Interval:'), tooltip_text=tooltip)
        grid.attach(label, 2, 1)

        adjustment = Gtk.Adjustment(lower=0, upper=60, step_increment=1)
        spin_button = Gtk.SpinButton(adjustment=adjustment, numeric=True,
                                     tooltip_text=tooltip)
        grid.attach(spin_button, 3, 1)
        self._task_options['retry-wait'] = _Option(spin_button, 'value',
                                                   _Option.int_mapper)

        # Timeout
        tooltip = _('Download timeout, in seconds.')

        label = RightAlignedLabel(_('Timeout:'), tooltip_text=tooltip)
        grid.attach(label, 0, 2)

        adjustment = Gtk.Adjustment(lower=1, upper=300, step_increment=1)
        spin_button = Gtk.SpinButton(adjustment=adjustment, numeric=True,
                                     tooltip_text=tooltip)
        grid.attach(spin_button, 1, 2)
        self._task_options['timeout'] = _Option(spin_button, 'value',
                                                _Option.int_mapper)

        tooltip = _('Timeout to connect HTTP/FTP/proxy server, in seconds.')

        label = RightAlignedLabel(_('Connect Timeout:'), tooltip_text=tooltip)
        grid.attach(label, 2, 2)

        adjustment = Gtk.Adjustment(lower=1, upper=300, step_increment=1)
        spin_button = Gtk.SpinButton(adjustment=adjustment, numeric=True,
                                     tooltip_text=tooltip)
        grid.attach(spin_button, 3, 2)
        self._task_options['connect-timeout'] = _Option(spin_button, 'value',
                                                        _Option.int_mapper)

        # Split and Connections
        tooltip = _('Minimal size to split the file into pieces, in MiB.')

        label = RightAlignedLabel(_('Split Size:'), tooltip_text=tooltip)
        grid.attach(label, 0, 3)

        adjustment = Gtk.Adjustment(lower=1, upper=1024, step_increment=1)
        spin_button = Gtk.SpinButton(adjustment=adjustment, numeric=True,
                                     tooltip_text=tooltip)
        grid.attach(spin_button, 1, 3)
        self._task_options['min-split-size'] = _Option(spin_button, 'value',
                                                       _Option.mib_mapper)

        tooltip = _('Max connections per server.')
        label = RightAlignedLabel(_('Per Server Connections:'), tooltip_text=tooltip)
        grid.attach(label, 2, 3)

        adjustment = Gtk.Adjustment(lower=1, upper=10, step_increment=1)
        spin_button = Gtk.SpinButton(adjustment=adjustment, numeric=True,
                                     tooltip_text=tooltip)
        grid.attach(spin_button, 3, 3)
        self._task_options['max-connection-per-server'] = _Option(
            spin_button, 'value', _Option.int_mapper)

        # Referer
        tooltip = _('The referrer page of the download.')
        label = RightAlignedLabel(_('Referer:'), tooltip_text=tooltip)
        grid.attach(label, 0, 4)

        entry = Gtk.Entry(activates_default=True, tooltip_text=tooltip)
        grid.attach(entry, 1, 4, 3, 1)
        self._task_options['referer'] = _Option(entry, 'text',
                                                _Option.string_mapper)

        # Header
        label = RightAlignedLabel(_('HTTP Header:'))
        grid.attach(label, 0, 5)

        entry = Gtk.Entry(activates_default=True)
        grid.attach(entry, 1, 5, 3, 1)
        self._task_options['header'] = _Option(entry, 'text',
                                               _Option.string_mapper)

        ## BT Task Page
        label = Gtk.Label(_('BitTorrent'))
        vbox = Box(VERTICAL, border_width=5)
        notebook.append_page(vbox, label)

        grid = Grid()
        vbox.pack_start(grid, expand=False)

        # Limit
        label = RightAlignedLabel(_('Max open files:'))
        grid.attach(label, 0, 0)

        adjustment = Gtk.Adjustment(lower=1, upper=1024, step_increment=1)
        spin_button = Gtk.SpinButton(adjustment=adjustment, numeric=True)
        grid.attach(spin_button, 1, 0)
        self._task_options['bt-max-open-files'] = _Option(spin_button, 'value',
                                                          _Option.int_mapper)

        label = RightAlignedLabel(_('Max peers:'))
        grid.attach(label, 2, 0)

        adjustment = Gtk.Adjustment(lower=1, upper=1024, step_increment=1)
        spin_button = Gtk.SpinButton(adjustment=adjustment, numeric=True)
        grid.attach(spin_button, 3, 0)
        self._task_options['bt-max-peers'] = _Option(spin_button, 'value',
                                                     _Option.int_mapper)

        # Seed
        tooltip = _('Seed time, in minutes')

        label = RightAlignedLabel(_('Seed time:'), tooltip_text=tooltip)
        grid.attach(label, 0, 1)

        adjustment = Gtk.Adjustment(lower=0, upper=7200, step_increment=1)
        spin_button = Gtk.SpinButton(adjustment=adjustment, numeric=True,
                                     tooltip_text=tooltip)
        grid.attach(spin_button, 1, 1)
        self._task_options['seed-time'] = _Option(spin_button, 'value',
                                                  _Option.int_mapper)

        label = RightAlignedLabel(_('Seed ratio:'))
        grid.attach(label, 2, 1)

        adjustment = Gtk.Adjustment(lower=0, upper=20, step_increment=.1)
        spin_button = Gtk.SpinButton(adjustment=adjustment, numeric=True, digits=1)
        grid.attach(spin_button, 3, 1)
        self._task_options['seed-ratio'] = _Option(spin_button, 'value',
                                                   _Option.float_mapper)

        # Timeout
        tooltip = _('Download timeout, in seconds.')

        label = RightAlignedLabel(_('Timeout:'), tooltip_text=tooltip)
        grid.attach(label, 0, 2)

        adjustment = Gtk.Adjustment(lower=1, upper=300, step_increment=1)
        spin_button = Gtk.SpinButton(adjustment=adjustment, numeric=True,
                                     tooltip_text=tooltip)
        grid.attach(spin_button, 1, 2)
        self._task_options['bt-tracker-timeout'] = _Option(spin_button, 'value',
                                                           _Option.int_mapper)

        tooltip = _('Timeout to establish connection to trackers, in seconds.')

        label = RightAlignedLabel(_('Connect Timeout:'), tooltip_text=tooltip)
        grid.attach(label, 2, 2)

        adjustment = Gtk.Adjustment(lower=1, upper=300, step_increment=1)
        spin_button = Gtk.SpinButton(adjustment=adjustment, numeric=True,
                                     tooltip_text=tooltip)
        grid.attach(spin_button, 3, 2)
        self._task_options['bt-tracker-connect-timeout'] = _Option(
            spin_button, 'value', _Option.int_mapper)

        tooltip = _('Try to download first and last pieces first.')
        label = RightAlignedLabel(_('Preview Mode:'), tooltip_text=tooltip)
        grid.attach(label, 0, 3)
        switch = Gtk.Switch(tooltip_text=tooltip)
        grid.attach(switch, 1, 3)
        self._task_options['bt-prioritize-piece'] = _Option(
            switch, 'active', _Option.prioritize_mapper)

        tooltip = _('Convert downloaded torrent files to BitTorrent tasks.')
        label = RightAlignedLabel(_('Follow Torrent:'), tooltip_text=tooltip)
        grid.attach(label, 2, 3)
        switch = Gtk.Switch(tooltip_text=tooltip)
        grid.attach(switch, 3, 3)
        self._task_options['follow-torrent'] = _Option(switch, 'active',
                                                       _Option.bool_mapper)

        # Mirrors
        tooltip = _('For single file torrents, a mirror can be a ' \
                    'complete URI pointing to the resource or if the mirror ' \
                    'ends with /, name in torrent file is added. For ' \
                    'multi-file torrents, name and path in torrent are ' \
                    'added to form a URI for each file.')
        expander = AlignedExpander(_('Mirrors'), expanded=False, tooltip_text=tooltip)
        expander.connect_after('activate', self.update_size)
        grid.attach(expander, 0, 4, 4, 1)
        #vbox.pack_start(expander, expand=False)

        uris_view = URIsView()
        uris_view.set_size_request(-1, 70)
        expander.add(uris_view)
        self._task_options['uris'] = _Option(uris_view, 'uris',
                                             _Option.default_mapper)

        ## Metalink Page
        label = Gtk.Label(_('Metalink'))
        vbox = Box(VERTICAL, border_width=5)
        notebook.append_page(vbox, label)

        grid = Grid(halign=Gtk.Align.CENTER)
        vbox.pack_start(grid, expand=False)

        label = RightAlignedLabel(_('Preferred locations:'))
        grid.attach(label, 0, 0)

        entry = Gtk.Entry()
        grid.attach(entry, 1, 0)
        self._task_options['metalink-location'] = _Option(entry, 'text',
                                                          _Option.string_mapper)

        label = RightAlignedLabel(_('Language:'))
        grid.attach(label, 0, 1)

        entry = Gtk.Entry()
        grid.attach(entry, 1, 1)
        self._task_options['metalink-language'] = _Option(entry, 'text',
                                                          _Option.string_mapper)

        label = RightAlignedLabel(_('Version:'))
        grid.attach(label, 0, 2)

        entry = Gtk.Entry()
        grid.attach(entry, 1, 2)
        self._task_options['metalink-version'] = _Option(entry, 'text',
                                                         _Option.string_mapper)

        label = RightAlignedLabel(_('OS:'))
        grid.attach(label, 0, 3)

        entry = Gtk.Entry()
        grid.attach(entry, 1, 3)
        self._task_options['metalink-os'] = _Option(entry, 'text',
                                                    _Option.string_mapper)

        tooltip = _('Convert downloaded metalink files to Metalink tasks.')

        label = RightAlignedLabel(_('Follow Metalink:'), tooltip_text=tooltip)
        grid.attach(label, 0, 4)

        switch = Gtk.Switch(tooltip_text=tooltip)
        grid.attach(switch, 1, 4)
        self._task_options['follow-metalink'] = _Option(switch, 'active',
                                                        _Option.bool_mapper)

        ## Miscellaneous Page
        label = Gtk.Label(_('Miscellaneous'))
        vbox = Box(VERTICAL, border_width=5)
        notebook.append_page(vbox, label)

        grid = Grid()
        vbox.pack_start(grid, expand=False)

        # Overwrite and Rename
        tooltip = _("Restart download from scratch if the corresponding"
                    " control file doesn't exist.")

        label = RightAlignedLabel(_('Allow Overwrite:'), tooltip_text=tooltip)
        grid.attach(label, 0, 0)

        switch = Gtk.Switch(tooltip_text=tooltip)
        grid.attach(switch, 1, 0)
        self._task_options['allow-overwrite'] = _Option(switch, 'active',
                                                        _Option.bool_mapper)

        tooltip = _('Rename file name if the same file already exists.')

        label = RightAlignedLabel(_('Auto Rename Files:'), tooltip_text=tooltip)
        grid.attach(label, 2, 0)

        switch = Gtk.Switch(tooltip_text=tooltip)
        grid.attach(switch, 3, 0)
        self._task_options['auto-file-renaming'] = _Option(switch, 'active',
                                                           _Option.bool_mapper)

        tooltip = _('Format: [http://][USER:PASSWORD@]HOST[:PORT]')
        label = RightAlignedLabel(_('Proxy:'), tooltip_text=tooltip)
        grid.attach(label, 0, 1)

        entry = Gtk.Entry(activates_default=True, tooltip_text=tooltip)
        entry.set_placeholder_text(tooltip)
        grid.attach(entry, 1, 1, 3, 1)
        self._task_options['all-proxy'] = _Option(entry, 'text',
                                                  _Option.string_mapper)

        # Authorization
        expander = AlignedExpander(_('Authorization'), expanded=False)
        expander.connect_after('activate', self.update_size)
        vbox.pack_start(expander, expand=False)

        grid = Grid()
        expander.add(grid)

        label = RightAlignedLabel(_('HTTP User:'******'http-user'] = _Option(entry, 'text',
                                                  _Option.string_mapper)

        label = RightAlignedLabel(_('Password:'******'http-passwd'] = _Option(entry, 'text',
                                                    _Option.string_mapper)

        label = RightAlignedLabel(_('FTP User:'******'ftp-user'] = _Option(entry, 'text',
                                                 _Option.string_mapper)

        label = RightAlignedLabel(_('Password:'******'ftp-passwd'] = _Option(entry, 'text',
                                                   _Option.string_mapper)

        self.show_all()
Esempio n. 6
0
    def __init__(self, pool_model, *args, **kwargs):
        Gtk.Dialog.__init__(self, title=_('Create New Task'), *args, **kwargs)
        LoggingMixin.__init__(self)

        self._ui = None
        self._default_ui = None
        self._normal_ui = None
        self._bt_ui = None
        self._ml_ui = None

        self._task_options = {}

        ### Action Area
        action_area = self.get_action_area()
        action_area.set_layout(Gtk.ButtonBoxStyle.START)

        button = Gtk.Button.new_from_stock(Gtk.STOCK_CANCEL)
        self.add_action_widget(button, Gtk.ResponseType.CANCEL)
        action_area.set_child_secondary(button, True)

        image = Gtk.Image.new_from_stock(Gtk.STOCK_GO_DOWN,
                                         Gtk.IconSize.BUTTON)
        button = Gtk.Button(_('_Download'), image=image, use_underline=True)
        self.add_action_widget(button, Gtk.ResponseType.OK)
        action_area.set_child_secondary(button, True)

        advanced_buttons = []

        image = Gtk.Image.new_from_stock(Gtk.STOCK_UNDO, Gtk.IconSize.BUTTON)
        button = Gtk.Button(_('_Reset Settings'),
                            image=image,
                            use_underline=True)
        button.set_no_show_all(True)
        self.add_action_widget(button, _RESPONSE_RESET)
        advanced_buttons.append(button)

        image = Gtk.Image.new_from_stock(Gtk.STOCK_SAVE, Gtk.IconSize.BUTTON)
        button = Gtk.Button(_('_Save Settings'),
                            image=image,
                            use_underline=True)
        button.set_no_show_all(True)
        self.add_action_widget(button, _RESPONSE_SAVE)
        advanced_buttons.append(button)

        ### Content Area
        content_area = self.get_content_area()

        vbox = Box(VERTICAL)
        content_area.add(vbox)
        self._main_vbox = vbox

        ## Save to
        expander = AlignedExpander(_('<b>Save to...</b>'))
        expander.connect_after('activate', self.update_size)
        vbox.pack_start(expander)
        self.save_expander = expander

        hbox = Box(HORIZONTAL)
        expander.add(hbox)

        # Directory
        tooltip = _('Select the directory to save files')
        entry = FileChooserEntry(_('Select download directory'),
                                 self,
                                 Gtk.FileChooserAction.SELECT_FOLDER,
                                 tooltip_text=tooltip)
        hbox.pack_end(entry)
        self._task_options['dir'] = _Option(entry, 'text',
                                            _Option.string_mapper)

        model = CategoryFilterModel(pool_model)
        combo_box = CategoryComboBox(model, self)
        combo_box.connect('changed', self._on_category_cb_changed, entry)
        combo_box.set_active(0)
        hbox.pack_start(combo_box)
        self._task_options['category'] = _Option(combo_box, 'category',
                                                 _Option.default_mapper)

        ## Advanced
        expander = AlignedExpander(_('<b>Advanced</b>'), expanded=False)
        expander.connect_after('activate',
                               self._on_advanced_expander_activated,
                               advanced_buttons)
        expander.connect_after('activate', self.update_size)
        vbox.pack_end(expander)
        self.advanced_expander = expander

        notebook = Gtk.Notebook()
        expander.add(notebook)

        ## Normal Task Page
        label = Gtk.Label(_('Normal Task'))
        vbox = Box(VERTICAL, border_width=5)
        notebook.append_page(vbox, label)

        grid = Grid()
        vbox.pack_start(grid, expand=False)

        # Speed Limit
        tooltip = _('Upload speed limit, in KiB/s.')

        label = RightAlignedLabel(_('Upload Limit:'), tooltip_text=tooltip)
        grid.attach(label, 0, 0)

        adjustment = Gtk.Adjustment(lower=0, upper=4096, step_increment=10)
        spin_button = Gtk.SpinButton(adjustment=adjustment,
                                     numeric=True,
                                     tooltip_text=tooltip)
        grid.attach(spin_button, 1, 0)
        self._task_options['max-upload-limit'] = _Option(
            spin_button, 'value', _Option.kib_mapper)

        tooltip = _('Download speed limit, in KiB/s.')

        label = RightAlignedLabel(_('Download Limit:'), tooltip_text=tooltip)
        grid.attach(label, 2, 0)

        adjustment = Gtk.Adjustment(lower=0, upper=4096, step_increment=10)
        spin_button = Gtk.SpinButton(adjustment=adjustment,
                                     numeric=True,
                                     tooltip_text=tooltip)
        grid.attach(spin_button, 3, 0)
        self._task_options['max-download-limit'] = _Option(
            spin_button, 'value', _Option.kib_mapper)

        # Retry
        tooltip = _('Number of retries.')

        label = RightAlignedLabel(_('Max Retries:'), tooltip_text=tooltip)
        grid.attach(label, 0, 1)

        adjustment = Gtk.Adjustment(lower=0, upper=60, step_increment=1)
        spin_button = Gtk.SpinButton(adjustment=adjustment,
                                     numeric=True,
                                     tooltip_text=tooltip)
        grid.attach(spin_button, 1, 1)
        self._task_options['max-tries'] = _Option(spin_button, 'value',
                                                  _Option.int_mapper)

        tooltip = _('Time to wait before retries, in seconds.')

        label = RightAlignedLabel(_('Retry Interval:'), tooltip_text=tooltip)
        grid.attach(label, 2, 1)

        adjustment = Gtk.Adjustment(lower=0, upper=60, step_increment=1)
        spin_button = Gtk.SpinButton(adjustment=adjustment,
                                     numeric=True,
                                     tooltip_text=tooltip)
        grid.attach(spin_button, 3, 1)
        self._task_options['retry-wait'] = _Option(spin_button, 'value',
                                                   _Option.int_mapper)

        # Timeout
        tooltip = _('Download timeout, in seconds.')

        label = RightAlignedLabel(_('Timeout:'), tooltip_text=tooltip)
        grid.attach(label, 0, 2)

        adjustment = Gtk.Adjustment(lower=1, upper=300, step_increment=1)
        spin_button = Gtk.SpinButton(adjustment=adjustment,
                                     numeric=True,
                                     tooltip_text=tooltip)
        grid.attach(spin_button, 1, 2)
        self._task_options['timeout'] = _Option(spin_button, 'value',
                                                _Option.int_mapper)

        tooltip = _('Timeout to connect HTTP/FTP/proxy server, in seconds.')

        label = RightAlignedLabel(_('Connect Timeout:'), tooltip_text=tooltip)
        grid.attach(label, 2, 2)

        adjustment = Gtk.Adjustment(lower=1, upper=300, step_increment=1)
        spin_button = Gtk.SpinButton(adjustment=adjustment,
                                     numeric=True,
                                     tooltip_text=tooltip)
        grid.attach(spin_button, 3, 2)
        self._task_options['connect-timeout'] = _Option(
            spin_button, 'value', _Option.int_mapper)

        # Split and Connections
        tooltip = _('Minimal size to split the file into pieces, in MiB.')

        label = RightAlignedLabel(_('Split Size:'), tooltip_text=tooltip)
        grid.attach(label, 0, 3)

        adjustment = Gtk.Adjustment(lower=1, upper=1024, step_increment=1)
        spin_button = Gtk.SpinButton(adjustment=adjustment,
                                     numeric=True,
                                     tooltip_text=tooltip)
        grid.attach(spin_button, 1, 3)
        self._task_options['min-split-size'] = _Option(spin_button, 'value',
                                                       _Option.mib_mapper)

        tooltip = _('Max connections per server.')
        label = RightAlignedLabel(_('Per Server Connections:'),
                                  tooltip_text=tooltip)
        grid.attach(label, 2, 3)

        adjustment = Gtk.Adjustment(lower=1, upper=10, step_increment=1)
        spin_button = Gtk.SpinButton(adjustment=adjustment,
                                     numeric=True,
                                     tooltip_text=tooltip)
        grid.attach(spin_button, 3, 3)
        self._task_options['max-connection-per-server'] = _Option(
            spin_button, 'value', _Option.int_mapper)

        # Referer
        tooltip = _('The referrer page of the download.')
        label = RightAlignedLabel(_('Referer:'), tooltip_text=tooltip)
        grid.attach(label, 0, 4)

        entry = Gtk.Entry(activates_default=True, tooltip_text=tooltip)
        grid.attach(entry, 1, 4, 3, 1)
        self._task_options['referer'] = _Option(entry, 'text',
                                                _Option.string_mapper)

        # Header
        label = RightAlignedLabel(_('HTTP Header:'))
        grid.attach(label, 0, 5)

        entry = Gtk.Entry(activates_default=True)
        grid.attach(entry, 1, 5, 3, 1)
        self._task_options['header'] = _Option(entry, 'text',
                                               _Option.string_mapper)

        ## BT Task Page
        label = Gtk.Label(_('BitTorrent'))
        vbox = Box(VERTICAL, border_width=5)
        notebook.append_page(vbox, label)

        grid = Grid()
        vbox.pack_start(grid, expand=False)

        # Limit
        label = RightAlignedLabel(_('Max open files:'))
        grid.attach(label, 0, 0)

        adjustment = Gtk.Adjustment(lower=1, upper=1024, step_increment=1)
        spin_button = Gtk.SpinButton(adjustment=adjustment, numeric=True)
        grid.attach(spin_button, 1, 0)
        self._task_options['bt-max-open-files'] = _Option(
            spin_button, 'value', _Option.int_mapper)

        label = RightAlignedLabel(_('Max peers:'))
        grid.attach(label, 2, 0)

        adjustment = Gtk.Adjustment(lower=1, upper=1024, step_increment=1)
        spin_button = Gtk.SpinButton(adjustment=adjustment, numeric=True)
        grid.attach(spin_button, 3, 0)
        self._task_options['bt-max-peers'] = _Option(spin_button, 'value',
                                                     _Option.int_mapper)

        # Seed
        tooltip = _('Seed time, in minutes')

        label = RightAlignedLabel(_('Seed time:'), tooltip_text=tooltip)
        grid.attach(label, 0, 1)

        adjustment = Gtk.Adjustment(lower=0, upper=7200, step_increment=1)
        spin_button = Gtk.SpinButton(adjustment=adjustment,
                                     numeric=True,
                                     tooltip_text=tooltip)
        grid.attach(spin_button, 1, 1)
        self._task_options['seed-time'] = _Option(spin_button, 'value',
                                                  _Option.int_mapper)

        label = RightAlignedLabel(_('Seed ratio:'))
        grid.attach(label, 2, 1)

        adjustment = Gtk.Adjustment(lower=0, upper=20, step_increment=.1)
        spin_button = Gtk.SpinButton(adjustment=adjustment,
                                     numeric=True,
                                     digits=1)
        grid.attach(spin_button, 3, 1)
        self._task_options['seed-ratio'] = _Option(spin_button, 'value',
                                                   _Option.float_mapper)

        # Timeout
        tooltip = _('Download timeout, in seconds.')

        label = RightAlignedLabel(_('Timeout:'), tooltip_text=tooltip)
        grid.attach(label, 0, 2)

        adjustment = Gtk.Adjustment(lower=1, upper=300, step_increment=1)
        spin_button = Gtk.SpinButton(adjustment=adjustment,
                                     numeric=True,
                                     tooltip_text=tooltip)
        grid.attach(spin_button, 1, 2)
        self._task_options['bt-tracker-timeout'] = _Option(
            spin_button, 'value', _Option.int_mapper)

        tooltip = _('Timeout to establish connection to trackers, in seconds.')

        label = RightAlignedLabel(_('Connect Timeout:'), tooltip_text=tooltip)
        grid.attach(label, 2, 2)

        adjustment = Gtk.Adjustment(lower=1, upper=300, step_increment=1)
        spin_button = Gtk.SpinButton(adjustment=adjustment,
                                     numeric=True,
                                     tooltip_text=tooltip)
        grid.attach(spin_button, 3, 2)
        self._task_options['bt-tracker-connect-timeout'] = _Option(
            spin_button, 'value', _Option.int_mapper)

        tooltip = _('Try to download first and last pieces first.')
        label = RightAlignedLabel(_('Preview Mode:'), tooltip_text=tooltip)
        grid.attach(label, 0, 3)
        switch = Gtk.Switch(tooltip_text=tooltip)
        grid.attach(switch, 1, 3)
        self._task_options['bt-prioritize-piece'] = _Option(
            switch, 'active', _Option.prioritize_mapper)

        tooltip = _('Convert downloaded torrent files to BitTorrent tasks.')
        label = RightAlignedLabel(_('Follow Torrent:'), tooltip_text=tooltip)
        grid.attach(label, 2, 3)
        switch = Gtk.Switch(tooltip_text=tooltip)
        grid.attach(switch, 3, 3)
        self._task_options['follow-torrent'] = _Option(switch, 'active',
                                                       _Option.bool_mapper)

        # Mirrors
        tooltip = _('For single file torrents, a mirror can be a ' \
                    'complete URI pointing to the resource or if the mirror ' \
                    'ends with /, name in torrent file is added. For ' \
                    'multi-file torrents, name and path in torrent are ' \
                    'added to form a URI for each file.')
        expander = AlignedExpander(_('Mirrors'),
                                   expanded=False,
                                   tooltip_text=tooltip)
        expander.connect_after('activate', self.update_size)
        grid.attach(expander, 0, 4, 4, 1)
        #vbox.pack_start(expander, expand=False)

        uris_view = URIsView()
        uris_view.set_size_request(-1, 70)
        expander.add(uris_view)
        self._task_options['uris'] = _Option(uris_view, 'uris',
                                             _Option.default_mapper)

        ## Metalink Page
        label = Gtk.Label(_('Metalink'))
        vbox = Box(VERTICAL, border_width=5)
        notebook.append_page(vbox, label)

        grid = Grid(halign=Gtk.Align.CENTER)
        vbox.pack_start(grid, expand=False)

        label = RightAlignedLabel(_('Preferred locations:'))
        grid.attach(label, 0, 0)

        entry = Gtk.Entry()
        grid.attach(entry, 1, 0)
        self._task_options['metalink-location'] = _Option(
            entry, 'text', _Option.string_mapper)

        label = RightAlignedLabel(_('Language:'))
        grid.attach(label, 0, 1)

        entry = Gtk.Entry()
        grid.attach(entry, 1, 1)
        self._task_options['metalink-language'] = _Option(
            entry, 'text', _Option.string_mapper)

        label = RightAlignedLabel(_('Version:'))
        grid.attach(label, 0, 2)

        entry = Gtk.Entry()
        grid.attach(entry, 1, 2)
        self._task_options['metalink-version'] = _Option(
            entry, 'text', _Option.string_mapper)

        label = RightAlignedLabel(_('OS:'))
        grid.attach(label, 0, 3)

        entry = Gtk.Entry()
        grid.attach(entry, 1, 3)
        self._task_options['metalink-os'] = _Option(entry, 'text',
                                                    _Option.string_mapper)

        tooltip = _('Convert downloaded metalink files to Metalink tasks.')

        label = RightAlignedLabel(_('Follow Metalink:'), tooltip_text=tooltip)
        grid.attach(label, 0, 4)

        switch = Gtk.Switch(tooltip_text=tooltip)
        grid.attach(switch, 1, 4)
        self._task_options['follow-metalink'] = _Option(
            switch, 'active', _Option.bool_mapper)

        ## Miscellaneous Page
        label = Gtk.Label(_('Miscellaneous'))
        vbox = Box(VERTICAL, border_width=5)
        notebook.append_page(vbox, label)

        grid = Grid()
        vbox.pack_start(grid, expand=False)

        # Overwrite and Rename
        tooltip = _("Restart download from scratch if the corresponding"
                    " control file doesn't exist.")

        label = RightAlignedLabel(_('Allow Overwrite:'), tooltip_text=tooltip)
        grid.attach(label, 0, 0)

        switch = Gtk.Switch(tooltip_text=tooltip)
        grid.attach(switch, 1, 0)
        self._task_options['allow-overwrite'] = _Option(
            switch, 'active', _Option.bool_mapper)

        tooltip = _('Rename file name if the same file already exists.')

        label = RightAlignedLabel(_('Auto Rename Files:'),
                                  tooltip_text=tooltip)
        grid.attach(label, 2, 0)

        switch = Gtk.Switch(tooltip_text=tooltip)
        grid.attach(switch, 3, 0)
        self._task_options['auto-file-renaming'] = _Option(
            switch, 'active', _Option.bool_mapper)

        tooltip = _('Format: [http://][USER:PASSWORD@]HOST[:PORT]')
        label = RightAlignedLabel(_('Proxy:'), tooltip_text=tooltip)
        grid.attach(label, 0, 1)

        entry = Gtk.Entry(activates_default=True, tooltip_text=tooltip)
        entry.set_placeholder_text(tooltip)
        grid.attach(entry, 1, 1, 3, 1)
        self._task_options['all-proxy'] = _Option(entry, 'text',
                                                  _Option.string_mapper)

        # Authorization
        expander = AlignedExpander(_('Authorization'), expanded=False)
        expander.connect_after('activate', self.update_size)
        vbox.pack_start(expander, expand=False)

        grid = Grid()
        expander.add(grid)

        label = RightAlignedLabel(_('HTTP User:'******'http-user'] = _Option(entry, 'text',
                                                  _Option.string_mapper)

        label = RightAlignedLabel(_('Password:'******'http-passwd'] = _Option(entry, 'text',
                                                    _Option.string_mapper)

        label = RightAlignedLabel(_('FTP User:'******'ftp-user'] = _Option(entry, 'text',
                                                 _Option.string_mapper)

        label = RightAlignedLabel(_('Password:'******'ftp-passwd'] = _Option(entry, 'text',
                                                   _Option.string_mapper)

        self.show_all()
Esempio n. 7
0
    def __init__(self):
        """
        Create toplevel window of L{yaner}. The window structure is
        like this:
            - vbox
                - toolbar
                - hpaned
                    - scrolled_window
                        - _pool_view
                    - task_vbox
                        - _task_list_view
        """
        Gtk.Window.__init__(self, title=_('Yaner'))
        LoggingMixin.__init__(self)

        self.logger.info('Initializing toplevel window...')

        self._settings = None

        self._popups = None

        # UIManager: Toolbar and menus
        self._action_group = None
        self._ui_manager = None

        self.set_default_size(self.settings.get_uint('width'),
                              self.settings.get_uint('height'))
        if self.settings.get_boolean('maximized'):
            self.maximize()

        self.set_default_icon_name('yaner')

        # The toplevel vbox
        vbox = Box(VERTICAL, 0)
        self.add(vbox)

        # Toolbar
        toolbar = self.ui_manager.get_widget('/toolbar')
        vbox.pack_start(toolbar, expand=False)

        # HPaned: PoolView as left, TaskVBox as right
        hpaned = Gtk.HPaned()
        vbox.pack_start(hpaned)

        # Right pane
        vbox = Box(VERTICAL)
        hpaned.pack2(vbox, True, False)
        self.task_box = vbox

        self._task_list_model = TaskListModel()

        scrolled_window = Gtk.ScrolledWindow()
        scrolled_window.set_shadow_type(Gtk.ShadowType.IN)
        scrolled_window.set_size_request(400, -1)
        vbox.pack_end(scrolled_window)

        task_list_view = TaskListView(self._task_list_model)
        task_list_view.set_show_expanders(False)
        task_list_view.set_level_indentation(16)
        task_list_view.expand_all()
        task_list_view.selection.set_mode(Gtk.SelectionMode.MULTIPLE)
        task_list_view.connect('key-press-event',
                               self._on_task_list_view_key_pressed)
        task_list_view.connect('button-press-event',
                               self._on_task_list_view_button_pressed)
        task_list_view.connect('row-activated',
                               self._on_task_list_view_row_activated)
        scrolled_window.add(task_list_view)

        self._task_list_view = task_list_view

        # Left pane
        scrolled_window = Gtk.ScrolledWindow()
        scrolled_window.set_policy(Gtk.PolicyType.AUTOMATIC,
                                   Gtk.PolicyType.NEVER)
        scrolled_window.set_shadow_type(Gtk.ShadowType.IN)
        scrolled_window.set_size_request(180, -1)
        hpaned.pack1(scrolled_window, False, False)

        self._pool_model = PoolModel()

        pool_view = PoolView(self._pool_model)
        pool_view.set_headers_visible(False)
        pool_view.set_show_expanders(False)
        pool_view.set_level_indentation(16)
        pool_view.connect('button-press-event',
                          self._on_pool_view_button_pressed)
        scrolled_window.add(pool_view)

        self._pool_view = pool_view

        pool_view.selection.set_mode(Gtk.SelectionMode.SINGLE)
        pool_view.selection.connect("changed",
                                    self._on_pool_view_selection_changed)

        # Add Pools to the PoolModel
        for pool in SQLSession.query(Pool):
            self._pool_model.add_pool(pool)
        pool_view.expand_all()
        # Select first iter
        pool_view.selection.select_iter(self._pool_model.get_iter_first())

        # Dialogs
        self._task_new_dialog = None
        self._preferences_dialog = None
        self._about_dialog = None
        self._category_bar = None
        self._pool_bar = None

        # Status icon
        status_icon = Gtk.StatusIcon(icon_name='yaner')
        status_icon.connect('activate', self._on_status_icon_activated)
        status_icon.connect('popup-menu', self._on_status_icon_popup)

        self.connect('delete-event', self._on_delete_event, status_icon)

        self.logger.info('Toplevel window initialized.')