Added openssl-dev dependency
[froff-onlinedoc] / 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 <QDesktopServices>
26 #include <QMaemo5InformationBox>
27
28 googleUploadDialog::googleUploadDialog(GoogleDocumentService *service, QWidget *parent):
29     QDialog(parent),
30     ui(new Ui::uploadDialog)
31 {
32     this->service = service;
33     ui->setupUi(this);
34     ui->descriptionBox->setVisible(false);
35     ui->tagsEdit->setVisible(false);
36     ui->label_3->setVisible(false);
37     ui->label_4->setVisible(false);
38
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()));
42 }
43
44 googleUploadDialog::~googleUploadDialog()
45 {
46     disconnect(service, SIGNAL(uploadDone(bool)), this, SLOT(uploadDoneSlot(bool)));
47     delete ui;
48 }
49
50 void googleUploadDialog::setOpenDoc(const QString & openDocPath)
51 {
52     ui->fileSelectEdit->setText(openDocPath);
53 }
54
55 void googleUploadDialog::changeEvent(QEvent *e)
56 {
57     QDialog::changeEvent(e);
58     switch(e->type()) {
59     case QEvent::LanguageChange:
60         ui->retranslateUi(this);
61         break;
62     default:
63         break;
64     }
65 }
66
67 void googleUploadDialog::uploadProgressSlot(qint64 bytesSent, qint64 bytesTotal)
68 {
69     int value = (bytesSent * 100) / bytesTotal;
70     ui->uploadProgress->setValue(value);
71 }
72
73 void googleUploadDialog::showFileDialog()
74 {
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);
78     if("" != filename)
79         ui->fileSelectEdit->setText(filename);
80 }
81
82 void googleUploadDialog::uploadButtonClickedSlot()
83 {
84     if(ui->fileSelectEdit->text() == "" || ui->titleEdit->text() == "") {
85         QMaemo5InformationBox::information(this, "Please enter both filename and title");
86         return;
87     } else {
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)));
93     }
94 }
95
96 void googleUploadDialog::uploadDoneSlot(bool status)
97 {
98     if(!status) {
99         QMaemo5InformationBox::information(this, "\nUpload failed\n", QMaemo5InformationBox::NoTimeout);
100     } else {
101         QMaemo5InformationBox::information(this, "Upload completed");
102     }
103     ui->doneButton->setEnabled(true);
104 }