Log In
New Account
  
Home My Page Project Cloud Code Snippets Project Openings Hermes
Summary Lists News SCM
authorFredrik Wendt <fredrik@wendt.se>
Sat, 5 Jun 2010 21:20:37 +0000 (23:20 +0200)
committerFredrik Wendt <fredrik@wendt.se>
Sat, 5 Jun 2010 21:20:37 +0000 (23:20 +0200)
"fixed" encoding issue with debug print statements

Signed-off-by: Fredrik Wendt <fredrik@wendt.se>

package/src/org/maemo/hermes/engine/contact.py

index 8d4a367..0b8cbd4 100644 (file)
@@ -79,33 +79,43 @@ class Contact:
            photo is wider than it is tall, it will be cropped with a bias towards
            the top of the photo."""
         
-        f = urllib.urlopen(url)
-        data = ''
-        while True:
-            read_data = f.read()
-            data += read_data
-            if not read_data:
-                break
-        
-        im = Image.open(StringIO.StringIO(data))
-        (w, h) = im.size
-        if (h > w):
-            print "Shrinking photo for %s as it's %d x %d" % (self._contact.get_name(), w, h)
-            im = ImageOps.fit(im, (w, w), Image.NEAREST, 0, (0, 0.1))
-          
-        print "Updating photo for %s" % (self._contact.get_name())
-        f = StringIO.StringIO()
-        im.save(f, "JPEG")
-        image_data = f.getvalue()
-        photo = EContactPhoto()
-        photo.type = 0
-        photo.data = EContactPhoto_data()
-        photo.data.inlined = EContactPhoto_inlined()
-        photo.data.inlined.mime_type = cast(create_string_buffer("image/jpeg"), c_char_p)
-        photo.data.inlined.length = len(image_data)
-        photo.data.inlined.data = cast(create_string_buffer(image_data), c_void_p)
-        ebook.e_contact_set(hash(self._contact), E_CONTACT_PHOTO, addressof(photo))
-        return True
+        try:
+            f = urllib.urlopen(url)
+            data = ''
+            while True:
+                read_data = f.read()
+                data += read_data
+                if not read_data:
+                    break
+            
+            im = Image.open(StringIO.StringIO(data))
+            (w, h) = im.size
+            if (h > w):
+                ##print u"Shrinking photo for %s as it's %d x %d" % (self._contact.get_name(), w, h)
+                im = ImageOps.fit(im, (w, w), Image.NEAREST, 0, (0, 0.1))
+              
+            ## print u"Updating photo for %s" % (self._contact.get_name())
+            f = StringIO.StringIO()
+            im.save(f, "JPEG")
+            image_data = f.getvalue()
+            photo = EContactPhoto()
+            photo.type = 0
+            photo.data = EContactPhoto_data()
+            photo.data.inlined = EContactPhoto_inlined()
+            photo.data.inlined.mime_type = cast(create_string_buffer("image/jpeg"), c_char_p)
+            photo.data.inlined.length = len(image_data)
+            photo.data.inlined.data = cast(create_string_buffer(image_data), c_void_p)
+            ebook.e_contact_set(hash(self._contact), E_CONTACT_PHOTO, addressof(photo))
+            return True
+        except:
+            print "FAILED to get photo from URL %s" % url
+            return False
+    
+    
+    # -----------------------------------------------------------------------
+    def has_photo(self):
+        # FIXME
+        return False
       
       
     # -----------------------------------------------------------------------
@@ -119,12 +129,21 @@ class Contact:
         birthday.year = year
         birthday.month = month
         birthday.day = day
-        print "Setting birthday for [%s] to %d-%d-%d" % (self._contact.get_name(), year, month, day)
+        print u"Setting birthday for [%s] to %d-%d-%d" % (self._contact.get_name(), year, month, day)
         ebook.e_contact_set(hash(self._contact), E_CONTACT_BIRTHDAY_DATE, addressof(birthday))
         return True
     
     
     # -----------------------------------------------------------------------
+    def set_nickname(self, nickname):
+        """Set the nickname for this contact to the given nickname."""
+        
+        # FIXME does this work?
+        self._contact.set_property('nickname', nickname)
+        #ebook.e_contact_set(hash(self._contact), E_NICKNAME, addressof(nickname))
+    
+    
+    # -----------------------------------------------------------------------
     def get_emails(self):
         """Return the email addresses associated with this contact."""
         
@@ -133,7 +152,7 @@ class Contact:
         while ai.has_next():
             attr = ai.next(as_a = EVCardAttribute)
             if not attr:
-                raise Exception("Unexpected null attribute for [" + self._contact.get_name() + "] with emails " + emails)
+                raise Exception(u"Unexpected null attribute for [" + self._contact.get_name() + "] with emails " + emails)
             emails.append(string_at(attr.value().next()))
           
         return emails
@@ -149,7 +168,7 @@ class Contact:
         while ai.has_next():
             attr = ai.next(as_a = EVCardAttribute)
             if not attr:
-                raise Exception("Unexpected null attribute for [" + self._contact.get_name() + "] with URLs " + urls)
+                raise Exception(u"Unexpected null attribute for [" + self._contact.get_name() + "] with URLs " + urls)
             urls.append(string_at(attr.value().next()))
           
         return urls
@@ -189,7 +208,7 @@ class Contact:
             url_attr.name = 'URL'
         
         val = GList()
-        print "Setting URL for [%s] to [%s]" % (self._contact.get_name(), url)
+        ##print u"Setting URL for [%s] to [%s]" % (self._contact.get_name(), url)
         val.set(create_string_buffer(url))
         ai.set(addressof(url_attr))
         url_attr.values = cast(addressof(val), POINTER(GList))

Terms of Use    Privacy Policy    Contribution Guidelines    Feedback

Powered By GForge Collaborative Development Environment