Added openssl-dev dependency
[froff-onlinedoc] / slideshareuploaddialog.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 "slideshareuploaddialog.h"
20 #include "ui_uploaddialog.h"
21
22 #include "slideshare.h"
23
24 #include <QFileDialog>
25 #include <QDesktopServices>
26 #include <QMaemo5InformationBox>
27
28 slideshareUploadDialog::slideshareUploadDialog(SlideShare *service, QWidget *parent) :
29     QDialog(parent),
30     ui(new Ui::uploadDialog)
31 {
32     this->service = service;
33     ui->setupUi(this);
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()));
38 }
39
40 slideshareUploadDialog::~slideshareUploadDialog()
41 {
42     delete ui;
43 }
44
45 void slideshareUploadDialog::setOpenDoc(const QString & openDocPath)
46 {
47     ui->fileSelectEdit->setText(openDocPath);
48 }
49
50 void slideshareUploadDialog::changeEvent(QEvent *e)
51 {
52     QDialog::changeEvent(e);
53     switch(e->type()) {
54     case QEvent::LanguageChange:
55         ui->retranslateUi(this);
56         break;
57     default:
58         break;
59     }
60 }
61
62
63 void slideshareUploadDialog::uploadProgressSlot(qint64 sent, qint64 total)
64 {
65     qint64 value = (sent * 100 / total) ;
66     ui->uploadProgress->setValue(value);
67 }
68
69 void slideshareUploadDialog::showFileDialog()
70 {
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);
74     if("" != filename)
75         ui->fileSelectEdit->setText(filename);
76 }
77
78 void slideshareUploadDialog::uploadButtonClickedSlot()
79 {
80     if(ui->fileSelectEdit->text() == "" || ui->titleEdit->text() == "") {
81         QMaemo5InformationBox::information(this, "Please enter atleast filename and title");
82         return;
83     } else {
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()));
94         service->upload();
95     }
96 }
97
98 void slideshareUploadDialog::uploadDoneSlot()
99 {
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);
102 }