void KoRdfCalendarEvent::importFromData(const QByteArray &ba, const KoDocumentRdf *_rdf, KoCanvasBase *host) { #ifdef KDEPIMLIBS_FOUND kDebug(30015) << "data.sz:" << ba.size(); kDebug(30015) << "_rdf:" << _rdf; if (_rdf) { m_rdf = _rdf; } KCalCore::VCalFormat v; KCalCore::Calendar::Ptr cal(new KCalCore::MemoryCalendar(KSystemTimeZones::local())); bool rc = v.fromRawString(cal, ba); kDebug(30015) << "parse rc:" << rc; KCalCore::Event::List events = cal->rawEvents(); kDebug(30015) << "found event count:" << events.size(); if (events.size() >= 1) { KCalCore::Event::Ptr e = events[0]; fromKEvent(e); } importFromDataComplete(ba, documentRdf(), host); #else Q_UNUSED(ba); Q_UNUSED(_rdf); Q_UNUSED(host); #endif }
bool timetrackerstorage::allEventsHaveEndTiMe() { kDebug(5970) << "Entering function"; KCalCore::Event::List eventList = d->mCalendar->rawEvents(); for(KCalCore::Event::List::iterator i = eventList.begin(); i != eventList.end(); ++i) { if ( !(*i)->hasEndDate() ) return false; } return true; }
QString timetrackerstorage::removeEvent(QString uid) { kDebug(5970) << "Entering function"; QString err=QString(); KCalCore::Event::List eventList = d->mCalendar->rawEvents(); for(KCalCore::Event::List::iterator i = eventList.begin(); i != eventList.end(); ++i) { if ( (*i)->uid() == uid ) { d->mCalendar->deleteEvent(*i); } } return err; }
void NemoCalendarAgendaModel::load() { // TODO: we really need a centralised event cache KCalCore::Event::List eventList = NemoCalendarDb::calendar()->rawEventsForDate(mStartDate, KDateTime::Spec(KDateTime::LocalZone), KCalCore::EventSortStartDate, KCalCore::SortDirectionAscending); qDebug() << Q_FUNC_INFO << "Loaded " << eventList.count() << " events for " << mStartDate; beginResetModel(); qDeleteAll(mEvents); mEvents.clear(); mEvents.reserve(eventList.size()); foreach (const KCalCore::Event::Ptr &evt, eventList) { NemoCalendarEvent *event = new NemoCalendarEvent(evt); mEvents.append(event); }
void TestBirthdayPlugin::testLeapYears() { const QString contactID = QUuid::createUuid().toString(); QFETCH(QDate, contactBirthDate); // Add contact with birthday to tracker. QContactName contactName; contactName.setFirstName(contactID); QContactBirthday contactBirthday; contactBirthday.setDate(contactBirthDate); QContact contact; QVERIFY(contact.saveDetail(&contactName)); QVERIFY(contact.saveDetail(&contactBirthday)); QVERIFY(saveContact(contact)); // Wait until calendar event gets to calendar. loopWait(calendarTimeout); // Open calendar database. mKCal::ExtendedCalendar::Ptr calendar = mKCal::ExtendedCalendar::Ptr(new mKCal::ExtendedCalendar(KDateTime::Spec::LocalZone())); mKCal::ExtendedStorage::Ptr storage = mKCal::ExtendedCalendar::defaultStorage(calendar); QVERIFY(storage->open()); QVERIFY(not storage->notebook(calNotebookId).isNull()); // Check calendar database for contact. QVERIFY(storage->loadNotebookIncidences(calNotebookId)); const KCalCore::Event::List eventList = findCalendarEvents(calendar->events(), contact); QCOMPARE(eventList.count(), 1); const KCalCore::Event::Ptr event = eventList.first(); QCOMPARE(event->summary(), contactID); QCOMPARE(event->dtStart().date(), contactBirthDate); QCOMPARE(event->allDay(), true); // Check number of recurrences and their values. const KDateTime first(QDate(2000, 1, 1), QTime(), KDateTime::ClockTime); const KDateTime last(QDate(2020, 12, 31), QTime(), KDateTime::ClockTime); const KCalCore::DateTimeList instances = event->recurrence()->timesInInterval(first, last); QCOMPARE(instances.length(), 13); for(int i = 0; i < instances.length(); ++i) { QCOMPARE(instances.at(i).date(), contactBirthDate.addYears(i)); } }
bool timetrackerstorage::removeTask(Task* task) { kDebug(5970) << "Entering function"; // delete history KCalCore::Event::List eventList = d->mCalendar->rawEvents(); for(KCalCore::Event::List::iterator i = eventList.begin(); i != eventList.end(); ++i) { if ( (*i)->relatedTo() == task->uid() ) { d->mCalendar->deleteEvent(*i); } } // delete todo KCalCore::Todo::Ptr todo = d->mCalendar->todo(task->uid()); d->mCalendar->deleteTodo(todo); // Save entire file saveCalendar(); return true; }
// export history report as csv, all tasks X all dates in one block QString timetrackerstorage::exportcsvHistory (TaskView *taskview, const QDate &from, const QDate &to, const ReportCriteria &rc) { kDebug(5970) << "Entering function"; QString delim = rc.delimiter; const QString cr = QString::fromLatin1("\n"); QString err=QString::null; QString retval; Task* task; const int intervalLength = from.daysTo(to)+1; QMap< QString, QVector<int> > secsForUid; QMap< QString, QString > uidForName; // Step 1: Prepare two hashmaps: // * "uid -> seconds each day": used while traversing events, as uid is their id // "seconds each day" are stored in a vector // * "name -> uid", ordered by name: used when creating the csv file at the end kDebug(5970) << "Taskview Count: " << taskview->count(); for ( int n=0; n<taskview->count(); n++ ) { task=taskview->itemAt(n); kDebug(5970) << "n: " << n << ", Task Name: " << task->name() << ", UID: " << task->uid(); // uid -> seconds each day // * Init each element to zero QVector<int> vector(intervalLength, 0); secsForUid[task->uid()] = vector; // name -> uid // * Create task fullname concatenating each parent's name QString fullName; Task* parentTask; parentTask = task; fullName += parentTask->name(); parentTask = parentTask->parent(); while (parentTask) { fullName = parentTask->name() + "->" + fullName; kDebug(5970) << "Fullname(inside): " << fullName; parentTask = parentTask->parent(); kDebug(5970) << "Parent task: " << parentTask; } uidForName[fullName] = task->uid(); kDebug(5970) << "Fullname(end): " << fullName; } kDebug(5970) << "secsForUid" << secsForUid; kDebug(5970) << "uidForName" << uidForName; // Step 2: For each date, get the events and calculate the seconds // Store the seconds using secsForUid hashmap, so we don't need to translate uids // We rely on rawEventsForDate to get the events kDebug(5970) << "Let's iterate for each date: "; for ( QDate mdate=from; mdate.daysTo(to)>=0; mdate=mdate.addDays(1) ) { kDebug(5970) << mdate.toString(); KCalCore::Event::List dateEvents = d->mCalendar->rawEventsForDate(mdate); for(KCalCore::Event::List::iterator i = dateEvents.begin();i != dateEvents.end(); ++i) { kDebug(5970) << "Summary: " << (*i)->summary() << ", Related to uid: " << (*i)->relatedTo(); kDebug(5970) << "Today's seconds: " << todaySeconds(mdate, *i); secsForUid[(*i)->relatedTo()][from.daysTo(mdate)] += todaySeconds(mdate, *i); } } // Step 3: For each task, generate the matching row for the CSV file // We use the two hashmaps to have direct access using the task name // First CSV file line // FIXME: localize strings and date formats retval.append("\"Task name\""); for (int i=0; i<intervalLength; i++) { retval.append(delim); retval.append(from.addDays(i).toString()); } retval.append(cr); // Rest of the CSV file QMapIterator<QString, QString> nameUid(uidForName); double time; while (nameUid.hasNext()) { nameUid.next(); retval.append("\"" + nameUid.key() + "\""); kDebug(5970) << nameUid.key() << ": " << nameUid.value() << endl; for (int day=0; day<intervalLength; day++) { kDebug(5970) << "Secs for day " << day << ":" << secsForUid[nameUid.value()][day]; retval.append(delim); time = secsForUid[nameUid.value()][day]/60.0; retval.append(formatTime(time, rc.decimalMinutes)); } retval.append(cr); } kDebug() << "Retval is \n" << retval; if (rc.bExPortToClipBoard) taskview->setClipBoardText(retval); else { // store the file locally or remote if ((rc.url.isLocalFile()) || (!rc.url.url().contains("/"))) { kDebug(5970) << "storing a local file"; QString filename=rc.url.toLocalFile(); if (filename.isEmpty()) filename=rc.url.url(); QFile f( filename ); if( !f.open( QIODevice::WriteOnly ) ) { err = i18n( "Could not open \"%1\".", filename ); kDebug(5970) << "Could not open file"; } kDebug() << "Err is " << err; if (err.length()==0) { QTextStream stream(&f); kDebug(5970) << "Writing to file: " << retval; // Export to file stream << retval; f.close(); } } else // use remote file { KTemporaryFile tmpFile; if ( !tmpFile.open() ) { err = QString::fromLatin1( "Unable to get temporary file" ); } else { QTextStream stream ( &tmpFile ); stream << retval; stream.flush(); if (!KIO::NetAccess::upload( tmpFile.fileName(), rc.url, 0 )) err=QString::fromLatin1("Could not upload"); } } } return err; }