1 #include "gmailmyinterface.h"
3 #include "mailsender.h"
12 #include <qtconcurrentrun.h>
14 GmailPyInterface::GmailPyInterface()
19 GmailPyInterface::~GmailPyInterface()
24 bool GmailPyInterface::login()
27 while(m_user
== "" || m_pass
== "") {
30 QLineEdit
* user(new QLineEdit
);
31 QLineEdit
* pass(new QLineEdit
);
32 pass
->setEchoMode(QLineEdit::Password
);
33 QVBoxLayout
* layout(new QVBoxLayout
);
35 layout
->addWidget(new QLabel("Enter you gmail account:"));
36 QGridLayout
* glayout(new QGridLayout());
37 glayout
->addWidget(new QLabel("Username:"),0,0);
38 glayout
->addWidget(user
,0,1);
39 glayout
->addWidget(new QLabel("Password:"),1,0);
40 glayout
->addWidget(pass
,1,1);
41 layout
->addLayout(glayout
);
42 QHBoxLayout
* buttons(new QHBoxLayout
);
43 QPushButton
* okbutton(new QPushButton("Ok"));
44 QPushButton
* cancelbutton(new QPushButton("Cancel"));
45 QObject::connect(okbutton
, SIGNAL(clicked()), &d
, SLOT(accept()));
46 QObject::connect(cancelbutton
, SIGNAL(clicked()), &d
, SLOT(reject()));
47 buttons
->addWidget(okbutton
);
48 buttons
->addWidget(cancelbutton
);
49 layout
->addLayout(buttons
);
51 if (d
.result() == QDialog::Accepted
) {
52 if (user
->text().isEmpty() || pass
->text().isEmpty()) continue;
53 m_user
= user
->text();
54 m_pass
= pass
->text();
60 m_sender
= new MailSender("smtp.gmail.com", m_user
+ "@gmail.com", QStringList(m_user
+ "@gmail.com"), "@SAK", "Enjoy!");
61 m_sender
->setSsl(true);
62 m_sender
->setPort(587);
63 m_sender
->setLogin(m_user
, m_pass
);
68 void GmailPyInterface::storeTaskFiles(const QStringList
& filePaths
)
74 QApplication::restoreOverrideCursor();
79 QProgressDialog
progress("Saving files to GMAIL...", "Abort Copy", 0, filePaths
.size(), 0);
80 progress
.setWindowModality(Qt::WindowModal
);
82 foreach(const QString
& filePath
, filePaths
) {
83 progress
.setValue(++value
);
84 progress
.setLabelText("Sending to gmail " + filePath
);
85 QString taskName
= QFileInfo(filePath
).baseName();
88 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor
));
91 m_sender
->setAttachments(QStringList(filePath
));
92 m_sender
->setSubject(taskName
+ "@SAK");
93 if (!m_sender
->send()) {
94 QMessageBox::warning(0, "Error!", "Error: " + m_sender
->lastError() + "\nexecuting command: " + m_sender
->lastCmd() + "\nResponse: " + m_sender
->lastResponse());
97 if (progress
.wasCanceled())
101 QApplication::restoreOverrideCursor();