[gnome-clocks] First stab at deleting alarms



commit 8ec978290254cfc15870cc6247dfca4437a61427
Author: Paolo Borelli <pborelli gnome org>
Date:   Sat Aug 25 18:28:12 2012 +0200

    First stab at deleting alarms

 gnomeclocks/alarm.py  |   22 +++++++++++++++-------
 gnomeclocks/clocks.py |    9 +++++++--
 2 files changed, 22 insertions(+), 9 deletions(-)
---
diff --git a/gnomeclocks/alarm.py b/gnomeclocks/alarm.py
index 3a2baeb..72c9093 100644
--- a/gnomeclocks/alarm.py
+++ b/gnomeclocks/alarm.py
@@ -29,11 +29,19 @@ class ICSHandler():
 
     def add_vevent(self, vobj):
         with open(self.ics_file, 'r+') as ics:
-            content = ics.read()
-            ics.seek(0)
-            vcal = vobject.readOne(content)
+            vcal = vobject.readOne(ics)
             vcal.add(vobj)
-            ics.write(vcal.serialize())
+            ics.seek(0)
+            vcal.serialize(ics)
+
+    def remove_vevents(self, uids):
+        with open(self.ics_file, 'r+') as ics:
+            vcal = vobject.readOne(ics)
+            for v in vcal.components():
+                if v.uid.value in uids:
+                    vcal.remove(v)
+            ics.seek(0)
+            vcal.serialize(ics)
 
     def load_vevents(self):
         alarms = []
@@ -142,10 +150,10 @@ class AlarmItem:
                 repeat_string += 'Sun, '
             return repeat_string[:-2]
 
-    def get_uid(self):
-        return self.vevent.uid.value
-
     def get_vevent(self):
+        if self.vevent:
+            return self.vevent
+
         self.vevent = vevent = vobject.newFromBehavior('vevent')
         vevent.add('summary').value = self.name
         vevent.add('dtstart').value = self.time
diff --git a/gnomeclocks/clocks.py b/gnomeclocks/clocks.py
index 529daed..280a74b 100644
--- a/gnomeclocks/clocks.py
+++ b/gnomeclocks/clocks.py
@@ -249,7 +249,8 @@ class Alarm(Clock):
         selection = self.get_selection()
         items = []
         for treepath in selection:
-            items.append(self.liststore[treepath][3])
+            v = self.liststore[treepath][-1].get_vevent()
+            items.append(v.uid.value)
         self.delete_alarms(items)
 
     def load_alarms(self):
@@ -297,7 +298,11 @@ class Alarm(Clock):
         print "To Do!"
 
     def delete_alarms(self, alarms):
-        print "To Do!"
+        handler = ICSHandler()
+        handler.remove_vevents(alarms)
+        self.iconview.unselect_all()
+        self.liststore.clear()
+        self.load_alarms()
 
     def open_new_dialog(self):
         window = AlarmDialog(self, self.get_toplevel())



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]