~ubuntu-branches/debian/wheezy/calibre/wheezy

« back to all changes in this revision

Viewing changes to src/calibre/gui2/dialogs/config/__init__.py

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2010-08-11 11:30:57 UTC
  • mfrom: (1.3.14 upstream)
  • mto: (29.3.2 oneiric)
  • mto: This revision was merged to the branch mainline in revision 31.
  • Revision ID: james.westby@ubuntu.com-20100811113057-2jhbcbavxw7wlt0c
Tags: 0.7.13+dfsg-1
* New upstream version.
* debian/control: Add python-routes recommends. (Closes: #590561)
* Convert to 3.0 (quilt) source format.
* Bump debhelper compat level to 7, and drop now obsolete
  DEB_DH_INSTALL_SOURCEDIR in debian/rules.
* debian/control: Add missing ${misc:Depends}.
* debian/control: Bump Standards-Version to 3.9.1.
* debian/copyright: Replace obsolete reference to
  /usr/share/common-licenses/BSD with their verbatim text from the original
  source.
* debian/rules: Remove invalid hashbang lines from *.recipe, these have no
  __main__.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
from calibre.constants import iswindows, isosx
15
15
from calibre.gui2.dialogs.config.config_ui import Ui_Dialog
16
16
from calibre.gui2.dialogs.config.create_custom_column import CreateCustomColumn
17
 
from calibre.gui2 import choose_dir, error_dialog, config, gprefs, \
 
17
from calibre.gui2 import error_dialog, config, gprefs, \
18
18
        open_url, open_local_file, \
19
19
        ALL_COLUMNS, NONE, info_dialog, choose_files, \
20
20
        warning_dialog, ResizableDialog, question_dialog
195
195
 
196
196
class CategoryModel(QStringListModel):
197
197
 
 
198
    CATEGORIES = [
 
199
             ('general', _('General'), 'dialog_information.svg'),
 
200
             ('interface', _('Interface'), 'lookfeel.svg'),
 
201
             ('conversion', _('Conversion'), 'convert.svg'),
 
202
             ('email', _('Email\nDelivery'), 'mail.svg'),
 
203
             ('add/save', _('Add/Save'), 'save.svg'),
 
204
             ('advanced', _('Advanced'), 'view.svg'),
 
205
             ('server', _('Content\nServer'), 'network-server.svg'),
 
206
             ('plugins', _('Plugins'), 'plugins.svg'),
 
207
    ]
 
208
 
198
209
    def __init__(self, *args):
199
210
        QStringListModel.__init__(self, *args)
200
 
        self.setStringList([_('General'), _('Interface'), _('Conversion'),
201
 
                            _('Email\nDelivery'), _('Add/Save'),
202
 
                            _('Advanced'), _('Content\nServer'), _('Plugins')])
203
 
        self.icons = list(map(QVariant, map(QIcon,
204
 
            [I('dialog_information.svg'), I('lookfeel.svg'),
205
 
                I('convert.svg'),
206
 
                I('mail.svg'), I('save.svg'), I('view.svg'),
207
 
             I('network-server.svg'), I('plugins.svg')])))
 
211
        self.setStringList([x[1] for x in self.CATEGORIES])
208
212
 
209
213
    def data(self, index, role):
210
214
        if role == Qt.DecorationRole:
211
 
            return self.icons[index.row()]
 
215
            return QVariant(QIcon(I(self.CATEGORIES[index.row()][2])))
212
216
        return QStringListModel.data(self, index, role)
213
217
 
 
218
    def index_for_name(self, name):
 
219
        for i, x in enumerate(self.CATEGORIES):
 
220
            if x[0] == name:
 
221
                return self.index(i)
 
222
        return self.index(0)
 
223
 
214
224
class EmailAccounts(QAbstractTableModel):
215
225
 
216
226
    def __init__(self, accounts):
332
342
    def category_current_changed(self, n, p):
333
343
        self.stackedWidget.setCurrentIndex(n.row())
334
344
 
335
 
    def __init__(self, parent, library_view, server=None):
 
345
    def __init__(self, parent, library_view, server=None,
 
346
            initial_category='general'):
336
347
        ResizableDialog.__init__(self, parent)
337
 
        self.ICON_SIZES = {0:QSize(48, 48), 1:QSize(32,32), 2:QSize(24,24)}
338
348
        self._category_model = CategoryModel()
339
349
 
340
350
        self.category_view.currentChanged = self.category_current_changed
344
354
        self.model = library_view.model()
345
355
        self.db = self.model.db
346
356
        self.server = server
347
 
        path = prefs['library_path']
348
 
        self.location.setText(path if path else '')
349
 
        self.connect(self.browse_button, SIGNAL('clicked(bool)'), self.browse)
350
357
        self.connect(self.compact_button, SIGNAL('clicked(bool)'), self.compact)
351
358
 
352
359
        input_map = prefs['input_format_order']
389
396
        self.add_custcol_button.clicked.connect(self.add_custcol)
390
397
        self.edit_custcol_button.clicked.connect(self.edit_custcol)
391
398
 
392
 
        icons = config['toolbar_icon_size']
393
 
        self.toolbar_button_size.setCurrentIndex(0 if icons == self.ICON_SIZES[0] else 1 if icons == self.ICON_SIZES[1] else 2)
394
 
        self.show_toolbar_text.setChecked(config['show_text_in_toolbar'])
395
 
 
396
399
        output_formats = sorted(available_output_formats())
397
400
        output_formats.remove('oeb')
398
401
        for f in output_formats:
469
472
        self.button_osx_symlinks.setVisible(isosx)
470
473
        self.separate_cover_flow.setChecked(config['separate_cover_flow'])
471
474
        self.setup_email_page()
472
 
        self.category_view.setCurrentIndex(self.category_view.model().index(0))
473
475
        self.delete_news.setEnabled(bool(self.sync_news.isChecked()))
474
476
        self.connect(self.sync_news, SIGNAL('toggled(bool)'),
475
477
                self.delete_news.setEnabled)
495
497
                li = i
496
498
        self.opt_gui_layout.setCurrentIndex(li)
497
499
        self.opt_disable_animations.setChecked(config['disable_animations'])
 
500
        self.opt_show_donate_button.setChecked(config['show_donate_button'])
 
501
        idx = 0
 
502
        for i, x in enumerate([(_('Small'), 'small'), (_('Medium'), 'medium'),
 
503
            (_('Large'), 'large')]):
 
504
            if x[1] == gprefs.get('toolbar_icon_size', 'medium'):
 
505
                idx = i
 
506
            self.opt_toolbar_icon_size.addItem(x[0], x[1])
 
507
        self.opt_toolbar_icon_size.setCurrentIndex(idx)
 
508
        idx = 0
 
509
        for i, x in enumerate([(_('Automatic'), 'auto'), (_('Always'), 'always'),
 
510
            (_('Never'), 'never')]):
 
511
            if x[1] == gprefs.get('toolbar_text', 'auto'):
 
512
                idx = i
 
513
            self.opt_toolbar_text.addItem(x[0], x[1])
 
514
        self.opt_toolbar_text.setCurrentIndex(idx)
 
515
        self.reset_confirmation_button.clicked.connect(self.reset_confirmation)
 
516
 
 
517
        self.category_view.setCurrentIndex(self.category_view.model().index_for_name(initial_category))
 
518
 
 
519
    def reset_confirmation(self):
 
520
        from calibre.gui2 import dynamic
 
521
        for key in dynamic.keys():
 
522
            if key.endswith('_again') and dynamic[key] is False:
 
523
                dynamic[key] = True
 
524
        info_dialog(self, _('Done'),
 
525
                _('Confirmation dialogs have all been reset'), show=True)
498
526
 
499
527
    def check_port_value(self, *args):
500
528
        port = self.port.value()
812
840
        d = CheckIntegrity(self.db, self)
813
841
        d.exec_()
814
842
 
815
 
    def browse(self):
816
 
        dir = choose_dir(self, 'database location dialog',
817
 
                         _('Select location for books'))
818
 
        if dir:
819
 
            self.location.setText(dir)
820
 
 
821
843
    def accept(self):
822
844
        mcs = unicode(self.max_cover_size.text()).strip()
823
845
        if not re.match(r'\d+x\d+', mcs):
838
860
        config['use_roman_numerals_for_series_number'] = bool(self.roman_numerals.isChecked())
839
861
        config['new_version_notification'] = bool(self.new_version_notification.isChecked())
840
862
        prefs['network_timeout'] = int(self.timeout.value())
841
 
        path = unicode(self.location.text())
842
863
        input_cols = [unicode(self.input_order.item(i).data(Qt.UserRole).toString()) for i in range(self.input_order.count())]
843
864
        prefs['input_format_order'] = input_cols
844
865
 
845
866
        must_restart = self.apply_custom_column_changes()
846
867
 
847
 
        config['toolbar_icon_size'] = self.ICON_SIZES[self.toolbar_button_size.currentIndex()]
848
 
        config['show_text_in_toolbar'] = bool(self.show_toolbar_text.isChecked())
849
868
        config['separate_cover_flow'] = bool(self.separate_cover_flow.isChecked())
850
869
        config['disable_tray_notification'] = not self.systray_notifications.isChecked()
851
870
        p = {0:'normal', 1:'high', 2:'low'}[self.priority.currentIndex()]
871
890
        config['overwrite_author_title_metadata'] = self.opt_overwrite_author_title_metadata.isChecked()
872
891
        config['enforce_cpu_limit'] = bool(self.opt_enforce_cpu_limit.isChecked())
873
892
        config['disable_animations'] = bool(self.opt_disable_animations.isChecked())
 
893
        config['show_donate_button'] = bool(self.opt_show_donate_button.isChecked())
874
894
        gprefs['show_splash_screen'] = bool(self.show_splash_screen.isChecked())
 
895
        for x in ('toolbar_icon_size', 'toolbar_text'):
 
896
            w = getattr(self, 'opt_'+x)
 
897
            data = w.itemData(w.currentIndex()).toString()
 
898
            gprefs[x] = unicode(data)
875
899
        fmts = []
876
900
        for i in range(self.viewer.count()):
877
901
            if self.viewer.item(i).checkState() == Qt.Checked:
880
904
        val = self.opt_gui_layout.itemData(self.opt_gui_layout.currentIndex()).toString()
881
905
        config['gui_layout'] = unicode(val)
882
906
 
883
 
        if not path or not os.path.exists(path) or not os.path.isdir(path):
884
 
            d = error_dialog(self, _('Invalid database location'),
885
 
                             _('Invalid database location ')+path+
886
 
                             _('<br>Must be a directory.'))
887
 
            d.exec_()
888
 
        elif not os.access(path, os.W_OK):
889
 
            d = error_dialog(self, _('Invalid database location'),
890
 
                     _('Invalid database location.<br>Cannot write to ')+path)
891
 
            d.exec_()
892
 
        else:
893
 
            self.database_location = os.path.abspath(path)
894
 
            if must_restart:
895
 
                warning_dialog(self, _('Must restart'),
896
 
                        _('The changes you made require that Calibre be '
897
 
                            'restarted. Please restart as soon as practical.'),
898
 
                        show=True, show_copy_button=False)
899
 
                self.parent.must_restart_before_config = True
900
 
            QDialog.accept(self)
 
907
        if must_restart:
 
908
            warning_dialog(self, _('Must restart'),
 
909
                    _('The changes you made require that Calibre be '
 
910
                        'restarted. Please restart as soon as practical.'),
 
911
                    show=True, show_copy_button=False)
 
912
            self.parent.must_restart_before_config = True
 
913
        QDialog.accept(self)
901
914
 
902
915
class VacThread(QThread):
903
916
 
968
981
    from PyQt4.Qt import QApplication
969
982
    app = QApplication([])
970
983
    d=ConfigDialog(None, LibraryDatabase2('/tmp'))
971
 
    d.category_view.setCurrentIndex(d.category_view.model().index(0))
972
984
    d.show()
973
985
    app.exec_()