Changeset View
Changeset View
Standalone View
Standalone View
src/freebusymodel/freebusyitemmodel.cpp
Show First 20 Lines • Show All 97 Lines • ▼ Show 20 Line(s) | 84 | public: | |||
---|---|---|---|---|---|
98 | QList<FreeBusyItem::Ptr> mFreeBusyItems; | 98 | QList<FreeBusyItem::Ptr> mFreeBusyItems; | ||
99 | ItemPrivateData *mRootData = nullptr; | 99 | ItemPrivateData *mRootData = nullptr; | ||
100 | }; | 100 | }; | ||
101 | 101 | | |||
102 | FreeBusyItemModel::FreeBusyItemModel(QObject *parent) | 102 | FreeBusyItemModel::FreeBusyItemModel(QObject *parent) | ||
103 | : QAbstractItemModel(parent) | 103 | : QAbstractItemModel(parent) | ||
104 | , d(new CalendarSupport::FreeBusyItemModelPrivate) | 104 | , d(new CalendarSupport::FreeBusyItemModelPrivate) | ||
105 | { | 105 | { | ||
106 | qRegisterMetaType<KCalCore::Attendee>(); | 106 | qRegisterMetaType<KCalendarCore::Attendee>(); | ||
107 | qRegisterMetaType<KCalCore::FreeBusy::Ptr>("KCalCore::FreeBusy::Ptr"); | 107 | qRegisterMetaType<KCalendarCore::FreeBusy::Ptr>("KCalendarCore::FreeBusy::Ptr"); | ||
108 | qRegisterMetaType<KCalCore::Period>("KCalCore::Period"); | 108 | qRegisterMetaType<KCalendarCore::Period>("KCalendarCore::Period"); | ||
109 | 109 | | |||
110 | Akonadi::FreeBusyManager *m = Akonadi::FreeBusyManager::self(); | 110 | Akonadi::FreeBusyManager *m = Akonadi::FreeBusyManager::self(); | ||
111 | connect(m, &Akonadi::FreeBusyManager::freeBusyRetrieved, this, | 111 | connect(m, &Akonadi::FreeBusyManager::freeBusyRetrieved, this, | ||
112 | &FreeBusyItemModel::slotInsertFreeBusy); | 112 | &FreeBusyItemModel::slotInsertFreeBusy); | ||
113 | 113 | | |||
114 | connect(&d->mReloadTimer, &QTimer::timeout, this, &FreeBusyItemModel::autoReload); | 114 | connect(&d->mReloadTimer, &QTimer::timeout, this, &FreeBusyItemModel::autoReload); | ||
115 | d->mReloadTimer.setSingleShot(true); | 115 | d->mReloadTimer.setSingleShot(true); | ||
116 | 116 | | |||
Show All 35 Lines | 133 | if (data->parent() == d->mRootData) { | |||
152 | } | 152 | } | ||
153 | } | 153 | } | ||
154 | 154 | | |||
155 | FreeBusyItem::Ptr fbitem = d->mFreeBusyItems.at(data->parent()->row()); | 155 | FreeBusyItem::Ptr fbitem = d->mFreeBusyItems.at(data->parent()->row()); | ||
156 | if (!fbitem->freeBusy() || index.row() >= fbitem->freeBusy()->busyPeriods().size()) { | 156 | if (!fbitem->freeBusy() || index.row() >= fbitem->freeBusy()->busyPeriods().size()) { | ||
157 | return QVariant(); | 157 | return QVariant(); | ||
158 | } | 158 | } | ||
159 | 159 | | |||
160 | KCalCore::FreeBusyPeriod period = fbitem->freeBusy()->fullBusyPeriods().at(index.row()); | 160 | KCalendarCore::FreeBusyPeriod period = fbitem->freeBusy()->fullBusyPeriods().at(index.row()); | ||
161 | switch (role) { | 161 | switch (role) { | ||
162 | case Qt::DisplayRole: // return something to make modeltest happy | 162 | case Qt::DisplayRole: // return something to make modeltest happy | ||
163 | return QStringLiteral("%1 - %2"). | 163 | return QStringLiteral("%1 - %2"). | ||
164 | arg(QLocale().toString(period.start().toLocalTime(), QLocale::ShortFormat), | 164 | arg(QLocale().toString(period.start().toLocalTime(), QLocale::ShortFormat), | ||
165 | QLocale().toString(period.end().toLocalTime(), QLocale::ShortFormat)); | 165 | QLocale().toString(period.end().toLocalTime(), QLocale::ShortFormat)); | ||
166 | case FreeBusyItemModel::FreeBusyPeriodRole: | 166 | case FreeBusyItemModel::FreeBusyPeriodRole: | ||
167 | return QVariant::fromValue(period); | 167 | return QVariant::fromValue(period); | ||
168 | default: | 168 | default: | ||
▲ Show 20 Lines • Show All 79 Lines • ▼ Show 20 Line(s) | 240 | { | |||
248 | if (freebusy->freeBusy() && freebusy->freeBusy()->fullBusyPeriods().size() > 0) { | 248 | if (freebusy->freeBusy() && freebusy->freeBusy()->fullBusyPeriods().size() > 0) { | ||
249 | QModelIndex parent = index(row, 0); | 249 | QModelIndex parent = index(row, 0); | ||
250 | setFreeBusyPeriods(parent, freebusy->freeBusy()->fullBusyPeriods()); | 250 | setFreeBusyPeriods(parent, freebusy->freeBusy()->fullBusyPeriods()); | ||
251 | } | 251 | } | ||
252 | updateFreeBusyData(freebusy); | 252 | updateFreeBusyData(freebusy); | ||
253 | } | 253 | } | ||
254 | 254 | | |||
255 | void FreeBusyItemModel::setFreeBusyPeriods(const QModelIndex &parent, | 255 | void FreeBusyItemModel::setFreeBusyPeriods(const QModelIndex &parent, | ||
256 | const KCalCore::FreeBusyPeriod::List &list) | 256 | const KCalendarCore::FreeBusyPeriod::List &list) | ||
257 | { | 257 | { | ||
258 | if (!parent.isValid()) { | 258 | if (!parent.isValid()) { | ||
259 | return; | 259 | return; | ||
260 | } | 260 | } | ||
261 | 261 | | |||
262 | ItemPrivateData *parentData = static_cast<ItemPrivateData *>(parent.internalPointer()); | 262 | ItemPrivateData *parentData = static_cast<ItemPrivateData *>(parent.internalPointer()); | ||
263 | int fb_count = list.size(); | 263 | int fb_count = list.size(); | ||
264 | int childCount = parentData->childCount(); | 264 | int childCount = parentData->childCount(); | ||
▲ Show 20 Lines • Show All 47 Lines • ▼ Show 20 Line(s) | |||||
312 | void FreeBusyItemModel::removeItem(const FreeBusyItem::Ptr &freebusy) | 312 | void FreeBusyItemModel::removeItem(const FreeBusyItem::Ptr &freebusy) | ||
313 | { | 313 | { | ||
314 | int row = d->mFreeBusyItems.indexOf(freebusy); | 314 | int row = d->mFreeBusyItems.indexOf(freebusy); | ||
315 | if (row >= 0) { | 315 | if (row >= 0) { | ||
316 | removeRow(row); | 316 | removeRow(row); | ||
317 | } | 317 | } | ||
318 | } | 318 | } | ||
319 | 319 | | |||
320 | void FreeBusyItemModel::removeAttendee(const KCalCore::Attendee &attendee) | 320 | void FreeBusyItemModel::removeAttendee(const KCalendarCore::Attendee &attendee) | ||
321 | { | 321 | { | ||
322 | FreeBusyItem::Ptr anItem; | 322 | FreeBusyItem::Ptr anItem; | ||
323 | for (int i = 0; i < d->mFreeBusyItems.count(); ++i) { | 323 | for (int i = 0; i < d->mFreeBusyItems.count(); ++i) { | ||
324 | anItem = d->mFreeBusyItems[i]; | 324 | anItem = d->mFreeBusyItems[i]; | ||
325 | if (anItem->attendee() == attendee) { | 325 | if (anItem->attendee() == attendee) { | ||
326 | if (anItem->updateTimerID() != 0) { | 326 | if (anItem->updateTimerID() != 0) { | ||
327 | killTimer(anItem->updateTimerID()); | 327 | killTimer(anItem->updateTimerID()); | ||
328 | } | 328 | } | ||
329 | removeRow(i); | 329 | removeRow(i); | ||
330 | break; | 330 | break; | ||
331 | } | 331 | } | ||
332 | } | 332 | } | ||
333 | } | 333 | } | ||
334 | 334 | | |||
335 | bool FreeBusyItemModel::containsAttendee(const KCalCore::Attendee &attendee) | 335 | bool FreeBusyItemModel::containsAttendee(const KCalendarCore::Attendee &attendee) | ||
336 | { | 336 | { | ||
337 | FreeBusyItem::Ptr anItem; | 337 | FreeBusyItem::Ptr anItem; | ||
338 | for (int i = 0; i < d->mFreeBusyItems.count(); ++i) { | 338 | for (int i = 0; i < d->mFreeBusyItems.count(); ++i) { | ||
339 | anItem = d->mFreeBusyItems[i]; | 339 | anItem = d->mFreeBusyItems[i]; | ||
340 | if (anItem->attendee() == attendee) { | 340 | if (anItem->attendee() == attendee) { | ||
341 | return true; | 341 | return true; | ||
342 | } | 342 | } | ||
343 | } | 343 | } | ||
Show All 24 Lines | 367 | for (FreeBusyItem::Ptr item : qAsConst(d->mFreeBusyItems)) { | |||
368 | if (item->updateTimerID() == event->timerId()) { | 368 | if (item->updateTimerID() == event->timerId()) { | ||
369 | item->setUpdateTimerID(0); | 369 | item->setUpdateTimerID(0); | ||
370 | item->startDownload(d->mForceDownload); | 370 | item->startDownload(d->mForceDownload); | ||
371 | return; | 371 | return; | ||
372 | } | 372 | } | ||
373 | } | 373 | } | ||
374 | } | 374 | } | ||
375 | 375 | | |||
376 | void FreeBusyItemModel::slotInsertFreeBusy(const KCalCore::FreeBusy::Ptr &fb, const QString &email) | 376 | void FreeBusyItemModel::slotInsertFreeBusy(const KCalendarCore::FreeBusy::Ptr &fb, const QString &email) | ||
377 | { | 377 | { | ||
378 | if (!fb) { | 378 | if (!fb) { | ||
379 | return; | 379 | return; | ||
380 | } | 380 | } | ||
381 | 381 | | |||
382 | if (fb->fullBusyPeriods().isEmpty()) { | 382 | if (fb->fullBusyPeriods().isEmpty()) { | ||
383 | return; | 383 | return; | ||
384 | } | 384 | } | ||
▲ Show 20 Lines • Show All 41 Lines • Show Last 20 Lines |