1 """ FeedPropertiesDialog.py
3 Provides a module for handling the properties of a feed
5 __copyright__
= "Copyright (c) 2002-2005 Free Software Foundation, Inc."
7 Straw is free software; you can redistribute it and/or modify it under the
8 terms of the GNU General Public License as published by the Free Software
9 Foundation; either version 2 of the License, or (at your option) any later
12 Straw is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License along with
17 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
18 Place - Suite 330, Boston, MA 02111-1307, USA. """
23 from error
import log
, logparam
, logtb
24 from xml
.sax
import saxutils
26 from gtk
.glade
import XML
35 from straw
import helpers
37 class FeedPropertyView(MVP
.GladeView
):
43 def _initialize(self
):
45 self
._defaults
= {'title':'','url':'','username':'','password':''}
46 self
._window
= self
._widget
.get_widget('feed_properties')
48 self
._title
_entry
= self
._widget
.get_widget('title_entry')
49 self
._location
_entry
= self
._widget
.get_widget('location_entry')
50 self
._website
_entry
= self
._widget
.get_widget('website_entry')
51 self
._description
_label
= self
._widget
.get_widget('description_label')
52 self
._copyright
_label
= self
._widget
.get_widget('copyright_label')
54 self
._username
= self
._widget
.get_widget('properties_username_entry')
55 self
._password
= self
._widget
.get_widget('properties_password_entry')
57 self
._next
_refresh
_label
= self
._widget
.get_widget('properties_next_refresh_label')
58 self
._previous
_refresh
_label
= self
._widget
.get_widget('properties_previous_refresh_label')
60 self
._restore
_button
= self
._widget
.get_widget('properties_reset_button')
61 self
._refresh
_spin
= self
._widget
.get_widget('properties_refresh_spin')
62 self
._articles
_spin
= self
._widget
.get_widget('properties_articles_spin')
63 self
._refresh
_default
_check
= self
._widget
.get_widget('properties_keep_refresh_default')
64 self
._articles
_default
_check
= self
._widget
.get_widget('properties_keep_articles_default')
66 def set_feed(self
, feed
):
70 self
._initializing
_window
= True
71 self
.display_properties()
72 self
._window
.present()
73 self
._initializing
_window
= False
75 def hide(self
, *args
):
77 self
._window
.destroy()
79 def _on_feed_properties_delete_event(self
, *args
):
83 def _on_properties_close_button_clicked(self
, *args
):
87 def _on_location_button_clicked(self
, *args
):
88 helpers
.url_show(self
._location
_entry
.get_text())
90 def _on_website_button_clicked(self
, *args
):
91 helpers
.url_show(self
._website
_entry
.get_text())
93 def display_properties(self
):
94 self
._window
.set_title(_("%s Properties") % self
._feed
.title
)
96 self
._title
_entry
.set_text(self
._feed
.title
)
97 self
._location
_entry
.set_text(self
._feed
.location
)
98 self
._description
_label
.set_text(self
._feed
.description
)
99 self
._copyright
_label
.set_text(self
._feed
.copyright
)
101 self
._website
_entry
.set_text(self
._feed
.link
)
103 """self._defaults['title'] = self._feed.title
104 loc, un, pw = "", "", ""#self._feed.access_info
105 self._defaults['url'] = loc
106 self._defaults['username'] = un
107 self._defaults['password'] = pw
108 self._defaults['frequency'] = self._feed.poll_frequency
109 self._defaults['stored'] = self._feed.number_of_items_stored
111 self._title.set_text(self._feed.title)
112 self._location.set_text(self._feed.access_info[0])
114 config = Config.get_instance()
115 if self._feed.poll_frequency == feeds.Feed.DEFAULT:
116 freq = config.poll_frequency
118 self._refresh_keep = True
120 freq = self._feed.poll_frequency
122 self._refresh_keep = False
123 self._refresh_spin.set_value(float(freq / 60))
124 self._refresh_spin.set_sensitive(not fdefault)
125 self._refresh_default_check.set_active(fdefault)
126 if self._feed.number_of_items_stored == feeds.Feed.DEFAULT:
127 nitems = config.number_of_items_stored
129 self._articles_keep = True
131 nitems = self._feed.number_of_items_stored
133 self._articles_keep = False
134 self._articles_spin.set_value(float(nitems))
135 self._articles_spin.set_sensitive(not nidefault)
136 self._articles_default_check.set_active(nidefault)
139 self._username.set_text(un)
141 self._password.set_text(pw)
143 model = self._categories_treeview.get_model()
145 fclist = feeds.category_list
146 for c in fclist.user_categories:
147 iter = model.append()
149 self.COLUMN_NAME, c.title,
150 self.COLUMN_MEMBER, self._feed in c.feeds,
151 self.COLUMN_OBJECT, c)
153 self._previous_refresh_label.set_text(
154 helpers.format_date(time.gmtime(self._feed.last_poll)))
155 next = self._feed.next_refresh
157 self._next_refresh_label.set_text(
158 helpers.format_date(time.gmtime(next)))
159 self._next_refresh_label.show()
161 self._next_refresh_label.hide()
163 description = helpers.convert_entities(feed.channel_description.strip())
164 if description and description != title:
165 description = read_text(description, len(description))
166 self._feed_info_description.set_text(helpers.convert_entities(description))
167 self._feed_info_description.show()
169 self._feed_info_description.hide()
171 copyright = helpers.convert_entities(feed.channel_copyright)
173 self._feed_info_copyright.set_text(copyright)
174 self._feed_info_copyright.show()
176 self._feed_info_copyright.hide()"""
178 def _load_uri(self
, widget
, event
):
179 helpers
.url_show(widget
.get_uri())
181 def restore_defaults(self
):
182 # FIXME: add frequency and number of items and the default flags
183 self
._feed
.title
= self
._defaults
['title']
184 self
._feed
.access_info
= (
185 self
._defaults
['url'], self
._defaults
['username'], self
._defaults
['password'])
186 self
._title
.set_text(self
._feed
.title
)
187 self
._location
.set_text(self
._feed
.location
)
188 self
._username
.set_text(self
._defaults
.get('username',''))
189 self
._password
.set_text(self
._defaults
.get('password',''))
190 self
._refresh
_default
_check
.set_active(self
._refresh
_keep
)
191 if not self
._refresh
_keep
:
192 self
._refresh
_spin
.set_value(float(self
._refresh
_default
))
193 self
._articles
_default
_check
.set_active(self
._articles
_keep
)
194 if not self
._articles
_keep
:
195 self
._articles
_spin
.set_value(float(self
._articles
_default
))
196 self
._restore
_button
.set_sensitive(False)
198 def _on_close_button_clicked(self
, *args
):
201 def _on_properties_title_entry_insert_text(self
, *args
):
202 if self
._initializing
_window
:
204 self
._restore
_button
.set_sensitive(True)
206 def _on_properties_title_entry_delete_text(self
, *args
):
207 if self
._initializing
_window
:
209 self
._restore
_button
.set_sensitive(True)
211 def _on_properties_title_entry_focus_out_event(self
, widget
, *args
):
212 self
._feed
.title
= widget
.get_text().strip()
214 def _on_properties_location_entry_insert_text(self
, *args
):
215 if self
._initializing
_window
:
217 self
._restore
_button
.set_sensitive(True)
219 def _on_properties_location_entry_delete_text(self
, *args
):
220 if self
._initializing
_window
:
222 self
._restore
_button
.set_sensitive(True)
224 def _on_properties_location_entry_focus_out_event(self
, widget
, *args
):
225 loc
, username
, pw
= self
._feed
.access_info
226 self
._feed
.access_info
= (widget
.get_text().strip(), username
, pw
)
228 def _on_properties_username_entry_insert_text(self
, *args
):
229 if self
._initializing
_window
:
231 self
._restore
_button
.set_sensitive(True)
233 def _on_properties_username_entry_delete_text(self
, *args
):
234 if self
._initializing
_window
:
236 self
._restore
_button
.set_sensitive(False)
238 def _on_properties_username_entry_focus_out_event(self
, widget
, *args
):
239 self
._presenter
.set_username(widget
.get_text().strip())
241 def _on_properties_password_entry_insert_text(self
, *args
):
242 if self
._initializing
_window
:
244 self
._restore
_button
.set_sensitive(True)
246 def _on_properties_password_entry_delete_text(self
, *args
):
247 if self
._initializing
_window
:
249 self
._restore
_button
.set_sensitive(False)
251 def _on_properties_password_entry_focus_out_event(self
, widget
, *args
):
252 self
._presenter
.set_password(widget
.get_text().strip())
254 def _on_properties_reset_button_clicked(self
, *args
):
255 self
.restore_defaults()
257 def _on_properties_refresh_spin_focus_out_event(self
, widget
, *args
):
259 value
= widget
.get_value_as_int()
260 self
._presenter
.set_poll_frequency(value
)
262 def _on_properties_articles_spin_focus_out_event(self
, widget
, *args
):
264 value
= widget
.get_value_as_int()
265 self
._presenter
.set_items_stored(value
)
267 def _on_properties_articles_spin_value_changed(self
, widget
, *args
):
268 if self
._initializing
_window
:
270 self
._restore
_button
.set_sensitive(True)
272 def _on_properties_refresh_spin_value_changed(self
, widget
, *args
):
273 if self
._initializing
_window
:
275 self
._restore
_button
.set_sensitive(True)
277 def _on_properties_keep_refresh_default_toggled(self
, widget
, *args
):
278 if self
._initializing
_window
:
280 isactive
= widget
.get_active()
282 self
._presenter
.set_poll_frequency(feeds
.Feed
.DEFAULT
)
283 self
._refresh
_spin
.set_value(float(Config
.get_instance().poll_frequency
/ 60))
285 self
._presenter
.set_poll_frequency(self
._refresh
_spin
.get_value_as_int() * 60)
287 self
._refresh
_spin
.set_sensitive(not isactive
)
288 self
._restore
_button
.set_sensitive(True)
290 def _on_properties_keep_articles_default_toggled(self
, widget
, *args
):
291 if self
._initializing
_window
:
293 isactive
= widget
.get_active()
295 self
._presenter
.set_items_stored(feeds
.Feed
.DEFAULT
)
296 self
._articles
_spin
.set_value(float(Config
.get_instance().number_of_items_stored
))
298 self
._presenter
.set_items_stored(self
._articles
_spin
.get_value_as_int())
299 self
._articles
_spin
.set_sensitive(not isactive
)
300 self
._restore
_button
.set_sensitive(True)
303 class FeedPropertyPresenter(MVP
.BasicPresenter
):
307 def _initialize(self
):
310 def set_feed(self
, feed
):
312 self
._view
.set_feed(self
._feed
)
314 def set_username(self
, username
):
315 loc
, uname
, pw
= self
._feed
.access_info
316 self
._feed
.access_info
= (loc
, username
, pw
)
318 def set_password(self
, password
):
319 loc
, uname
, pw
= self
._feed
.access_info
320 self
._feed
.access_info
= (loc
, uname
, password
)
322 def set_poll_frequency(self
, pf
):
323 if pf
!= self
._feed
.poll_frequency
:
324 self
._feed
.poll_frequency
= pf
* FeedPropertyPresenter
.TIME_INTERVAL
326 def set_items_stored(self
, nitems
):
327 if nitems
!= self
._feed
.number_of_items_stored
:
328 self
._feed
.number_of_items_stored
= nitems
330 def feed_properties_show(feed
):
331 gladefile
= XML(os
.path
.join(straw
.defs
.STRAW_DATA_DIR
, "feed-properties.glade"))
332 dialog
= FeedPropertyPresenter(view
=FeedPropertyView(gladefile
))
333 dialog
.set_feed(feed
)
337 def read_text(fragment
, chars
):
338 """Read chars cdata characters from html fragment fragment"""
339 parser
= SummaryParser
.TitleImgParser()
340 parser
.feed(fragment
)
341 text
= parser
.get_text(chars
)