~ubuntu-branches/ubuntu/oneiric/rhythmbox/oneiric

« back to all changes in this revision

Viewing changes to plugins/lyrics/LyricsConfigureDialog.py

  • Committer: Bazaar Package Importer
  • Author(s): Rico Tzschichholz
  • Date: 2011-07-29 16:41:38 UTC
  • mto: This revision was merged to the branch mainline in revision 191.
  • Revision ID: james.westby@ubuntu.com-20110729164138-wwicy8nqalm18ck7
Tags: upstream-2.90.1~20110802
Import upstream version 2.90.1~20110802

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- Mode: python; coding: utf-8; tab-width: 8; indent-tabs-mode: t; -*-
 
2
#
 
3
# Copyright (C) 2007 James Livingston
 
4
# Copyright (C) 2007 Sirio Bolaños Puchet
 
5
#
 
6
# This program is free software; you can redistribute it and/or modify
 
7
# it under the terms of the GNU General Public License as published by
 
8
# the Free Software Foundation; either version 2, or (at your option)
 
9
# any later version.
 
10
#
 
11
# The Rhythmbox authors hereby grant permission for non-GPL compatible
 
12
# GStreamer plugins to be used and distributed together with GStreamer
 
13
# and Rhythmbox. This permission is above and beyond the permissions granted
 
14
# by the GPL license by which Rhythmbox is covered. If you modify this code
 
15
# you may extend this exception to your version of the code, but you are not
 
16
# obligated to do so. If you do not wish to do so, delete this exception
 
17
# statement from your version.
 
18
#
 
19
# This program is distributed in the hope that it will be useful,
 
20
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
21
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
22
# GNU General Public License for more details.
 
23
#
 
24
# You should have received a copy of the GNU General Public License
 
25
# along with this program; if not, write to the Free Software
 
26
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA.
 
27
 
 
28
from LyricsSites import lyrics_sites
 
29
 
 
30
import gobject
 
31
from os import system, path
 
32
 
 
33
import rb
 
34
from gi.repository import Gtk, Gio, GObject, PeasGtk
 
35
 
 
36
class LyricsConfigureDialog (GObject.Object, PeasGtk.Configurable):
 
37
        __gtype_name__ = 'LyricsConfigureDialog'
 
38
        object = GObject.property(type=GObject.Object)
 
39
 
 
40
        def __init__(self):
 
41
                GObject.Object.__init__(self)
 
42
                self.settings = Gio.Settings("org.gnome.rhythmbox.plugins.lyrics")
 
43
 
 
44
        def do_create_configure_widget(self):
 
45
                builder = Gtk.Builder()
 
46
                builder.add_from_file(rb.find_plugin_file(self, "lyrics-prefs.ui"))
 
47
 
 
48
                self.config = builder.get_object("config")
 
49
 
 
50
                self.choose_button = builder.get_object("choose_button")
 
51
                self.path_display = builder.get_object("path_display")
 
52
 
 
53
                self.choose_button.connect("clicked", self.choose_callback)
 
54
 
 
55
                engines, self.folder = self.get_prefs()
 
56
                if self.folder is None:
 
57
                        self.folder = '~/.lyrics'
 
58
                self.path_display.set_text(self.folder)
 
59
 
 
60
                # build site list
 
61
                site_box = builder.get_object("sites")
 
62
                self.site_checks = {}
 
63
                for s in lyrics_sites:
 
64
                        site_id = s['id']
 
65
                        checkbutton = Gtk.CheckButton(label = s['name'])
 
66
                        checkbutton.set_active(s['id'] in engines)
 
67
                        self.site_checks[site_id] = checkbutton
 
68
                        site_box.pack_start(checkbutton, True, True, 0)
 
69
 
 
70
                site_box.show_all()
 
71
 
 
72
                return self.config
 
73
 
 
74
        def set_values(self):
 
75
                sites = []
 
76
                for s in lyrics_sites:
 
77
                        check = self.site_checks[s['id']]
 
78
                        if check is None:
 
79
                                continue
 
80
 
 
81
                        if check.get_active():
 
82
                                sites.append(s['id'])
 
83
 
 
84
                if len(self.path_display.get_text()) is not 0:
 
85
                        self.folder = self.path_display.get_text()
 
86
 
 
87
                self.settings['sites'] = sites
 
88
                self.settings['folder'] = self.folder
 
89
 
 
90
        def choose_callback(self, widget):
 
91
                def response_handler(widget, response):
 
92
                        if response == Gtk.ResponseType.OK:
 
93
                                path = self.chooser.get_filename()
 
94
                                self.chooser.destroy()
 
95
                                self.path_display.set_text(path)
 
96
                        else:
 
97
                                self.chooser.destroy()
 
98
 
 
99
                buttons = (Gtk.STOCK_CLOSE, Gtk.ResponseTypeCLOSE,
 
100
                                Gtk.STOCK_OK, Gtk.ResponseType.OK)
 
101
                self.chooser = Gtk.FileChooserDialog(title=_("Choose lyrics folder..."),
 
102
                                        parent=None,
 
103
                                        action=Gtk.FileChooserAction.SELECT_FOLDER,
 
104
                                        buttons=buttons)
 
105
                self.chooser.connect("response", response_handler)
 
106
                self.chooser.set_modal(True)
 
107
                self.chooser.set_transient_for(self.dialog)
 
108
                self.chooser.present()
 
109
 
 
110
        def get_prefs (self):
 
111
                try:
 
112
                        sites = self.settings['sites']
 
113
                except gobject.GError, e:
 
114
                        print e
 
115
                        engines = []
 
116
                folder = self.settings['folder']
 
117
 
 
118
                print "lyric sites: " + str (sites)
 
119
                print "lyric folder: " + folder
 
120
                return (sites, folder)