58
59
'filter', self.customStatus.customStatusParser)
59
60
self.controller.emit('preferences-changed')
60
61
self.customStatus.unsetCustomStatus()
62
self.customStatus.register_slash_commands()
63
statusMenuItem = gtk.MenuItem (_('Custom status...'), False)
64
statusMenuItem.connect("activate", self.on_status_menu_activated)
65
self.controller.mainWindow.userPanel.statusMenu.add(statusMenuItem)
61
66
self.enabled = True
64
69
self.disconnect(self.onStatusChangeId)
65
70
self.controller.unifiedParser.disconnect(self.customStatusParserId)
71
self.customStatus.unregister_slash_commands()
66
72
self.enabled = False
72
78
CustomStatusDialog(self.customStatus, DIALOG_TYPE_CONFIG).run()
81
def on_status_menu_activated(self, item):
82
self.customStatus.statusChanged(None, "AWY")
76
84
class CustomStatus:
133
142
# We temporary block custom status changing to avoid double-dialog
134
143
self.doChange = False
136
response = CustomStatusDialog(self, DIALOG_TYPE_SET, status).run()
145
response = CustomStatusDialog(self, DIALOG_TYPE_SET, status, "status_changed").run()
137
146
if response != None:
138
147
status_type, status_name,\
139
automessage, automessage_text = response
148
automessage, automessage_text, slash_command = response
140
149
self.setCustomStatus(status_type, status_name,\
141
150
automessage, automessage_text)
142
151
# We enable again custom status changing
155
164
if automessage_enabled and autoreply_message != '':
156
165
self.controller.config.user['autoReply'] = True
157
self.controller.mainWindow.menu.activateAutoReply.set_active(True)
158
166
self.controller.autoReplyMessage = autoreply_message
159
167
self.controller.config.user['autoReplyMessage'] = autoreply_message
166
174
if self.msn.getNick() != newnick:
167
175
self.msn.changeNick(statusTag.sub('', self.msn.getNick()))
168
176
self.controller.config.user['autoReply'] = False
169
self.controller.mainWindow.menu.activateAutoReply.set_active(False)
171
178
def loadSavedStatus(self):
172
179
'''Method that loads saved custom statuses. It returns a list of lists
173
[statustype, statusname, autoreplyenabled, autoreplymessage]'''
180
[statustype, statusname, autoreplyenabled, autoreplymessage, slashcommand]'''
175
182
numStatus = self.config.getPluginValue(self.name,\
176
183
'custom_status_count', 0)
187
194
'cAR'+str(i), None)
188
195
cARMessage = self.config.getPluginValue(self.name,\
189
196
'cARMessage'+str(i), None)
197
cCommand = self.config.getPluginValue(self.name, \
198
'cCommand'+str(i), "")
191
200
if not (cStatus == None or cName == None or \
192
201
cAR == None or cARMessage == None):
193
data.append([cStatus,cName,bool(int(cAR)),cARMessage])
202
data.append([cStatus,cName,bool(int(cAR)),cARMessage, cCommand])
204
213
str(int(data[i][2])))
205
214
self.config.setPluginValue(self.name, 'cARMessage'+str(i), \
216
self.config.setPluginValue(self.name, 'cCommand'+str(i), \
208
219
# We need to update custom statuses count
209
220
self.config.setPluginValue(self.name, 'custom_status_count', len(data))
222
def register_slash_commands(self):
223
numStatus = self.config.getPluginValue(self.name,\
224
'custom_status_count', 0)
225
for i in range(int(numStatus)):
226
cCommand = self.config.getPluginValue(self.name, \
227
'cCommand'+str(i), None)
228
if not ((cCommand == None) or (cCommand == "")):
229
self.slash.register(cCommand, self.on_slash_command, \
230
_("Applies a custom status"))
232
def unregister_slash_commands(self):
233
numStatus = self.config.getPluginValue(self.name,\
234
'custom_status_count', 0)
235
for i in range(int(numStatus)):
236
cCommand = self.config.getPluginValue(self.name, \
237
'cCommand'+str(i), None)
238
if not ((cCommand == None) or (cCommand == "")):
239
self.slash.unregister(cCommand)
241
#search for al the custom statuses the one that matches the slash command
242
def on_slash_command(self, slash_action):
243
self.doChange = False
244
data = self.loadSavedStatus()
245
for i in data: #search every status
246
if i[4] == slash_action.name: #if slash_command = custom status command
247
self.setCustomStatus(i[0],i[1],i[2],i[3]) #change status
212
251
class CustomStatusDialog(gtk.Dialog):
218
257
def __init__(self, customStatus, dialog_type=DIALOG_TYPE_SET, \
219
current_status=None):
258
current_status=None, source=""):
220
259
'''Constructor'''
222
261
gtk.Dialog.__init__(self , _('Custom status setting'), None, \
229
268
self.controller = self.customStatus.controller
231
270
self.set_position(gtk.WIN_POS_CENTER_ON_PARENT)
232
self.set_resizable(False)
233
self.set_border_width(12)
271
self.set_size_request(550,-1)
272
self.set_resizable(True)
273
self.set_border_width(10)
234
274
self.set_has_separator(False)
235
self.vbox.set_spacing(20)
275
self.vbox.set_spacing(15)
277
#if the dialog appears changing status, the timer starts
278
#if the dialog is open with the Configure button in plugins manager, no timer
279
if source == "status_changed":
281
self.title_text = _('Custom status setting - Closing in: %ds')
282
text = self.title_text % self.timer_time
283
self.set_property("title",text)
284
self.timer = gobject.timeout_add(1000,self.updateTimer)
285
self.set_focus_on_map(False) #dialog appears unfocused
286
self.connect('focus-in-event', self.disableTimer) #when focused, stop the timer
237
288
# We load the saved custom statuses
238
289
self.data = self.customStatus.loadSavedStatus()
253
304
self.connect('delete-event', self.closeCancel)
254
self.create_panel.custom_status.connect('activate', self.closeOk)
305
self.create_panel.custom_status.connect('activate', self.closeAccept)
255
306
self.create_panel.custom_autoreply_message.connect(\
256
'activate', self.closeOk)
307
'activate', self.closeAccept)
257
308
self.select_panel.btn_add.connect('clicked', self.addStatus)
258
309
self.select_panel.btn_remove.connect('clicked', self.delStatus)
259
310
if dialog_type == DIALOG_TYPE_SET:
270
321
if status == None:
273
status_type,status_name, automessage, automessage_text = status
324
status_type,status_name, automessage, automessage_text, command = status
274
325
if automessage == False:
275
326
automessage_text = ''
276
327
self.select_panel.data.append([status_type, status_name, \
277
automessage, automessage_text])
328
automessage, automessage_text, command])
278
329
self.select_panel.treeview.addStatusRow(status_type, status_name, \
279
automessage,automessage_text)
330
automessage,automessage_text,command)
280
331
self.create_panel.clear()
282
333
def delStatus(self, *args):
296
347
self.dataOK = self.data[view_column[0]]
297
348
self.response(gtk.RESPONSE_OK)
299
def closeOk(self, *args):
300
'''Click on OK button'''
350
def closeAccept(self, *args):
351
'''Click on Accept button'''
301
352
self.response(gtk.RESPONSE_ACCEPT)
303
354
def closeCancel(self, *args):
308
359
'''Method that manage the open and close of the dialog.'''
309
360
response = gtk.Dialog.run(self)
312
363
# If we want to enable a custom status...
313
364
if response == gtk.RESPONSE_ACCEPT or response == gtk.RESPONSE_OK:
365
self.customStatus.unregister_slash_commands()
314
367
# We save the configuration
315
368
self.customStatus.saveSavedStatus(self.select_panel.data)
370
self.customStatus.register_slash_commands()
317
372
# We return the list containing choosed status settings.
318
373
# If response is ACCEPT we use form data, else we use treeview data
319
374
if response == gtk.RESPONSE_ACCEPT:
320
375
return (self.create_panel.getStatus())
322
377
# ... or if we click on Cancel button
381
#this method updates the title of the dialog if the timer is running
382
def updateTimer(self):
383
self.timer_time = self.timer_time - 1
384
text = self.title_text % self.timer_time
385
self.set_property("title", text)
386
if self.timer_time == 0:
392
#disable the timer and change the title bar
393
def disableTimer(self, widget, event):
395
gobject.source_remove(self.timer)
396
self.set_property("title", _('Custom status setting'))
327
398
class CustomStatusTreeView(gtk.TreeView):
333
404
def __init__(self, controller, data):
334
405
'''Constructor'''
336
self.liststore = gtk.ListStore(str, str, bool, str)
407
self.liststore = gtk.ListStore(str, str, bool, str, str)
337
408
self.controller = controller
344
415
cell1 = gtk.CellRendererText()
345
416
cell2 = gtk.CellRendererToggle()
346
417
cell3 = gtk.CellRendererText()
418
cell4 = gtk.CellRendererText()
348
420
cell1.set_property('editable', True)
349
421
cell1.connect('edited', self.onEdited, self.liststore, 1)
351
423
cell2.connect('toggled', self.onToggled, self.liststore, 2)
352
424
cell3.set_property('editable', True)
353
425
cell3.connect('edited', self.onEdited, self.liststore, 3)
426
cell4.set_property('editable', True)
427
cell4.connect('edited', self.onEdited, self.liststore, 4)
356
430
col0 = gtk.TreeViewColumn(_('Status'), cell0)
358
432
col1 = gtk.TreeViewColumn(_('Status Name'), cell1, text=1)
359
433
col2 = gtk.TreeViewColumn(_('A.R.'), cell2, active=2)
360
434
col3 = gtk.TreeViewColumn(_('Autoreply message'), cell3, text=3)
435
col4 = gtk.TreeViewColumn(_('Command'), cell4, text=4)
362
437
col1.set_resizable(True)
363
438
col3.set_resizable(True)
439
col4.set_resizable(True)
365
441
self.append_column(col0)
366
442
self.append_column(col1)
367
443
self.append_column(col2)
368
444
self.append_column(col3)
445
self.append_column(col4)
370
447
# We add the data to the table
371
448
for item in self.data:
372
449
self.liststore.append(item)
374
def addStatusRow(self, status, status_name, automessage, automessage_text):
451
def addStatusRow(self, status, status_name, automessage, automessage_text, command):
375
452
'''Method that adds a row to the table using the liststore object'''
376
453
self.liststore.append([status, status_name, \
377
automessage, automessage_text])
454
automessage, automessage_text, command])
379
456
def getSelectedRow(self):
380
457
'''Method that returns the currently selected row'''
579
656
self.status_type.get_active_iter()])[0], \
580
657
self.custom_status.get_text().strip(), \
581
658
self.custom_autoreply_checkbox.get_active(), \
582
self.custom_autoreply_message.get_text().strip())
659
self.custom_autoreply_message.get_text().strip(),"")
584
661
def enableAutoreply (self, *args):
585
662
'''Method that enables autoreply text entry'''