X-Git-Url: http://git.maemo.org/git/?a=blobdiff_plain;f=wifiscanner%2Fwifimap%2Fconfig.py;h=78c59742defa3b84806ecc5861dfc79a8e88ce01;hb=e4cb350eceeaa7a50e20de154c9f59139703eefb;hp=f7caad9d1367f1a2f0305d819fec884985b3622e;hpb=4f44e9a0570ff3c70e7c02596a6bc614f98dd23e;p=wifihood diff --git a/wifiscanner/wifimap/config.py b/wifiscanner/wifimap/config.py index f7caad9..78c5974 100644 --- a/wifiscanner/wifimap/config.py +++ b/wifiscanner/wifimap/config.py @@ -9,34 +9,67 @@ except : 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 + def __init__ ( self , type ) : + self._type = type 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 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 = gconf.client_get_default() + + self.homedir = self._client.get_string( "/apps/wifihood/basedir" ) or "/home/user/MyDocs" + 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.scan_period = self._client.get_int( "/apps/wifihood/scan-period" ) or 5000 + + self.store_log = self._client.get_bool( "/apps/wifihood/store-logfile" ) + + self.use_mapper = self._client.get_bool( "/apps/wifihood/use-mapper" ) + self.store_gps = self._client.get_bool( "/apps/wifihood/store-gps" ) + if self.use_mapper : + # FIXME : This will reset the stored default + self.store_gps = False + self.lat = self._client.get_float( "/apps/maemo/maemo-mapper/center_latitude" ) + self.lon = self._client.get_float( "/apps/maemo/maemo-mapper/center_longitude" ) + self.zoom = self._client.get_int( "/apps/maemo/maemo-mapper/zoom" ) + else : + self.lat = self._client.get_float( "/apps/wifihood/latitude" ) + self.lon = self._client.get_float( "/apps/wifihood/longitude" ) + self.zoom = self._client.get_int( "/apps/wifihood/map-zoom" ) + + if self._type == 'scanner' : + self.zoom = self._client.get_int( "/apps/wifihood/%s-zoom" % self._type ) + + if self.lat == 0.0 and self.lon == 0.0 : + self.lat , self.lon = 40.416 , -3.683 + if self.zoom == 0 : + self.zoom = 15 + + def set_latlon ( self , ( lat , lon ) ) : + if self.store_gps : + 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 ) : + if self.store_gps or self._type == 'scanner' : + self._client.set_int( "/apps/wifihood/%s-zoom" % self._type , zoom ) + self.zoom = zoom + + def save ( self , widget , event ) : + 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 ) + + self._client.set_int( "/apps/wifihood/scan-period" , self.scan_period ) + self._client.set_bool( "/apps/wifihood/store-logfile" , self.store_log ) + self._client.set_bool( "/apps/wifihood/use-mapper" , self.use_mapper ) + self._client.set_bool( "/apps/wifihood/store-gps" , self.store_gps ) + + self.set_latlon( ( self.lat , self.lon ) ) + self.set_zoom( self.zoom ) class AbstractSettingsWindow : @@ -66,6 +99,7 @@ class AbstractSettingsWindow : database.attach(dblabel, 0, 1, 0, 1, gtk.EXPAND|gtk.FILL, 0, 0, 5) dbvalue = self.Entry() + dbvalue.connect( "unrealize" , self.entry_cb , config , "basedir" ) dbvalue.set_text( config.homedir ) dbvalue.show() database.attach(dbvalue, 1, 2, 0, 1, gtk.EXPAND|gtk.FILL, 0, 0, 5) @@ -75,6 +109,7 @@ class AbstractSettingsWindow : database.attach(dblabel, 0, 1, 1, 2, gtk.EXPAND|gtk.FILL, 0, 0, 5) dbvalue = self.Entry() + dbvalue.connect( "unrealize" , self.entry_cb , config , "dbname" ) dbvalue.set_text( config.dbname ) dbvalue.show() database.attach(dbvalue, 1, 2, 1, 2, gtk.EXPAND|gtk.FILL, 0, 0, 5) @@ -111,11 +146,15 @@ class AbstractSettingsWindow : button = self.CheckButton() button.set_label( "Take initial coordinates from maemo-mapper" ) + button.connect( "toggled" , self.checkbutton_cb , config , "use-mapper" ) + button.set_active( config.use_mapper ) button.show() gps.attach(button, 0, 2, 0, 1, gtk.EXPAND|gtk.FILL) #, 0, 0, 5) button = self.CheckButton() button.set_label( "Store changes in coordinates" ) + button.connect( "toggled" , self.checkbutton_cb , config , "store-gps" ) + button.set_active( config.store_gps ) button.show() gps.attach(button, 0, 2, 1, 2, gtk.EXPAND|gtk.FILL) #, 0, 0, 5) @@ -125,13 +164,38 @@ class AbstractSettingsWindow : dataframe.show() vbox.pack_start(dataframe, True, True, 0) + datatable = gtk.Table(2, 2, False) + datatable.show() + dataframe.add(datatable) + + scanlabel = gtk.Label( "Scanning interval" ) + scanlabel.show() + datatable.attach(scanlabel, 0, 1, 0, 1, gtk.EXPAND|gtk.FILL) + + scanvalue = self.Entry() + scanvalue.connect( "unrealize" , self.int_cb , config , "scan-period" , 1000 ) + scanvalue.set_text( "%s" % ( float(config.scan_period) / 1000 ) ) + scanvalue.show() + datatable.attach(scanvalue, 1, 2, 0, 1, gtk.EXPAND|gtk.FILL) + button = self.CheckButton() button.set_label( "Write full logfile" ) + button.connect( "toggled" , self.checkbutton_cb , config , "store-logfile" ) + button.set_active( config.store_log ) button.show() - dataframe.add(button) + datatable.attach(button, 0, 2, 1, 2, gtk.EXPAND|gtk.FILL) self.show() + def entry_cb ( self , entry , config , keyword ) : + config._client.set_string( "%s/%s" % ( "/apps/wifihood" , keyword ) , entry.get_text() ) + + def int_cb ( self , entry , config , keyword , scale=1 ) : + config._client.set_int( "%s/%s" % ( "/apps/wifihood" , keyword ) , int( scale * float( entry.get_text() ) ) ) + + def checkbutton_cb ( self , button , config , keyword ) : + config._client.set_bool( "%s/%s" % ( "/apps/wifihood" , keyword ) , button.get_active() ) + if hildon : class ZoomDialog ( hildon.TouchSelector ) : @@ -158,7 +222,7 @@ if hildon : 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 ) : @@ -223,7 +287,7 @@ else : 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 ) : @@ -231,10 +295,11 @@ else : def __init__ ( self , config , handler=None ) : gtk.Window.__init__( self ) AbstractSettingsWindow.__init__( self , config , handler ) + self.connect_object("delete_event", config.save , self ) def MainArea ( self ) : scrollwin = gtk.ScrolledWindow() - scrollwin.set_size_request(-1, 260) + scrollwin.set_size_request(-1, 290) scrollwin.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC) return scrollwin @@ -264,9 +329,8 @@ else : 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()