1 # -*- coding: utf-8 -*-
3 # gPodder - A media aggregator and podcast client
4 # Copyright (c) 2005-2010 Thomas Perl and the gPodder Team
6 # gPodder 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 3 of the License, or
9 # (at your option) any later version.
11 # gPodder is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
27 from gpodder
import util
29 from gpodder
.gtkui
.interface
.common
import BuilderWidget
30 from gpodder
.gtkui
.frmntl
.portrait
import FremantleRotation
34 class gPodderPreferences(BuilderWidget
):
37 (20, N_('Every %(count)d minute', 'Every %(count)d minutes', 20) % {'count':20}),
39 (60*6, N_('Every %(count)d hour', 'Every %(count)d hours', 6) % {'count':6}),
44 ('quiet', _('Do nothing')),
45 ('never', _('Show episode list')),
46 ('queue', _('Add to download list')),
47 # ('wifi', _('Download when on Wi-Fi')),
48 ('always', _('Download immediately')),
52 ('default', _('Media Player')),
53 ('panucci', _('Panucci')),
54 ('MediaBox', _('MediaBox')),
58 ('default', _('Media Player')),
59 ('mplayer', _('MPlayer')),
60 ('MediaBox', _('MediaBox')),
64 # Store the current configuration options in case we cancel later
65 self
._config
_backup
= self
._config
.get_backup()
66 self
._do
_restore
_config
= True
67 self
.main_window
.connect('destroy', self
.on_destroy
)
69 self
.save_button
= self
.main_window
.add_button(gtk
.STOCK_SAVE
, 1)
70 self
.save_button
.connect('clicked', self
.on_save_button_clicked
)
72 self
.touch_selector_orientation
= hildon
.TouchSelector(text
=True)
73 for caption
in FremantleRotation
.MODE_CAPTIONS
:
74 self
.touch_selector_orientation
.append_text(caption
)
75 self
.touch_selector_orientation
.set_active(0, self
._config
.rotation_mode
)
76 self
.picker_orientation
.set_selector(self
.touch_selector_orientation
)
78 if not self
._config
.auto_update_feeds
:
79 self
._config
.auto_update_frequency
= 0
81 # Create a mapping from minute values to touch selector indices
82 minute_index_mapping
= dict((b
, a
) for a
, b
in enumerate(x
[0] for x
in self
.UPDATE_INTERVALS
))
84 self
.touch_selector_interval
= hildon
.TouchSelector(text
=True)
85 for value
, caption
in self
.UPDATE_INTERVALS
:
86 self
.touch_selector_interval
.append_text(caption
)
87 interval
= self
._config
.auto_update_frequency
88 if interval
in minute_index_mapping
:
89 self
._custom
_interval
= 0
90 self
.touch_selector_interval
.set_active(0, minute_index_mapping
[interval
])
92 self
._custom
_interval
= self
._config
.auto_update_frequency
93 self
.touch_selector_interval
.append_text(N_('Every %(count)d minute', 'Every %(count)d minutes', interval
) % {'count':interval
})
94 self
.touch_selector_interval
.set_active(0, len(self
.UPDATE_INTERVALS
))
95 self
.picker_interval
.set_selector(self
.touch_selector_interval
)
97 # Create a mapping from download methods to touch selector indices
98 download_method_mapping
= dict((b
, a
) for a
, b
in enumerate(x
[0] for x
in self
.DOWNLOAD_METHODS
))
100 self
.touch_selector_download
= hildon
.TouchSelector(text
=True)
101 for value
, caption
in self
.DOWNLOAD_METHODS
:
102 self
.touch_selector_download
.append_text(caption
)
104 if self
._config
.auto_download
not in (x
[0] for x
in self
.DOWNLOAD_METHODS
):
105 self
._config
.auto_download
= self
.DOWNLOAD_METHODS
[0][0]
107 self
.touch_selector_download
.set_active(0, download_method_mapping
[self
._config
.auto_download
])
108 self
.picker_download
.set_selector(self
.touch_selector_download
)
110 # Determine possible audio and video players (only installed ones)
111 self
.audio_players
= [(c
, l
) for c
, l
in self
.AUDIO_PLAYERS
if c
== 'default' or util
.find_command(c
)]
112 self
.video_players
= [(c
, l
) for c
, l
in self
.VIDEO_PLAYERS
if c
== 'default' or util
.find_command(c
)]
114 # Create a mapping from audio players to touch selector indices
115 audio_player_mapping
= dict((b
, a
) for a
, b
in enumerate(x
[0] for x
in self
.audio_players
))
117 self
.touch_selector_audio_player
= hildon
.TouchSelector(text
=True)
118 for value
, caption
in self
.audio_players
:
119 self
.touch_selector_audio_player
.append_text(caption
)
121 if self
._config
.player
not in (x
[0] for x
in self
.audio_players
):
122 self
._config
.player
= self
.audio_players
[0][0]
124 self
.touch_selector_audio_player
.set_active(0, audio_player_mapping
[self
._config
.player
])
125 self
.picker_audio_player
.set_selector(self
.touch_selector_audio_player
)
127 # Create a mapping from video players to touch selector indices
128 video_player_mapping
= dict((b
, a
) for a
, b
in enumerate(x
[0] for x
in self
.video_players
))
130 self
.touch_selector_video_player
= hildon
.TouchSelector(text
=True)
131 for value
, caption
in self
.video_players
:
132 self
.touch_selector_video_player
.append_text(caption
)
134 if self
._config
.videoplayer
not in (x
[0] for x
in self
.video_players
):
135 self
._config
.videoplayer
= self
.video_players
[0][0]
137 self
.touch_selector_video_player
.set_active(0, video_player_mapping
[self
._config
.videoplayer
])
138 self
.picker_video_player
.set_selector(self
.touch_selector_video_player
)
140 # Fix the styling and layout of the picker buttons
141 for button
in (self
.picker_orientation
, \
142 self
.picker_interval
, \
143 self
.picker_download
, \
144 self
.picker_audio_player
, \
145 self
.picker_video_player
):
146 # Work around Maemo bug #4718
147 button
.set_name('HildonButton-finger')
148 # Fix alignment problems (Maemo bug #6205)
149 button
.set_alignment(.0, .5, 1., 0.)
150 child
= button
.get_child()
151 child
.set_padding(0, 0, 12, 0)
153 self
.button_enable_mygpo
.set_name('HildonCheckButton-finger')
155 self
.check_view_all_episodes
= hildon
.CheckButton(gtk
.HILDON_SIZE_FINGER_HEIGHT
)
156 self
.check_view_all_episodes
.set_label(_('Show "All episodes" view'))
157 self
.check_view_all_episodes
.set_active(self
._config
.podcast_list_view_all
)
158 self
.pannable_vbox
.add(self
.check_view_all_episodes
)
159 self
.pannable_vbox
.reorder_child(self
.check_view_all_episodes
, 2)
161 # Disable capitalization word completion
162 self
.entry_mygpo_username
.set_property('hildon-input-mode', \
163 gtk
.HILDON_GTK_INPUT_MODE_FULL
)
164 self
.entry_mygpo_password
.set_property('hildon-input-mode', \
165 gtk
.HILDON_GTK_INPUT_MODE_FULL
)
167 self
.entry_mygpo_password
.set_visibility(False)
169 self
.button_enable_mygpo
.set_active(self
._config
.mygpo_enabled
)
170 self
.entry_mygpo_username
.set_text(self
._config
.mygpo_username
)
171 self
.entry_mygpo_password
.set_text(self
._config
.mygpo_password
)
172 self
.entry_mygpo_device
.set_text(self
._config
.mygpo_device_caption
)
174 if self
._config
.auto_remove_played_episodes
:
175 adjustment_expiration
= self
.hscale_expiration
.get_adjustment()
176 if self
._config
.episode_old_age
> adjustment_expiration
.upper
:
177 # Patch the adjustment to include the higher current value
178 adjustment_expiration
.upper
= self
._config
.episode_old_age
180 self
.hscale_expiration
.set_value(self
._config
.episode_old_age
)
182 self
.hscale_expiration
.set_value(0)
184 self
.gPodderPreferences
.show_all()
186 def on_picker_orientation_value_changed(self
, *args
):
187 self
._config
.rotation_mode
= self
.touch_selector_orientation
.get_active(0)
189 def on_picker_interval_value_changed(self
, *args
):
190 active_index
= self
.touch_selector_interval
.get_active(0)
191 if active_index
< len(self
.UPDATE_INTERVALS
):
192 new_frequency
= self
.UPDATE_INTERVALS
[active_index
][0]
194 new_frequency
= self
._custom
_interval
196 if new_frequency
== 0:
197 self
._config
.auto_update_feeds
= False
198 self
._config
.auto_update_frequency
= new_frequency
199 if new_frequency
> 0:
200 self
._config
.auto_update_feeds
= True
202 def on_picker_download_value_changed(self
, *args
):
203 active_index
= self
.touch_selector_download
.get_active(0)
204 new_value
= self
.DOWNLOAD_METHODS
[active_index
][0]
205 self
._config
.auto_download
= new_value
207 def on_picker_audio_player_value_changed(self
, *args
):
208 active_index
= self
.touch_selector_audio_player
.get_active(0)
209 new_value
= self
.audio_players
[active_index
][0]
210 self
._config
.player
= new_value
212 def on_picker_video_player_value_changed(self
, *args
):
213 active_index
= self
.touch_selector_video_player
.get_active(0)
214 new_value
= self
.video_players
[active_index
][0]
215 self
._config
.videoplayer
= new_value
217 def on_destroy(self
, window
):
218 if self
._do
_restore
_config
:
219 self
._config
.restore_backup(self
._config
_backup
)
221 self
._config
.podcast_list_view_all
= self
.check_view_all_episodes
.get_active()
222 self
._config
.mygpo_enabled
= self
.button_enable_mygpo
.get_active()
223 self
._config
.mygpo_username
= self
.entry_mygpo_username
.get_text()
224 self
._config
.mygpo_password
= self
.entry_mygpo_password
.get_text()
225 self
._config
.mygpo_device_caption
= self
.entry_mygpo_device
.get_text()
227 # Make sure the device is successfully created/updated
228 self
.mygpo_client
.create_device()
229 # Flush settings for mygpo client now
230 self
.mygpo_client
.flush(now
=True)
232 self
.callback_finished()
234 def on_save_button_clicked(self
, button
):
235 self
._do
_restore
_config
= False
236 self
.main_window
.destroy()
238 def format_expiration_value(self
, scale
, value
):
243 return N_('after %(count)d day', 'after %(count)d days', value
) % {'count':value
}
245 def on_expiration_value_changed(self
, range):
246 value
= int(range.get_value())
249 self
._config
.auto_remove_played_episodes
= False
251 self
._config
.auto_remove_played_episodes
= True
252 self
._config
.episode_old_age
= value
254 self
._config
.auto_remove_unplayed_episodes
= False