1# -*- coding: utf-8 -*-
2
3
4__license__ = 'GPL 3'
5__copyright__ = '2011, John Schember <john@nachtimwald.com>'
6__docformat__ = 'restructuredtext en'
7
8from qt.core import QWidget
9
10from calibre.gui2 import JSONConfig
11from calibre.gui2.store.config.search.search_widget_ui import Ui_Form
12
13
14class StoreConfigWidget(QWidget, Ui_Form):
15
16    def __init__(self, config=None):
17        QWidget.__init__(self)
18        self.setupUi(self)
19
20        self.config = JSONConfig('store/search') if not config else config
21
22        # These default values should be the same as in
23        # calibre.gui2.store.search.search:SearchDialog.load_settings
24        # Seconds
25        self.opt_timeout.setValue(self.config.get('timeout', 75))
26        self.opt_hang_time.setValue(self.config.get('hang_time', 75))
27
28        self.opt_max_results.setValue(self.config.get('max_results', 10))
29        self.opt_open_external.setChecked(self.config.get('open_external', True))
30
31        # Number of threads to run for each type of operation
32        self.opt_search_thread_count.setValue(self.config.get('search_thread_count', 4))
33        self.opt_cache_thread_count.setValue(self.config.get('cache_thread_count', 2))
34        self.opt_cover_thread_count.setValue(self.config.get('cover_thread_count', 2))
35        self.opt_details_thread_count.setValue(self.config.get('details_thread_count', 4))
36
37    def save_settings(self):
38        self.config['timeout'] = self.opt_timeout.value()
39        self.config['hang_time'] = self.opt_hang_time.value()
40        self.config['max_results'] = self.opt_max_results.value()
41        self.config['open_external'] = self.opt_open_external.isChecked()
42        self.config['search_thread_count'] = self.opt_search_thread_count.value()
43        self.config['cache_thread_count'] = self.opt_cache_thread_count.value()
44        self.config['cover_thread_count'] = self.opt_cover_thread_count.value()
45        self.config['details_thread_count'] = self.opt_details_thread_count.value()
46