~ubuntu-branches/ubuntu/natty/miro/natty

« back to all changes in this revision

Viewing changes to lib/frontends/widgets/newfeed.py

  • Committer: Bazaar Package Importer
  • Author(s): Bryce Harrington
  • Date: 2011-01-22 02:46:33 UTC
  • mfrom: (1.4.10 upstream) (1.7.5 experimental)
  • Revision ID: james.westby@ubuntu.com-20110122024633-kjme8u93y2il5nmf
Tags: 3.5.1-1ubuntu1
* Merge from debian.  Remaining ubuntu changes:
  - Use python 2.7 instead of python 2.6
  - Relax dependency on python-dbus to >= 0.83.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Miro - an RSS based video player application
 
2
# Copyright (C) 2005-2010 Participatory Culture Foundation
 
3
#
 
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.
 
8
#
 
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.
 
13
#
 
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
 
17
#
 
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
 
20
# library.
 
21
#
 
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.
 
28
 
 
29
"""miro.frontends.widgets.newfeed -- Holds dialog and processing
 
30
code for adding a new feed.
 
31
"""
 
32
 
 
33
from miro.gtcache import gettext as _
 
34
from miro import searchengines
 
35
 
 
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
 
40
 
 
41
from miro import app
 
42
from miro import feed
 
43
 
 
44
import logging
 
45
 
 
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".
 
49
 
 
50
    Returns a tuple of the (url, section).
 
51
    """
 
52
    window = MainDialog(title, description)
 
53
    try:
 
54
        try:
 
55
            window.add_button(BUTTON_CREATE_FEED.text)
 
56
            window.add_button(BUTTON_CANCEL.text)
 
57
 
 
58
            extra = widgetset.VBox()
 
59
 
 
60
            lab = widgetset.Label(_('URL:'))
 
61
            url_entry = widgetset.TextEntry()
 
62
            url_entry.set_text(initial_text)
 
63
            url_entry.set_activates_default(True)
 
64
 
 
65
            h = widgetset.HBox()
 
66
            h.pack_start(lab, padding=5)
 
67
            h.pack_start(url_entry, expand=True)
 
68
            extra.pack_start(h, padding=5)
 
69
 
 
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)
 
74
 
 
75
            extra.pack_start(widgetutil.build_hbox((lab, video_rb, audio_rb)))
 
76
 
 
77
            window.set_extra_widget(extra)
 
78
 
 
79
            response = window.run()
 
80
 
 
81
            if response == 0:
 
82
                if rbg.get_selected() == video_rb:
 
83
                    section = u"video"
 
84
                else:
 
85
                    section = u"audio"
 
86
 
 
87
                text = url_entry.get_text()
 
88
                return (text, section)
 
89
            
 
90
            return (None, None)
 
91
 
 
92
        except StandardError:
 
93
            logging.exception("newfeed threw exception.")
 
94
    finally:
 
95
        window.destroy()
 
96
        
 
97
def run_dialog():
 
98
    """Creates and launches the New Feed dialog.  This dialog waits for
 
99
    the user to press "Create Feed" or "Cancel".
 
100
 
 
101
    Returns a tuple of the (url, section).
 
102
    """
 
103
    text = app.widgetapp.get_clipboard_text()
 
104
    if text and feed.validate_feed_url(text):
 
105
        text = feed.normalize_feed_url(text)
 
106
    else:
 
107
        text = ""
 
108
 
 
109
    title = _('Add Feed')
 
110
    description = _('Enter the URL of the feed to add')
 
111
 
 
112
    while 1:
 
113
        text, section = _run_dialog(title, description, initial_text=text)
 
114
        if text == None:
 
115
            return (None, None)
 
116
 
 
117
        normalized_url = feed.normalize_feed_url(text)
 
118
        if feed.validate_feed_url(normalized_url):
 
119
            return (normalized_url, section)
 
120
 
 
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')