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
)
96 self
._website
_entry
.set_text(self
._feed
.link
)
98 for key
in ("description", "copyright", "category", "generator",
99 "creator", "webmaster", "ttl"):
100 label
= self
._widget
.get_widget("%s_label" % key
)
101 input = self
._widget
.get_widget("%s_input" % key
)
105 if hasattr(self
._feed
, key
):
106 value
= getattr(self
._feed
, key
)
107 elif self
._feed
.pdict
.has_key(key
):
108 value
= self
._feed
.pdict
[key
]
112 input.set_text(value
)
115 window
= self
._widget
.get_widget("%s_window" % key
)
120 """self._defaults['title'] = self._feed.title
121 loc, un, pw = "", "", ""#self._feed.access_info
122 self._defaults['url'] = loc
123 self._defaults['username'] = un
124 self._defaults['password'] = pw
125 self._defaults['frequency'] = self._feed.poll_frequency
126 self._defaults['stored'] = self._feed.number_of_items_stored
128 self._title.set_text(self._feed.title)
129 self._location.set_text(self._feed.access_info[0])
131 config = Config.get_instance()
132 if self._feed.poll_frequency == feeds.Feed.DEFAULT:
133 freq = config.poll_frequency
135 self._refresh_keep = True
137 freq = self._feed.poll_frequency
139 self._refresh_keep = False
140 self._refresh_spin.set_value(float(freq / 60))
141 self._refresh_spin.set_sensitive(not fdefault)
142 self._refresh_default_check.set_active(fdefault)
143 if self._feed.number_of_items_stored == feeds.Feed.DEFAULT:
144 nitems = config.number_of_items_stored
146 self._articles_keep = True
148 nitems = self._feed.number_of_items_stored
150 self._articles_keep = False
151 self._articles_spin.set_value(float(nitems))
152 self._articles_spin.set_sensitive(not nidefault)
153 self._articles_default_check.set_active(nidefault)
156 self._username.set_text(un)
158 self._password.set_text(pw)
160 model = self._categories_treeview.get_model()
162 fclist = feeds.category_list
163 for c in fclist.user_categories:
164 iter = model.append()
166 self.COLUMN_NAME, c.title,
167 self.COLUMN_MEMBER, self._feed in c.feeds,
168 self.COLUMN_OBJECT, c)
170 self._previous_refresh_label.set_text(
171 helpers.format_date(time.gmtime(self._feed.last_poll)))
172 next = self._feed.next_refresh
174 self._next_refresh_label.set_text(
175 helpers.format_date(time.gmtime(next)))
176 self._next_refresh_label.show()
178 self._next_refresh_label.hide()
180 description = helpers.convert_entities(feed.channel_description.strip())
181 if description and description != title:
182 description = read_text(description, len(description))
183 self._feed_info_description.set_text(helpers.convert_entities(description))
184 self._feed_info_description.show()
186 self._feed_info_description.hide()
188 copyright = helpers.convert_entities(feed.channel_copyright)
190 self._feed_info_copyright.set_text(copyright)
191 self._feed_info_copyright.show()
193 self._feed_info_copyright.hide()"""
195 def _load_uri(self
, widget
, event
):
196 helpers
.url_show(widget
.get_uri())
198 def restore_defaults(self
):
199 # FIXME: add frequency and number of items and the default flags
200 self
._feed
.title
= self
._defaults
['title']
201 self
._feed
.access_info
= (
202 self
._defaults
['url'], self
._defaults
['username'], self
._defaults
['password'])
203 self
._title
.set_text(self
._feed
.title
)
204 self
._location
.set_text(self
._feed
.location
)
205 self
._username
.set_text(self
._defaults
.get('username',''))
206 self
._password
.set_text(self
._defaults
.get('password',''))
207 self
._refresh
_default
_check
.set_active(self
._refresh
_keep
)
208 if not self
._refresh
_keep
:
209 self
._refresh
_spin
.set_value(float(self
._refresh
_default
))
210 self
._articles
_default
_check
.set_active(self
._articles
_keep
)
211 if not self
._articles
_keep
:
212 self
._articles
_spin
.set_value(float(self
._articles
_default
))
213 self
._restore
_button
.set_sensitive(False)
215 def _on_close_button_clicked(self
, *args
):
218 def _on_properties_title_entry_insert_text(self
, *args
):
219 if self
._initializing
_window
:
221 self
._restore
_button
.set_sensitive(True)
223 def _on_properties_title_entry_delete_text(self
, *args
):
224 if self
._initializing
_window
:
226 self
._restore
_button
.set_sensitive(True)
228 def _on_properties_title_entry_focus_out_event(self
, widget
, *args
):
229 self
._feed
.title
= widget
.get_text().strip()
231 def _on_properties_location_entry_insert_text(self
, *args
):
232 if self
._initializing
_window
:
234 self
._restore
_button
.set_sensitive(True)
236 def _on_properties_location_entry_delete_text(self
, *args
):
237 if self
._initializing
_window
:
239 self
._restore
_button
.set_sensitive(True)
241 def _on_properties_location_entry_focus_out_event(self
, widget
, *args
):
242 loc
, username
, pw
= self
._feed
.access_info
243 self
._feed
.access_info
= (widget
.get_text().strip(), username
, pw
)
245 def _on_properties_username_entry_insert_text(self
, *args
):
246 if self
._initializing
_window
:
248 self
._restore
_button
.set_sensitive(True)
250 def _on_properties_username_entry_delete_text(self
, *args
):
251 if self
._initializing
_window
:
253 self
._restore
_button
.set_sensitive(False)
255 def _on_properties_username_entry_focus_out_event(self
, widget
, *args
):
256 self
._presenter
.set_username(widget
.get_text().strip())
258 def _on_properties_password_entry_insert_text(self
, *args
):
259 if self
._initializing
_window
:
261 self
._restore
_button
.set_sensitive(True)
263 def _on_properties_password_entry_delete_text(self
, *args
):
264 if self
._initializing
_window
:
266 self
._restore
_button
.set_sensitive(False)
268 def _on_properties_password_entry_focus_out_event(self
, widget
, *args
):
269 self
._presenter
.set_password(widget
.get_text().strip())
271 def _on_properties_reset_button_clicked(self
, *args
):
272 self
.restore_defaults()
274 def _on_properties_refresh_spin_focus_out_event(self
, widget
, *args
):
276 value
= widget
.get_value_as_int()
277 self
._presenter
.set_poll_frequency(value
)
279 def _on_properties_articles_spin_focus_out_event(self
, widget
, *args
):
281 value
= widget
.get_value_as_int()
282 self
._presenter
.set_items_stored(value
)
284 def _on_properties_articles_spin_value_changed(self
, widget
, *args
):
285 if self
._initializing
_window
:
287 self
._restore
_button
.set_sensitive(True)
289 def _on_properties_refresh_spin_value_changed(self
, widget
, *args
):
290 if self
._initializing
_window
:
292 self
._restore
_button
.set_sensitive(True)
294 def _on_properties_keep_refresh_default_toggled(self
, widget
, *args
):
295 if self
._initializing
_window
:
297 isactive
= widget
.get_active()
299 self
._presenter
.set_poll_frequency(feeds
.Feed
.DEFAULT
)
300 self
._refresh
_spin
.set_value(float(Config
.get_instance().poll_frequency
/ 60))
302 self
._presenter
.set_poll_frequency(self
._refresh
_spin
.get_value_as_int() * 60)
304 self
._refresh
_spin
.set_sensitive(not isactive
)
305 self
._restore
_button
.set_sensitive(True)
307 def _on_properties_keep_articles_default_toggled(self
, widget
, *args
):
308 if self
._initializing
_window
:
310 isactive
= widget
.get_active()
312 self
._presenter
.set_items_stored(feeds
.Feed
.DEFAULT
)
313 self
._articles
_spin
.set_value(float(Config
.get_instance().number_of_items_stored
))
315 self
._presenter
.set_items_stored(self
._articles
_spin
.get_value_as_int())
316 self
._articles
_spin
.set_sensitive(not isactive
)
317 self
._restore
_button
.set_sensitive(True)
319 class FeedPropertyPresenter(MVP
.BasicPresenter
):
323 def _initialize(self
):
326 def set_feed(self
, feed
):
328 self
._view
.set_feed(self
._feed
)
330 def set_username(self
, username
):
331 loc
, uname
, pw
= self
._feed
.access_info
332 self
._feed
.access_info
= (loc
, username
, pw
)
334 def set_password(self
, password
):
335 loc
, uname
, pw
= self
._feed
.access_info
336 self
._feed
.access_info
= (loc
, uname
, password
)
338 def set_poll_frequency(self
, pf
):
339 if pf
!= self
._feed
.poll_frequency
:
340 self
._feed
.poll_frequency
= pf
* FeedPropertyPresenter
.TIME_INTERVAL
342 def set_items_stored(self
, nitems
):
343 if nitems
!= self
._feed
.number_of_items_stored
:
344 self
._feed
.number_of_items_stored
= nitems
346 def feed_properties_show(feed
):
347 gladefile
= XML(os
.path
.join(straw
.defs
.STRAW_DATA_DIR
, "node-properties.glade"))
348 dialog
= FeedPropertyPresenter(view
=FeedPropertyView(gladefile
))
349 dialog
.set_feed(feed
)
353 def read_text(fragment
, chars
):
354 """Read chars cdata characters from html fragment fragment"""
355 parser
= SummaryParser
.TitleImgParser()
356 parser
.feed(fragment
)
357 text
= parser
.get_text(chars
)