Exemplo n.º 1
0
	def getEvents(self, start_calendar_date, end_calendar_date):
		events = []
		self.eventId_calendarId = {}
		self.date_to_events = {}
		
		s = utils.formatDateTime_get_iso(start_calendar_date) + 'Z'
		e = utils.formatDateTime_get_iso(end_calendar_date) + 'Z'
		print str(s) + " --- " + str(e)
		tmp_events=[]
		# Loop over all calendars
		for cal in self.calendars:
			# Check if calendar is enabled
			if self.is_selected(cal['summary']):
				eventsResult = self.service.events().list(calendarId=cal['id'], timeMin=s, timeMax=e, maxResults=100, singleEvents=True, orderBy='startTime').execute()
				tmp_events = eventsResult.get('items', [])
				
				# Save mapping
				for event in tmp_events:
					# Map event id to calendar id
					self.eventId_calendarId[event['id']] = cal['id']
					if not utils.formatDate(event, 'start') in self.date_to_events:
						self.date_to_events[utils.formatDate(event, 'start')] = []
					self.date_to_events[utils.formatDate(event, 'start')].append(event)
				
				events.extend(tmp_events)
		return events
Exemplo n.º 2
0
	def onControl(self, control):
		# Change the selected control info
		self.change_selection(control)
		
		value = self.control_to_data[control.getId()]
		
		ctrl_data = self.control_to_data[control.getId()]
		if ctrl_data != None and type(ctrl_data) is utils.Data:
			if ctrl_data.type == utils.CONTROL_TYPE_EVENT_SUMMARY:
				self.event['summary'] = utils.getKeyboardResults(control.getLabel(), 'Task Summary')
				control.setLabel(self.event['summary'])
				
			if ctrl_data.type == utils.CONTROL_TYPE_EVENT_DESCRIPTION:
				self.event['description'] = utils.getKeyboardResults(control.getLabel(), 'Task Description')
				control.setLabel(self.event['description'])
				
			if ctrl_data.type == utils.CONTROL_TYPE_TIMEZONE:
				dialog = timezoneselection.TimezoneDialog(utils.addon.getSetting('timezone'))
				dialog.doModal()
				if dialog.selected != None:
					self.event['start']['timeZone'] = dialog.selected
					self.event['end']['timeZone'] = dialog.selected
					control.setLabel(dialog.selected)
				
			if  ctrl_data.type == utils.CONTROL_TYPE_EVENT_LOCATION:
				self.event['location'] = utils.getKeyboardResults(control.getLabel(), 'Task Location')
				control.setLabel(self.event['location'])
				
			if value.type =='start_day':
				dialog = dayselection.DaySelectionDialog(utils.formatDateTime(self.event, 'start'))
				dialog.doModal()
		
				control.setLabel(str(dialog.selection_date))
				self.event['start']['dateTime']= utils.formatDateTime_get_iso(dialog.selection_date)
				
			if value.type =='end_day':
				dialog = dayselection.DaySelectionDialog(utils.formatDateTime(self.event, 'end'))
				dialog.doModal()
				
				control.setLabel(str(dialog.selection_date))
				self.event['end']['dateTime']= utils.formatDateTime_get_iso(dialog.selection_date)
			
			if ctrl_data.type == utils.CONTROL_TYPE_ACTION:
				if ctrl_data.value == utils.CONTROL_VALUE_ACTION_DELETE:
					self.calCon.deleteEvent(self.event)
					self.close()
					
				if ctrl_data.value == utils.CONTROL_VALUE_ACTION_OK:
					print str(self.event)
					if 'timeZone' in self.event['start'] and self.event['start']['timeZone'] in pytz.all_timezones and self.event['end']['timeZone'] in pytz.all_timezones:
						if self.is_new:
							self.calCon.createEvent(self.event)
						else:
							self.calCon.updateEvent(self.event)
						
						self.close()
					
					else:
						utils.message("You must select time zone from the list of timezones")
					
				if ctrl_data.value == utils.CONTROL_VALUE_ACTION_CANCEL:
					self.close()
					
			if value.type == "action" and value.value == "cancel":
				self.close()