|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2012 - 2022 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing the synchronization status wizard page. |
|
8 """ |
|
9 |
|
10 from PyQt6.QtCore import QTimer |
|
11 from PyQt6.QtWidgets import QWizardPage |
|
12 |
|
13 from . import SyncGlobals |
|
14 |
|
15 from .Ui_SyncCheckPage import Ui_SyncCheckPage |
|
16 |
|
17 import Preferences |
|
18 import UI.PixmapCache |
|
19 |
|
20 |
|
21 class SyncCheckPage(QWizardPage, Ui_SyncCheckPage): |
|
22 """ |
|
23 Class implementing the synchronization status wizard page. |
|
24 """ |
|
25 def __init__(self, parent=None): |
|
26 """ |
|
27 Constructor |
|
28 |
|
29 @param parent reference to the parent widget (QWidget) |
|
30 """ |
|
31 super().__init__(parent) |
|
32 self.setupUi(self) |
|
33 |
|
34 def initializePage(self): |
|
35 """ |
|
36 Public method to initialize the page. |
|
37 """ |
|
38 self.syncErrorLabel.hide() |
|
39 |
|
40 forceUpload = self.field("ReencryptData") |
|
41 |
|
42 from WebBrowser.WebBrowserWindow import WebBrowserWindow |
|
43 syncMgr = WebBrowserWindow.syncManager() |
|
44 syncMgr.syncError.connect(self.__syncError) |
|
45 syncMgr.syncStatus.connect(self.__updateMessages) |
|
46 syncMgr.syncFinished.connect(self.__updateLabels) |
|
47 |
|
48 if Preferences.getWebBrowser("SyncType") == SyncGlobals.SyncTypeFtp: |
|
49 self.handlerLabel.setText(self.tr("FTP")) |
|
50 self.infoLabel.setText(self.tr("Host:")) |
|
51 self.infoDataLabel.setText( |
|
52 Preferences.getWebBrowser("SyncFtpServer")) |
|
53 elif ( |
|
54 Preferences.getWebBrowser("SyncType") == |
|
55 SyncGlobals.SyncTypeDirectory |
|
56 ): |
|
57 self.handlerLabel.setText(self.tr("Shared Directory")) |
|
58 self.infoLabel.setText(self.tr("Directory:")) |
|
59 self.infoDataLabel.setText( |
|
60 Preferences.getWebBrowser("SyncDirectoryPath")) |
|
61 else: |
|
62 self.handlerLabel.setText(self.tr("No Synchronization")) |
|
63 self.hostLabel.setText("") |
|
64 |
|
65 self.bookmarkMsgLabel.setText("") |
|
66 self.historyMsgLabel.setText("") |
|
67 self.passwordsMsgLabel.setText("") |
|
68 self.userAgentsMsgLabel.setText("") |
|
69 self.speedDialMsgLabel.setText("") |
|
70 |
|
71 if not syncMgr.syncEnabled(): |
|
72 self.bookmarkLabel.setPixmap( |
|
73 UI.PixmapCache.getPixmap("syncNo")) |
|
74 self.historyLabel.setPixmap(UI.PixmapCache.getPixmap("syncNo")) |
|
75 self.passwordsLabel.setPixmap( |
|
76 UI.PixmapCache.getPixmap("syncNo")) |
|
77 self.userAgentsLabel.setPixmap( |
|
78 UI.PixmapCache.getPixmap("syncNo")) |
|
79 self.speedDialLabel.setPixmap( |
|
80 UI.PixmapCache.getPixmap("syncNo")) |
|
81 return |
|
82 |
|
83 # bookmarks |
|
84 if Preferences.getWebBrowser("SyncBookmarks"): |
|
85 self.__makeAnimatedLabel("loadingAnimation", self.bookmarkLabel) |
|
86 else: |
|
87 self.bookmarkLabel.setPixmap( |
|
88 UI.PixmapCache.getPixmap("syncNo")) |
|
89 |
|
90 # history |
|
91 if Preferences.getWebBrowser("SyncHistory"): |
|
92 self.__makeAnimatedLabel("loadingAnimation", self.historyLabel) |
|
93 else: |
|
94 self.historyLabel.setPixmap(UI.PixmapCache.getPixmap("syncNo")) |
|
95 |
|
96 # Passwords |
|
97 if Preferences.getWebBrowser("SyncPasswords"): |
|
98 self.__makeAnimatedLabel("loadingAnimation", self.passwordsLabel) |
|
99 else: |
|
100 self.passwordsLabel.setPixmap( |
|
101 UI.PixmapCache.getPixmap("syncNo")) |
|
102 |
|
103 # user agent settings |
|
104 if Preferences.getWebBrowser("SyncUserAgents"): |
|
105 self.__makeAnimatedLabel("loadingAnimation", self.userAgentsLabel) |
|
106 else: |
|
107 self.userAgentsLabel.setPixmap( |
|
108 UI.PixmapCache.getPixmap("syncNo")) |
|
109 |
|
110 # speed dial settings |
|
111 if Preferences.getWebBrowser("SyncSpeedDial"): |
|
112 self.__makeAnimatedLabel("loadingAnimation", self.speedDialLabel) |
|
113 else: |
|
114 self.speedDialLabel.setPixmap( |
|
115 UI.PixmapCache.getPixmap("syncNo")) |
|
116 |
|
117 QTimer.singleShot( |
|
118 0, lambda: syncMgr.loadSettings(forceUpload=forceUpload)) |
|
119 |
|
120 def __makeAnimatedLabel(self, fileName, label): |
|
121 """ |
|
122 Private slot to create an animated label. |
|
123 |
|
124 @param fileName name of the file containing the animation |
|
125 @type str |
|
126 @param label reference to the label to be animated |
|
127 @type EricAnimatedLabel |
|
128 """ |
|
129 label.setInterval(40) |
|
130 label.setAnimationFile(fileName) |
|
131 label.start() |
|
132 |
|
133 def __updateMessages(self, type_, msg): |
|
134 """ |
|
135 Private slot to update the synchronization status info. |
|
136 |
|
137 @param type_ type of synchronization data (string) |
|
138 @param msg synchronization message (string) |
|
139 """ |
|
140 if type_ == "bookmarks": |
|
141 self.bookmarkMsgLabel.setText(msg) |
|
142 elif type_ == "history": |
|
143 self.historyMsgLabel.setText(msg) |
|
144 elif type_ == "passwords": |
|
145 self.passwordsMsgLabel.setText(msg) |
|
146 elif type_ == "useragents": |
|
147 self.userAgentsMsgLabel.setText(msg) |
|
148 elif type_ == "speeddial": |
|
149 self.speedDialMsgLabel.setText(msg) |
|
150 |
|
151 def __updateLabels(self, type_, status, download): |
|
152 """ |
|
153 Private slot to handle a finished synchronization event. |
|
154 |
|
155 @param type_ type of the synchronization event (string one |
|
156 of "bookmarks", "history", "passwords", "useragents" or |
|
157 "speeddial") |
|
158 @param status flag indicating success (boolean) |
|
159 @param download flag indicating a download of a file (boolean) |
|
160 """ |
|
161 if type_ == "bookmarks": |
|
162 if status: |
|
163 self.bookmarkLabel.setPixmap( |
|
164 UI.PixmapCache.getPixmap("syncCompleted")) |
|
165 else: |
|
166 self.bookmarkLabel.setPixmap( |
|
167 UI.PixmapCache.getPixmap("syncFailed")) |
|
168 elif type_ == "history": |
|
169 if status: |
|
170 self.historyLabel.setPixmap( |
|
171 UI.PixmapCache.getPixmap("syncCompleted")) |
|
172 else: |
|
173 self.historyLabel.setPixmap( |
|
174 UI.PixmapCache.getPixmap("syncFailed")) |
|
175 elif type_ == "passwords": |
|
176 if status: |
|
177 self.passwordsLabel.setPixmap( |
|
178 UI.PixmapCache.getPixmap("syncCompleted")) |
|
179 else: |
|
180 self.passwordsLabel.setPixmap( |
|
181 UI.PixmapCache.getPixmap("syncFailed")) |
|
182 elif type_ == "useragents": |
|
183 if status: |
|
184 self.userAgentsLabel.setPixmap( |
|
185 UI.PixmapCache.getPixmap("syncCompleted")) |
|
186 else: |
|
187 self.userAgentsLabel.setPixmap( |
|
188 UI.PixmapCache.getPixmap("syncFailed")) |
|
189 elif type_ == "speeddial": |
|
190 if status: |
|
191 self.speedDialLabel.setPixmap( |
|
192 UI.PixmapCache.getPixmap("syncCompleted")) |
|
193 else: |
|
194 self.speedDialLabel.setPixmap( |
|
195 UI.PixmapCache.getPixmap("syncFailed")) |
|
196 |
|
197 def __syncError(self, message): |
|
198 """ |
|
199 Private slot to handle general synchronization issues. |
|
200 |
|
201 @param message error message (string) |
|
202 """ |
|
203 self.syncErrorLabel.show() |
|
204 self.syncErrorLabel.setText(self.tr( |
|
205 '<font color="#FF0000"><b>Error:</b> {0}</font>').format(message)) |