2 Provides a module for handling the properties of a Feed.
4 __copyright__
= "Copyright (c) 2002-2005 Free Software Foundation, Inc."
6 Straw is free software; you can redistribute it and/or modify it under the
7 terms of the GNU General Public License as published by the Free Software
8 Foundation; either version 2 of the License, or (at your option) any later
11 Straw is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
13 A PARTICULAR PURPOSE. See the GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License along with
16 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
17 Place - Suite 330, Boston, MA 02111-1307, USA. """
19 from error
import log
, logparam
, logtb
20 from gtk
.glade
import XML
21 from straw
import helpers
22 from xml
.sax
import saxutils
33 class FeedPropertyView(MVP
.GladeView
):
39 def _initialize(self
):
41 self
._defaults
= {'title':'','url':'','username':'','password':''}
42 self
._window
= self
._widget
.get_widget('feed_properties')
44 self
._title
_entry
= self
._widget
.get_widget('title_entry')
45 self
._location
_entry
= self
._widget
.get_widget('location_entry')
46 self
._website
_entry
= self
._widget
.get_widget('website_entry')
47 self
._description
_label
= self
._widget
.get_widget('description_label')
48 self
._copyright
_label
= self
._widget
.get_widget('copyright_label')
50 self
._username
= self
._widget
.get_widget('properties_username_entry')
51 self
._password
= self
._widget
.get_widget('properties_password_entry')
53 self
._next
_refresh
_label
= self
._widget
.get_widget('properties_next_refresh_label')
54 self
._previous
_refresh
_label
= self
._widget
.get_widget('properties_previous_refresh_label')
56 self
._restore
_button
= self
._widget
.get_widget('properties_reset_button')
57 self
._refresh
_spin
= self
._widget
.get_widget('properties_refresh_spin')
58 self
._articles
_spin
= self
._widget
.get_widget('properties_articles_spin')
59 self
._refresh
_default
_check
= self
._widget
.get_widget('properties_keep_refresh_default')
60 self
._articles
_default
_check
= self
._widget
.get_widget('properties_keep_articles_default')
62 def set_feed(self
, feed
):
66 self
._initializing
_window
= True
67 self
.display_properties()
68 self
._window
.present()
69 self
._initializing
_window
= False
71 def hide(self
, *args
):
73 self
._window
.destroy()
75 def _on_feed_properties_delete_event(self
, *args
):
79 def _on_properties_close_button_clicked(self
, *args
):
83 def _on_location_button_clicked(self
, *args
):
84 helpers
.url_show(self
._location
_entry
.get_text())
86 def _on_website_button_clicked(self
, *args
):
87 helpers
.url_show(self
._website
_entry
.get_text())
89 def display_properties(self
):
90 self
._window
.set_title(_("%s Properties") % self
._feed
.title
)
92 self
._title
_entry
.set_text(self
._feed
.title
)
93 self
._location
_entry
.set_text(self
._feed
.location
)
95 self
._website
_entry
.set_text(self
._feed
.link
)
97 for key
in ("description", "copyright", "category", "generator",
98 "creator", "webmaster", "ttl"):
99 label
= self
._widget
.get_widget("%s_label" % key
)
100 input = self
._widget
.get_widget("%s_input" % key
)
104 if hasattr(self
._feed
, key
):
105 value
= getattr(self
._feed
, key
)
106 elif self
._feed
.pdict
.has_key(key
):
107 value
= self
._feed
.pdict
[key
]
111 input.set_text(value
)
114 window
= self
._widget
.get_widget("%s_window" % key
)
119 def _load_uri(self
, widget
, event
):
120 helpers
.url_show(widget
.get_uri())
122 def restore_defaults(self
):
123 # FIXME: add frequency and number of items and the default flags
124 self
._feed
.title
= self
._defaults
['title']
125 self
._feed
.access_info
= (
126 self
._defaults
['url'], self
._defaults
['username'], self
._defaults
['password'])
127 self
._title
.set_text(self
._feed
.title
)
128 self
._location
.set_text(self
._feed
.location
)
129 self
._username
.set_text(self
._defaults
.get('username',''))
130 self
._password
.set_text(self
._defaults
.get('password',''))
131 self
._refresh
_default
_check
.set_active(self
._refresh
_keep
)
132 if not self
._refresh
_keep
:
133 self
._refresh
_spin
.set_value(float(self
._refresh
_default
))
134 self
._articles
_default
_check
.set_active(self
._articles
_keep
)
135 if not self
._articles
_keep
:
136 self
._articles
_spin
.set_value(float(self
._articles
_default
))
137 self
._restore
_button
.set_sensitive(False)
139 def _on_close_button_clicked(self
, *args
):
142 def _on_properties_title_entry_insert_text(self
, *args
):
143 if self
._initializing
_window
:
145 self
._restore
_button
.set_sensitive(True)
147 def _on_properties_title_entry_delete_text(self
, *args
):
148 if self
._initializing
_window
:
150 self
._restore
_button
.set_sensitive(True)
152 def _on_properties_title_entry_focus_out_event(self
, widget
, *args
):
153 self
._feed
.title
= widget
.get_text().strip()
155 def _on_properties_location_entry_insert_text(self
, *args
):
156 if self
._initializing
_window
:
158 self
._restore
_button
.set_sensitive(True)
160 def _on_properties_location_entry_delete_text(self
, *args
):
161 if self
._initializing
_window
:
163 self
._restore
_button
.set_sensitive(True)
165 def _on_properties_location_entry_focus_out_event(self
, widget
, *args
):
166 loc
, username
, pw
= self
._feed
.access_info
167 self
._feed
.access_info
= (widget
.get_text().strip(), username
, pw
)
169 def _on_properties_username_entry_insert_text(self
, *args
):
170 if self
._initializing
_window
:
172 self
._restore
_button
.set_sensitive(True)
174 def _on_properties_username_entry_delete_text(self
, *args
):
175 if self
._initializing
_window
:
177 self
._restore
_button
.set_sensitive(False)
179 def _on_properties_username_entry_focus_out_event(self
, widget
, *args
):
180 self
._presenter
.set_username(widget
.get_text().strip())
182 def _on_properties_password_entry_insert_text(self
, *args
):
183 if self
._initializing
_window
:
185 self
._restore
_button
.set_sensitive(True)
187 def _on_properties_password_entry_delete_text(self
, *args
):
188 if self
._initializing
_window
:
190 self
._restore
_button
.set_sensitive(False)
192 def _on_properties_password_entry_focus_out_event(self
, widget
, *args
):
193 self
._presenter
.set_password(widget
.get_text().strip())
195 def _on_properties_reset_button_clicked(self
, *args
):
196 self
.restore_defaults()
198 def _on_properties_refresh_spin_focus_out_event(self
, widget
, *args
):
200 value
= widget
.get_value_as_int()
201 self
._presenter
.set_poll_frequency(value
)
203 def _on_properties_articles_spin_focus_out_event(self
, widget
, *args
):
205 value
= widget
.get_value_as_int()
206 self
._presenter
.set_items_stored(value
)
208 def _on_properties_articles_spin_value_changed(self
, widget
, *args
):
209 if self
._initializing
_window
:
211 self
._restore
_button
.set_sensitive(True)
213 def _on_properties_refresh_spin_value_changed(self
, widget
, *args
):
214 if self
._initializing
_window
:
216 self
._restore
_button
.set_sensitive(True)
218 def _on_properties_keep_refresh_default_toggled(self
, widget
, *args
):
219 if self
._initializing
_window
:
221 isactive
= widget
.get_active()
223 self
._presenter
.set_poll_frequency(feeds
.Feed
.DEFAULT
)
224 self
._refresh
_spin
.set_value(float(Config
.get_instance().poll_frequency
/ 60))
226 self
._presenter
.set_poll_frequency(self
._refresh
_spin
.get_value_as_int() * 60)
228 self
._refresh
_spin
.set_sensitive(not isactive
)
229 self
._restore
_button
.set_sensitive(True)
231 def _on_properties_keep_articles_default_toggled(self
, widget
, *args
):
232 if self
._initializing
_window
:
234 isactive
= widget
.get_active()
236 self
._presenter
.set_items_stored(feeds
.Feed
.DEFAULT
)
237 self
._articles
_spin
.set_value(float(Config
.get_instance().number_of_items_stored
))
239 self
._presenter
.set_items_stored(self
._articles
_spin
.get_value_as_int())
240 self
._articles
_spin
.set_sensitive(not isactive
)
241 self
._restore
_button
.set_sensitive(True)
243 class FeedPropertyPresenter(MVP
.BasicPresenter
):
247 def _initialize(self
):
250 def set_feed(self
, feed
):
252 self
._view
.set_feed(self
._feed
)
254 def set_username(self
, username
):
255 loc
, uname
, pw
= self
._feed
.access_info
256 self
._feed
.access_info
= (loc
, username
, pw
)
258 def set_password(self
, password
):
259 loc
, uname
, pw
= self
._feed
.access_info
260 self
._feed
.access_info
= (loc
, uname
, password
)
262 def set_poll_frequency(self
, pf
):
263 if pf
!= self
._feed
.poll_frequency
:
264 self
._feed
.poll_frequency
= pf
* FeedPropertyPresenter
.TIME_INTERVAL
266 def set_items_stored(self
, nitems
):
267 if nitems
!= self
._feed
.number_of_items_stored
:
268 self
._feed
.number_of_items_stored
= nitems
271 gladefile
= XML(os
.path
.join(straw
.defs
.STRAW_DATA_DIR
, "node-properties.glade"))
272 dialog
= FeedPropertyPresenter(view
=FeedPropertyView(gladefile
))
273 dialog
.set_feed(feed
)
277 def read_text(fragment
, chars
):
278 """Read chars cdata characters from html fragment fragment"""
279 parser
= SummaryParser
.TitleImgParser()
280 parser
.feed(fragment
)
281 text
= parser
.get_text(chars
)