|
15 | 15 | import wx |
16 | 16 | from slugify import slugify |
17 | 17 |
|
18 | | -from bookworm import app, config, ocr, paths, speech |
| 18 | +from bookworm import app, config, ocr, paths, qread, speech |
19 | 19 | from bookworm.commandline_handler import run_subcommand_in_a_new_process |
20 | 20 | from bookworm.concurrency import call_threaded, process_worker |
21 | 21 | from bookworm.document import READING_MODE_LABELS |
@@ -89,12 +89,23 @@ def create(self): |
89 | 89 | self.pinnedDocumentsMenu = wx.Menu() |
90 | 90 | # A submenu for recent documents |
91 | 91 | self.recentFilesMenu = wx.Menu() |
| 92 | + # a submenu to import books from external sources |
| 93 | + self.import_menu = wx.Menu() |
92 | 94 | # File menu |
93 | 95 | # Translators: the label of an item in the application menubar |
94 | 96 | self.Append(wx.ID_OPEN, _("Open...\tCtrl-O")) |
95 | 97 | # Translators: the label of an item in the application menubar |
96 | 98 | self.Append(wx.ID_NEW, _("New Window...\tCtrl-N")) |
97 | 99 | self.AppendSeparator() |
| 100 | + self.AppendSubMenu( |
| 101 | + self.import_menu, |
| 102 | + # translators, the label of an item in the application menubar |
| 103 | + _("i&mport"), |
| 104 | + # Translators: the help text of an item in the application menubar |
| 105 | + _("Import a book from an external resource") |
| 106 | + ) |
| 107 | + self.import_menu.Append(ImportMenuIds.qread, _("&Import QRD file")) |
| 108 | + self.AppendSeparator() |
98 | 109 | # Translators: the label of an item in the application menubar |
99 | 110 | self.Append( |
100 | 111 | BookRelatedMenuIds.pin_document, _("&Pin\tCtrl-P"), kind=wx.ITEM_CHECK |
@@ -163,6 +174,7 @@ def create(self): |
163 | 174 | # Bind event handlers |
164 | 175 | self.view.Bind(wx.EVT_MENU, self.onOpenEBook, id=wx.ID_OPEN) |
165 | 176 | self.view.Bind(wx.EVT_MENU, self.onNewWindow, id=wx.ID_NEW) |
| 177 | + self.view.Bind(wx.EVT_MENU, self.onImportQread, id=ImportMenuIds.qread) |
166 | 178 | self.view.Bind( |
167 | 179 | wx.EVT_MENU, self.onClearPinDocuments, id=self.clearPinnedDocumentsID |
168 | 180 | ) |
@@ -230,6 +242,29 @@ def onNewWindow(self, event): |
230 | 242 | args.append("--debug") |
231 | 243 | run_subcommand_in_a_new_process(args, hidden=False) |
232 | 244 |
|
| 245 | + def onImportQread(self, event): |
| 246 | + with wx.FileDialog( |
| 247 | + self.view, |
| 248 | + # translators: the title of a file dialog to import qrd files |
| 249 | + message = _("Import QRD file"), |
| 250 | + style=wx.FD_OPEN | wx.FD_FILE_MUST_EXIST, |
| 251 | + wildcard=("*.qrd") |
| 252 | + ) as dlg: |
| 253 | + if dlg.ShowModal() != wx.ID_OK: |
| 254 | + return |
| 255 | + |
| 256 | + qrd_path = dlg.GetPath() |
| 257 | + book_info = qread.get_book_info(qrd_path) |
| 258 | + if not book_info: |
| 259 | + return self.view.notify_user( |
| 260 | + _("Failed to import QRD file"), |
| 261 | + _("The QRD file could not be imported"), |
| 262 | + icon=wx.ICON_ERROR |
| 263 | + ) |
| 264 | + uri = DocumentUri.from_filename(book_info.original_path) |
| 265 | + uri.openner_args = {"position": book_info.current_position} |
| 266 | + return self.view.open_uri(uri) |
| 267 | + |
233 | 268 | def onClearPinDocuments(self, event): |
234 | 269 | recents_manager.clear_pinned() |
235 | 270 | self.populate_pinned_documents_list() |
|
0 commit comments