diff options
Diffstat (limited to 'tderesources/kolab/knotes')
-rw-r--r-- | tderesources/kolab/knotes/CMakeLists.txt | 55 | ||||
-rw-r--r-- | tderesources/kolab/knotes/Makefile.am | 29 | ||||
-rw-r--r-- | tderesources/kolab/knotes/kolabresource.desktop | 52 | ||||
-rw-r--r-- | tderesources/kolab/knotes/note.cpp | 229 | ||||
-rw-r--r-- | tderesources/kolab/knotes/note.h | 111 | ||||
-rw-r--r-- | tderesources/kolab/knotes/resourcekolab.cpp | 463 | ||||
-rw-r--r-- | tderesources/kolab/knotes/resourcekolab.h | 133 | ||||
-rw-r--r-- | tderesources/kolab/knotes/resourcekolab_plugin.cpp | 50 |
8 files changed, 1122 insertions, 0 deletions
diff --git a/tderesources/kolab/knotes/CMakeLists.txt b/tderesources/kolab/knotes/CMakeLists.txt new file mode 100644 index 000000000..8e10f3e52 --- /dev/null +++ b/tderesources/kolab/knotes/CMakeLists.txt @@ -0,0 +1,55 @@ +################################################# +# +# (C) 2010-2011 Serghei Amelian +# serghei (DOT) amelian (AT) gmail.com +# +# Improvements and feedback are welcome +# +# This file is released under GPL >= 2 +# +################################################# + +include_directories( + ${CMAKE_CURRENT_BINARY_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}/../shared + ${CMAKE_SOURCE_DIR} + ${CMAKE_SOURCE_DIR}/knotes + ${CMAKE_SOURCE_DIR}/libtdepim + ${TDE_INCLUDE_DIR} + ${TQT_INCLUDE_DIRS} +) + +link_directories( + ${TQT_LIBRARY_DIRS} +) + + +##### other data ################################ + +install( + FILES kolabresource.desktop + DESTINATION ${SERVICES_INSTALL_DIR}/tderesources/knotes ) + +install( + FILES ${CMAKE_CURRENT_SOURCE_DIR}/../uninstall.desktop + DESTINATION ${SERVICES_INSTALL_DIR}/tderesources/knotes + RENAME imap.desktop ) + + +##### knotes_kolab (module) ##################### + +tde_add_kpart( knotes_kolab AUTOMOC + SOURCES resourcekolab_plugin.cpp + LINK knoteskolab-shared + DESTINATION ${PLUGIN_INSTALL_DIR} +) + + +##### knoteskolab (shared) ###################### + +tde_add_library( knoteskolab SHARED AUTOMOC + SOURCES resourcekolab.cpp note.cpp + VERSION 0.0.0 + LINK resourcekolabshared-static kgroupwarebase-shared knotes-shared + DESTINATION ${LIB_INSTALL_DIR} +) diff --git a/tderesources/kolab/knotes/Makefile.am b/tderesources/kolab/knotes/Makefile.am new file mode 100644 index 000000000..54337ce89 --- /dev/null +++ b/tderesources/kolab/knotes/Makefile.am @@ -0,0 +1,29 @@ +METASOURCES = AUTO + +INCLUDES = -I$(top_srcdir)/tderesources/kolab/shared \ + -I$(top_srcdir) -I$(top_srcdir)/knotes -I$(top_builddir)/libtdepim $(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)/tderesources/kolab/shared/libresourcekolabshared.la \ + $(top_builddir)/knotes/libknotesresources.la \ + $(top_builddir)/libkcal/libkcal.la \ + -ltderesources -ltdeprint + +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)/tderesources/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/tderesources/kolab/knotes/kolabresource.desktop b/tderesources/kolab/knotes/kolabresource.desktop new file mode 100644 index 000000000..16f48e45a --- /dev/null +++ b/tderesources/kolab/knotes/kolabresource.desktop @@ -0,0 +1,52 @@ +[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[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-TDE-Library=knotes_kolab +Type=Service +ServiceTypes=KResources/Plugin +X-TDE-ResourceFamily=notes +X-TDE-ResourceType=imap diff --git a/tderesources/kolab/knotes/note.cpp b/tderesources/kolab/knotes/note.cpp new file mode 100644 index 000000000..7df5b26b3 --- /dev/null +++ b/tderesources/kolab/knotes/note.cpp @@ -0,0 +1,229 @@ +/* + 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 TQt library by Trolltech AS, Norway (or with modified versions + of TQt that use the same license as TQt), 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 + TQt. 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 TQString& xml ) +{ + Note note; + note.load( xml ); + KCal::Journal* journal = new KCal::Journal(); + note.saveTo( journal ); + return journal; +} + +TQString 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 TQString& summary ) +{ + mSummary = summary; +} + +TQString Note::summary() const +{ + return mSummary; +} + +void Note::setBackgroundColor( const TQColor& bgColor ) +{ + mBackgroundColor = bgColor; +} + +TQColor Note::backgroundColor() const +{ + return mBackgroundColor; +} + +void Note::setForegroundColor( const TQColor& fgColor ) +{ + mForegroundColor = fgColor; +} + +TQColor Note::foregroundColor() const +{ + return mForegroundColor; +} + +void Note::setRichText( bool richText ) +{ + mRichText = richText; +} + +bool Note::richText() const +{ + return mRichText; +} + +bool Note::loadAttribute( TQDomElement& element ) +{ + TQString 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( TQDomElement& element ) const +{ + // Save the base class elements + KolabBase::saveAttributes( element ); + + // Save the elements +#if 0 + TQDomComment c = element.ownerDocument().createComment( "Note specific attributes" ); + element.appendChild( c ); +#endif + + writeString( element, "summary", summary() ); + if ( foregroundColor().isValid() ) + writeString( element, "foreground-color", colorToString( foregroundColor() ) ); + if ( backgroundColor().isValid() ) + writeString( element, "background-color", colorToString( backgroundColor() ) ); + writeString( element, "knotes-richtext", mRichText ? "true" : "false" ); + + return true; +} + + +bool Note::loadXML( const TQDomDocument& document ) +{ + TQDomElement top = document.documentElement(); + + if ( top.tagName() != "note" ) { + tqWarning( "XML error: Top tag was %s instead of the expected note", + top.tagName().ascii() ); + return false; + } + + for ( TQDomNode n = top.firstChild(); !n.isNull(); n = n.nextSibling() ) { + if ( n.isComment() ) + continue; + if ( n.isElement() ) { + TQDomElement 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; +} + +TQString Note::saveXML() const +{ + TQDomDocument document = domTree(); + TQDomElement 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 ); + + setSummary( journal->summary() ); + + TQString property = journal->customProperty( "KNotes", "BgColor" ); + if ( !property.isNull() ) { + setBackgroundColor( property ); + } else { + setBackgroundColor( "yellow" ); + } + property = journal->customProperty( "KNotes", "FgColor" ); + if ( !property.isNull() ) { + setForegroundColor( property ); + } else { + setForegroundColor( "black" ); + } + + property = journal->customProperty( "KNotes", "RichText" ); + if ( !property.isNull() ) { + setRichText( property == "true" ? true : false ); + } else { + setRichText( "false" ); + } +} + +void Note::saveTo( KCal::Journal* journal ) +{ + KolabBase::saveTo( journal ); + + // TODO: background and foreground + journal->setSummary( summary() ); + if ( foregroundColor().isValid() ) + journal->setCustomProperty( "KNotes", "FgColor", + colorToString( foregroundColor() ) ); + if ( backgroundColor().isValid() ) + journal->setCustomProperty( "KNotes", "BgColor", + colorToString( backgroundColor() ) ); + journal->setCustomProperty( "KNotes", "RichText", + richText() ? "true" : "false" ); +} + +TQString Note::productID() const +{ + return TQString( "KNotes %1, Kolab resource" ).arg( KNOTES_VERSION ); +} diff --git a/tderesources/kolab/knotes/note.h b/tderesources/kolab/knotes/note.h new file mode 100644 index 000000000..d61a2009e --- /dev/null +++ b/tderesources/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 TQt library by Trolltech AS, Norway (or with modified versions + of TQt that use the same license as TQt), 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 + TQt. 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 TQDomElement; + +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 TQString& xml ); + + /// Use this to get an xml string describing this journal entry + static TQString journalToXML( KCal::Journal* ); + + /// Create a note object and + explicit Note( KCal::Journal* journal = 0 ); + virtual ~Note(); + + void saveTo( KCal::Journal* journal ); + + virtual TQString type() const { return "Note"; } + + virtual void setSummary( const TQString& summary ); + virtual TQString summary() const; + + virtual void setBackgroundColor( const TQColor& bgColor ); + virtual TQColor backgroundColor() const; + + virtual void setForegroundColor( const TQColor& fgColor ); + virtual TQColor foregroundColor() const; + + virtual void setRichText( bool richText ); + virtual bool richText() const; + + // Load the attributes of this class + virtual bool loadAttribute( TQDomElement& ); + + // Save the attributes of this class + virtual bool saveAttributes( TQDomElement& ) const; + + // Load this note by reading the XML file + virtual bool loadXML( const TQDomDocument& xml ); + + // Serialize this note to an XML string + virtual TQString 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; + + TQString productID() const; + + TQString mSummary; + TQColor mBackgroundColor; + TQColor mForegroundColor; + bool mRichText; +}; + +} + +#endif // KOLAB_NOTE_H diff --git a/tderesources/kolab/knotes/resourcekolab.cpp b/tderesources/kolab/knotes/resourcekolab.cpp new file mode 100644 index 000000000..a28a51b27 --- /dev/null +++ b/tderesources/kolab/knotes/resourcekolab.cpp @@ -0,0 +1,463 @@ +/* + 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 TQt library by Trolltech AS, Norway (or with modified versions + of TQt that use the same license as TQt), 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 + TQt. 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> +#include <klocale.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 TDEConfig *config ) + : ResourceNotes( config ), ResourceKolabBase( "ResourceKolab-KNotes" ), + mCalendar( TQString::fromLatin1("UTC") ) +{ + if ( !config ) { + setResourceName( i18n( "Kolab Server" ) ); + } + setType( "imap" ); +} + +ResourceKolab::~ResourceKolab() +{ +} + +bool ResourceKolab::doOpen() +{ + TDEConfig config( configFile() ); + config.setGroup( configGroupName ); + + // Get the list of Notes folders from KMail + TQValueList<KMailICalIface::SubResource> subResources; + if ( !kmailSubresources( subResources, kmailContentsType ) ) + return false; + + // Make the resource map from the folder list + TQValueList<KMailICalIface::SubResource>::ConstIterator it; + mSubResources.clear(); + for ( it = subResources.constBegin(); it != subResources.constEnd(); ++it ) { + const TQString subResource = (*it).location; + const bool active = config.readBoolEntry( subResource, true ); + mSubResources[ subResource ] = Kolab::SubResource( active, (*it).writable, (*it).label ); + } + + return true; +} + +void ResourceKolab::doClose() +{ + TDEConfig config( configFile() ); + config.setGroup( configGroupName ); + Kolab::ResourceMap::ConstIterator it; + for ( it = mSubResources.constBegin(); it != mSubResources.constEnd(); ++it ) + config.writeEntry( it.key(), it.data().active() ); +} + +bool ResourceKolab::loadSubResource( const TQString& subResource, + const TQString &mimetype ) +{ + // Get the list of journals + int count = 0; + if ( !kmailIncidencesCount( count, mimetype, subResource ) ) { + kdError() << "Communication problem in ResourceKolab::load()\n"; + return false; + } + + TQMap<TQ_UINT32, TQString> 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; + TQMap<TQ_UINT32, TQString>::ConstIterator it; + for ( it = lst.constBegin(); it != lst.constEnd(); ++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.constBegin(); itR != mSubResources.constEnd(); ++itR ) { + if ( !itR.data().active() ) + // This subResource is disabled + continue; + + TQString 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, TQString(), 0 ); +} + +KCal::Journal* ResourceKolab::addNote( const TQString& data, const TQString& subresource, + TQ_UINT32 sernum, const TQString &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 ); + + bool addedOk = journal && + !mUidMap.contains( journal->uid() ) && + addNote( journal, subresource, sernum ); + + // for debugging + if ( journal && mUidMap.contains( journal->uid() ) ) { + kdDebug(5500) << "mUidMap already contains " << journal->uid() << endl; + } + + if ( !addedOk ) { + delete journal; + journal = 0; + } + + return journal; +} + +bool ResourceKolab::addNote( KCal::Journal *journal, const TQString &subresource, TQ_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(); + if ( !mCalendar.addJournal( journal ) ) { + return false; + } + + TQString resource = newNote ? findWritableResource( Kolab::Notes, mSubResources ) : subresource; + if ( resource.isEmpty() ) { + // canceled + return false; + } + + if ( !mSilent ) { + TQString 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 TQString uid = journal->uid(); + if ( !mUidMap.contains( uid ) ) + // Odd + return false; + + if ( !mSilent ) { + kmailDeleteIncidence( mUidMap[ uid ].resource(), + mUidMap[ uid ].serialNumber() ); + } + mUidMap.remove( uid ); + return mCalendar.deleteJournal( journal ); +} + +KCal::Alarm::List ResourceKolab::alarms( const TQDateTime& from, const TQDateTime& to ) +{ + KCal::Alarm::List alarms; + KCal::Journal::List notes = mCalendar.journals(); + KCal::Journal::List::ConstIterator note; + for ( note = notes.begin(); note != notes.end(); ++note ) + { + TQDateTime preTime = from.addSecs( -1 ); + KCal::Alarm::List::ConstIterator it; + for( it = (*note)->alarms().constBegin(); it != (*note)->alarms().constEnd(); ++it ) + { + if ( (*it)->enabled() ) + { + TQDateTime dt = (*it)->nextRepetition( preTime ); + if ( dt.isValid() && dt <= to ) + alarms.append( *it ); + } + } + } + + return alarms; +} + +void ResourceKolab::incidenceUpdated( KCal::IncidenceBase* i ) +{ + TQString subResource; + TQ_UINT32 sernum; + if ( mUidMap.contains( i->uid() ) ) { + subResource = mUidMap[ i->uid() ].resource(); + sernum = mUidMap[ i->uid() ].serialNumber(); + } else { // can this happen? + subResource = findWritableResource( Kolab::Notes, mSubResources ); + if ( subResource.isEmpty() ) // canceled + return; + sernum = 0; + } + + KCal::Journal* journal = dynamic_cast<KCal::Journal*>( i ); + TQString 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 TQString& type, + const TQString& subResource, + TQ_UINT32 sernum, + int format, + const TQString& note ) +{ + // Check if this is a note + if( type != kmailContentsType ) return false; + + const bool silent = mSilent; + mSilent = true; + TQString 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 TQString& type, + const TQString& /*subResource*/, + const TQString& 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 ) { + if ( deleteNote( j ) ) { + manager()->deleteNote( j ); + } + } + mSilent = silent; +} + +void ResourceKolab::fromKMailRefresh( const TQString& type, + const TQString& /*subResource*/ ) +{ + if ( type == kmailContentsType ) + load(); // ### should call loadSubResource(subResource) probably +} + +void ResourceKolab::fromKMailAddSubresource( const TQString& type, + const TQString& subResource, + const TQString& /*label*/, + bool writable, + bool /*alarmRelevant*/ ) +{ + if ( type != kmailContentsType ) + // Not ours + return; + + if ( mSubResources.contains( subResource ) ) + // Already registered + return; + + TDEConfig 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 TQString& type, + const TQString& 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 ); + + TDEConfig config( configFile() ); + config.setGroup( configGroupName ); + config.deleteEntry( subResource ); + config.sync(); + + // Make a list of all uids to remove + Kolab::UidMap::ConstIterator mapIt; + TQStringList uids; + for ( mapIt = mUidMap.constBegin(); mapIt != mUidMap.constEnd(); ++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; + TQStringList::ConstIterator it; + for ( it = uids.constBegin(); it != uids.constEnd(); ++it ) { + KCal::Journal* j = mCalendar.journal( *it ); + if( j ) + deleteNote( j ); + } + mSilent = silent; + } + + emit signalSubresourceRemoved( this, type, subResource ); +} + +void ResourceKolab::fromKMailAsyncLoadResult( const TQMap<TQ_UINT32, TQString>& map, + const TQString& type, + const TQString& folder ) +{ + // We are only interested in notes + if ( ( type != attachmentMimeType ) && ( type != inlineMimeType ) ) return; + // Populate with the new entries + const bool silent = mSilent; + mSilent = true; + TQString mimetype; + if ( kmailStorageFormat( folder ) == KMailICalIface::StorageXML ) + mimetype = attachmentMimeType; + else + mimetype = inlineMimeType; + for( TQMap<TQ_UINT32, TQString>::ConstIterator it = map.constBegin(); it != map.constEnd(); ++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; +} + + +TQStringList ResourceKolab::subresources() const +{ + return mSubResources.keys(); +} + +bool ResourceKolab::subresourceActive( const TQString& res ) const +{ + if ( mSubResources.contains( res ) ) { + return mSubResources[ res ].active(); + } + + // Safe default bet: + kdDebug(5650) << "subresourceActive( " << res << " ): Safe bet\n"; + + return true; +} + +bool ResourceKolab::subresourceWritable( const TQString& res ) const +{ + if ( mSubResources.contains( res ) ) { + return mSubResources[ res ].writable(); + } + + // Safe default bet: + return false; +} + +#include "resourcekolab.moc" diff --git a/tderesources/kolab/knotes/resourcekolab.h b/tderesources/kolab/knotes/resourcekolab.h new file mode 100644 index 000000000..fb0d191b9 --- /dev/null +++ b/tderesources/kolab/knotes/resourcekolab.h @@ -0,0 +1,133 @@ +/* + 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 TQt library by Trolltech AS, Norway (or with modified versions + of TQt that use the same license as TQt), 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 + TQt. 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 <tdepimmacros.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 TDEConfig* ); + 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 TQDateTime& from, const TQDateTime& 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 TQString& type, const TQString& resource, + TQ_UINT32 sernum, int format, const TQString& note ); + void fromKMailDelIncidence( const TQString& type, const TQString& resource, + const TQString& uid ); + void fromKMailRefresh( const TQString& type, const TQString& resource ); + + /// Listen to KMail changes in the amount of sub resources + void fromKMailAddSubresource( const TQString& type, const TQString& resource, + const TQString& label, bool writable, + bool alarmRelevant ); + void fromKMailDelSubresource( const TQString& type, const TQString& resource ); + + void fromKMailAsyncLoadResult( const TQMap<TQ_UINT32, TQString>& map, + const TQString& type, + const TQString& folder ); + + /** Return the list of subresources. */ + TQStringList subresources() const; + + /** Is this subresource active? */ + bool subresourceActive( const TQString& ) const; + + /** Is this subresource writable? */ + bool subresourceWritable( const TQString& ) const; + +signals: + void signalSubresourceAdded( Resource*, const TQString&, const TQString& ); + void signalSubresourceRemoved( Resource*, const TQString&, const TQString& ); + +private: + bool addNote( KCal::Journal* journal, const TQString& resource, + TQ_UINT32 sernum ); + KCal::Journal* addNote( const TQString& data, const TQString& subresource, + TQ_UINT32 sernum, const TQString &mimetype ); + + bool loadSubResource( const TQString& resource, const TQString& mimetype ); + + TQString configFile() const { + return ResourceKolabBase::configFile( "knotes" ); + } + + KCal::CalendarLocal mCalendar; + + // The list of subresources + Kolab::ResourceMap mSubResources; +}; + +} + +#endif // KNOTES_RESOURCEKOLAB_H diff --git a/tderesources/kolab/knotes/resourcekolab_plugin.cpp b/tderesources/kolab/knotes/resourcekolab_plugin.cpp new file mode 100644 index 000000000..f589986cb --- /dev/null +++ b/tderesources/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 TQt library by Trolltech AS, Norway (or with modified versions + of TQt that use the same license as TQt), 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 + TQt. 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 TDEConfig *config ) + { + return new Kolab::ResourceKolab( config ); + } + + KRES::ConfigWidget *configWidget( TQWidget* ) + { + return 0; + } +}; + +K_EXPORT_COMPONENT_FACTORY(knotes_kolab,KolabFactory()) + |