Fix dnd email
[kdepim.git] / kalarm / eventid.cpp
blob654c3a84f830a3ad3d0d2063572c66977921a0a6
1 /*
2 * eventid.cpp - KAlarm unique event identifier for Akonadi
3 * Program: kalarm
4 * Copyright © 2012 by David Jarvie <djarvie@kde.org>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 #include "eventid.h"
23 #include "collectionmodel.h"
25 #include <QString>
26 #include <QRegExp>
27 #include "kalarm_debug.h"
29 /** Set by event ID and optional resource ID, in the format "[rid:]eid". */
30 EventId::EventId(const QString& resourceEventId)
32 bool resourceOk = false;
33 QRegExp rx(QStringLiteral("^\\w+:"));
34 if (rx.indexIn(resourceEventId) == 0)
36 // A resource ID has been supplied, so use it
37 int n = rx.matchedLength();
38 Akonadi::Collection c = CollectionControlModel::collectionForResource(resourceEventId.left(n - 1));
40 first = c.id();
41 second = resourceEventId.mid(n);
42 resourceOk = true;
45 if (!resourceOk)
47 // Only an event ID has been supplied (or the syntax was invalid)
48 first = -1;
49 second = resourceEventId;
53 // vim: et sw=4: