[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-pim
Subject: [Kde-pim] [PATCH] New KNotes-Part patch
From: Tobias Koenig <tokoe () kde ! org>
Date: 2003-11-30 11:26:15
[Download RAW message or body]
[Attachment #2 (multipart/signed)]
[Attachment #4 (multipart/mixed)]
Hi,
this new patch replaces the old one, I sent 2 days ago.
This patch does a more sane locking, so changes (renaming, editing,
removing) are visible in the summary view immediately.
I'm not sure what to do with the new i18n strings... I guess 'Title'
is already used somewhere else in KDE, so can I just use the string here
as well?
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 30 Nov 2003 11:17:56 -0000
@@ -18,22 +18,23 @@
Boston, MA 02111-1307, USA.
*/
+#include <qlayout.h>
#include <qpopupmenu.h>
-#include <qsplitter.h>
#include <qtextedit.h>
-#include <dcopclient.h>
-#include <dcopref.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 <kmessagebox.h>
#include <kstandarddirs.h>
#include <kstdaction.h>
#include <kxmlguifactory.h>
+
#include <libkdepim/infoextension.h>
#include <libkdepim/sidebarextension.h>
@@ -42,44 +43,80 @@
class NotesItem : public KListViewItem
{
public:
- NotesItem( KListView *parent, const QString &id, const QString &text );
- QString id() { return noteID; };
+ 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; }
+
+ virtual void setText( int column, const QString &text )
+ {
+ if ( column == 0 )
+ mJournal->setSummary( text );
+ }
+
+ virtual QString text( int column ) const
+ {
+ if ( column == 0 )
+ return mJournal->summary();
+ else if ( column == 1 )
+ return mJournal->description();
+ else
+ return QString();
+ }
+
private:
- QString noteID;
+ KCal::Journal* mJournal;
};
-NotesItem::NotesItem( KListView *parent, const QString &id, const QString &text )
- : KListViewItem( parent, text )
+class NoteEditDialog : public KDialogBase
{
- noteID = id;
- setRenameEnabled( 0, true );
+ 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 );
- setPixmap( 0, KGlobal::iconLoader()->loadIcon( "knotes", KIcon::Small ) );
-}
+ mTextEdit = new QTextEdit( page );
+ layout->addWidget( mTextEdit );
+
+ mTextEdit->setText( text );
+ mTextEdit->setFocus();
+ }
+
+ QString text() const { return mTextEdit->text(); }
+
+ private:
+ QTextEdit *mTextEdit;
+};
KNotesPart::KNotesPart( QObject *parent, const char *name )
: KParts::ReadOnlyPart( parent, name ),
- mPopupMenu( 0 ),
- mNoteChanged( false )
+ mTicket( 0 ), 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();
-
- QSplitter *splitter = new QSplitter( Qt::Horizontal );
+ connect( mCalendar, SIGNAL( calendarChanged() ), SLOT( slotCalendarChanged() ) );
- mNotesView = new KListView( splitter );
+ 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" );
- mNotesEdit = new QTextEdit( splitter );
-
KStdAction::openNew( this, SLOT( newNote() ), actionCollection() );
mActionEdit = new KAction( i18n( "Rename" ), "editrename", this,
SLOT( renameNote() ), actionCollection(),
@@ -90,17 +127,14 @@ KNotesPart::KNotesPart( QObject *parent,
(void) new KAction( i18n( "Reload" ), "reload", 0, this,
SLOT( reloadNotes() ), actionCollection(), "view_refresh" );
- connect( mNotesView, SIGNAL( selectionChanged() ),
- this, SLOT( showNote() ) );
+ connect( mNotesView, SIGNAL( doubleClicked( QListViewItem*, const QPoint&, int ) \
), + this, SLOT( editNote( QListViewItem*, const QPoint&, int ) ) );
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& ) ) );
- connect( mNotesEdit, SIGNAL( textChanged() ),
- this, SLOT( noteChanged() ) );
- reloadNotes();
- setWidget( splitter );
+ setWidget( mNotesView );
mAppIcon = KGlobal::iconLoader()->loadIcon( "knotes", KIcon::Small );
@@ -111,48 +145,22 @@ KNotesPart::KNotesPart( QObject *parent,
info, SIGNAL( iconChanged( const QPixmap& ) ) );
setXMLFile( "knotes_part.rc" );
+
+ reloadNotes();
}
KNotesPart::~KNotesPart()
{
- saveNote();
}
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;
- }
-
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;
- }
-
- NotesMap::ConstIterator it;
- for ( it = map.begin(); it != map.end(); ++it )
- (void) new NotesItem( mNotesView, it.key(), it.data() );
-
- mNotesView->setCurrentItem( mNotesView->firstChild() );
- showNote( mNotesView->firstChild() );
+ KCal::Journal::List::Iterator it;
+ KCal::Journal::List notes = mCalendar->journals();
+ for ( it = notes.begin(); it != notes.end(); ++it )
+ (void) new NotesItem( mNotesView, (*it) );
}
bool KNotesPart::openFile()
@@ -180,50 +188,57 @@ void KNotesPart::removeNote()
if ( !item )
return;
- DCOPRef dcopCall( "knotes", "KNotesIface" );
- dcopCall.call( "killNote(QString, bool)", item->id(), true );
+ if ( !lock() )
+ return;
+
+ mCalendar->deleteJournal( item->journal() );
- reloadNotes();
+ unlock();
}
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,
+ if ( !lock() )
+ return;
+
+ int ret = KMessageBox::warningContinueCancelList( mNotesView,
+ 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;
}
}
- reloadNotes();
+ unlock();
}
void KNotesPart::renameNote()
@@ -239,63 +254,89 @@ void KNotesPart::noteRenamed( QListViewI
if ( !item )
return;
- DCOPRef dcopCall( "knotes", "KNotesIface" );
- dcopCall.send( "setName(QString,QString)", item->id(), text );
-}
+ if ( !lock() )
+ return;
-void KNotesPart::showNote()
-{
- showNote( mNotesView->currentItem() );
+ unlock();
}
-void KNotesPart::showNote( QListViewItem *i )
+void KNotesPart::editNote( QListViewItem *i, const QPoint&, int column )
{
- if ( !mCurrentNote.isEmpty() ) {
- if ( mNoteChanged )
- saveNote();
- }
-
- mNotesEdit->clear();
+ if ( column != 1 )
+ return;
NotesItem *item = static_cast<NotesItem*>( i );
- if ( !item ) {
- mCurrentNote = "";
+
+ if ( !item )
return;
+
+ if ( !lock() )
+ return;
+
+ NoteEditDialog dlg( mNotesView, item->journal()->description() );
+ if ( dlg.exec() ) {
+ item->journal()->setDescription( dlg.text() );
}
- mCurrentNote = item->id();
+ unlock();
+}
- DCOPRef dcopCall( "knotes", "KNotesIface" );
- mNotesEdit->blockSignals( true );
- mNotesEdit->setText( dcopCall.call( "text(QString)", item->id() ) );
- mNotesEdit->blockSignals( false );
+void KNotesPart::newNote()
+{
+ bool ok;
+ QString title = KInputDialog::getText( "" /* i18n( "Title" ) */,
+ "" /* i18n( "Title" ) */,
+ KGlobal::locale()->formatDateTime( \
QDateTime::currentDateTime() ), + &ok );
+ if ( !ok )
+ return;
+
+ if ( !lock() )
+ return;
- emit noteSelected( item->text( 0 ) );
- emit noteSelected( mAppIcon );
+ NoteEditDialog dlg( mNotesView, "" );
+ if ( dlg.exec() ) {
+ KCal::Journal* journal = new KCal::Journal();
+ mCalendar->addJournal( journal );
+ journal->setSummary( title );
+ journal->setDescription( dlg.text() );
+ }
+
+ unlock();
}
-void KNotesPart::noteChanged()
+void KNotesPart::slotCalendarChanged()
{
- mNoteChanged = true;
+ reloadNotes();
}
-void KNotesPart::saveNote()
+bool KNotesPart::lock()
{
- if ( mCurrentNote.isEmpty() )
- return;
+ if ( mTicket ) // we still have a valid ticket
+ return true;
- DCOPRef dcopCall( "knotes", "KNotesIface" );
- dcopCall.send( "setText(QString,QString)", mCurrentNote, mNotesEdit->text() );
+ mTicket = mCalendar->requestSaveTicket( mResource );
- mNoteChanged = false;
+ bool ok = (mTicket != 0);
+
+ if ( !ok ) {
+// KMessageBox::error( mNotesView, i18n( "Unable to access the notes, are you sure \
no other program uses them?" ) ); + }
+
+ return ok;
}
-void KNotesPart::newNote()
+bool KNotesPart::unlock()
{
- DCOPRef dcopCall( "knotes", "KNotesIface" );
- dcopCall.call( "newNote(QString, QString)", QString::null, QString::null );
+ if ( !mTicket ) {
+ kdError() << "save with null ticket" << endl;
+ return false;
+ }
- reloadNotes();
+ mCalendar->save( mTicket );
+ mTicket = 0;
+
+ return true;
}
#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 30 Nov 2003 11:17:56 -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;
@@ -33,7 +34,6 @@ class KListView;
class QListViewItem;
class QPoint;
-class QTextEdit;
class KNotesPart : public KParts::ReadOnlyPart
{
@@ -58,26 +58,24 @@ class KNotesPart : public KParts::ReadOn
void removeNote();
void removeSelectedNotes();
void renameNote();
- void showNote();
- void showNote( QListViewItem* item );
- void noteChanged();
- void saveNote();
+ void editNote( QListViewItem* item, const QPoint&, int );
void reloadNotes();
+ void slotCalendarChanged();
private:
- KCal::CalendarLocal *mICal;
- KCal::Journal::List mNotes;
+ bool lock();
+ bool unlock();
+
+ KCal::ResourceLocal *mResource;
+ KCal::CalendarResources *mCalendar;
+ KCal::CalendarResources::Ticket *mTicket;
KAction *mActionEdit;
KAction *mActionDelete;
KListView *mNotesView;
- QTextEdit *mNotesEdit;
QPixmap mAppIcon;
QPopupMenu *mPopupMenu;
-
- bool mNoteChanged;
- QString mCurrentNote;
};
#endif
Index: summarywidget.cpp
===================================================================
RCS file: /home/kde/kdepim/kontact/plugins/knotes/summarywidget.cpp,v
retrieving revision 1.13
diff -p -u -b -r1.13 summarywidget.cpp
--- summarywidget.cpp 9 Nov 2003 18:54:57 -0000 1.13
+++ summarywidget.cpp 30 Nov 2003 11:17:56 -0000
@@ -41,10 +41,12 @@ SummaryWidget::SummaryWidget( QWidget *p
{
mMainLayout = new QVBoxLayout( this, 3, 3 );
- mICal = new KCal::CalendarLocal;
+ mCalendar = new KCal::CalendarResources;
+ mResource = new KCal::ResourceLocal( ::locate( "data", "knotes/notes.ics" ) );
+ mCalendar->resourceManager()->add( mResource );
+ mCalendar->load();
- // doesn't get triggered (danimo)
- connect(mICal, SIGNAL(calendarChanged()), SLOT(updateView()));
+ connect( mCalendar, SIGNAL( calendarChanged() ), SLOT( updateView() ) );
QPixmap icon = KGlobal::iconLoader()->loadIcon( "knotes", KIcon::Desktop, \
KIcon::SizeMedium ); QWidget* heading = createHeader( this, icon, i18n( "Notes" ) );
@@ -71,8 +73,7 @@ bool SummaryWidget::ensureKNotesRunning(
void SummaryWidget::updateView()
{
- mICal->load(::locate("data", "knotes/notes.ics"));
- mNotes = mICal->journals();
+ mNotes = mCalendar->journals();
delete mLayout;
mLayout = new QVBoxLayout( mMainLayout );
@@ -98,8 +99,7 @@ void SummaryWidget::updateView()
void SummaryWidget::urlClicked( const QString &uid )
{
- if (ensureKNotesRunning())
- {
+ if ( ensureKNotesRunning() ) {
DCOPRef dcopCall( "knotes", "KNotesIface" );
dcopCall.send( "showNote(QString)", uid );
}
Index: summarywidget.h
===================================================================
RCS file: /home/kde/kdepim/kontact/plugins/knotes/summarywidget.h,v
retrieving revision 1.5
diff -p -u -b -r1.5 summarywidget.h
--- summarywidget.h 9 Nov 2003 18:54:57 -0000 1.5
+++ summarywidget.h 30 Nov 2003 11:17:56 -0000
@@ -30,7 +30,8 @@
#include <qptrlist.h>
#include <qwidget.h>
-#include <libkcal/calendarlocal.h>
+#include <libkcal/resourcelocal.h>
+#include <libkcal/calendarresources.h>
typedef QMap<QString, QString> NotesMap;
@@ -52,7 +53,8 @@ class SummaryWidget : public Kontact::Su
void updateView();
private:
- KCal::CalendarLocal *mICal;
+ KCal::ResourceLocal *mResource;
+ KCal::CalendarResources *mCalendar;
KCal::Journal::List mNotes;
QVBoxLayout *mMainLayout;
["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