libkcal
calhelper.cppGo to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00032 #include "calhelper.h"
00033 #include "calendarresources.h"
00034
00035 #include <libemailfunctions/email.h>
00036
00037 #include <kemailsettings.h>
00038
00039 using namespace KCal;
00040
00041 bool CalHelper::isMyKolabIncidence( Calendar *calendar, Incidence *incidence )
00042 {
00043 CalendarResources *cal = dynamic_cast<CalendarResources*>( calendar );
00044 if ( !cal || !incidence ) {
00045 return true;
00046 }
00047
00048 CalendarResourceManager *manager = cal->resourceManager();
00049 CalendarResourceManager::Iterator it;
00050 for ( it = manager->begin(); it != manager->end(); ++it ) {
00051 QString subRes = (*it)->subresourceIdentifier( incidence );
00052 if ( !subRes.isEmpty() && !subRes.contains( "/.INBOX.directory/" ) ) {
00053 return false;
00054 }
00055 }
00056 return true;
00057 }
00058
00059 bool CalHelper::isMyCalendarIncidence( Calendar *calendar, Incidence *incidence )
00060 {
00061 return isMyKolabIncidence( calendar, incidence );
00062 }
00063
00064 Incidence *CalHelper::findMyCalendarIncidenceByUid( Calendar *calendar, const QString &uid )
00065 {
00066
00067 Incidence *existingIncidence = 0;
00068 if ( calendar ) {
00069 existingIncidence = calendar->incidence( uid );
00070 if ( !isMyCalendarIncidence( calendar, existingIncidence ) ) {
00071 existingIncidence = 0;
00072 }
00073 if ( !existingIncidence ) {
00074 const Incidence::List list = calendar->incidences();
00075 for ( Incidence::List::ConstIterator it = list.begin(), end = list.end(); it != end; ++it ) {
00076 if ( (*it)->schedulingID() == uid && isMyCalendarIncidence( calendar, *it ) ) {
00077 existingIncidence = *it;
00078 break;
00079 }
00080 }
00081 }
00082 }
00083 return existingIncidence;
00084 }
00085
00086 bool CalHelper::usingGroupware( Calendar *calendar )
00087 {
00088 CalendarResources *cal = dynamic_cast<CalendarResources*>( calendar );
00089 if ( !cal ) {
00090 return true;
00091 }
00092
00093 CalendarResourceManager *manager = cal->resourceManager();
00094 CalendarResourceManager::Iterator it;
00095 for ( it = manager->begin(); it != manager->end(); ++it ) {
00096 QString res = (*it)->type();
00097 if ( res == "imap" ) {
00098 return true;
00099 }
00100 }
00101 return false;
00102 }
00103
00104 bool CalHelper::hasMyWritableEventsFolders( const QString &family )
00105 {
00106 QString myfamily = family;
00107 if ( family.isEmpty() ) {
00108 myfamily = "calendar";
00109 }
00110
00111 CalendarResourceManager manager( myfamily );
00112 manager.readConfig();
00113
00114 CalendarResourceManager::ActiveIterator it;
00115 for ( it=manager.activeBegin(); it != manager.activeEnd(); ++it ) {
00116 if ( (*it)->readOnly() ) {
00117 continue;
00118 }
00119
00120 const QStringList subResources = (*it)->subresources();
00121 if ( subResources.isEmpty() ) {
00122 return true;
00123 }
00124
00125 QStringList::ConstIterator subIt;
00126 for ( subIt=subResources.begin(); subIt != subResources.end(); ++subIt ) {
00127 if ( !(*it)->subresourceActive( (*subIt) ) ) {
00128 continue;
00129 }
00130 if ( (*it)->type() == "imap" || (*it)->type() == "kolab" ) {
00131 if ( (*it)->subresourceType( ( *subIt ) ) == "todo" ||
00132 (*it)->subresourceType( ( *subIt ) ) == "journal" ||
00133 !(*subIt).contains( "/.INBOX.directory/" ) ) {
00134 continue;
00135 }
00136 }
00137 return true;
00138 }
00139 }
00140 return false;
00141 }
00142
00143 ResourceCalendar *CalHelper::incResourceCalendar( Calendar *calendar, Incidence *incidence )
00144 {
00145 CalendarResources *cal = dynamic_cast<CalendarResources*>( calendar );
00146 if ( !cal || !incidence ) {
00147 return 0;
00148 }
00149
00150 return cal->resource( incidence );
00151 }
00152
00153 QPair<ResourceCalendar *, QString> CalHelper::incSubResourceCalendar( Calendar *calendar,
00154 Incidence *incidence )
00155 {
00156 QPair<ResourceCalendar *, QString> p( 0, QString() );
00157
00158 CalendarResources *cal = dynamic_cast<CalendarResources*>( calendar );
00159 if ( !cal || !incidence ) {
00160 return p;
00161 }
00162
00163 ResourceCalendar *res = cal->resource( incidence );
00164
00165 QString subRes;
00166 if ( res && res->canHaveSubresources() ) {
00167 subRes = res->subresourceIdentifier( incidence );
00168 }
00169 p = qMakePair( res, subRes );
00170 return p;
00171 }
00172
00173 bool CalHelper::incOrganizerOwnsCalendar( Calendar *calendar, Incidence *incidence )
00174 {
00175 if ( !calendar || !incidence ) {
00176 return false;
00177 }
00178
00179 QPair<ResourceCalendar *, QString> p = incSubResourceCalendar( calendar, incidence );
00180 ResourceCalendar *res = p.first;
00181 QString subRes = p.second;
00182
00183 if ( !res ) {
00184 return false;
00185 }
00186
00187 QString orgEmail;
00188 QString orgName;
00189 KPIM::getNameAndMail( incidence->organizer().email(), orgName, orgEmail );
00190 if ( KPIM::isValidEmailAddress( orgEmail ) != KPIM::AddressOk ) {
00191 return false;
00192 }
00193
00194
00195 bool iam = false;
00196 KEMailSettings settings;
00197 QStringList profiles = settings.profiles();
00198 for( QStringList::Iterator it=profiles.begin(); it!=profiles.end(); ++it ) {
00199 settings.setProfile( *it );
00200 if ( settings.getSetting( KEMailSettings::EmailAddress ) == orgEmail ) {
00201 iam = true;
00202 break;
00203 }
00204 }
00205
00206
00207 if ( iam && isMyCalendarIncidence( calendar, incidence ) ) {
00208
00209 return true;
00210 }
00211
00212
00213
00214 if ( ( res->type() == "imap" || res->type() == "kolab" ) && !subRes.isEmpty() ) {
00215
00216
00217
00218
00219 const int atChar = orgEmail.findRev( '@' );
00220 const QString name = orgEmail.left( atChar );
00221 QString kolabFolder = "/.user.directory/." + name + ".directory/";
00222 if ( subRes.contains( kolabFolder ) ) {
00223 return true;
00224 }
00225
00226 const int dotChar = name.find( '.' );
00227 if ( dotChar > 0 ) {
00228 const QString firstName = name.left( dotChar );
00229 kolabFolder = "/.user.directory/." + firstName + ".directory/";
00230 if ( subRes.contains( kolabFolder ) ) {
00231 return true;
00232 }
00233 }
00234 }
00235
00236
00237
00238 return false;
00239 }
|