diff --git a/src/calibre/gui2/dialogs/user_profiles.py b/src/calibre/gui2/dialogs/user_profiles.py index 7ca2f95bd4..45ed14427a 100644 --- a/src/calibre/gui2/dialogs/user_profiles.py +++ b/src/calibre/gui2/dialogs/user_profiles.py @@ -14,7 +14,6 @@ from calibre.gui2 import error_dialog, question_dialog, open_url, \ from calibre.gui2.widgets import PythonHighlighter from calibre.ptempfile import PersistentTemporaryFile from calibre.utils.icu import sort_key -from calibre.utils.opml import OPML class CustomRecipeModel(QAbstractListModel): @@ -65,6 +64,10 @@ class CustomRecipeModel(QAbstractListModel): self.recipe_model.add_custom_recipe(title, script) self.reset() + def add_many(self, scriptmap): + self.recipe_model.add_custom_recipes(scriptmap) + self.reset() + def remove(self, rows): urns = [] for r in rows: @@ -208,16 +211,15 @@ class UserProfiles(ResizableDialog, Ui_Dialog): classname = 'BasicUserRecipe'+str(int(time.time())) if 'nr' in kw: 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() if not title: title = classname self.profile_title.setText(title) - oldest_article = kw['oldest_article'] if 'oldest_article' in kw else self.oldest_article.value() - max_articles = kw['max_articles'] if 'max_articles' in kw else self.max_articles.value() - feeds = kw['feeds'] \ - if 'feeds' in kw \ - else [i.user_data for i in self.added_feeds.items()] + oldest_article = kw.get('oldest_article', self.oldest_article.value()) + max_articles = kw.get('max_articles', self.max_articles.value()) + feeds = kw.get('feeds', \ + [i.user_data for i in self.added_feeds.items()]) src = '''\ class %(classname)s(%(base_class)s): @@ -355,6 +357,7 @@ class %(classname)s(%(base_class)s): self.clear() def opml_import(self): + from calibre.utils.opml import OPML opml_files = choose_files(self, 'OPML chooser dialog', _('Select OPML file'), filters=[(_('OPML'), ['opml'])] ) @@ -363,6 +366,7 @@ class %(classname)s(%(base_class)s): skip_dialog_name='replace_recipes' opml = OPML(self.oldest_article.value(), self.max_articles.value()); + scriptmap = {} for opml_file in opml_files: opml.load(opml_file) outlines = opml.parse() @@ -380,7 +384,8 @@ class %(classname)s(%(base_class)s): compile_recipe(src) except Exception as err: error_dialog(self, _('Invalid input'), - _('
Could not create recipe. Error:
%s')%str(err)).exec_()
+ _('
Could not create recipe. Error:
%s')%str(err)).exec_()
+ continue
profile = src
if self._model.has_title(title):
if question_dialog(self, _('Replace recipe?'),
@@ -391,8 +396,10 @@ class %(classname)s(%(base_class)s):
):
self._model.replace_by_title(title, profile)
else:
- self.model.add(title, profile)
+ scriptmap.update({ title: profile })
nr+=1
+ if scriptmap:
+ self.model.add_many(scriptmap)
self.clear()
# reset the question_dialog
diff --git a/src/calibre/web/feeds/recipes/model.py b/src/calibre/web/feeds/recipes/model.py
index b5c123bd4f..327e04e09d 100644
--- a/src/calibre/web/feeds/recipes/model.py
+++ b/src/calibre/web/feeds/recipes/model.py
@@ -17,8 +17,8 @@ from calibre.utils.localization import get_language
from calibre.web.feeds.recipes.collection import \
get_builtin_recipe_collection, get_custom_recipe_collection, \
SchedulerConfig, download_builtin_recipe, update_custom_recipe, \
- add_custom_recipe, remove_custom_recipe, get_custom_recipe, \
- get_builtin_recipe
+ add_custom_recipe, add_custom_recipes, remove_custom_recipe, \
+ get_custom_recipe, get_builtin_recipe
from calibre.utils.search_query_parser import ParseException
class NewsTreeItem(object):
@@ -172,7 +172,10 @@ class RecipeModel(QAbstractItemModel, SearchQueryParser):
self.custom_recipe_collection = get_custom_recipe_collection()
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()
def remove_custom_recipes(self, urns):