1 # -*- coding: utf-8 -*-
3 # gPodder - A media aggregator and podcast client
4 # Copyright (c) 2005-2018 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/>.
20 from gi
.repository
import Gdk
, Gtk
23 from gpodder
import util
24 from gpodder
.gtkui
.interface
.common
import BuilderWidget
29 class gPodderAddPodcast(BuilderWidget
):
31 self
.gPodderAddPodcast
.set_transient_for(self
.parent_widget
)
32 if not hasattr(self
, 'add_podcast_list'):
33 self
.add_podcast_list
= None
34 if hasattr(self
, 'custom_label'):
35 self
.label_add
.set_text(self
.custom_label
)
36 if hasattr(self
, 'custom_title'):
37 self
.gPodderAddPodcast
.set_title(self
.custom_title
)
38 if hasattr(self
, 'preset_url'):
39 self
.entry_url
.set_text(self
.preset_url
)
40 self
.entry_url
.connect('activate', self
.on_entry_url_activate
)
41 self
.entry_url
.connect('icon-press', self
.on_clear_url
)
42 self
.gPodderAddPodcast
.show()
44 if not hasattr(self
, 'preset_url'):
45 # Fill the entry if a valid URL is in the clipboard, but
46 # only if there's no preset_url available (see bug 1132).
47 # First try from CLIPBOARD (everyday copy-paste),
48 # then from SELECTION (text selected and pasted via
49 # middle mouse button).
50 clipboard
= Gtk
.Clipboard
.get(Gdk
.SELECTION_CLIPBOARD
)
52 def receive_clipboard_text(clipboard
, text
, second_try
):
53 # Heuristic: If space is present in clipboard text
54 # normalize_feed_url will either fix to valid url or
55 # return None if URL cannot be validated
57 url
= util
.normalize_feed_url(text
)
59 self
.entry_url
.set_text(url
)
60 self
.entry_url
.set_position(-1)
64 clipboard
= Gtk
.Clipboard
.get(Gdk
.SELECTION_PRIMARY
)
65 clipboard
.request_text(receive_clipboard_text
, True)
66 clipboard
.request_text(receive_clipboard_text
, False)
68 def on_clear_url(self
, widget
, icon_position
, event
):
69 self
.entry_url
.set_text('')
71 def on_btn_close_clicked(self
, widget
):
72 self
.gPodderAddPodcast
.destroy()
74 def on_btn_paste_clicked(self
, widget
):
75 clipboard
= Gtk
.Clipboard
.get(Gdk
.SELECTION_CLIPBOARD
)
76 clipboard
.request_text(self
.receive_clipboard_text
)
78 def receive_clipboard_text(self
, clipboard
, text
, data
=None):
80 self
.entry_url
.set_text(text
.strip())
82 self
.show_message(_('Nothing to paste.'), _('Clipboard is empty'))
84 def on_entry_url_changed(self
, widget
):
85 self
.btn_add
.set_sensitive(self
.entry_url
.get_text().strip() != '')
87 def on_entry_url_activate(self
, widget
):
88 self
.on_btn_add_clicked(widget
)
90 def on_btn_add_clicked(self
, widget
):
91 url
= self
.entry_url
.get_text()
92 self
.on_btn_close_clicked(widget
)
93 if self
.add_podcast_list
is not None:
94 title
= None # FIXME: Add title GUI element
95 self
.add_podcast_list([(title
, url
)])