limit subtask list
[Sak.git] / gmailstorage / gmailmyinterface.cpp
bloba554b5efe85dc3cfaef383cff33c8f0cf6c6af95
1 #include "gmailmyinterface.h"
3 #include "mailsender.h"
5 #include <QFileInfo>
6 #include <QDebug>
7 #include <QFile>
8 #include <QResource>
9 #include <QtGui>
11 #include <QFuture>
12 #include <qtconcurrentrun.h>
14 GmailPyInterface::GmailPyInterface()
16 m_sender=0;
19 GmailPyInterface::~GmailPyInterface()
24 bool GmailPyInterface::login()
26 bool goon=true;
27 while(m_user == "" || m_pass == "") {
28 QDialog d;
29 d.setModal(true);
30 QLineEdit* user(new QLineEdit);
31 QLineEdit* pass(new QLineEdit);
32 pass->setEchoMode(QLineEdit::Password);
33 QVBoxLayout* layout(new QVBoxLayout);
34 d.setLayout(layout);
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);
50 d.exec();
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();
55 break;
56 } else return false;
58 delete m_sender;
59 m_sender = 0;
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);
64 return true;
68 void GmailPyInterface::storeTaskFiles(const QStringList& filePaths)
70 bool overide=false;
72 if (!login()) {
73 if (overide)
74 QApplication::restoreOverrideCursor();
75 return;
79 QProgressDialog progress("Saving files to GMAIL...", "Abort Copy", 0, filePaths.size(), 0);
80 progress.setWindowModality(Qt::WindowModal);
81 int value=0;
82 foreach(const QString& filePath, filePaths) {
83 progress.setValue(++value);
84 progress.setLabelText("Sending to gmail " + filePath);
85 QString taskName = QFileInfo(filePath).baseName();
87 if (!overide) {
88 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
89 overide=true;
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());
95 break;
97 if (progress.wasCanceled())
98 break;
100 if (overide)
101 QApplication::restoreOverrideCursor();