summaryrefslogtreecommitdiffstats
path: root/kresources/kolab/knotes
diff options
context:
space:
mode:
Diffstat (limited to 'kresources/kolab/knotes')
-rw-r--r--kresources/kolab/knotes/Makefile.am29
-rw-r--r--kresources/kolab/knotes/kolabresource.desktop53
-rw-r--r--kresources/kolab/knotes/note.cpp210
-rw-r--r--kresources/kolab/knotes/note.h111
-rw-r--r--kresources/kolab/knotes/resourcekolab.cpp437
-rw-r--r--kresources/kolab/knotes/resourcekolab.h129
-rw-r--r--kresources/kolab/knotes/resourcekolab_plugin.cpp50
7 files changed, 1019 insertions, 0 deletions
diff --git a/kresources/kolab/knotes/Makefile.am b/kresources/kolab/knotes/Makefile.am
new file mode 100644
index 00000000..de4ff1dd
--- /dev/null
+++ b/kresources/kolab/knotes/Makefile.am
@@ -0,0 +1,29 @@
+METASOURCES = AUTO
+
+INCLUDES = -I$(top_srcdir)/kresources/kolab/shared \
+ -I$(top_srcdir) -I$(top_srcdir)/knotes -I$(top_builddir)/libkdepim $(all_includes)
+
+# The kolab wizard links to this library too
+lib_LTLIBRARIES = libknoteskolab.la
+
+libknoteskolab_la_SOURCES = resourcekolab.cpp note.cpp
+libknoteskolab_la_LDFLAGS = $(all_libraries) -no-undefined
+libknoteskolab_la_LIBADD = \
+ $(top_builddir)/kresources/kolab/shared/libresourcekolabshared.la \
+ $(top_builddir)/knotes/libknotesresources.la \
+ $(top_builddir)/libkcal/libkcal.la \
+ -lkresources -lkdeprint
+
+kde_module_LTLIBRARIES = knotes_kolab.la
+
+knotes_kolab_la_SOURCES = resourcekolab_plugin.cpp
+knotes_kolab_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN) -no-undefined
+knotes_kolab_la_LIBADD = libknoteskolab.la
+
+servicedir = $(kde_servicesdir)/kresources/knotes
+service_DATA = kolabresource.desktop
+
+install-data-local: $(srcdir)/../uninstall.desktop
+ $(mkinstalldirs) $(DESTDIR)$(servicedir)
+ $(INSTALL_DATA) $(srcdir)/../uninstall.desktop $(DESTDIR)$(servicedir)/imap.desktop
+
diff --git a/kresources/kolab/knotes/kolabresource.desktop b/kresources/kolab/knotes/kolabresource.desktop
new file mode 100644
index 00000000..d74e3f59
--- /dev/null
+++ b/kresources/kolab/knotes/kolabresource.desktop
@@ -0,0 +1,53 @@
+[Desktop Entry]
+Name=IMAP Server via KMail
+Name[af]=IMAP bediener via KMail
+Name[bg]=Сървър IMAP през KMail
+Name[br]=Servijer IMAP gant KMail
+Name[ca]=Servidor IMAP mitjançant KMail
+Name[cs]=IMAP server přes KMail
+Name[da]=IMAP-server via KMail
+Name[de]=IMAP-Server via KMail
+Name[el]=Εξυπηρετητής IMAP μέσω του KMail
+Name[es]=Servidor IMAP por medio de KMail
+Name[et]=IMAP-server (KMaili vahendusel)
+Name[eu]=IMAP zerbitzaria KMail-en bidez
+Name[fa]=کارساز IMAP از طریق KMail
+Name[fi]=IMAP-palvelin KMailin avulla
+Name[fr]=Serveur IMAP (via KMail)
+Name[fy]=IMAP-tsjinner fia KMail
+Name[ga]=Freastalaí IMAP via KMail
+Name[gl]=Servidor MAP mediante KMail
+Name[hu]=IMAP-kiszolgáló a KMailen keresztül
+Name[is]=IMAP þjónn gegnum KMail
+Name[it]=Server IMAP via KMail
+Name[ja]=KMail 経由 IMAP サーバ
+Name[ka]= IMAP-ს სერვერთან დაშვება KMail-ის საშუალებით
+Name[kk]=KMail арқылы IMAP сервері
+Name[km]=ម៉ាស៊ីន​បម្រើ IMAP តាម​រយៈ KMail
+Name[lt]=IMAP serveris per KMail
+Name[mk]=IMAP-сервер преку КПошта
+Name[ms]=Pelayan IMAP melalui KMail
+Name[nb]=IMAP-tjener via KMail
+Name[nds]=IMAP-Server över KMail
+Name[ne]=केडीई मेल मार्फत IMAP सर्भर
+Name[nl]=IMAP-server via KMail
+Name[nn]=IMAP-tenar via KMail
+Name[pl]=Serwer IMAP za pośrednictwem KMail
+Name[pt]=Servidor IMAP via KMail
+Name[pt_BR]=Servidor IMAP via KMail
+Name[ru]=Доступ к серверу IMAP через KMail
+Name[sk]=IMAP-server pomocou KMail
+Name[sl]=Strežnik IMAP preko KMaila
+Name[sr]=IMAP сервер преко KMail-а
+Name[sr@Latn]=IMAP server preko KMail-a
+Name[sv]=IMAP-server via Kmail
+Name[ta]=IMAP சேவகன் மூலாம் கேஅஞ்சல்
+Name[tr]=KMail aracılığı ile IMAP Sunucu
+Name[uk]=Сервер IMAP через KMail
+Name[zh_CN]=通过 KMail 访问 IMAP 服务器
+Name[zh_TW]=透過 KMail 取得 IMAP 伺服器
+X-KDE-Library=knotes_kolab
+Type=Service
+ServiceTypes=KResources/Plugin
+X-KDE-ResourceFamily=notes
+X-KDE-ResourceType=imap
diff --git a/kresources/kolab/knotes/note.cpp b/kresources/kolab/knotes/note.cpp
new file mode 100644
index 00000000..76ecdd9d
--- /dev/null
+++ b/kresources/kolab/knotes/note.cpp
@@ -0,0 +1,210 @@
+/*
+ This file is part of the kolab resource - the implementation of the
+ Kolab storage format. See www.kolab.org for documentation on this.
+
+ Copyright (c) 2004 Bo Thorsen <bo@sonofthor.dk>
+
+ 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.
+
+ In addition, as a special exception, the copyright holders give
+ permission to link the code of this program with any edition of
+ the Qt library by Trolltech AS, Norway (or with modified versions
+ of Qt that use the same license as Qt), and distribute linked
+ combinations including the two. You must obey the GNU General
+ Public License in all respects for all of the code used other than
+ Qt. If you modify this file, you may extend this exception to
+ your version of the file, but you are not obligated to do so. If
+ you do not wish to do so, delete this exception statement from
+ your version.
+*/
+
+#include "note.h"
+
+#include <libkcal/journal.h>
+#include <knotes/version.h>
+#include <kdebug.h>
+
+using namespace Kolab;
+
+
+KCal::Journal* Note::xmlToJournal( const QString& xml )
+{
+ Note note;
+ note.load( xml );
+ KCal::Journal* journal = new KCal::Journal();
+ note.saveTo( journal );
+ return journal;
+}
+
+QString Note::journalToXML( KCal::Journal* journal )
+{
+ Note note( journal );
+ return note.saveXML();
+}
+
+Note::Note( KCal::Journal* journal ) : mRichText( false )
+{
+ if ( journal )
+ setFields( journal );
+}
+
+Note::~Note()
+{
+}
+
+void Note::setSummary( const QString& summary )
+{
+ mSummary = summary;
+}
+
+QString Note::summary() const
+{
+ return mSummary;
+}
+
+void Note::setBackgroundColor( const QColor& bgColor )
+{
+ mBackgroundColor = bgColor;
+}
+
+QColor Note::backgroundColor() const
+{
+ return mBackgroundColor;
+}
+
+void Note::setForegroundColor( const QColor& fgColor )
+{
+ mForegroundColor = fgColor;
+}
+
+QColor Note::foregroundColor() const
+{
+ return mForegroundColor;
+}
+
+void Note::setRichText( bool richText )
+{
+ mRichText = richText;
+}
+
+bool Note::richText() const
+{
+ return mRichText;
+}
+
+bool Note::loadAttribute( QDomElement& element )
+{
+ QString tagName = element.tagName();
+
+ if ( tagName == "summary" )
+ setSummary( element.text() );
+ else if ( tagName == "foreground-color" )
+ setForegroundColor( stringToColor( element.text() ) );
+ else if ( tagName == "background-color" )
+ setBackgroundColor( stringToColor( element.text() ) );
+ else if ( tagName == "knotes-richtext" )
+ mRichText = ( element.text() == "true" );
+ else
+ return KolabBase::loadAttribute( element );
+
+ // We handled this
+ return true;
+}
+
+bool Note::saveAttributes( QDomElement& element ) const
+{
+ // Save the base class elements
+ KolabBase::saveAttributes( element );
+
+ // Save the elements
+#if 0
+ QDomComment c = element.ownerDocument().createComment( "Note specific attributes" );
+ element.appendChild( c );
+#endif
+
+ writeString( element, "summary", summary() );
+ writeString( element, "foreground-color", colorToString( foregroundColor() ) );
+ writeString( element, "background-color", colorToString( backgroundColor() ) );
+ writeString( element, "knotes-richtext", mRichText ? "true" : "false" );
+
+ return true;
+}
+
+
+bool Note::loadXML( const QDomDocument& document )
+{
+ QDomElement top = document.documentElement();
+
+ if ( top.tagName() != "note" ) {
+ qWarning( "XML error: Top tag was %s instead of the expected note",
+ top.tagName().ascii() );
+ return false;
+ }
+
+ for ( QDomNode n = top.firstChild(); !n.isNull(); n = n.nextSibling() ) {
+ if ( n.isComment() )
+ continue;
+ if ( n.isElement() ) {
+ QDomElement e = n.toElement();
+ if ( !loadAttribute( e ) )
+ // TODO: Unhandled tag - save for later storage
+ kdDebug() << "Warning: Unhandled tag " << e.tagName() << endl;
+ } else
+ kdDebug() << "Node is not a comment or an element???" << endl;
+ }
+
+ return true;
+}
+
+QString Note::saveXML() const
+{
+ QDomDocument document = domTree();
+ QDomElement element = document.createElement( "note" );
+ element.setAttribute( "version", "1.0" );
+ saveAttributes( element );
+ document.appendChild( element );
+ return document.toString();
+}
+
+void Note::setFields( const KCal::Journal* journal )
+{
+ KolabBase::setFields( journal );
+
+ // TODO: background and foreground
+ setSummary( journal->summary() );
+ setBackgroundColor( journal->customProperty( "KNotes", "BgColor" ) );
+ setForegroundColor( journal->customProperty( "KNotes", "FgColor" ) );
+ setRichText( journal->customProperty( "KNotes", "RichText" ) == "true" );
+}
+
+void Note::saveTo( KCal::Journal* journal )
+{
+ KolabBase::saveTo( journal );
+
+ // TODO: background and foreground
+ journal->setSummary( summary() );
+ journal->setCustomProperty( "KNotes", "FgColor",
+ colorToString( foregroundColor() ) );
+ journal->setCustomProperty( "KNotes", "BgColor",
+ colorToString( backgroundColor() ) );
+ journal->setCustomProperty( "KNotes", "RichText",
+ richText() ? "true" : "false" );
+}
+
+QString Note::productID() const
+{
+ return QString( "KNotes %1, Kolab resource" ).arg( KNOTES_VERSION );
+}
diff --git a/kresources/kolab/knotes/note.h b/kresources/kolab/knotes/note.h
new file mode 100644
index 00000000..45769f97
--- /dev/null
+++ b/kresources/kolab/knotes/note.h
@@ -0,0 +1,111 @@
+/*
+ This file is part of the kolab resource - the implementation of the
+ Kolab storage format. See www.kolab.org for documentation on this.
+
+ Copyright (c) 2004 Bo Thorsen <bo@sonofthor.dk>
+
+ 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.
+
+ In addition, as a special exception, the copyright holders give
+ permission to link the code of this program with any edition of
+ the Qt library by Trolltech AS, Norway (or with modified versions
+ of Qt that use the same license as Qt), and distribute linked
+ combinations including the two. You must obey the GNU General
+ Public License in all respects for all of the code used other than
+ Qt. If you modify this file, you may extend this exception to
+ your version of the file, but you are not obligated to do so. If
+ you do not wish to do so, delete this exception statement from
+ your version.
+*/
+
+#ifndef KOLAB_NOTE_H
+#define KOLAB_NOTE_H
+
+#include <kolabbase.h>
+
+class QDomElement;
+
+namespace KCal {
+ class Journal;
+}
+
+namespace Kolab {
+
+/**
+ * This class represents a note, and knows how to load/save it
+ * from/to XML, and from/to a KCal::Journal.
+ * The instances of this class are temporary, only used to convert
+ * one to the other.
+ */
+class Note : public KolabBase {
+public:
+ /// Use this to parse an xml string to a journal entry
+ /// The caller is responsible for deleting the returned journal
+ static KCal::Journal* xmlToJournal( const QString& xml );
+
+ /// Use this to get an xml string describing this journal entry
+ static QString journalToXML( KCal::Journal* );
+
+ /// Create a note object and
+ explicit Note( KCal::Journal* journal = 0 );
+ virtual ~Note();
+
+ void saveTo( KCal::Journal* journal );
+
+ virtual QString type() const { return "Note"; }
+
+ virtual void setSummary( const QString& summary );
+ virtual QString summary() const;
+
+ virtual void setBackgroundColor( const QColor& bgColor );
+ virtual QColor backgroundColor() const;
+
+ virtual void setForegroundColor( const QColor& fgColor );
+ virtual QColor foregroundColor() const;
+
+ virtual void setRichText( bool richText );
+ virtual bool richText() const;
+
+ // Load the attributes of this class
+ virtual bool loadAttribute( QDomElement& );
+
+ // Save the attributes of this class
+ virtual bool saveAttributes( QDomElement& ) const;
+
+ // Load this note by reading the XML file
+ virtual bool loadXML( const QDomDocument& xml );
+
+ // Serialize this note to an XML string
+ virtual QString saveXML() const;
+
+protected:
+ // Read all known fields from this ical incidence
+ void setFields( const KCal::Journal* );
+
+ // Save all known fields into this ical incidence
+ void saveTo( KCal::Incidence* ) const;
+
+ QString productID() const;
+
+ QString mSummary;
+ QColor mBackgroundColor;
+ QColor mForegroundColor;
+ bool mRichText;
+};
+
+}
+
+#endif // KOLAB_NOTE_H
diff --git a/kresources/kolab/knotes/resourcekolab.cpp b/kresources/kolab/knotes/resourcekolab.cpp
new file mode 100644
index 00000000..b5cad153
--- /dev/null
+++ b/kresources/kolab/knotes/resourcekolab.cpp
@@ -0,0 +1,437 @@
+/*
+ This file is part of the kolab resource - the implementation of the
+ Kolab storage format. See www.kolab.org for documentation on this.
+
+ Copyright (c) 2004 Bo Thorsen <bo@sonofthor.dk>
+ Copyright (c) 2004 Till Adam <adam@kde.org>
+
+ 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.
+
+ In addition, as a special exception, the copyright holders give
+ permission to link the code of this program with any edition of
+ the Qt library by Trolltech AS, Norway (or with modified versions
+ of Qt that use the same license as Qt), and distribute linked
+ combinations including the two. You must obey the GNU General
+ Public License in all respects for all of the code used other than
+ Qt. If you modify this file, you may extend this exception to
+ your version of the file, but you are not obligated to do so. If
+ you do not wish to do so, delete this exception statement from
+ your version.
+*/
+
+#include "resourcekolab.h"
+#include "note.h"
+
+#include <knotes/resourcemanager.h>
+
+#include <libkcal/icalformat.h>
+
+#include <kdebug.h>
+#include <kglobal.h>
+
+using namespace Kolab;
+
+static const char* configGroupName = "Note";
+static const char* kmailContentsType = "Note";
+static const char* attachmentMimeType = "application/x-vnd.kolab.note";
+static const char* inlineMimeType = "text/calendar";
+
+ResourceKolab::ResourceKolab( const KConfig *config )
+ : ResourceNotes( config ), ResourceKolabBase( "ResourceKolab-KNotes" ),
+ mCalendar( QString::fromLatin1("UTC") )
+{
+ setType( "imap" );
+}
+
+ResourceKolab::~ResourceKolab()
+{
+}
+
+bool ResourceKolab::doOpen()
+{
+ KConfig config( configFile() );
+ config.setGroup( configGroupName );
+
+ // Get the list of Notes folders from KMail
+ QValueList<KMailICalIface::SubResource> subResources;
+ if ( !kmailSubresources( subResources, kmailContentsType ) )
+ return false;
+
+ // Make the resource map from the folder list
+ QValueList<KMailICalIface::SubResource>::ConstIterator it;
+ mSubResources.clear();
+ for ( it = subResources.begin(); it != subResources.end(); ++it ) {
+ const QString subResource = (*it).location;
+ const bool active = config.readBoolEntry( subResource, true );
+ mSubResources[ subResource ] = Kolab::SubResource( active, (*it).writable, (*it).label );
+ }
+
+ return true;
+}
+
+void ResourceKolab::doClose()
+{
+ KConfig config( configFile() );
+ config.setGroup( configGroupName );
+ Kolab::ResourceMap::ConstIterator it;
+ for ( it = mSubResources.begin(); it != mSubResources.end(); ++it )
+ config.writeEntry( it.key(), it.data().active() );
+}
+
+bool ResourceKolab::loadSubResource( const QString& subResource,
+ const QString &mimetype )
+{
+ // Get the list of journals
+ int count = 0;
+ if ( !kmailIncidencesCount( count, mimetype, subResource ) ) {
+ kdError() << "Communication problem in ResourceKolab::load()\n";
+ return false;
+ }
+
+ QMap<Q_UINT32, QString> lst;
+ if( !kmailIncidences( lst, mimetype, subResource, 0, count ) ) {
+ kdError(5500) << "Communication problem in "
+ << "ResourceKolab::getIncidenceList()\n";
+ return false;
+ }
+
+ kdDebug(5500) << "Notes kolab resource: got " << lst.count() << " notes in " << subResource << endl;
+
+ // Populate with the new entries
+ const bool silent = mSilent;
+ mSilent = true;
+ QMap<Q_UINT32, QString>::Iterator it;
+ for ( it = lst.begin(); it != lst.end(); ++it ) {
+ KCal::Journal* journal = addNote( it.data(), subResource, it.key(), mimetype );
+ if ( !journal )
+ kdDebug(5500) << "loading note " << it.key() << " failed" << endl;
+ else
+ manager()->registerNote( this, journal );
+ }
+ mSilent = silent;
+
+ return true;
+}
+
+bool ResourceKolab::load()
+{
+ // We get a fresh list of events, so clean out the old ones
+ mCalendar.deleteAllEvents();
+ mUidMap.clear();
+
+ bool rc = true;
+ Kolab::ResourceMap::ConstIterator itR;
+ for ( itR = mSubResources.begin(); itR != mSubResources.end(); ++itR ) {
+ if ( !itR.data().active() )
+ // This subResource is disabled
+ continue;
+
+ QString mimetype = inlineMimeType;
+ rc &= loadSubResource( itR.key(), mimetype );
+ mimetype = attachmentMimeType;
+ rc &= loadSubResource( itR.key(), mimetype );
+ }
+
+ return rc;
+}
+
+bool ResourceKolab::save()
+{
+ // Nothing to do here, we save everything in incidenceUpdated()
+ return true;
+}
+
+bool ResourceKolab::addNote( KCal::Journal* journal )
+{
+ return addNote( journal, QString::null, 0 );
+}
+
+KCal::Journal* ResourceKolab::addNote( const QString& data, const QString& subresource,
+ Q_UINT32 sernum, const QString &mimetype )
+{
+ KCal::Journal* journal = 0;
+ // FIXME: This does not take into account the time zone!
+ KCal::ICalFormat formatter;
+ if ( mimetype == attachmentMimeType )
+ journal = Note::xmlToJournal( data );
+ else
+ journal = static_cast<KCal::Journal*>( formatter.fromString( data ) );
+
+ Q_ASSERT( journal );
+ if( journal && !mUidMap.contains( journal->uid() ) )
+ if ( addNote( journal, subresource, sernum ) )
+ return journal;
+ else
+ delete journal;
+ return 0;
+}
+
+bool ResourceKolab::addNote( KCal::Journal* journal,
+ const QString& subresource, Q_UINT32 sernum )
+{
+ kdDebug(5500) << "ResourceKolab::addNote( KCal::Journal*, '" << subresource << "', " << sernum << " )\n";
+
+ journal->registerObserver( this );
+
+ // Find out if this note was previously stored in KMail
+ bool newNote = subresource.isEmpty();
+ mCalendar.addJournal( journal );
+
+ QString resource =
+ newNote ? findWritableResource( mSubResources ) : subresource;
+ if ( resource.isEmpty() ) // canceled
+ return false;
+
+ if ( !mSilent ) {
+ QString xml = Note::journalToXML( journal );
+ kdDebug(5500) << k_funcinfo << "XML string:\n" << xml << endl;
+
+ if( !kmailUpdate( resource, sernum, xml, attachmentMimeType, journal->uid() ) ) {
+ kdError(5500) << "Communication problem in ResourceKolab::addNote()\n";
+ return false;
+ }
+ }
+
+ if ( !resource.isEmpty() && sernum != 0 ) {
+ mUidMap[ journal->uid() ] = StorageReference( resource, sernum );
+ return true;
+ }
+
+ return false;
+}
+
+bool ResourceKolab::deleteNote( KCal::Journal* journal )
+{
+ const QString uid = journal->uid();
+ if ( !mUidMap.contains( uid ) )
+ // Odd
+ return false;
+
+ if ( !mSilent ) {
+ kmailDeleteIncidence( mUidMap[ uid ].resource(),
+ mUidMap[ uid ].serialNumber() );
+ }
+ mUidMap.remove( uid );
+ manager()->deleteNote( journal );
+ mCalendar.deleteJournal( journal );
+ return true;
+}
+
+KCal::Alarm::List ResourceKolab::alarms( const QDateTime& from, const QDateTime& to )
+{
+ KCal::Alarm::List alarms;
+ KCal::Journal::List notes = mCalendar.journals();
+ KCal::Journal::List::ConstIterator note;
+ for ( note = notes.begin(); note != notes.end(); ++note )
+ {
+ QDateTime preTime = from.addSecs( -1 );
+ KCal::Alarm::List::ConstIterator it;
+ for( it = (*note)->alarms().begin(); it != (*note)->alarms().end(); ++it )
+ {
+ if ( (*it)->enabled() )
+ {
+ QDateTime dt = (*it)->nextRepetition( preTime );
+ if ( dt.isValid() && dt <= to )
+ alarms.append( *it );
+ }
+ }
+ }
+
+ return alarms;
+}
+
+void ResourceKolab::incidenceUpdated( KCal::IncidenceBase* i )
+{
+ QString subResource;
+ Q_UINT32 sernum;
+ if ( mUidMap.contains( i->uid() ) ) {
+ subResource = mUidMap[ i->uid() ].resource();
+ sernum = mUidMap[ i->uid() ].serialNumber();
+ } else { // can this happen?
+ subResource = findWritableResource( mSubResources );
+ if ( subResource.isEmpty() ) // canceled
+ return;
+ sernum = 0;
+ }
+
+ KCal::Journal* journal = dynamic_cast<KCal::Journal*>( i );
+ QString xml = Note::journalToXML( journal );
+ if( !xml.isEmpty() && kmailUpdate( subResource, sernum, xml, attachmentMimeType, journal->uid() ) )
+ mUidMap[ i->uid() ] = StorageReference( subResource, sernum );
+}
+
+/*
+ * These are the DCOP slots that KMail call to notify when something
+ * changed.
+ */
+bool ResourceKolab::fromKMailAddIncidence( const QString& type,
+ const QString& subResource,
+ Q_UINT32 sernum,
+ int format,
+ const QString& note )
+{
+ // Check if this is a note
+ if( type != kmailContentsType ) return false;
+
+ const bool silent = mSilent;
+ mSilent = true;
+ QString mimetype;
+ if ( format == KMailICalIface::StorageXML )
+ mimetype = attachmentMimeType;
+ else
+ mimetype = inlineMimeType;
+ KCal::Journal* journal = addNote( note, subResource, sernum, mimetype );
+ if ( journal )
+ manager()->registerNote( this, journal );
+ mSilent = silent;
+ return true;
+}
+
+void ResourceKolab::fromKMailDelIncidence( const QString& type,
+ const QString& /*subResource*/,
+ const QString& uid )
+{
+ // Check if this is a note
+ if( type != kmailContentsType ) return;
+
+ kdDebug(5500) << "ResourceKolab::fromKMailDelIncidence( " << type << ", " << uid
+ << " )" << endl;
+
+ const bool silent = mSilent;
+ mSilent = true;
+ KCal::Journal* j = mCalendar.journal( uid );
+ if( j )
+ deleteNote( j );
+ mSilent = silent;
+}
+
+void ResourceKolab::fromKMailRefresh( const QString& type,
+ const QString& /*subResource*/ )
+{
+ if ( type == kmailContentsType )
+ load(); // ### should call loadSubResource(subResource) probably
+}
+
+void ResourceKolab::fromKMailAddSubresource( const QString& type,
+ const QString& subResource,
+ const QString& /*label*/,
+ bool writable,
+ bool /*alarmRelevant*/ )
+{
+ if ( type != kmailContentsType )
+ // Not ours
+ return;
+
+ if ( mSubResources.contains( subResource ) )
+ // Already registered
+ return;
+
+ KConfig config( configFile() );
+ config.setGroup( configGroupName );
+
+ bool active = config.readBoolEntry( subResource, true );
+ mSubResources[ subResource ] = Kolab::SubResource( active, writable, subResource );
+ loadSubResource( subResource, attachmentMimeType );
+ emit signalSubresourceAdded( this, type, subResource );
+}
+
+void ResourceKolab::fromKMailDelSubresource( const QString& type,
+ const QString& subResource )
+{
+ if ( type != configGroupName )
+ // Not ours
+ return;
+
+ if ( !mSubResources.contains( subResource ) )
+ // Not registered
+ return;
+
+ // Ok, it's our job, and we have it here
+ mSubResources.erase( subResource );
+
+ KConfig config( configFile() );
+ config.setGroup( configGroupName );
+ config.deleteEntry( subResource );
+ config.sync();
+
+ // Make a list of all uids to remove
+ Kolab::UidMap::ConstIterator mapIt;
+ QStringList uids;
+ for ( mapIt = mUidMap.begin(); mapIt != mUidMap.end(); ++mapIt )
+ if ( mapIt.data().resource() == subResource )
+ // We have a match
+ uids << mapIt.key();
+
+ // Finally delete all the incidences
+ if ( !uids.isEmpty() ) {
+ const bool silent = mSilent;
+ mSilent = true;
+ QStringList::ConstIterator it;
+ for ( it = uids.begin(); it != uids.end(); ++it ) {
+ KCal::Journal* j = mCalendar.journal( *it );
+ if( j )
+ deleteNote( j );
+ }
+ mSilent = silent;
+ }
+
+ emit signalSubresourceRemoved( this, type, subResource );
+}
+
+void ResourceKolab::fromKMailAsyncLoadResult( const QMap<Q_UINT32, QString>& map,
+ const QString& type,
+ const QString& folder )
+{
+ // We are only interested in notes
+ if ( ( type != attachmentMimeType ) && ( type != inlineMimeType ) ) return;
+ // Populate with the new entries
+ const bool silent = mSilent;
+ mSilent = true;
+ QString mimetype;
+ if ( kmailStorageFormat( folder ) == KMailICalIface::StorageXML )
+ mimetype = attachmentMimeType;
+ else
+ mimetype = inlineMimeType;
+ for( QMap<Q_UINT32, QString>::ConstIterator it = map.begin(); it != map.end(); ++it ) {
+ KCal::Journal* journal = addNote( it.data(), folder, it.key(), mimetype );
+ if ( !journal )
+ kdDebug(5500) << "loading note " << it.key() << " failed" << endl;
+ else
+ manager()->registerNote( this, journal );
+ }
+ mSilent = silent;
+}
+
+
+QStringList ResourceKolab::subresources() const
+{
+ return mSubResources.keys();
+}
+
+bool ResourceKolab::subresourceActive( const QString& res ) const
+{
+ if ( mSubResources.contains( res ) ) {
+ return mSubResources[ res ].active();
+ }
+
+ // Safe default bet:
+ kdDebug(5650) << "subresourceActive( " << res << " ): Safe bet\n";
+
+ return true;
+}
+
+
+#include "resourcekolab.moc"
diff --git a/kresources/kolab/knotes/resourcekolab.h b/kresources/kolab/knotes/resourcekolab.h
new file mode 100644
index 00000000..44ce480b
--- /dev/null
+++ b/kresources/kolab/knotes/resourcekolab.h
@@ -0,0 +1,129 @@
+/*
+ This file is part of the kolab resource - the implementation of the
+ Kolab storage format. See www.kolab.org for documentation on this.
+
+ Copyright (c) 2004 Bo Thorsen <bo@sonofthor.dk>
+
+ 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.
+
+ In addition, as a special exception, the copyright holders give
+ permission to link the code of this program with any edition of
+ the Qt library by Trolltech AS, Norway (or with modified versions
+ of Qt that use the same license as Qt), and distribute linked
+ combinations including the two. You must obey the GNU General
+ Public License in all respects for all of the code used other than
+ Qt. If you modify this file, you may extend this exception to
+ your version of the file, but you are not obligated to do so. If
+ you do not wish to do so, delete this exception statement from
+ your version.
+*/
+
+#ifndef KNOTES_RESOURCEKOLAB_H
+#define KNOTES_RESOURCEKOLAB_H
+
+#include <resourcenotes.h>
+#include <libkcal/incidencebase.h>
+#include <libkcal/calendarlocal.h>
+#include "../shared/resourcekolabbase.h"
+#include "../shared/subresource.h"
+#include <kdepimmacros.h>
+
+
+namespace Kolab {
+
+/**
+ * This class implements a KNotes resource that keeps its
+ * addresses in an IMAP folder in KMail (or other conforming email
+ * clients).
+ */
+class KDE_EXPORT ResourceKolab : public ResourceNotes,
+ public KCal::IncidenceBase::Observer,
+ public ResourceKolabBase
+{
+ Q_OBJECT
+
+public:
+ ResourceKolab( const KConfig* );
+ virtual ~ResourceKolab();
+
+ /// Load resource data.
+ bool load();
+
+ /// Save resource data.
+ bool save();
+
+ /// Open the notes resource.
+ bool doOpen();
+ /// Close the notes resource.
+ void doClose();
+
+ bool addNote( KCal::Journal* );
+
+ bool deleteNote( KCal::Journal* );
+
+ KCal::Alarm::List alarms( const QDateTime& from, const QDateTime& to );
+
+ /// Reimplemented from IncidenceBase::Observer to know when a note was changed
+ void incidenceUpdated( KCal::IncidenceBase* );
+
+ /// The ResourceKolabBase methods called by KMail
+ bool fromKMailAddIncidence( const QString& type, const QString& resource,
+ Q_UINT32 sernum, int format, const QString& note );
+ void fromKMailDelIncidence( const QString& type, const QString& resource,
+ const QString& uid );
+ void fromKMailRefresh( const QString& type, const QString& resource );
+
+ /// Listen to KMail changes in the amount of sub resources
+ void fromKMailAddSubresource( const QString& type, const QString& resource,
+ const QString& label, bool writable,
+ bool alarmRelevant );
+ void fromKMailDelSubresource( const QString& type, const QString& resource );
+
+ void fromKMailAsyncLoadResult( const QMap<Q_UINT32, QString>& map,
+ const QString& type,
+ const QString& folder );
+
+ /** Return the list of subresources. */
+ QStringList subresources() const;
+
+ /** Is this subresource active? */
+ bool subresourceActive( const QString& ) const;
+
+signals:
+ void signalSubresourceAdded( Resource*, const QString&, const QString& );
+ void signalSubresourceRemoved( Resource*, const QString&, const QString& );
+
+private:
+ bool addNote( KCal::Journal* journal, const QString& resource,
+ Q_UINT32 sernum );
+ KCal::Journal* addNote( const QString& data, const QString& subresource,
+ Q_UINT32 sernum, const QString &mimetype );
+
+ bool loadSubResource( const QString& resource, const QString& mimetype );
+
+ QString configFile() const {
+ return ResourceKolabBase::configFile( "knotes" );
+ }
+
+ KCal::CalendarLocal mCalendar;
+
+ // The list of subresources
+ Kolab::ResourceMap mSubResources;
+};
+
+}
+
+#endif // KNOTES_RESOURCEKOLAB_H
diff --git a/kresources/kolab/knotes/resourcekolab_plugin.cpp b/kresources/kolab/knotes/resourcekolab_plugin.cpp
new file mode 100644
index 00000000..cd97ecf6
--- /dev/null
+++ b/kresources/kolab/knotes/resourcekolab_plugin.cpp
@@ -0,0 +1,50 @@
+/*
+ This file is part of libkabc and/or kaddressbook.
+ Copyright (c) 2002 - 2004 Klarlvdalens Datakonsult AB
+ <info@klaralvdalens-datakonsult.se>
+
+ 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.
+
+ In addition, as a special exception, the copyright holders give
+ permission to link the code of this program with any edition of
+ the Qt library by Trolltech AS, Norway (or with modified versions
+ of Qt that use the same license as Qt), and distribute linked
+ combinations including the two. You must obey the GNU General
+ Public License in all respects for all of the code used other than
+ Qt. If you modify this file, you may extend this exception to
+ your version of the file, but you are not obligated to do so. If
+ you do not wish to do so, delete this exception statement from
+ your version.
+*/
+
+#include "resourcekolab.h"
+
+class KolabFactory : public KRES::PluginFactoryBase
+{
+public:
+ KRES::Resource *resource( const KConfig *config )
+ {
+ return new Kolab::ResourceKolab( config );
+ }
+
+ KRES::ConfigWidget *configWidget( QWidget* )
+ {
+ return 0;
+ }
+};
+
+K_EXPORT_COMPONENT_FACTORY(knotes_kolab,KolabFactory())
+