calhelper.cpp
Go to the documentation of this file.
00001 /* 00002 This file is part of the kcal library. 00003 00004 Copyright (c) 2009-2010 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.net> 00005 00006 This library is free software; you can redistribute it and/or 00007 modify it under the terms of the GNU Library General Public 00008 License as published by the Free Software Foundation; either 00009 version 2 of the License, or (at your option) any later version. 00010 00011 This library is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 Library General Public License for more details. 00015 00016 You should have received a copy of the GNU Library General Public License 00017 along with this library; see the file COPYING.LIB. If not, write to 00018 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00019 Boston, MA 02110-1301, USA. 00020 */ 00032 #include "calhelper.h" 00033 #include "calendarresources.h" 00034 00035 using namespace KCal; 00036 00037 bool CalHelper::isMyKolabIncidence( Calendar *calendar, Incidence *incidence ) 00038 { 00039 CalendarResources *cal = dynamic_cast<CalendarResources*>( calendar ); 00040 if ( !cal || !incidence ) { 00041 return true; 00042 } 00043 00044 CalendarResourceManager *manager = cal->resourceManager(); 00045 CalendarResourceManager::Iterator it; 00046 for ( it = manager->begin(); it != manager->end(); ++it ) { 00047 QString subRes = (*it)->subresourceIdentifier( incidence ); 00048 if ( !subRes.isEmpty() && !subRes.contains( "/.INBOX.directory/" ) ) { 00049 return false; 00050 } 00051 } 00052 return true; 00053 } 00054 00055 bool CalHelper::isMyCalendarIncidence( Calendar *calendar, Incidence *incidence ) 00056 { 00057 return isMyKolabIncidence( calendar, incidence ); 00058 } 00059 00060 Incidence *CalHelper::findMyCalendarIncidenceByUid( Calendar *calendar, const QString &uid ) 00061 { 00062 // Determine if this incidence is in my calendar (and owned by me) 00063 Incidence *existingIncidence = 0; 00064 if ( calendar ) { 00065 existingIncidence = calendar->incidence( uid ); 00066 if ( !isMyCalendarIncidence( calendar, existingIncidence ) ) { 00067 existingIncidence = 0; 00068 } 00069 if ( !existingIncidence ) { 00070 const Incidence::List list = calendar->incidences(); 00071 for ( Incidence::List::ConstIterator it = list.begin(), end = list.end(); it != end; ++it ) { 00072 if ( (*it)->schedulingID() == uid && isMyCalendarIncidence( calendar, *it ) ) { 00073 existingIncidence = *it; 00074 break; 00075 } 00076 } 00077 } 00078 } 00079 return existingIncidence; 00080 } 00081 00082 bool CalHelper::usingGroupware( Calendar *calendar ) 00083 { 00084 CalendarResources *cal = dynamic_cast<CalendarResources*>( calendar ); 00085 if ( !cal ) { 00086 return true; 00087 } 00088 00089 CalendarResourceManager *manager = cal->resourceManager(); 00090 CalendarResourceManager::Iterator it; 00091 for ( it = manager->begin(); it != manager->end(); ++it ) { 00092 QString res = (*it)->type(); 00093 if ( res == QLatin1String( "imap" ) ) { 00094 return true; 00095 } 00096 } 00097 return false; 00098 } 00099