class Configuration :
- def __init__ ( self ) :
- self.homedir = None
- self.dbname = None
- self.mapsdir , self.mapclass = None , None
- self.lat , self.lon = 0.0 , 0.0
- self.zoom = 0
- self.read()
-
- def read ( self ) :
- client = gconf.client_get_default()
- self.homedir = client.get_string( "/apps/wifihood/basedir" ) or "/home/user/MyDocs"
- self.dbname = client.get_string( "/apps/wifihood/dbname" ) or "wifiscanner.db"
- self.mapsdir = client.get_string( "/apps/wifihood/maps" ) or "/home/user/MyDocs/.maps"
- self.mapclass = client.get_string( "/apps/wifihood/maptype" ) or "OpenStreetMap I"
- self.lat = client.get_float( "/apps/wifihood/lattitude" ) or client.get_float( "/apps/maemo/maemo-mapper/center_latitude" ) or 40.416
- self.lon = client.get_float( "/apps/wifihood/longitude" ) or client.get_float( "/apps/maemo/maemo-mapper/center_longitude" ) or -3.683
- self.zoom = client.get_int( "/apps/wifihood/zoom" ) or client.get_float( "/apps/maemo/maemo-mapper/zoom" ) or 15
+ def __init__ ( self , type ) :
+ self._type = type
+ self._client = gconf.client_get_default()
+ self.homedir = self._client.get_string( "/apps/wifihood/basedir" ) or "/home/user/MyDocs"
+ self.homedir = "/tmp"
+ self.dbname = self._client.get_string( "/apps/wifihood/dbname" ) or "wifiscanner.db"
+ self.mapsdir = self._client.get_string( "/apps/wifihood/maps" ) or "/home/user/MyDocs/.maps"
+ self.mapclass = self._client.get_string( "/apps/wifihood/maptype" ) or "OpenStreetMap I"
+ self.lat = self._client.get_float( "/apps/wifihood/latitude" ) or self._client.get_float( "/apps/maemo/maemo-mapper/center_latitude" ) or 40.416
+ self.lon = self._client.get_float( "/apps/wifihood/longitude" ) or self._client.get_float( "/apps/maemo/maemo-mapper/center_longitude" ) or -3.683
+ if self._type == 'map' :
+ self.zoom = self._client.get_int( "/apps/wifihood/map-zoom" ) or self._client.get_float( "/apps/maemo/maemo-mapper/zoom" ) or 15
+ else :
+ self.zoom = self._client.get_int( "/apps/wifihood/%s-zoom" % self._type ) or 16
+
+ def set_latlon ( self , ( lat , lon ) ) :
+ self._client.set_float( "/apps/wifihood/latitude" , lat )
+ self._client.set_float( "/apps/wifihood/longitude" , lon )
+ self.lat , self.lon = lat , lon
+
+ def set_zoom ( self , zoom ) :
+ self._client.set_int( "/apps/wifihood/%s-zoom" % self._type , zoom )
+ self.zoom = zoom
def save ( self ) :
- client = gconf.client_get_default()
- client.set_string( "/apps/wifihood/basedir" , self.homedir )
- client.set_string( "/apps/wifihood/dbname" , self.dbname )
- client.set_string( "/apps/wifihood/maps" , self.mapsdir )
- client.set_string( "/apps/wifihood/maptype" , self.mapclass )
- client.set_float( "/apps/wifihood/lattitude" , self.lat )
- client.set_float( "/apps/wifihood/longitude" , self.lon )
- client.set_int( "/apps/wifihood/zoom" , self.zoom )
+ self._client.set_string( "/apps/wifihood/basedir" , self.homedir )
+ self._client.set_string( "/apps/wifihood/dbname" , self.dbname )
+ self._client.set_string( "/apps/wifihood/maps" , self.mapsdir )
+ self._client.set_string( "/apps/wifihood/maptype" , self.mapclass )
class AbstractSettingsWindow :
def zoomdialog ( self , widget , conf ) :
newzoom = int( widget.get_selector().get_current_text() )
if self.handler : self.handler( newzoom )
- conf.zoom = newzoom
+ conf.set_zoom( newzoom )
class SettingsWindow ( hildon.StackableWindow , AbstractSettingsWindow ) :
newzoom = model.get(item,0)[0]
if labelsetter : labelsetter( newzoom )
if handler : handler( newzoom )
- config.zoom = newzoom
+ config.set_zoom( newzoom )
self.destroy()
class SettingsWindow ( gtk.Window , AbstractSettingsWindow ) :
def CheckButton ( self ) :
return gtk.CheckButton()
-config = Configuration()
-
if __name__ == "__main__" :
+ config = Configuration( 'scanner' )
window = SettingsWindow( config )
window.connect("delete_event", gtk.main_quit, None)
window.show()
import os
-conf = config.Configuration()
-
class Scanner ( gps.GPSObject , wifiscan.WifiScanner ) :
def __init__ ( self , ifname="wlan0" ) :
gps.GPSObject.__init__( self )
wifiscan.WifiScanner.__init__( self , ifname )
- self.db = db.database( os.path.join( conf.homedir , conf.dbname ) )
+ conf = config.Configuration( 'scanner' )
+ self.homedir = conf.homedir
+ self.db = db.database( os.path.join( self.homedir , conf.dbname ) )
# Values to be set by wireless scans
self.newap = 0
self.write_logs()
def write_logs ( self ) :
- fd = open( os.path.join( conf.homedir , "wiscan_gui.info" ) , 'a' )
+ fd = open( os.path.join( self.homedir , "wiscan_gui.info" ) , 'a' )
fd.write( "%s %s %s\n" % ( self.tstamp , self.info , self.scanlist ) )
fd.close()
if self.satellites :
- loclist = open( os.path.join( conf.homedir , "location.info" ) , 'a' )
+ loclist = open( os.path.join( self.homedir , "location.info" ) , 'a' )
loclist.write ( "%s\n" % ( self.satellites ,) )
loclist.close()
if self.cells :
- celllist = open( os.path.join( conf.homedir , "cell.info" ) , 'a' )
+ celllist = open( os.path.join( self.homedir , "cell.info" ) , 'a' )
celllist.write ( "%s\n" % ( self.cells ,) )
celllist.close()
# FIXME : instead of hardcoded, should depend on the actual display size
if distance > 150 :
- self.conf.lat , self.conf.lon = latlon
+ self.conf.set_latlon( latlon )
self.reftile_x , self.refpix_x = self.lon2tilex( self.conf.lon , self.conf.zoom )
self.reftile_y , self.refpix_y = self.lat2tiley( self.conf.lat , self.conf.zoom )
lon = self.tilex2lon( ( self.reftile_x , self.refpix_x ) , self.conf.zoom )
self.reftile_x , self.refpix_x = self.lon2tilex( lon , zoom )
self.reftile_y , self.refpix_y = self.lat2tiley( lat , zoom )
- self.conf.zoom = zoom
+ self.conf.set_zoom( zoom )
self.composeMap()
self.show()