Implemented "mark all as read".
[straw.git] / straw / OfflineToggle.py
blobc4b39dbf6ab1d829477a176b867340406c9346e4
1 """ OfflineToggle.py
3 """
4 __copyright__ = "Copyright (c) 2002-2005 Free Software Foundation, Inc."
5 __license__ = """
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
9 version.
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 Constants import *
20 import pygtk
21 pygtk.require('2.0')
22 import gtk
23 import os
24 import MVP
25 import Config
27 class OfflineView(MVP.WidgetView):
28 """
29 Model: Config module
30 Presenter: OfflinePresenter instance
31 """
33 def _initialize(self):
34 self._tooltips = gtk.Tooltips()
35 self._tooltips.enable()
37 def _on_offline_toggle_toggled(self, *args):
38 status = self._widget.get_active()
39 if status != self._model.get(OPTION_OFFLINE):
40 self._model.set(OPTION_OFFLINE, status)
42 def set_status(self, active):
43 self._widget.set_active(active)
45 def set_text(self, text):
46 self._tooltips.set_tip(self._widget, text, text)
48 def set_icon(self, icon):
49 image = self._widget.get_child()
50 image.set_from_stock(icon, gtk.ICON_SIZE_BUTTON)
52 class OfflinePresenter(MVP.BasicPresenter):
53 """
54 Model: Config module
55 View: OfflineView instance
56 """
58 def _initialize(self):
59 self._attribs = {'online': (gtk.STOCK_CONNECT, _("Straw is currently online. Click to go offline.")),
60 'offline': (gtk.STOCK_DISCONNECT, _("Straw is currently offline. Click to go online."))}
62 #self._model.connect('offline-mode-changed', self._config_offline_changed)
63 if self._model.get(OPTION_OFFLINE):
64 self._config_offline_changed(None)
66 def _config_offline_changed(self, config):
67 offline = self._model.get(OPTION_OFFLINE)
68 if offline:
69 icon, tip = self._attribs.get('offline')
70 else:
71 icon, tip = self._attribs.get('online')
72 self._view.set_status(offline)
73 self._view.set_text(tip)
74 self._view.set_icon(icon)
76 class OfflineToggle:
77 def __init__(self, widget):
78 oview = OfflineView(widget, model=Config)
79 self._presenter = OfflinePresenter(model=Config, view=oview)