SyncItem* WebOsCalendarSyncSource::getNextDeletedItem()
{
	LOG.info("=========== GET NEXT DELETED ITEM CALLED ==================");
	if(!mGetChangesCalled)
	{
		getChanges();
	}

	std::vector<WString> result = BlockingServiceCall("getDeletedEvent",TEXT(""));
	if(result.empty())
	{
		LOG.error("GetDeleted failed.");
	}
	else
	{
		if(result.front() != "finished")
		{
			SyncItem* item = new SyncItem();
			item->setDataType(TEXT("text/calendar"));
			//item->setData(e.second.c_str(),e.second.length()); no data for deleted items..
			item->setKey(result.front().c_str());
			LOG.debug("Added %s as deleted.",result.front().c_str());
			return item;
		}
	}

	return NULL;
}
SyncItem* WebOsCalendarSyncSource::getNextItem()
{
	LOG.info("========== GET NEXT ITEM CALLED ===========");
	if(mEvents.empty())
	{
		//no items anymore, need to get more. If that doesn't work, there are no more items.
		getMoreItems();
		if(mEvents.empty())
		{
			LOG.info("======= NO MORE ELEMENTS ==========");
			return NULL;
		}
	}

	if(!mEvents.empty())
	{
		//take first event and convert into item of correct type.
		std::pair<WString,WString>& e = mEvents.front();
		SyncItem* item = new SyncItem();
		item->setDataType(TEXT("text/calendar"));
		item->setData(e.second.c_str(),e.second.length());
		item->setKey(e.first.c_str());
		LOG.debug("Received %s from JS with key %s.",e.second.c_str(),e.first.c_str());
		mEvents.pop_front();
		return item;
	}
	else
		return NULL;
}
SyncItem* WebOsCalendarSyncSource::getNextUpdatedItem()
{
	LOG.info("=========== GET NEXT UPDATED ITEM CALLED ==================");
	if(!mGetChangesCalled)
	{
		getChanges();
	}

	if(!mEvents.empty())
	{
		//take first event and convert into item of correct type.
		std::pair<WString,WString>& e = mEvents.front();
		SyncItem* item = new SyncItem();
		item->setDataType(TEXT("text/calendar"));
		item->setData(e.second.c_str(),e.second.length());
		item->setKey(e.first.c_str());
		LOG.debug("Received %s from JS.",e.second.c_str());
		mEvents.pop_front();
		return item;
	}
	else
		return NULL;


	return NULL;
}
Пример #4
0
SyncItem *AbstractSyncSource::createSyncItem(const QUniqueId &id, bool wantData, SyncState state) const
{
    //qDebug() << "AbstractSyncSource::createSyncItem(" << id.toString() << "," << wantData << "," << state << ")";
    QByteArray record = m_model->record(id, m_type);
    SyncItem *item = new SyncItem();
    QString key = id.toString();
    item->setKey(key.toAscii().data());
    item->setModificationTime(m_lastSync.toTime_t());
    item->setState(state);
    if (wantData) {
        item->setData(record.data(), record.size() - 1); // have to omit '\0'
        item->setDataType(getConfig().getType());
    }
    //qDebug() << "AbstractSyncSource::createSyncItem()" << toString(*item);
    return item;
}