1 """ FeedPropertiesDialog.py
3 Provides a module for handling the properties of a Node.
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. """
20 from error
import log
, logparam
, logtb
21 from gtk
.glade
import XML
22 from straw
import helpers
23 from xml
.sax
import saxutils
34 class FeedPropertyView(MVP
.GladeView
):
40 def _initialize(self
):
42 self
._defaults
= {'title':'','url':'','username':'','password':''}
43 self
._window
= self
._widget
.get_widget('feed_properties')
45 self
._title
_entry
= self
._widget
.get_widget('title_entry')
46 self
._location
_entry
= self
._widget
.get_widget('location_entry')
47 self
._website
_entry
= self
._widget
.get_widget('website_entry')
48 self
._description
_label
= self
._widget
.get_widget('description_label')
49 self
._copyright
_label
= self
._widget
.get_widget('copyright_label')
51 self
._username
= self
._widget
.get_widget('properties_username_entry')
52 self
._password
= self
._widget
.get_widget('properties_password_entry')
54 self
._next
_refresh
_label
= self
._widget
.get_widget('properties_next_refresh_label')
55 self
._previous
_refresh
_label
= self
._widget
.get_widget('properties_previous_refresh_label')
57 self
._restore
_button
= self
._widget
.get_widget('properties_reset_button')
58 self
._refresh
_spin
= self
._widget
.get_widget('properties_refresh_spin')
59 self
._articles
_spin
= self
._widget
.get_widget('properties_articles_spin')
60 self
._refresh
_default
_check
= self
._widget
.get_widget('properties_keep_refresh_default')
61 self
._articles
_default
_check
= self
._widget
.get_widget('properties_keep_articles_default')
63 def set_feed(self
, feed
):
67 self
._initializing
_window
= True
68 self
.display_properties()
69 self
._window
.present()
70 self
._initializing
_window
= False
72 def hide(self
, *args
):
74 self
._window
.destroy()
76 def _on_feed_properties_delete_event(self
, *args
):
80 def _on_properties_close_button_clicked(self
, *args
):
84 def _on_location_button_clicked(self
, *args
):
85 helpers
.url_show(self
._location
_entry
.get_text())
87 def _on_website_button_clicked(self
, *args
):
88 helpers
.url_show(self
._website
_entry
.get_text())
90 def display_properties(self
):
91 self
._window
.set_title(_("%s Properties") % self
._feed
.title
)
93 self
._title
_entry
.set_text(self
._feed
.title
)
94 self
._location
_entry
.set_text(self
._feed
.location
)
95 self
._description
_label
.set_text(self
._feed
.description
)
96 self
._copyright
_label
.set_text(self
._feed
.copyright
)
98 self
._website
_entry
.set_text(self
._feed
.link
)
100 for key
in ("category", "generator", "creator", "webmaster", "ttl"):
101 label
= self
._widget
.get_widget("%s_label" % key
)
102 hbox
= self
._widget
.get_widget("%s_hbox" % key
)
105 value
= getattr(self
._feed
, key
)
109 label
.set_text(value
)
113 """self._defaults['title'] = self._feed.title
114 loc, un, pw = "", "", ""#self._feed.access_info
115 self._defaults['url'] = loc
116 self._defaults['username'] = un
117 self._defaults['password'] = pw
118 self._defaults['frequency'] = self._feed.poll_frequency
119 self._defaults['stored'] = self._feed.number_of_items_stored
121 self._title.set_text(self._feed.title)
122 self._location.set_text(self._feed.access_info[0])
124 config = Config.get_instance()
125 if self._feed.poll_frequency == feeds.Feed.DEFAULT:
126 freq = config.poll_frequency
128 self._refresh_keep = True
130 freq = self._feed.poll_frequency
132 self._refresh_keep = False
133 self._refresh_spin.set_value(float(freq / 60))
134 self._refresh_spin.set_sensitive(not fdefault)
135 self._refresh_default_check.set_active(fdefault)
136 if self._feed.number_of_items_stored == feeds.Feed.DEFAULT:
137 nitems = config.number_of_items_stored
139 self._articles_keep = True
141 nitems = self._feed.number_of_items_stored
143 self._articles_keep = False
144 self._articles_spin.set_value(float(nitems))
145 self._articles_spin.set_sensitive(not nidefault)
146 self._articles_default_check.set_active(nidefault)
149 self._username.set_text(un)
151 self._password.set_text(pw)
153 model = self._categories_treeview.get_model()
155 fclist = feeds.category_list
156 for c in fclist.user_categories:
157 iter = model.append()
159 self.COLUMN_NAME, c.title,
160 self.COLUMN_MEMBER, self._feed in c.feeds,
161 self.COLUMN_OBJECT, c)
163 self._previous_refresh_label.set_text(
164 helpers.format_date(time.gmtime(self._feed.last_poll)))
165 next = self._feed.next_refresh
167 self._next_refresh_label.set_text(
168 helpers.format_date(time.gmtime(next)))
169 self._next_refresh_label.show()
171 self._next_refresh_label.hide()
173 description = helpers.convert_entities(feed.channel_description.strip())
174 if description and description != title:
175 description = read_text(description, len(description))
176 self._feed_info_description.set_text(helpers.convert_entities(description))
177 self._feed_info_description.show()
179 self._feed_info_description.hide()
181 copyright = helpers.convert_entities(feed.channel_copyright)
183 self._feed_info_copyright.set_text(copyright)
184 self._feed_info_copyright.show()
186 self._feed_info_copyright.hide()"""
188 def _load_uri(self
, widget
, event
):
189 helpers
.url_show(widget
.get_uri())
191 def restore_defaults(self
):
192 # FIXME: add frequency and number of items and the default flags
193 self
._feed
.title
= self
._defaults
['title']
194 self
._feed
.access_info
= (
195 self
._defaults
['url'], self
._defaults
['username'], self
._defaults
['password'])
196 self
._title
.set_text(self
._feed
.title
)
197 self
._location
.set_text(self
._feed
.location
)
198 self
._username
.set_text(self
._defaults
.get('username',''))
199 self
._password
.set_text(self
._defaults
.get('password',''))
200 self
._refresh
_default
_check
.set_active(self
._refresh
_keep
)
201 if not self
._refresh
_keep
:
202 self
._refresh
_spin
.set_value(float(self
._refresh
_default
))
203 self
._articles
_default
_check
.set_active(self
._articles
_keep
)
204 if not self
._articles
_keep
:
205 self
._articles
_spin
.set_value(float(self
._articles
_default
))
206 self
._restore
_button
.set_sensitive(False)
208 def _on_close_button_clicked(self
, *args
):
211 def _on_properties_title_entry_insert_text(self
, *args
):
212 if self
._initializing
_window
:
214 self
._restore
_button
.set_sensitive(True)
216 def _on_properties_title_entry_delete_text(self
, *args
):
217 if self
._initializing
_window
:
219 self
._restore
_button
.set_sensitive(True)
221 def _on_properties_title_entry_focus_out_event(self
, widget
, *args
):
222 self
._feed
.title
= widget
.get_text().strip()
224 def _on_properties_location_entry_insert_text(self
, *args
):
225 if self
._initializing
_window
:
227 self
._restore
_button
.set_sensitive(True)
229 def _on_properties_location_entry_delete_text(self
, *args
):
230 if self
._initializing
_window
:
232 self
._restore
_button
.set_sensitive(True)
234 def _on_properties_location_entry_focus_out_event(self
, widget
, *args
):
235 loc
, username
, pw
= self
._feed
.access_info
236 self
._feed
.access_info
= (widget
.get_text().strip(), username
, pw
)
238 def _on_properties_username_entry_insert_text(self
, *args
):
239 if self
._initializing
_window
:
241 self
._restore
_button
.set_sensitive(True)
243 def _on_properties_username_entry_delete_text(self
, *args
):
244 if self
._initializing
_window
:
246 self
._restore
_button
.set_sensitive(False)
248 def _on_properties_username_entry_focus_out_event(self
, widget
, *args
):
249 self
._presenter
.set_username(widget
.get_text().strip())
251 def _on_properties_password_entry_insert_text(self
, *args
):
252 if self
._initializing
_window
:
254 self
._restore
_button
.set_sensitive(True)
256 def _on_properties_password_entry_delete_text(self
, *args
):
257 if self
._initializing
_window
:
259 self
._restore
_button
.set_sensitive(False)
261 def _on_properties_password_entry_focus_out_event(self
, widget
, *args
):
262 self
._presenter
.set_password(widget
.get_text().strip())
264 def _on_properties_reset_button_clicked(self
, *args
):
265 self
.restore_defaults()
267 def _on_properties_refresh_spin_focus_out_event(self
, widget
, *args
):
269 value
= widget
.get_value_as_int()
270 self
._presenter
.set_poll_frequency(value
)
272 def _on_properties_articles_spin_focus_out_event(self
, widget
, *args
):
274 value
= widget
.get_value_as_int()
275 self
._presenter
.set_items_stored(value
)
277 def _on_properties_articles_spin_value_changed(self
, widget
, *args
):
278 if self
._initializing
_window
:
280 self
._restore
_button
.set_sensitive(True)
282 def _on_properties_refresh_spin_value_changed(self
, widget
, *args
):
283 if self
._initializing
_window
:
285 self
._restore
_button
.set_sensitive(True)
287 def _on_properties_keep_refresh_default_toggled(self
, widget
, *args
):
288 if self
._initializing
_window
:
290 isactive
= widget
.get_active()
292 self
._presenter
.set_poll_frequency(feeds
.Feed
.DEFAULT
)
293 self
._refresh
_spin
.set_value(float(Config
.get_instance().poll_frequency
/ 60))
295 self
._presenter
.set_poll_frequency(self
._refresh
_spin
.get_value_as_int() * 60)
297 self
._refresh
_spin
.set_sensitive(not isactive
)
298 self
._restore
_button
.set_sensitive(True)
300 def _on_properties_keep_articles_default_toggled(self
, widget
, *args
):
301 if self
._initializing
_window
:
303 isactive
= widget
.get_active()
305 self
._presenter
.set_items_stored(feeds
.Feed
.DEFAULT
)
306 self
._articles
_spin
.set_value(float(Config
.get_instance().number_of_items_stored
))
308 self
._presenter
.set_items_stored(self
._articles
_spin
.get_value_as_int())
309 self
._articles
_spin
.set_sensitive(not isactive
)
310 self
._restore
_button
.set_sensitive(True)
312 class FeedPropertyPresenter(MVP
.BasicPresenter
):
316 def _initialize(self
):
319 def set_feed(self
, feed
):
321 self
._view
.set_feed(self
._feed
)
323 def set_username(self
, username
):
324 loc
, uname
, pw
= self
._feed
.access_info
325 self
._feed
.access_info
= (loc
, username
, pw
)
327 def set_password(self
, password
):
328 loc
, uname
, pw
= self
._feed
.access_info
329 self
._feed
.access_info
= (loc
, uname
, password
)
331 def set_poll_frequency(self
, pf
):
332 if pf
!= self
._feed
.poll_frequency
:
333 self
._feed
.poll_frequency
= pf
* FeedPropertyPresenter
.TIME_INTERVAL
335 def set_items_stored(self
, nitems
):
336 if nitems
!= self
._feed
.number_of_items_stored
:
337 self
._feed
.number_of_items_stored
= nitems
339 def feed_properties_show(feed
):
340 gladefile
= XML(os
.path
.join(straw
.defs
.STRAW_DATA_DIR
, "feed-properties.glade"))
341 dialog
= FeedPropertyPresenter(view
=FeedPropertyView(gladefile
))
342 dialog
.set_feed(feed
)
346 def read_text(fragment
, chars
):
347 """Read chars cdata characters from html fragment fragment"""
348 parser
= SummaryParser
.TitleImgParser()
349 parser
.feed(fragment
)
350 text
= parser
.get_text(chars
)