2 * Copyright (c) 2010 Kaushal M <kshlmster@gmail.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 #include "googleuploaddialog.h"
20 #include "ui_uploaddialog.h"
22 #include "googledocumentservice.h"
24 #include <QFileDialog>
25 #include <QDesktopServices>
26 #include <QMaemo5InformationBox>
28 googleUploadDialog::googleUploadDialog(GoogleDocumentService *service, QWidget *parent):
30 ui(new Ui::uploadDialog)
32 this->service = service;
34 ui->descriptionBox->setVisible(false);
35 ui->tagsEdit->setVisible(false);
36 ui->label_3->setVisible(false);
37 ui->label_4->setVisible(false);
39 connect(service, SIGNAL(uploadProgress(qint64, qint64)), this, SLOT(uploadProgressSlot(qint64, qint64)));
40 connect(ui->fileSelectButton, SIGNAL(clicked()), this, SLOT(showFileDialog()));
41 connect(ui->uploadButton, SIGNAL(clicked()), this, SLOT(uploadButtonClickedSlot()));
44 googleUploadDialog::~googleUploadDialog()
46 disconnect(service, SIGNAL(uploadDone(bool)), this, SLOT(uploadDoneSlot(bool)));
50 void googleUploadDialog::setOpenDoc(const QString & openDocPath)
52 ui->fileSelectEdit->setText(openDocPath);
55 void googleUploadDialog::changeEvent(QEvent *e)
57 QDialog::changeEvent(e);
59 case QEvent::LanguageChange:
60 ui->retranslateUi(this);
67 void googleUploadDialog::uploadProgressSlot(qint64 bytesSent, qint64 bytesTotal)
69 int value = (bytesSent * 100) / bytesTotal;
70 ui->uploadProgress->setValue(value);
73 void googleUploadDialog::showFileDialog()
75 QString currentFile = ("" == ui->fileSelectEdit->text()) ? QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation) : ui->fileSelectEdit->text();
76 QString filter = "Supported Files (*.odt *.doc *.ppt *.xls)";
77 QString filename = QFileDialog::getOpenFileName(this, QString("Select File"), currentFile, filter, &filter);
79 ui->fileSelectEdit->setText(filename);
82 void googleUploadDialog::uploadButtonClickedSlot()
84 if(ui->fileSelectEdit->text() == "" || ui->titleEdit->text() == "") {
85 QMaemo5InformationBox::information(this, "Please enter both filename and title");
88 ui->fileSelectButton->setEnabled(false);
89 ui->titleEdit->setEnabled(false);
90 ui->uploadButton->setEnabled(false);
91 service->uploadDocument(&ui->fileSelectEdit->text(), &ui->titleEdit->text());
92 connect(service, SIGNAL(uploadDone(bool)), this, SLOT(uploadDoneSlot(bool)));
96 void googleUploadDialog::uploadDoneSlot(bool status)
99 QMaemo5InformationBox::information(this, "\nUpload failed\n", QMaemo5InformationBox::NoTimeout);
101 QMaemo5InformationBox::information(this, "Upload completed");
103 ui->doneButton->setEnabled(true);