Initial Commit.
[onlineservices] / 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 <QMessageBox>
26
27 slideshareUploadDialog::slideshareUploadDialog(SlideShare *service, QWidget *parent) :
28     QDialog(parent),
29     ui(new Ui::uploadDialog)
30 {
31     this->service = service;
32     ui->setupUi(this);
33     connect(service, SIGNAL(uploadProgress(qint64,qint64)), this, SLOT(uploadProgressSlot(qint64,qint64)));
34     connect(ui->fileSelectButton, SIGNAL(clicked()), this, SLOT(showFileDialog()));
35     connect(ui->uploadButton, SIGNAL(clicked()), this, SLOT(uploadButtonClickedSlot()));
36     connect(service, SIGNAL(uploadDone()), this, SLOT(uploadDoneSlot()));
37 }
38
39 slideshareUploadDialog::~slideshareUploadDialog()
40 {
41     delete ui;
42 }
43
44 void slideshareUploadDialog::changeEvent(QEvent *e)
45 {
46     QDialog::changeEvent(e);
47     switch (e->type()) {
48     case QEvent::LanguageChange:
49         ui->retranslateUi(this);
50         break;
51     default:
52         break;
53     }
54 }
55
56
57 void slideshareUploadDialog::uploadProgressSlot(qint64 sent, qint64 total)
58 {
59     qint64 value = (sent * 100 / total) ;
60     ui->uploadProgress->setValue(value);
61 }
62
63 void slideshareUploadDialog::showFileDialog()
64 {
65     QString filter = "Supported Files (odt doc odp ppt ods xls)(*.odt *.doc *.odp *.ppt *.ods *.xls);; Documents (odt doc)(*.odt *.doc);; Presentations (odp ppt)(*.odp *.ppt) ;; Spreadsheets(ods xls)(*.ods *.xls)";
66     QString filename = QFileDialog::getOpenFileName(this,QString("Select File"),tr(""),filter);
67     ui->fileSelectEdit->setText(filename);
68 }
69
70 void slideshareUploadDialog::uploadButtonClickedSlot()
71 {
72     if(ui->fileSelectEdit->text() == "" || ui->titleEdit->text() == "")
73     {
74         QMessageBox::information(this,"Incomplete parameters","Please enter atleast filename and title");
75         return;
76     }
77     else
78     {
79         ui->fileSelectButton->setEnabled(false);
80         ui->titleEdit->setEnabled(false);
81         ui->descriptionBox->setEnabled(false);
82         ui->tagsEdit->setEnabled(false);
83         ui->uploadButton->setEnabled(false);
84         ui->uploadLabel->setText(tr("Uploading file..."));
85         service->setSourceFile(&ui->fileSelectEdit->text());
86         service->setSlideTitle(&ui->titleEdit->text());
87         service->setDescription(&ui->descriptionBox->toPlainText());
88         service->setTags(&ui->tagsEdit->text());
89         service->setFormat(new QString(QFileInfo(ui->fileSelectEdit->text()).suffix()));
90         service->upload();
91     }
92 }
93
94 void slideshareUploadDialog::uploadDoneSlot()
95 {
96     ui->uploadLabel->setText(tr("Upload done"));
97     ui->doneButton->setEnabled(true);
98 }