예제 #1
0
def update_remote_data_source(sync_type, google_acct_id):
	global dialog
	remote_sources.clear()

	if sync_type == consts.SYNC_TYPE_CAL:
		hildon.hildon_gtk_window_set_progress_indicator(dialog, 1)
		try:
			if not google_api.switch_account(\
					google_accounts.get_account_by_id(\
					google_acct_id)):
				display_google_auth_error(dialog)
				google_new_btn.set_sensitive(False)
				google_item_picker.set_sensitive(False)
				hildon.hildon_gtk_window_set_progress_indicator(dialog, 0)
				return
		except ErminigError, e:
			error_win.display(e.title(), e.description())
			return

		google_new_btn.set_sensitive(True)
		google_item_picker.set_sensitive(True)
		for id, title in google_api.get_all_calendars():
			logger.append("ID->")
			logger.append(id)
			logger.append("title->")
			logger.append(title)
			remote_sources.append([id, title])
		hildon.hildon_gtk_window_set_progress_indicator(dialog, 0)
예제 #2
0
def getDeletedEventsFromLocal(pid, localSource, remoteSource, lastSync, progress):
	# get all events in the Trash:
	rows = cwrapper.getAllDeletedEvents(localSource, lastSync)
	if not rows:
		update_progress(progress, 1.0)
		return

	progress_inc = 1.0/3.0/len(rows)
	progress_val = 1.0/3.0*2
	for e in rows:
		progress_val = progress_val + progress_inc
		update_progress(progress, progress_val)

		gid = getGoogleIdFromLocalId(e)
		if not gid:
			continue

		try:
			event = google_api.run_google_action(google_api.gd_client.GetCalendarEventEntry, urllib.quote("/calendar/feeds/" + remoteSource + "/private/full/" + gid))

			if event == None:
				logger.append("Unable to get event to delete!")
				return 

			google_api.run_google_action(google_api.gd_client.DeleteEvent, event.GetEditLink().href)
		except ErminigGoogleError, e:
			error_win.display(e.title(), e.description())
			return
예제 #3
0
def getDeletedEventsFromLocal(pid, localSource, remoteSource, lastSync,
                              progress):
    # get all events in the Trash:
    rows = cwrapper.getAllDeletedEvents(localSource, lastSync)
    if not rows:
        update_progress(progress, 1.0)
        return

    progress_inc = 1.0 / 3.0 / len(rows)
    progress_val = 1.0 / 3.0 * 2
    for e in rows:
        progress_val = progress_val + progress_inc
        update_progress(progress, progress_val)

        gid = getGoogleIdFromLocalId(e)
        if not gid:
            continue

        try:
            event = google_api.run_google_action(
                google_api.gd_client.GetCalendarEventEntry,
                urllib.quote("/calendar/feeds/" + remoteSource +
                             "/private/full/" + gid))

            if event == None:
                logger.append("Unable to get event to delete!")
                return

            google_api.run_google_action(google_api.gd_client.DeleteEvent,
                                         event.GetEditLink().href)
        except ErminigGoogleError, e:
            error_win.display(e.title(), e.description())
            return
예제 #4
0
def getNewEventsFromGoogle(pid, localSource, remoteSource, lastSync, \
		                        progress):
	query = gdata.calendar.service.CalendarEventQuery(remoteSource, \
			'private', 'composite', None, {"ctz":"utc"})
	query.updated_min = timestampToIso8601(lastSync)
	query.updated_max = timestampToIso8601(int(time.time()))
	query.max_results = "100000"

	feed = None
	try:
		feed = google_api.run_google_action(google_api.gd_client.CalendarQuery, query)
	except ErminigGoogleError, e:
		error_win.display(e.title(), e.description())
		return
예제 #5
0
def getNewEventsFromGoogle(pid, localSource, remoteSource, lastSync, \
                          progress):
    query = gdata.calendar.service.CalendarEventQuery(remoteSource, \
      'private', 'composite', None, {"ctz":"utc"})
    query.updated_min = timestampToIso8601(lastSync)
    query.updated_max = timestampToIso8601(int(time.time()))
    query.max_results = "100000"

    feed = None
    try:
        feed = google_api.run_google_action(google_api.gd_client.CalendarQuery,
                                            query)
    except ErminigGoogleError, e:
        error_win.display(e.title(), e.description())
        return
예제 #6
0
def updateGoogleEvent(evt, googleid, pid):
	"""
	@type  evt:      L{Event.Event}
	@param googleid: name of calendar ?
	@type  googleid: unicode
	@type  pid:      int
	"""
	# get Googleid of event:
	gid = getGoogleIdFromLocalId(evt.get_id())
	if not gid:
		return

	event = None
	try:
		event = google_api.run_google_action(google_api.gd_client.GetCalendarEventEntry, urllib.quote("/calendar/feeds/" + googleid + "/private/full/" + gid))
	except ErminigGoogleError, e:
		error_win.display(e.title(), e.description())
		return
예제 #7
0
def createNewGoogleEvent(evt, googleid, pid):

    start_time = timestampToIso8601(evt.get_start())
    end_time = timestampToIso8601(evt.get_end())

    # if it's a full-day event, then we can strip the start/end times:
    if evt.get_fullday() == 1:
        start_time = timestampToIso8601(
            int(evt.get_start()) + evt.get_tzOffset())
        end_time = timestampToIso8601(int(evt.get_end()) + evt.get_tzOffset())
        start_time = start_time[0:10]
        end_time = end_time[0:10]

        # Add artificially one day:
        td = datetime.timedelta(1)
        time_dt = datetime.datetime.strptime(end_time, "%Y-%m-%d")
        time_dt = time_dt + td
        end_time = time_dt.strftime("%Y-%m-%d")

    event = gdata.calendar.CalendarEventEntry()
    event.title = atom.Title(text=evt.get_title())
    event.content = atom.Content(text=evt.get_description())
    event.where.append(gdata.calendar.Where(value_string=evt.get_where()))
    # Differentiate for recurrence:
    if evt.get_rrule() <> "":
        rec_data = create_rrule(start_time, end_time, evt.get_rrule())
        event.recurrence = gdata.calendar.Recurrence(text=rec_data)
        event.reminder.append(gdata.calendar.Reminder(minutes=evt.get_alarm()))
    else:
        event.when.append(
            gdata.calendar.When(start_time=start_time, end_time=end_time))
        event.when[0].reminder.append(
            gdata.calendar.Reminder(minutes=evt.get_alarm()))

    new_event = None
    try:
        new_event = google_api.run_google_action(
            google_api.gd_client.InsertEvent, event,
            urllib.quote('/calendar/feeds/' + googleid + '/private/full'))
    except ErminigGoogleError, e:
        error_win.display(e.title(), e.description())
        return
예제 #8
0
def updateGoogleEvent(evt, googleid, pid):
    """
	@type  evt:      L{Event.Event}
	@param googleid: name of calendar ?
	@type  googleid: unicode
	@type  pid:      int
	"""
    # get Googleid of event:
    gid = getGoogleIdFromLocalId(evt.get_id())
    if not gid:
        return

    event = None
    try:
        event = google_api.run_google_action(
            google_api.gd_client.GetCalendarEventEntry,
            urllib.quote("/calendar/feeds/" + googleid + "/private/full/" +
                         gid))
    except ErminigGoogleError, e:
        error_win.display(e.title(), e.description())
        return
예제 #9
0
def createNewGoogleEvent(evt, googleid, pid):

	start_time = timestampToIso8601(evt.get_start())
	end_time = timestampToIso8601(evt.get_end())

	# if it's a full-day event, then we can strip the start/end times:
	if evt.get_fullday() == 1:
		start_time = timestampToIso8601(int(evt.get_start())+evt.get_tzOffset())
		end_time = timestampToIso8601(int(evt.get_end())+evt.get_tzOffset())
		start_time = start_time[0:10]
		end_time = end_time[0:10]

		# Add artificially one day:
		td = datetime.timedelta(1)
		time_dt = datetime.datetime.strptime(end_time, "%Y-%m-%d")
		time_dt = time_dt + td
		end_time = time_dt.strftime("%Y-%m-%d")

	event = gdata.calendar.CalendarEventEntry()
	event.title = atom.Title(text=evt.get_title())
	event.content = atom.Content(text=evt.get_description())
	event.where.append(gdata.calendar.Where(value_string=evt.get_where()))
	# Differentiate for recurrence:
	if evt.get_rrule() <> "":
		rec_data = create_rrule(start_time, end_time, evt.get_rrule())
		event.recurrence = gdata.calendar.Recurrence(text=rec_data)
		event.reminder.append(gdata.calendar.Reminder(minutes=evt.get_alarm()));
	else:
		event.when.append(gdata.calendar.When(start_time=start_time, end_time=end_time))
		event.when[0].reminder.append(gdata.calendar.Reminder(minutes=evt.get_alarm()));

	new_event = None
	try:
		new_event = google_api.run_google_action(google_api.gd_client.InsertEvent, event, urllib.quote('/calendar/feeds/' + googleid + '/private/full'))
	except ErminigGoogleError, e:
		error_win.display(e.title(), e.description())
		return
예제 #10
0
		event.recurrence = gdata.calendar.Recurrence(text=rec_data)
		if len(event.reminder) > 0:
			event.reminder[0].minutes = evt.get_alarm()
		else:
			event.reminder.append(gdata.calendar.Reminder(minutes=evt.get_alarm()));
	else:
		event.when[0] = gdata.calendar.When(start_time=start_time, end_time=end_time)
		if len(event.when[0].reminder) > 0:
			event.when[0].reminder[0].minutes = evt.get_alarm()
		else:
			event.when[0].reminder.append(gdata.calendar.Reminder(minutes=evt.get_alarm()));

	try:
		google_api.run_google_action(google_api.gd_client.UpdateEvent, event.GetEditLink().href, event)
	except ErminigGoogleError, e:
		error_win.display(e.title(), e.description())
		return

def getUpdatedEventsFromLocal(pid, localSource, remoteSource, lastSync, progress):
	# Those are events to update in Google:
	evts = queryUpdatedLocalEvents(lastSync, localSource)
	if not evts:
		update_progress(progress, 1.0/3*2)
		return

	progress_inc = 1.0/3.0/len(evts)
	progress_val = 1.0/3.0
	for e in evts:
		progress_val = progress_val + progress_inc
		update_progress(progress, progress_val)
예제 #11
0
            event.reminder.append(
                gdata.calendar.Reminder(minutes=evt.get_alarm()))
    else:
        event.when[0] = gdata.calendar.When(start_time=start_time,
                                            end_time=end_time)
        if len(event.when[0].reminder) > 0:
            event.when[0].reminder[0].minutes = evt.get_alarm()
        else:
            event.when[0].reminder.append(
                gdata.calendar.Reminder(minutes=evt.get_alarm()))

    try:
        google_api.run_google_action(google_api.gd_client.UpdateEvent,
                                     event.GetEditLink().href, event)
    except ErminigGoogleError, e:
        error_win.display(e.title(), e.description())
        return


def getUpdatedEventsFromLocal(pid, localSource, remoteSource, lastSync,
                              progress):
    # Those are events to update in Google:
    evts = queryUpdatedLocalEvents(lastSync, localSource)
    if not evts:
        update_progress(progress, 1.0 / 3 * 2)
        return

    progress_inc = 1.0 / 3.0 / len(evts)
    progress_val = 1.0 / 3.0
    for e in evts:
        progress_val = progress_val + progress_inc