From kde-commits Tue Oct 31 22:57:45 2006 From: Tom Albers Date: Tue, 31 Oct 2006 22:57:45 +0000 To: kde-commits Subject: playground/pim/mailody Message-Id: <1162335465.046565.27290.nullmailer () svn ! kde ! org> X-MARC-Message: https://marc.info/?l=kde-commits&m=116233547722716 SVN commit 600822 by toma: - When password is empty / wrong or when people dont want to use KWallet, present a nice dialog for them - Composer refered to Settings, provide button in the dialog to go to the settings - Disable password box in the Settings when KWallet is not activated - Fill statusbar with info from the network status M +0 -3 TODO M +35 -11 src/composer.cpp M +1 -0 src/composer.h M +64 -24 src/qmafetch.cpp M +6 -0 src/qmafetch.h M +7 -0 src/qmawidget.cpp M +1 -0 src/qmawidget.h M +8 -13 src/setupaccount.cpp --- trunk/playground/pim/mailody/TODO #600821:600822 @@ -10,9 +10,6 @@ Settings: check capabilities -after close we get a reconnect warning (missing abouttoclose call?) -maybe thats only when tls is selected and there is no support? -no valid password -> add button to settings ------------------------------------ --- trunk/playground/pim/mailody/src/composer.cpp #600821:600822 @@ -568,18 +568,25 @@ while (smtp_server.isEmpty() || name.isEmpty() || email.isEmpty()) { - KMessageBox::error(this, i18n("Settings are not complete, " - "complete them and try again...")); + int i = KMessageBox::warningContinueCancel(this, + i18n("Settings are not complete, " + "complete them and try again..."), + i18n("Could not send the message"), + i18n("Settings")); + if (i == KMessageBox::Continue) + { + Setup setup(0,"Setup"); + if (setup.exec() != QDialog::Accepted) + return; - Setup setup(0,"Setup"); - if (setup.exec() != QDialog::Accepted) - return; - - KConfig* config = kapp->config(); - config->setGroup("General"); - smtp_server = config->readEntry("smtpServer"); - name = config->readEntry("fullName"); - email = config->readEntry("emailAddress"); + KConfig* config = kapp->config(); + config->setGroup("General"); + smtp_server = config->readEntry("smtpServer"); + name = config->readEntry("fullName"); + email = config->readEntry("emailAddress"); + } + else + break; } m = new Message(); @@ -741,8 +748,25 @@ SLOT(slotRead(const QString&))); connect(m_smtp, SIGNAL(connected()), SLOT(slotConnected())); m_smtp->reconnect(); + connect(m_smtp, SIGNAL(error(const QString&)), + SLOT(slotError(const QString&))); + } +void Composer::slotError(const QString& error) +{ + // There is a 10% chance for a crash remaining here + // on a timeout error + // Thiago guarded for that for KDE 3.5.6 - comitted on 2006-10-29 + if (m_smtp) + { + m_smtp->deleteLater(); + m_smtp = 0; + } + + KMessageBox::information(0,error); +} + void Composer::slotRead(const QString& dataIn) { //kdDebug() << "Received: " << dataIn.stripWhiteSpace() --- trunk/playground/pim/mailody/src/composer.h #600821:600822 @@ -169,6 +169,7 @@ void slotSend(); void slotConnected(); void slotRead(const QString&); + void slotError(const QString& error); }; #endif // COMPOSER --- trunk/playground/pim/mailody/src/qmafetch.cpp #600821:600822 @@ -26,11 +26,13 @@ #include #include #include +#include #include using KWallet::Wallet; #include "db.h" #include "socketsafe.h" +#include "setup.h" #include "qmafetch.h" QMAFetch *QMAFetch::m_instance = 0; @@ -71,38 +73,57 @@ void QMAFetch::slotLogin() { + emit status(i18n("Connected")); kapp->config()->setGroup("General"); QString login = kapp->config()->readEntry("userName"); QString pass; Wallet* wallet = Wallet::openWallet(Wallet::NetworkWallet()); - if (!wallet) + if (wallet && wallet->isOpen() && wallet->hasFolder("mailody")) { - KMessageBox::error(0,i18n("Mailody could not access KWallet, " - "Mailody can not operate without it. Please activate it.")); - exit(1); - } - - if (wallet->isOpen() && wallet->hasFolder("mailody")) - { wallet->setFolder( "mailody" ); wallet->readPassword("account1", pass); } delete wallet; if (pass.isEmpty()) + manualAuth(); + else { - m_imap->deleteLater(); - m_imap = 0; + m_queue.prepend(Queue(Queue::Auth, "", + "login \"" + login + "\" \"" + pass + "\"")); - KMessageBox::information(0,i18n("Could not find a valid password in " - "the wallet, please go to the setup page")); - return; + emit status(i18n("Ready")); + m_readyToSend = true; } +} - m_queue.prepend(Queue(Queue::Auth, "", - "login \"" + login + "\" \"" + pass + "\"")); +void QMAFetch::manualAuth() +{ + kapp->config()->setGroup("General"); + QString login = kapp->config()->readEntry("userName"); + QCString password; + int result = KPasswordDialog::getPassword(password, + i18n("Could not find a valid password, please enter it here")); + if (!password) + { + m_readyToSend = false; + if (m_imap) + { + m_imap->deleteLater(); + m_imap=0; + } + emit status(i18n("Offline")); + return; + } + if (result == KPasswordDialog::Accepted) + m_queue.prepend(Queue(Queue::Auth, "", + "login \"" + login + "\" \"" + + QString(password) + "\"")); + password.fill(0); // safe enough? + m_currentQueueItem=Queue(); + emit status(i18n("Ready")); m_readyToSend = true; } @@ -136,17 +157,34 @@ else if (received.find("a02 NO") != -1 && m_currentQueueItem.state() == Queue::Auth) { + m_currentQueueItem=Queue(); m_readyToSend = false; - if (m_imap) + + emit status(i18n("Offline")); + int i = KMessageBox::questionYesNoCancel(0, + i18n("The server refused the supplied username and password, " + "do you want to go to the settings, re-enter it for one " + "time or do nothing?"), + i18n("Could not log in"), + i18n("Settings"), i18n("Single Input")); + if (i == KMessageBox::Yes) { - m_imap->deleteLater(); - m_imap=0; + Setup setup(0,"Setup"); + if (setup.exec() != QDialog::Accepted) + return; + slotLogin(); } - - KMessageBox::information(0,i18n("The server refused the supplied " - "username and password.")); - m_currentQueueItem=Queue(); - return; + else if (i == KMessageBox::No) + manualAuth(); + else + { + if (m_imap) + { + m_imap->deleteLater(); + m_imap=0; + } + return; + } } else if (received.find("a02 NO") != -1 || received.find("a02 BAD") != -1) { @@ -560,7 +598,7 @@ // Priority; above the checkmail calls in the queue. m_queue.prepend(Queue(Queue::GetHeaders, mb, "UID FETCH " + part - + " (BODY.PEEK[HEADER.FIELDS (FROM TO CC SUBJECT DATE)])")); + + " (BODY.PEEK[HEADER.FIELDS (FROM TO CC SUBJECT DATE)])")); } } @@ -599,6 +637,7 @@ m_imap = 0; } + emit status(i18n("Offline")); KMessageBox::information(0,error); } @@ -639,6 +678,7 @@ connect(m_imap, SIGNAL(error(const QString&)), SLOT(slotError(const QString&))); + emit status(i18n("Connecting")); m_imap->reconnect(); } #include "qmafetch.moc" --- trunk/playground/pim/mailody/src/qmafetch.h #600821:600822 @@ -211,6 +211,11 @@ */ void unseenCount(const QString& mb, int amount); + /** + * Reports about the network status + */ + void status(const QString&); + private slots: void slotRead(const QString&); void slotError(const QString& error); @@ -219,6 +224,7 @@ private: static QMAFetch* m_instance; + void manualAuth(); }; #endif // QMAFETCH_H --- trunk/playground/pim/mailody/src/qmawidget.cpp #600821:600822 @@ -119,6 +119,8 @@ SLOT(slotUpdateUnseenMessageCount(const QString&, int))); connect(d->connection, SIGNAL(allUidsKnown(const QString&)), SLOT(slotAllMessages(const QString&))); + connect(d->connection, SIGNAL(status(const QString&)), + SLOT(slotUpdateStatusBar(const QString&))); d->first = new QSplitter(this); @@ -1285,6 +1287,11 @@ checkMail(); } +void QMAWidget::slotUpdateStatusBar(const QString& text) +{ + statusBar()->changeItem(text,1); +} + void QMAWidget::slotQuit() { exit(0); --- trunk/playground/pim/mailody/src/qmawidget.h #600821:600822 @@ -115,6 +115,7 @@ void slotUser3(); void slotUser4(); void slotUser5(); + void slotUpdateStatusBar(const QString&); void slotQuit(); }; --- trunk/playground/pim/mailody/src/setupaccount.cpp #600821:600822 @@ -179,15 +179,8 @@ config->sync(); Wallet* wallet = Wallet::openWallet(Wallet::NetworkWallet()); - if (!wallet) + if (wallet && wallet->isOpen()) { - KMessageBox::error(0,i18n("Mailody could not access KWallet, " - "Mailody can not operate without it. Please activate it.")); - exit(1); - } - - if (wallet->isOpen()) - { if (!wallet->hasFolder("mailody")) wallet->createFolder( "mailody" ); @@ -220,12 +213,14 @@ Wallet* wallet = Wallet::openWallet(Wallet::NetworkWallet()); if (!wallet) { - KMessageBox::error(0,i18n("Mailody could not access KWallet, " - "Mailody can not operate without it. Please activate it.")); - exit(1); + d->password->setEnabled(false); + KMessageBox::information(0,i18n("Mailody could not access KWallet, " + "if you want to store the password permanently then you have to " + "activate it. If you don't " + "want to use KWallet, check the box below en enjoy the dialogs."), + i18n("No KWallet"), "warning_kwallet_disabled"); } - - if (wallet->isOpen() && wallet->hasFolder("mailody")) + else if (wallet->isOpen() && wallet->hasFolder("mailody")) { wallet->setFolder( "mailody" ); wallet->readPassword("account1", pass);