Beispiel #1
0
    def __init__(self, parent, db):
        QObject.__init__(self, parent)
        self.internet_connection_failed = False
        self._parent = parent
        self.no_internet_msg = _('Cannot download news as no internet connection '
                'is active')
        self.no_internet_dialog = d = error_dialog(self._parent,
                self.no_internet_msg, _('No internet connection'),
                show_copy_button=False)
        d.setModal(False)

        self.recipe_model = RecipeModel()
        self.db = db
        self.lock = QMutex(QMutex.Recursive)
        self.download_queue = set()

        self.news_menu = QMenu()
        self.news_icon = QIcon(I('news.png'))
        self.scheduler_action = QAction(QIcon(I('scheduler.png')), _('Schedule news download'), self)
        self.news_menu.addAction(self.scheduler_action)
        self.scheduler_action.triggered[bool].connect(self.show_dialog)
        self.cac = QAction(QIcon(I('user_profile.png')), _('Add or edit a custom news source'), self)
        self.cac.triggered[bool].connect(self.customize_feeds)
        self.news_menu.addAction(self.cac)
        self.news_menu.addSeparator()
        self.all_action = self.news_menu.addAction(
                _('Download all scheduled news sources'),
                self.download_all_scheduled)

        self.timer = QTimer(self)
        self.timer.start(int(self.INTERVAL * 60 * 1000))
        self.timer.timeout.connect(self.check)
        self.oldest = gconf['oldest_news']
        QTimer.singleShot(5 * 1000, self.oldest_check)
        if add_recipes:
            self.recipe_list.add_many(add_recipes)
        if replace_recipes:
            self.recipe_list.replace_many_by_title(replace_recipes)
        if failed_recipes:
            det_msg = '\n'.join('%s\n%s\n' % (title, tb)
                                for title, tb in failed_recipes.items())
            error_dialog(
                self,
                _('Failed to create recipes'),
                _('Failed to create some recipes, click "Show details" for details'
                  ),
                show=True,
                det_msg=det_msg)

    def switch_to_advanced(self):
        src = self.basic_recipe.recipe_source
        src = src.replace('AutomaticNewsRecipe', 'BasicNewsRecipe')
        src = src.replace('BasicUserRecipe', 'AdvancedUserRecipe')
        self.advanced_recipe.recipe_source = src
        self.stack.setCurrentIndex(2)


if __name__ == '__main__':
    from calibre.gui2 import Application
    from calibre.web.feeds.recipes.model import RecipeModel
    app = Application([])
    CustomRecipes(RecipeModel()).exec_()
    del app
Beispiel #3
0
    def populate_options(self, profile):
        self.oldest_article.setValue(profile.oldest_article)
        self.max_articles.setValue(profile.max_articles_per_feed)
        self.profile_title.setText(profile.title)
        self.added_feeds.clear()
        feeds = [] if profile.feeds is None else profile.feeds
        for title, url in feeds:
            self.added_feeds.add_item(title+' - '+url, (title, url))
        self.feed_title.setText('')
        self.feed_url.setText('')

    def clear(self):
        self.populate_options(AutomaticNewsRecipe)
        self.source_code.setText('')

    def reject(self):
        if question_dialog(self, _('Are you sure?'),
                _('You will lose any unsaved changes. To save your'
                    ' changes, click the Add/Update recipe button.'
                    ' Continue?'), show_copy_button=False):
            ResizableDialog.reject(self)

if __name__ == '__main__':
    from PyQt5.Qt import QApplication
    app = QApplication([])
    from calibre.web.feeds.recipes.model import RecipeModel
    d=UserProfiles(None, RecipeModel())
    d.exec_()
    del app

Beispiel #4
0
            return False
        self.internet_connection_failed = False
        if self.no_internet_dialog.isVisible():
            self.no_internet_dialog.hide()
        return True

    def download(self, urn):
        self.lock.lock()
        if not self.has_internet_connection():
            return False
        doit = urn not in self.download_queue
        self.lock.unlock()
        if doit:
            self.do_download(urn)
        return True

    def check(self):
        recipes = self.recipe_model.get_to_be_downloaded_recipes()
        for urn in recipes:
            if not self.download(urn):
                # No internet connection, we will try again in a minute
                break


if __name__ == '__main__':
    from calibre.gui2 import Application
    app = Application([])
    d = SchedulerDialog(RecipeModel())
    d.exec_()
    del app