[conduit/iphone] Note support kind of working...
- From: John Stowers <jstowers src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [conduit/iphone] Note support kind of working...
- Date: Thu, 23 Sep 2010 06:29:17 +0000 (UTC)
commit 938c9f5e00d3f385498b758afcc62df398477277
Author: John Stowers <john stowers gmail com>
Date: Thu Sep 23 18:07:47 2010 +1200
Note support kind of working...
conduit/modules/iPodModule/iPodModule.py | 10 ++--
conduit/modules/iPodModule/idevice/__init__.py | 81 ++++++++++++++++--------
2 files changed, 59 insertions(+), 32 deletions(-)
---
diff --git a/conduit/modules/iPodModule/iPodModule.py b/conduit/modules/iPodModule/iPodModule.py
index 7493b5b..c3a81bc 100644
--- a/conduit/modules/iPodModule/iPodModule.py
+++ b/conduit/modules/iPodModule/iPodModule.py
@@ -12,7 +12,7 @@ import conduit.utils as Utils
from gettext import gettext as _
Utils.dataprovider_add_dir_to_path(__file__)
-from idevice import iPhoneContactsTwoWay, iPhoneCalendarsTwoWay
+from idevice import iPhoneContactsTwoWay, iPhoneCalendarsTwoWay, iPhoneNotesTwoWay
from ipod import IPodMusicTwoWay, IPodVideoTwoWay, IPodNoteTwoWay, IPodContactsTwoWay, IPodCalendarTwoWay, IPodPhotoSink
MODULES = {
@@ -82,7 +82,7 @@ class iPhoneFactory(HalFactory.HalFactory):
def get_dataproviders(self, key, **props):
""" Return a list of dataproviders for this class of device """
- return [IPodDummy, IPodPhotoSink, iPhoneCalendarsTwoWay, iPhoneContactsTwoWay]
+ return [IPodDummy, IPodPhotoSink, iPhoneCalendarsTwoWay, iPhoneContactsTwoWay, iPhoneNotesTwoWay]
def get_args(self, key, **props):
return (props[PROPS_KEY_UUID], props[PROPS_KEY_TYPE])
@@ -153,10 +153,10 @@ class IPodDummy(DataProvider.TwoWay):
def __init__(self, *args):
DataProvider.TwoWay.__init__(self)
- print "CONSTRUCTED ", args
- self.args = args or "q"
+ log.debug("CONSTRUCTED: %s" % ", ".join(args))
+ self.args = args
def get_UID(self):
- print "-----".join(self.args)
+ return "-----".join(self.args)
diff --git a/conduit/modules/iPodModule/idevice/__init__.py b/conduit/modules/iPodModule/idevice/__init__.py
index f4d8a8b..aef1ac5 100644
--- a/conduit/modules/iPodModule/idevice/__init__.py
+++ b/conduit/modules/iPodModule/idevice/__init__.py
@@ -1,4 +1,6 @@
# -*- coding: utf-8 -*-
+import time
+import datetime
import logging
log = logging.getLogger("modules.iPhone")
@@ -10,18 +12,20 @@ import conduit.Exceptions as Exceptions
import conduit.datatypes.Contact as Contact
import conduit.datatypes.Event as Event
-import conduit.datatypes.Event as Bookmark
+import conduit.datatypes.Note as Note
from iPhoneDataStorage import *
from iPhoneSyncAgent import *
from vCardOutput import *
from iCalendarOutput import *
-class iPhoneBaseTwoWay(DataProvider.TwoWay):
+class _iPhoneBaseTwoWay(DataProvider.TwoWay):
def __init__(self, *args):
self.agent = iPhoneSyncAgent()
self.uuid = str(args[0])
self.model = str(args[1])
+
+ #FIXME: This blocks. Perhaps we can do it in refresh...
if self.agent.connect(self.uuid):
log.info("Connected to %s with uuid %s" % (self.model, self.uuid))
else:
@@ -54,9 +58,10 @@ class iPhoneBaseTwoWay(DataProvider.TwoWay):
def _refresh(self):
self.agent.set_data_storage(self.data_class);
- if self.agent.start_session():
+ sync_type = self.agent.start_session()
+ if sync_type:
self._phone_uuid = self.agent._phone.get_uuid()
- self.agent.synchronize()
+ self.agent.synchronize(sync_type)
self.agent.finish_session()
def get_all(self):
@@ -94,9 +99,50 @@ class iPhoneBaseTwoWay(DataProvider.TwoWay):
else:
return self._get_data(LUID).get_rid()
+ def get_UID(self):
+ return "%s-%s" % (self.__class__.__name__, self.uuid)
+
+class iPhoneNotesTwoWay(_iPhoneBaseTwoWay):
+ """
+ Notes syncing for iPhone and iPod Touch
+ """
+
+ _name_ = "iPhone Notes"
+ _description_ = "iPhone and iPod Touch Contact Dataprovider"
+ _category_ = conduit.dataproviders.CATEGORY_MISC
+ _module_type_ = "twoway"
+ _in_type_ = "note"
+ _out_type_ = "note"
+ _icon_ = "note"
+ def __init__(self, *args):
+ _iPhoneBaseTwoWay.__init__(self, *args)
+ DataProvider.TwoWay.__init__(self)
+ self.data_class = iPhoneNotesDataStorage()
+ self.storage_entity = iPhoneNoteRecordEntity
+
+ def _convert_note_datetime(self, date):
+ ODD_EPOCH = 978307200
+ #to struct_time
+ st = time.strptime(date, "%Y-%m-%d %H:%M:%S")
+ #for some reason Apple decided the epoch was on a different day?
+ seconds = time.mktime(st) + ODD_EPOCH
+ #Assumes the timestamp is in UTC. Is this correct?
+ return datetime.datetime.fromtimestamp(seconds)
-class iPhoneContactsTwoWay(iPhoneBaseTwoWay):
+ def get(self, LUID):
+ DataProvider.TwoWay.get(self, LUID)
+ n = None
+ i = self._get_data(LUID)
+ if i:
+ n = Note.Note(
+ title=i.data.subject,
+ contents=i.data.content)
+ n.set_UID(i.id)
+ n.set_mtime(self._convert_note_datetime(i.data.dateModified))
+ return n
+
+class iPhoneContactsTwoWay(_iPhoneBaseTwoWay):
"""
Contact syncing for iPhone and iPod Touch
"""
@@ -110,7 +156,7 @@ class iPhoneContactsTwoWay(iPhoneBaseTwoWay):
_icon_ = "contact-new"
def __init__(self, *args):
- iPhoneBaseTwoWay.__init__(self, *args)
+ _iPhoneBaseTwoWay.__init__(self, *args)
DataProvider.TwoWay.__init__(self)
self.selectedGroup = None
self.data_class = iPhoneContactsDataStorage()
@@ -126,21 +172,6 @@ class iPhoneContactsTwoWay(iPhoneBaseTwoWay):
c.set_from_vcard_string(vcard._to_vcard(i))
return c
- def get_UID(self):
- return "iPhoneContactsTwoWay"
-
- def get(self, LUID):
- # FIXME: This should be rewritten to translate like iPhoneCalendarTwoWay
- # After doing that we can get rid of this method.
- DataProvider.TwoWay.get(self, LUID)
- c = None
- i = self._get_data(LUID)
- if (None != i):
- vcard = vCardOutput(self.data_class)
- c = Contact.Contact()
- c.set_from_vcard_string(vcard._to_vcard(i))
- return c
-
class iPhoneConduitEvent(DataType.DataType):
_name_ = 'event/iphone'
@@ -158,7 +189,7 @@ class iPhoneConduitEvent(DataType.DataType):
def set_from_ical_string(self, string):
pass
-class iPhoneCalendarsTwoWay(iPhoneBaseTwoWay):
+class iPhoneCalendarsTwoWay(_iPhoneBaseTwoWay):
"""
Contact syncing for iPhone and iPod Touch
"""
@@ -173,7 +204,7 @@ class iPhoneCalendarsTwoWay(iPhoneBaseTwoWay):
_configurable_ = True
def __init__(self, *args):
- iPhoneBaseTwoWay.__init__(self, *args)
+ _iPhoneBaseTwoWay.__init__(self, *args)
DataProvider.TwoWay.__init__(self)
self.data_class = iPhoneCalendarsDataStorage()
self.storage_entity = iPhoneEventRecordEntity
@@ -182,10 +213,6 @@ class iPhoneCalendarsTwoWay(iPhoneBaseTwoWay):
_calendarId = ""
)
- def get_UID(self):
- # FIXME: This should include the UUID of the phone as well
- return "iPhoneCalendarsTwoWay-%s" % (self._calendarId)
-
# Implement this for faster syncs
#def get_changes(self):
# return (new, changed, deleted)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]