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 "googlelistdialog.h"
20 #include "ui_filelistdialog.h"
22 #include "googledocument.h"
23 #include "googleuploaddialog.h"
25 #include <QMaemo5InformationBox>
26 #include <QFileDialog>
27 #include <QDesktopServices>
29 googleListDialog::googleListDialog(GoogleDocumentService *service, QWidget *parent):
31 ui(new Ui::fileListDialog)
34 this->setWindowTitle("Google Docs");
35 this->service = service;
36 ui->listTab->setCurrentIndex(0);
37 ui->downloadProgressBar->setVisible(false);
39 connect(ui->downloadButton, SIGNAL(clicked()), this, SLOT(downloadButtonClickedSlot()));
40 connect(ui->uploadButton, SIGNAL(clicked()), this, SLOT(uploadButtonClickedSlot()));
41 connect(ui->refreshButton, SIGNAL(clicked()), this, SLOT(refreshList()));
42 connect(service, SIGNAL(listDone(bool)), this, SLOT(fillList(bool)));
43 connect(service, SIGNAL(downloadDone(bool)), this, SLOT(downloadDoneSlot(bool)));
44 connect(service, SIGNAL(downloadProgress(qint64, qint64)), this, SLOT(updateProgressBar(qint64, qint64)));
48 void googleListDialog::changeEvent(QEvent *e)
50 QDialog::changeEvent(e);
52 case QEvent::LanguageChange:
53 ui->retranslateUi(this);
60 void googleListDialog::refreshList()
62 ui->listTab->setEnabled(false);
63 ui->downloadButton->setEnabled(false);
64 ui->uploadButton->setEnabled(false);
65 ui->refreshButton->setEnabled(false);
66 ui->downloadProgressBar->setMinimum(0);
67 ui->downloadProgressBar->setMaximum(0);
68 ui->downloadProgressBar->setVisible(true);
69 service->listDocuments();
72 void googleListDialog::fillList(bool status)
75 ui->documentList->clear();
76 ui->presentationList->clear();
77 ui->spreadsheetList->clear();
78 ui->othersList->clear();
80 QList<GoogleDocument *> list;
82 list = service->documentList;
83 foreach(GoogleDocument * i, list) {
84 ui->documentList->addItem(i->title());
87 list = service->presentationList;
88 foreach(GoogleDocument * i, list) {
89 ui->presentationList->addItem(i->title());
92 list = service->spreadsheetList;
93 foreach(GoogleDocument * i, list) {
94 ui->spreadsheetList->addItem(i->title());
97 list = service->othersList;
98 foreach(GoogleDocument * i, list) {
99 ui->othersList->addItem(i->title());
102 QMaemo5InformationBox::information(this, "<p><b>Error</b></p> <p>An error occured while fetching document list</p>", QMaemo5InformationBox::NoTimeout);
104 ui->downloadProgressBar->setMaximum(100);
105 ui->downloadProgressBar->setVisible(false);
106 ui->listTab->setEnabled(true);
107 ui->downloadButton->setEnabled(true);
108 ui->uploadButton->setEnabled(true);
109 ui->refreshButton->setEnabled(true);
112 void googleListDialog::downloadButtonClickedSlot()
114 QList<GoogleDocument *> list;
115 QListWidget *tmp = 0;
116 switch(ui->listTab->currentIndex()) {
118 tmp = ui->documentList;
119 list = service->documentList;
122 tmp = ui->presentationList;
123 list = service->presentationList;
126 tmp = ui->spreadsheetList;
127 list = service->spreadsheetList;
130 tmp = ui->othersList;
131 list = service->othersList;
134 if(-1 == tmp->currentRow()) {
135 QMaemo5InformationBox::information(this, "Select a file from the list to download", QMaemo5InformationBox::DefaultTimeout);
138 GoogleDocument *doc = list[tmp->currentRow()];
140 if("presentation" == doc->documentType()) {
142 } else if("document" == doc->documentType()) {
144 } else if("spreadsheet" == doc->documentType()) {
147 QString filename = QFileDialog::getSaveFileName(this, "Save File", QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation) + "/" + doc->title() + format, "(*" + format + ")");
150 service->downloadDocument(doc, new QString(filename));
151 ui->listTab->setEnabled(false);
152 ui->uploadButton->setEnabled(false);
153 ui->downloadButton->setEnabled(false);
154 ui->refreshButton->setEnabled(false);
155 ui->downloadProgressBar->setVisible(true);
158 void googleListDialog::uploadButtonClickedSlot()
160 googleUploadDialog *ud = new googleUploadDialog(service, this);
161 if("" != openDocPath) {
162 ud->setOpenDoc(openDocPath);
165 connect(ud, SIGNAL(accepted()), this, SLOT(refreshList()));
168 void googleListDialog::downloadDoneSlot(bool status)
170 ui->downloadProgressBar->setVisible(false);
171 ui->downloadProgressBar->setValue(0);
172 ui->listTab->setEnabled(true);
173 ui->downloadButton->setEnabled(true);
174 ui->refreshButton->setEnabled(true);
175 ui->uploadButton->setEnabled(true);
177 QMaemo5InformationBox::information(this, "The file has finished downloading", QMaemo5InformationBox::DefaultTimeout);
179 QMaemo5InformationBox::information(this, "<p><b>Error</b></p> <p>An error occured while downloading the document</p>", QMaemo5InformationBox::NoTimeout);
182 void googleListDialog::updateProgressBar(qint64 bytesDone, qint64 bytesTotal)
184 int value = (bytesDone * 100) / bytesTotal;
185 ui->downloadProgressBar->setValue(value);
188 void googleListDialog::setOpenDoc(const QString & openDocPath)
190 this->openDocPath = openDocPath;