home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 November / maximum-cd-2010-11.iso / DiscContents / calibre-0.7.13.msi / file_1231 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-08-06  |  3.7 KB  |  82 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. from PyQt4.Qt import QDialog
  9. from calibre.gui2.dialogs.choose_library_ui import Ui_Dialog
  10. from calibre.gui2 import error_dialog, choose_dir
  11. from calibre.constants import filesystem_encoding
  12. from calibre import isbytestring, patheq
  13. from calibre.utils.config import prefs
  14. from calibre.gui2.wizard import move_library
  15.  
  16. class ChooseLibrary(QDialog, Ui_Dialog):
  17.     
  18.     def __init__(self, db, callback, parent):
  19.         QDialog.__init__(self, parent)
  20.         self.setupUi(self)
  21.         self.db = db
  22.         self.new_db = None
  23.         self.callback = callback
  24.         self.location.initialize('choose_library_dialog')
  25.         lp = db.library_path
  26.         if isbytestring(lp):
  27.             lp = lp.decode(filesystem_encoding)
  28.         
  29.         loc = unicode(self.old_location.text()).format(lp)
  30.         self.old_location.setText(loc)
  31.         self.browse_button.clicked.connect(self.choose_loc)
  32.  
  33.     
  34.     def choose_loc(self, *args):
  35.         loc = choose_dir(self, 'choose library location', _('Choose location for calibre library'))
  36.         if loc is not None:
  37.             self.location.setText(loc)
  38.         
  39.  
  40.     
  41.     def check_action(self, ac, loc):
  42.         exists = self.db.exists_at(loc)
  43.         if patheq(loc, self.db.library_path):
  44.             error_dialog(self, _('Same as current'), _('The location %s contains the current calibre library') % loc, show = True)
  45.             return False
  46.         empty = not os.listdir(loc)
  47.         if ac == 'existing' and not exists:
  48.             error_dialog(self, _('No existing library found'), _('There is no existing calibre library at %s') % loc, show = True)
  49.             return False
  50.         if ac in ('new', 'move') and not empty:
  51.             error_dialog(self, _('Not empty'), _('The folder %s is not empty. Please choose an empty folder') % loc, show = True)
  52.             return False
  53.         return True
  54.  
  55.     
  56.     def perform_action(self, ac, loc):
  57.         if ac in ('new', 'existing'):
  58.             prefs['library_path'] = loc
  59.             self.callback(loc)
  60.         else:
  61.             move_library(self.db.library_path, loc, self.parent(), self.callback)
  62.  
  63.     
  64.     def accept(self):
  65.         action = 'move'
  66.         if self.existing_library.isChecked():
  67.             action = 'existing'
  68.         elif self.empty_library.isChecked():
  69.             action = 'new'
  70.         
  71.         text = unicode(self.location.text()).strip()
  72.         if not text:
  73.             return error_dialog(self, _('No location'), _('No location selected'), show = True)
  74.         loc = os.path.abspath()
  75.         if not loc and not os.path.exists(loc) or not self.check_action(action, loc):
  76.             return None
  77.         QDialog.accept(self)
  78.         self.location.save_history()
  79.         self.perform_action(action, loc)
  80.  
  81.  
  82.