From: Pali Rohár Date: Fri, 20 Jul 2012 08:16:20 +0000 (+0200) Subject: Some fixes: X-Git-Url: https://vcs.maemo.org/git/?p=callnotify;a=commitdiff_plain;h=21c4382c7a679a05a209c878aad7877cbf69b5c1 Some fixes: * Fix reading file sound.txt if is empty * Default volume level is now max (1.0) * Sleep for 1s between starting and stopping vibrate * Change timeout before which is missed icon shown from 60s to 20s * Fix calling chmod commands * Remove whitespaces --- diff --git a/src/usr/lib/hildon-desktop/CallNotify.py b/src/usr/lib/hildon-desktop/CallNotify.py index b121c31..e9ae6bf 100644 --- a/src/usr/lib/hildon-desktop/CallNotify.py +++ b/src/usr/lib/hildon-desktop/CallNotify.py @@ -55,7 +55,7 @@ class Playbin2: f.write('\n') f.close() - + class CallNotify(hildondesktop.StatusMenuItem): def __init__(self): hildondesktop.StatusMenuItem.__init__(self) @@ -74,26 +74,24 @@ class CallNotify(hildondesktop.StatusMenuItem): self.soundCall = self.soundFile self.soundSMS = self.soundFile self.soundBoth = self.soundFile - self.volume = 0.0 + self.volume = 1.0 self.readConfigurationFile() self.dbg('constructor') # Load images self.loadImages() - + # Register to handle screen off/on events osso_c = osso.Context("osso_test_device_on", "0.0.1", False) device = osso.DeviceState(osso_c) - + # add d-bus listener for removing notification after viewing missed call # Doing timeout_add with return False instead of explicitly raising a thread gobject.timeout_add(500, self.startDbusListeners) - - if self.Debug: - hildon.hildon_play_system_sound(self.soundFile) + self.dbg('constructor end') - + def checkForConfigFile(self): self.dbg('checkForConfigFile started') os.umask(0) @@ -108,9 +106,9 @@ class CallNotify(hildondesktop.StatusMenuItem): a.write('\n') a.close() # set proper permissions - os.system("chmod 766 " + self.configDir) - os.system("chmod 766" + self.configDir+self.configFile) - os.system("chmod 766" + self.configDir+self.configSoundFile) + os.system("chmod 755 " + self.configDir) + os.system("chmod 644 " + self.configDir+self.configFile) + os.system("chmod 644 " + self.configDir+self.configSoundFile) def readConfigurationFile(self): @@ -124,28 +122,32 @@ class CallNotify(hildondesktop.StatusMenuItem): self.vibration = raw_set[2] in ('y') self.interval = float(raw_set[3].replace(',','.')) f.close() - + # read sound config file f = open(self.configDir+self.configSoundFile, 'r') line = f.readline() # check if specific missed call, SMS or common sound was defined in config file - if line: - self.soundCall = line.rstrip() + if line.strip(): + self.soundCall = line.strip() + self.dbg('soundCall changed to: '+self.soundCall) line = f.readline() - if line: + if line.strip(): self.soundSMS = line.rstrip() + self.dbg('soundSMS changed to: '+self.soundSMS) line = f.readline() - if line: - self.soundBoth = line.rstrip() + if line.strip(): + self.soundBoth = line.strip() + self.dbg('soundBoth changed to: '+self.soundBoth) line = f.readline() - if line: - self.volume = float(line.rstrip()) + if line.strip(): + self.volume = float(line.strip()) + self.dbg('volume changed to: '+self.volume) f.close() except: os.remove(self.configDir+self.configFile) os.remove(self.configDir+self.configSoundFile) self.checkForConfigFile() - + def playSound(self): self.dbg('playSound started') profiled = dbus.Interface(dbus.SessionBus().get_object("com.nokia.profiled", "/com/nokia/profiled"), "com.nokia.profiled") @@ -165,17 +167,19 @@ class CallNotify(hildondesktop.StatusMenuItem): Playbin2().play(self.soundFile, self.volume) if self.vibration and profiled.get_value("", "vibrating.alert.enabled") == "On": + self.dbg('vibrate:') mce.req_vibrator_pattern_activate("PatternIncomingCall") + time.sleep(1); mce.req_vibrator_pattern_deactivate("PatternIncomingCall") return True - + def loadImages(self): self.dbg('loadImages started') icon_theme = gtk.icon_theme_get_default() self.callPicture = gtk.gdk.pixbuf_new_from_file_at_size("/usr/share/CallNotify/call.png",18,18) self.smsPicture = gtk.gdk.pixbuf_new_from_file_at_size("/usr/share/CallNotify/sms.png",18,18) - - # Load 5 numbers and the "+5" + + # Load 5 numbers and the "+5" self.imgList = [] self.imgList.append(gtk.gdk.pixbuf_new_from_file_at_size("/usr/share/CallNotify/1.png",18,18)) self.imgList.append(gtk.gdk.pixbuf_new_from_file_at_size("/usr/share/CallNotify/2.png",18,18)) @@ -183,7 +187,7 @@ class CallNotify(hildondesktop.StatusMenuItem): self.imgList.append(gtk.gdk.pixbuf_new_from_file_at_size("/usr/share/CallNotify/4.png",18,18)) self.imgList.append(gtk.gdk.pixbuf_new_from_file_at_size("/usr/share/CallNotify/5.png",18,18)) self.imgList.append(gtk.gdk.pixbuf_new_from_file_at_size("/usr/share/CallNotify/more.png",18,18)) - + def startDbusListeners(self): self.dbg('startDbusListeners started') DBusGMainLoop(set_as_default=True) @@ -200,13 +204,13 @@ class CallNotify(hildondesktop.StatusMenuItem): def newEvent(self, a, b, c, d, e, f): self.dbg('newEvent started') # On NewEvent the notifications.db is not immediately filled, thus check the event after one minute waiting - self.tmr_main = gobject.timeout_add(60000, self.handleMissed) + self.tmr_main = gobject.timeout_add(20000, self.handleMissed) return True def notificationClosed(self, a): self.dbg('notificationClosed started') self.stop_notification(a) - + def pendingMessagesRemoved(self, a): self.dbg('pendingMessagesRemoved started') self.stop_notification(self) @@ -226,13 +230,13 @@ class CallNotify(hildondesktop.StatusMenuItem): elif missedSMS and not missedCall: self.msgType = "SMS" self.dbg('***********handleMissed SMS started***********: ' + str(missedSMS)) - + if missedCall or missedSMS: self.show() - + # Execute the function only once on NewEvent return False - + def stop_notification(self, a): self.dbg('stop_notification started') try: @@ -259,7 +263,7 @@ class CallNotify(hildondesktop.StatusMenuItem): #self.dbg('get missed SMSs: ' + str(missed)) #else: #self.dbg('get missed Calls: ' + str(missed)) - + return missed def show(self): @@ -271,7 +275,7 @@ class CallNotify(hildondesktop.StatusMenuItem): if self.visual: self.tmr_ptr = gobject.timeout_add(1000, self.blinkIcon) self.tmr_ptr2 = gobject.timeout_add(int(self.interval*1000*60), self.playSound) - + def blinkIcon(self): # self.dbg('blinkIcon started') if self.toShow: @@ -296,7 +300,7 @@ class CallNotify(hildondesktop.StatusMenuItem): self.toShow = True self.set_status_area_icon(img) return True - + def dbg(self, txt): if self.Debug: f = open(self.configDir+'log.txt', 'a') @@ -304,7 +308,7 @@ class CallNotify(hildondesktop.StatusMenuItem): f.write('\n') f.close() - + hd_plugin_type = CallNotify