-rw-r--r-- | kmicromail/opiemail.cpp | 62 |
1 files changed, 39 insertions, 23 deletions
diff --git a/kmicromail/opiemail.cpp b/kmicromail/opiemail.cpp index 0c581c0..b2119e6 100644 --- a/kmicromail/opiemail.cpp +++ b/kmicromail/opiemail.cpp @@ -1,159 +1,175 @@ // CHANGED 2004-09-31 Lutz Rogowski // CHANGED 2004-08-06 Lutz Rogowski #include "settingsdialog.h" #include "opiemail.h" #include "editaccounts.h" #include "composemail.h" #include "mailistviewitem.h" #include "viewmail.h" #include "selectstore.h" #include "selectsmtp.h" #include <qmessagebox.h> +#include <qtimer.h> #include <libkdepim/externalapphandler.h> #include <qpe/qpeapplication.h> #include <libmailwrapper/smtpwrapper.h> #include <libmailwrapper/mailtypes.h> #include <libmailwrapper/abstractmail.h> /* OPIE */ //#include <qpe/resource.h> //#include <qpe/qpeapplication.h> /* QT */ //using namespace Opie::Core; OpieMail::OpieMail( QWidget *parent, const char *name ) : MainWindow( parent, name) //, WStyle_ContextHelp ) { settings = new Settings(); folderView->populate( settings->getAccounts() ); } OpieMail::~OpieMail() { if (settings) delete settings; } void OpieMail::appMessage(const QCString &msg, const QByteArray &data) { } #include <stdlib.h> void OpieMail::message(const QCString &msg, const QByteArray &data) { // copied from old mail2 static int ii = 0; - qDebug("call ############################# %d ", ii); - // block second call - if ( ii < 2 ) { - //++ii; - if ( ii > 1 ) { - qDebug("qcop call blocked "); - //return; - } - } + //qDebug("QCOP CALL ############################# %d ", ii); + //QString mess ( msg ); + //qDebug("Message = %s ",mess.latin1()); ++ii; //qDebug("KM:appMessage %d *%s* %x", ii, msg.data(), this); + + mPendingEmail = QString::null; + mPendingName = QString::null; if (msg == "writeMail(QString,QString)") { + //qDebug("writeMail(QString,QString) "); QDataStream stream(data,IO_ReadOnly); - QString name, email; - stream >> name >> email; + stream >> mPendingName >> mPendingEmail; // removing the whitespaces at beginning and end is needed! - slotwriteMail(name.stripWhiteSpace(),email.stripWhiteSpace()); + QTimer::singleShot ( 50, this, SLOT(slotComposeMail() ) ); } else if (msg == "newMail()") { - slotComposeMail(); + //qDebug("slotComposeMail() "); + // we cannot call slotComposeMail(); directly, because may be executing a QCOP call + // and a QCOP call does not like a processevents in his execution + // with the Qtimer we call slotComposeMail() after we reached the main event loop + QTimer::singleShot ( 50, this, SLOT(slotComposeMail() ) ); + // slotComposeMail(); } else if (msg == "newMail(QString)") { + //qDebug(" newMail(QString)"); QDataStream stream(data,IO_ReadOnly); - QString nameemail; - stream >> nameemail; + stream >> mPendingName; // the format is // NAME <EMAIL>:SUBJECT - //qDebug("message %s ", nameemail.latin1()); - - slotwriteMail2( nameemail ); - } else - ExternalAppHandler::instance()->appMessage ( msg, data); + QTimer::singleShot ( 50, this, SLOT(slotComposeMail() ) ); + } else { + if ( ii == 1 ) { + qDebug("Kopiemail::Error:: Initial QCOP call for ExternalAppHandler not supported "); + return; + } + ExternalAppHandler::instance()->appMessage ( msg, data); + } + + //qDebug("END OpieMail::message "); } void OpieMail::slotwriteMail2(const QString& namemail ) { - // qDebug("OpieMail::slotwriteMail2 "); - qApp->processEvents(); + //qDebug("OpieMail::slotwriteMail2 "); + //qApp->processEvents(); ComposeMail compose( settings, this, 0, true ); if ( !namemail.isEmpty() ) { QString to = namemail; if ( namemail.find( " <") > 1 ) { to = "\"" +to.replace( QRegExp( " <"), "\" <") ; } else if ( namemail.find( "<") > 1 ) { to = "\"" +to.replace( QRegExp( "<"), "\" <") ; } int sub = to.find( ">:"); if ( sub > 0 ) { compose.setTo( to.left(sub+1) ); compose.setSubject( to.mid(sub+2) ); } else compose.setTo( to ); } compose.slotAdjustColumns(); compose.showMaximized(); compose.exec(); raise(); //qDebug("retttich "); } void OpieMail::slotwriteMail(const QString&name,const QString&email) { // qDebug("OpieMail::slotwriteMail "); ComposeMail compose( settings, this, 0, true ); if (!email.isEmpty()) { if (!name.isEmpty()) { compose.setTo("\"" + name + "\"" + " " + "<"+ email + ">"); } else { compose.setTo(email); } } compose.slotAdjustColumns(); compose.showMaximized(); compose.exec(); + raise(); } void OpieMail::slotComposeMail() { - slotwriteMail2( QString () ); + if ( mPendingEmail == QString::null && mPendingName == QString::null) + slotwriteMail2( QString () ); + else { + if ( mPendingEmail == QString::null ) + slotwriteMail2( mPendingName ); + else + slotwriteMail( mPendingName, mPendingEmail ); + } //slotwriteMail(0l,0l); } void OpieMail::slotSendQueued() { SMTPaccount *smtp = 0; QList<Account> list = settings->getAccounts(); QList<SMTPaccount> smtpList; smtpList.setAutoDelete(false); Account *it; for ( it = list.first(); it; it = list.next() ) { if ( it->getType() == MAILLIB::A_SMTP ) { smtp = static_cast<SMTPaccount *>(it); smtpList.append(smtp); } } if (smtpList.count()==0) { QMessageBox::information(0,tr("Info"),tr("Define a smtp account first!\n")); return; } |