[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    kdereview/mailody/src
From:       Tom Albers <tomalbers () kde ! nl>
Date:       2008-05-31 21:29:23
Message-ID: 1212269363.699836.18245.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 815002 by toma:

Sort out the debugging and what makes the composer 'dirty' and provide clearer \
errors.


 M  +30 -35    composer.cpp  


--- trunk/kdereview/mailody/src/composer.cpp #815001:815002
@@ -78,8 +78,8 @@
     setObjectName( "composer#" );
     setCaption( i18n( "Composer" ) );
     
-    if ( m_mailbox.isValid() )
-    	kDebug() << "Message will be stored in " << m_mailbox.remoteId() << endl;
+    if ( !m_mailbox.isValid() )
+    	kDebug() << "Message can not be stored in " << m_mailbox.remoteId() << endl;
 
     connect( parent, SIGNAL( setupFinished() ), SLOT( slotStatusChanged() ) );
 
@@ -456,7 +456,6 @@
 
 void Composer::slotShowIdentities( bool on )
 {
-    kDebug() << on;
     m_identitylabel->setVisible( on );
     m_identityBox->setVisible( on );
     m_showIdentities->setChecked( on ); // when reading from config...
@@ -484,11 +483,22 @@
 
 bool Composer::canClose()
 {
-    if ( m_dirty )
-        return KMessageBox::Yes == KMessageBox::questionYesNo( this,
-                i18n( "Are you sure you want to close this window?" ) );
-    else
-        return true;
+    if ( m_dirty ) {
+
+	if ( m_mailbox.isValid() ) {
+        	int res = KMessageBox::questionYesNo( this,
+                	i18n( "You have unsaved changes, do you want to save the draft?" ) \
); +		if (res == KMessageBox::Yes ) {
+			slotSave();
+			return false; /* slotSave will close it if needed */
+		} else
+			return true;
+	}
+	else
+        	return KMessageBox::Yes == KMessageBox::questionYesNo( this,
+                	i18n( "You have unsaved changes, are you sure you want to close \
this window?" ) ); +    }
+    return true;
 }
 
 void Composer::setRcpt( const QString& address, TypeOfAddress addressType )
@@ -517,6 +527,7 @@
     }
     setMsg( plain, html, sign );
 
+    bool dirty = m_dirty;
     // Add header.
     m_text->insertHtml( i18n("<br><hr><b>You wrote:</b><br>") );
 
@@ -524,21 +535,21 @@
     QTextCursor cursor = m_text->textCursor();
     cursor.setPosition(0);
     m_text->setTextCursor( cursor );
+    setDirty( dirty );
 }
 
 void Composer::setMsg( const QString& plain, const QString& html, bool sign )
 {
     QString message = (m_text->textMode()==KRichTextWidget::Rich) ? html : plain;
-    kDebug() << message;
 
     if ( sign )
         addSignaturePlaceholder( message );
 
     // we do not want to get this dirty
-    m_text->blockSignals( true );
+    bool dirty = m_dirty;
     m_text->setTextOrHtml( message );
     ( m_addressbox->topLevelItemCount() > 0 ) ? m_text->setFocus() : \
                m_edit->setFocus();
-    m_text->blockSignals( false );
+    setDirty( dirty );
 }
 
 void Composer::addAttachment( const KUrl& attachment, const QString& name )
@@ -660,9 +671,9 @@
     addSignaturePlaceholder( msg );
 
     // Set the text in the box again, but don't trigger dirty.
-    m_text->blockSignals( true );
+    bool dirty = m_dirty;
     m_text->setText( msg );
-    m_text->blockSignals( false );
+    setDirty( dirty );
 }
 
 void Composer::addAddress( const QString& text )
@@ -700,8 +711,6 @@
     if ( !file.isFile() )
         return;
 
-    kDebug() << "Adding: " << file.url() << endl;
-
     // find existing one
     QList<KUrl> list = m_attachview->attachments().keys();
     foreach( const KUrl& url, list )
@@ -709,13 +718,13 @@
         return;
 
     // Add it...
-    m_dirty = true; // do it here, as forward message does not come here
+    setDirty( true ); // do it here, as forward message does not come here
     addAttachment( file.url() );
 }
 
 void Composer::slotAddFile( const KUrl& file )
 {
-    m_dirty = true;
+    setDirty( true );
     addAttachment( file );
 }
 
@@ -865,8 +874,6 @@
         QString amount = ( *its );
         ++its;
 
-        kDebug() << "Add Item To Completion: " << name << email << endl;
-
         m_edit->completion()->addItem( name + " <" + email + '>' );
         MailodyBaseListViewItem * i = new MailodyBaseListViewItem( m_recentbook );
         i->setText( 0, email );
@@ -948,7 +955,6 @@
         QTreeWidgetItem* item = m_addressbox->topLevelItem( i );
         if ( !item->icon( 1 ).isNull() ) {
             msg->addTo( item->text( 0 ).trimmed().toLatin1() );
-            kDebug() << item->text( 0 ).trimmed().toLatin1() << endl;
         } else if ( !item->icon( 2 ).isNull() )
             msg->addCc( item->text( 0 ).trimmed().toLatin1() );
         else if ( !item->icon( 3 ).isNull() )
@@ -959,8 +965,6 @@
 
 void Composer::slotSend()
 {
-    kDebug() << "start slotSend" << endl;
-
     int current = m_transportBox->currentTransportId();
     if ( current == -1 ) {
         KMessageBox::information( this, i18n( "There is no outgoing mailserver \
configuration found, please set it up before sending" ) ); @@ -1032,8 +1036,6 @@
         return;
     }
 
-    kDebug() << "Saving message to Akonadi";
-
     Akonadi::Item item( "message/rfc822" );
     item.setPayload( MessagePtr( kmimeMessage ) );
 
@@ -1054,26 +1056,22 @@
     QString msg = m_text->textOrHtml();
     placeSignature( msg );
 
-    // Set the text in the box again, but don't trigger dirty.
-    bool old_dirty = m_dirty;
-
     // if this is rich text, switch to rich text mode first...
     ComposerTextEdit::Mode mode = m_text->textMode();
+    bool dirty = m_dirty;
     m_text->setTextOrHtml( msg );
-    m_dirty = old_dirty;
+    setDirty( dirty );
 
     // If the signature is made up from html, the textedit is now
     // automatically set to html mode, revert that.
     // It kind of sucks, because formatting could be lost here.
     if ( mode == ComposerTextEdit::Plain && m_text->textMode() == \
                ComposerTextEdit::Rich ) {
-	kDebug() << "back to plain";
         m_text->switchToPlainText();
     }
 }
 
 void Composer::slotHTMLMode( bool toggle )
 {
-    kDebug() << m_text->textOrHtml();
     if ( !toggle && m_text->textMode() == KRichTextEdit::Rich && \
                !m_text->toPlainText().isEmpty()) {
         int choice = KMessageBox::warningContinueCancel(this, i18n("Switching from \
                HTML mode "
                 "to Plain mode will cause the text to loose the formatting. Are you \
sure?"), @@ -1092,25 +1090,22 @@
 
 void Composer::slotSetup()
 {
-    kDebug();
     emit showSettings();
 }
 
 void Composer::slotSetDirty()
 {
-    m_dirty = true;
+    setDirty( true );
 }
 
 void Composer::slotDone()
 {
-    m_close = true;
+    setDirty( true );
     close();
 }
 
 void Composer::slotDone( KJob* job )
 {
-    kDebug();
-
     //TODO: KMessageBox...
     QApplication::restoreOverrideCursor();
     if ( job->error() ) {


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic