Ejemplo n.º 1
0
int clearAllFlipAlarms() {

	cookie_t *setAlarms, *iter;	//Container for alarm ID's
	alarm_event_t *thisAlarm;	//All alarm events
	alarm_action_t *act = 0;	//Action for this alarm event
	int i = 0;
	
	const char *dbusInterface = NULL;
	const char *dbusPath = NULL;
	
	int matchedAlarm =0;	//Does alarm match criteria?
	
	setAlarms = NULL;
	
	setAlarms = alarmd_event_query((time_t) 0, (time_t) INT_MAX, 0, 0, APPID);
	if (setAlarms == NULL) {
		printf("No alarms!\n");
		return 0;
	}
	
	if (setAlarms[0] == (cookie_t) 0) {
		printf("No alarms!\n");
	} else {
		//Alarms found!
		for (iter = setAlarms; *iter != (cookie_t) 0; iter++) {
			thisAlarm = alarmd_event_get(*iter);
			
			matchedAlarm = 0;
			
			//Shouldn't need to do this thanks to that APPID thing, but might as well just to be safe... never hurts!
			//Libalarm2 introduces multiple actions per alarm event, so we have to check them all
			for(i = 0; (act = alarm_event_get_action(thisAlarm, i)) != 0; ++i )
			{
				//printf("action%d.label = %s\n", i, alarm_action_get_label(act));

				dbusInterface = alarm_action_get_dbus_interface(act);
				dbusPath = alarm_action_get_dbus_path(act);

				if ((dbusInterface != NULL)  && (dbusPath != NULL)) {
					if (!strcmp(dbusInterface, DBUS_INTERFACE)) { 
						if (!strcmp(dbusPath, DBUS_PATH)) {	
							matchedAlarm = 1;
						}
					}
					//Should I be freeing these? guess so..
					//free(dbusInterface);
					//free(dbusPath);
				}
			}
			
			
			if (matchedAlarm) {
				clearFlipAlarm(*iter);
				printf("Cleared flip alarm %s\n", alarm_event_get_title(thisAlarm));
			}
			
			
			alarm_event_delete(thisAlarm);
		}
		

	}
	
	if (setAlarms != NULL) {
		free(setAlarms);
	}
	
	return 1;
	

}
void OrganizerItemTransform::fillInCommonCComponentDetails(QOrganizerItem *item, CComponent *component, bool setId)
{
    if (item) {
        // Summary
        QString tempstr = QString::fromStdString(component->getSummary());
        if (!tempstr.isEmpty())
            item->setDisplayLabel(tempstr);

        // Description
        tempstr = QString::fromStdString(component->getDescription());
        if (!tempstr.isEmpty())
            item->setDescription(tempstr);

        // Location
        tempstr = QString::fromStdString(component->getLocation());
        if(!tempstr.isEmpty()) {
            QOrganizerItemLocation il = item->detail<QOrganizerItemLocation>();
            il.setLabel(tempstr);
            item->saveDetail(&il);
        }

        // Timestamps
        time_t createdTime = component->getCreatedTime();
        time_t lastModifiedTime = component->getLastModified();

        if (createdTime || lastModifiedTime) {
            QOrganizerItemTimestamp timeStamps = item->detail<QOrganizerItemTimestamp>();
            timeStamps.setCreated(QDateTime::fromTime_t(createdTime));
            timeStamps.setLastModified(QDateTime::fromTime_t(lastModifiedTime));
            item->saveDetail(&timeStamps);
        }

        // GUid
        QOrganizerItemGuid ig = item->detail<QOrganizerItemGuid>();
        tempstr = QString::fromStdString(component->getGUid());
        if(!tempstr.isEmpty())
            ig.setGuid(tempstr);
        item->saveDetail(&ig);

        // Set component ID
        if (setId) {
            QString idString = QString::fromStdString(component->getId());
            item->setId(QOrganizerItemId(new QOrganizerItemMaemo5EngineId(idString.toUInt())));
        } else {
            item->setId(QOrganizerItemId());
        }

        // Set comments
        CComponentDetails *componentDetails = dynamic_cast<CComponentDetails*>(component);
        if (componentDetails) {
            string comments = componentDetails->getComments();
            if (!comments.empty()) {
                QStringList commentList = QString::fromStdString(comments).split('\n', QString::SkipEmptyParts);
                foreach(const QString comment, commentList)
                    item->addComment(comment);
            }
        }

        // Reminder (alarm)
        CAlarm *alarm = component->getAlarm();
        if (alarm) {
            // TODO: Only visual remainders are supported
            QOrganizerItemVisualReminder reminder = item->detail<QOrganizerItemVisualReminder>();
            reminder.setRepetition(alarm->getRepeat(), reminder.repetitionDelay());

            // Alarm time and messages can't be read with CAlarm,
            // read them straight from the alarm framework:

            // Get the cookie
            std::vector<long> cookies = alarm->getCookie();
            if (cookies.size() > 0) {
                cookie_t cookie = static_cast<cookie_t>(cookies[0]); // only one alarm supported

                alarm_event_t *eve = 0;
                if ((eve = alarmd_event_get(cookie)) != 0) {
                    QString message = QString::fromStdString(alarm_event_get_title(eve));
                    reminder.setMessage(message);
                    time_t alarmTime = alarm_event_get_trigger(eve);
                    alarm_event_delete(eve);

                    QDateTime sTime = QDateTime::fromTime_t(component->getDateStart());
                    QDateTime aTime = QDateTime::fromTime_t(alarmTime);
                    reminder.setSecondsBeforeStart(aTime.secsTo(sTime));
                }
            }

            item->saveDetail(&reminder);
        }
    }