[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-pim
Subject:    [Kde-pim] KNotes kontact plugin patch
From:       Bo Thorsen <bo () sonofthor ! dk>
Date:       2004-08-31 8:57:48
Message-ID: 200408311057.48592.bo () sonofthor ! dk
[Download RAW message or body]

[Attachment #2 (multipart/signed)]

[Attachment #4 (multipart/mixed)]


Hi all,

I backported Michaels KNotes changes to 3.3 branch, so we would be able to 
use the resources. The attached patch is what I have so far.

I probably need to remove the rich text stuff, since that's a new feature. 
But other than that the patch has the problem that it introduces several 
new strings.

So, what to do? Should I continue with the patch or what? Any directions 
you prefer me to take?

Bo,

-- 

     Bo Thorsen                 |   Praestevejen 4
     Senior Software Engineer   |   5290 Marslev
     Klarälvdalens Datakonsult  |   Denmark

["knotes-kontact.patch" (text/x-diff)]

Index: knotes/knote.cpp
===================================================================
RCS file: /home/kde/kdepim/knotes/knote.cpp,v
retrieving revision 1.120.2.1
diff -u -3 -p -r1.120.2.1 knote.cpp
--- knotes/knote.cpp	20 Aug 2004 19:55:47 -0000	1.120.2.1
+++ knotes/knote.cpp	31 Aug 2004 08:52:08 -0000
@@ -132,7 +132,7 @@ KNote::KNote( KXMLGUIBuilder* builder, Q
     setName( m_journal->summary() );      // don't worry, no signals are connected \
at this stage yet  
     // create the note editor
-    m_editor = new KNoteEdit( this );
+    m_editor = new KNoteEdit( actionCollection(), this );
     m_editor->installEventFilter( this ); // receive events (for modified)
     m_editor->viewport()->installEventFilter( this );
 
Index: knotes/knoteedit.cpp
===================================================================
RCS file: /home/kde/kdepim/knotes/knoteedit.cpp,v
retrieving revision 1.45.2.1
diff -u -3 -p -r1.45.2.1 knoteedit.cpp
--- knotes/knoteedit.cpp	20 Aug 2004 17:55:03 -0000	1.45.2.1
+++ knotes/knoteedit.cpp	31 Aug 2004 08:52:08 -0000
@@ -27,7 +27,6 @@
 #include <kurldrag.h>
 #include <kstdaction.h>
 #include <kcolordialog.h>
-#include <kxmlguiclient.h>
 
 #include "knoteedit.h"
 #include "knotebutton.h"
@@ -36,7 +35,7 @@ static const short SEP = 5;
 static const short ICON_SIZE = 10;
 
 
-KNoteEdit::KNoteEdit( QWidget *parent, const char *name )
+KNoteEdit::KNoteEdit( KActionCollection *actions, QWidget *parent, const char *name \
)  : KTextEdit( parent, name )
 {
     setAcceptDrops( true );
@@ -44,9 +43,6 @@ KNoteEdit::KNoteEdit( QWidget *parent, c
     setWrapPolicy( AtWhiteSpace );
     setLinkUnderline( true );
 
-    KXMLGUIClient* client = dynamic_cast<KXMLGUIClient*>(parent);
-    KActionCollection* actions = client->actionCollection();
-
     // create the actions for the RMB menu
     KAction* undo = KStdAction::undo( this, SLOT(undo()), actions );
     KAction* redo = KStdAction::redo( this, SLOT(redo()), actions );
Index: knotes/knoteedit.h
===================================================================
RCS file: /home/kde/kdepim/knotes/knoteedit.h,v
retrieving revision 1.25
diff -u -3 -p -r1.25 knoteedit.h
--- knotes/knoteedit.h	20 Apr 2004 21:55:57 -0000	1.25
+++ knotes/knoteedit.h	31 Aug 2004 08:52:08 -0000
@@ -29,6 +29,7 @@ class QFont;
 class QColor;
 class QPushButton;
 class KAction;
+class KActionCollection;
 class KToggleAction;
 class KFontAction;
 class KFontSizeAction;
@@ -38,7 +39,7 @@ class KNoteEdit : public KTextEdit
 {
     Q_OBJECT
 public:
-    KNoteEdit( QWidget *parent=0, const char *name=0 );
+    KNoteEdit( KActionCollection *actions, QWidget *parent=0, const char *name=0 );
     ~KNoteEdit();
 
     void setText( const QString& text );
Index: kontact/plugins/knotes/Makefile.am
===================================================================
RCS file: /home/kde/kdepim/kontact/plugins/knotes/Makefile.am,v
retrieving revision 1.11
diff -u -3 -p -r1.11 Makefile.am
--- kontact/plugins/knotes/Makefile.am	9 Nov 2003 18:54:57 -0000	1.11
+++ kontact/plugins/knotes/Makefile.am	31 Aug 2004 08:52:08 -0000
@@ -4,11 +4,11 @@ kde_module_LTLIBRARIES = libkontact_knot
 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
+                                    $(top_builddir)/libkcal/libkcal.la -lkresources \
\ +                                    $(top_builddir)/knotes/libknotes.la -lkdeprint
 
-
-libkontact_knotesplugin_la_SOURCES = knotes_plugin.cpp knotes_part.cpp \
-                                     summarywidget.cpp
+libkontact_knotesplugin_la_SOURCES = knotes_plugin.cpp knotes_part.cpp \
summarywidget.cpp \ +                                     knotetip.cpp
 
 METASOURCES = AUTO
 
Index: kontact/plugins/knotes/knotes_part.cpp
===================================================================
RCS file: /home/kde/kdepim/kontact/plugins/knotes/knotes_part.cpp,v
retrieving revision 1.31
diff -u -3 -p -r1.31 knotes_part.cpp
--- kontact/plugins/knotes/knotes_part.cpp	25 Jul 2004 09:00:36 -0000	1.31
+++ kontact/plugins/knotes/knotes_part.cpp	31 Aug 2004 08:52:08 -0000
@@ -1,6 +1,7 @@
 /*
    This file is part of the KDE project
    Copyright (C) 2002-2003 Daniel Molkentin <molkentin@kde.org>
+   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
@@ -18,334 +19,327 @@
    Boston, MA 02111-1307, USA.
 */
 
-#include <qlayout.h>
 #include <qpopupmenu.h>
-#include <qtextedit.h>
+#include <qclipboard.h>
 
-#include <kaction.h>
 #include <kapplication.h>
 #include <kdebug.h>
-#include <kdialogbase.h>
-#include <kiconloader.h>
-#include <kinputdialog.h>
-#include <klistview.h>
-#include <klocale.h>
+#include <kaction.h>
 #include <kmessagebox.h>
-#include <kstandarddirs.h>
-#include <kstdaction.h>
-#include <kxmlguifactory.h>
 
 #include <libkdepim/infoextension.h>
 #include <libkdepim/sidebarextension.h>
 
+#include "knotes/resourcemanager.h"
+
 #include "knotes_part.h"
+#include "knotes_part_p.h"
+#include "knotetip.h"
 
-class NotesItem : public KListViewItem
-{
-  public:
-    NotesItem( KListView *parent, KCal::Journal *journal )
-      : KListViewItem( parent, "" ), mJournal( journal )
-    {
-      setRenameEnabled( 0, true );
-      setPixmap( 0, KGlobal::iconLoader()->loadIcon( "knotes", KIcon::Small ) );
-    }
 
-    KCal::Journal* journal() { return mJournal; }
+KNotesPart::KNotesPart( QObject *parent, const char *name )
+  : DCOPObject("KNotesIface"), KParts::ReadOnlyPart( parent, name ),
+    m_notesView( new KIconView() ),
+    m_noteTip( new KNoteTip( m_notesView ) ),
+    m_noteEditDlg( 0 ),
+    m_context_menu( 0 ),
+    m_manager( new KNotesResourceManager() )
+{
+    m_noteList.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", 0, this, SLOT(killSelectedNotes()),
+                 actionCollection(), "edit_delete" );
+
+    // TODO styleguide: s/New.../New/, s/Rename/Rename.../
+    // TODO icons: s/editdelete/knotes_delete/ or the other way round in knotes
+
+    // set the view up
+    m_notesView->setSelectionMode( QIconView::Extended );
+    m_notesView->setItemsMovable( false );
+    m_notesView->setResizeMode( QIconView::Adjust );
+
+    connect( m_notesView, SIGNAL(executed( QIconViewItem * )),
+             this, SLOT(editNote( QIconViewItem * )) );
+    connect( m_notesView, SIGNAL(returnPressed( QIconViewItem * )),
+             this, SLOT(editNote( QIconViewItem * )) );
+    connect( m_notesView, SIGNAL(itemRenamed( QIconViewItem * )),
+             this, SLOT(renamedNote( QIconViewItem * )) );
+    connect( m_notesView, SIGNAL(contextMenuRequested( QIconViewItem *, const QPoint \
& )), +             this, SLOT(popupRMB( QIconViewItem *, const QPoint & )) );
+    connect( m_notesView, SIGNAL(onItem( QIconViewItem * )),
+             this, SLOT(slotOnItem( QIconViewItem * )) );
+    connect( m_notesView, SIGNAL(onViewport()), this, SLOT(slotOnViewport()) );
+
+    new KParts::SideBarExtension( m_notesView, this, "NotesSideBarExtension" );
+
+    setWidget( m_notesView );
+    setXMLFile( "knotes_part.rc" );
+
+    // connect the resource manager
+    connect( m_manager, SIGNAL(sigRegisteredNote( KCal::Journal * )),
+             this,      SLOT(createNote( KCal::Journal * )) );
+    connect( m_manager, SIGNAL(sigDeregisteredNote( KCal::Journal * )),
+             this,      SLOT(killNote( KCal::Journal * )) );
 
-    virtual void setText( int column, const QString &text )
-    {
-      if ( column == 0 )
-        mJournal->setSummary( text );
-    }
+    // read the notes
+    m_manager->load();
+}
 
-    virtual QString text( int column ) const
-    {
-      if ( column == 0 )
-        return mJournal->summary();
-      else if ( column == 1 )
-        return mJournal->description().replace( "\n", " " );
-      else
-        return QString();
-    }
+KNotesPart::~KNotesPart()
+{
+    delete m_noteTip;
+    delete m_manager;
+}
 
-  private:
-    KCal::Journal* mJournal;
-};
-
-class NoteEditDialog : public KDialogBase
-{
-  public:
-    NoteEditDialog( QWidget *parent, const QString &text )
-      : KDialogBase( Plain, i18n( "Edit Note" ), Ok | Cancel, Ok,
-                     parent, 0, true, true )
-    {
-      QWidget *page = plainPage();
-      QVBoxLayout *layout = new QVBoxLayout( page );
+bool KNotesPart::openFile()
+{
+    return false;
+}
 
-      mTextEdit = new QTextEdit( page );
-      layout->addWidget( mTextEdit );
 
-      mTextEdit->setText( text );
-      mTextEdit->setFocus();
-    }
+// public KNotes DCOP interface implementation
 
-    QString text() const { return mTextEdit->text(); }
+QString KNotesPart::newNote( const QString& name, const QString& text )
+{
+    // create the new note
+    KCal::Journal *journal = new KCal::Journal();
 
-  private:
-    QTextEdit *mTextEdit;
-};
+    // 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() ) );  
-KNotesPart::KNotesPart( QObject *parent, const char *name )
-  : KParts::ReadOnlyPart( parent, name ),
-    mTicket( 0 ), mPopupMenu( 0 )
-{
-  setInstance( new KInstance( "knotes" ) );
+    // the body of the note
+    journal->setDescription( text );
 
-  mCalendar = new KCal::CalendarResources;
-  mResource = new KCal::ResourceLocal( ::locateLocal( "data", "knotes/notes.ics" ) \
                );
-  mCalendar->resourceManager()->add( mResource );
-  mCalendar->load();
-
-  connect( mCalendar, SIGNAL( calendarChanged() ), SLOT( slotCalendarChanged() ) );
-
-  mNotesView = new KListView();
-  mNotesView->setSelectionMode( QListView::Extended );
-  mNotesView->addColumn( i18n( "Title" ) );
-  mNotesView->addColumn( i18n( "Content" ) );
-  mNotesView->setAllColumnsShowFocus( true );
-  mNotesView->setResizeMode( QListView::LastColumn );
-
-  (void) new KParts::SideBarExtension( mNotesView, this, "NotesSideBarExtension" );
-
-  (void) new KAction( i18n("&New..."), "knotes", CTRL+Key_N, this, SLOT( newNote() \
                ), actionCollection(), "file_new" );
-  mActionEdit = new KAction( i18n( "Rename" ), "editrename", this,
-                             SLOT( renameNote() ), actionCollection(),
-                                     "edit_rename" );
-  mActionDelete = new KAction( i18n( "Delete" ), "editdelete", 0, this,
-                               SLOT( removeSelectedNotes() ), actionCollection(),
-                               "edit_delete" );
-  (void) new KAction( i18n( "Reload" ), "reload", 0, this,
-                      SLOT( reloadNotes() ), actionCollection(), "view_refresh" );
-
-  connect( mNotesView, SIGNAL( doubleClicked( QListViewItem*, const QPoint&, int ) \
                ),
-           this, SLOT( editNote( QListViewItem*, const QPoint&, int ) ) );
-  connect( mNotesView, SIGNAL( returnPressed( QListViewItem* ) ),
-           this, SLOT( editNote( QListViewItem* ) ) );
-  connect( mNotesView, SIGNAL( contextMenuRequested( QListViewItem*, const QPoint&, \
                int ) ),
-           this, SLOT( popupRMB( QListViewItem*, const QPoint&, int ) ) );
-  connect( mNotesView, SIGNAL( itemRenamed( QListViewItem*, int, const QString& ) ),
-           this, SLOT( noteRenamed( QListViewItem*, int, const QString& ) ) );
-
-  setWidget( mNotesView );
-
-  mAppIcon = KGlobal::iconLoader()->loadIcon( "knotes", KIcon::Small );
-
-  KParts::InfoExtension *info = new KParts::InfoExtension( this, \
                "KNoteInfoExtension" );
-  connect( this, SIGNAL( noteSelected( const QString& ) ),
-           info, SIGNAL( textChanged( const QString& ) ) );
-  connect( this, SIGNAL( noteSelected( const QPixmap& ) ),
-           info, SIGNAL( iconChanged( const QPixmap& ) ) );
+    m_manager->addNewNote( journal );
 
-  setXMLFile( "knotes_part.rc" );
+    showNote( journal->uid() );
 
-  reloadNotes();
+    m_manager->save();
+
+    return journal->uid();
 }
 
-KNotesPart::~KNotesPart()
+QString KNotesPart::newNoteFromClipboard( const QString& name )
 {
+    const QString& text = KApplication::clipboard()->text();
+    return newNote( name, text );
 }
 
-void KNotesPart::reloadNotes()
+void KNotesPart::showNote( const QString& id ) const
 {
-  int pos = mNotesView->itemPos( mNotesView->currentItem() );
-  mNotesView->clear();
-
-  KCal::Journal::List::Iterator it;
-  KCal::Journal::List notes = mCalendar->journals();
-  for ( it = notes.begin(); it != notes.end(); ++it )
-    (void) new NotesItem( mNotesView, (*it) );
+    KNotesIconViewItem *note = m_noteList[id];
+    if ( !note )
+        return;
 
-  mNotesView->setCurrentItem( mNotesView->itemAt( QPoint( 1, pos ) ) );
+    m_notesView->ensureItemVisible( note );
+    m_notesView->setCurrentItem( note );
 }
 
-bool KNotesPart::openFile()
+void KNotesPart::hideNote( const QString& ) const
 {
-  return false;
+    // simply does nothing, there is nothing to hide
 }
 
-void KNotesPart::popupRMB( QListViewItem *item, const QPoint& pos, int )
+void KNotesPart::killNote( const QString& id )
 {
-  mPopupMenu = static_cast<QPopupMenu*>( factory()->container( "notePopup", this ) \
                );
-  if ( !mPopupMenu )
-    return;
-
-  bool state = ( item != 0 );
-  mActionEdit->setEnabled( state );
-  mActionDelete->setEnabled( state );
-
-  mPopupMenu->popup( pos );
+    killNote( id, false );
 }
 
-void KNotesPart::removeNote()
+void KNotesPart::killNote( const QString& id, bool force )
 {
-  NotesItem *item = static_cast<NotesItem*>( mNotesView->currentItem() );
-
-  if ( !item )
-    return;
-
-  if ( !lock() )
-    return;
+    KNotesIconViewItem *note = m_noteList[id];
 
-  mCalendar->deleteJournal( item->journal() );
+    if ( note && !force && KMessageBox::warningContinueCancelList( m_notesView,
+            i18n( "Do you really want to delete this note?" ),
+            m_noteList[id]->text(), i18n("Confirm Delete"),
+            KGuiItem( i18n("Delete"), "editdelete" ) ) == KMessageBox::Continue )
+    {
+        m_manager->deleteNote( m_noteList[id]->journal() );
+        m_manager->save();
+    }
+}
 
-  unlock();
+QString KNotesPart::name( const QString& id ) const
+{
+    KNotesIconViewItem *note = m_noteList[id];
+    if ( note )
+        return note->text();
+    else
+        return QString::null;
 }
 
-void KNotesPart::removeSelectedNotes()
+QString KNotesPart::text( const QString& id ) const
 {
-  QListViewItemIterator it( mNotesView );
-  QPtrList<NotesItem> items;
-  QStringList titles;
+    KNotesIconViewItem *note = m_noteList[id];
+    if ( note )
+        return note->journal()->description();
+    else
+        return QString::null;
+}
 
-  while ( it.current() ) {
-    if ( it.current()->isSelected() ) {
-      NotesItem *item = static_cast<NotesItem*>( it.current() );
-      items.append( item );
-      titles.append( item->journal()->summary() );
+void KNotesPart::setName( const QString& id, const QString& newName )
+{
+    KNotesIconViewItem *note = m_noteList[id];
+    if ( note )
+    {
+        note->setText( newName );
+        m_manager->save();
     }
+}
 
-    ++it;
-  }
+void KNotesPart::setText( const QString& id, const QString& newText )
+{
+    KNotesIconViewItem *note = m_noteList[id];
+    if ( note )
+    {
+        note->journal()->setDescription( newText );
+        m_manager->save();
+    }
+}
 
-  if ( items.isEmpty() )
-    return;
+QMap<QString, QString> KNotesPart::notes() const
+{
+    QMap<QString, QString> notes;
+    QDictIterator<KNotesIconViewItem> it( m_noteList );
 
-  if ( !lock() )
-    return;
+    for ( ; it.current(); ++it )
+        notes.insert( (*it)->journal()->uid(), (*it)->journal()->description() );
 
-  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() ),
-      titles,
-      i18n( "Confirm Delete" ),
-      KGuiItem( i18n( "Delete" ), "editdelete")
-      );
-
-  if ( ret == KMessageBox::Continue ) {
-    QPtrListIterator<NotesItem> itemIt( items );
-    NotesItem *item;
-    while ( (item = itemIt.current()) != 0 ) {
-      ++itemIt;
+    return notes;
+}
 
-      mCalendar->deleteJournal( item->journal() );
+// TODO KDE 4.0: remove
 
-      delete item;
-    }
-  }
+void KNotesPart::sync( const QString& )
+{
+}
 
-  unlock();
+bool KNotesPart::isNew( const QString&, const QString& ) const
+{
+    return true;
 }
 
-void KNotesPart::renameNote()
+bool KNotesPart::isModified( const QString&, const QString& ) const
 {
-  if ( mNotesView->currentItem() )
-    mNotesView->currentItem()->startRename( 0 );
+    return true;
 }
 
-void KNotesPart::noteRenamed( QListViewItem *i, int,  const QString& )
+
+// private stuff
+
+void KNotesPart::killSelectedNotes()
 {
-  NotesItem *item = static_cast<NotesItem*>( i );
+    QPtrList<KNotesIconViewItem> items;
+    QStringList notes;
 
-  if ( !item )
-    return;
+    KNotesIconViewItem *knivi;
+    for ( QIconViewItem *it = m_notesView->firstItem(); it; it = it->nextItem() )
+    {
+        if ( it->isSelected() )
+        {
+            knivi = static_cast<KNotesIconViewItem *>( it );
+            items.append( knivi );
+            notes.append( knivi->text() );
+        }
+    }
 
-  if ( !lock() )
-    return;
+    if ( items.isEmpty() )
+        return;
 
-  unlock();
-}
+//   if ( !lock() )
+//     return;
 
-void KNotesPart::editNote( QListViewItem *i, const QPoint&, int column )
-{
-  if ( column == 1 )
-    editNote( i );
+    int ret = KMessageBox::warningContinueCancelList( m_notesView,
+            i18n( "Do you really want to delete this note?",
+                  "Do you really want to delete these %n notes?", items.count() ),
+            notes, i18n("Confirm Delete"),
+            KGuiItem( i18n("Delete"), "editdelete" )
+                                                    );
+
+    if ( ret == KMessageBox::Continue )
+    {
+        QPtrListIterator<KNotesIconViewItem> kniviIt( items );
+        while ( (knivi = *kniviIt) )
+        {
+            ++kniviIt;
+            m_manager->deleteNote( knivi->journal() );
+        }
+        m_manager->save();
+    }
+
+//   unlock();
 }
 
-void KNotesPart::editNote( QListViewItem *i )
+void KNotesPart::popupRMB( QIconViewItem *item, const QPoint& pos )
 {
-  NotesItem *item = static_cast<NotesItem*>( i );
+    if ( !m_context_menu )
+        m_context_menu = static_cast<QPopupMenu *>(factory()->container( \
"note_context", this ));  
-  if ( !item )
-    return;
+    if ( !m_context_menu || !item )
+        return;
 
-  if ( !lock() )
-    return;
+    m_context_menu->popup( pos );
+}
 
-  NoteEditDialog dlg( mNotesView, item->journal()->description() );
-  if ( dlg.exec() ) {
-    item->journal()->setDescription( dlg.text() );
-  }
+void KNotesPart::slotOnItem( QIconViewItem *i )
+{
+    // TODO: disable (i.e. setNote( QString::null )) when mouse button pressed
 
-  unlock();
+    KNotesIconViewItem *item = static_cast<KNotesIconViewItem *>(i);
+    m_noteTip->setNote( item, Qt::AutoText );
 }
 
-void KNotesPart::newNote()
+void KNotesPart::slotOnViewport()
 {
-  bool ok;
-  QString title = KInputDialog::getText( i18n( "New Note" ),
-                                         i18n( "Enter title for the note:" ),
-                                         KGlobal::locale()->formatDateTime( \
                QDateTime::currentDateTime() ),
-                                         &ok );
-  if ( !ok )
-    return;
+    m_noteTip->setNote( 0 );
+}
 
-  if ( !lock() )
-    return;
+// TODO: also with takeItem, clear(),
 
-  NoteEditDialog dlg( mNotesView, "" );
-  if ( dlg.exec() ) {
-    KCal::Journal* journal = new KCal::Journal();
-    mCalendar->addJournal( journal );
-    journal->setSummary( title );
-    journal->setDescription( dlg.text() );
-    (void) new NotesItem( mNotesView, journal );
-  }
+// create and kill the icon view item corresponding to the note, edit the note
 
-  unlock();
+void KNotesPart::createNote( KCal::Journal *journal )
+{
+    m_noteList.insert( journal->uid(), new KNotesIconViewItem( m_notesView, journal \
) );  }
 
-void KNotesPart::slotCalendarChanged()
+void KNotesPart::killNote( KCal::Journal *journal )
 {
-  reloadNotes();
+    m_noteList.remove( journal->uid() );
 }
 
-bool KNotesPart::lock()
+void KNotesPart::editNote( QIconViewItem *item )
 {
-  if ( mTicket ) // we still have a valid ticket
-    return true;
-
-  mTicket = mCalendar->requestSaveTicket( mResource );
+    if ( !m_noteEditDlg )
+        m_noteEditDlg = new KNoteEditDlg( widget() );
 
-  bool ok = (mTicket != 0);
+    KCal::Journal *journal = static_cast<KNotesIconViewItem *>(item)->journal();
+    m_noteEditDlg->setText( journal->description() );
+    if ( m_noteEditDlg->exec() == QDialog::Accepted )
+        journal->setDescription( m_noteEditDlg->text() );
 
-  if ( !ok )
-    KMessageBox::error( mNotesView,
-                        i18n( "Unable to access the notes, make sure no other \
                program uses them." ) );
-
-  return ok;
+    m_manager->save();
 }
 
-bool KNotesPart::unlock()
+void KNotesPart::renameNote()
 {
-  if ( !mTicket ) {
-    kdError() << "save with null ticket" << endl;
-    return false;
-  }
-
-  mCalendar->save( mTicket );
-  mTicket = 0;
+    m_notesView->currentItem()->rename();
+}
 
-  return true;
+void KNotesPart::renamedNote( QIconViewItem * )
+{
+    m_manager->save();
 }
 
 #include "knotes_part.moc"
+#include "knotes_part_p.moc"
Index: kontact/plugins/knotes/knotes_part.h
===================================================================
RCS file: /home/kde/kdepim/kontact/plugins/knotes/knotes_part.h,v
retrieving revision 1.14
diff -u -3 -p -r1.14 knotes_part.h
--- kontact/plugins/knotes/knotes_part.h	18 Jan 2004 01:24:20 -0000	1.14
+++ kontact/plugins/knotes/knotes_part.h	31 Aug 2004 08:52:08 -0000
@@ -1,6 +1,7 @@
 /*
    This file is part of the KDE project
    Copyright (C) 2002 Daniel Molkentin <molkentin@kde.org>
+   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
@@ -18,65 +19,90 @@
    Boston, MA 02111-1307, USA.
 */
 
-#ifndef KNOTE_PART_H
-#define KNOTE_PART_H
+#ifndef KNOTES_PART_H
+#define KNOTES_PART_H
 
-#include <qmap.h>
-#include <qpixmap.h>
+#include <qdict.h>
+
+#include <kiconview.h>
+#include <kglobal.h>
+#include <kiconloader.h>
+
+#include <libkcal/journal.h>
 #include <kparts/part.h>
-#include <libkcal/resourcelocal.h>
-#include <libkcal/calendarresources.h>
 
-typedef QMap<QString, QString> NotesMap;
+#include "knotes/KNotesIface.h"
 
-class KAction;
-class KListView;
+class KIconView;
+class QIconViewItem;
+class KNotesIconViewItem;
+class KNoteTip;
+class KNoteEditDlg;
+class KNotesResourceManager;
 
-class QListViewItem;
-class QPoint;
+namespace KCal {
+    class Journal;
+}
 
-class KNotesPart : public KParts::ReadOnlyPart
-{
-  Q_OBJECT
 
-  public:
+class KNotesPart : public KParts::ReadOnlyPart, virtual public KNotesIface
+{
+    Q_OBJECT
+public:
     KNotesPart( QObject *parent = 0, const char *name = 0 );
-    ~KNotesPart();
+   ~KNotesPart();
 
     bool openFile();
 
-  public slots:
-    void newNote();
+public slots:
+    QString newNote( const QString& name = QString::null,
+                     const QString& text = QString::null );
+    QString newNoteFromClipboard( const QString& name = QString::null );
+
+public:
+    void showNote( const QString& id ) const;
+    void hideNote( const QString& id ) const;
+
+    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;
+
+// TODO: remove for KDE 4.0
+    void sync( const QString& app );
+    bool isNew( const QString& app, const QString& id ) const;
+    bool isModified( const QString& app, const QString& id ) const;
+
+private slots:
+    void createNote( KCal::Journal *journal );
+    void killNote( KCal::Journal *journal );
+
+    void editNote( QIconViewItem *item );
 
-  signals:
-    void noteSelected( const QString &name );
-    void noteSelected( const QPixmap &pixmap );
-
-  protected slots:
-    void noteRenamed( QListViewItem *item, int col, const QString& text );
-    void popupRMB( QListViewItem *item, const QPoint& pos, int );
-    void removeNote();
-    void removeSelectedNotes();
     void renameNote();
-    void editNote( QListViewItem* item, const QPoint&, int );
-    void editNote( QListViewItem* item );
-    void reloadNotes();
-    void slotCalendarChanged();
-
-  private:
-    bool lock();
-    bool unlock();
-
-    KCal::ResourceLocal *mResource;
-    KCal::CalendarResources *mCalendar;
-    KCal::CalendarResources::Ticket *mTicket;
-
-    KAction *mActionEdit;
-    KAction *mActionDelete;
-
-    KListView *mNotesView;
-    QPixmap mAppIcon;
-    QPopupMenu *mPopupMenu;
+    void renamedNote( QIconViewItem *item );
+
+    void slotOnItem( QIconViewItem *item );
+    void slotOnViewport();
+
+    void popupRMB( QIconViewItem *item, const QPoint& pos );
+    void killSelectedNotes();
+
+private:
+    KIconView *m_notesView;
+    KNoteTip *m_noteTip;
+    KNoteEditDlg *m_noteEditDlg;
+    QPopupMenu *m_context_menu;
+
+    KNotesResourceManager *m_manager;
+    QDict<KNotesIconViewItem> m_noteList;
 };
 
+
 #endif
Index: kontact/plugins/knotes/knotes_part.rc
===================================================================
RCS file: /home/kde/kdepim/kontact/plugins/knotes/knotes_part.rc,v
retrieving revision 1.3
diff -u -3 -p -r1.3 knotes_part.rc
--- kontact/plugins/knotes/knotes_part.rc	5 Jul 2003 13:54:04 -0000	1.3
+++ kontact/plugins/knotes/knotes_part.rc	31 Aug 2004 08:52:08 -0000
@@ -1,28 +1,15 @@
 <!DOCTYPE kpartgui>
-<kpartgui name="knotes" version="1">
-
+<kpartgui name="knotes" version="2">
   <MenuBar>
     <Menu name="edit"><text>&amp;Edit</text>
       <Action name="edit_rename"/>
       <Action name="edit_delete"/>
     </Menu>
-    
-    <Menu name="view"><text>&amp;View</text>
-      <Action name="view_refresh"/>
-    </Menu>
   </MenuBar>
 
-  <Menu name="notePopup">
+  <Menu name="note_context">
     <Action name="file_new"/>
     <Action name="edit_rename"/>
     <Action name="edit_delete"/>
-    <Separator/>
-   <Action name="view_refresh"/>
   </Menu>
-
-  <ToolBar name="mainToolBar" noMerge="1"><text>Main Toolbar</text>
-    <Merge/>
-    <Action name="view_refresh"/>
-  </ToolBar>
-  
 </kpartgui>
Index: kontact/plugins/knotes/knotes_part_p.h
===================================================================
RCS file: kontact/plugins/knotes/knotes_part_p.h
diff -N kontact/plugins/knotes/knotes_part_p.h
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ kontact/plugins/knotes/knotes_part_p.h	31 Aug 2004 08:52:08 -0000
@@ -0,0 +1,135 @@
+/*
+   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., 59 Temple Place - Suite 330,
+   Boston, MA 02111-1307, 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 <kactioncollection.h>
+#include <klocale.h>
+#include <kiconview.h>
+#include <kglobal.h>
+#include <kiconloader.h>
+#include <ktoolbar.h>
+#include <kpopupmenu.h>
+#include <kdialogbase.h>
+#include <kxmlguiclient.h>
+#include <kxmlguifactory.h>
+#include <kxmlguibuilder.h>
+
+#include <libkcal/journal.h>
+
+#include "knotes/knoteedit.h"
+
+
+class KNotesIconViewItem : public KIconViewItem
+{
+public:
+    KNotesIconViewItem( KIconView *parent, KCal::Journal *journal )
+      : KIconViewItem( parent ),
+        m_journal( journal )
+    {
+        setRenameEnabled( true );
+
+        setPixmap( KGlobal::iconLoader()->loadIcon( "knotes", KIcon::Desktop ) );
+        setText( journal->summary() );
+    }
+
+    KCal::Journal *journal()
+    {
+        return m_journal;
+    }
+
+    virtual void setText( const QString & text )
+    {
+        KIconViewItem::setText( text );
+        m_journal->setSummary( text );
+    }
+
+    virtual QString text() const
+    {
+        return m_journal->summary();
+    }
+
+private:
+    KCal::Journal *m_journal;
+};
+
+
+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 );
+
+        m_noteEdit = new KNoteEdit( actionCollection(), page );
+        m_noteEdit->setFocus();
+
+        KXMLGUIBuilder builder( page );
+        KXMLGUIFactory factory( &builder, this );
+        factory.addClient( this );
+
+        m_tool = static_cast<KToolBar *>(factory.container( "note_tool", this ));
+
+        layout->addWidget( m_tool );
+        layout->addWidget( m_noteEdit );
+    }
+
+    QString text() const
+    {
+        return m_noteEdit->text();
+    }
+
+    void setText( const QString& text )
+    {
+        m_noteEdit->setText( text );
+    }
+
+private:
+    KNoteEdit  *m_noteEdit;
+    KToolBar   *m_tool;
+    KPopupMenu *m_edit_menu;
+};
+
+
+#endif
Index: kontact/plugins/knotes/knotetip.cpp
===================================================================
RCS file: kontact/plugins/knotes/knotetip.cpp
diff -N kontact/plugins/knotes/knotetip.cpp
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ kontact/plugins/knotes/knotetip.cpp	31 Aug 2004 08:52:09 -0000
@@ -0,0 +1,210 @@
+/*
+   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., 59 Temple Place - Suite 330,
+   Boston, MA 02111-1307, 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 \
), +      m_filter( false ),
+      m_view( parent ),
+      m_noteIVI( 0 ),
+      m_preview( new QTextEdit( this ) )
+{
+    m_preview->setReadOnly( true );
+    m_preview->setHScrollBarMode( QScrollView::AlwaysOff );
+    m_preview->setVScrollBarMode( QScrollView::AlwaysOff );
+
+    QBoxLayout *layout = new QVBoxLayout( this );
+    layout->addWidget( m_preview );
+
+    setPalette( QToolTip::palette() );
+    setMargin( 1 );
+    setFrameStyle( QFrame::Plain | QFrame::Box );
+    hide();
+}
+
+KNoteTip::~KNoteTip()
+{
+    delete m_preview;
+}
+
+void KNoteTip::setNote( KNotesIconViewItem *item, TextFormat format )
+{
+    if ( m_noteIVI == item && m_format == format )
+        return;
+
+    m_noteIVI = item;
+    m_format = format;
+
+    if ( !m_noteIVI )
+    {
+        killTimers();
+        if ( isVisible() )
+        {
+            setFilter( false );
+            hide();
+        }
+    }
+    else
+    {
+        m_preview->setTextFormat( format );
+        m_preview->setText( item->journal()->description() );
+        m_preview->zoomTo( 6 );
+        m_preview->sync();
+
+        int w = 400;
+        int h = m_preview->heightForWidth( w );
+        while ( w > 60 && h == m_preview->heightForWidth( w - 20 ) )
+            w -= 20;
+
+        QRect desk = KGlobalSettings::desktopGeometry( m_noteIVI->rect().center() );
+        resize( w, QMIN(h, desk.height()/2 - 20) );
+
+        hide();
+        killTimers();
+        setFilter( true );
+        startTimer( 700 );  // 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::setFilter( bool enable )
+{
+    if ( enable == m_filter )
+        return;
+
+    if ( enable )
+    {
+        kapp->installEventFilter( this );
+        QApplication::setGlobalMouseTracking( true );
+    }
+    else
+    {
+        QApplication::setGlobalMouseTracking( false );
+        kapp->removeEventFilter( this );
+    }
+
+    m_filter = enable;
+}
+
+void KNoteTip::reposition()
+{
+    if ( !m_noteIVI )
+        return;
+
+    QRect rect = m_noteIVI->rect();
+    QPoint off = m_view->mapToGlobal( m_view->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();
+}
Index: kontact/plugins/knotes/knotetip.h
===================================================================
RCS file: kontact/plugins/knotes/knotetip.h
diff -N kontact/plugins/knotes/knotetip.h
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ kontact/plugins/knotes/knotetip.h	31 Aug 2004 08:52:09 -0000
@@ -0,0 +1,70 @@
+/*
+   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., 59 Temple Place - Suite 330,
+   Boston, MA 02111-1307, 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, Qt::TextFormat format = Qt::PlainText );
+
+protected:
+    virtual bool eventFilter( QObject *, QEvent *e );
+    virtual void timerEvent( QTimerEvent * );
+    virtual void resizeEvent( QResizeEvent * );
+
+private:
+    void setFilter( bool enable );
+    void reposition();
+
+private:
+    bool m_filter;
+
+    KIconView *m_view;
+    KNotesIconViewItem *m_noteIVI;
+
+    QTextEdit *m_preview;
+    Qt::TextFormat m_format;
+};
+
+
+#endif


[Attachment #8 (application/pgp-signature)]

_______________________________________________
kde-pim mailing list
kde-pim@mail.kde.org
https://mail.kde.org/mailman/listinfo/kde-pim
kde-pim home page at http://pim.kde.org/

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic