22 #include <tqpopupmenu.h>
23 #include <tqclipboard.h>
25 #include <kapplication.h>
28 #include <kmessagebox.h>
30 #include <libkdepim/infoextension.h>
31 #include <libkdepim/sidebarextension.h>
33 #include "knotes/knoteprinter.h"
34 #include "knotes/resourcemanager.h"
36 #include "knotes_part.h"
37 #include "knotes_part_p.h"
41 KNotesPart::KNotesPart( TQObject *parent,
const char *name )
42 : DCOPObject(
"KNotesIface" ), KParts::ReadOnlyPart( parent, name ),
43 mNotesView( new KNotesIconView() ),
44 mNoteTip( new KNoteTip( mNotesView ) ),
46 mManager( new KNotesResourceManager() )
48 mNoteList.setAutoDelete(
true );
50 setInstance(
new KInstance(
"knotes" ) );
53 new KAction( i18n(
"&New" ),
"knotes", CTRL+Key_N,
this, TQT_SLOT( newNote() ),
54 actionCollection(),
"file_new" );
55 new KAction( i18n(
"Rename..." ),
"text",
this, TQT_SLOT( renameNote() ),
56 actionCollection(),
"edit_rename" );
57 new KAction( i18n(
"Delete" ),
"editdelete", Key_Delete,
this, TQT_SLOT( killSelectedNotes() ),
58 actionCollection(),
"edit_delete" );
59 new KAction( i18n(
"Print Selected Notes..." ),
"print", CTRL+Key_P,
this, TQT_SLOT( printSelectedNotes() ),
60 actionCollection(),
"print_note" );
65 mNotesView->setSelectionMode( TQIconView::Extended );
66 mNotesView->setItemsMovable(
false );
67 mNotesView->setResizeMode( TQIconView::Adjust );
68 mNotesView->setAutoArrange(
true );
69 mNotesView->setSorting(
true );
71 connect( mNotesView, TQT_SIGNAL( executed( TQIconViewItem* ) ),
72 this, TQT_SLOT( editNote( TQIconViewItem* ) ) );
73 connect( mNotesView, TQT_SIGNAL( returnPressed( TQIconViewItem* ) ),
74 this, TQT_SLOT( editNote( TQIconViewItem* ) ) );
75 connect( mNotesView, TQT_SIGNAL( itemRenamed( TQIconViewItem* ) ),
76 this, TQT_SLOT( renamedNote( TQIconViewItem* ) ) );
77 connect( mNotesView, TQT_SIGNAL( contextMenuRequested( TQIconViewItem*,
const TQPoint& ) ),
78 this, TQT_SLOT( popupRMB( TQIconViewItem*,
const TQPoint& ) ) );
79 connect( mNotesView, TQT_SIGNAL( onItem( TQIconViewItem* ) ),
80 this, TQT_SLOT( slotOnItem( TQIconViewItem* ) ) );
81 connect( mNotesView, TQT_SIGNAL( onViewport() ),
82 this, TQT_SLOT( slotOnViewport() ) );
83 connect( mNotesView, TQT_SIGNAL( currentChanged( TQIconViewItem* ) ),
84 this, TQT_SLOT( slotOnCurrentChanged( TQIconViewItem* ) ) );
86 slotOnCurrentChanged( 0 );
88 new KParts::SideBarExtension( mNotesView,
this,
"NotesSideBarExtension" );
90 setWidget( mNotesView );
91 setXMLFile(
"knotes_part.rc" );
94 connect( mManager, TQT_SIGNAL( sigRegisteredNote(
KCal::Journal* ) ),
96 connect( mManager, TQT_SIGNAL( sigDeregisteredNote(
KCal::Journal* ) ),
103 KNotesPart::~KNotesPart()
112 void KNotesPart::printSelectedNotes()
114 TQValueList<KCal::Journal*> journals;
116 for ( TQIconViewItem *it = mNotesView->firstItem(); it; it = it->nextItem() ) {
117 if ( it->isSelected() ) {
118 journals.append( static_cast<KNotesIconViewItem *>( it )->journal() );
122 if ( journals.isEmpty() ) {
123 KMessageBox::information( mNotesView, i18n(
"To print notes, first select the notes to print from the list."), i18n(
"Print Notes") );
127 KNotePrinter printer;
128 printer.printNotes(journals );
132 if ( m_editor->textFormat() == PlainText )
133 content = TQStyleSheet::convertFromPlainText( m_editor->text() );
135 content = m_editor->text();
137 KNotePrinter printer;
138 printer.setMimeSourceFactory( m_editor->mimeSourceFactory() );
142 printer.setColorGroup( colorGroup() );
143 printer.printNote( , content );
147 bool KNotesPart::openFile()
155 TQString KNotesPart::newNote(
const TQString& name,
const TQString& text )
161 if ( !name.isEmpty() )
162 journal->setSummary( name );
164 journal->setSummary( KGlobal::locale()->formatDateTime( TQDateTime::currentDateTime() ) );
167 journal->setDescription( text );
175 mNoteEditDlg =
new KNoteEditDlg( widget() );
177 mNoteEditDlg->setTitle( journal->summary() );
178 mNoteEditDlg->setText( journal->description() );
180 if ( mNoteEditDlg->exec() == TQDialog::Accepted )
182 journal->setSummary( mNoteEditDlg->title() );
183 journal->setDescription( mNoteEditDlg->text() );
192 mManager->addNewNote( journal );
195 KNotesIconViewItem *note = mNoteList[ journal->uid() ];
196 mNotesView->ensureItemVisible( note );
197 mNotesView->setCurrentItem( note );
199 return journal->uid();
202 TQString KNotesPart::newNoteFromClipboard(
const TQString& name )
204 const TQString& text = KApplication::clipboard()->text();
205 return newNote( name, text );
208 void KNotesPart::killNote(
const TQString&
id )
210 killNote(
id,
false );
213 void KNotesPart::killNote(
const TQString&
id,
bool force )
215 KNotesIconViewItem *note = mNoteList[ id ];
218 ( (!force && KMessageBox::warningContinueCancelList( mNotesView,
219 i18n(
"Do you really want to delete this note?" ),
220 mNoteList[
id ]->text(), i18n(
"Confirm Delete" ),
221 KStdGuiItem::del() ) == KMessageBox::Continue)
225 mManager->deleteNote( mNoteList[
id]->journal() );
230 TQString KNotesPart::name(
const TQString&
id )
const
232 KNotesIconViewItem *note = mNoteList[ id ];
239 TQString KNotesPart::text(
const TQString&
id )
const
241 KNotesIconViewItem *note = mNoteList[id];
243 return note->journal()->description();
248 void KNotesPart::setName(
const TQString&
id,
const TQString& newName )
250 KNotesIconViewItem *note = mNoteList[ id ];
252 note->setText( newName );
257 void KNotesPart::setText(
const TQString&
id,
const TQString& newText )
259 KNotesIconViewItem *note = mNoteList[ id ];
261 note->journal()->setDescription( newText );
266 TQMap<TQString, TQString> KNotesPart::notes()
const
268 TQMap<TQString, TQString> notes;
269 TQDictIterator<KNotesIconViewItem> it( mNoteList );
271 for ( ; it.current(); ++it )
272 notes.insert( (*it)->journal()->uid(), (*it)->journal()->summary() );
280 void KNotesPart::killSelectedNotes()
282 TQPtrList<KNotesIconViewItem> items;
285 KNotesIconViewItem *knivi;
286 for ( TQIconViewItem *it = mNotesView->firstItem(); it; it = it->nextItem() ) {
287 if ( it->isSelected() ) {
288 knivi =
static_cast<KNotesIconViewItem *
>( it );
289 items.append( knivi );
290 notes.append( knivi->text() );
294 if ( items.isEmpty() )
297 int ret = KMessageBox::warningContinueCancelList( mNotesView,
298 i18n(
"Do you really want to delete this note?",
299 "Do you really want to delete these %n notes?", items.count() ),
300 notes, i18n(
"Confirm Delete" ),
301 KStdGuiItem::del() );
303 if ( ret == KMessageBox::Continue ) {
304 TQPtrListIterator<KNotesIconViewItem> kniviIt( items );
305 while ( (knivi = *kniviIt) ) {
307 mManager->deleteNote( knivi->journal() );
314 void KNotesPart::popupRMB( TQIconViewItem *item,
const TQPoint& pos )
316 TQPopupMenu *contextMenu = NULL;
319 contextMenu =
static_cast<TQPopupMenu *
>( factory()->container(
"note_context",
this ) );
321 contextMenu =
static_cast<TQPopupMenu *
>( factory()->container(
"notepart_context",
this ) );
326 contextMenu->popup( pos );
329 void KNotesPart::slotOnItem( TQIconViewItem *i )
333 KNotesIconViewItem *item =
static_cast<KNotesIconViewItem *
>( i );
334 mNoteTip->setNote( item );
337 void KNotesPart::slotOnViewport()
339 mNoteTip->setNote( 0 );
349 TQString
property = journal->customProperty(
"KNotes",
"BgColor" );
350 if ( property.isNull() )
351 journal->setCustomProperty(
"KNotes",
"BgColor",
"#ffff00" );
353 property = journal->customProperty(
"KNotes",
"FgColor" );
354 if ( property.isNull() )
355 journal->setCustomProperty(
"KNotes",
"FgColor",
"#000000" );
357 property = journal->customProperty(
"KNotes",
"RichText" );
358 if ( property.isNull() )
359 journal->setCustomProperty(
"KNotes",
"RichText",
"true" );
361 mNoteList.insert( journal->uid(),
new KNotesIconViewItem( mNotesView, journal ) );
366 mNoteList.remove( journal->uid() );
369 void KNotesPart::editNote( TQIconViewItem *item )
372 mNoteEditDlg =
new KNoteEditDlg( widget() );
374 KCal::Journal *journal =
static_cast<KNotesIconViewItem *
>( item )->journal();
376 mNoteEditDlg->setRichText( journal->customProperty(
"KNotes",
"RichText" ) ==
"true" );
377 mNoteEditDlg->setTitle( journal->summary() );
378 mNoteEditDlg->setText( journal->description() );
380 if ( mNoteEditDlg->exec() == TQDialog::Accepted ) {
381 item->setText( mNoteEditDlg->title() );
382 journal->setDescription( mNoteEditDlg->text() );
387 void KNotesPart::renameNote()
389 mOldName = mNotesView->currentItem()->text();
390 mNotesView->currentItem()->rename();
393 void KNotesPart::renamedNote( TQIconViewItem* )
395 if ( mOldName != mNotesView->currentItem()->text() )
399 void KNotesPart::slotOnCurrentChanged( TQIconViewItem* )
401 KAction *renameAction = actionCollection()->action(
"edit_rename" );
402 KAction *deleteAction = actionCollection()->action(
"edit_delete" );
404 if ( !mNotesView->currentItem() ) {
405 renameAction->setEnabled(
false );
406 deleteAction->setEnabled(
false );
408 renameAction->setEnabled(
true );
409 deleteAction->setEnabled(
true );
413 #include "knotes_part.moc"
414 #include "knotes_part_p.moc"