eric6/WebBrowser/Sync/SyncCheckPage.py

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

eric ide

mercurial