Adding of multiple recipes now goes lightning fast

This commit is contained in:
ingkebil 2014-04-04 00:05:15 +02:00
parent 73b613fac1
commit 43980872f2
2 changed files with 22 additions and 12 deletions

View File

@ -14,7 +14,6 @@ from calibre.gui2 import error_dialog, question_dialog, open_url, \
from calibre.gui2.widgets import PythonHighlighter from calibre.gui2.widgets import PythonHighlighter
from calibre.ptempfile import PersistentTemporaryFile from calibre.ptempfile import PersistentTemporaryFile
from calibre.utils.icu import sort_key from calibre.utils.icu import sort_key
from calibre.utils.opml import OPML
class CustomRecipeModel(QAbstractListModel): class CustomRecipeModel(QAbstractListModel):
@ -65,6 +64,10 @@ class CustomRecipeModel(QAbstractListModel):
self.recipe_model.add_custom_recipe(title, script) self.recipe_model.add_custom_recipe(title, script)
self.reset() self.reset()
def add_many(self, scriptmap):
self.recipe_model.add_custom_recipes(scriptmap)
self.reset()
def remove(self, rows): def remove(self, rows):
urns = [] urns = []
for r in rows: for r in rows:
@ -208,16 +211,15 @@ class UserProfiles(ResizableDialog, Ui_Dialog):
classname = 'BasicUserRecipe'+str(int(time.time())) classname = 'BasicUserRecipe'+str(int(time.time()))
if 'nr' in kw: if 'nr' in kw:
classname = classname + str(kw['nr']) classname = classname + str(kw['nr'])
title = kw['title'] if 'title' in kw else self.profile_title.text() title = kw.get('title', self.profile_title.text())
title = unicode(title).strip() title = unicode(title).strip()
if not title: if not title:
title = classname title = classname
self.profile_title.setText(title) self.profile_title.setText(title)
oldest_article = kw['oldest_article'] if 'oldest_article' in kw else self.oldest_article.value() oldest_article = kw.get('oldest_article', self.oldest_article.value())
max_articles = kw['max_articles'] if 'max_articles' in kw else self.max_articles.value() max_articles = kw.get('max_articles', self.max_articles.value())
feeds = kw['feeds'] \ feeds = kw.get('feeds', \
if 'feeds' in kw \ [i.user_data for i in self.added_feeds.items()])
else [i.user_data for i in self.added_feeds.items()]
src = '''\ src = '''\
class %(classname)s(%(base_class)s): class %(classname)s(%(base_class)s):
@ -355,6 +357,7 @@ class %(classname)s(%(base_class)s):
self.clear() self.clear()
def opml_import(self): def opml_import(self):
from calibre.utils.opml import OPML
opml_files = choose_files(self, 'OPML chooser dialog', opml_files = choose_files(self, 'OPML chooser dialog',
_('Select OPML file'), filters=[(_('OPML'), ['opml'])] ) _('Select OPML file'), filters=[(_('OPML'), ['opml'])] )
@ -363,6 +366,7 @@ class %(classname)s(%(base_class)s):
skip_dialog_name='replace_recipes' skip_dialog_name='replace_recipes'
opml = OPML(self.oldest_article.value(), self.max_articles.value()); opml = OPML(self.oldest_article.value(), self.max_articles.value());
scriptmap = {}
for opml_file in opml_files: for opml_file in opml_files:
opml.load(opml_file) opml.load(opml_file)
outlines = opml.parse() outlines = opml.parse()
@ -380,7 +384,8 @@ class %(classname)s(%(base_class)s):
compile_recipe(src) compile_recipe(src)
except Exception as err: except Exception as err:
error_dialog(self, _('Invalid input'), error_dialog(self, _('Invalid input'),
_('<p>Could not create recipe. Error:<br>%s')%str(err)).exec_() _('<p>Could not create recipe. Error:<br>%s')%str(err)).exec_()
continue
profile = src profile = src
if self._model.has_title(title): if self._model.has_title(title):
if question_dialog(self, _('Replace recipe?'), if question_dialog(self, _('Replace recipe?'),
@ -391,8 +396,10 @@ class %(classname)s(%(base_class)s):
): ):
self._model.replace_by_title(title, profile) self._model.replace_by_title(title, profile)
else: else:
self.model.add(title, profile) scriptmap.update({ title: profile })
nr+=1 nr+=1
if scriptmap:
self.model.add_many(scriptmap)
self.clear() self.clear()
# reset the question_dialog # reset the question_dialog

View File

@ -17,8 +17,8 @@ from calibre.utils.localization import get_language
from calibre.web.feeds.recipes.collection import \ from calibre.web.feeds.recipes.collection import \
get_builtin_recipe_collection, get_custom_recipe_collection, \ get_builtin_recipe_collection, get_custom_recipe_collection, \
SchedulerConfig, download_builtin_recipe, update_custom_recipe, \ SchedulerConfig, download_builtin_recipe, update_custom_recipe, \
add_custom_recipe, remove_custom_recipe, get_custom_recipe, \ add_custom_recipe, add_custom_recipes, remove_custom_recipe, \
get_builtin_recipe get_custom_recipe, get_builtin_recipe
from calibre.utils.search_query_parser import ParseException from calibre.utils.search_query_parser import ParseException
class NewsTreeItem(object): class NewsTreeItem(object):
@ -172,7 +172,10 @@ class RecipeModel(QAbstractItemModel, SearchQueryParser):
self.custom_recipe_collection = get_custom_recipe_collection() self.custom_recipe_collection = get_custom_recipe_collection()
def add_custom_recipe(self, title, script): def add_custom_recipe(self, title, script):
add_custom_recipe(title, script) self.add_custom_recipes({ title: script })
def add_custom_recipes(self, scriptmap):
add_custom_recipes(scriptmap)
self.custom_recipe_collection = get_custom_recipe_collection() self.custom_recipe_collection = get_custom_recipe_collection()
def remove_custom_recipes(self, urns): def remove_custom_recipes(self, urns):