11
11
from PyQt4.Qt import QAbstractItemModel, QVariant, Qt, QColor, QFont, QIcon, \
12
QModelIndex, QMetaObject, pyqtSlot, pyqtSignal
12
QModelIndex, pyqtSignal
14
14
from calibre.utils.search_query_parser import SearchQueryParser
15
15
from calibre.gui2 import NONE
16
16
from calibre.utils.localization import get_language
17
17
from calibre.web.feeds.recipes.collection import \
18
18
get_builtin_recipe_collection, get_custom_recipe_collection, \
19
SchedulerConfig, download_builtin_recipe
19
SchedulerConfig, download_builtin_recipe, update_custom_recipe, \
20
add_custom_recipe, remove_custom_recipe, get_custom_recipe
20
21
from calibre.utils.pyparsing import ParseException
22
23
class NewsTreeItem(object):
122
123
LOCATIONS = ['all']
123
124
searched = pyqtSignal(object)
125
def __init__(self, db, *args):
126
def __init__(self, *args):
126
127
QAbstractItemModel.__init__(self, *args)
127
128
SearchQueryParser.__init__(self, locations=['all'])
129
129
self.default_icon = QVariant(QIcon(I('news.png')))
130
130
self.custom_icon = QVariant(QIcon(I('user_profile.png')))
131
131
self.builtin_recipe_collection = get_builtin_recipe_collection()
132
132
self.scheduler_config = SchedulerConfig()
133
133
self.do_refresh()
136
def do_database_change(self):
141
def database_changed(self, db):
143
QMetaObject.invokeMethod(self, 'do_database_change', Qt.QueuedConnection)
145
135
def get_builtin_recipe(self, urn, download=True):
158
148
if recipe.get('id', False) == urn:
159
149
if coll is self.builtin_recipe_collection:
160
150
return self.get_builtin_recipe(urn[8:], download=download)
161
return self.db.get_feed(int(urn[len('custom:'):]))
151
return get_custom_recipe(int(urn[len('custom:'):]))
163
153
def update_custom_recipe(self, urn, title, script):
164
self.db.update_feed(int(urn[len('custom:'):]), script, title)
165
self.custom_recipe_collection = get_custom_recipe_collection(self.db)
154
id_ = int(urn[len('custom:'):])
155
update_custom_recipe(id_, title, script)
156
self.custom_recipe_collection = get_custom_recipe_collection()
167
158
def add_custom_recipe(self, title, script):
168
self.db.add_feed(title, script)
169
self.custom_recipe_collection = get_custom_recipe_collection(self.db)
159
add_custom_recipe(title, script)
160
self.custom_recipe_collection = get_custom_recipe_collection()
171
162
def remove_custom_recipes(self, urns):
172
163
ids = [int(x[len('custom:'):]) for x in urns]
173
self.db.remove_feeds(ids)
174
self.custom_recipe_collection = get_custom_recipe_collection(self.db)
164
for id_ in ids: remove_custom_recipe(id_)
165
self.custom_recipe_collection = get_custom_recipe_collection()
176
167
def do_refresh(self, restrict_to_urns=set([])):
177
self.custom_recipe_collection = get_custom_recipe_collection(self.db)
168
self.custom_recipe_collection = get_custom_recipe_collection()
179
170
def factory(cls, parent, *args):
180
171
args = list(args)
211
203
lang_map[lang] = factory(NewsCategory, new_root, lang)
212
204
factory(NewsItem, lang_map[lang], urn, x.get('title'))
213
205
self.showing_count += 1
206
self.builtin_count += 1
214
207
for x in self.scheduler_config.iter_recipes():
215
208
urn = x.get('id')
216
209
if urn not in self.all_urns:
354
347
self.scheduler_config.schedule_recipe(self.recipe_from_urn(urn),
355
348
sched_type, schedule)
357
def customize_recipe(self, urn, add_title_tag, custom_tags):
350
def customize_recipe(self, urn, add_title_tag, custom_tags, keep_issues):
358
351
self.scheduler_config.customize_recipe(urn, add_title_tag,
352
custom_tags, keep_issues)
361
354
def get_to_be_downloaded_recipes(self):
362
355
ans = self.scheduler_config.get_to_be_downloaded_recipes()