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/>.
26 from gpodder
.gtkui
.interface
.common
import BuilderWidget
28 from gpodder
import util
31 class gPodderAddPodcast(BuilderWidget
):
32 finger_friendly_widgets
= ['btn_close', 'btn_add' 'btn_paste']
35 if not hasattr(self
, 'add_urls_callback'):
36 self
.add_urls_callback
= None
37 if hasattr(self
, 'custom_label'):
38 self
.label_add
.set_text(self
.custom_label
)
39 if hasattr(self
, 'custom_title'):
40 self
.gPodderAddPodcast
.set_title(self
.custom_title
)
41 if hasattr(self
, 'preset_url'):
42 self
.entry_url
.set_text(self
.preset_url
)
43 self
.entry_url
.connect('activate', self
.on_entry_url_activate
)
44 if gpodder
.ui
.fremantle
:
45 self
.btn_add
= self
.main_window
.add_button(gtk
.STOCK_ADD
, 0)
46 self
.btn_add
.connect('clicked', self
.on_btn_add_clicked
)
47 self
.on_entry_url_changed(self
.entry_url
) # for sensitivity
48 self
.btn_add
.show_all()
49 # Deactivate capitalization and word completion (Maemo bug 5184)
50 self
.entry_url
.set_property('hildon-input-mode', \
51 gtk
.HILDON_GTK_INPUT_MODE_FULL
)
52 elif gpodder
.ui
.diablo
:
53 self
.entry_url
.set_property('hildon-input-mode', \
54 'HILDON_GTK_INPUT_MODE_FULL')
55 self
.gPodderAddPodcast
.show()
57 if not hasattr(self
, 'preset_url'):
58 # Fill the entry if a valid URL is in the clipboard, but
59 # only if there's no preset_url available (see bug 1132)
60 clipboard
= gtk
.Clipboard(selection
='PRIMARY')
61 def receive_clipboard_text(clipboard
, text
, second_try
):
62 # Heuristic: If there is a space in the clipboard
63 # text, assume it's some arbitrary text, and no URL
64 if text
is not None and ' ' not in text
:
65 url
= util
.normalize_feed_url(text
)
67 self
.entry_url
.set_text(url
)
68 self
.entry_url
.set_position(-1)
72 clipboard
= gtk
.Clipboard()
73 clipboard
.request_text(receive_clipboard_text
, True)
74 clipboard
.request_text(receive_clipboard_text
, False)
76 def on_btn_close_clicked(self
, widget
):
77 self
.gPodderAddPodcast
.destroy()
79 def on_btn_paste_clicked(self
, widget
):
80 clipboard
= gtk
.Clipboard()
81 clipboard
.request_text(self
.receive_clipboard_text
)
83 def receive_clipboard_text(self
, clipboard
, text
, data
=None):
85 self
.entry_url
.set_text(text
)
87 self
.show_message(_('Nothing to paste.'), _('Clipboard is empty'))
89 def on_entry_url_changed(self
, widget
):
90 self
.btn_add
.set_sensitive(self
.entry_url
.get_text().strip() != '')
92 def on_entry_url_activate(self
, widget
):
93 self
.on_btn_add_clicked(widget
)
95 def on_btn_add_clicked(self
, widget
):
96 url
= self
.entry_url
.get_text()
97 self
.on_btn_close_clicked(widget
)
98 if self
.add_urls_callback
is not None:
99 self
.add_urls_callback([url
])