~eduardo-mucelli/rhythmidgin/trunk

« back to all changes in this revision

Viewing changes to __init__.py

  • Committer: eduardo-mucelli
  • Date: 2010-08-13 01:08:24 UTC
  • Revision ID: edumucelli@gmail.com-20100813010824-3nfslpaswg3t4bms
Get the preferences values persistent because they were not being saved between executions.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
#
3
3
# Author: Eduardo Mucelli Rezende Oliveira
4
4
# E-mail: edumucelli@gmail.com or eduardom@dcc.ufmg.br
5
 
# Version: 0.0.3
 
5
# Version: 0.0.4
6
6
#
7
7
# This program is free software: you can redistribute it and/or modify
8
8
#    it under the terms of the GNU General Public License as published by
25
25
import os.path, gettext
26
26
import dbus
27
27
 
 
28
# mantem os valores escolhidos pelo usuario para as proximas execucoes
 
29
gconf_keys = {
 
30
        'show_song_title'   : '/apps/rhythmbox/plugins/rhythmidgin/show_song_title',
 
31
        'show_song_artist'  : '/apps/rhythmbox/plugins/rhythmidgin/show_song_artist',
 
32
        'show_song_album'   : '/apps/rhythmbox/plugins/rhythmidgin/show_song_album'
 
33
}
 
34
 
28
35
# o XML que define os botoes da barra de menus, do menu Controle, e a acao que sera mapeada para eles
29
36
ui_str = \
30
37
        """
103
110
        gtk.gdk.threads_enter()
104
111
        connected = self.establish_dbus_connection()
105
112
        if not connected:                                                                               # enquanto nao conectar ao Pidgin vai voltar
106
 
                gtk.gdk.threads_leave()
107
 
                return True
 
113
            gtk.gdk.threads_leave()
 
114
            return True
108
115
        else:                                                                                           # conectou-se ao Pidgin
109
116
            if (self.song):                                                                             # ha musica tocando ...
110
117
                self.set_message()                                                                      # ... informar a msg de status no Pidgin
181
188
        self.song = None
182
189
        
183
190
        # default values that can be changed through the Preferences dialog
184
 
        self.show_song_title = True                                                                     
185
 
        self.show_song_artist = True
186
 
        self.show_song_album = False
 
191
        client = gconf.client_get_default()
 
192
        # recupera os valores dos checkboxes da execucao anterior que ficaram guardados em ~/.gconf/apps/rhythmbox/plugins/rhythmidgin/
 
193
        self.show_song_title = client.get_bool(gconf_keys['show_song_title'])
 
194
        self.show_song_artist = client.get_bool(gconf_keys['show_song_artist'])
 
195
        self.show_song_album = client.get_bool(gconf_keys['show_song_album'])
187
196
        
188
197
        self.load_local_language()
189
198
        self.load_icon()                                                                                # necessary load icon first ...
217
226
    def log (self, string):
218
227
        print "Rhythmidgin: %s" % string
219
228
 
220
 
# Class que lida com a interface da janela de preferencias, pega os valores e recebe o sinal
 
229
# Classe que lida com a interface da janela de preferencias, pega os valores e recebe o sinal
221
230
class RhythmidginPreferencesDialog (object):
222
231
    def __init__(self, plugin, glade_file):
223
232
        self.plugin = plugin
224
 
        self.gconf = gconf.client_get_default()
225
233
        gladexml = gtk.glade.XML(glade_file)
226
234
 
227
 
        self.dialog = gladexml.get_widget('preferences_dialog')                                        # the rhythmidgin-preferences.glade main id
228
 
        self.show_song_title = gladexml.get_widget('chk_show_song_title')                              # checkbox
229
 
        self.show_song_artist = gladexml.get_widget('chk_show_song_artist')                            # checkbox
230
 
        self.show_song_album = gladexml.get_widget('chk_show_song_album')                              # checkbox
 
235
        gladexml.signal_autoconnect({                                                                   # ver os sinais definidos para os botoes, xml
 
236
            'on_cancelbtn_clicked': self.on_cancel_clicked,
 
237
            'on_okbtn_clicked': self.on_ok_clicked
 
238
                })
231
239
 
232
 
        self.dialog.connect("response", self.dialog_response)
 
240
        self.dialog = gladexml.get_widget('preferences_dialog')                                         # the rhythmidgin-preferences.glade main id
 
241
        gladexml.get_widget('chk_show_song_title').set_active(self.plugin.show_song_title)
 
242
        gladexml.get_widget('chk_show_song_artist').set_active(self.plugin.show_song_artist)
 
243
        gladexml.get_widget('chk_show_song_album').set_active(self.plugin.show_song_album)
 
244
        self.chk_show_song_title = gladexml.get_widget('chk_show_song_title')                           # checkbox
 
245
        self.chk_show_song_artist = gladexml.get_widget('chk_show_song_artist')                         # checkbox
 
246
        self.chk_show_song_album = gladexml.get_widget('chk_show_song_album')                           # checkbox
233
247
 
234
248
    def get_dialog (self):
235
249
        return self.dialog
236
250
 
237
 
    def dialog_response (self, dialog, response):
238
 
        self.plugin.show_song_title = self.show_song_title.get_active()                                 # ve se o checkbox esta marcado
239
 
        self.plugin.show_song_artist = self.show_song_artist.get_active()
240
 
        self.plugin.show_song_album = self.show_song_album.get_active()
241
 
        dialog.hide()
 
251
    def on_ok_clicked (self, dialog, response=None):
 
252
        self.plugin.show_song_title = self.chk_show_song_title.get_active()                             # ve se o checkbox esta marcado
 
253
        self.plugin.show_song_artist = self.chk_show_song_artist.get_active()
 
254
        self.plugin.show_song_album = self.chk_show_song_album.get_active()
 
255
        client = gconf.client_get_default()
 
256
        client.set_bool(gconf_keys['show_song_title'], self.plugin.show_song_title)                     # seta os campos para a proxima execucao
 
257
        client.set_bool(gconf_keys['show_song_artist'], self.plugin.show_song_artist)
 
258
        client.set_bool(gconf_keys['show_song_album'], self.plugin.show_song_album)
 
259
        self.dialog.destroy()
 
260
 
 
261
    def on_cancel_clicked (self, dialog, response=None):
 
262
        self.dialog.destroy()