|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2012 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing the synchronization status wizard page. |
|
8 """ |
|
9 |
|
10 import os |
|
11 |
|
12 from PyQt4.QtCore import QByteArray |
|
13 from PyQt4.QtGui import QWizardPage, QMovie |
|
14 |
|
15 from .Ui_SyncCheckPage import Ui_SyncCheckPage |
|
16 |
|
17 import Preferences |
|
18 import UI.PixmapCache |
|
19 |
|
20 import Helpviewer.HelpWindow |
|
21 |
|
22 from eric5config import getConfig |
|
23 |
|
24 |
|
25 class SyncCheckPage(QWizardPage, Ui_SyncCheckPage): |
|
26 """ |
|
27 Class implementing the synchronization status wizard page. |
|
28 """ |
|
29 def __init__(self, parent=None): |
|
30 """ |
|
31 Constructor |
|
32 |
|
33 @param parent reference to the parent widget (QWidget) |
|
34 """ |
|
35 super().__init__(parent) |
|
36 self.setupUi(self) |
|
37 |
|
38 def initializePage(self): |
|
39 """ |
|
40 Public method to initialize the page. |
|
41 """ |
|
42 self.syncErrorLabel.hide() |
|
43 |
|
44 syncMgr = Helpviewer.HelpWindow.HelpWindow.syncManager() |
|
45 syncMgr.syncError.connect(self.__syncError) |
|
46 syncMgr.loadSettings() |
|
47 |
|
48 if Preferences.getHelp("SyncType") == 0: |
|
49 self.handlerLabel.setText(self.trUtf8("FTP")) |
|
50 self.hostLabel.setText(Preferences.getHelp("SyncFtpServer")) |
|
51 else: |
|
52 self.handlerLabel.setText(self.trUtf8("No Synchronization")) |
|
53 self.hostLabel.setText("") |
|
54 |
|
55 self.bookmarkMsgLabel.setText("") |
|
56 self.historyMsgLabel.setText("") |
|
57 self.passwordsMsgLabel.setText("") |
|
58 self.userAgentsMsgLabel.setText("") |
|
59 |
|
60 if not syncMgr.syncEnabled(): |
|
61 self.bookmarkLabel.setPixmap(UI.PixmapCache.getPixmap("syncNo.png")) |
|
62 self.historyLabel.setPixmap(UI.PixmapCache.getPixmap("syncNo.png")) |
|
63 self.passwordsLabel.setPixmap(UI.PixmapCache.getPixmap("syncNo.png")) |
|
64 self.userAgentsLabel.setPixmap(UI.PixmapCache.getPixmap("syncNo.png")) |
|
65 return |
|
66 |
|
67 animationFile = os.path.join(getConfig("ericPixDir"), "loading.gif") |
|
68 |
|
69 # bookmarks |
|
70 if Preferences.getHelp("SyncBookmarks"): |
|
71 movie = QMovie(animationFile, QByteArray(), self.bookmarkLabel) |
|
72 movie.setSpeed(50) |
|
73 self.bookmarkLabel.setMovie(movie) |
|
74 movie.start() |
|
75 else: |
|
76 self.bookmarkLabel.setPixmap(UI.PixmapCache.getPixmap("syncNo.png")) |
|
77 |
|
78 # history |
|
79 if Preferences.getHelp("SyncHistory"): |
|
80 movie = QMovie(animationFile, QByteArray(), self.historyLabel) |
|
81 movie.setSpeed(50) |
|
82 self.historyLabel.setMovie(movie) |
|
83 movie.start() |
|
84 else: |
|
85 self.historyLabel.setPixmap(UI.PixmapCache.getPixmap("syncNo.png")) |
|
86 |
|
87 # Passwords |
|
88 if Preferences.getHelp("SyncPasswords"): |
|
89 movie = QMovie(animationFile, QByteArray(), self.passwordsLabel) |
|
90 movie.setSpeed(50) |
|
91 self.passwordsLabel.setMovie(movie) |
|
92 movie.start() |
|
93 else: |
|
94 self.passwordsLabel.setPixmap(UI.PixmapCache.getPixmap("syncNo.png")) |
|
95 |
|
96 # user agent settings |
|
97 if Preferences.getHelp("SyncUserAgents"): |
|
98 movie = QMovie(animationFile, QByteArray(), self.userAgentsLabel) |
|
99 movie.setSpeed(50) |
|
100 self.userAgentsLabel.setMovie(movie) |
|
101 movie.start() |
|
102 else: |
|
103 self.userAgentsLabel.setPixmap(UI.PixmapCache.getPixmap("syncNo.png")) |
|
104 |
|
105 handler = syncMgr.handler() |
|
106 handler.syncStatus.connect(self.__updatePage) |
|
107 |
|
108 def __updatePage(self, type_, done, msg): |
|
109 """ |
|
110 Private slot to update the synchronization status info. |
|
111 |
|
112 @param type_ type of synchronization data (string) |
|
113 @param done flag indicating success (boolean) |
|
114 @param msg synchronization message (string) |
|
115 """ |
|
116 if type_ == "bookmarks": |
|
117 if done: |
|
118 self.bookmarkLabel.setPixmap( |
|
119 UI.PixmapCache.getPixmap("syncCompleted.png")) |
|
120 else: |
|
121 self.bookmarkLabel.setPixmap(UI.PixmapCache.getPixmap("syncFailed.png")) |
|
122 self.bookmarkMsgLabel.setText(msg) |
|
123 elif type_ == "history": |
|
124 if done: |
|
125 self.historyLabel.setPixmap(UI.PixmapCache.getPixmap("syncCompleted.png")) |
|
126 else: |
|
127 self.historyLabel.setPixmap(UI.PixmapCache.getPixmap("syncFailed.png")) |
|
128 self.historyMsgLabel.setText(msg) |
|
129 elif type_ == "passwords": |
|
130 if done: |
|
131 self.passwordsLabel.setPixmap( |
|
132 UI.PixmapCache.getPixmap("syncCompleted.png")) |
|
133 else: |
|
134 self.passwordsLabel.setPixmap(UI.PixmapCache.getPixmap("syncFailed.png")) |
|
135 self.passwordsMsgLabel.setText(msg) |
|
136 elif type_ == "useragents": |
|
137 if done: |
|
138 self.userAgentsLabel.setPixmap( |
|
139 UI.PixmapCache.getPixmap("syncCompleted.png")) |
|
140 else: |
|
141 self.userAgentsLabel.setPixmap(UI.PixmapCache.getPixmap("syncFailed.png")) |
|
142 self.userAgentsMsgLabel.setText(msg) |
|
143 |
|
144 def __syncError(self, message): |
|
145 """ |
|
146 Private slot to handle general synchronization issues. |
|
147 |
|
148 @param message error message (string) |
|
149 """ |
|
150 self.syncErrorLabel.show() |
|
151 self.syncErrorLabel.setText( |
|
152 self.trUtf8('<font color="#FF0000"><b>Error:</b> {0}</font>').format(message)) |