diff --git a/libkcal/Makefile.am b/libkcal/Makefile.am index 9cc2675c40..a1cd9ea11c 100644 --- a/libkcal/Makefile.am +++ b/libkcal/Makefile.am @@ -1,83 +1,84 @@ SUBDIRS = libical versit tests INCLUDES = -I$(srcdir)/libical/src/libical \ -I$(srcdir)/libical/src/libicalss -I./libical/src/libical \ -I./libical/src/libicalss -I$(srcdir)/versit -I$(top_srcdir)/ \ -I$(top_srcdir)/ktnef \ -I$(top_srcdir)/libemailfunctions \ $(all_includes) lib_LTLIBRARIES = libkcal.la libkcal_la_LDFLAGS = $(all_libraries) -no-undefined -version-info 2:0:0 libkcal_la_LIBADD = versit/libversit.la $(LIB_KIO) \ ./libical/src/libical/libical.la \ ./libical/src/libicalss/libicalss.la \ $(top_builddir)/ktnef/lib/libktnef.la \ ../libkmime/libkmime.la \ ../libemailfunctions/libemailfunctions.la \ -lkresources -lkabc libkcal_la_COMPILE_FIRST = ./libical/src/libical/ical.h ./libical/src/libicalss/icalss.h libkcal_la_SOURCES = \ assignmentvisitor.cpp comparisonvisitor.cpp \ incidencebase.cpp incidence.cpp journal.cpp todo.cpp event.cpp \ freebusy.cpp attendee.cpp attachment.cpp recurrencerule.cpp recurrence.cpp alarm.cpp \ customproperties.cpp calendar.cpp calendarlocal.cpp \ calformat.cpp vcalformat.cpp icalformat.cpp icalformatimpl.cpp \ - incidenceformatter.cpp \ + incidenceformatter.cpp calhelper.cpp \ vcaldrag.cpp icaldrag.cpp \ exceptions.cpp \ scheduler.cpp imipscheduler.cpp dummyscheduler.cpp \ calfilter.cpp \ person.cpp period.cpp duration.cpp \ dndfactory.cpp \ filestorage.cpp \ compat.cpp \ resourcecalendar.cpp resourcelocal.cpp resourcelocalconfig.cpp \ resourcelocaldir.cpp resourcelocaldirconfig.cpp \ resourcecached.cpp resourcecachedconfig.cpp \ calendarresources.cpp \ qtopiaformat.cpp \ htmlexportsettings.kcfgc htmlexport.cpp calendarnull.cpp \ freebusyurlstore.cpp \ confirmsavedialog.cpp libkcalincludedir = $(includedir)/libkcal libkcalinclude_HEADERS = alarm.h attachment.h attendee.h calendar.h \ calendarlocal.h calendarnull.h calendarresources.h calfilter.h calformat.h \ calstorage.h customproperties.h dndfactory.h duration.h event.h \ exceptions.h filestorage.h freebusy.h htmlexportsettings.h htmlexport.h icaldrag.h icalformat.h \ - incidencebase.h incidence.h incidenceformatter.h journal.h kcalversion.h listbase.h period.h person.h \ + incidencebase.h incidence.h incidenceformatter.h calhelper.h \ + journal.h kcalversion.h listbase.h period.h person.h \ qtopiaformat.h recurrencerule.h recurrence.h resourcecached.h resourcecalendar.h \ resourcelocalconfig.h resourcelocaldirconfig.h resourcelocaldir.h \ resourcelocal.h scheduler.h libkcal_export.h \ todo.h vcaldrag.h vcalformat.h kde_module_LTLIBRARIES = kcal_local.la kcal_localdir.la kcal_local_la_SOURCES = resourcelocal_plugin.cpp kcal_local_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN) kcal_local_la_LIBADD = libkcal.la kcal_localdir_la_SOURCES = resourcelocaldir_plugin.cpp kcal_localdir_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN) kcal_localdir_la_LIBADD = libkcal.la EXTRA_PROGRAMS = convertqtopia convertqtopia_SOURCES = convertqtopia.cpp convertqtopia_LDADD = libkcal.la servicedir = $(kde_servicesdir)/kresources/kcal service_DATA = local.desktop localdir.desktop manager_DATA = kcal_manager.desktop managerdir = $(kde_servicesdir)/kresources METASOURCES = AUTO messages: rc.cpp $(XGETTEXT) *.cpp -o $(podir)/libkcal.pot DOXYGEN_EXCLUDE = libical DOXYGEN_REFERENCES=kresources include $(top_srcdir)/admin/Doxyfile.am diff --git a/libkcal/calhelper.cpp b/libkcal/calhelper.cpp new file mode 100644 index 0000000000..2853995937 --- /dev/null +++ b/libkcal/calhelper.cpp @@ -0,0 +1,80 @@ +/* + This file is part of the kcal library. + + Copyright (c) 2009 Klarälvdalens Datakonsult AB, a KDAB Group company + + 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 \ +*/ + +#include "calhelper.h" +#include "calendarresources.h" + +using namespace KCal; + +bool CalHelper::isMyKolabIncidence( Calendar *calendar, Incidence *incidence ) +{ + CalendarResources *cal = dynamic_cast( calendar ); + if ( !cal || !incidence ) { + return true; + } + ResourceCalendar *res = cal->resource( incidence ); + if ( !res ) { + return true; + } + const QString subRes = res->subresourceIdentifier( incidence ); + if ( !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 QString &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; +} diff --git a/libkcal/calhelper.h b/libkcal/calhelper.h new file mode 100644 index 0000000000..12e23d5530 --- /dev/null +++ b/libkcal/calhelper.h @@ -0,0 +1,84 @@ +/* + This file is part of libkcal. + + Copyright (c) 2009 Klarälvdalens Datakonsult AB, a KDAB Group company + + 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. + + @author Allen Winter \ +*/ + +#ifndef KCAL_CALENDARHELPER_H +#define KCAL_CALENDARHELPER_H + +#include + +namespace KCal { +class Calendar; +class Incidence; + +/** + @brief + Provides methods for making decisions about calendar data. +*/ +namespace CalHelper { + + /** + Determine if the specified incidence is likely a Kolab incidence + owned by the the user. + + @param calendar is a pointer to a valid Calendar object. + @param incidence is a pointer to an Incidence object. + + @return true if it is likely that the specified incidence belongs + to the user in their Kolab resource; false otherwise. + */ + bool isMyKolabIncidence( Calendar *calendar, Incidence *incidence ); + + /** + Determine if the specified incidence is likely owned by the the user, + independent of the Resource type. + + @param calendar is a pointer to a valid Calendar object. + @param incidence is a pointer to an Incidence object. + + @return true if it is likely that the specified incidence belongs + to the user; false otherwise. + */ + bool isMyCalendarIncidence( Calendar *calendar, Incidence *incidence ); + + /** + Searches for the specified Incidence by UID, returning an Incidence pointer + if and only if the found Incidence is owned by the user. + + @param calendar is a pointer to a valid Calendar object. + @param Uid is a QString containing an Incidence UID. + + @return a pointer to the Incidence found; 0 if the Incidence is not found + or the Incidence is found but is not owned by the user. + */ + Incidence *findMyCalendarIncidenceByUid( Calendar *calendar, const QString &uid ); +} + +} + +#endif +