Skip to content

Commit

Permalink
[demo] Cache server object so that the same one is used
Browse files Browse the repository at this point in the history
  • Loading branch information
dantti committed Jan 8, 2020
1 parent d21e4c1 commit a57d7a5
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
28 changes: 23 additions & 5 deletions demos/demo2/sendemail.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,29 @@ void SendEmail::on_sendEmail_clicked()
void SendEmail::sendMailAsync(const MimeMessage &msg)
{
qDebug() << "sendMailAsync";
auto server = new Server(this);
server->setHost(ui->host->text());
server->setPort(quint16(ui->port->value()));
server->setConnectionType(ui->security->currentIndex() == 0 ? Server::TcpConnection :
ui->security->currentIndex() == 1 ? Server::SslConnection : Server::TlsConnection);

const QString host = ui->host->text();
const quint16 port(ui->port->value());
const Server::ConnectionType ct = ui->security->currentIndex() == 0 ?
Server::TcpConnection : ui->security->currentIndex() == 1 ?
Server::SslConnection : Server::TlsConnection;

Server *server = nullptr;
for (auto srv : m_aServers) {
if (srv->host() == host && srv->port() == port & srv->connectionType() == ct) {
server = srv;
break;
}
}

if (!server) {
server = new Server(this);
server->setHost(host);
server->setPort(port);
server->setConnectionType(ct);
m_aServers.push_back(server);
}

const QString user = ui->username->text();
if (!user.isEmpty()) {
server->setAuthMethod(Server::AuthLogin);
Expand Down
5 changes: 5 additions & 0 deletions demos/demo2/sendemail.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ namespace Ui {
class SendEmail;
}

namespace SimpleMail {
class Server;
}

using namespace SimpleMail;

class SendEmail : public QWidget
Expand All @@ -45,6 +49,7 @@ private Q_SLOTS:

private:
QSettings m_settings;
std::vector<Server *> m_aServers;
Ui::SendEmail *ui;

void errorMessage(const QString & message);
Expand Down

0 comments on commit a57d7a5

Please sign in to comment.