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 <QMessageBox>
27 googleUploadDialog::googleUploadDialog(GoogleDocumentService *service, QWidget *parent):
29 ui(new Ui::uploadDialog)
31 this->service = service;
33 ui->descriptionBox->setVisible(false);
34 ui->tagsEdit->setVisible(false);
35 ui->label_3->setVisible(false);
36 ui->label_4->setVisible(false);
38 connect(service, SIGNAL(uploadProgress(qint64,qint64)), this, SLOT(uploadProgressSlot(qint64,qint64)));
39 connect(ui->fileSelectButton, SIGNAL(clicked()), this, SLOT(showFileDialog()));
40 connect(ui->uploadButton, SIGNAL(clicked()), this, SLOT(uploadButtonClickedSlot()));
43 googleUploadDialog::~googleUploadDialog()
45 disconnect(service, SIGNAL(uploadDone(bool)), this, SLOT(uploadDoneSlot(bool)));
49 void googleUploadDialog::changeEvent(QEvent *e)
51 QDialog::changeEvent(e);
53 case QEvent::LanguageChange:
54 ui->retranslateUi(this);
61 void googleUploadDialog::uploadProgressSlot(qint64 bytesSent, qint64 bytesTotal)
63 int value = (bytesSent * 100) / bytesTotal;
64 ui->uploadProgress->setValue(value);
67 void googleUploadDialog::showFileDialog()
69 QString filter = "Supported Files (odt doc ppt xls)(*.odt *.doc *.ppt *.xls);; Documents (odt doc)(*.odt *.doc);; Presentations (ppt)(*.ppt) ;; Spreadsheets(xls)(*.xls)";
70 QString filename = QFileDialog::getOpenFileName(this,QString("Select File"),tr(""),filter);
71 ui->fileSelectEdit->setText(filename);
74 void googleUploadDialog::uploadButtonClickedSlot()
76 if(ui->fileSelectEdit->text() == "" || ui->titleEdit->text() == "")
78 QMessageBox::information(this,"Incomplete parameters","Please enter both filename and title");
83 ui->fileSelectButton->setEnabled(false);
84 ui->titleEdit->setEnabled(false);
85 ui->uploadButton->setEnabled(false);
86 ui->uploadLabel->setText(tr("Uploading file.."));
87 service->uploadDocument(&ui->fileSelectEdit->text(), &ui->titleEdit->text());
88 connect(service, SIGNAL(uploadDone(bool)), this, SLOT(uploadDoneSlot(bool)));
92 void googleUploadDialog::uploadDoneSlot(bool status)
95 ui->uploadLabel->setText(tr("Upload failed"));
96 ui->uploadProgress->setValue(0);
99 ui->uploadLabel->setText(tr("Upload completed"));
101 ui->doneButton->setEnabled(true);