diff options
author | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-09-01 00:37:02 +0000 |
---|---|---|
committer | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-09-01 00:37:02 +0000 |
commit | cc29364f06178f8f6b457384f2ec37a042bd9d43 (patch) | |
tree | 7c77a3184c698bbf9d98cef09fb1ba8124daceba /knotes/knote.cpp | |
parent | 4f6c584bacc8c3c694228f36ada3de77a76614a6 (diff) | |
download | tdepim-cc29364f06178f8f6b457384f2ec37a042bd9d43.tar.gz tdepim-cc29364f06178f8f6b457384f2ec37a042bd9d43.zip |
* Massive set of changes to bring in all fixes and enhancements from the Enterprise PIM branch
* Ensured that the Trinity changes were applied on top of those enhancements, and any redundancy removed
* Added journal read support to the CalDAV resource
* Fixed CalDAV resource to use events URL for tasks and journals when separate URL checkbox unchecked
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdepim@1170461 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'knotes/knote.cpp')
-rw-r--r-- | knotes/knote.cpp | 146 |
1 files changed, 114 insertions, 32 deletions
diff --git a/knotes/knote.cpp b/knotes/knote.cpp index 1e55dd14c..9e644d7a6 100644 --- a/knotes/knote.cpp +++ b/knotes/knote.cpp @@ -30,6 +30,7 @@ #include <tqobjectlist.h> #include <tqfile.h> #include <tqcheckbox.h> +#include <tqtimer.h> #include <kapplication.h> #include <kdebug.h> @@ -84,7 +85,8 @@ KNote::KNote( TQDomDocument buildDoc, Journal *j, TQWidget *parent, const char * : TQFrame( parent, name, WStyle_Customize | WStyle_NoBorder | WDestructiveClose ), m_label( 0 ), m_pushpin( 0 ), m_fold( 0 ), m_button( 0 ), m_tool( 0 ), m_editor( 0 ), m_config( 0 ), m_journal( j ), m_find( 0 ), - m_kwinConf( KSharedConfig::openConfig( "kwinrc", true ) ) + m_kwinConf( KSharedConfig::openConfig( "kwinrc", true ) ), + m_busy( 0 ), m_deleteWhenIdle( false ), m_blockEmitDataChanged( false ) { setAcceptDrops( true ); actionCollection()->setWidget( this ); @@ -105,7 +107,7 @@ KNote::KNote( TQDomDocument buildDoc, Journal *j, TQWidget *parent, const char * // create the menu items for the note - not the editor... // rename, mail, print, save as, insert date, alarm, close, delete, new note new KAction( i18n("New"), "filenew", 0, - this, TQT_SIGNAL(sigRequestNewNote()), actionCollection(), "new_note" ); + this,TQT_SLOT(slotRequestNewNote()) , actionCollection(), "new_note" ); new KAction( i18n("Rename..."), "text", 0, this, TQT_SLOT(slotRename()), actionCollection(), "rename_note" ); m_readOnly = new KToggleAction( i18n("Lock"), "lock" , 0, @@ -159,6 +161,7 @@ KNote::KNote( TQDomDocument buildDoc, Journal *j, TQWidget *parent, const char * // create the note editor m_editor = new KNoteEdit( actionCollection(), this ); + m_editor->setNote( this ); m_editor->installEventFilter( this ); // receive events (for modified) m_editor->viewport()->installEventFilter( this ); connect( m_editor, TQT_SIGNAL(contentsMoving( int, int )), this, TQT_SLOT(slotUpdateViewport( int, int ))); @@ -369,11 +372,27 @@ KNote::~KNote() delete m_config; } +void KNote::slotRequestNewNote() +{ + //Be sure to save before to request a new note + saveConfig(); + saveData(); + emit sigRequestNewNote(); +} + +void KNote::changeJournal(KCal::Journal *journal) +{ + m_journal = journal; + m_editor->setText( m_journal->description() ); + m_label->setText( m_journal->summary() ); + updateLabelAlignment(); +} // -------------------- public slots -------------------- // void KNote::slotKill( bool force ) { + m_blockEmitDataChanged = true; if ( !force && KMessageBox::warningContinueCancel( this, i18n("<qt>Do you really want to delete note <b>%1</b>?</qt>").arg( m_label->text() ), @@ -382,9 +401,10 @@ void KNote::slotKill( bool force ) ) != KMessageBox::Continue ) { + m_blockEmitDataChanged = false; return; } - + aboutToEnterEventLoop(); // delete the configuration first, then the corresponding file delete m_config; m_config = 0; @@ -396,21 +416,24 @@ void KNote::slotKill( bool force ) kdError(5500) << "Can't remove the note config: " << configFile << endl; emit sigKillNote( m_journal ); + eventLoopLeft(); + } // -------------------- public member functions -------------------- // -void KNote::saveData() +void KNote::saveData(bool update) { m_journal->setSummary( m_label->text() ); m_journal->setDescription( m_editor->text() ); m_journal->setCustomProperty( "KNotes", "FgColor", m_config->fgColor().name() ); m_journal->setCustomProperty( "KNotes", "BgColor", m_config->bgColor().name() ); m_journal->setCustomProperty( "KNotes", "RichText", m_config->richText() ? "true" : "false" ); - - emit sigDataChanged(); + if(update) { + emit sigDataChanged( noteId() ); m_editor->setModified( false ); + } } void KNote::saveConfig() const @@ -498,7 +521,7 @@ void KNote::setColor( const TQColor& fg, const TQColor& bg ) m_config->setBgColor( bg ); m_journal->updated(); // because setCustomProperty() doesn't call it!! - emit sigDataChanged(); + emit sigDataChanged(noteId()); m_config->writeConfig(); TQPalette newpalette = palette(); @@ -684,11 +707,16 @@ void KNote::setStyle( int style ) void KNote::slotRename() { + m_blockEmitDataChanged = true; // pop up dialog to get the new name bool ok; + aboutToEnterEventLoop(); + TQString oldName = m_label->text(); TQString newName = KInputDialog::getText( TQString::null, i18n("Please enter the new name:"), m_label->text(), &ok, this ); - if ( !ok ) // handle cancel + eventLoopLeft(); + m_blockEmitDataChanged = false; + if ( !ok || ( oldName == newName) ) // handle cancel return; setName( newName ); @@ -711,6 +739,21 @@ void KNote::slotUpdateReadOnly() actionCollection()->action( "edit_cut" )->setEnabled( !readOnly && m_editor->hasSelectedText() ); actionCollection()->action( "edit_paste" )->setEnabled( !readOnly ); actionCollection()->action( "edit_clear" )->setEnabled( !readOnly ); + actionCollection()->action( "rename_note" )->setEnabled( !readOnly ); + + actionCollection()->action( "format_bold" )->setEnabled( !readOnly ); + actionCollection()->action( "format_italic" )->setEnabled( !readOnly ); + actionCollection()->action( "format_underline" )->setEnabled( !readOnly ); + actionCollection()->action( "format_strikeout" )->setEnabled( !readOnly ); + actionCollection()->action( "format_alignleft" )->setEnabled( !readOnly ); + actionCollection()->action( "format_aligncenter" )->setEnabled( !readOnly ); + actionCollection()->action( "format_alignright" )->setEnabled( !readOnly ); + actionCollection()->action( "format_alignblock" )->setEnabled( !readOnly ); + actionCollection()->action( "format_list" )->setEnabled( !readOnly ); + actionCollection()->action( "format_super" )->setEnabled( !readOnly ); + actionCollection()->action( "format_sub" )->setEnabled( !readOnly ); + actionCollection()->action( "format_size" )->setEnabled( !readOnly ); + actionCollection()->action( "format_color" )->setEnabled( !readOnly ); updateFocus(); } @@ -724,7 +767,7 @@ void KNote::slotClose() m_editor->clearFocus(); m_config->setHideNote( true ); m_config->setPosition( pos() ); - + m_config->writeConfig(); // just hide the note so it's still available from the dock window hide(); } @@ -736,11 +779,15 @@ void KNote::slotInsDate() void KNote::slotSetAlarm() { + m_blockEmitDataChanged = true; KNoteAlarmDlg dlg( name(), this ); dlg.setIncidence( m_journal ); + aboutToEnterEventLoop(); if ( dlg.exec() == TQDialog::Accepted ) - emit sigDataChanged(); + emit sigDataChanged(noteId()); + eventLoopLeft(); + m_blockEmitDataChanged = false; } void KNote::slotPreferences() @@ -760,11 +807,12 @@ void KNote::slotSend() { // pop up dialog to get the IP KNoteHostDlg hostDlg( i18n("Send \"%1\"").arg( name() ), this ); + aboutToEnterEventLoop(); bool ok = (hostDlg.exec() == TQDialog::Accepted); - TQString host = hostDlg.host(); - + eventLoopLeft(); if ( !ok ) // handle cancel return; + TQString host = hostDlg.host(); if ( host.isEmpty() ) { @@ -782,11 +830,11 @@ void KNote::slotSend() void KNote::slotMail() { // get the mail action command - TQStringList cmd_list = TQStringList::split( TQChar(' '), KNotesGlobalConfig::mailAction() ); + const TQStringList cmd_list = TQStringList::split( TQChar(' '), KNotesGlobalConfig::mailAction() ); KProcess mail; - for ( TQStringList::Iterator it = cmd_list.begin(); - it != cmd_list.end(); ++it ) + for ( TQStringList::ConstIterator it = cmd_list.constBegin(); + it != cmd_list.constEnd(); ++it ) { if ( *it == "%f" ) mail << plainText().local8Bit(); // convert rich text to plain text @@ -802,8 +850,6 @@ void KNote::slotMail() void KNote::slotPrint() { - saveData(); - TQString content; if ( m_editor->textFormat() == PlainText ) content = TQStyleSheet::convertFromPlainText( m_editor->text() ); @@ -821,6 +867,7 @@ void KNote::slotPrint() void KNote::slotSaveAs() { + m_blockEmitDataChanged = true; TQCheckBox *convert = 0; if ( m_editor->textFormat() == RichText ) @@ -832,12 +879,16 @@ void KNote::slotSaveAs() KFileDialog dlg( TQString::null, TQString::null, this, "filedialog", true, convert ); dlg.setOperationMode( KFileDialog::Saving ); dlg.setCaption( i18n("Save As") ); + aboutToEnterEventLoop(); dlg.exec(); + eventLoopLeft(); TQString fileName = dlg.selectedFile(); if ( fileName.isEmpty() ) + { + m_blockEmitDataChanged = false; return; - + } TQFile file( fileName ); if ( file.exists() && @@ -845,6 +896,7 @@ void KNote::slotSaveAs() "Are you sure you want to overwrite it?</qt>").arg( TQFileInfo(file).fileName() ) ) != KMessageBox::Continue ) { + m_blockEmitDataChanged = false; return; } @@ -857,6 +909,7 @@ void KNote::slotSaveAs() else stream << text(); } + m_blockEmitDataChanged = false; } void KNote::slotPopupActionToDesktop( int id ) @@ -993,19 +1046,20 @@ void KNote::updateFocus() { m_label->setBackgroundColor( palette().active().shadow() ); m_button->show(); - m_editor->cornerWidget()->show(); if ( !m_editor->isReadOnly() ) { if ( m_tool && m_tool->isHidden() && m_editor->textFormat() == TQTextEdit::RichText ) { m_tool->show(); + m_editor->cornerWidget()->show(); setGeometry( x(), y(), width(), height() + m_tool->height() ); } } else if ( m_tool && !m_tool->isHidden() ) { m_tool->hide(); + m_editor->cornerWidget()->hide(); setGeometry( x(), y(), width(), height() - m_tool->height() ); updateLayout(); // to update the minimum height } @@ -1210,8 +1264,9 @@ void KNote::resizeEvent( TQResizeEvent *qre ) updateLayout(); } -void KNote::closeEvent( TQCloseEvent * ) +void KNote::closeEvent( TQCloseEvent *event ) { + event->ignore(); //We don't want to close (and delete the widget). Just hide it slotClose(); } @@ -1268,8 +1323,10 @@ bool KNote::eventFilter( TQObject *o, TQEvent *ev ) TQMouseEvent *e = (TQMouseEvent *)ev; if ( ev->type() == TQEvent::MouseButtonDblClick ) - slotRename(); - + { + if( !m_editor->isReadOnly()) + slotRename(); + } if ( ev->type() == TQEvent::MouseButtonPress && (e->button() == LeftButton || e->button() == MidButton)) { @@ -1301,21 +1358,21 @@ bool KNote::eventFilter( TQObject *o, TQEvent *ev ) return false; } - if ( o == m_editor ) - { - if ( ev->type() == TQEvent::FocusOut ) - { + if ( o == m_editor ) { + if ( ev->type() == TQEvent::FocusOut ) { TQFocusEvent *fe = static_cast<TQFocusEvent *>(ev); if ( fe->reason() != TQFocusEvent::Popup && - fe->reason() != TQFocusEvent::Mouse ) - { + fe->reason() != TQFocusEvent::Mouse ) { updateFocus(); - if ( m_editor->isModified() ) - saveData(); + if ( isModified() ) { + saveConfig(); + if ( !m_blockEmitDataChanged ) + saveData(); + } } - } - else if ( ev->type() == TQEvent::FocusIn ) + } else if ( ev->type() == TQEvent::FocusIn ) { updateFocus(); + } return false; } @@ -1334,6 +1391,31 @@ bool KNote::eventFilter( TQObject *o, TQEvent *ev ) return false; } +void KNote::slotSaveData() +{ + saveData(); +} + +void KNote::deleteWhenIdle() +{ + if ( m_busy <= 0 ) + deleteLater(); + else + m_deleteWhenIdle = true; +} + +void KNote::aboutToEnterEventLoop() +{ + ++m_busy; +} + +void KNote::eventLoopLeft() +{ + --m_busy; + if ( m_busy <= 0 && m_deleteWhenIdle ) + deleteLater(); +} + #include "knote.moc" #include "knotebutton.moc" |