IGN:Add option to automatically delete old news

This commit is contained in:
Kovid Goyal 2008-11-21 16:46:04 -08:00
parent 07fed161e5
commit 1c48356c96
5 changed files with 61 additions and 5 deletions

View File

@ -52,7 +52,7 @@ def _config():
c.add_opt('column_map', default=ALL_COLUMNS,
help=_('Columns to be displayed in the book list'))
c.add_opt('autolaunch_server', default=False, help=_('Automatically launch content server on application startup'))
c.add_opt('oldest_news', default=60, help=_('Oldest news kept in database'))
return ConfigProxy(c)
config = _config()

View File

@ -18,7 +18,7 @@ from calibre.gui2.dialogs.scheduler_ui import Ui_Dialog
from calibre.web.feeds.recipes import recipes, recipe_modules, compile_recipe
from calibre.utils.search_query_parser import SearchQueryParser
from calibre.utils.pyparsing import ParseException
from calibre.gui2 import NONE, error_dialog
from calibre.gui2 import NONE, error_dialog, config as gconf
from calibre.utils.config import DynamicConfig
from calibre.gui2.dialogs.user_profiles import UserProfiles
@ -227,6 +227,7 @@ class SchedulerDialog(QDialog, Ui_Dialog):
self.connect(self._model, SIGNAL('modelReset()'), lambda : self.detail_box.setVisible(False))
self.connect(self.download, SIGNAL('clicked()'), self.download_now)
self.search.setFocus(Qt.OtherFocusReason)
self.old_news.setValue(gconf['oldest_news'])
def download_now(self):
recipe = self._model.data(self.recipes.currentIndex(), Qt.UserRole)
@ -308,6 +309,11 @@ class Scheduler(QObject):
self.dirtied = False
self.connect(self.timer, SIGNAL('timeout()'), self.check)
self.timer.start(int(self.INTERVAL * 60000))
self.oldest_timer = QTimer()
self.connect(self.oldest_timer, SIGNAL('timeout()'), self.oldest_check)
self.oldest = gconf['oldest_news']
self.oldest_timer.start(int(60 * 60000))
self.oldest_check()
self.news_menu = QMenu()
self.news_icon = QIcon(':/images/news.svg')
@ -318,6 +324,13 @@ class Scheduler(QObject):
self.connect(self.cac, SIGNAL('triggered(bool)'), self.customize_feeds)
self.news_menu.addAction(self.cac)
def oldest_check(self):
if self.oldest > 0:
delta = timedelta(days=self.oldest)
ids = self.main.library_view.model().db.tags_older_than(_('News'), delta)
if ids:
self.main.library_view.model().delete_books_by_id(ids)
def customize_feeds(self, *args):
main = self.main
d = UserProfiles(main, main.library_view.model().db.get_feeds())
@ -412,7 +425,9 @@ class Scheduler(QObject):
self.connect(d, SIGNAL('new_schedule(PyQt_PyObject)'), self.refresh_schedule)
self.connect(d, SIGNAL('download_now(PyQt_PyObject)'), self.download)
d.exec_()
gconf['oldest_news'] = d.old_news.value()
self.recipes = load_recipes()
self.oldest = d.old_news.value()
finally:
self.lock.unlock()

View File

@ -17,7 +17,7 @@
<normaloff>:/images/scheduler.svg</normaloff>:/images/scheduler.svg</iconset>
</property>
<layout class="QGridLayout" name="gridLayout" >
<item rowspan="2" row="0" column="0" >
<item rowspan="3" row="0" column="0" >
<widget class="QGroupBox" name="recipe_box" >
<property name="title" >
<string>Recipes</string>
@ -164,7 +164,7 @@
<item>
<widget class="QLabel" name="last_downloaded" >
<property name="text" >
<string> </string>
<string/>
</property>
</widget>
</item>
@ -262,7 +262,7 @@
</item>
</layout>
</item>
<item row="1" column="1" >
<item row="2" column="1" >
<widget class="QDialogButtonBox" name="buttonBox" >
<property name="orientation" >
<enum>Qt::Horizontal</enum>
@ -272,6 +272,22 @@
</property>
</widget>
</item>
<item row="1" column="1" >
<widget class="QSpinBox" name="old_news" >
<property name="toolTip" >
<string>Delete downloaded news older than the specified number of days. Set to zero to disable.</string>
</property>
<property name="suffix" >
<string> days</string>
</property>
<property name="prefix" >
<string>Delete downloaded news older than </string>
</property>
<property name="maximum" >
<number>1000</number>
</property>
</widget>
</item>
</layout>
</widget>
<resources>

View File

@ -188,6 +188,19 @@ class BooksModel(QAbstractTableModel):
self.endRemoveRows()
self.clear_caches()
self.reset()
def delete_books_by_id(self, ids):
for id in ids:
try:
row = self.db.row(id)
except:
row = -1
if row > -1:
self.beginRemoveRows(QModelIndex(), row, row)
self.db.delete_book(id)
if row > -1:
self.endRemoveRows()
self.clear_caches()
def books_added(self, num):
if num > 0:

View File

@ -749,6 +749,18 @@ class LibraryDatabase2(LibraryDatabase):
return categories
def tags_older_than(self, tag, delta):
tag = tag.lower().strip()
now = datetime.now()
for r in self.data._data:
if r is not None:
if (now - r[FIELD_MAP['timestamp']]) > delta:
tags = r[FIELD_MAP['tags']]
if tags and tag in tags.lower():
yield r[FIELD_MAP['id']]
def set(self, row, column, val):
'''
Convenience method for setting the title, authors, publisher or rating