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 CalendarResourceManager *manager )
00106 {
00107 Q_ASSERT( manager );
00108 QString myfamily = family;
00109 if ( family.isEmpty() ) {
00110 myfamily = "calendar";
00111 }
00112
00113 CalendarResourceManager::ActiveIterator it;
00114
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 bool CalHelper::hasWritableEventsFolders( const QString &family,
00144 CalendarResourceManager *manager )
00145 {
00146 Q_ASSERT( manager );
00147 QString myfamily = family;
00148 if ( family.isEmpty() ) {
00149 myfamily = "calendar";
00150 }
00151
00152 CalendarResourceManager::ActiveIterator it;
00153
00154 for ( it=manager->activeBegin(); it != manager->activeEnd(); ++it ) {
00155 if ( (*it)->readOnly() ) {
00156 continue;
00157 }
00158
00159 const QStringList subResources = (*it)->subresources();
00160 if ( subResources.isEmpty() ) {
00161 return true;
00162 }
00163
00164 QStringList::ConstIterator subIt;
00165 for ( subIt=subResources.begin(); subIt != subResources.end(); ++subIt ) {
00166 if ( !(*it)->subresourceActive( (*subIt) ) ) {
00167 continue;
00168 }
00169 if ( (*it)->type() == "imap" || (*it)->type() == "kolab" ) {
00170 if ( (*it)->subresourceType( ( *subIt ) ) == "todo" ||
00171 (*it)->subresourceType( ( *subIt ) ) == "journal" ||
00172 !(*it)->subresourceWritable( *subIt ) ) {
00173 continue;
00174 }
00175 }
00176 return true;
00177 }
00178 }
00179 return false;
00180 }
00181
00182 ResourceCalendar *CalHelper::incResourceCalendar( Calendar *calendar, Incidence *incidence )
00183 {
00184 CalendarResources *cal = dynamic_cast<CalendarResources*>( calendar );
00185 if ( !cal || !incidence ) {
00186 return 0;
00187 }
00188
00189 return cal->resource( incidence );
00190 }
00191
00192 QPair<ResourceCalendar *, QString> CalHelper::incSubResourceCalendar( Calendar *calendar,
00193 Incidence *incidence )
00194 {
00195 QPair<ResourceCalendar *, QString> p( 0, QString() );
00196
00197 CalendarResources *cal = dynamic_cast<CalendarResources*>( calendar );
00198 if ( !cal || !incidence ) {
00199 return p;
00200 }
00201
00202 ResourceCalendar *res = cal->resource( incidence );
00203
00204 QString subRes;
00205 if ( res && res->canHaveSubresources() ) {
00206 subRes = res->subresourceIdentifier( incidence );
00207 }
00208 p = qMakePair( res, subRes );
00209 return p;
00210 }
00211
00212 bool CalHelper::incOrganizerOwnsCalendar( Calendar *calendar, Incidence *incidence )
00213 {
00214 if ( !calendar || !incidence ) {
00215 return false;
00216 }
00217
00218 QPair<ResourceCalendar *, QString> p = incSubResourceCalendar( calendar, incidence );
00219 ResourceCalendar *res = p.first;
00220 QString subRes = p.second;
00221
00222 if ( !res ) {
00223 return false;
00224 }
00225
00226 QString orgEmail;
00227 QString orgName;
00228 KPIM::getNameAndMail( incidence->organizer().email(), orgName, orgEmail );
00229 if ( KPIM::isValidEmailAddress( orgEmail ) != KPIM::AddressOk ) {
00230 return false;
00231 }
00232
00233
00234 bool iam = false;
00235 KEMailSettings settings;
00236 QStringList profiles = settings.profiles();
00237 for( QStringList::Iterator it=profiles.begin(); it!=profiles.end(); ++it ) {
00238 settings.setProfile( *it );
00239 if ( settings.getSetting( KEMailSettings::EmailAddress ) == orgEmail ) {
00240 iam = true;
00241 break;
00242 }
00243 }
00244
00245
00246 if ( iam && isMyCalendarIncidence( calendar, incidence ) ) {
00247
00248 return true;
00249 }
00250
00251
00252
00253 if ( ( res->type() == "imap" || res->type() == "kolab" ) && !subRes.isEmpty() ) {
00254
00255
00256
00257
00258 const int atChar = orgEmail.findRev( '@' );
00259 const QString name = orgEmail.left( atChar );
00260 QString kolabFolder = "/.user.directory/." + name + ".directory/";
00261 if ( subRes.contains( kolabFolder ) ) {
00262 return true;
00263 }
00264
00265 const int dotChar = name.find( '.' );
00266 if ( dotChar > 0 ) {
00267 const QString firstName = name.left( dotChar );
00268 kolabFolder = "/.user.directory/." + firstName + ".directory/";
00269 if ( subRes.contains( kolabFolder ) ) {
00270 return true;
00271 }
00272 }
00273 }
00274
00275
00276
00277 return false;
00278 }
|