From 242f7a04e3e4963a5606ac603d54a4f115de4a04 Mon Sep 17 00:00:00 2001 From: alwin Date: Wed, 24 Dec 2003 01:29:43 +0000 Subject: tried to implement a progress dialog when sending mails. It doesn't work (dialog will show but makes no updates, when using qApp->progressEvents(x) dialog hides) I don't know why - and I giving up for the moment. --- (limited to 'noncore') diff --git a/noncore/net/mail/libmailwrapper/sendmailprogress.cpp b/noncore/net/mail/libmailwrapper/sendmailprogress.cpp new file mode 100644 index 0000000..13ddd37 --- a/dev/null +++ b/noncore/net/mail/libmailwrapper/sendmailprogress.cpp @@ -0,0 +1,48 @@ +#include "sendmailprogress.h" +#include +#include +#include + +progressMailSend::progressMailSend(QWidget*parent, const char * name) + :progressMailSendUI(parent,name,false),m_current_mail(0),m_current_single(0),m_max_mail(0),m_max_single(0) +{ +} + +progressMailSend::~progressMailSend() +{ +} + +void progressMailSend::setMaxMails(unsigned int aMaxMails) +{ + m_max_mail = aMaxMails; + allMailProgressBar->setTotalSteps(aMaxMails); + setMails(); +} + +void progressMailSend::setCurrentMails(unsigned int aCurrent) +{ + m_current_mail = aCurrent; + allMailProgressBar->setProgress(aCurrent); + setMails(); +} + +void progressMailSend::setSingleMail(unsigned int aCurrent,unsigned int aMax) +{ + m_current_single = aCurrent; + m_max_single = aMax; + setSingle(); +} + +void progressMailSend::setSingle() +{ + QString text = QString(tr("%1 of %2 bytes send")).arg(m_current_single).arg(m_max_single); + singleMailLabel->setText(text); + singleMailProgressBar->setTotalSteps(m_max_single); + singleMailProgressBar->setProgress(m_current_single); +} + +void progressMailSend::setMails() +{ + QString text = QString(tr("Sending mail %1 of %2")).arg(m_current_single+1).arg(m_max_single); + allMailLabel->setText(text); +} diff --git a/noncore/net/mail/libmailwrapper/sendmailprogress.h b/noncore/net/mail/libmailwrapper/sendmailprogress.h new file mode 100644 index 0000000..5b7d33b --- a/dev/null +++ b/noncore/net/mail/libmailwrapper/sendmailprogress.h @@ -0,0 +1,19 @@ +#include "sendmailprogressui.h" + +class progressMailSend:public progressMailSendUI +{ + Q_OBJECT +public: + progressMailSend(QWidget*parent = 0, const char * name = 0); + ~progressMailSend(); + + void setMaxMails(unsigned int aMaxMails); + void setCurrentMails(unsigned int aCurrent); + + void setSingleMail(unsigned int aCurrent,unsigned int aMax); + +protected: + unsigned m_current_mail,m_current_single,m_max_mail,m_max_single; + void setSingle(); + void setMails(); +}; diff --git a/noncore/net/mail/libmailwrapper/sendmailprogressui.ui b/noncore/net/mail/libmailwrapper/sendmailprogressui.ui new file mode 100644 index 0000000..b90b088 --- a/dev/null +++ b/noncore/net/mail/libmailwrapper/sendmailprogressui.ui @@ -0,0 +1,110 @@ + +progressMailSendUI + + QDialog + + name + progressMailSendUI + + + geometry + + 0 + 0 + 316 + 266 + + + + caption + Sending mail + + + layoutMargin + + + layoutSpacing + + + + margin + 4 + + + spacing + 2 + + + QLabel + + name + singleMailLabel + + + text + Progress of mail + + + alignment + AlignCenter + + + hAlign + + + + QProgressBar + + name + singleMailProgressBar + + + + QLabel + + name + allMailLabel + + + text + Sending mail + + + alignment + AlignCenter + + + hAlign + + + + QProgressBar + + name + allMailProgressBar + + + + + name + Spacer6 + + + orientation + Vertical + + + sizeType + Expanding + + + sizeHint + + 20 + 20 + + + + + + diff --git a/noncore/net/mail/libmailwrapper/smtpwrapper.cpp b/noncore/net/mail/libmailwrapper/smtpwrapper.cpp index b81a87f..53c0af5 100644 --- a/noncore/net/mail/libmailwrapper/smtpwrapper.cpp +++ b/noncore/net/mail/libmailwrapper/smtpwrapper.cpp @@ -15,6 +15,9 @@ #include "logindialog.h" #include "mailtypes.h" #include "defines.h" +#include "sendmailprogress.h" + +progressMailSend*SMTPwrapper::sendProgress = 0; SMTPwrapper::SMTPwrapper( Settings *s ) : QObject() @@ -520,7 +523,10 @@ void SMTPwrapper::readFromFile(const QString&file, char **data, size_t *size ) void SMTPwrapper::progress( size_t current, size_t maximum ) { -// qDebug( "Current: %i of %i", current, maximum ); + if (SMTPwrapper::sendProgress) { + SMTPwrapper::sendProgress->setSingleMail(current, maximum ); + qDebug("%u of %u",current,maximum); + } } void SMTPwrapper::storeMail(char*mail, size_t length, const QString&box) @@ -645,9 +651,16 @@ void SMTPwrapper::sendMail(const Mail&mail,bool later ) if ( mimeMail == NULL ) { qDebug( "sendMail: error creating mime mail" ); } else { + sendProgress = new progressMailSend(); + sendProgress->showMaximized(); + sendProgress->show(); + qApp->processEvents(10); smtpSend( mimeMail,later,smtp); mailmime_free( mimeMail ); qDebug("Clean up done"); + sendProgress->hide(); + delete sendProgress; + sendProgress = 0; } } @@ -673,6 +686,7 @@ int SMTPwrapper::sendQueuedMail(MBOXwrapper*wrap,SMTPaccount*smtp,RecMail*which) rcpts = createRcptList( fields ); ffrom = getField(fields, MAILIMF_FIELD_FROM ); from = getFrom(ffrom); + qDebug("Size: %i vs. %i",length,strlen(data)); if (rcpts && from) { return smtpSend(from,rcpts,data,strlen(data),smtp ); diff --git a/noncore/net/mail/libmailwrapper/smtpwrapper.h b/noncore/net/mail/libmailwrapper/smtpwrapper.h index c0dcc11..baa353b 100644 --- a/noncore/net/mail/libmailwrapper/smtpwrapper.h +++ b/noncore/net/mail/libmailwrapper/smtpwrapper.h @@ -18,6 +18,7 @@ struct mailimf_field; struct mailimf_mailbox; struct mailmime; struct mailimf_address_list; +class progressMailSend; class SMTPwrapper : public QObject { @@ -29,6 +30,7 @@ public: void sendMail(const Mail& mail,bool later=false ); void flushOutbox(SMTPaccount*smtp); + static progressMailSend*sendProgress; protected: mailimf_mailbox *newMailbox(const QString&name,const QString&mail ); mailimf_fields *createImfFields(const Mail &mail ); @@ -52,7 +54,7 @@ protected: static char *getFrom( mailmime *mail ); static char *getFrom( mailimf_field *ffrom); static mailimf_field *getField( mailimf_fields *fields, int type ); - static int smtpSend(char*from,clist*rcpts,char*data,size_t size, SMTPaccount *smtp ); + int smtpSend(char*from,clist*rcpts,char*data,size_t size, SMTPaccount *smtp ); void storeMail(mailmime*mail, const QString&box); Settings *settings; diff --git a/noncore/net/mail/mail.pro b/noncore/net/mail/mail.pro index dd3c337..ea5fb58 100644 --- a/noncore/net/mail/mail.pro +++ b/noncore/net/mail/mail.pro @@ -20,7 +20,8 @@ HEADERS = defines.h \ statuswidget.h \ smtpwrapper.h \ genericwrapper.h \ - mboxwrapper.h + mboxwrapper.h \ + sendmailprogress.h SOURCES = main.cpp \ opiemail.cpp \ @@ -42,7 +43,8 @@ SOURCES = main.cpp \ statuswidget.cpp \ smtpwrapper.cpp \ genericwrapper.cpp \ - mboxwrapper.cpp + mboxwrapper.cpp \ + sendmailprogress.cpp INTERFACES = editaccountsui.ui \ selectmailtypeui.ui \ @@ -54,7 +56,8 @@ INTERFACES = editaccountsui.ui \ logindialogui.ui \ composemailui.ui \ settingsdialogui.ui \ - statuswidgetui.ui + statuswidgetui.ui \ + sendmailprogressui.ui INCLUDEPATH += $(OPIEDIR)/include diff --git a/noncore/net/mail/sendmailprogress.cpp b/noncore/net/mail/sendmailprogress.cpp new file mode 100644 index 0000000..13ddd37 --- a/dev/null +++ b/noncore/net/mail/sendmailprogress.cpp @@ -0,0 +1,48 @@ +#include "sendmailprogress.h" +#include +#include +#include + +progressMailSend::progressMailSend(QWidget*parent, const char * name) + :progressMailSendUI(parent,name,false),m_current_mail(0),m_current_single(0),m_max_mail(0),m_max_single(0) +{ +} + +progressMailSend::~progressMailSend() +{ +} + +void progressMailSend::setMaxMails(unsigned int aMaxMails) +{ + m_max_mail = aMaxMails; + allMailProgressBar->setTotalSteps(aMaxMails); + setMails(); +} + +void progressMailSend::setCurrentMails(unsigned int aCurrent) +{ + m_current_mail = aCurrent; + allMailProgressBar->setProgress(aCurrent); + setMails(); +} + +void progressMailSend::setSingleMail(unsigned int aCurrent,unsigned int aMax) +{ + m_current_single = aCurrent; + m_max_single = aMax; + setSingle(); +} + +void progressMailSend::setSingle() +{ + QString text = QString(tr("%1 of %2 bytes send")).arg(m_current_single).arg(m_max_single); + singleMailLabel->setText(text); + singleMailProgressBar->setTotalSteps(m_max_single); + singleMailProgressBar->setProgress(m_current_single); +} + +void progressMailSend::setMails() +{ + QString text = QString(tr("Sending mail %1 of %2")).arg(m_current_single+1).arg(m_max_single); + allMailLabel->setText(text); +} diff --git a/noncore/net/mail/sendmailprogress.h b/noncore/net/mail/sendmailprogress.h new file mode 100644 index 0000000..5b7d33b --- a/dev/null +++ b/noncore/net/mail/sendmailprogress.h @@ -0,0 +1,19 @@ +#include "sendmailprogressui.h" + +class progressMailSend:public progressMailSendUI +{ + Q_OBJECT +public: + progressMailSend(QWidget*parent = 0, const char * name = 0); + ~progressMailSend(); + + void setMaxMails(unsigned int aMaxMails); + void setCurrentMails(unsigned int aCurrent); + + void setSingleMail(unsigned int aCurrent,unsigned int aMax); + +protected: + unsigned m_current_mail,m_current_single,m_max_mail,m_max_single; + void setSingle(); + void setMails(); +}; diff --git a/noncore/net/mail/sendmailprogressui.ui b/noncore/net/mail/sendmailprogressui.ui new file mode 100644 index 0000000..b90b088 --- a/dev/null +++ b/noncore/net/mail/sendmailprogressui.ui @@ -0,0 +1,110 @@ + +progressMailSendUI + + QDialog + + name + progressMailSendUI + + + geometry + + 0 + 0 + 316 + 266 + + + + caption + Sending mail + + + layoutMargin + + + layoutSpacing + + + + margin + 4 + + + spacing + 2 + + + QLabel + + name + singleMailLabel + + + text + Progress of mail + + + alignment + AlignCenter + + + hAlign + + + + QProgressBar + + name + singleMailProgressBar + + + + QLabel + + name + allMailLabel + + + text + Sending mail + + + alignment + AlignCenter + + + hAlign + + + + QProgressBar + + name + allMailProgressBar + + + + + name + Spacer6 + + + orientation + Vertical + + + sizeType + Expanding + + + sizeHint + + 20 + 20 + + + + + + diff --git a/noncore/net/mail/smtpwrapper.cpp b/noncore/net/mail/smtpwrapper.cpp index b81a87f..53c0af5 100644 --- a/noncore/net/mail/smtpwrapper.cpp +++ b/noncore/net/mail/smtpwrapper.cpp @@ -15,6 +15,9 @@ #include "logindialog.h" #include "mailtypes.h" #include "defines.h" +#include "sendmailprogress.h" + +progressMailSend*SMTPwrapper::sendProgress = 0; SMTPwrapper::SMTPwrapper( Settings *s ) : QObject() @@ -520,7 +523,10 @@ void SMTPwrapper::readFromFile(const QString&file, char **data, size_t *size ) void SMTPwrapper::progress( size_t current, size_t maximum ) { -// qDebug( "Current: %i of %i", current, maximum ); + if (SMTPwrapper::sendProgress) { + SMTPwrapper::sendProgress->setSingleMail(current, maximum ); + qDebug("%u of %u",current,maximum); + } } void SMTPwrapper::storeMail(char*mail, size_t length, const QString&box) @@ -645,9 +651,16 @@ void SMTPwrapper::sendMail(const Mail&mail,bool later ) if ( mimeMail == NULL ) { qDebug( "sendMail: error creating mime mail" ); } else { + sendProgress = new progressMailSend(); + sendProgress->showMaximized(); + sendProgress->show(); + qApp->processEvents(10); smtpSend( mimeMail,later,smtp); mailmime_free( mimeMail ); qDebug("Clean up done"); + sendProgress->hide(); + delete sendProgress; + sendProgress = 0; } } @@ -673,6 +686,7 @@ int SMTPwrapper::sendQueuedMail(MBOXwrapper*wrap,SMTPaccount*smtp,RecMail*which) rcpts = createRcptList( fields ); ffrom = getField(fields, MAILIMF_FIELD_FROM ); from = getFrom(ffrom); + qDebug("Size: %i vs. %i",length,strlen(data)); if (rcpts && from) { return smtpSend(from,rcpts,data,strlen(data),smtp ); diff --git a/noncore/net/mail/smtpwrapper.h b/noncore/net/mail/smtpwrapper.h index c0dcc11..baa353b 100644 --- a/noncore/net/mail/smtpwrapper.h +++ b/noncore/net/mail/smtpwrapper.h @@ -18,6 +18,7 @@ struct mailimf_field; struct mailimf_mailbox; struct mailmime; struct mailimf_address_list; +class progressMailSend; class SMTPwrapper : public QObject { @@ -29,6 +30,7 @@ public: void sendMail(const Mail& mail,bool later=false ); void flushOutbox(SMTPaccount*smtp); + static progressMailSend*sendProgress; protected: mailimf_mailbox *newMailbox(const QString&name,const QString&mail ); mailimf_fields *createImfFields(const Mail &mail ); @@ -52,7 +54,7 @@ protected: static char *getFrom( mailmime *mail ); static char *getFrom( mailimf_field *ffrom); static mailimf_field *getField( mailimf_fields *fields, int type ); - static int smtpSend(char*from,clist*rcpts,char*data,size_t size, SMTPaccount *smtp ); + int smtpSend(char*from,clist*rcpts,char*data,size_t size, SMTPaccount *smtp ); void storeMail(mailmime*mail, const QString&box); Settings *settings; -- cgit v0.9.0.2