3 Manages status messages
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 dbus
import DBusException
21 from subscribe
import subscribe_show
29 log
= error
.get_logger()
31 # Based on the values from NetworkManager/include/NetworkManager.h
32 # We only care about CONNECTED and DISCONNECTED at the moment.
33 NM_STATE_CONNECTED
= 3
34 NM_STATE_DISCONNECTED
= 4
36 class FeedReader(dbus
.service
.Object
):
37 service_name
= "org.gnome.feed.Reader"
38 object_path
= "/org/gnome/feed/Reader"
42 self
._session
_bus
= dbus
.SessionBus()
43 self
._service
= dbus
.service
.BusName(self
.service_name
, bus
=self
._session
_bus
)
44 dbus
.service
.Object
.__init
__(self
, self
._service
, self
.object_path
)
45 except DBusException
, e
:
46 logging
.info(_("Error while initializing feed subscribe service: [%s]" % str(e
)))
48 @dbus.service
.method("org.gnome.feed.Reader")
49 def Subscribe(self
, url
):
53 class NetworkListener(object):
54 SERVICE_NAME
= "org.freedesktop.NetworkManager"
55 SERVICE_PATH
= "/org/freedesktop/NetworkManager"
60 def set_state(self
, state
):
61 pass #self._config.offline = not (state == NM_STATE_CONNECTED)
63 def active_cb(self
, path
):
64 pass #self._config.offline = False
66 def inactive_cb(self
, path
):
67 pass #self._config.offline = True
71 systemBus
= dbus
.SystemBus()
72 proxy_obj
= systemBus
.get_object(NetworkListener
.SERVICE_NAME
, NetworkListener
.SERVICE_PATH
)
73 nl
= NetworkListener()
75 # don't touch offline if it has been previously set.
76 #if not Config.get_instance().offline:
77 # nl.set_state(proxy_obj.state())
79 nm_interface
= dbus
.Interface(proxy_obj
, NetworkListener
.SERVICE_NAME
)
80 nm_interface
.connect_to_signal('DeviceNowActive', nl
.active_cb
)
81 nm_interface
.connect_to_signal('DeviceNoLongerActive', nl
.inactive_cb
)
82 except DBusException
, e
:
83 log
.info(_("Unable to find NetworkManager service: [%s]" % str(e
)))
85 class StatusMessageManager(gobject
.GObject
):
88 'changed' : (gobject
.SIGNAL_RUN_LAST
, gobject
.TYPE_NONE
, ())
92 gobject
.GObject
.__init
__(self
)
95 def post_message(self
, message
):
96 self
.__messages
.append(message
)
99 def read_message(self
):
100 return self
.__messages
.pop(0)
102 def number_of_messages(self
):
103 return len(self
.__messages
)
106 def post_status_message(text
):
110 _smmanager
.post_message(text
)
112 def get_status_manager():
115 _smmanager
= StatusMessageManager()