From kde-pim Thu Nov 27 14:47:08 2003 From: Tobias Koenig Date: Thu, 27 Nov 2003 14:47:08 +0000 To: kde-pim Subject: [Kde-pim] [PATCH] KNotes-Part in Kontact X-MARC-Message: https://marc.info/?l=kde-pim&m=106994463331657 MIME-Version: 1 Content-Type: multipart/mixed; boundary="--===============0938536619==" --===============0938536619== Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="OzxllxdKGCiKxUZM" Content-Disposition: inline --OzxllxdKGCiKxUZM Content-Type: multipart/mixed; boundary="Lb0e7rgc7IsuDeGj" Content-Disposition: inline --Lb0e7rgc7IsuDeGj Content-Type: text/plain; charset=iso-8859-15 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable 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! --Lb0e7rgc7IsuDeGj Content-Type: text/plain; charset=iso-8859-15 Content-Disposition: attachment; filename="kontact_knotes_with_calendarresources.patch" Content-Transfer-Encoding: quoted-printable Index: knotes_part.cpp =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D 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 #include =20 -#include -#include #include #include #include @@ -34,6 +32,9 @@ #include #include #include + +#include + #include #include =20 @@ -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; }; =20 -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 =3D id; + mJournal =3D journal; setRenameEnabled( 0, true ); - setPixmap( 0, KGlobal::iconLoader()->loadIcon( "knotes", KIcon::Small ) = ); } =20 KNotesPart::KNotesPart( QObject *parent, const char *name ) : KParts::ReadOnlyPart( parent, name ), - mPopupMenu( 0 ), - mNoteChanged( false ) + mPopupMenu( 0 ) { setInstance( new KInstance( "knotes" ) ); =20 + mCalendar =3D new KCal::CalendarResources; + mResource =3D new KCal::ResourceLocal( ::locate( "data", "knotes/notes.i= cs" ) ); + mCalendar->resourceManager()->add( mResource ); + mCalendar->load(); =20 - mICal =3D new KCal::CalendarLocal; - connect(mICal, SIGNAL(calendarChanged()), SLOT(slotCalendarChanged())); - mICal->load(::locate("data", "knotes/notes.ics")); - mNotes =3D mICal->journals(); + connect( mCalendar, SIGNAL( calendarChanged() ), SLOT( slotCalendarChang= ed() ) ); =20 QSplitter *splitter =3D new QSplitter( Qt::Horizontal ); =20 mNotesView =3D new KListView( splitter ); mNotesView->setSelectionMode( QListView::Extended ); mNotesView->addColumn( i18n( "Title" ) ); + mNotesView->setResizeMode( QListView::LastColumn ); =20 (void) new KParts::SideBarExtension( mNotesView, this, "NotesSideBarExte= nsion" ); =20 @@ -99,7 +101,6 @@ KNotesPart::KNotesPart( QObject *parent, connect( mNotesEdit, SIGNAL( textChanged() ), this, SLOT( noteChanged() ) ); =20 - reloadNotes(); setWidget( splitter ); =20 mAppIcon =3D KGlobal::iconLoader()->loadIcon( "knotes", KIcon::Small ); @@ -111,48 +112,40 @@ KNotesPart::KNotesPart( QObject *parent, info, SIGNAL( iconChanged( const QPixmap& ) ) ); =20 setXMLFile( "knotes_part.rc" ); + + reloadNotes(); } =20 KNotesPart::~KNotesPart() { - saveNote(); + mCalendar->save( mTicket ); + mTicket =3D 0; } =20 void KNotesPart::reloadNotes() { - if ( !kapp->dcopClient()->isApplicationRegistered( "knotes" ) ) { - QString *error =3D 0; - int started =3D KApplication::startServiceByDesktopName( "knotes", - QString(), err= or ); - - if ( started > 0 ) { - if ( error ) - KMessageBox::error( 0L, *error, i18n( "Error" ) ); - return; - } - - delete error; - } - + mNotesEdit->blockSignals( true ); mNotesView->clear(); =20 - 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 =3D mCalendar->requestSaveTicket( mResource ); + if ( !mTicket ) { +/* TODO: Enable this after i18n freez + KMessageBox::error( this, i18n( "Unable to get lock for %1. Make sur= e no other program is using it!" ) + .arg( ::locate( "data", "knotes/notes.ics" ) ) ); +*/ + return; + } } =20 - NotesMap::ConstIterator it; - for ( it =3D map.begin(); it !=3D map.end(); ++it ) - (void) new NotesItem( mNotesView, it.key(), it.data() ); + KCal::Journal::List::Iterator it; + KCal::Journal::List notes =3D mCalendar->journals(); + for ( it =3D notes.begin(); it !=3D notes.end(); ++it ) + (void) new NotesItem( mNotesView, (*it) ); =20 - mNotesView->setCurrentItem( mNotesView->firstChild() ); showNote( mNotesView->firstChild() ); + mNotesEdit->blockSignals( false ); } =20 bool KNotesPart::openFile() @@ -180,46 +173,47 @@ void KNotesPart::removeNote() if ( !item ) return; =20 - DCOPRef dcopCall( "knotes", "KNotesIface" ); - dcopCall.call( "killNote(QString, bool)", item->id(), true ); + mCalendar->deleteJournal( item->journal() ); =20 reloadNotes(); } =20 void KNotesPart::removeSelectedNotes() { - QStringList ids; - QStringList names; - QListViewItemIterator it( mNotesView ); + QPtrList items; + QStringList titles; + while ( it.current() ) { if ( it.current()->isSelected() ) { - ids +=3D static_cast( it.current() )->id(); - names +=3D it.current()->text( 0 ); + NotesItem *item =3D static_cast( it.current() ); + items.append( item ); + titles.append( item->journal()->summary() ); } =20 ++it; } =20 - if ( ids.isEmpty() ) + if ( items.isEmpty() ) return; =20 - if ( ids.count() =3D=3D 1 ) { - DCOPRef dcopCall( "knotes", "KNotesIface" ); - dcopCall.call( "killNote(QString)", ids.first() ); - } else { int ret =3D KMessageBox::warningContinueCancelList( 0, - i18n( "Do you really want to delete that note?", "Do you really wa= nt to delete these %n notes?", ids.count() ), - names, + i18n( "Do you really want to delete that note?",=20 + "Do you really want to delete these %n notes?", items.count() = ), + titles, i18n( "Confirm Delete" ), - i18n( "Delete" ) ); + i18n( "Delete" ) + ); + + if ( ret =3D=3D KMessageBox::Continue ) { + QPtrListIterator itemIt( items ); + NotesItem *item; + while ( (item =3D itemIt.current()) !=3D 0 ) { + ++itemIt; =20 - int doIt =3D ( ret =3D=3D KMessageBox::Continue ); + mCalendar->deleteJournal( item->journal() ); =20 - if ( doIt ) - for ( QStringList::ConstIterator it =3D ids.begin(); it !=3D ids.end= (); ++it ) { - DCOPRef dcopCall( "knotes", "KNotesIface" ); - dcopCall.call( "killNote(QString, bool)", *it, true ); + delete item; } } =20 @@ -239,8 +233,7 @@ void KNotesPart::noteRenamed( QListViewI if ( !item ) return; =20 - DCOPRef dcopCall( "knotes", "KNotesIface" ); - dcopCall.send( "setName(QString,QString)", item->id(), text ); + item->journal()->setSummary( text ); } =20 void KNotesPart::showNote() @@ -250,52 +243,44 @@ void KNotesPart::showNote() =20 void KNotesPart::showNote( QListViewItem *i ) { - if ( !mCurrentNote.isEmpty() ) { - if ( mNoteChanged ) - saveNote(); - } - + mNotesEdit->blockSignals( true ); mNotesEdit->clear(); + mNotesEdit->blockSignals( false ); =20 NotesItem *item =3D static_cast( i ); - if ( !item ) { - mCurrentNote =3D ""; - return; - } =20 - mCurrentNote =3D item->id(); + if ( !item ) return; =20 - 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 ); } =20 void KNotesPart::noteChanged() { - mNoteChanged =3D true; =20 -} + NotesItem *item =3D static_cast( mNotesView->currentItem() ); =20 -void KNotesPart::saveNote() -{ - if ( mCurrentNote.isEmpty() ) + if ( !item ) return; =20 - DCOPRef dcopCall( "knotes", "KNotesIface" ); - dcopCall.send( "setText(QString,QString)", mCurrentNote, mNotesEdit->tex= t() ); - - mNoteChanged =3D false; + item->journal()->setDescription( mNotesEdit->text() ); } =20 void KNotesPart::newNote() { - DCOPRef dcopCall( "knotes", "KNotesIface" ); - dcopCall.call( "newNote(QString, QString)", QString::null, QString::null= ); + KCal::Journal* journal =3D new KCal::Journal(); + mCalendar->addJournal( journal ); + + KLocale *locale =3D KGlobal::locale(); + journal->setSummary( locale->formatDateTime( QDateTime::currentDateTime(= ) ) ); + (void) new NotesItem( mNotesView, journal ); =20 reloadNotes(); } =20 +void KNotesPart::slotCalendarChanged() +{ + // this should never be called because we have the lock... +} + #include "knotes_part.moc" Index: knotes_part.h =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D 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 #include #include -#include +#include +#include =20 typedef QMap NotesMap; =20 @@ -61,12 +62,13 @@ class KNotesPart : public KParts::ReadOn void showNote(); void showNote( QListViewItem* item ); void noteChanged(); - void saveNote(); void reloadNotes(); + void slotCalendarChanged(); =20 private: - KCal::CalendarLocal *mICal; - KCal::Journal::List mNotes; + KCal::ResourceLocal *mResource; + KCal::CalendarResources *mCalendar; + KCal::CalendarResources::Ticket *mTicket; =20 KAction *mActionEdit; KAction *mActionDelete; @@ -75,9 +77,6 @@ class KNotesPart : public KParts::ReadOn QTextEdit *mNotesEdit; QPixmap mAppIcon; QPopupMenu *mPopupMenu; - - bool mNoteChanged; - QString mCurrentNote; }; =20 #endif --Lb0e7rgc7IsuDeGj-- --OzxllxdKGCiKxUZM Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.3 (GNU/Linux) iD8DBQE/xg5sSvFUKpY6VLARAkEDAKCUJBeGZO5z1HNU1rYP+DfBrS55ogCgvZm0 BaxWO7FTLwDZO3dYHGoWyc4= =3yWX -----END PGP SIGNATURE----- --OzxllxdKGCiKxUZM-- --===============0938536619== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ 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/ --===============0938536619==--