libkcal

calhelper.cpp

Go to the documentation of this file.
00001 /*
00002   This file is part of the kcal library.
00003 
00004   Copyright (c) 2009 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 == "imap" ) {
00094       return true;
00095     }
00096   }
00097   return false;
00098 }
00099 
00100 bool CalHelper::hasMyWritableEventsFolders( Calendar *calendar )
00101 {
00102   CalendarResources *cal = dynamic_cast<CalendarResources*>( calendar );
00103   if ( !cal ) {
00104     return true;
00105   }
00106 
00107   CalendarResourceManager *manager = cal->resourceManager();
00108 
00109   CalendarResourceManager::ActiveIterator it;
00110   for ( it=manager->activeBegin(); it != manager->activeEnd(); ++it ) {
00111     if ( (*it)->readOnly() ) {
00112       continue;
00113     }
00114 
00115     const QStringList subResources = (*it)->subresources();
00116     if ( subResources.isEmpty() ) {
00117       return true;
00118     }
00119 
00120     QStringList::ConstIterator subIt;
00121     for ( subIt=subResources.begin(); subIt != subResources.end(); ++subIt ) {
00122       if ( !(*it)->subresourceActive( (*subIt) ) ) {
00123         continue;
00124       }
00125       if ( (*it)->type() == "imap" || (*it)->type() == "kolab" ) {
00126         if ( (*it)->subresourceType( ( *subIt ) ) == "todo" ||
00127              (*it)->subresourceType( ( *subIt ) ) == "journal" ||
00128              !(*subIt).contains( "/.INBOX.directory/" ) ) {
00129           continue;
00130         }
00131       }
00132       return true;
00133     }
00134   }
00135   return false;
00136 }
KDE Home | KDE Accessibility Home | Description of Access Keys