summaryrefslogtreecommitdiffstats
path: root/kontact/plugins/knotes
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commit460c52653ab0dcca6f19a4f492ed2c5e4e963ab0 (patch)
tree67208f7c145782a7e90b123b982ca78d88cc2c87 /kontact/plugins/knotes
downloadtdepim-460c52653ab0dcca6f19a4f492ed2c5e4e963ab0.tar.gz
tdepim-460c52653ab0dcca6f19a4f492ed2c5e4e963ab0.zip
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdepim@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kontact/plugins/knotes')
-rw-r--r--kontact/plugins/knotes/Makefile.am23
-rw-r--r--kontact/plugins/knotes/knotes_part.cpp413
-rw-r--r--kontact/plugins/knotes/knotes_part.h101
-rw-r--r--kontact/plugins/knotes/knotes_part.rc23
-rw-r--r--kontact/plugins/knotes/knotes_part_p.h188
-rw-r--r--kontact/plugins/knotes/knotes_plugin.cpp97
-rw-r--r--kontact/plugins/knotes/knotes_plugin.h58
-rw-r--r--kontact/plugins/knotes/knotesplugin.desktop95
-rw-r--r--kontact/plugins/knotes/knotetip.cpp227
-rw-r--r--kontact/plugins/knotes/knotetip.h68
-rw-r--r--kontact/plugins/knotes/summarywidget.cpp164
-rw-r--r--kontact/plugins/knotes/summarywidget.h71
12 files changed, 1528 insertions, 0 deletions
diff --git a/kontact/plugins/knotes/Makefile.am b/kontact/plugins/knotes/Makefile.am
new file mode 100644
index 000000000..4a3b1710f
--- /dev/null
+++ b/kontact/plugins/knotes/Makefile.am
@@ -0,0 +1,23 @@
+INCLUDES = -I$(top_srcdir)/kontact/interfaces -I$(top_srcdir) $(all_includes)
+
+kde_module_LTLIBRARIES = libkontact_knotesplugin.la
+libkontact_knotesplugin_la_LDFLAGS = $(all_libraries) $(KDE_PLUGIN)
+libkontact_knotesplugin_la_LIBADD = $(top_builddir)/kontact/interfaces/libkpinterfaces.la \
+ $(LIB_KPARTS) $(top_builddir)/libkdepim/libkdepim.la \
+ $(top_builddir)/libkcal/libkcal.la -lkresources -lkdeprint \
+ $(top_builddir)/knotes/libknotesresources.la \
+ $(top_builddir)/knotes/libknoteseditor.la \
+ $(top_builddir)/knotes/libknotesprinting.la
+
+libkontact_knotesplugin_la_SOURCES = knotes_plugin.cpp knotes_part.cpp summarywidget.cpp \
+ knotetip.cpp KNotesIface.skel
+
+METASOURCES = AUTO
+
+servicedir = $(kde_servicesdir)/kontact
+service_DATA = knotesplugin.desktop
+
+partdir = $(kde_datadir)/knotes
+part_DATA = knotes_part.rc
+
+KNotesIface_DIR = $(top_srcdir)/knotes
diff --git a/kontact/plugins/knotes/knotes_part.cpp b/kontact/plugins/knotes/knotes_part.cpp
new file mode 100644
index 000000000..5bd160d1d
--- /dev/null
+++ b/kontact/plugins/knotes/knotes_part.cpp
@@ -0,0 +1,413 @@
+/*
+ This file is part of the KDE project
+ Copyright (C) 2002-2003 Daniel Molkentin <molkentin@kde.org>
+ Copyright (C) 2004-2006 Michael Brade <brade@kde.org>
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This program 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
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; see the file COPYING. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include <qpopupmenu.h>
+#include <qclipboard.h>
+
+#include <kapplication.h>
+#include <kdebug.h>
+#include <kaction.h>
+#include <kmessagebox.h>
+
+#include <libkdepim/infoextension.h>
+#include <libkdepim/sidebarextension.h>
+
+#include "knotes/knoteprinter.h"
+#include "knotes/resourcemanager.h"
+
+#include "knotes_part.h"
+#include "knotes_part_p.h"
+#include "knotetip.h"
+
+
+KNotesPart::KNotesPart( QObject *parent, const char *name )
+ : DCOPObject( "KNotesIface" ), KParts::ReadOnlyPart( parent, name ),
+ mNotesView( new KNotesIconView() ),
+ mNoteTip( new KNoteTip( mNotesView ) ),
+ mNoteEditDlg( 0 ),
+ mManager( new KNotesResourceManager() )
+{
+ mNoteList.setAutoDelete( true );
+
+ setInstance( new KInstance( "knotes" ) );
+
+ // create the actions
+ new KAction( i18n( "&New" ), "knotes", CTRL+Key_N, this, SLOT( newNote() ),
+ actionCollection(), "file_new" );
+ new KAction( i18n( "Rename..." ), "text", this, SLOT( renameNote() ),
+ actionCollection(), "edit_rename" );
+ new KAction( i18n( "Delete" ), "editdelete", Key_Delete, this, SLOT( killSelectedNotes() ),
+ actionCollection(), "edit_delete" );
+ new KAction( i18n( "Print Selected Notes..." ), "print", CTRL+Key_P, this, SLOT( printSelectedNotes() ),
+ actionCollection(), "print_note" );
+
+ // TODO icons: s/editdelete/knotes_delete/ or the other way round in knotes
+
+ // set the view up
+ mNotesView->setSelectionMode( QIconView::Extended );
+ mNotesView->setItemsMovable( false );
+ mNotesView->setResizeMode( QIconView::Adjust );
+ mNotesView->setAutoArrange( true );
+ mNotesView->setSorting( true );
+
+ connect( mNotesView, SIGNAL( executed( QIconViewItem* ) ),
+ this, SLOT( editNote( QIconViewItem* ) ) );
+ connect( mNotesView, SIGNAL( returnPressed( QIconViewItem* ) ),
+ this, SLOT( editNote( QIconViewItem* ) ) );
+ connect( mNotesView, SIGNAL( itemRenamed( QIconViewItem* ) ),
+ this, SLOT( renamedNote( QIconViewItem* ) ) );
+ connect( mNotesView, SIGNAL( contextMenuRequested( QIconViewItem*, const QPoint& ) ),
+ this, SLOT( popupRMB( QIconViewItem*, const QPoint& ) ) );
+ connect( mNotesView, SIGNAL( onItem( QIconViewItem* ) ),
+ this, SLOT( slotOnItem( QIconViewItem* ) ) );
+ connect( mNotesView, SIGNAL( onViewport() ),
+ this, SLOT( slotOnViewport() ) );
+ connect( mNotesView, SIGNAL( currentChanged( QIconViewItem* ) ),
+ this, SLOT( slotOnCurrentChanged( QIconViewItem* ) ) );
+
+ slotOnCurrentChanged( 0 );
+
+ new KParts::SideBarExtension( mNotesView, this, "NotesSideBarExtension" );
+
+ setWidget( mNotesView );
+ setXMLFile( "knotes_part.rc" );
+
+ // connect the resource manager
+ connect( mManager, SIGNAL( sigRegisteredNote( KCal::Journal* ) ),
+ this, SLOT( createNote( KCal::Journal* ) ) );
+ connect( mManager, SIGNAL( sigDeregisteredNote( KCal::Journal* ) ),
+ this, SLOT( killNote( KCal::Journal* ) ) );
+
+ // read the notes
+ mManager->load();
+}
+
+KNotesPart::~KNotesPart()
+{
+ delete mNoteTip;
+ mNoteTip = 0;
+
+ delete mManager;
+ mManager = 0;
+}
+
+void KNotesPart::printSelectedNotes()
+{
+ QValueList<KCal::Journal*> journals;
+
+ for ( QIconViewItem *it = mNotesView->firstItem(); it; it = it->nextItem() ) {
+ if ( it->isSelected() ) {
+ journals.append( static_cast<KNotesIconViewItem *>( it )->journal() );
+ }
+ }
+
+ if ( journals.isEmpty() ) {
+ KMessageBox::information( mNotesView, i18n("To print notes, first select the notes to print from the list."), i18n("Print Notes") );
+ return;
+ }
+
+ KNotePrinter printer;
+ printer.printNotes(journals );
+
+#if 0
+ QString content;
+ if ( m_editor->textFormat() == PlainText )
+ content = QStyleSheet::convertFromPlainText( m_editor->text() );
+ else
+ content = m_editor->text();
+
+ KNotePrinter printer;
+ printer.setMimeSourceFactory( m_editor->mimeSourceFactory() );
+ //printer.setFont( m_config->font() );
+ //printer.setContext( m_editor->context() );
+ //printer.setStyleSheet( m_editor->styleSheet() );
+ printer.setColorGroup( colorGroup() );
+ printer.printNote( , content );
+#endif
+}
+
+bool KNotesPart::openFile()
+{
+ return false;
+}
+
+
+// public KNotes DCOP interface implementation
+
+QString KNotesPart::newNote( const QString& name, const QString& text )
+{
+ // create the new note
+ KCal::Journal *journal = new KCal::Journal();
+
+ // new notes have the current date/time as title if none was given
+ if ( !name.isEmpty() )
+ journal->setSummary( name );
+ else
+ journal->setSummary( KGlobal::locale()->formatDateTime( QDateTime::currentDateTime() ) );
+
+ // the body of the note
+ journal->setDescription( text );
+
+
+
+ // Edit the new note if text is empty
+ if ( text.isNull() )
+ {
+ if ( !mNoteEditDlg )
+ mNoteEditDlg = new KNoteEditDlg( widget() );
+
+ mNoteEditDlg->setTitle( journal->summary() );
+ mNoteEditDlg->setText( journal->description() );
+
+ if ( mNoteEditDlg->exec() == QDialog::Accepted )
+ {
+ journal->setSummary( mNoteEditDlg->title() );
+ journal->setDescription( mNoteEditDlg->text() );
+ }
+ else
+ {
+ delete journal;
+ return "";
+ }
+ }
+
+ mManager->addNewNote( journal );
+ mManager->save();
+
+ KNotesIconViewItem *note = mNoteList[ journal->uid() ];
+ mNotesView->ensureItemVisible( note );
+ mNotesView->setCurrentItem( note );
+
+ return journal->uid();
+}
+
+QString KNotesPart::newNoteFromClipboard( const QString& name )
+{
+ const QString& text = KApplication::clipboard()->text();
+ return newNote( name, text );
+}
+
+void KNotesPart::killNote( const QString& id )
+{
+ killNote( id, false );
+}
+
+void KNotesPart::killNote( const QString& id, bool force )
+{
+ KNotesIconViewItem *note = mNoteList[ id ];
+
+ if ( note &&
+ ( (!force && KMessageBox::warningContinueCancelList( mNotesView,
+ i18n( "Do you really want to delete this note?" ),
+ mNoteList[ id ]->text(), i18n( "Confirm Delete" ),
+ KStdGuiItem::del() ) == KMessageBox::Continue)
+ || force )
+ )
+ {
+ mManager->deleteNote( mNoteList[id]->journal() );
+ mManager->save();
+ }
+}
+
+QString KNotesPart::name( const QString& id ) const
+{
+ KNotesIconViewItem *note = mNoteList[ id ];
+ if ( note )
+ return note->text();
+ else
+ return QString::null;
+}
+
+QString KNotesPart::text( const QString& id ) const
+{
+ KNotesIconViewItem *note = mNoteList[id];
+ if ( note )
+ return note->journal()->description();
+ else
+ return QString::null;
+}
+
+void KNotesPart::setName( const QString& id, const QString& newName )
+{
+ KNotesIconViewItem *note = mNoteList[ id ];
+ if ( note ) {
+ note->setText( newName );
+ mManager->save();
+ }
+}
+
+void KNotesPart::setText( const QString& id, const QString& newText )
+{
+ KNotesIconViewItem *note = mNoteList[ id ];
+ if ( note ) {
+ note->journal()->setDescription( newText );
+ mManager->save();
+ }
+}
+
+QMap<QString, QString> KNotesPart::notes() const
+{
+ QMap<QString, QString> notes;
+ QDictIterator<KNotesIconViewItem> it( mNoteList );
+
+ for ( ; it.current(); ++it )
+ notes.insert( (*it)->journal()->uid(), (*it)->journal()->summary() );
+
+ return notes;
+}
+
+
+// private stuff
+
+void KNotesPart::killSelectedNotes()
+{
+ QPtrList<KNotesIconViewItem> items;
+ QStringList notes;
+
+ KNotesIconViewItem *knivi;
+ for ( QIconViewItem *it = mNotesView->firstItem(); it; it = it->nextItem() ) {
+ if ( it->isSelected() ) {
+ knivi = static_cast<KNotesIconViewItem *>( it );
+ items.append( knivi );
+ notes.append( knivi->text() );
+ }
+ }
+
+ if ( items.isEmpty() )
+ return;
+
+ int ret = KMessageBox::warningContinueCancelList( mNotesView,
+ i18n( "Do you really want to delete this note?",
+ "Do you really want to delete these %n notes?", items.count() ),
+ notes, i18n( "Confirm Delete" ),
+ KStdGuiItem::del() );
+
+ if ( ret == KMessageBox::Continue ) {
+ QPtrListIterator<KNotesIconViewItem> kniviIt( items );
+ while ( (knivi = *kniviIt) ) {
+ ++kniviIt;
+ mManager->deleteNote( knivi->journal() );
+ }
+
+ mManager->save();
+ }
+}
+
+void KNotesPart::popupRMB( QIconViewItem *item, const QPoint& pos )
+{
+ QPopupMenu *contextMenu = NULL;
+
+ if ( item )
+ contextMenu = static_cast<QPopupMenu *>( factory()->container( "note_context", this ) );
+ else
+ contextMenu = static_cast<QPopupMenu *>( factory()->container( "notepart_context", this ) );
+
+ if ( !contextMenu )
+ return;
+
+ contextMenu->popup( pos );
+}
+
+void KNotesPart::slotOnItem( QIconViewItem *i )
+{
+ // TODO: disable (i.e. setNote( QString::null )) when mouse button pressed
+
+ KNotesIconViewItem *item = static_cast<KNotesIconViewItem *>( i );
+ mNoteTip->setNote( item );
+}
+
+void KNotesPart::slotOnViewport()
+{
+ mNoteTip->setNote( 0 );
+}
+
+// TODO: also with takeItem, clear(),
+
+// create and kill the icon view item corresponding to the note, edit the note
+
+void KNotesPart::createNote( KCal::Journal *journal )
+{
+ // make sure all fields are existent, initialize them with default values
+ QString property = journal->customProperty( "KNotes", "BgColor" );
+ if ( property.isNull() )
+ journal->setCustomProperty( "KNotes", "BgColor", "#ffff00" );
+
+ property = journal->customProperty( "KNotes", "FgColor" );
+ if ( property.isNull() )
+ journal->setCustomProperty( "KNotes", "FgColor", "#000000" );
+
+ property = journal->customProperty( "KNotes", "RichText" );
+ if ( property.isNull() )
+ journal->setCustomProperty( "KNotes", "RichText", "true" );
+
+ mNoteList.insert( journal->uid(), new KNotesIconViewItem( mNotesView, journal ) );
+}
+
+void KNotesPart::killNote( KCal::Journal *journal )
+{
+ mNoteList.remove( journal->uid() );
+}
+
+void KNotesPart::editNote( QIconViewItem *item )
+{
+ if ( !mNoteEditDlg )
+ mNoteEditDlg = new KNoteEditDlg( widget() );
+
+ KCal::Journal *journal = static_cast<KNotesIconViewItem *>( item )->journal();
+
+ mNoteEditDlg->setRichText( journal->customProperty( "KNotes", "RichText" ) == "true" );
+ mNoteEditDlg->setTitle( journal->summary() );
+ mNoteEditDlg->setText( journal->description() );
+
+ if ( mNoteEditDlg->exec() == QDialog::Accepted ) {
+ item->setText( mNoteEditDlg->title() );
+ journal->setDescription( mNoteEditDlg->text() );
+ mManager->save();
+ }
+}
+
+void KNotesPart::renameNote()
+{
+ mNotesView->currentItem()->rename();
+}
+
+void KNotesPart::renamedNote( QIconViewItem* )
+{
+ mManager->save();
+}
+
+void KNotesPart::slotOnCurrentChanged( QIconViewItem* )
+{
+ KAction *renameAction = actionCollection()->action( "edit_rename" );
+ KAction *deleteAction = actionCollection()->action( "edit_delete" );
+
+ if ( !mNotesView->currentItem() ) {
+ renameAction->setEnabled( false );
+ deleteAction->setEnabled( false );
+ } else {
+ renameAction->setEnabled( true );
+ deleteAction->setEnabled( true );
+ }
+}
+
+#include "knotes_part.moc"
+#include "knotes_part_p.moc"
+
diff --git a/kontact/plugins/knotes/knotes_part.h b/kontact/plugins/knotes/knotes_part.h
new file mode 100644
index 000000000..c034d04fb
--- /dev/null
+++ b/kontact/plugins/knotes/knotes_part.h
@@ -0,0 +1,101 @@
+/*
+ This file is part of the KDE project
+ Copyright (C) 2002 Daniel Molkentin <molkentin@kde.org>
+ Copyright (C) 2004-2006 Michael Brade <brade@kde.org>
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This program 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
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; see the file COPYING. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#ifndef KNOTES_PART_H
+#define KNOTES_PART_H
+
+#include <qdict.h>
+
+#include <kiconview.h>
+#include <kglobal.h>
+#include <kiconloader.h>
+
+#include <libkcal/journal.h>
+#include <kparts/part.h>
+
+#include "knotes/KNotesIface.h"
+
+class KIconView;
+class QIconViewItem;
+class KNotesIconViewItem;
+class KNoteTip;
+class KNoteEditDlg;
+class KNotesResourceManager;
+
+namespace KCal {
+class Journal;
+}
+
+class KNotesPart : public KParts::ReadOnlyPart, virtual public KNotesIface
+{
+ Q_OBJECT
+
+ public:
+ KNotesPart( QObject *parent = 0, const char *name = 0 );
+ ~KNotesPart();
+
+ bool openFile();
+
+ public slots:
+ QString newNote( const QString& name = QString::null,
+ const QString& text = QString::null );
+ QString newNoteFromClipboard( const QString& name = QString::null );
+
+ public:
+ void killNote( const QString& id );
+ void killNote( const QString& id, bool force );
+
+ QString name( const QString& id ) const;
+ QString text( const QString& id ) const;
+
+ void setName( const QString& id, const QString& newName );
+ void setText( const QString& id, const QString& newText );
+
+ QMap<QString, QString> notes() const;
+
+ private slots:
+ void createNote( KCal::Journal *journal );
+ void killNote( KCal::Journal *journal );
+
+ void editNote( QIconViewItem *item );
+
+ void renameNote();
+ void renamedNote( QIconViewItem *item );
+
+ void slotOnItem( QIconViewItem *item );
+ void slotOnViewport();
+ void slotOnCurrentChanged( QIconViewItem *item );
+
+ void popupRMB( QIconViewItem *item, const QPoint& pos );
+ void killSelectedNotes();
+
+ void printSelectedNotes();
+
+ private:
+ KIconView *mNotesView;
+ KNoteTip *mNoteTip;
+ KNoteEditDlg *mNoteEditDlg;
+
+ KNotesResourceManager *mManager;
+ QDict<KNotesIconViewItem> mNoteList;
+};
+
+#endif
diff --git a/kontact/plugins/knotes/knotes_part.rc b/kontact/plugins/knotes/knotes_part.rc
new file mode 100644
index 000000000..ef4461868
--- /dev/null
+++ b/kontact/plugins/knotes/knotes_part.rc
@@ -0,0 +1,23 @@
+<!DOCTYPE kpartgui>
+<kpartgui name="knotes" version="5">
+ <MenuBar>
+ <Menu name="file"><text>&amp;File</text>
+ <Merge/>
+ <Action name="print_note"/>
+ </Menu>
+ <Menu name="edit"><text>&amp;Edit</text>
+ <Action name="edit_rename"/>
+ <Action name="edit_delete"/>
+ </Menu>
+ </MenuBar>
+ <Menu name="note_context">
+ <Action name="file_new"/>
+ <Action name="edit_rename"/>
+ <Action name="edit_delete"/>
+ <Action name="print_note"/>
+ </Menu>
+ <Menu name="notepart_context">
+ <Action name="file_new"/>
+ </Menu>
+
+</kpartgui>
diff --git a/kontact/plugins/knotes/knotes_part_p.h b/kontact/plugins/knotes/knotes_part_p.h
new file mode 100644
index 000000000..55a0374b6
--- /dev/null
+++ b/kontact/plugins/knotes/knotes_part_p.h
@@ -0,0 +1,188 @@
+/*
+ This file is part of the KDE project
+ Copyright (C) 2004-2006 Michael Brade <brade@kde.org>
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This program 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
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; see the file COPYING. 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_PART_P_H
+#define KNOTES_PART_P_H
+
+#include <qlayout.h>
+#include <qlabel.h>
+
+#include <kactioncollection.h>
+#include <klocale.h>
+#include <kiconview.h>
+#include <kglobal.h>
+#include <kiconloader.h>
+#include <kiconeffect.h>
+#include <klineedit.h>
+#include <ktoolbar.h>
+#include <kpopupmenu.h>
+#include <kdialogbase.h>
+#include <kxmlguiclient.h>
+#include <kxmlguifactory.h>
+#include <kxmlguibuilder.h>
+
+#include <libkcal/calendarlocal.h>
+#include <libkcal/journal.h>
+#include <libkcal/icaldrag.h>
+#include <libkdepim/kpimprefs.h>
+
+#include "knotes/knoteedit.h"
+
+
+class KNotesIconViewItem : public KIconViewItem
+{
+ public:
+ KNotesIconViewItem( KIconView *parent, KCal::Journal *journal )
+ : KIconViewItem( parent ),
+ mJournal( journal )
+ {
+ setRenameEnabled( true );
+
+ KIconEffect effect;
+ QColor color( journal->customProperty( "KNotes", "BgColor" ) );
+ QPixmap icon = KGlobal::iconLoader()->loadIcon( "knotes", KIcon::Desktop );
+ icon = effect.apply( icon, KIconEffect::Colorize, 1, color, false );
+ setPixmap( icon );
+ setText( journal->summary() );
+ }
+
+ KCal::Journal *journal()
+ {
+ return mJournal;
+ }
+
+ virtual void setText( const QString& text )
+ {
+ KIconViewItem::setText( text );
+ mJournal->setSummary( text );
+ }
+
+ private:
+ KCal::Journal *mJournal;
+};
+
+
+class KNotesIconView : public KIconView
+{
+ protected:
+ QDragObject* dragObject()
+ {
+ QValueList<KNotesIconViewItem*> selectedItems;
+ for ( QIconViewItem *it = firstItem(); it; it = it->nextItem() ) {
+ if ( it->isSelected() )
+ selectedItems.append( static_cast<KNotesIconViewItem *>( it ) );
+ }
+ if ( selectedItems.count() != 1 )
+ return KIconView::dragObject();
+
+ KCal::CalendarLocal cal( KPimPrefs::timezone() );
+ KCal::Incidence *i = selectedItems.first()->journal()->clone();
+ cal.addIncidence( i );
+ KCal::ICalDrag *icd = new KCal::ICalDrag( &cal, this );
+ return icd;
+ }
+};
+
+
+class KNoteEditDlg : public KDialogBase, virtual public KXMLGUIClient
+{
+ Q_OBJECT
+
+ public:
+ KNoteEditDlg( QWidget *parent = 0, const char *name = 0 )
+ : KDialogBase( Plain, i18n( "Edit Note" ), Ok | Cancel, Ok,
+ parent, name, true, true )
+ {
+ // this dialog is modal to prevent one from editing the same note twice in two
+ // different windows
+
+ setInstance( new KInstance( "knotes" ) ); // TODO: hm, memleak??
+ setXMLFile( "knotesui.rc" );
+ actionCollection()->setWidget( this );
+
+ QWidget *page = plainPage();
+ QVBoxLayout *layout = new QVBoxLayout( page );
+
+ QHBoxLayout *hbl = new QHBoxLayout( layout, marginHint() );
+ QLabel *label = new QLabel( page);
+ label->setText( i18n( "Name:" ) );
+ hbl->addWidget( label,0 );
+ mTitleEdit= new KLineEdit( page, "name" );
+ hbl->addWidget( mTitleEdit, 1,Qt::AlignVCenter );
+
+ mNoteEdit = new KNoteEdit( actionCollection(), page );
+ mNoteEdit->setTextFormat( RichText );
+ mNoteEdit->setFocus();
+
+ KXMLGUIBuilder builder( page );
+ KXMLGUIFactory factory( &builder, this );
+ factory.addClient( this );
+
+ mTool = static_cast<KToolBar *>(factory.container( "note_tool", this ));
+
+ layout->addWidget( mTool );
+ layout->addWidget( mNoteEdit );
+ }
+
+ QString text() const
+ {
+ return mNoteEdit->text();
+ }
+
+ void setText( const QString& text )
+ {
+ mNoteEdit->setText( text );
+ }
+
+ QString title() const
+ {
+ return mTitleEdit->text();
+ }
+
+ void setTitle( const QString& text )
+ {
+ mTitleEdit->setText( text );
+ }
+
+ void setRichText( bool rt )
+ {
+ mNoteEdit->setTextFormat( rt ? RichText : PlainText );
+ }
+
+ private:
+ KLineEdit *mTitleEdit;
+ KNoteEdit *mNoteEdit;
+ KToolBar *mTool;
+ KPopupMenu *mEditMenu;
+};
+
+
+#endif
diff --git a/kontact/plugins/knotes/knotes_plugin.cpp b/kontact/plugins/knotes/knotes_plugin.cpp
new file mode 100644
index 000000000..beaaa6331
--- /dev/null
+++ b/kontact/plugins/knotes/knotes_plugin.cpp
@@ -0,0 +1,97 @@
+/*
+ This file is part of Kontact
+ Copyright (c) 2002 Daniel Molkentin <molkentin@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.
+*/
+
+#include <dcopref.h>
+#include <kaboutdata.h>
+#include <kaction.h>
+#include <kdebug.h>
+#include <kgenericfactory.h>
+#include <kiconloader.h>
+#include <kstatusbar.h>
+
+#include "core.h"
+#include "knotes_part.h"
+#include "summarywidget.h"
+
+#include "knotes_plugin.h"
+
+
+typedef KGenericFactory< KNotesPlugin, Kontact::Core > KNotesPluginFactory;
+K_EXPORT_COMPONENT_FACTORY( libkontact_knotesplugin,
+ KNotesPluginFactory( "kontact_knotesplugin" ) )
+
+
+KNotesPlugin::KNotesPlugin( Kontact::Core *core, const char *, const QStringList & )
+ : Kontact::Plugin( core, core, "knotes" ),
+ mAboutData( 0 )
+{
+ setInstance( KNotesPluginFactory::instance() );
+
+ insertNewAction( new KAction( i18n( "New Note..." ), "knotes", CTRL+SHIFT+Key_N,
+ this, SLOT( slotNewNote() ), actionCollection(), "new_note" ) );
+ insertSyncAction( new KAction( i18n( "Synchronize Notes" ), "reload", 0,
+ this, SLOT( slotSyncNotes() ), actionCollection(), "knotes_sync" ) );
+}
+
+KNotesPlugin::~KNotesPlugin()
+{
+}
+
+KParts::ReadOnlyPart* KNotesPlugin::createPart()
+{
+ return new KNotesPart( this, "notes" );
+}
+
+Kontact::Summary *KNotesPlugin::createSummaryWidget( QWidget *parentWidget )
+{
+ return new KNotesSummaryWidget( this, parentWidget );
+}
+
+const KAboutData *KNotesPlugin::aboutData()
+{
+ if ( !mAboutData ) {
+ mAboutData = new KAboutData( "knotes", I18N_NOOP( "Notes Management" ),
+ "0.5", I18N_NOOP( "Notes Management" ),
+ KAboutData::License_GPL_V2,
+ "(c) 2003-2004 The Kontact developers" );
+ mAboutData->addAuthor( "Michael Brade", "Current Maintainer", "brade@kde.org" );
+ mAboutData->addAuthor( "Tobias Koenig", "", "tokoe@kde.org" );
+ }
+
+ return mAboutData;
+}
+
+
+// private slots
+
+void KNotesPlugin::slotNewNote()
+{
+ if ( part() )
+ static_cast<KNotesPart *>( part() )->newNote();
+}
+
+void KNotesPlugin::slotSyncNotes()
+{
+ DCOPRef ref( "kmail", "KMailICalIface" );
+ ref.send( "triggerSync", QString("Note") );
+}
+
+#include "knotes_plugin.moc"
+
diff --git a/kontact/plugins/knotes/knotes_plugin.h b/kontact/plugins/knotes/knotes_plugin.h
new file mode 100644
index 000000000..d4d58cb03
--- /dev/null
+++ b/kontact/plugins/knotes/knotes_plugin.h
@@ -0,0 +1,58 @@
+/* This file is part of the KDE project
+ Copyright (C) 2002 Daniel Molkentin <molkentin@kde.org>
+ 2004 Michael Brade <brade@kde.org>
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This program 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
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; see the file COPYING. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+ */
+
+#ifndef KNOTES_PLUGIN_H
+#define KNOTES_PLUGIN_H
+
+#include <klocale.h>
+
+#include "plugin.h"
+
+class KNotesPart;
+class SummaryWidget;
+
+
+class KNotesPlugin : public Kontact::Plugin
+{
+ Q_OBJECT
+
+ public:
+ KNotesPlugin( Kontact::Core *core, const char *name, const QStringList& );
+ ~KNotesPlugin();
+
+ virtual Kontact::Summary *createSummaryWidget( QWidget *parentWidget );
+
+ int weight() const { return 600; }
+
+ const KAboutData *aboutData();
+
+ protected:
+ KParts::ReadOnlyPart* createPart();
+
+ private slots:
+ void slotNewNote();
+ void slotSyncNotes();
+
+ private:
+ KAboutData *mAboutData;
+};
+
+#endif
+
diff --git a/kontact/plugins/knotes/knotesplugin.desktop b/kontact/plugins/knotes/knotesplugin.desktop
new file mode 100644
index 000000000..e7fe8fc0c
--- /dev/null
+++ b/kontact/plugins/knotes/knotesplugin.desktop
@@ -0,0 +1,95 @@
+[Desktop Entry]
+Type=Service
+Icon=kontact_notes
+ServiceTypes=Kontact/Plugin,KPluginInfo
+
+X-KDE-Library=libkontact_knotesplugin
+X-KDE-KontactPluginVersion=6
+X-KDE-KontactPluginHasSummary=true
+
+X-KDE-PluginInfo-Website=http://pim.kde.org/components/knotes.php
+X-KDE-PluginInfo-Name=kontact_knotesplugin
+X-KDE-PluginInfo-Version=0.1
+X-KDE-PluginInfo-License=LGPL
+X-KDE-PluginInfo-EnabledByDefault=true
+
+Comment=Notes Component (KNotes Plugin)
+Comment[bg]=Приставка за бележки
+Comment[ca]=Component de notes (endollable del KNotes)
+Comment[da]=Notatkomponent (KNotes-plugin)
+Comment[de]=Notizen-Komponente (KNotes-Modul)
+Comment[el]=Συσταικό σημειώσεων (Πρόσθετο του KNotes)
+Comment[es]=Componente de notas (complemento de KNotes)
+Comment[et]=Märkmete plugin (KNotes)
+Comment[fr]=Composant de notes (Module KNotes)
+Comment[is]=Minnismiðaeining (KNotes íforrit)
+Comment[it]=Componente note (plugin KNotes)
+Comment[ja]=メモコンポーネント (KNotes プラグイン)
+Comment[km]=សមាសភាគ​ចំណាំ (កម្មវិធី​ជំនួយ KNotes​)
+Comment[nds]=Notizen-Komponent (KNotes-Moduul)
+Comment[nl]=Notitiecomponent (KNotes-plugin)
+Comment[pl]=Składnik notatek (wtyczka KNotes)
+Comment[ru]=Заметки (модуль KNotes)
+Comment[sr]=Компонента белешки (прикључак KNotes-а)
+Comment[sr@Latn]=Komponenta beleški (priključak KNotes-a)
+Comment[sv]=Anteckningskomponent (Knotes-insticksprogram)
+Comment[tr]=Notlar Bileşeni (KNotes Eklentisi)
+Comment[zh_CN]=便笺组件(KNotes 插件)
+Comment[zh_TW]=便條組件(KNotes 外掛程式)
+Name=Notes
+Name[af]=Notas
+Name[ar]=الملاحظات
+Name[be]=Нататкі
+Name[bg]=Бележки
+Name[br]=Notennoù
+Name[bs]=Bilješke
+Name[cs]=Poznámky
+Name[cy]=Nodiadau
+Name[da]=Noter
+Name[de]=Notizen
+Name[el]=Σημειώσεις
+Name[eo]=Notoj
+Name[es]=Notas
+Name[et]=Märkmed
+Name[eu]=Oharrak
+Name[fa]=یادداشتها
+Name[fi]=Muistio
+Name[fy]=Notysjes
+Name[ga]=Nótaí
+Name[gl]=Notas
+Name[he]=פתקים
+Name[hi]=टीप
+Name[hu]=Feljegyzések
+Name[is]=Minnismiðar
+Name[it]=Note
+Name[ja]=メモ
+Name[ka]=ჩანიშვნები
+Name[kk]=Жазбалар
+Name[km]=ចំណាំ
+Name[lt]=Užrašai
+Name[mk]=Белешки
+Name[ms]=Nota
+Name[nds]=Notizen
+Name[ne]=टिपोट
+Name[nl]=Notities
+Name[nn]=Notat
+Name[pl]=Notatki
+Name[pt]=Notas
+Name[pt_BR]=Notas
+Name[ro]=Notiţe
+Name[ru]=Заметки
+Name[se]=Nohtat
+Name[sk]=Poznámky
+Name[sl]=Notice
+Name[sr]=Белешке
+Name[sr@Latn]=Beleške
+Name[sv]=Anteckningar
+Name[ta]=குறிப்புகள்
+Name[tg]=Ахборот
+Name[th]=บันทึกช่วยจำ
+Name[tr]=Notlar
+Name[uk]=Примітки
+Name[uz]=Yozma xotira
+Name[uz@cyrillic]=Ёзма хотира
+Name[zh_CN]=便笺
+Name[zh_TW]=備忘錄
diff --git a/kontact/plugins/knotes/knotetip.cpp b/kontact/plugins/knotes/knotetip.cpp
new file mode 100644
index 000000000..6e2c998d7
--- /dev/null
+++ b/kontact/plugins/knotes/knotetip.cpp
@@ -0,0 +1,227 @@
+/*
+ This file is part of the KDE project
+ Copyright (C) 2004 Michael Brade <brade@kde.org>
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This program 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
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; see the file COPYING. 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 <qtooltip.h>
+#include <qlayout.h>
+#include <qtextedit.h>
+
+#include <kapplication.h>
+#include <kglobalsettings.h>
+
+#include "knotetip.h"
+#include "knotes_part_p.h"
+
+
+KNoteTip::KNoteTip( KIconView *parent )
+ : QFrame( 0, 0, WX11BypassWM | // this will make Seli happy >:-P
+ WStyle_Customize | WStyle_NoBorder | WStyle_Tool | WStyle_StaysOnTop ),
+ mFilter( false ),
+ mView( parent ),
+ mNoteIVI( 0 ),
+ mPreview( new QTextEdit( this ) )
+{
+ mPreview->setReadOnly( true );
+ mPreview->setHScrollBarMode( QScrollView::AlwaysOff );
+ mPreview->setVScrollBarMode( QScrollView::AlwaysOff );
+
+ QBoxLayout *layout = new QVBoxLayout( this );
+ layout->addWidget( mPreview );
+
+ setPalette( QToolTip::palette() );
+ setMargin( 1 );
+ setFrameStyle( QFrame::Plain | QFrame::Box );
+ hide();
+}
+
+KNoteTip::~KNoteTip()
+{
+ delete mPreview;
+ mPreview = 0;
+}
+
+void KNoteTip::setNote( KNotesIconViewItem *item )
+{
+ if ( mNoteIVI == item )
+ return;
+
+ mNoteIVI = item;
+
+ if ( !mNoteIVI ) {
+ killTimers();
+ if ( isVisible() ) {
+ setFilter( false );
+ hide();
+ }
+ } else {
+ KCal::Journal *journal = item->journal();
+ if ( journal->customProperty( "KNotes", "RichText" ) == "true" )
+ mPreview->setTextFormat( Qt::RichText );
+ else
+ mPreview->setTextFormat( Qt::PlainText );
+
+ QColor fg( journal->customProperty( "KNotes", "FgColor" ) );
+ QColor bg( journal->customProperty( "KNotes", "BgColor" ) );
+ setColor( fg, bg );
+
+ mPreview->setText( journal->description() );
+ mPreview->zoomTo( 8 );
+ mPreview->sync();
+
+ int w = 400;
+ int h = mPreview->heightForWidth( w );
+ while ( w > 60 && h == mPreview->heightForWidth( w - 20 ) )
+ w -= 20;
+
+ QRect desk = KGlobalSettings::desktopGeometry( mNoteIVI->rect().center() );
+ resize( w, QMIN( h, desk.height() / 2 - 20 ) );
+
+ hide();
+ killTimers();
+ setFilter( true );
+ startTimer( 600 ); // delay showing the tooltip for 0.7 sec
+ }
+}
+
+
+// protected, virtual methods
+
+void KNoteTip::resizeEvent( QResizeEvent *ev )
+{
+ QFrame::resizeEvent( ev );
+ reposition();
+}
+
+void KNoteTip::timerEvent( QTimerEvent * )
+{
+ killTimers();
+
+ if ( !isVisible() ) {
+ startTimer( 15000 ); // show the tooltip for 15 sec
+ reposition();
+ show();
+ } else {
+ setFilter( false );
+ hide();
+ }
+}
+
+bool KNoteTip::eventFilter( QObject *, QEvent *e )
+{
+ switch ( e->type() ) {
+ case QEvent::Leave:
+ case QEvent::MouseButtonPress:
+ case QEvent::MouseButtonRelease:
+ case QEvent::KeyPress:
+ case QEvent::KeyRelease:
+ case QEvent::FocusIn:
+ case QEvent::FocusOut:
+ case QEvent::Wheel:
+ killTimers();
+ setFilter( false );
+ hide();
+ default:
+ break;
+ }
+
+ return false;
+}
+
+
+// private stuff
+
+void KNoteTip::setColor( const QColor &fg, const QColor &bg )
+{
+ QPalette newpalette = palette();
+ newpalette.setColor( QColorGroup::Background, bg );
+ newpalette.setColor( QColorGroup::Foreground, fg );
+ newpalette.setColor( QColorGroup::Base, bg ); // text background
+ newpalette.setColor( QColorGroup::Text, fg ); // text color
+ newpalette.setColor( QColorGroup::Button, bg );
+
+ // the shadow
+ newpalette.setColor( QColorGroup::Midlight, bg.light(110) );
+ newpalette.setColor( QColorGroup::Shadow, bg.dark(116) );
+ newpalette.setColor( QColorGroup::Light, bg.light(180) );
+ newpalette.setColor( QColorGroup::Dark, bg.dark(108) );
+ setPalette( newpalette );
+
+ // set the text color
+ mPreview->setColor( fg );
+}
+
+
+void KNoteTip::setFilter( bool enable )
+{
+ if ( enable == mFilter )
+ return;
+
+ if ( enable ) {
+ kapp->installEventFilter( this );
+ QApplication::setGlobalMouseTracking( true );
+ } else {
+ QApplication::setGlobalMouseTracking( false );
+ kapp->removeEventFilter( this );
+ }
+
+ mFilter = enable;
+}
+
+void KNoteTip::reposition()
+{
+ if ( !mNoteIVI )
+ return;
+
+ QRect rect = mNoteIVI->rect();
+ QPoint off = mView->mapToGlobal( mView->contentsToViewport( QPoint( 0, 0 ) ) );
+ rect.moveBy( off.x(), off.y() );
+
+ QPoint pos = rect.center();
+
+ // should the tooltip be shown to the left or to the right of the ivi?
+ QRect desk = KGlobalSettings::desktopGeometry( pos );
+ if ( rect.center().x() + width() > desk.right() ) {
+ // to the left
+ if ( pos.x() - width() < 0 )
+ pos.setX( 0 );
+ else
+ pos.setX( pos.x() - width() );
+ }
+
+ // should the tooltip be shown above or below the ivi ?
+ if ( rect.bottom() + height() > desk.bottom() ) {
+ // above
+ pos.setY( rect.top() - height() );
+ } else
+ pos.setY( rect.bottom() );
+
+ move( pos );
+ update();
+}
diff --git a/kontact/plugins/knotes/knotetip.h b/kontact/plugins/knotes/knotetip.h
new file mode 100644
index 000000000..f07b75f0c
--- /dev/null
+++ b/kontact/plugins/knotes/knotetip.h
@@ -0,0 +1,68 @@
+/*
+ This file is part of the KDE project
+ Copyright (C) 2004 Michael Brade <brade@kde.org>
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This program 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
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; see the file COPYING. 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 KNOTETIP_H
+#define KNOTETIP_H
+
+#include <qframe.h>
+
+class QTextEdit;
+class KIconView;
+class KNotesIconViewItem;
+
+class KNoteTip : public QFrame
+{
+ public:
+ KNoteTip( KIconView *parent );
+ ~KNoteTip();
+
+ void setNote( KNotesIconViewItem *item );
+
+ protected:
+ virtual bool eventFilter( QObject *, QEvent *e );
+ virtual void timerEvent( QTimerEvent * );
+ virtual void resizeEvent( QResizeEvent * );
+
+ private:
+ void setColor( const QColor &fg, const QColor &bg );
+ void setFilter( bool enable );
+ void reposition();
+
+ private:
+ bool mFilter;
+
+ KIconView *mView;
+ KNotesIconViewItem *mNoteIVI;
+
+ QTextEdit *mPreview;
+};
+
+#endif
diff --git a/kontact/plugins/knotes/summarywidget.cpp b/kontact/plugins/knotes/summarywidget.cpp
new file mode 100644
index 000000000..3045ede53
--- /dev/null
+++ b/kontact/plugins/knotes/summarywidget.cpp
@@ -0,0 +1,164 @@
+/*
+ This file is part of Kontact.
+ Copyright (c) 2003 Tobias Koenig <tokoe@kde.org>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program 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 General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+ As a special exception, permission is given to link this program
+ with any edition of Qt, and distribute the resulting executable,
+ without including the source code for Qt in the source distribution.
+*/
+
+#include <qobject.h>
+#include <qlabel.h>
+#include <qlayout.h>
+#include <qtooltip.h>
+
+#include <dcopclient.h>
+#include <dcopref.h>
+#include <kapplication.h>
+#include <kdebug.h>
+#include <kglobal.h>
+#include <kiconloader.h>
+#include <klocale.h>
+#include <kurllabel.h>
+#include <kstandarddirs.h>
+
+#include <knotes/resourcenotes.h>
+#include <knotes/resourcemanager.h>
+
+#include "core.h"
+#include "plugin.h"
+
+#include "summarywidget.h"
+
+KNotesSummaryWidget::KNotesSummaryWidget( Kontact::Plugin *plugin,
+ QWidget *parent, const char *name )
+ : Kontact::Summary( parent, name ), mLayout( 0 ), mPlugin( plugin )
+{
+ QVBoxLayout *mainLayout = new QVBoxLayout( this, 3, 3 );
+
+ QPixmap icon = KGlobal::iconLoader()->loadIcon( "kontact_notes",
+ KIcon::Desktop, KIcon::SizeMedium );
+ QWidget* header = createHeader( this, icon, i18n( "Notes" ) );
+ mainLayout->addWidget( header );
+
+ mLayout = new QGridLayout( mainLayout, 7, 3, 3 );
+ mLayout->setRowStretch( 6, 1 );
+
+ mCalendar = new KCal::CalendarLocal( QString::fromLatin1("UTC") );
+ KNotesResourceManager *manager = new KNotesResourceManager();
+
+ QObject::connect( manager, SIGNAL( sigRegisteredNote( KCal::Journal* ) ),
+ this, SLOT( addNote( KCal::Journal* ) ) );
+ QObject::connect( manager, SIGNAL( sigDeregisteredNote( KCal::Journal* ) ),
+ this, SLOT( removeNote( KCal::Journal* ) ) );
+ manager->load();
+
+
+ updateView();
+}
+
+void KNotesSummaryWidget::updateView()
+{
+ mNotes = mCalendar->journals();
+ QLabel *label;
+
+ for ( label = mLabels.first(); label; label = mLabels.next() )
+ label->deleteLater();
+ mLabels.clear();
+
+ KIconLoader loader( "knotes" );
+
+ int counter = 0;
+ QPixmap pm = loader.loadIcon( "knotes", KIcon::Small );
+
+ KCal::Journal::List::Iterator it;
+ if ( mNotes.count() ) {
+ for (it = mNotes.begin(); it != mNotes.end(); ++it) {
+
+ // Fill Note Pixmap Field
+ label = new QLabel( this );
+ label->setPixmap( pm );
+ label->setMaximumWidth( label->minimumSizeHint().width() );
+ label->setAlignment( AlignVCenter );
+ mLayout->addWidget( label, counter, 0 );
+ mLabels.append( label );
+
+ // File Note Summary Field
+ QString newtext = (*it)->summary();
+
+ KURLLabel *urlLabel = new KURLLabel( (*it)->uid(), newtext, this );
+ urlLabel->installEventFilter( this );
+ urlLabel->setTextFormat(RichText);
+ urlLabel->setAlignment( urlLabel->alignment() | Qt::WordBreak );
+ mLayout->addWidget( urlLabel, counter, 1 );
+ mLabels.append( urlLabel );
+
+ if ( !(*it)->description().isEmpty() ) {
+ QToolTip::add( urlLabel, (*it)->description().left( 80 ) );
+ }
+
+ connect( urlLabel, SIGNAL( leftClickedURL( const QString& ) ),
+ this, SLOT( urlClicked( const QString& ) ) );
+ counter++;
+ }
+
+ } else {
+ QLabel *noNotes = new QLabel( i18n( "No Notes Available" ), this );
+ noNotes->setAlignment( AlignHCenter | AlignVCenter );
+ mLayout->addWidget( noNotes, 0, 1 );
+ mLabels.append( noNotes );
+ }
+
+ for ( label = mLabels.first(); label; label = mLabels.next() )
+ label->show();
+}
+
+void KNotesSummaryWidget::urlClicked( const QString &/*uid*/ )
+{
+ if ( !mPlugin->isRunningStandalone() )
+ mPlugin->core()->selectPlugin( mPlugin );
+ else
+ mPlugin->bringToForeground();
+}
+
+bool KNotesSummaryWidget::eventFilter( QObject *obj, QEvent* e )
+{
+ if ( obj->inherits( "KURLLabel" ) ) {
+ KURLLabel* label = static_cast<KURLLabel*>( obj );
+ if ( e->type() == QEvent::Enter )
+ emit message( i18n( "Read Note: \"%1\"" ).arg( label->text() ) );
+ if ( e->type() == QEvent::Leave )
+ emit message( QString::null );
+ }
+
+ return Kontact::Summary::eventFilter( obj, e );
+}
+
+void KNotesSummaryWidget::addNote( KCal::Journal *j )
+{
+ mCalendar->addJournal( j );
+ updateView();
+}
+
+void KNotesSummaryWidget::removeNote( KCal::Journal *j )
+{
+ mCalendar->deleteJournal( j );
+ updateView();
+}
+
+
+#include "summarywidget.moc"
diff --git a/kontact/plugins/knotes/summarywidget.h b/kontact/plugins/knotes/summarywidget.h
new file mode 100644
index 000000000..f21d829fa
--- /dev/null
+++ b/kontact/plugins/knotes/summarywidget.h
@@ -0,0 +1,71 @@
+/*
+ This file is part of Kontact.
+ Copyright (c) 2003 Tobias Koenig <tokoe@kde.org>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program 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 General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+ As a special exception, permission is given to link this program
+ with any edition of Qt, and distribute the resulting executable,
+ without including the source code for Qt in the source distribution.
+*/
+
+#ifndef SUMMARYWIDGET_H
+#define SUMMARYWIDGET_H
+
+#include "summary.h"
+
+#include <qmap.h>
+#include <qptrlist.h>
+#include <qwidget.h>
+
+#include <libkcal/resourcelocal.h>
+#include <libkcal/calendarresources.h>
+
+class QGridLayout;
+class QLabel;
+
+namespace Kontact {
+ class Plugin;
+}
+
+class KNotesSummaryWidget : public Kontact::Summary
+{
+ Q_OBJECT
+
+ public:
+ KNotesSummaryWidget( Kontact::Plugin *plugin, QWidget *parent, const char *name = 0 );
+
+ void updateSummary( bool force = false ) { Q_UNUSED( force ); updateView(); }
+
+ protected:
+ virtual bool eventFilter( QObject *obj, QEvent* e );
+
+ protected slots:
+ void urlClicked( const QString& );
+ void updateView();
+ void addNote( KCal::Journal* );
+ void removeNote( KCal::Journal* );
+
+ private:
+ KCal::CalendarLocal *mCalendar;
+ KCal::Journal::List mNotes;
+
+ QGridLayout *mLayout;
+
+ QPtrList<QLabel> mLabels;
+ Kontact::Plugin *mPlugin;
+};
+
+#endif