Integrate feeds2lrf into the GUI.

This commit is contained in:
Kovid Goyal 2008-03-18 04:01:44 +00:00
parent 92dc588f80
commit f7ba58fa36
4 changed files with 29 additions and 33 deletions

View File

@ -616,18 +616,18 @@ class Main(MainWindow, Ui_MainWindow):
self.news_menu.set_custom_feeds(feeds)
def fetch_news(self, data):
pt = PersistentTemporaryFile(suffix='.lrf')
pt = PersistentTemporaryFile(suffix='_feeds2lrf.lrf')
pt.close()
args = ['web2lrf', '-o', pt.name]
args = ['feeds2lrf', '--output', pt.name, '--debug']
if data['username']:
args.extend(['--username', data['username']])
if data['password']:
args.extend(['--password', data['password']])
args.append(data['profile'])
id = self.job_manager.run_conversion_job(self.news_fetched, 'web2lrf', args=[args],
job_description='Fetch news from '+data['title'])
args.append(data['title'])
id = self.job_manager.run_conversion_job(self.news_fetched, 'feeds2lrf', args=[args],
job_description=_('Fetch news from ')+data['title'])
self.conversion_jobs[id] = (pt, 'lrf')
self.status_bar.showMessage('Fetching news from '+data['title'], 2000)
self.status_bar.showMessage(_('Fetching news from ')+data['title'], 2000)
def news_fetched(self, id, description, result, exception, formatted_traceback, log):
pt, fmt = self.conversion_jobs.pop(id)
@ -637,7 +637,7 @@ class Main(MainWindow, Ui_MainWindow):
to_device = self.device_connected and fmt in self.device_manager.device_class.FORMATS
self._add_books([pt.name], to_device)
if to_device:
self.status_bar.showMessage('News fetched. Uploading to device.', 2000)
self.status_bar.showMessage(_('News fetched. Uploading to device.'), 2000)
self.persistent_files.append(pt)
############################################################################

View File

@ -16,26 +16,25 @@ from PyQt4.QtCore import QObject, SIGNAL, QFile
from PyQt4.QtGui import QMenu, QIcon, QDialog, QAction
from libprs500.gui2.dialogs.password import PasswordDialog
from libprs500.ebooks.lrf.web import builtin_profiles, available_profiles
from libprs500.ebooks.lrf.web.profiles import create_class
from libprs500.web.feeds.recipes import titles, get_builtin_recipe
class NewsAction(QAction):
def __init__(self, profile, module, parent):
self.profile = profile
self.module = module
if QFile(':/images/news/'+module+'.png').exists():
ic = QIcon(':/images/news/'+module+'.png')
def __init__(self, recipe, parent):
self.recipe = recipe
self.module = recipe.__module__.rpartition('.')[-1]
if QFile(':/images/news/'+self.module+'.png').exists():
ic = QIcon(':/images/news/'+self.module+'.png')
else:
ic = QIcon(':/images/news.svg')
QAction.__init__(self, ic, profile.title, parent)
QAction.__init__(self, ic, recipe.title, parent)
QObject.connect(self, SIGNAL('triggered(bool)'), self.fetch_news)
QObject.connect(self, SIGNAL('start_news_fetch(PyQt_PyObject, PyQt_PyObject)'),
parent.fetch_news)
def fetch_news(self, checked):
self.emit(SIGNAL('start_news_fetch(PyQt_PyObject, PyQt_PyObject)'),
self.profile, self.module)
self.recipe, self.module)
class NewsMenu(QMenu):
@ -50,28 +49,26 @@ class NewsMenu(QMenu):
self.connect(self.custom_menu, SIGNAL('start_news_fetch(PyQt_PyObject, PyQt_PyObject)'),
self.fetch_news)
self.addSeparator()
for profile, module in zip(builtin_profiles, available_profiles):
self.addAction(NewsAction(profile, module, self))
for title in titles:
recipe = get_builtin_recipe(title)[0]
self.addAction(NewsAction(recipe, self))
def fetch_news(self, profile, module=None):
if module is None:
module = profile.title
def fetch_news(self, recipe, module):
username = password = None
fetch = True
if isinstance(profile, basestring):
module = profile
profile = create_class(module)
if profile.needs_subscription:
if recipe.needs_subscription:
d = PasswordDialog(self, module + ' info dialog',
'<p>Please enter your username and password for %s<br>If you do not have one, please subscribe to get access to the articles.<br/> Click OK to proceed.'%(profile.title,))
_('<p>Please enter your username and password for %s<br>If you do not have one, please subscribe to get access to the articles.<br/> Click OK to proceed.')%(recipe.title,))
d.exec_()
if d.result() == QDialog.Accepted:
username, password = d.username(), d.password()
else:
fetch = False
if fetch:
data = dict(profile=module, title=profile.title, username=username, password=password)
data = dict(title=recipe.title, username=username, password=password)
self.emit(SIGNAL('fetch_news(PyQt_PyObject)'), data)
def set_custom_feeds(self, feeds):
@ -101,6 +98,3 @@ class CustomNewsMenu(QMenu):
self.clear()
for title, src in feeds:
self.addAction(CustomNewMenuItem(title, src, self))

View File

@ -21,6 +21,7 @@ from functools import partial
from libprs500.ebooks.lrf.any.convert_from import main as any2lrf
from libprs500.ebooks.lrf.web.convert_from import main as web2lrf
from libprs500.ebooks.lrf.feeds.convert_from import main as feeds2lrf
from libprs500.gui2.lrf_renderer.main import main as lrfviewer
from libprs500 import iswindows, __appname__
@ -28,6 +29,7 @@ PARALLEL_FUNCS = {
'any2lrf' : partial(any2lrf, gui_mode=True),
'web2lrf' : web2lrf,
'lrfviewer' : lrfviewer,
'feeds2lrf' : feeds2lrf,
}
python = sys.executable

View File

@ -138,12 +138,12 @@ def run_recipe(opts, recipe_arg, parser, notification=None, handler=None):
def main(args=sys.argv, notification=None, handler=None):
p = option_parser()
opts, args = p.parse_args(args)
opts, args = p.parse_args(args=args[1:])
if len(args) != 2 and opts.feeds is None:
if len(args) != 1 and opts.feeds is None:
p.print_help()
return 1
recipe_arg = args[1] if len(args) > 1 else None
recipe_arg = args[0] if len(args) > 0 else None
run_recipe(opts, recipe_arg, p, notification=notification, handler=handler)
return 0