[current profile] add new module with ability to change ringtone from GUI
authorSebastian Krzyszkowiak <seba.dos1@gmail.com>
Tue, 24 Feb 2009 09:52:59 +0000 (10:52 +0100)
committerSebastian Krzyszkowiak <seba.dos1@gmail.com>
Tue, 24 Feb 2009 09:52:59 +0000 (10:52 +0100)
shr-settings
shr_settings_modules/shr_currentprofile.py [new file with mode: 0644]

index f6c929f..0ac8816 100755 (executable)
@@ -4,7 +4,7 @@ import ecore
 import dbus, e_dbus
 import os
 
-from shr_settings_modules import shr_gsm, shr_device_timeouts,shr_pm, shr_bt, shr_wifi, shr_gprs, shr_usb, shr_clock, shr_profile, shr_services, shr_test, shr_gps, shr_sim, shr_battery
+from shr_settings_modules import shr_gsm, shr_device_timeouts,shr_pm, shr_bt, shr_wifi, shr_gprs, shr_usb, shr_clock, shr_profile, shr_services, shr_test, shr_gps, shr_sim, shr_battery, shr_currentprofile
 
 class CategoryButton(elementary.Button):
     def set_modules(self, modules):
@@ -111,12 +111,12 @@ class ModulesWindow:
 
         self.modList = []
         #DEBUG
-        #for mod in modulesList[2]:
-        #
-        #    print "debug loading %s" % mod
-        #    debugmod=mod(self.win2, bus)
-        #    if debugmod.isEnabled():
-        #        debugmod.createView()
+        for mod in modulesList[2]:
+        
+            print "debug loading %s" % mod
+            debugmod=mod(self.win2, bus)
+            if debugmod.isEnabled():
+                debugmod.createView()
         #END OF DEBUG
         ecore.idler_add(self.renderModules, modulesList, bus)
         self.win2.show()
@@ -199,7 +199,7 @@ class MainWindow:
         dirs = [    ["GSM","ico_gsm_32_32.png",                        [ shr_gsm.Gsm, shr_sim.Sim ] ],
                     ["Bluetooth","ico_bt_32_32.png",                   [ shr_bt.Bt ] ],
                     ["Internet","ico_internet_32_32.png",              [ shr_wifi.Wifi, shr_gprs.Gprs ] ],
-                    ["Profiles","ico_profile_32_32.png",               [ shr_profile.Profile ] ],
+                    ["Profiles","ico_profile_32_32.png",               [ shr_profile.Profile, shr_currentprofile.CurrentProfile ] ],
                     ["Date/time","ico_timeset_32_32.png",                  [ shr_clock.Clock ] ],
                     ["Power","ico_powermanager_32_32.png",  [ shr_battery.Battery, shr_pm.Pm , shr_device_timeouts.Timeouts ] ],
                     ["USB","ico_usb_32_32.png",                        [ shr_usb.Usb ] ],
diff --git a/shr_settings_modules/shr_currentprofile.py b/shr_settings_modules/shr_currentprofile.py
new file mode 100644 (file)
index 0000000..a38e346
--- /dev/null
@@ -0,0 +1,121 @@
+import elementary
+import ecore
+import module
+import dbus
+import os
+
+def getDbusObject (bus, busname , objectpath , interface):
+        dbusObject = bus.get_object(busname, objectpath)
+        return dbus.Interface(dbusObject, dbus_interface=interface)
+
+class FileButton(elementary.Button):
+    def set_filename( self, filename ):
+        self.filename = filename
+        self.label_set(filename)
+
+    def get_filename( self ):
+        return self.filename
+
+class CurrentProfile(module.AbstractModule):
+    name = "Current profile"    
+
+    def setringtone(self, obj, event):
+        self.dbusobj.SetValue('ring-tone',obj.get_filename())
+        self.destroy(obj, event)
+        self.update()
+
+    def destroy(self, obj, event):
+        self.win.hide()
+
+    def tonegui(self, obj, event):
+        self.win = elementary.Window("change-ringtone",elementary.ELM_WIN_BASIC)
+        bg = elementary.Background(self.win)
+        self.win.resize_object_add(bg)
+        self.win.title_set("Change ringtone")
+        bg.show()
+        self.win.autodel_set(1)
+        box = elementary.Box(self.win)
+        fr = elementary.Frame(self.win)
+        fr.label_set("Select ringtone")
+        lab = elementary.Label(self.win)
+        lab.label_set("Ringtones are placed in /usr/share/sounds/")
+        fr.content_set(lab)
+        lab.show()
+        fr.show()
+        fr.size_hint_align_set(-1.0, 0.0)
+        box.pack_start(fr)
+        scr = elementary.Scroller(self.win)
+        scr.size_hint_weight_set(1.0, 1.0)
+        scr.size_hint_align_set(-1.0, -1.0)
+        box.pack_end(scr)
+        exitbtn = elementary.Button(self.win)
+        exitbtn.label_set("Quit")
+        exitbtn.size_hint_weight_set(1.0, 0.0)
+        exitbtn.size_hint_align_set(-1.0, -1.0)
+        exitbtn.clicked = self.destroy
+        box.pack_end(exitbtn)
+        self.win.resize_object_add(box)
+        box.show()
+        scr.show()
+        exitbtn.show()
+        self.win.show()
+
+        box1 = elementary.Box(self.win)
+        scr.content_set(box1)
+        box1.size_hint_weight_set(1.0, 0.0)
+        box1.show()
+
+        for filename in os.listdir("/usr/share/sounds"):
+            filebtn = FileButton(self.win)
+            filebtn.set_filename(filename)
+            filebtn.clicked = self.setringtone
+            filebtn.size_hint_align_set(-1.0, 0.0)
+            box1.pack_end(filebtn)
+            filebtn.show()
+
+    def update(self):
+        keys = self.dbusobj.GetKeys()
+        for i in keys:
+            wyn = self.dbusobj.GetValue(i)
+            try:
+                self.labels[i].label_set(str(wyn))
+            except:
+                frame = elementary.Frame(self.window)
+                frame.label_set(i)
+                label = elementary.Label(self.window)
+                label.label_set(str(wyn))
+                self.labels[i] = label
+
+#                if i in ['ring-tone','message-tone']:
+                if i=='ring-tone':
+                    table = elementary.Box(self.window)
+                    table.pack_start(label)
+                    table.size_hint_align_set(-1.0, 0.0)
+                    table.size_hint_weight_set(1.0, 1.0)
+                    label.size_hint_align_set(-1.0, 0.0)
+                    tonebtn = elementary.Button(self.window)
+                    tonebtn.label_set("change")
+                    tonebtn.clicked = self.tonegui
+                    tonebtn.size_hint_align_set(-1.0, 0.0)
+                    tonebtn.show()
+                    table.pack_end(tonebtn)
+                    frame.content_set(table)
+                    table.show()
+                else:   
+                    frame.content_set(label)
+
+                frame.size_hint_align_set(-1.0, 0.0)
+                frame.size_hint_weight_set(1.0, 1.0)
+                label.show()
+                frame.show()
+                self.main.pack_start(frame)
+        return 1
+                
+    def createView(self):
+        self.dbusobj = getDbusObject(self.dbus,"org.freesmartphone.opreferencesd","/org/freesmartphone/Preferences/phone","org.freesmartphone.Preferences.Service")
+       self.main = elementary.Box(self.window)
+        self.labels = {}
+        self.update()
+        #self.dbus.add_signal_receiver(self.update, "
+        ecore.timer_add( 5, self.update)
+        return self.main