Allow adding multiple books to running calibre

Allow adding multiple books to an already running calibre by passing
multiple file arguments to calibre.exe. Also change the .desktop file in
linux to indicate calibre can accept file arguments. Fixes #1207518 [Calibre is invisible in Ubuntu 13.04 "Open with" dialog](https://bugs.launchpad.net/calibre/+bug/1207518)
This commit is contained in:
Kovid Goyal 2013-08-02 07:21:27 +05:30
parent 8352b43e28
commit e5e2eae97f
3 changed files with 12 additions and 10 deletions

View File

@ -401,8 +401,9 @@ def communicate(opts, args):
shutdown_other(t) shutdown_other(t)
else: else:
if len(args) > 1: if len(args) > 1:
args[1] = os.path.abspath(args[1]) args[1:] = [os.path.abspath(x) if os.path.exists(x) else x for x in args[1:]]
t.conn.send('launched:'+repr(args)) import json
t.conn.send('launched:'+json.dumps(args))
t.conn.close() t.conn.close()
raise SystemExit(0) raise SystemExit(0)

View File

@ -520,11 +520,12 @@ class Main(MainWindow, MainWindowMixin, DeviceMixin, EmailMixin, # {{{
except Empty: except Empty:
return return
if msg.startswith('launched:'): if msg.startswith('launched:'):
argv = eval(msg[len('launched:'):]) import json
if len(argv) > 1: argv = json.loads(msg[len('launched:'):])
path = os.path.abspath(argv[1]) if isinstance(argv, (list, tuple)) and len(argv) > 1:
if os.access(path, os.R_OK): files = [os.path.abspath(p) for p in argv[1:] if not os.path.isdir(p) and os.access(p, os.R_OK)]
self.iactions['Add Books'].add_filesystem_book(path) if files:
self.iactions['Add Books'].add_filesystem_book(files)
self.setWindowState(self.windowState() & self.setWindowState(self.windowState() &
~Qt.WindowMinimized|Qt.WindowActive) ~Qt.WindowMinimized|Qt.WindowActive)
self.show_windows() self.show_windows()

View File

@ -833,7 +833,7 @@ Name=LRF Viewer
GenericName=Viewer for LRF files GenericName=Viewer for LRF files
Comment=Viewer for LRF files (SONY ebook format files) Comment=Viewer for LRF files (SONY ebook format files)
TryExec=lrfviewer TryExec=lrfviewer
Exec=lrfviewer %F Exec=lrfviewer %f
Icon=calibre-viewer Icon=calibre-viewer
MimeType=application/x-sony-bbeb; MimeType=application/x-sony-bbeb;
Categories=Graphics;Viewer; Categories=Graphics;Viewer;
@ -847,7 +847,7 @@ Name=E-book Viewer
GenericName=Viewer for E-books GenericName=Viewer for E-books
Comment=Viewer for E-books in all the major formats Comment=Viewer for E-books in all the major formats
TryExec=ebook-viewer TryExec=ebook-viewer
Exec=ebook-viewer %F Exec=ebook-viewer %f
Icon=calibre-viewer Icon=calibre-viewer
Categories=Graphics;Viewer; Categories=Graphics;Viewer;
''' '''
@ -857,7 +857,7 @@ GUI = '''\
[Desktop Entry] [Desktop Entry]
Version=1.0 Version=1.0
Type=Application Type=Application
Name=calibre Name=calibre %F
GenericName=E-book library management GenericName=E-book library management
Comment=E-book library management: Convert, view, share, catalogue all your e-books Comment=E-book library management: Convert, view, share, catalogue all your e-books
TryExec=calibre TryExec=calibre