Exemple #1
0
    def _on_pool_bar_response(self, info_bar, response_id):
        """When pool bar responsed, create or edit pool."""
        if response_id != Gtk.ResponseType.OK:
            info_bar.hide()
            return

        pool = info_bar.pool
        widgets = info_bar.widgets
        props = {}

        for (prop, widget) in widgets.items():
            props[prop] = widget.get_text().strip()

        for prop in ('name', 'host', 'port'):
            if not props[prop]:
                widgets[prop].set_placeholder_text(_('Required'))
                return

        if pool is None:
            pool = Pool(**props)
            self._pool_model.add_pool(pool)
            self._pool_view.expand_all()
        else:
            pool.name = props['name']
            pool.host = props['host']
            pool.port = props['port']
            pool.user = props['user']
            pool.passwd = props['passwd']
            SQLSession.commit()

        info_bar.hide()
Exemple #2
0
    def __init__(self,
                 name,
                 category,
                 options,
                 uris=[],
                 torrent=None,
                 metafile=None):
        self.name = name
        self.status = Task._DEFAULT_STATUS

        self.uris = uris
        self.torrent = torrent
        self.metafile = metafile

        self.options = options
        self.category = category

        LoggingMixin.__init__(self)
        self.logger.info('Adding new task: {}...'.format(self))
        self.logger.debug('Task options: {}'.format(options))

        SQLSession.add(self)
        SQLSession.commit()

        self._init()
Exemple #3
0
 def _on_pool_remove(self, action, data):
     """Remove pool."""
     queuing = self._pool_view.selected_presentable
     pool = queuing.pool
     if pool.is_local:
         dialog = Gtk.MessageDialog(
             self,
             Gtk.DialogFlags.MODAL,
             Gtk.MessageType.ERROR,
             Gtk.ButtonsType.CLOSE,
             _('The local server should not be removed.'),
         )
     else:
         dialog = Gtk.MessageDialog(
             self,
             Gtk.DialogFlags.MODAL,
             Gtk.MessageType.WARNING,
             Gtk.ButtonsType.YES_NO,
             _('Are you sure to remove the server "{}"?\nAll tasks '
               'in the server will be <b>removed!</b>').format(pool.name),
             use_markup=True)
     response = dialog.run()
     dialog.destroy()
     if response == Gtk.ResponseType.YES:
         # Select the local pool, in order to remove the selected pool
         local_pool = SQLSession.query(Pool).filter(
             Pool.is_local == True)[0]
         iter_ = self._pool_model.get_iter_for_presentable(
             local_pool.queuing)
         self._pool_view.selection.select_iter(iter_)
         # Remove the category iter
         self._pool_model.remove_pool(pool)
         SQLSession.delete(pool)
         SQLSession.commit()
Exemple #4
0
    def _on_category_bar_response(self, info_bar, response_id):
        """When category_bar responsed, create or edit category."""
        if response_id != Gtk.ResponseType.OK:
            info_bar.hide()
            return

        category = info_bar.category
        pool = info_bar.pool
        widgets = info_bar.widgets

        name = widgets['name'].get_text().strip()
        directory = widgets['directory'].get_text().strip()

        if not name:
            widgets['name'].set_placeholder_text(_('Required'))
            return
        if not directory:
            widgets['directory'].set_placeholder_text(_('Required'))
            return

        if category is None:
            category = Category(name=name, directory=directory, pool=pool)
            self._pool_model.add_presentable(category, insert=True)
        else:
            category.name = name
            category.directory = directory
            SQLSession.commit()
        info_bar.hide()
Exemple #5
0
 def _on_category_remove(self, action, data):
     """Remove category."""
     category = self._pool_view.selected_presentable
     pool = category.pool
     if category is pool.default_category:
         dialog = Gtk.MessageDialog(
             self,
             Gtk.DialogFlags.MODAL,
             Gtk.MessageType.ERROR,
             Gtk.ButtonsType.CLOSE,
             _('The default category should not be removed.'),
         )
     else:
         dialog = Gtk.MessageDialog(
             self,
             Gtk.DialogFlags.MODAL,
             Gtk.MessageType.WARNING,
             Gtk.ButtonsType.YES_NO,
             _('Are you sure to remove the category "{}"?\nAll tasks '
               'in the category will be moved to the default category.').
             format(category.name),
         )
     response = dialog.run()
     dialog.destroy()
     if response == Gtk.ResponseType.YES:
         # Move all tasks to default category
         for task in category.tasks:
             task.category = pool.default_category
             pool.default_category.add_task(task)
         # Remove the category iter
         self._pool_model.remove_presentable(category)
         SQLSession.delete(category)
         SQLSession.commit()
Exemple #6
0
 def state(self, state):
     """Always sync when task state changes."""
     if hash(self) and self.state != state:
         self.status['status'] = state
         SQLSession.commit()
         self.emit('changed')
     else:
         self.status['status'] = state
Exemple #7
0
 def state(self, state):
     """Always sync when task state changes."""
     if hash(self) and self.state != state:
         self.status['status'] = state
         SQLSession.commit()
         self.emit('changed')
     else:
         self.status['status'] = state
Exemple #8
0
    def __init__(self, name, directory, pool):
        self.name = name
        self.directory = directory
        self.pool = pool

        SQLSession.add(self)
        SQLSession.commit()

        self._init()
Exemple #9
0
    def __init__(self, name, directory, pool):
        self.name = name
        self.directory = directory
        self.pool = pool

        SQLSession.add(self)
        SQLSession.commit()

        self._init()
Exemple #10
0
    def __init__(self, name, host, user='', passwd='', port='6800', is_local=False):
        self.name = name
        self.user = user
        self.passwd = passwd
        self.host = host
        self.port = port
        self.is_local = is_local

        SQLSession.add(self)
        SQLSession.commit()

        self._init()
Exemple #11
0
    def do_shutdown(self):
        """When shutdown, finalize database and logging systems."""
        self.logger.info('Shutting down database...')
        SQLSession.commit()
        SQLSession.close()

        self._daemon.terminate()

        self.logger.info('Application quit normally.')
        logging.shutdown()

        Gtk.Application.do_shutdown(self)
Exemple #12
0
    def do_shutdown(self):
        """When shutdown, finalize database and logging systems."""
        self.logger.info('Shutting down database...')
        SQLSession.commit()
        SQLSession.close()

        self._daemon.terminate()

        self.logger.info('Application quit normally.')
        logging.shutdown()

        Gtk.Application.do_shutdown(self)
Exemple #13
0
    def __init__(self, name, category, options, uris=[],
                 torrent=None, metafile=None):
        self.name = name
        self.status = Task._DEFAULT_STATUS

        self.uris = uris
        self.torrent = torrent
        self.metafile = metafile

        self.options = options
        self.category = category

        LoggingMixin.__init__(self)
        self.logger.info('Adding new task: {}...'.format(self))
        self.logger.debug('Task options: {}'.format(options))

        SQLSession.add(self)
        SQLSession.commit()

        self._init()
Exemple #14
0
    def _init(self):
        GObject.GObject.__init__(self)
        LoggingMixin.__init__(self)

        self._queuing = None
        self._categories = []
        self._dustbin = None

        self._connected = False
        self._proxy = None

        if self.default_category is None:
            self.logger.info('Creating default category for {}.'.format(self))
            down_dir = os.environ.get('XDG_DOWNLOAD_DIR', os.path.expanduser('~'))
            self.default_category = Category(name=_('My Downloads'),
                                             directory= down_dir,
                                             pool=self)
            SQLSession.commit()

        self.do_disconnected()
        self._keep_connection()
Exemple #15
0
 def remove(self):
     """Remove task."""
     if self.is_trashed:
         self.pool.dustbin.remove_task(self)
         SQLSession.delete(self)
         SQLSession.commit()
Exemple #16
0
 def on_got_session_info(deferred):
     """Set session id the task belongs to."""
     self.session_id = deferred.result['sessionId']
     SQLSession.commit()
Exemple #17
0
 def on_got_session_info(deferred):
     """Set session id the task belongs to."""
     self.session_id = deferred.result['sessionId']
     SQLSession.commit()
Exemple #18
0
 def remove(self):
     """Remove task."""
     if self.is_trashed:
         self.pool.dustbin.remove_task(self)
         SQLSession.delete(self)
         SQLSession.commit()