eric6/Helpviewer/Sync/SyncCheckPage.py

branch
maintenance
changeset 7286
7eb04391adf7
parent 7226
babe80d84a3e
parent 7285
1ff497f33f31
child 7287
1c17f2191bdd
equal deleted inserted replaced
7226:babe80d84a3e 7286:7eb04391adf7
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 import Helpviewer.HelpWindow
50 syncMgr = Helpviewer.HelpWindow.HelpWindow.syncManager()
51 syncMgr.syncError.connect(self.__syncError)
52 syncMgr.syncStatus.connect(self.__updateMessages)
53 syncMgr.syncFinished.connect(self.__updateLabels)
54
55 if Preferences.getHelp("SyncType") == SyncGlobals.SyncTypeFtp:
56 self.handlerLabel.setText(self.tr("FTP"))
57 self.infoLabel.setText(self.tr("Host:"))
58 self.infoDataLabel.setText(Preferences.getHelp("SyncFtpServer"))
59 elif Preferences.getHelp("SyncType") == SyncGlobals.SyncTypeDirectory:
60 self.handlerLabel.setText(self.tr("Shared Directory"))
61 self.infoLabel.setText(self.tr("Directory:"))
62 self.infoDataLabel.setText(
63 Preferences.getHelp("SyncDirectoryPath"))
64 else:
65 self.handlerLabel.setText(self.tr("No Synchronization"))
66 self.hostLabel.setText("")
67
68 self.bookmarkMsgLabel.setText("")
69 self.historyMsgLabel.setText("")
70 self.passwordsMsgLabel.setText("")
71 self.userAgentsMsgLabel.setText("")
72 self.speedDialMsgLabel.setText("")
73
74 if not syncMgr.syncEnabled():
75 self.bookmarkLabel.setPixmap(
76 UI.PixmapCache.getPixmap("syncNo.png"))
77 self.historyLabel.setPixmap(UI.PixmapCache.getPixmap("syncNo.png"))
78 self.passwordsLabel.setPixmap(
79 UI.PixmapCache.getPixmap("syncNo.png"))
80 self.userAgentsLabel.setPixmap(
81 UI.PixmapCache.getPixmap("syncNo.png"))
82 self.speedDialLabel.setPixmap(
83 UI.PixmapCache.getPixmap("syncNo.png"))
84 return
85
86 animationFile = os.path.join(getConfig("ericPixDir"), "loading.gif")
87
88 # bookmarks
89 if Preferences.getHelp("SyncBookmarks"):
90 self.__makeAnimatedLabel(animationFile, self.bookmarkLabel)
91 else:
92 self.bookmarkLabel.setPixmap(
93 UI.PixmapCache.getPixmap("syncNo.png"))
94
95 # history
96 if Preferences.getHelp("SyncHistory"):
97 self.__makeAnimatedLabel(animationFile, self.historyLabel)
98 else:
99 self.historyLabel.setPixmap(UI.PixmapCache.getPixmap("syncNo.png"))
100
101 # Passwords
102 if Preferences.getHelp("SyncPasswords"):
103 self.__makeAnimatedLabel(animationFile, self.passwordsLabel)
104 else:
105 self.passwordsLabel.setPixmap(
106 UI.PixmapCache.getPixmap("syncNo.png"))
107
108 # user agent settings
109 if Preferences.getHelp("SyncUserAgents"):
110 self.__makeAnimatedLabel(animationFile, self.userAgentsLabel)
111 else:
112 self.userAgentsLabel.setPixmap(
113 UI.PixmapCache.getPixmap("syncNo.png"))
114
115 # speed dial settings
116 if Preferences.getHelp("SyncSpeedDial"):
117 self.__makeAnimatedLabel(animationFile, self.speedDialLabel)
118 else:
119 self.speedDialLabel.setPixmap(
120 UI.PixmapCache.getPixmap("syncNo.png"))
121
122 QTimer.singleShot(
123 0, lambda: syncMgr.loadSettings(forceUpload=forceUpload))
124
125 def __makeAnimatedLabel(self, fileName, label):
126 """
127 Private slot to create an animated label.
128
129 @param fileName name of the file containing the animation (string)
130 @param label reference to the label to be animated (QLabel)
131 """
132 movie = QMovie(fileName, QByteArray(), label)
133 movie.setSpeed(100)
134 label.setMovie(movie)
135 movie.start()
136
137 def __updateMessages(self, type_, msg):
138 """
139 Private slot to update the synchronization status info.
140
141 @param type_ type of synchronization data (string)
142 @param msg synchronization message (string)
143 """
144 if type_ == "bookmarks":
145 self.bookmarkMsgLabel.setText(msg)
146 elif type_ == "history":
147 self.historyMsgLabel.setText(msg)
148 elif type_ == "passwords":
149 self.passwordsMsgLabel.setText(msg)
150 elif type_ == "useragents":
151 self.userAgentsMsgLabel.setText(msg)
152 elif type_ == "speeddial":
153 self.speedDialMsgLabel.setText(msg)
154
155 def __updateLabels(self, type_, status, download):
156 """
157 Private slot to handle a finished synchronization event.
158
159 @param type_ type of the synchronization event (string one
160 of "bookmarks", "history", "passwords", "useragents" or
161 "speeddial")
162 @param status flag indicating success (boolean)
163 @param download flag indicating a download of a file (boolean)
164 """
165 if type_ == "bookmarks":
166 if status:
167 self.bookmarkLabel.setPixmap(
168 UI.PixmapCache.getPixmap("syncCompleted.png"))
169 else:
170 self.bookmarkLabel.setPixmap(
171 UI.PixmapCache.getPixmap("syncFailed.png"))
172 elif type_ == "history":
173 if status:
174 self.historyLabel.setPixmap(
175 UI.PixmapCache.getPixmap("syncCompleted.png"))
176 else:
177 self.historyLabel.setPixmap(
178 UI.PixmapCache.getPixmap("syncFailed.png"))
179 elif type_ == "passwords":
180 if status:
181 self.passwordsLabel.setPixmap(
182 UI.PixmapCache.getPixmap("syncCompleted.png"))
183 else:
184 self.passwordsLabel.setPixmap(
185 UI.PixmapCache.getPixmap("syncFailed.png"))
186 elif type_ == "useragents":
187 if status:
188 self.userAgentsLabel.setPixmap(
189 UI.PixmapCache.getPixmap("syncCompleted.png"))
190 else:
191 self.userAgentsLabel.setPixmap(
192 UI.PixmapCache.getPixmap("syncFailed.png"))
193 elif type_ == "speeddial":
194 if status:
195 self.speedDialLabel.setPixmap(
196 UI.PixmapCache.getPixmap("syncCompleted.png"))
197 else:
198 self.speedDialLabel.setPixmap(
199 UI.PixmapCache.getPixmap("syncFailed.png"))
200
201 def __syncError(self, message):
202 """
203 Private slot to handle general synchronization issues.
204
205 @param message error message (string)
206 """
207 self.syncErrorLabel.show()
208 self.syncErrorLabel.setText(self.tr(
209 '<font color="#FF0000"><b>Error:</b> {0}</font>').format(message))

eric ide

mercurial