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 <QMessageBox>
26 #include <QFileDialog>
27 #include <QDesktopServices>
28 #include <QListWidgetItem>
30 #include <QMouseEvent>
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->listTab->setEnabled(false);
60 ui->downloadButton->setEnabled(false);
61 ui->uploadButton->setEnabled(false);
62 ui->refreshButton->setEnabled(false);
63 service->listDocuments();
66 void slideshareListDialog::changeEvent(QEvent *e)
68 QDialog::changeEvent(e);
70 case QEvent::LanguageChange:
71 ui->retranslateUi(this);
78 void slideshareListDialog::downloadButtonClickedSlot()
81 QList<SlideShareDocument> list;
82 if(0 == ui->listTab->currentIndex())
84 tmp = ui->documentList;
85 list = service->textDocList;
87 if(1 == ui->listTab->currentIndex())
89 tmp = ui->presentationList;
90 list = service->presentationList;
92 if(2 == ui->listTab->currentIndex())
94 tmp = ui->spreadsheetList;
95 list = service->spreadsheetList;
98 if(tmp->currentRow() == -1)
100 QMessageBox::information(this, QString("No selection"), QString("Please select a file from the list"));
104 SlideShareDocument p = list[tmp->currentRow()];
105 QString durl = p.downloadUrl;
107 QString saveFileName = QFileDialog::getSaveFileName(this, "Save file", QDesktopServices::storageLocation(QDesktopServices::HomeLocation).append("/").append(p.title).append(p.format), QString("(*.").append(p.format).append(")"));
108 qDebug() << saveFileName << endl;
109 if("" == saveFileName)
113 service->setSaveFileName(new QString(saveFileName));
115 service->download(&durl);
116 ui->listTab->setEnabled(false);
117 ui->downloadButton->setEnabled(false);
118 ui->uploadButton->setEnabled(false);
119 ui->refreshButton->setEnabled(false);
120 ui->downloadProgressBar->setVisible(true);
123 void slideshareListDialog::uploadButtonClickedSlot()
125 slideshareUploadDialog *ud = new slideshareUploadDialog(service, this);
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)
142 SlideShareDocument j = *i;
143 QListWidgetItem *k = new QListWidgetItem(j.title);
144 ui->documentList->addItem(k);
147 list = service->presentationList;
148 for(i = list.begin(); i != list.end(); ++i)
150 SlideShareDocument j = *i;
151 QListWidgetItem *k = new QListWidgetItem(j.title);
152 ui->presentationList->addItem(k);
155 list = service->spreadsheetList;
156 for(i = list.begin(); i != list.end(); ++i)
158 SlideShareDocument j = *i;
159 QListWidgetItem *k = new QListWidgetItem(j.title);
160 ui->spreadsheetList->addItem(k);
163 ui->listTab->setEnabled(true);
164 ui->downloadButton->setEnabled(true);
165 ui->uploadButton->setEnabled(true);
166 ui->refreshButton->setEnabled(true);
169 void slideshareListDialog::updateProgressBar(qint64 done, qint64 total)
171 int value = (done * 100/total);
172 ui->downloadProgressBar->setValue((int)value);
175 void slideshareListDialog::downloadDoneSlot()
177 ui->downloadProgressBar->setVisible(false);
178 ui->downloadProgressBar->setValue(0);
179 ui->listTab->setEnabled(true);
180 ui->downloadButton->setEnabled(true);
181 ui->refreshButton->setEnabled(true);
182 ui->uploadButton->setEnabled(true);
183 QMessageBox::information(this, "Download done", "The file has finished downloading");
186 bool slideshareListDialog::eventFilter(QObject *obj, QEvent *event)
188 if(event->type() == QEvent::ContextMenu)
190 QMouseEvent *mouseEvent = static_cast<QMouseEvent*> (event);
191 QMenu *menu = new QMenu(this);
192 menu->addAction(new QAction("CLICK", this));
193 menu->exec(mouseEvent->globalPos());