~stub/ubuntu/precise/calibre/devel

« back to all changes in this revision

Viewing changes to src/calibre/web/feeds/recipes/model.py

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2011-04-12 11:29:25 UTC
  • mfrom: (42.1.2 sid)
  • Revision ID: james.westby@ubuntu.com-20110412112925-c7171kt2bb5rmft4
Tags: 0.7.50+dfsg-2
* debian/control: Build with libpodofo-dev to enable PDF metadata.
  (Closes: #619632)
* debian/control: Add libboost1.42-dev build dependency. Apparently it is
  needed in some setups. (Closes: #619807)
* debian/rules: Call dh_sip to generate a proper sip API dependency, to
  prevent crashes like #616372 for partial upgrades.
* debian/control: Bump python-qt4 dependency to >= 4.8.3-2, which reportedly
  fixes crashes on startup. (Closes: #619701, #620125)

Show diffs side-by-side

added added

removed removed

Lines of Context:
9
9
import os, copy
10
10
 
11
11
from PyQt4.Qt import QAbstractItemModel, QVariant, Qt, QColor, QFont, QIcon, \
12
 
        QModelIndex, QMetaObject, pyqtSlot, pyqtSignal
 
12
        QModelIndex, pyqtSignal
13
13
 
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
21
22
 
22
23
class NewsTreeItem(object):
122
123
    LOCATIONS = ['all']
123
124
    searched = pyqtSignal(object)
124
125
 
125
 
    def __init__(self, db, *args):
 
126
    def __init__(self, *args):
126
127
        QAbstractItemModel.__init__(self, *args)
127
128
        SearchQueryParser.__init__(self, locations=['all'])
128
 
        self.db = db
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()
134
134
 
135
 
    @pyqtSlot()
136
 
    def do_database_change(self):
137
 
        self.db = self.newdb
138
 
        self.newdb = None
139
 
        self.do_refresh()
140
 
 
141
 
    def database_changed(self, db):
142
 
        self.newdb = db
143
 
        QMetaObject.invokeMethod(self, 'do_database_change', Qt.QueuedConnection)
144
 
 
145
135
    def get_builtin_recipe(self, urn, download=True):
146
136
        if download:
147
137
            try:
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:'):]))
162
152
 
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()
166
157
 
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()
170
161
 
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()
175
166
 
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()
178
169
 
179
170
        def factory(cls, parent, *args):
180
171
            args = list(args)
196
187
        lang_map = {}
197
188
        self.all_urns = set([])
198
189
        self.showing_count = 0
 
190
        self.builtin_count = 0
199
191
        for x in self.custom_recipe_collection:
200
192
            urn = x.get('id')
201
193
            self.all_urns.add(urn)
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)
356
349
 
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,
359
 
                custom_tags)
 
352
                custom_tags, keep_issues)
360
353
 
361
354
    def get_to_be_downloaded_recipes(self):
362
355
        ans = self.scheduler_config.get_to_be_downloaded_recipes()