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 "slideshareuploaddialog.h"
20 #include "ui_uploaddialog.h"
22 #include "slideshare.h"
24 #include <QFileDialog>
25 #include <QDesktopServices>
26 #include <QMaemo5InformationBox>
28 slideshareUploadDialog::slideshareUploadDialog(SlideShare *service, QWidget *parent) :
30 ui(new Ui::uploadDialog)
32 this->service = service;
34 connect(service, SIGNAL(uploadProgress(qint64, qint64)), this, SLOT(uploadProgressSlot(qint64, qint64)));
35 connect(ui->fileSelectButton, SIGNAL(clicked()), this, SLOT(showFileDialog()));
36 connect(ui->uploadButton, SIGNAL(clicked()), this, SLOT(uploadButtonClickedSlot()));
37 connect(service, SIGNAL(uploadDone()), this, SLOT(uploadDoneSlot()));
40 slideshareUploadDialog::~slideshareUploadDialog()
45 void slideshareUploadDialog::setOpenDoc(const QString & openDocPath)
47 ui->fileSelectEdit->setText(openDocPath);
50 void slideshareUploadDialog::changeEvent(QEvent *e)
52 QDialog::changeEvent(e);
54 case QEvent::LanguageChange:
55 ui->retranslateUi(this);
63 void slideshareUploadDialog::uploadProgressSlot(qint64 sent, qint64 total)
65 qint64 value = (sent * 100 / total) ;
66 ui->uploadProgress->setValue(value);
69 void slideshareUploadDialog::showFileDialog()
71 QString currentFile = ("" == ui->fileSelectEdit->text()) ? QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation) : ui->fileSelectEdit->text();
72 QString filter = "Supported Files (*.odt *.doc *.odp *.ppt *.ods *.xls)";
73 QString filename = QFileDialog::getOpenFileName(this, QString("Select File"), currentFile, filter, &filter);
75 ui->fileSelectEdit->setText(filename);
78 void slideshareUploadDialog::uploadButtonClickedSlot()
80 if(ui->fileSelectEdit->text() == "" || ui->titleEdit->text() == "") {
81 QMaemo5InformationBox::information(this, "Please enter atleast filename and title");
84 ui->fileSelectButton->setEnabled(false);
85 ui->titleEdit->setEnabled(false);
86 ui->descriptionBox->setEnabled(false);
87 ui->tagsEdit->setEnabled(false);
88 ui->uploadButton->setEnabled(false);
89 service->setSourceFile(&ui->fileSelectEdit->text());
90 service->setSlideTitle(&ui->titleEdit->text());
91 service->setDescription(&ui->descriptionBox->text());
92 service->setTags(&ui->tagsEdit->text());
93 service->setFormat(new QString(QFileInfo(ui->fileSelectEdit->text()).suffix()));
98 void slideshareUploadDialog::uploadDoneSlot()
100 QMaemo5InformationBox::information(this, "<p><b>Upload done</b></p> It'll take some time for the file to appear in the list. Please be patient.");
101 ui->doneButton->setEnabled(true);