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

List:       kde-pim
Subject:    [Kde-pim] [PATCH] KNotes-Part in Kontact
From:       Tobias Koenig <tokoe () kde ! org>
Date:       2003-11-27 14:47:08
[Download RAW message or body]

[Attachment #2 (multipart/signed)]

[Attachment #4 (multipart/mixed)]


Hi,

This patch lets the KNotes-Part in Kontact make use of CalendarResources
to access the knotes data instead of starting the standalone app and
talk with it via dcop. That should fix at least 1 bug...
Ok for commit?

Ciao,
Tobias
--=20
Can a government that shoots at reporters be democratic?
Separate politics from religion and economy!

["kontact_knotes_with_calendarresources.patch" (text/plain)]

Index: knotes_part.cpp
===================================================================
RCS file: /home/kde/kdepim/kontact/plugins/knotes/knotes_part.cpp,v
retrieving revision 1.23
diff -p -u -b -r1.23 knotes_part.cpp
--- knotes_part.cpp	14 Nov 2003 12:21:47 -0000	1.23
+++ knotes_part.cpp	27 Nov 2003 14:28:07 -0000
@@ -22,8 +22,6 @@
 #include <qsplitter.h>
 #include <qtextedit.h>
 
-#include <dcopclient.h>
-#include <dcopref.h>
 #include <kaction.h>
 #include <kapplication.h>
 #include <kdebug.h>
@@ -34,6 +32,9 @@
 #include <kstandarddirs.h>
 #include <kstdaction.h>
 #include <kxmlguifactory.h>
+
+#include <libkcal/icalformat.h>
+
 #include <libkdepim/infoextension.h>
 #include <libkdepim/sidebarextension.h>
 
@@ -42,39 +43,40 @@
 class NotesItem : public KListViewItem
 {
   public:
-    NotesItem( KListView *parent, const QString &id, const QString &text );
-    QString id() { return noteID; };
+    NotesItem( KListView *parent, KCal::Journal *journal );
+    KCal::Journal* journal() { return mJournal; }
+
   private:
-    QString noteID;
+    KCal::Journal* mJournal;
 };
 
-NotesItem::NotesItem( KListView *parent, const QString &id, const QString &text )
-  :	KListViewItem( parent, text )
+NotesItem::NotesItem( KListView *parent, KCal::Journal *journal )
+  :	KListViewItem( parent, journal->summary() )
 {
-  noteID = id;
+  mJournal = journal;
   setRenameEnabled( 0, true );
-
   setPixmap( 0, KGlobal::iconLoader()->loadIcon( "knotes", KIcon::Small ) );
 }
 
 KNotesPart::KNotesPart( QObject *parent, const char *name )
   : KParts::ReadOnlyPart( parent, name ),
-    mPopupMenu( 0 ),
-    mNoteChanged( false )
+    mPopupMenu( 0 )
 {
   setInstance( new KInstance( "knotes" ) );
 
+  mCalendar = new KCal::CalendarResources;
+  mResource = new KCal::ResourceLocal( ::locate( "data", "knotes/notes.ics" ) );
+  mCalendar->resourceManager()->add( mResource );
+  mCalendar->load();
 
-  mICal = new KCal::CalendarLocal;
-  connect(mICal, SIGNAL(calendarChanged()), SLOT(slotCalendarChanged()));
-  mICal->load(::locate("data", "knotes/notes.ics"));
-  mNotes = mICal->journals();
+  connect( mCalendar, SIGNAL( calendarChanged() ), SLOT( slotCalendarChanged() ) );
 
   QSplitter *splitter = new QSplitter( Qt::Horizontal );
 
   mNotesView = new KListView( splitter );
   mNotesView->setSelectionMode( QListView::Extended );
   mNotesView->addColumn( i18n( "Title" ) );
+  mNotesView->setResizeMode( QListView::LastColumn );
 
   (void) new KParts::SideBarExtension( mNotesView, this, "NotesSideBarExtension" );
 
@@ -99,7 +101,6 @@ KNotesPart::KNotesPart( QObject *parent,
   connect( mNotesEdit, SIGNAL( textChanged() ),
            this, SLOT( noteChanged() ) );
 
-  reloadNotes();
   setWidget( splitter );
 
   mAppIcon = KGlobal::iconLoader()->loadIcon( "knotes", KIcon::Small );
@@ -111,48 +112,40 @@ KNotesPart::KNotesPart( QObject *parent,
            info, SIGNAL( iconChanged( const QPixmap& ) ) );
 
   setXMLFile( "knotes_part.rc" );
+
+  reloadNotes();
 }
 
 KNotesPart::~KNotesPart()
 {
-  saveNote();
+  mCalendar->save( mTicket );
+  mTicket = 0;
 }
 
 void KNotesPart::reloadNotes()
 {
-  if ( !kapp->dcopClient()->isApplicationRegistered( "knotes" ) ) {
-    QString *error = 0;
-    int started  = KApplication::startServiceByDesktopName( "knotes",
-                                                            QString(), error );
-
-    if ( started > 0 ) {
-      if ( error )
-        KMessageBox::error( 0L, *error, i18n( "Error" ) );
-      return;
-    }
-
-    delete error;
-  }
-
+  mNotesEdit->blockSignals( true );
   mNotesView->clear();
 
-  NotesMap map;
-
-  QCString replyType;
-  QByteArray data, replyData;
-  QDataStream arg( data, IO_WriteOnly );
-  if ( kapp->dcopClient()->call( "knotes", "KNotesIface", "notes()", data, \
                replyType, replyData ) ) {
-    kdDebug(5602) << "Reply Type: " << replyType << endl;
-    QDataStream answer( replyData, IO_ReadOnly );
-    answer >> map;
+  if ( !mTicket ) {
+    // lock the resource here and release it in d'tor
+    mTicket = mCalendar->requestSaveTicket( mResource );
+    if ( !mTicket ) {
+/*    TODO: Enable this after i18n freez
+      KMessageBox::error( this, i18n( "Unable to get lock for %1. Make sure no other \
program is using it!" ) +                          .arg( ::locate( "data", \
"knotes/notes.ics" ) ) ); +*/
+      return;
+    }
   }
 
-  NotesMap::ConstIterator it;
-  for ( it = map.begin(); it != map.end(); ++it )
-    (void) new NotesItem( mNotesView, it.key(), it.data() );
+  KCal::Journal::List::Iterator it;
+  KCal::Journal::List notes = mCalendar->journals();
+  for ( it = notes.begin(); it != notes.end(); ++it )
+    (void) new NotesItem( mNotesView, (*it) );
 
-  mNotesView->setCurrentItem( mNotesView->firstChild() );
   showNote( mNotesView->firstChild() );
+  mNotesEdit->blockSignals( false );
 }
 
 bool KNotesPart::openFile()
@@ -180,46 +173,47 @@ void KNotesPart::removeNote()
   if ( !item )
     return;
 
-  DCOPRef dcopCall( "knotes", "KNotesIface" );
-  dcopCall.call( "killNote(QString, bool)", item->id(), true );
+  mCalendar->deleteJournal( item->journal() );
 
   reloadNotes();
 }
 
 void KNotesPart::removeSelectedNotes()
 {
-  QStringList ids;
-  QStringList names;
-
   QListViewItemIterator it( mNotesView );
+  QPtrList<NotesItem> items;
+  QStringList titles;
+
   while ( it.current() ) {
     if ( it.current()->isSelected() ) {
-      ids += static_cast<NotesItem*>( it.current() )->id();
-      names += it.current()->text( 0 );
+      NotesItem *item = static_cast<NotesItem*>( it.current() );
+      items.append( item );
+      titles.append( item->journal()->summary() );
     }
 
     ++it;
   }
 
-  if ( ids.isEmpty() )
+  if ( items.isEmpty() )
     return;
 
-  if ( ids.count() == 1 ) {
-    DCOPRef dcopCall( "knotes", "KNotesIface" );
-    dcopCall.call( "killNote(QString)", ids.first() );
-  } else {
     int ret = KMessageBox::warningContinueCancelList( 0,
-        i18n( "Do you really want to delete that note?", "Do you really want to \
                delete these %n notes?", ids.count() ),
-        names,
+      i18n( "Do you really want to delete that note?", 
+            "Do you really want to delete these %n notes?", items.count() ),
+      titles,
         i18n( "Confirm Delete" ),
-        i18n( "Delete" ) );
+      i18n( "Delete" )
+      );
+
+  if ( ret == KMessageBox::Continue ) {
+    QPtrListIterator<NotesItem> itemIt( items );
+    NotesItem *item;
+    while ( (item = itemIt.current()) != 0 ) {
+      ++itemIt;
 
-    int doIt = ( ret == KMessageBox::Continue );
+      mCalendar->deleteJournal( item->journal() );
 
-    if ( doIt )
-      for ( QStringList::ConstIterator it = ids.begin(); it != ids.end(); ++it ) {
-        DCOPRef dcopCall( "knotes", "KNotesIface" );
-        dcopCall.call( "killNote(QString, bool)", *it, true );
+      delete item;
       }
   }
 
@@ -239,8 +233,7 @@ void KNotesPart::noteRenamed( QListViewI
   if ( !item )
     return;
 
-  DCOPRef dcopCall( "knotes", "KNotesIface" );
-  dcopCall.send( "setName(QString,QString)", item->id(), text );
+  item->journal()->setSummary( text );
 }
 
 void KNotesPart::showNote()
@@ -250,52 +243,44 @@ void KNotesPart::showNote()
 
 void KNotesPart::showNote( QListViewItem *i )
 {
-  if ( !mCurrentNote.isEmpty() ) {
-    if ( mNoteChanged )
-      saveNote();
-  }
-
+  mNotesEdit->blockSignals( true );
   mNotesEdit->clear();
+  mNotesEdit->blockSignals( false );
 
   NotesItem *item = static_cast<NotesItem*>( i );
-  if ( !item ) {
-    mCurrentNote = "";
-    return;
-  }
 
-  mCurrentNote = item->id();
+  if ( !item ) return;
 
-  DCOPRef dcopCall( "knotes", "KNotesIface" );
   mNotesEdit->blockSignals( true );
-  mNotesEdit->setText( dcopCall.call( "text(QString)", item->id() ) );
+  mNotesEdit->setText( item->journal()->description() );
   mNotesEdit->blockSignals( false );
-
-  emit noteSelected( item->text( 0 ) );
-  emit noteSelected( mAppIcon );
 }
 
 void KNotesPart::noteChanged()
 {
-  mNoteChanged = true;  
-}
+  NotesItem *item = static_cast<NotesItem*>( mNotesView->currentItem() );
 
-void KNotesPart::saveNote()
-{
-  if ( mCurrentNote.isEmpty() )
+  if ( !item )
     return;
 
-  DCOPRef dcopCall( "knotes", "KNotesIface" );
-  dcopCall.send( "setText(QString,QString)", mCurrentNote, mNotesEdit->text() );
-
-  mNoteChanged = false;
+  item->journal()->setDescription( mNotesEdit->text() );
 }
 
 void KNotesPart::newNote()
 {
-  DCOPRef dcopCall( "knotes", "KNotesIface" );
-  dcopCall.call( "newNote(QString, QString)", QString::null, QString::null );
+  KCal::Journal* journal = new KCal::Journal();
+  mCalendar->addJournal( journal );
+
+  KLocale *locale = KGlobal::locale();
+  journal->setSummary( locale->formatDateTime( QDateTime::currentDateTime() ) );
+  (void) new NotesItem( mNotesView, journal );
 
   reloadNotes();
 }
 
+void KNotesPart::slotCalendarChanged()
+{
+  // this should never be called because we have the lock...
+}
+
 #include "knotes_part.moc"
Index: knotes_part.h
===================================================================
RCS file: /home/kde/kdepim/kontact/plugins/knotes/knotes_part.h,v
retrieving revision 1.13
diff -p -u -b -r1.13 knotes_part.h
--- knotes_part.h	9 Nov 2003 18:54:57 -0000	1.13
+++ knotes_part.h	27 Nov 2003 14:28:07 -0000
@@ -24,7 +24,8 @@
 #include <qmap.h>
 #include <qpixmap.h>
 #include <kparts/part.h>
-#include <libkcal/calendarlocal.h>
+#include <libkcal/resourcelocal.h>
+#include <libkcal/calendarresources.h>
 
 typedef QMap<QString, QString> NotesMap;
 
@@ -61,12 +62,13 @@ class KNotesPart : public KParts::ReadOn
     void showNote();
     void showNote( QListViewItem* item );
     void noteChanged();
-    void saveNote();
     void reloadNotes();
+    void slotCalendarChanged();
 
   private:
-    KCal::CalendarLocal *mICal;
-    KCal::Journal::List mNotes;
+    KCal::ResourceLocal *mResource;
+    KCal::CalendarResources *mCalendar;
+    KCal::CalendarResources::Ticket *mTicket;
 
     KAction *mActionEdit;
     KAction *mActionDelete;
@@ -75,9 +77,6 @@ class KNotesPart : public KParts::ReadOn
     QTextEdit *mNotesEdit;
     QPixmap mAppIcon;
     QPopupMenu *mPopupMenu;
-
-    bool mNoteChanged;
-    QString mCurrentNote;
 };
 
 #endif


["signature.asc" (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