|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2010 - 2019 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing a dialog to configure the offline storage. |
|
8 """ |
|
9 |
|
10 from __future__ import unicode_literals |
|
11 |
|
12 from PyQt5.QtCore import pyqtSlot |
|
13 from PyQt5.QtWidgets import QDialog |
|
14 from PyQt5.QtWebKit import QWebSettings |
|
15 |
|
16 from .Ui_OfflineStorageConfigDialog import Ui_OfflineStorageConfigDialog |
|
17 |
|
18 import Preferences |
|
19 |
|
20 |
|
21 class OfflineStorageConfigDialog(QDialog, Ui_OfflineStorageConfigDialog): |
|
22 """ |
|
23 Class implementing a dialog to configure the offline storage. |
|
24 """ |
|
25 def __init__(self, parent=None): |
|
26 """ |
|
27 Constructor |
|
28 |
|
29 @param parent reference to the parent widget (QWidget) |
|
30 """ |
|
31 super(OfflineStorageConfigDialog, self).__init__(parent) |
|
32 self.setupUi(self) |
|
33 |
|
34 self.databaseEnabledCheckBox.setChecked( |
|
35 Preferences.getHelp("OfflineStorageDatabaseEnabled")) |
|
36 self.databaseQuotaSpinBox.setValue( |
|
37 Preferences.getHelp("OfflineStorageDatabaseQuota")) |
|
38 |
|
39 if hasattr(QWebSettings, "OfflineWebApplicationCacheEnabled"): |
|
40 self.applicationCacheEnabledCheckBox.setChecked( |
|
41 Preferences.getHelp("OfflineWebApplicationCacheEnabled")) |
|
42 self.applicationCacheQuotaSpinBox.setValue( |
|
43 Preferences.getHelp("OfflineWebApplicationCacheQuota")) |
|
44 else: |
|
45 self.applicationCacheGroup.setEnabled(False) |
|
46 |
|
47 if hasattr(QWebSettings, "LocalStorageEnabled"): |
|
48 self.localStorageEnabledCheckBox.setChecked( |
|
49 Preferences.getHelp("LocalStorageEnabled")) |
|
50 else: |
|
51 self.localStorageGroup.setEnabled(False) |
|
52 |
|
53 if hasattr(QWebSettings, "LocalContentCanAccessRemoteUrls"): |
|
54 self.localRemoteUrlsCheckBox.setChecked( |
|
55 Preferences.getHelp("LocalContentCanAccessRemoteUrls")) |
|
56 else: |
|
57 self.localRemoteUrlsCheckBox.setVisible(False) |
|
58 |
|
59 if hasattr(QWebSettings, "LocalContentCanAccessFileUrls"): |
|
60 self.localFileUrlsCheckBox.setChecked( |
|
61 Preferences.getHelp("LocalContentCanAccessFileUrls")) |
|
62 else: |
|
63 self.localFileUrlsCheckBox.setVisible(False) |
|
64 |
|
65 msh = self.minimumSizeHint() |
|
66 self.resize(max(self.width(), msh.width()), msh.height()) |
|
67 |
|
68 def storeData(self): |
|
69 """ |
|
70 Public slot to store the configuration data. |
|
71 """ |
|
72 Preferences.setHelp( |
|
73 "OfflineStorageDatabaseEnabled", |
|
74 self.databaseEnabledCheckBox.isChecked()) |
|
75 Preferences.setHelp( |
|
76 "OfflineStorageDatabaseQuota", |
|
77 self.databaseQuotaSpinBox.value()) |
|
78 |
|
79 if self.applicationCacheGroup.isEnabled(): |
|
80 Preferences.setHelp( |
|
81 "OfflineWebApplicationCacheEnabled", |
|
82 self.applicationCacheEnabledCheckBox.isChecked()) |
|
83 Preferences.setHelp( |
|
84 "OfflineWebApplicationCacheQuota", |
|
85 self.applicationCacheQuotaSpinBox.value()) |
|
86 |
|
87 if self.localStorageGroup.isEnabled(): |
|
88 Preferences.setHelp( |
|
89 "LocalStorageEnabled", |
|
90 self.localStorageEnabledCheckBox.isChecked()) |
|
91 if self.localRemoteUrlsCheckBox.isVisible(): |
|
92 Preferences.setHelp( |
|
93 "LocalContentCanAccessRemoteUrls", |
|
94 self.localRemoteUrlsCheckBox.isChecked()) |
|
95 if self.localFileUrlsCheckBox.isVisible(): |
|
96 Preferences.setHelp( |
|
97 "LocalContentCanAccessFileUrls", |
|
98 self.localFileUrlsCheckBox.isChecked()) |
|
99 |
|
100 @pyqtSlot() |
|
101 def on_showDatabasesButton_clicked(self): |
|
102 """ |
|
103 Private slot to show a dialog with all databases. |
|
104 """ |
|
105 from .WebDatabasesDialog import WebDatabasesDialog |
|
106 dlg = WebDatabasesDialog(self) |
|
107 dlg.exec_() |