summaryrefslogtreecommitdiffstats
path: root/libkcal/calhelper.cpp
diff options
context:
space:
mode:
authortpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-09-01 00:37:02 +0000
committertpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-09-01 00:37:02 +0000
commitcc29364f06178f8f6b457384f2ec37a042bd9d43 (patch)
tree7c77a3184c698bbf9d98cef09fb1ba8124daceba /libkcal/calhelper.cpp
parent4f6c584bacc8c3c694228f36ada3de77a76614a6 (diff)
downloadtdepim-cc29364f06178f8f6b457384f2ec37a042bd9d43.tar.gz
tdepim-cc29364f06178f8f6b457384f2ec37a042bd9d43.zip
* Massive set of changes to bring in all fixes and enhancements from the Enterprise PIM branch
* Ensured that the Trinity changes were applied on top of those enhancements, and any redundancy removed * Added journal read support to the CalDAV resource * Fixed CalDAV resource to use events URL for tasks and journals when separate URL checkbox unchecked git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdepim@1170461 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'libkcal/calhelper.cpp')
-rw-r--r--libkcal/calhelper.cpp167
1 files changed, 167 insertions, 0 deletions
diff --git a/libkcal/calhelper.cpp b/libkcal/calhelper.cpp
new file mode 100644
index 000000000..cae5c102f
--- /dev/null
+++ b/libkcal/calhelper.cpp
@@ -0,0 +1,167 @@
+/*
+ This file is part of the kcal library.
+
+ Copyright (c) 2009-2010 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.net>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+/**
+ @file
+ This file is part of the API for handling calendar data and provides
+ static convenience functions for making decisions about calendar data.
+
+ @brief
+ Provides methods for making decisions about calendar data.
+
+ @author Allen Winter \<allen@kdab.net\>
+*/
+
+#include "calhelper.h"
+#include "calendarresources.h"
+
+using namespace KCal;
+
+bool CalHelper::isMyKolabIncidence( Calendar *calendar, Incidence *incidence )
+{
+ CalendarResources *cal = dynamic_cast<CalendarResources*>( calendar );
+ if ( !cal || !incidence ) {
+ return true;
+ }
+
+ CalendarResourceManager *manager = cal->resourceManager();
+ CalendarResourceManager::Iterator it;
+ for ( it = manager->begin(); it != manager->end(); ++it ) {
+ TQString subRes = (*it)->subresourceIdentifier( incidence );
+ if ( !subRes.isEmpty() && !subRes.contains( "/.INBOX.directory/" ) ) {
+ return false;
+ }
+ }
+ return true;
+}
+
+bool CalHelper::isMyCalendarIncidence( Calendar *calendar, Incidence *incidence )
+{
+ return isMyKolabIncidence( calendar, incidence );
+}
+
+Incidence *CalHelper::findMyCalendarIncidenceByUid( Calendar *calendar, const TQString &uid )
+{
+ // Determine if this incidence is in my calendar (and owned by me)
+ Incidence *existingIncidence = 0;
+ if ( calendar ) {
+ existingIncidence = calendar->incidence( uid );
+ if ( !isMyCalendarIncidence( calendar, existingIncidence ) ) {
+ existingIncidence = 0;
+ }
+ if ( !existingIncidence ) {
+ const Incidence::List list = calendar->incidences();
+ for ( Incidence::List::ConstIterator it = list.begin(), end = list.end(); it != end; ++it ) {
+ if ( (*it)->schedulingID() == uid && isMyCalendarIncidence( calendar, *it ) ) {
+ existingIncidence = *it;
+ break;
+ }
+ }
+ }
+ }
+ return existingIncidence;
+}
+
+bool CalHelper::usingGroupware( Calendar *calendar )
+{
+ CalendarResources *cal = dynamic_cast<CalendarResources*>( calendar );
+ if ( !cal ) {
+ return true;
+ }
+
+ CalendarResourceManager *manager = cal->resourceManager();
+ CalendarResourceManager::Iterator it;
+ for ( it = manager->begin(); it != manager->end(); ++it ) {
+ TQString res = (*it)->type();
+ if ( res == "imap" ) {
+ return true;
+ }
+ }
+ return false;
+}
+
+bool CalHelper::hasMyWritableEventsFolders( const TQString &family )
+{
+ TQString myfamily = family;
+ if ( family.isEmpty() ) {
+ myfamily = "calendar";
+ }
+
+ CalendarResourceManager manager( myfamily );
+ manager.readConfig();
+
+ CalendarResourceManager::ActiveIterator it;
+ for ( it=manager.activeBegin(); it != manager.activeEnd(); ++it ) {
+ if ( (*it)->readOnly() ) {
+ continue;
+ }
+
+ const TQStringList subResources = (*it)->subresources();
+ if ( subResources.isEmpty() ) {
+ return true;
+ }
+
+ TQStringList::ConstIterator subIt;
+ for ( subIt=subResources.begin(); subIt != subResources.end(); ++subIt ) {
+ if ( !(*it)->subresourceActive( (*subIt) ) ) {
+ continue;
+ }
+ if ( (*it)->type() == "imap" || (*it)->type() == "kolab" ) {
+ if ( (*it)->subresourceType( ( *subIt ) ) == "todo" ||
+ (*it)->subresourceType( ( *subIt ) ) == "journal" ||
+ !(*subIt).contains( "/.INBOX.directory/" ) ) {
+ continue;
+ }
+ }
+ return true;
+ }
+ }
+ return false;
+}
+
+ResourceCalendar *CalHelper::incResourceCalendar( Calendar *calendar, Incidence *incidence )
+{
+ CalendarResources *cal = dynamic_cast<CalendarResources*>( calendar );
+ if ( !cal || !incidence ) {
+ return 0;
+ }
+
+ return cal->resource( incidence );
+}
+
+QPair<ResourceCalendar *, TQString> CalHelper::incSubResourceCalendar( Calendar *calendar,
+ Incidence *incidence )
+{
+ QPair<ResourceCalendar *, TQString> p( 0, TQString() );
+
+ CalendarResources *cal = dynamic_cast<CalendarResources*>( calendar );
+ if ( !cal || !incidence ) {
+ return p;
+ }
+
+ ResourceCalendar *res = cal->resource( incidence );
+
+ TQString subRes;
+ if ( res && res->canHaveSubresources() ) {
+ subRes = res->subresourceIdentifier( incidence );
+ }
+ p = qMakePair( res, subRes );
+ return p;
+}