mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-07 10:14:46 -04:00
IGN:Add option to automatically delete old news
This commit is contained in:
parent
07fed161e5
commit
1c48356c96
@ -52,7 +52,7 @@ def _config():
|
|||||||
c.add_opt('column_map', default=ALL_COLUMNS,
|
c.add_opt('column_map', default=ALL_COLUMNS,
|
||||||
help=_('Columns to be displayed in the book list'))
|
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('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)
|
return ConfigProxy(c)
|
||||||
|
|
||||||
config = _config()
|
config = _config()
|
||||||
|
@ -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.web.feeds.recipes import recipes, recipe_modules, compile_recipe
|
||||||
from calibre.utils.search_query_parser import SearchQueryParser
|
from calibre.utils.search_query_parser import SearchQueryParser
|
||||||
from calibre.utils.pyparsing import ParseException
|
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.utils.config import DynamicConfig
|
||||||
from calibre.gui2.dialogs.user_profiles import UserProfiles
|
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._model, SIGNAL('modelReset()'), lambda : self.detail_box.setVisible(False))
|
||||||
self.connect(self.download, SIGNAL('clicked()'), self.download_now)
|
self.connect(self.download, SIGNAL('clicked()'), self.download_now)
|
||||||
self.search.setFocus(Qt.OtherFocusReason)
|
self.search.setFocus(Qt.OtherFocusReason)
|
||||||
|
self.old_news.setValue(gconf['oldest_news'])
|
||||||
|
|
||||||
def download_now(self):
|
def download_now(self):
|
||||||
recipe = self._model.data(self.recipes.currentIndex(), Qt.UserRole)
|
recipe = self._model.data(self.recipes.currentIndex(), Qt.UserRole)
|
||||||
@ -308,6 +309,11 @@ class Scheduler(QObject):
|
|||||||
self.dirtied = False
|
self.dirtied = False
|
||||||
self.connect(self.timer, SIGNAL('timeout()'), self.check)
|
self.connect(self.timer, SIGNAL('timeout()'), self.check)
|
||||||
self.timer.start(int(self.INTERVAL * 60000))
|
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_menu = QMenu()
|
||||||
self.news_icon = QIcon(':/images/news.svg')
|
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.connect(self.cac, SIGNAL('triggered(bool)'), self.customize_feeds)
|
||||||
self.news_menu.addAction(self.cac)
|
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):
|
def customize_feeds(self, *args):
|
||||||
main = self.main
|
main = self.main
|
||||||
d = UserProfiles(main, main.library_view.model().db.get_feeds())
|
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('new_schedule(PyQt_PyObject)'), self.refresh_schedule)
|
||||||
self.connect(d, SIGNAL('download_now(PyQt_PyObject)'), self.download)
|
self.connect(d, SIGNAL('download_now(PyQt_PyObject)'), self.download)
|
||||||
d.exec_()
|
d.exec_()
|
||||||
|
gconf['oldest_news'] = d.old_news.value()
|
||||||
self.recipes = load_recipes()
|
self.recipes = load_recipes()
|
||||||
|
self.oldest = d.old_news.value()
|
||||||
finally:
|
finally:
|
||||||
self.lock.unlock()
|
self.lock.unlock()
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
<normaloff>:/images/scheduler.svg</normaloff>:/images/scheduler.svg</iconset>
|
<normaloff>:/images/scheduler.svg</normaloff>:/images/scheduler.svg</iconset>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QGridLayout" name="gridLayout" >
|
<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" >
|
<widget class="QGroupBox" name="recipe_box" >
|
||||||
<property name="title" >
|
<property name="title" >
|
||||||
<string>Recipes</string>
|
<string>Recipes</string>
|
||||||
@ -164,7 +164,7 @@
|
|||||||
<item>
|
<item>
|
||||||
<widget class="QLabel" name="last_downloaded" >
|
<widget class="QLabel" name="last_downloaded" >
|
||||||
<property name="text" >
|
<property name="text" >
|
||||||
<string> </string>
|
<string/>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
@ -262,7 +262,7 @@
|
|||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="1" >
|
<item row="2" column="1" >
|
||||||
<widget class="QDialogButtonBox" name="buttonBox" >
|
<widget class="QDialogButtonBox" name="buttonBox" >
|
||||||
<property name="orientation" >
|
<property name="orientation" >
|
||||||
<enum>Qt::Horizontal</enum>
|
<enum>Qt::Horizontal</enum>
|
||||||
@ -272,6 +272,22 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</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>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
<resources>
|
<resources>
|
||||||
|
@ -189,6 +189,19 @@ class BooksModel(QAbstractTableModel):
|
|||||||
self.clear_caches()
|
self.clear_caches()
|
||||||
self.reset()
|
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):
|
def books_added(self, num):
|
||||||
if num > 0:
|
if num > 0:
|
||||||
self.beginInsertRows(QModelIndex(), 0, num-1)
|
self.beginInsertRows(QModelIndex(), 0, num-1)
|
||||||
|
@ -749,6 +749,18 @@ class LibraryDatabase2(LibraryDatabase):
|
|||||||
return categories
|
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):
|
def set(self, row, column, val):
|
||||||
'''
|
'''
|
||||||
Convenience method for setting the title, authors, publisher or rating
|
Convenience method for setting the title, authors, publisher or rating
|
||||||
|
Loading…
x
Reference in New Issue
Block a user