#! /usr/bin/python # # Copyright (C) 2008 Ross Burton # # This program is free software: you can redistribute it and/or modify it under # the terms of the GNU General Public License as published by the Free Software # Foundation, either version 2 of the License, or (at your option) any later # version. # # This program is distributed in the hope that it will be useful, but WITHOUT # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more # details. # # You should have received a copy of the GNU General Public License along with # this program. If not, see . from fireeagle_api import FireEagle import dbus, geoclue, gobject, gtk, oauth, pynotify from dbus.mainloop.glib import DBusGMainLoop DBusGMainLoop(set_as_default=True) pynotify.init("Fire Eagle Location Updater") fe = FireEagle("NmUm6hxQ9a4u", "t4FM7LiUeD4RBwKSPa6ichKPDh5Jx4kt") user_token = oauth.OAuthConsumer("3Kaa4nssbGum", "eucZfQthzpAMJNp6nGGSrcNayfOW6bEl") bus = dbus.SessionBus() master = bus.get_object(geoclue.MASTER_SERVICE, geoclue.MASTER_PATH) client = bus.get_object(geoclue.MASTER_SERVICE, master.Create()) # TODO: should the resources be network, all, or a configuration option? client.SetRequirements(geoclue.Accuracy.LOCALITY, 0, True, geoclue.Resource.NETWORK) def geoclue2fireeagle(addr): """ Impedance matcher between GeoClue and Fire Eagle field naming. @addr is a dict of GeoClue fields, the return value is a dict of Fire Eagle fields. """ mapping = { "street": "address", "postalcode": "postal", "locality": "city", "region": "state", "country": "country" } new = {} for key in addr: if key in mapping: # TODO: should be able to remove str() new[mapping[key]] = str(addr[key]) return new address = dbus.Interface(client, dbus_interface=geoclue.ADDRESS_INTERFACE) def on_address_changed(timestamp, address, accuracy): # 0 accuracy is no data if accuracy[0] == geoclue.Accuracy.NONE: return address = geoclue2fireeagle(address) # TODO: call lookup to verify this address maps to a single location if fe.update(user_token, **address): n = pynotify.Notification("Updated location", "Location updated to somewhere, blaa blaa.") geom = icon.get_geometry()[1] n.set_hint("x", geom.x) n.set_hint("y", geom.y + geom.height) n.show() address.connect_to_signal("AddressChanged", on_address_changed) client.AddressStart() def idle(): on_address_changed(*address.GetAddress()) return False gobject.idle_add(idle) def show_location(): import webbrowser webbrowser.open("http://fireeagle.yahoo.net/my/location") icon = gtk.StatusIcon() icon.set_from_icon_name("stock_navigator") icon.set_tooltip("Fire Eagle") icon.connect("activate", lambda icon: show_location()) menu = gtk.Menu() item = gtk.MenuItem("_Show my location") item.connect("activate", lambda item: show_location()) menu.append(item) item = gtk.CheckMenuItem("_Update my location") item.set_active(True) item.set_sensitive(False) menu.append(item) menu.append(gtk.SeparatorMenuItem()) item = gtk.ImageMenuItem(gtk.STOCK_ABOUT) def on_about_activated(menuitem): about = gtk.AboutDialog() about.set_name("Fire Eagle Location Updater") about.set_copyright(u'Copyright \u00A9 2008 Ross Burton') about.set_authors(('Ross Burton ',)) about.set_website('http://burtonini.com/') about.set_logo_icon_name("stock_navigator") about.run() about.destroy() item.connect("activate", on_about_activated) menu.append(item) menu.show_all() def on_icon_popup(icon, button, timestamp): menu.popup(None, None, gtk.status_icon_position_menu, button, timestamp, icon) icon.connect("popup-menu", on_icon_popup) gtk.main()