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
196
196
class CategoryModel(QStringListModel):
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'),
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'),
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])
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)
218
def index_for_name(self, name):
219
for i, x in enumerate(self.CATEGORIES):
214
224
class EmailAccounts(QAbstractTableModel):
216
226
def __init__(self, accounts):
332
342
def category_current_changed(self, n, p):
333
343
self.stackedWidget.setCurrentIndex(n.row())
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()
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)
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)
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'])
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)
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'])
502
for i, x in enumerate([(_('Small'), 'small'), (_('Medium'), 'medium'),
503
(_('Large'), 'large')]):
504
if x[1] == gprefs.get('toolbar_icon_size', 'medium'):
506
self.opt_toolbar_icon_size.addItem(x[0], x[1])
507
self.opt_toolbar_icon_size.setCurrentIndex(idx)
509
for i, x in enumerate([(_('Automatic'), 'auto'), (_('Always'), 'always'),
510
(_('Never'), 'never')]):
511
if x[1] == gprefs.get('toolbar_text', 'auto'):
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)
517
self.category_view.setCurrentIndex(self.category_view.model().index_for_name(initial_category))
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:
524
info_dialog(self, _('Done'),
525
_('Confirmation dialogs have all been reset'), show=True)
499
527
def check_port_value(self, *args):
500
528
port = self.port.value()
812
840
d = CheckIntegrity(self.db, self)
816
dir = choose_dir(self, 'database location dialog',
817
_('Select location for books'))
819
self.location.setText(dir)
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
845
866
must_restart = self.apply_custom_column_changes()
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)
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)
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.'))
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)
893
self.database_location = os.path.abspath(path)
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
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
902
915
class VacThread(QThread):