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 "slidesharelistdialog.h"
20 #include "ui_filelistdialog.h"
22 #include "slideshareuploaddialog.h"
23 #include "slideshareDocument.h"
25 #include <QFileDialog>
26 #include <QDesktopServices>
27 #include <QListWidgetItem>
29 #include <QMouseEvent>
30 #include <QMaemo5InformationBox>
32 slideshareListDialog::slideshareListDialog(SlideShare *s, QWidget *parent):
34 ui(new Ui::fileListDialog)
37 this->setWindowTitle("SlideShare");
38 ui->downloadProgressBar->setVisible(false);
40 ui->listTab->setCurrentIndex(1);
41 ui->listTab->removeTab(3);
42 connect(ui->uploadButton, SIGNAL(clicked()), this, SLOT(uploadButtonClickedSlot()));
43 connect(ui->downloadButton, SIGNAL(clicked()), this, SLOT(downloadButtonClickedSlot()));
44 connect(ui->refreshButton, SIGNAL(clicked()), this, SLOT(refreshList()));
45 connect(service, SIGNAL(downloadProgress(qint64, qint64)), this, SLOT(updateProgressBar(qint64, qint64)));
46 connect(service, SIGNAL(downloadDone()), this, SLOT(downloadDoneSlot()));
47 connect(service, SIGNAL(listDone()), this, SLOT(fillList()));
52 slideshareListDialog::~slideshareListDialog()
57 void slideshareListDialog::refreshList()
59 ui->downloadProgressBar->setMaximum(0);
60 ui->downloadProgressBar->setVisible(true);
61 ui->listTab->setEnabled(false);
62 ui->downloadButton->setEnabled(false);
63 ui->uploadButton->setEnabled(false);
64 ui->refreshButton->setEnabled(false);
65 service->listDocuments();
68 void slideshareListDialog::changeEvent(QEvent *e)
70 QDialog::changeEvent(e);
72 case QEvent::LanguageChange:
73 ui->retranslateUi(this);
80 void slideshareListDialog::downloadButtonClickedSlot()
83 QList<SlideShareDocument> list;
84 if(0 == ui->listTab->currentIndex()) {
85 tmp = ui->documentList;
86 list = service->textDocList;
88 if(1 == ui->listTab->currentIndex()) {
89 tmp = ui->presentationList;
90 list = service->presentationList;
92 if(2 == ui->listTab->currentIndex()) {
93 tmp = ui->spreadsheetList;
94 list = service->spreadsheetList;
97 if(tmp->currentRow() == -1) {
98 QMaemo5InformationBox::information(this, "Select a file from the list to download", QMaemo5InformationBox::DefaultTimeout);
102 SlideShareDocument p = list[tmp->currentRow()];
103 QString durl = p.downloadUrl;
105 QString saveFileName = QFileDialog::getSaveFileName(this, "Save file", QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation).append("/").append(p.title).append(".").append(p.format), QString("(*.").append(p.format).append(")"));
106 qDebug() << saveFileName << endl;
107 if("" == saveFileName) {
110 service->setSaveFileName(new QString(saveFileName));
112 service->download(&durl);
113 ui->listTab->setEnabled(false);
114 ui->downloadButton->setEnabled(false);
115 ui->uploadButton->setEnabled(false);
116 ui->refreshButton->setEnabled(false);
117 ui->downloadProgressBar->setVisible(true);
120 void slideshareListDialog::uploadButtonClickedSlot()
122 slideshareUploadDialog *ud = new slideshareUploadDialog(service, this);
123 if("" != openDocPath) {
124 ud->setOpenDoc(openDocPath);
127 connect(ud, SIGNAL(accepted()), this, SLOT(refreshList()));
130 void slideshareListDialog::fillList()
132 ui->documentList->clear();
133 ui->presentationList->clear();
134 ui->spreadsheetList->clear();
136 QList<SlideShareDocument> list;
137 QList<SlideShareDocument>::iterator i;
139 list = service->textDocList;
140 for(i = list.begin(); i != list.end(); ++i) {
141 SlideShareDocument j = *i;
142 QListWidgetItem *k = new QListWidgetItem(j.title);
143 ui->documentList->addItem(k);
146 list = service->presentationList;
147 for(i = list.begin(); i != list.end(); ++i) {
148 SlideShareDocument j = *i;
149 QListWidgetItem *k = new QListWidgetItem(j.title);
150 ui->presentationList->addItem(k);
153 list = service->spreadsheetList;
154 for(i = list.begin(); i != list.end(); ++i) {
155 SlideShareDocument j = *i;
156 QListWidgetItem *k = new QListWidgetItem(j.title);
157 ui->spreadsheetList->addItem(k);
159 ui->downloadProgressBar->setMaximum(100);
160 ui->downloadProgressBar->setVisible(false);
161 ui->listTab->setEnabled(true);
162 ui->downloadButton->setEnabled(true);
163 ui->uploadButton->setEnabled(true);
164 ui->refreshButton->setEnabled(true);
167 void slideshareListDialog::updateProgressBar(qint64 done, qint64 total)
169 int value = (done * 100 / total);
170 ui->downloadProgressBar->setValue((int)value);
173 void slideshareListDialog::downloadDoneSlot()
175 ui->downloadProgressBar->setVisible(false);
176 ui->downloadProgressBar->setValue(0);
177 ui->listTab->setEnabled(true);
178 ui->downloadButton->setEnabled(true);
179 ui->refreshButton->setEnabled(true);
180 ui->uploadButton->setEnabled(true);
181 QMaemo5InformationBox::information(this, "The file has finished downloading", QMaemo5InformationBox::DefaultTimeout);
184 void slideshareListDialog::setOpenDoc(const QString & openDocPath)
186 this->openDocPath = openDocPath;
189 bool slideshareListDialog::eventFilter(QObject *obj, QEvent *event)
191 if(event->type() == QEvent::ContextMenu) {
192 QMouseEvent *mouseEvent = static_cast<QMouseEvent*>(event);
193 QMenu *menu = new QMenu(this);
194 menu->addAction(new QAction("CLICK", this));
195 menu->exec(mouseEvent->globalPos());