[hamster-applet] Bringing in support for trophies first two are rather simplistic. This is work in progress, hamster



commit d4464b3d1407eb76b42c587f81d02faeee59017d
Author: Toms Bauģis <toms baugis gmail com>
Date:   Tue Aug 17 08:20:54 2010 +0100

    Bringing in support for trophies first two are rather simplistic. This is work in progress, hamster being the first guinea pig. And everything there is about the trophy system you can find here: http://github.com/tbaugis/gnome-achievements  (code, wiki)

 src/hamster/client.py   |    9 +++++-
 src/hamster/trophies.py |   67 +++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 75 insertions(+), 1 deletions(-)
---
diff --git a/src/hamster/client.py b/src/hamster/client.py
index 9d7e4bd..7870a5a 100644
--- a/src/hamster/client.py
+++ b/src/hamster/client.py
@@ -23,6 +23,7 @@ import datetime as dt
 from calendar import timegm
 import dbus, dbus.mainloop.glib
 import gobject
+from trophies import checker
 
 
 def from_dbus_fact(fact):
@@ -187,7 +188,13 @@ class Storage(gobject.GObject):
         category_name = category_name or ''
         description = description or ''
 
-        return self.conn.AddFact(activity_name, tags, start_time, end_time, category_name, description, temporary)
+        new_id = self.conn.AddFact(activity_name, tags, start_time, end_time, category_name, description, temporary)
+
+        # TODO - the parsing should happen just once and preferably here
+        # we should feed (serialized_activity, start_time, end_time) into AddFact and others
+        checker.check_fact_based(activity_name, tags, start_time, end_time, category_name, description)
+
+        return new_id
 
     def stop_tracking(self, end_time = None):
         """Stop tracking current activity. end_time can be passed in if the
diff --git a/src/hamster/trophies.py b/src/hamster/trophies.py
new file mode 100644
index 0000000..c14bd16
--- /dev/null
+++ b/src/hamster/trophies.py
@@ -0,0 +1,67 @@
+# - coding: utf-8 -
+
+# Copyright (C) 2010 Toms Bauģis <toms.baugis at gmail.com>
+
+# This file is part of Project Hamster.
+
+# Project Hamster is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+
+# Project Hamster is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with Project Hamster.  If not, see <http://www.gnu.org/licenses/>.
+
+"""Deal with trophies if there.
+   For now the trophy configuration of hamster reside in gnome-achievements, in
+   github:
+   http://github.com/tbaugis/gnome-achievements/blob/master/data/achievements/hamster-applet.trophies.xml
+   Eventually they will move into hamster.
+"""
+
+try:
+    from gnome_achievements import client as trophies_client
+except:
+    trophies_client = None
+
+import stuff
+
+class Checker(object):
+    def __init__(self):
+        self.storage = None
+        if trophies_client:
+            self.trophies = trophies_client.Storage()
+
+
+
+    def check_fact_based(self, activity_name, tags, start_time, end_time, category_name, description):
+        # checks fact based trophies
+        if not self.trophies: return
+
+        # explicit over implicit
+        fact = stuff.parse_activity_input(activity_name)
+        fact.tags = [tag.strip() for tag in tags.split(",") if tag.strip()] or fact.tags
+        fact.category_name = category_name or fact.category_name
+        fact.description = description or fact.description
+        fact.start_time = start_time or fact.start_time
+        fact.end_time = end_time or fact.end_time
+
+        if not fact.activity_name:  # TODO - parse_activity could return None for these cases
+            return
+
+
+        # cryptic - hidden - used word shorter than 4 letters for the activity name
+        if len(fact.activity_name) < 4:
+            self.trophies.unlock_achievement("hamster-applet", "cryptic")
+
+        # madness â?? hidden â?? entered an activity in all caps
+        if fact.activity_name == fact.activity_name.upper():
+            self.trophies.unlock_achievement("hamster-applet", "madness")
+
+
+checker = Checker()



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