home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2011 January / maximum-cd-2011-01.iso / DiscContents / calibre-0.7.26.msi / file_1158 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-10-31  |  3.4 KB  |  67 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. __license__ = 'GPL v3'
  5. __copyright__ = '2010, Kovid Goyal <kovid@kovidgoyal.net>'
  6. __docformat__ = 'restructuredtext en'
  7. import os
  8. import shutil
  9. from PyQt4.Qt import QModelIndex
  10. from calibre.gui2 import error_dialog, choose_dir
  11. from calibre.gui2.tools import generate_catalog
  12. from calibre.utils.config import dynamic
  13. from calibre.gui2.actions import InterfaceAction
  14.  
  15. class GenerateCatalogAction(InterfaceAction):
  16.     name = 'Generate Catalog'
  17.     action_spec = (_('Create catalog of books in your calibre library'), None, None, None)
  18.     dont_add_to = frozenset([
  19.         'toolbar-device',
  20.         'context-menu-device'])
  21.     
  22.     def generate_catalog(self):
  23.         rows = self.gui.library_view.selectionModel().selectedRows()
  24.         if not rows or len(rows) < 2:
  25.             rows = xrange(self.gui.library_view.model().rowCount(QModelIndex()))
  26.         
  27.         ids = map(self.gui.library_view.model().id, rows)
  28.         if not ids:
  29.             return error_dialog(self.gui, _('No books selected'), _('No books selected to generate catalog for'), show = True)
  30.         db = self.gui.library_view.model().db
  31.         dbspec = { }
  32.         for id in ids:
  33.             dbspec[id] = {
  34.                 'ondevice': db.ondevice(id, index_is_id = True) }
  35.         
  36.         ret = generate_catalog(self.gui, dbspec, ids, self.gui.device_manager)
  37.         if ret is None:
  38.             return None
  39.         (func, args, desc, out, sync, title) = ret
  40.         fmt = os.path.splitext(out)[1][1:].upper()
  41.         job = self.gui.job_manager.run_job(self.Dispatcher(self.catalog_generated), func, args = args, description = desc)
  42.         job.catalog_file_path = out
  43.         job.fmt = fmt
  44.         job.catalog_sync = sync
  45.         job.catalog_title = title
  46.         self.gui.status_bar.show_message(_('Generating %s catalog...') % fmt)
  47.  
  48.     
  49.     def catalog_generated(self, job):
  50.         if job.result:
  51.             return error_dialog(self.gui, _('No books found'), _('No books to catalog\nCheck exclude tags'), show = True)
  52.         if job.failed:
  53.             return self.gui.job_exception(job)
  54.         id = self.gui.library_view.model().add_catalog(job.catalog_file_path, job.catalog_title)
  55.         self.gui.library_view.model().reset()
  56.         self.gui.status_bar.show_message(_('Catalog generated.'), 3000)
  57.         self.gui.sync_catalogs()
  58.         if job.fmt not in ('EPUB', 'MOBI'):
  59.             export_dir = choose_dir(self.gui, _('Export Catalog Directory'), _('Select destination for %s.%s') % (job.catalog_title, job.fmt.lower()))
  60.             if export_dir:
  61.                 destination = os.path.join(export_dir, '%s.%s' % (job.catalog_title, job.fmt.lower()))
  62.                 shutil.copyfile(job.catalog_file_path, destination)
  63.             
  64.         
  65.  
  66.  
  67.