1
# Miro - an RSS based video player application
2
# Copyright (C) 2005-2010 Participatory Culture Foundation
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 2 of the License, or
7
# (at your option) any later version.
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
# GNU General Public License for more details.
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
# In addition, as a special exception, the copyright holders give
19
# permission to link the code of portions of this program with the OpenSSL
22
# You must obey the GNU General Public License in all respects for all of
23
# the code used other than OpenSSL. If you modify file(s) with this
24
# exception, you may extend this exception to your version of the file(s),
25
# but you are not obligated to do so. If you do not wish to do so, delete
26
# this exception statement from your version. If you delete this exception
27
# statement from all source files in the program, then also delete it here.
29
"""miro.frontends.widgets.newfeed -- Holds dialog and processing
30
code for adding a new feed.
33
from miro.gtcache import gettext as _
34
from miro import searchengines
36
from miro.plat.frontends.widgets import widgetset
37
from miro.frontends.widgets import widgetutil
38
from miro.frontends.widgets.dialogs import MainDialog
39
from miro.dialogs import BUTTON_CANCEL, BUTTON_CREATE_FEED
46
def _run_dialog(title, description, initial_text):
47
"""Creates and launches the New Feed dialog. This dialog waits for
48
the user to press "Create Feed" or "Cancel".
50
Returns a tuple of the (url, section).
52
window = MainDialog(title, description)
55
window.add_button(BUTTON_CREATE_FEED.text)
56
window.add_button(BUTTON_CANCEL.text)
58
extra = widgetset.VBox()
60
lab = widgetset.Label(_('URL:'))
61
url_entry = widgetset.TextEntry()
62
url_entry.set_text(initial_text)
63
url_entry.set_activates_default(True)
66
h.pack_start(lab, padding=5)
67
h.pack_start(url_entry, expand=True)
68
extra.pack_start(h, padding=5)
70
lab = widgetset.Label(_('Feed should go in this section:'))
71
rbg = widgetset.RadioButtonGroup()
72
video_rb = widgetset.RadioButton(_("video"), rbg)
73
audio_rb = widgetset.RadioButton(_("audio"), rbg)
75
extra.pack_start(widgetutil.build_hbox((lab, video_rb, audio_rb)))
77
window.set_extra_widget(extra)
79
response = window.run()
82
if rbg.get_selected() == video_rb:
87
text = url_entry.get_text()
88
return (text, section)
93
logging.exception("newfeed threw exception.")
98
"""Creates and launches the New Feed dialog. This dialog waits for
99
the user to press "Create Feed" or "Cancel".
101
Returns a tuple of the (url, section).
103
text = app.widgetapp.get_clipboard_text()
104
if text and feed.validate_feed_url(text):
105
text = feed.normalize_feed_url(text)
109
title = _('Add Feed')
110
description = _('Enter the URL of the feed to add')
113
text, section = _run_dialog(title, description, initial_text=text)
117
normalized_url = feed.normalize_feed_url(text)
118
if feed.validate_feed_url(normalized_url):
119
return (normalized_url, section)
121
title = _('Add Feed - Invalid URL')
122
description = _('The address you entered is not a valid url.\nPlease check the URL and try again.\n\nEnter the URL of the feed to add')