|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2012 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing the IRC configuration page. |
|
8 """ |
|
9 |
|
10 from PyQt4.QtCore import pyqtSlot |
|
11 ##from PyQt4.QtGui import QWidget |
|
12 |
|
13 from .ConfigurationPageBase import ConfigurationPageBase |
|
14 from .Ui_IrcPage import Ui_IrcPage |
|
15 |
|
16 import Preferences |
|
17 |
|
18 |
|
19 class IrcPage(ConfigurationPageBase, Ui_IrcPage): |
|
20 """ |
|
21 Class implementing the IRC configuration page. |
|
22 """ |
|
23 TimeFormats = ["hh:mm", "hh:mm:ss", "h:mm ap", "h:mm:ss ap"] |
|
24 DateFormats = ["yyyy-MM-dd", "dd.MM.yyyy", "MM/dd/yyyy", |
|
25 "yyyy MMM. dd", "dd MMM. yyyy", "MMM. dd, yyyy"] |
|
26 |
|
27 def __init__(self): |
|
28 """ |
|
29 Constructor |
|
30 """ |
|
31 super().__init__() |
|
32 self.setupUi(self) |
|
33 self.setObjectName("IrcPage") |
|
34 |
|
35 self.timeFormatCombo.addItems(IrcPage.TimeFormats) |
|
36 self.dateFormatCombo.addItems(IrcPage.DateFormats) |
|
37 |
|
38 self.ircColours = {} |
|
39 |
|
40 # set initial values |
|
41 # timestamps |
|
42 self.timestampGroup.setChecked(Preferences.getIrc("ShowTimestamps")) |
|
43 self.showDateCheckBox.setChecked(Preferences.getIrc("TimestampIncludeDate")) |
|
44 self.timeFormatCombo.setCurrentIndex( |
|
45 self.timeFormatCombo.findText(Preferences.getIrc("TimeFormat"))) |
|
46 self.dateFormatCombo.setCurrentIndex( |
|
47 self.dateFormatCombo.findText(Preferences.getIrc("DateFormat"))) |
|
48 |
|
49 # colours |
|
50 self.ircColours["NetworkMessageColour"] = \ |
|
51 self.initColour("NetworkMessageColour", self.networkButton, |
|
52 Preferences.getIrc) |
|
53 self.ircColours["ServerMessageColour"] = \ |
|
54 self.initColour("ServerMessageColour", self.serverButton, |
|
55 Preferences.getIrc) |
|
56 self.ircColours["ErrorMessageColour"] = \ |
|
57 self.initColour("ErrorMessageColour", self.errorButton, |
|
58 Preferences.getIrc) |
|
59 self.ircColours["TimestampColour"] = \ |
|
60 self.initColour("TimestampColour", self.timestampButton, |
|
61 Preferences.getIrc) |
|
62 self.ircColours["HyperlinkColour"] = \ |
|
63 self.initColour("HyperlinkColour", self.hyperlinkButton, |
|
64 Preferences.getIrc) |
|
65 self.ircColours["ChannelMessageColour"] = \ |
|
66 self.initColour("ChannelMessageColour", self.channelButton, |
|
67 Preferences.getIrc) |
|
68 self.ircColours["OwnNickColour"] = \ |
|
69 self.initColour("OwnNickColour", self.ownNickButton, |
|
70 Preferences.getIrc) |
|
71 self.ircColours["NickColour"] = \ |
|
72 self.initColour("NickColour", self.nickButton, |
|
73 Preferences.getIrc) |
|
74 self.ircColours["JoinChannelColour"] = \ |
|
75 self.initColour("JoinChannelColour", self.joinButton, |
|
76 Preferences.getIrc) |
|
77 self.ircColours["LeaveChannelColour"] = \ |
|
78 self.initColour("LeaveChannelColour", self.leaveButton, |
|
79 Preferences.getIrc) |
|
80 self.ircColours["ChannelInfoColour"] = \ |
|
81 self.initColour("ChannelInfoColour", self.infoButton, |
|
82 Preferences.getIrc) |
|
83 |
|
84 # notifications |
|
85 self.notificationsGroup.setChecked(Preferences.getIrc("ShowNotifications")) |
|
86 self.joinLeaveCheckBox.setChecked(Preferences.getIrc("NotifyJoinPart")) |
|
87 self.messageCheckBox.setChecked(Preferences.getIrc("NotifyMessage")) |
|
88 self.ownNickCheckBox.setChecked(Preferences.getIrc("NotifyNick")) |
|
89 |
|
90 def save(self): |
|
91 """ |
|
92 Public slot to save the IRC configuration. |
|
93 """ |
|
94 # timestamps |
|
95 Preferences.setIrc("ShowTimestamps", self.timestampGroup.isChecked()) |
|
96 Preferences.setIrc("TimestampIncludeDate", self.showDateCheckBox.isChecked()) |
|
97 Preferences.setIrc("TimeFormat", self.timeFormatCombo.currentText()) |
|
98 Preferences.setIrc("DateFormat", self.dateFormatCombo.currentText()) |
|
99 |
|
100 # notifications |
|
101 Preferences.setIrc("ShowNotifications", self.notificationsGroup.isChecked()) |
|
102 Preferences.setIrc("NotifyJoinPart", self.joinLeaveCheckBox.isChecked()) |
|
103 Preferences.setIrc("NotifyMessage", self.messageCheckBox.isChecked()) |
|
104 Preferences.setIrc("NotifyNick", self.ownNickCheckBox.isChecked()) |
|
105 |
|
106 # colours |
|
107 for key in self.ircColours: |
|
108 Preferences.setIrc(key, self.ircColours[key].name()) |
|
109 |
|
110 @pyqtSlot() |
|
111 def on_networkButton_clicked(self): |
|
112 """ |
|
113 Private slot to set the color for network messages. |
|
114 """ |
|
115 self.ircColours["NetworkMessageColour"] = \ |
|
116 self.selectColour(self.networkButton, |
|
117 self.ircColours["NetworkMessageColour"]) |
|
118 |
|
119 @pyqtSlot() |
|
120 def on_nickButton_clicked(self): |
|
121 """ |
|
122 Private slot to set the color for nick names. |
|
123 """ |
|
124 self.ircColours["NickColour"] = \ |
|
125 self.selectColour(self.nickButton, |
|
126 self.ircColours["NickColour"]) |
|
127 |
|
128 @pyqtSlot() |
|
129 def on_serverButton_clicked(self): |
|
130 """ |
|
131 Private slot to set the color for server messages. |
|
132 """ |
|
133 self.ircColours["ServerMessageColour"] = \ |
|
134 self.selectColour(self.serverButton, |
|
135 self.ircColours["ServerMessageColour"]) |
|
136 |
|
137 @pyqtSlot() |
|
138 def on_ownNickButton_clicked(self): |
|
139 """ |
|
140 Private slot to set the color for own nick name. |
|
141 """ |
|
142 self.ircColours["OwnNickColour"] = \ |
|
143 self.selectColour(self.ownNickButton, |
|
144 self.ircColours["OwnNickColour"]) |
|
145 |
|
146 @pyqtSlot() |
|
147 def on_channelButton_clicked(self): |
|
148 """ |
|
149 Private slot to set the color for channel messages. |
|
150 """ |
|
151 self.ircColours["ChannelMessageColour"] = \ |
|
152 self.selectColour(self.channelButton, |
|
153 self.ircColours["ChannelMessageColour"]) |
|
154 |
|
155 @pyqtSlot() |
|
156 def on_joinButton_clicked(self): |
|
157 """ |
|
158 Private slot to set the color for join events. |
|
159 """ |
|
160 self.ircColours["JoinChannelColour"] = \ |
|
161 self.selectColour(self.joinButton, |
|
162 self.ircColours["JoinChannelColour"]) |
|
163 |
|
164 @pyqtSlot() |
|
165 def on_errorButton_clicked(self): |
|
166 """ |
|
167 Private slot to set the color for error messages. |
|
168 """ |
|
169 self.ircColours["ErrorMessageColour"] = \ |
|
170 self.selectColour(self.errorButton, |
|
171 self.ircColours["ErrorMessageColour"]) |
|
172 |
|
173 @pyqtSlot() |
|
174 def on_leaveButton_clicked(self): |
|
175 """ |
|
176 Private slot to set the color for leave events. |
|
177 """ |
|
178 self.ircColours["LeaveChannelColour"] = \ |
|
179 self.selectColour(self.leaveButton, |
|
180 self.ircColours["LeaveChannelColour"]) |
|
181 |
|
182 @pyqtSlot() |
|
183 def on_timestampButton_clicked(self): |
|
184 """ |
|
185 Private slot to set the color for timestamps. |
|
186 """ |
|
187 self.ircColours["TimestampColour"] = \ |
|
188 self.selectColour(self.timestampButton, |
|
189 self.ircColours["TimestampColour"]) |
|
190 |
|
191 @pyqtSlot() |
|
192 def on_infoButton_clicked(self): |
|
193 """ |
|
194 Private slot to set the color for info messages. |
|
195 """ |
|
196 self.ircColours["ChannelInfoColour"] = \ |
|
197 self.selectColour(self.infoButton, |
|
198 self.ircColours["ChannelInfoColour"]) |
|
199 |
|
200 @pyqtSlot() |
|
201 def on_hyperlinkButton_clicked(self): |
|
202 """ |
|
203 Private slot to set the color for hyperlinks. |
|
204 """ |
|
205 self.ircColours["HyperlinkColour"] = \ |
|
206 self.selectColour(self.hyperlinkButton, |
|
207 self.ircColours["HyperlinkColour"]) |
|
208 |
|
209 |
|
210 def create(dlg): |
|
211 """ |
|
212 Module function to create the configuration page. |
|
213 |
|
214 @param dlg reference to the configuration dialog |
|
215 """ |
|
216 page = IrcPage() |
|
217 return page |