Release version 0.27
[straw.git] / src / lib / dialogs.py
blob2d7304cc495119ea6e0594229e02cff7e6fb3c22
1 """ dialogs.py
3 Module for displaying dialogs related to errors, warnings, notifications,
4 etc...
5 """
6 __copyright__ = "Copyright (c) 2002-2005 Free Software Foundation, Inc."
7 __license__ = """
8 Straw is free software; you can redistribute it and/or modify it under the
9 terms of the GNU General Public License as published by the Free Software
10 Foundation; either version 2 of the License, or (at your option) any later
11 version.
13 Straw is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
15 A PARTICULAR PURPOSE. See the GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License along with
18 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
19 Place - Suite 330, Boston, MA 02111-1307, USA. """
21 import pygtk
22 pygtk.require('2.0')
23 import gobject
24 import gtk
25 import gnome
26 import error
27 import FeedCategoryList
28 import FeedList
29 import OPMLExport
30 import OPMLImport
31 import utils
32 import constants
33 import gnome.ui
34 import os, os.path
35 import gettext
38 def _setup_filechooser_dialog(title, action, extra_widget_title):
39 """
40 Setup the file chooser dialog. This includes an extra widget (a combobox)
41 to include the categories to import or export
42 """
43 dialog = gtk.FileChooserDialog(title, action=action,
44 buttons=(gtk.STOCK_CANCEL,
45 gtk.RESPONSE_CANCEL,
46 gtk.STOCK_OK, gtk.RESPONSE_OK))
47 category_list = FeedCategoryList.get_instance()
48 model = gtk.ListStore(gobject.TYPE_STRING, gobject.TYPE_PYOBJECT)
49 combobox = gtk.ComboBox(model)
50 celltitle = gtk.CellRendererText()
51 combobox.pack_start(celltitle,False)
52 combobox.add_attribute(celltitle, 'text', 0)
54 # add 'All' Category
55 it = model.append()
56 model.set(it, 0, category_list.all_category.title,
57 1, category_list.all_category)
59 # add user categories
60 for category in category_list.user_categories:
61 it = model.append()
62 model.set(it, 0, category.title, 1, category)
64 # ..
65 combobox.set_active(0)
66 label = gtk.Label(extra_widget_title)
67 label.set_alignment(1.0,0.5)
68 hbox = gtk.HBox(spacing=6)
69 hbox.pack_start(label,True,True,0)
70 hbox.pack_end(combobox,False,False,0)
71 hbox.show_all()
73 dialog.set_extra_widget(hbox)
74 return (dialog, combobox)
77 def export_subscriptions(parent):
78 (dialog,combobox) = _setup_filechooser_dialog(_("Export Subscriptions"),
79 gtk.FILE_CHOOSER_ACTION_SAVE,
80 _("Select category to export:"))
81 def selection_changed(widget, dialog):
82 model = widget.get_model()
83 category = model[widget.get_active()][1]
84 dialog.set_current_name("Straw-%s.xml" % category.title)
86 combobox.connect('changed',
87 selection_changed,
88 dialog)
89 selection_changed(combobox, dialog)
90 dialog.set_transient_for(parent)
91 response = dialog.run()
92 if response == gtk.RESPONSE_OK:
93 filename = dialog.get_filename()
94 model = combobox.get_model()
95 cat = model[combobox.get_active()][1]
96 OPMLExport.export(cat.title, cat.feeds, filename)
97 dialog.destroy()
99 def import_subscriptions(parent):
100 (dialog,combobox) = _setup_filechooser_dialog(_("Import Subscriptions"),
101 gtk.FILE_CHOOSER_ACTION_OPEN,
102 _("Add new subscriptions in:"))
103 ffilter = gtk.FileFilter()
104 ffilter.set_name(_("OPML Files Only"))
105 ffilter.add_pattern("*.xml")
106 ffilter.add_pattern("*.opml")
107 dialog.add_filter(ffilter)
108 dialog.set_transient_for(parent)
109 response = dialog.run()
110 if response == gtk.RESPONSE_OK:
111 filename = dialog.get_filename()
112 model = combobox.get_model()
113 cat = model[combobox.get_active()][1]
114 dialog.hide()
115 OPMLImport.import_opml(filename, cat)
116 dialog.destroy()
118 def report_error(primary, secondary, parent=None):
119 dialog = gtk.MessageDialog(parent,
120 type=gtk.MESSAGE_ERROR,
121 buttons=gtk.BUTTONS_OK,
122 message_format=primary)
123 dialog.format_secondary_text(secondary)
124 response = dialog.run()
125 dialog.destroy()
126 return response
128 def report_offline_status(parent=None):
129 dialog = gtk.MessageDialog(parent,
130 type=gtk.MESSAGE_WARNING,
131 buttons=gtk.BUTTONS_OK_CANCEL,
132 message_format="You Are Offline!")
133 dialog.format_secondary_markup(_("You are currently reading offline. Would you like to go online now?"))
134 response = dialog.run()
135 dialog.destroy()
136 return response
138 def confirm_delete(primary, secondary,parent=None):
139 dialog = gtk.MessageDialog(parent,
140 type=gtk.MESSAGE_QUESTION,
141 buttons=gtk.BUTTONS_OK_CANCEL,
142 message_format=primary)
143 dialog.format_secondary_text(secondary)
144 response = dialog.run()
145 dialog.hide()
146 return response
148 def credits():
149 iconfile = os.path.join(utils.find_image_dir(),"straw.png")
150 logo = gtk.gdk.pixbuf_new_from_file(iconfile)
151 description = _("A feed aggregator for the GNOME Desktop")
152 straw_copyright = u"""
153 Copyright \xa9 2002-2004 Juri Pakaste
154 Copyright \xa9 2005-2007 Straw Contributors"""
155 people = [
156 u"Iain McCoy <iain@mccoy.id.au>",
157 u"Jan Alonzo <jmalonzo@unpluggable.com>",
158 u"Juri Pakaste <juri@iki.fi>",
159 u"Leandro Lameiro <lameiro@gmail.com>",
160 u"Lucas Nussbaum <lucas@lucas-nussbaum.net>",
161 u"Mark Pilgrim (feedparser and feedfinder)",
162 u"Olivier Crete <tester@tester.ca>",
163 u"Ryan P. Skadberg <skadz@stigmata.org>",
164 u"Scott Douglas-Watson <sdouglaswatson@yahoo.co.uk>",
165 u"Terje R\xf8sten (distutils)",
166 u"Tuukka Hastrup <tuukka@iki.fi>"]
168 artists = [
169 u"Jakub 'jimmac' Steiner"
172 translators = [
173 u"GNOME i18n Project and Translators<http://developer.gnome.org/projects/gtp/>",
174 u"Juri Pakaste <juri@iki.fi>",
175 u"Martin Steldinger <tribble@hanfplantage.de>",
176 u"David Rousseau <boiteaflood@wanadoo.fr>",
177 u"Sergei Vavinov <svv@cmc.msu.ru>",
178 u"Terje R\xf8sten <terjeros@phys.ntnu.no>",
179 u"Francisco J. Fernandez <franciscojavier.fernandez.serrador@hispalinux.es>",
180 u"Elros Cyriatan (Dutch Translation)"
183 translator_credits = 'translator_credits'
184 about = gtk.AboutDialog()
185 about.set_name(constants.APPNAME)
186 about.set_version(constants.VERSION)
187 about.set_copyright(straw_copyright)
188 about.set_comments(description)
189 about.set_authors(people)
190 artists.append(u'Juri Pakaste')
191 about.set_artists(artists)
192 about.set_logo(logo)
193 about.set_translator_credits(translator_credits)
194 about.set_license(__license__)
195 gtk.about_dialog_set_url_hook(lambda about, url: utils.url_show(url))
196 about.set_website(constants.STRAW_URL)
197 about.set_website_label(constants.STRAW_URL)
198 about.connect('response', lambda widget, response: widget.destroy())
199 return about