22 #include <tqpopupmenu.h>
23 #include <tqclipboard.h>
25 #include <tdeapplication.h>
27 #include <tdeaction.h>
28 #include <tdemessagebox.h>
30 #include <libtdepim/infoextension.h>
31 #include <libtdepim/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 TDEInstance(
"knotes" ) );
53 new TDEAction( i18n(
"&New" ),
"knotes", CTRL+Key_N,
this, TQ_SLOT( newNote() ),
54 actionCollection(),
"file_new" );
55 new TDEAction( i18n(
"Rename..." ),
"text",
this, TQ_SLOT( renameNote() ),
56 actionCollection(),
"edit_rename" );
57 new TDEAction( i18n(
"Delete" ),
"edit-delete", Key_Delete,
this, TQ_SLOT( killSelectedNotes() ),
58 actionCollection(),
"edit_delete" );
59 new TDEAction( i18n(
"Print Selected Notes..." ),
"print", CTRL+Key_P,
this, TQ_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, TQ_SIGNAL( executed( TQIconViewItem* ) ),
72 this, TQ_SLOT( editNote( TQIconViewItem* ) ) );
73 connect( mNotesView, TQ_SIGNAL( returnPressed( TQIconViewItem* ) ),
74 this, TQ_SLOT( editNote( TQIconViewItem* ) ) );
75 connect( mNotesView, TQ_SIGNAL( itemRenamed( TQIconViewItem* ) ),
76 this, TQ_SLOT( renamedNote( TQIconViewItem* ) ) );
77 connect( mNotesView, TQ_SIGNAL( contextMenuRequested( TQIconViewItem*,
const TQPoint& ) ),
78 this, TQ_SLOT( popupRMB( TQIconViewItem*,
const TQPoint& ) ) );
79 connect( mNotesView, TQ_SIGNAL( onItem( TQIconViewItem* ) ),
80 this, TQ_SLOT( slotOnItem( TQIconViewItem* ) ) );
81 connect( mNotesView, TQ_SIGNAL( onViewport() ),
82 this, TQ_SLOT( slotOnViewport() ) );
83 connect( mNotesView, TQ_SIGNAL( currentChanged( TQIconViewItem* ) ),
84 this, TQ_SLOT( slotOnCurrentChanged( TQIconViewItem* ) ) );
86 slotOnCurrentChanged( 0 );
88 new KParts::SideBarExtension( mNotesView,
this,
"NotesSideBarExtension" );
90 setWidget( mNotesView );
91 setXMLFile(
"knotes_part.rc" );
94 connect( mManager, TQ_SIGNAL( sigRegisteredNote(
KCal::Journal* ) ),
96 connect( mManager, TQ_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() )
164 journal->
setSummary( TDEGlobal::locale()->formatDateTime( TQDateTime::currentDateTime() ) );
175 mNoteEditDlg =
new KNoteEditDlg( widget() );
177 mNoteEditDlg->setTitle( journal->
summary() );
180 if ( mNoteEditDlg->exec() == TQDialog::Accepted )
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 = TDEApplication::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() );
277 TQDateTime KNotesPart::getLastModified(
const TQString&
id )
const
279 KNotesIconViewItem *note = mNoteList[ id ];
282 dt = note->journal()->lastModified();
288 void KNotesPart::killSelectedNotes()
290 TQPtrList<KNotesIconViewItem> items;
293 KNotesIconViewItem *knivi;
294 for ( TQIconViewItem *it = mNotesView->firstItem(); it; it = it->nextItem() ) {
295 if ( it->isSelected() ) {
296 knivi =
static_cast<KNotesIconViewItem *
>( it );
297 items.append( knivi );
298 notes.append( knivi->text() );
302 if ( items.isEmpty() )
305 int ret = KMessageBox::warningContinueCancelList( mNotesView,
306 i18n(
"Do you really want to delete this note?",
307 "Do you really want to delete these %n notes?", items.count() ),
308 notes, i18n(
"Confirm Delete" ),
309 KStdGuiItem::del() );
311 if ( ret == KMessageBox::Continue ) {
312 TQPtrListIterator<KNotesIconViewItem> kniviIt( items );
313 while ( (knivi = *kniviIt) ) {
315 mManager->deleteNote( knivi->journal() );
322 void KNotesPart::popupRMB( TQIconViewItem *item,
const TQPoint& pos )
324 TQPopupMenu *contextMenu = NULL;
327 contextMenu =
static_cast<TQPopupMenu *
>( factory()->container(
"note_context",
this ) );
329 contextMenu =
static_cast<TQPopupMenu *
>( factory()->container(
"notepart_context",
this ) );
334 contextMenu->popup( pos );
337 void KNotesPart::slotOnItem( TQIconViewItem *i )
341 KNotesIconViewItem *item =
static_cast<KNotesIconViewItem *
>( i );
342 mNoteTip->setNote( item );
345 void KNotesPart::slotOnViewport()
347 mNoteTip->setNote( 0 );
357 TQString
property = journal->
customProperty(
"KNotes",
"BgColor" );
358 if ( property.isNull() )
362 if ( property.isNull() )
366 if ( property.isNull() )
369 mNoteList.insert( journal->
uid(),
new KNotesIconViewItem( mNotesView, journal ) );
374 mNoteList.remove( journal->
uid() );
377 void KNotesPart::editNote( TQIconViewItem *item )
380 mNoteEditDlg =
new KNoteEditDlg( widget() );
382 KCal::Journal *journal =
static_cast<KNotesIconViewItem *
>( item )->journal();
384 mNoteEditDlg->setRichText( journal->
customProperty(
"KNotes",
"RichText" ) ==
"true" );
385 mNoteEditDlg->setTitle( journal->
summary() );
388 if ( mNoteEditDlg->exec() == TQDialog::Accepted ) {
389 item->setText( mNoteEditDlg->title() );
395 void KNotesPart::renameNote()
397 mOldName = mNotesView->currentItem()->text();
398 mNotesView->currentItem()->rename();
401 void KNotesPart::renamedNote( TQIconViewItem* )
403 if ( mOldName != mNotesView->currentItem()->text() )
407 void KNotesPart::slotOnCurrentChanged( TQIconViewItem* )
409 TDEAction *renameAction = actionCollection()->action(
"edit_rename" );
410 TDEAction *deleteAction = actionCollection()->action(
"edit_delete" );
412 if ( !mNotesView->currentItem() ) {
413 renameAction->setEnabled(
false );
414 deleteAction->setEnabled(
false );
416 renameAction->setEnabled(
true );
417 deleteAction->setEnabled(
true );
421 #include "knotes_part.moc"
422 #include "knotes_part_p.moc"
void setCustomProperty(const TQCString &app, const TQCString &key, const TQString &value)
TQString customProperty(const TQCString &app, const TQCString &key) const
void setSummary(const TQString &summary)
TQString description() const
void setDescription(const TQString &description)