2 Provides a module for handling the properties of a Category.
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
._category
.name
)
92 self
._title
_entry
.set_text(self
._category
.name
)
94 def _load_uri(self
, widget
, event
):
95 helpers
.url_show(widget
.get_uri())
97 def restore_defaults(self
):
98 # FIXME: add frequency and number of items and the default flags
99 self
._category
.name
= self
._defaults
['title']
100 self
._category
.access_info
= (
101 self
._defaults
['url'], self
._defaults
['username'], self
._defaults
['password'])
102 self
._title
.set_text(self
._category
.name
)
103 self
._location
.set_text(self
._category
.location
)
104 self
._username
.set_text(self
._defaults
.get('username',''))
105 self
._password
.set_text(self
._defaults
.get('password',''))
106 self
._refresh
_default
_check
.set_active(self
._refresh
_keep
)
107 if not self
._refresh
_keep
:
108 self
._refresh
_spin
.set_value(float(self
._refresh
_default
))
109 self
._articles
_default
_check
.set_active(self
._articles
_keep
)
110 if not self
._articles
_keep
:
111 self
._articles
_spin
.set_value(float(self
._articles
_default
))
112 self
._restore
_button
.set_sensitive(False)
114 def _on_close_button_clicked(self
, *args
):
117 def _on_properties_title_entry_insert_text(self
, *args
):
118 if self
._initializing
_window
:
120 self
._restore
_button
.set_sensitive(True)
122 def _on_properties_title_entry_delete_text(self
, *args
):
123 if self
._initializing
_window
:
125 self
._restore
_button
.set_sensitive(True)
127 def _on_properties_title_entry_focus_out_event(self
, widget
, *args
):
128 self
._category
.name
= widget
.get_text().strip()
130 def _on_properties_location_entry_insert_text(self
, *args
):
131 if self
._initializing
_window
:
133 self
._restore
_button
.set_sensitive(True)
135 def _on_properties_location_entry_delete_text(self
, *args
):
136 if self
._initializing
_window
:
138 self
._restore
_button
.set_sensitive(True)
140 def _on_properties_location_entry_focus_out_event(self
, widget
, *args
):
141 loc
, username
, pw
= self
._category
.access_info
142 self
._category
.access_info
= (widget
.get_text().strip(), username
, pw
)
144 def _on_properties_username_entry_insert_text(self
, *args
):
145 if self
._initializing
_window
:
147 self
._restore
_button
.set_sensitive(True)
149 def _on_properties_username_entry_delete_text(self
, *args
):
150 if self
._initializing
_window
:
152 self
._restore
_button
.set_sensitive(False)
154 def _on_properties_username_entry_focus_out_event(self
, widget
, *args
):
155 self
._presenter
.set_username(widget
.get_text().strip())
157 def _on_properties_password_entry_insert_text(self
, *args
):
158 if self
._initializing
_window
:
160 self
._restore
_button
.set_sensitive(True)
162 def _on_properties_password_entry_delete_text(self
, *args
):
163 if self
._initializing
_window
:
165 self
._restore
_button
.set_sensitive(False)
167 def _on_properties_password_entry_focus_out_event(self
, widget
, *args
):
168 self
._presenter
.set_password(widget
.get_text().strip())
170 def _on_properties_reset_button_clicked(self
, *args
):
171 self
.restore_defaults()
173 def _on_properties_refresh_spin_focus_out_event(self
, widget
, *args
):
175 value
= widget
.get_value_as_int()
176 self
._presenter
.set_poll_frequency(value
)
178 def _on_properties_articles_spin_focus_out_event(self
, widget
, *args
):
180 value
= widget
.get_value_as_int()
181 self
._presenter
.set_items_stored(value
)
183 def _on_properties_articles_spin_value_changed(self
, widget
, *args
):
184 if self
._initializing
_window
:
186 self
._restore
_button
.set_sensitive(True)
188 def _on_properties_refresh_spin_value_changed(self
, widget
, *args
):
189 if self
._initializing
_window
:
191 self
._restore
_button
.set_sensitive(True)
193 def _on_properties_keep_refresh_default_toggled(self
, widget
, *args
):
194 if self
._initializing
_window
:
196 isactive
= widget
.get_active()
198 self
._presenter
.set_poll_frequency(feeds
.Feed
.DEFAULT
)
199 self
._refresh
_spin
.set_value(float(Config
.get_instance().poll_frequency
/ 60))
201 self
._presenter
.set_poll_frequency(self
._refresh
_spin
.get_value_as_int() * 60)
203 self
._refresh
_spin
.set_sensitive(not isactive
)
204 self
._restore
_button
.set_sensitive(True)
206 def _on_properties_keep_articles_default_toggled(self
, widget
, *args
):
207 if self
._initializing
_window
:
209 isactive
= widget
.get_active()
211 self
._presenter
.set_items_stored(feeds
.Feed
.DEFAULT
)
212 self
._articles
_spin
.set_value(float(Config
.get_instance().number_of_items_stored
))
214 self
._presenter
.set_items_stored(self
._articles
_spin
.get_value_as_int())
215 self
._articles
_spin
.set_sensitive(not isactive
)
216 self
._restore
_button
.set_sensitive(True)
218 class FeedPropertyPresenter(MVP
.BasicPresenter
):
222 def _initialize(self
):
223 self
._category
= None
225 def set_feed(self
, feed
):
226 self
._category
= feed
227 self
._view
.set_feed(self
._category
)
229 def set_username(self
, username
):
230 loc
, uname
, pw
= self
._category
.access_info
231 self
._category
.access_info
= (loc
, username
, pw
)
233 def set_password(self
, password
):
234 loc
, uname
, pw
= self
._category
.access_info
235 self
._category
.access_info
= (loc
, uname
, password
)
237 def set_poll_frequency(self
, pf
):
238 if pf
!= self
._category
.poll_frequency
:
239 self
._category
.poll_frequency
= pf
* FeedPropertyPresenter
.TIME_INTERVAL
241 def set_items_stored(self
, nitems
):
242 if nitems
!= self
._category
.number_of_items_stored
:
243 self
._category
.number_of_items_stored
= nitems
246 gladefile
= XML(os
.path
.join(straw
.defs
.STRAW_DATA_DIR
, "node-properties.glade"))
247 dialog
= FeedPropertyPresenter(view
=FeedPropertyView(gladefile
))
248 dialog
.set_feed(feed
)
252 def read_text(fragment
, chars
):
253 """Read chars cdata characters from html fragment fragment"""
254 parser
= SummaryParser
.TitleImgParser()
255 parser
.feed(fragment
)
256 text
= parser
.get_text(chars
)