Bump to 0.8.12
[nqaap] / src / settings.py
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3
4 """
5 This file is part of Multilist.
6
7 Multilist is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11
12 Multilist is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with Multilist.  If not, see <http://www.gnu.org/licenses/>.
19
20 Copyright (C) 2008 Christoph Würstle
21 """
22
23 import logging
24
25 import gtk
26
27 import hildonize
28 import gtk_toolbox
29
30 try:
31         _
32 except NameError:
33         _ = lambda x: x
34
35
36 _moduleLogger = logging.getLogger(__name__)
37
38
39 class SettingsDialog(object):
40
41         def __init__(self, parent):
42                 self.window = None
43
44                 self.__isPortraitCheckbutton = gtk.CheckButton("Portrait Mode")
45
46                 self.__rotationSection = gtk.VBox()
47                 self.__rotationSection.pack_start(self.__isPortraitCheckbutton, False, True)
48
49                 rotationFrame = gtk.Frame("Rotation")
50                 rotationFrame.add(self.__rotationSection)
51
52                 self.__audioBooksPath = gtk.Entry()
53                 self.__audioBooksPathButton = gtk.Button("Choose")
54                 self.__audioBooksPathButton.connect("clicked", self._on_path_choose)
55
56                 self.__audiobookPathSection = gtk.HBox()
57                 self.__audiobookPathSection.pack_start(self.__audioBooksPath, True, True)
58                 self.__audiobookPathSection.pack_start(self.__audioBooksPathButton, False, True)
59
60                 self.__audiobookSection = gtk.VBox()
61                 self.__audiobookSection.pack_start(self.__audiobookPathSection)
62
63                 audiobookFrame = gtk.Frame("Audiobooks")
64                 audiobookFrame.add(self.__audiobookSection)
65
66                 settingsBox = gtk.VBox()
67                 settingsBox.pack_start(rotationFrame, False, True)
68                 settingsBox.pack_start(audiobookFrame, False, True)
69                 settingsView = gtk.Viewport()
70                 settingsView.add(settingsBox)
71                 settingsScrollView = gtk.ScrolledWindow()
72                 settingsScrollView.add(settingsView)
73                 settingsScrollView.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
74                 parent.pack_start(settingsScrollView, True, True)
75
76                 settingsScrollView = hildonize.hildonize_scrollwindow(settingsScrollView)
77
78         def set_portrait_state(self, isPortrait):
79                 self.__isPortraitCheckbutton.set_active(isPortrait)
80
81         def is_portrait(self):
82                 return self.__isPortraitCheckbutton.get_active()
83
84         def set_audiobook_path(self, path):
85                 self.__audioBooksPath.set_text(path)
86
87         def get_audiobook_path(self):
88                 return self.__audioBooksPath.get_text()
89
90         @gtk_toolbox.log_exception(_moduleLogger)
91         def _on_path_choose(self, *args):
92                 fileChooser = gtk.FileChooserDialog(
93                         title="Audiobooks",
94                         action=gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER,
95                         parent=self.window,
96                 )
97                 fileChooser.add_button(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL)
98                 fileChooser.add_button(gtk.STOCK_OK, gtk.RESPONSE_OK)
99                 fileChooser.set_filename(self.__audioBooksPath.get_text())
100                 userResponse = fileChooser.run()
101                 fileChooser.hide()
102                 if userResponse == gtk.RESPONSE_OK:
103                         filename = fileChooser.get_filename()
104                         self.__audioBooksPath.set_text(filename)