From e5e2eae97fb06ad4e3777960d14d1a8ff697ce32 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 2 Aug 2013 07:21:27 +0530 Subject: [PATCH] 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) --- src/calibre/gui2/main.py | 5 +++-- src/calibre/gui2/ui.py | 11 ++++++----- src/calibre/linux.py | 6 +++--- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/calibre/gui2/main.py b/src/calibre/gui2/main.py index bcfc88d239..fc9c542b92 100644 --- a/src/calibre/gui2/main.py +++ b/src/calibre/gui2/main.py @@ -401,8 +401,9 @@ def communicate(opts, args): shutdown_other(t) else: if len(args) > 1: - args[1] = os.path.abspath(args[1]) - t.conn.send('launched:'+repr(args)) + args[1:] = [os.path.abspath(x) if os.path.exists(x) else x for x in args[1:]] + import json + t.conn.send('launched:'+json.dumps(args)) t.conn.close() raise SystemExit(0) diff --git a/src/calibre/gui2/ui.py b/src/calibre/gui2/ui.py index e2f02eb578..43740876ea 100644 --- a/src/calibre/gui2/ui.py +++ b/src/calibre/gui2/ui.py @@ -520,11 +520,12 @@ class Main(MainWindow, MainWindowMixin, DeviceMixin, EmailMixin, # {{{ except Empty: return if msg.startswith('launched:'): - argv = eval(msg[len('launched:'):]) - if len(argv) > 1: - path = os.path.abspath(argv[1]) - if os.access(path, os.R_OK): - self.iactions['Add Books'].add_filesystem_book(path) + import json + argv = json.loads(msg[len('launched:'):]) + if isinstance(argv, (list, tuple)) and len(argv) > 1: + files = [os.path.abspath(p) for p in argv[1:] if not os.path.isdir(p) and os.access(p, os.R_OK)] + if files: + self.iactions['Add Books'].add_filesystem_book(files) self.setWindowState(self.windowState() & ~Qt.WindowMinimized|Qt.WindowActive) self.show_windows() diff --git a/src/calibre/linux.py b/src/calibre/linux.py index 41af312c41..98d68816f3 100644 --- a/src/calibre/linux.py +++ b/src/calibre/linux.py @@ -833,7 +833,7 @@ Name=LRF Viewer GenericName=Viewer for LRF files Comment=Viewer for LRF files (SONY ebook format files) TryExec=lrfviewer -Exec=lrfviewer %F +Exec=lrfviewer %f Icon=calibre-viewer MimeType=application/x-sony-bbeb; Categories=Graphics;Viewer; @@ -847,7 +847,7 @@ Name=E-book Viewer GenericName=Viewer for E-books Comment=Viewer for E-books in all the major formats TryExec=ebook-viewer -Exec=ebook-viewer %F +Exec=ebook-viewer %f Icon=calibre-viewer Categories=Graphics;Viewer; ''' @@ -857,7 +857,7 @@ GUI = '''\ [Desktop Entry] Version=1.0 Type=Application -Name=calibre +Name=calibre %F GenericName=E-book library management Comment=E-book library management: Convert, view, share, catalogue all your e-books TryExec=calibre