Initial Commit.
[onlineservices] / googleuploaddialog.cpp
1 /*
2  *  Copyright (c) 2010 Kaushal M <kshlmster@gmail.com>
3  *
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.
8  *
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.
13  *
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.
17  */
18
19 #include "googleuploaddialog.h"
20 #include "ui_uploaddialog.h"
21
22 #include "googledocumentservice.h"
23
24 #include <QFileDialog>
25 #include <QMessageBox>
26
27 googleUploadDialog::googleUploadDialog(GoogleDocumentService *service, QWidget *parent):
28         QDialog(parent),
29         ui(new Ui::uploadDialog)
30 {
31     this->service = service;
32     ui->setupUi(this);
33     ui->descriptionBox->setVisible(false);
34     ui->tagsEdit->setVisible(false);
35     ui->label_3->setVisible(false);
36     ui->label_4->setVisible(false);
37
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()));
41 }
42
43 googleUploadDialog::~googleUploadDialog()
44 {
45     disconnect(service, SIGNAL(uploadDone(bool)), this, SLOT(uploadDoneSlot(bool)));
46     delete ui;
47 }
48
49 void googleUploadDialog::changeEvent(QEvent *e)
50 {
51     QDialog::changeEvent(e);
52     switch(e->type()) {
53     case QEvent::LanguageChange:
54         ui->retranslateUi(this);
55         break;
56     default:
57         break;
58     }
59 }
60
61 void googleUploadDialog::uploadProgressSlot(qint64 bytesSent, qint64 bytesTotal)
62 {
63     int value = (bytesSent * 100) / bytesTotal;
64     ui->uploadProgress->setValue(value);
65 }
66
67 void googleUploadDialog::showFileDialog()
68 {
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);
72 }
73
74 void googleUploadDialog::uploadButtonClickedSlot()
75 {
76     if(ui->fileSelectEdit->text() == "" || ui->titleEdit->text() == "")
77     {
78         QMessageBox::information(this,"Incomplete parameters","Please enter both filename and title");
79         return;
80     }
81     else
82     {
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)));
89     }
90 }
91
92 void googleUploadDialog::uploadDoneSlot(bool status)
93 {
94     if(!status) {
95         ui->uploadLabel->setText(tr("Upload failed"));
96         ui->uploadProgress->setValue(0);
97     }
98     else {
99         ui->uploadLabel->setText(tr("Upload completed"));
100     }
101     ui->doneButton->setEnabled(true);
102 }