From 5eb2cc4594ab2181ccc3b09a2540af3fb615468e Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Thu, 24 Oct 2013 22:30:21 -0200 Subject: Created a 'WebService' dialog that will handle download and upload. Created a WebService dialog that will handle download and upload from all child based webservices. Also, ported the currently - only - one webservice to use the new dialog. Signed-off-by: Tomaz Canabrava --- qt-ui/mainwindow.cpp | 2 +- qt-ui/subsurfacewebservices.cpp | 33 +++++++---- qt-ui/subsurfacewebservices.h | 32 +++++++--- qt-ui/subsurfacewebservices.ui | 106 --------------------------------- qt-ui/webservices.ui | 127 ++++++++++++++++++++++++++++++++++++++++ 5 files changed, 174 insertions(+), 126 deletions(-) delete mode 100644 qt-ui/subsurfacewebservices.ui create mode 100644 qt-ui/webservices.ui (limited to 'qt-ui') diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp index 69cf363c3..bb21e6625 100644 --- a/qt-ui/mainwindow.cpp +++ b/qt-ui/mainwindow.cpp @@ -252,7 +252,7 @@ void MainWindow::on_actionDownloadDC_triggered() void MainWindow::on_actionDownloadWeb_triggered() { - SubsurfaceWebServices::instance()->runDialog(); + SubsurfaceWebServices::instance()->exec(); } void MainWindow::on_actionEditDeviceNames_triggered() diff --git a/qt-ui/subsurfacewebservices.cpp b/qt-ui/subsurfacewebservices.cpp index f2b1b88cc..d9da69287 100644 --- a/qt-ui/subsurfacewebservices.cpp +++ b/qt-ui/subsurfacewebservices.cpp @@ -15,6 +15,26 @@ struct dive_table gps_location_table; static bool merge_locations_into_dives(void); +WebServices::WebServices(QWidget* parent, Qt::WindowFlags f): QDialog(parent, f) +{ + ui.setupUi(this); + connect(ui.buttonBox, SIGNAL(clicked(QAbstractButton*)), this, SLOT(buttonClicked(QAbstractButton*))); + connect(ui.download, SIGNAL(clicked(bool)), this, SLOT(startDownload())); + ui.buttonBox->button(QDialogButtonBox::Apply)->setEnabled(false); + +} + +void WebServices::hidePassword() +{ + ui.password->hide(); + ui.passLabel->hide(); +} + +void WebServices::hideUpload() +{ + ui.upload->hide(); +} + SubsurfaceWebServices* SubsurfaceWebServices::instance() { static SubsurfaceWebServices *self = new SubsurfaceWebServices(); @@ -24,12 +44,10 @@ SubsurfaceWebServices* SubsurfaceWebServices::instance() SubsurfaceWebServices::SubsurfaceWebServices(QWidget* parent, Qt::WindowFlags f) { - ui.setupUi(this); - connect(ui.buttonBox, SIGNAL(clicked(QAbstractButton*)), this, SLOT(buttonClicked(QAbstractButton*))); - connect(ui.download, SIGNAL(clicked(bool)), this, SLOT(startDownload())); - ui.buttonBox->button(QDialogButtonBox::Apply)->setEnabled(false); QSettings s; ui.userID->setText(s.value("webservice_uid").toString()); + hidePassword(); + hideUpload(); } static void clear_table(struct dive_table *table) @@ -56,7 +74,7 @@ void SubsurfaceWebServices::buttonClicked(QAbstractButton* button) /* store last entered uid in config */ QSettings s; - s.setValue("webservice_uid", ui.userID->text()); + s.setValue("subsurface_webservice_uid", ui.userID->text()); s.sync(); hide(); close(); @@ -135,11 +153,6 @@ void SubsurfaceWebServices::setStatusText(int status) ui.status->setText(text); } -void SubsurfaceWebServices::runDialog() -{ - exec(); -} - /* requires that there is a or tag under the tag */ void SubsurfaceWebServices::download_dialog_traverse_xml(xmlNodePtr node, unsigned int *download_status) { diff --git a/qt-ui/subsurfacewebservices.h b/qt-ui/subsurfacewebservices.h index 0719a8f15..19c3f56c7 100644 --- a/qt-ui/subsurfacewebservices.h +++ b/qt-ui/subsurfacewebservices.h @@ -5,16 +5,35 @@ #include #include -#include "ui_subsurfacewebservices.h" +#include "ui_webservices.h" class QAbstractButton; class QNetworkReply; -class SubsurfaceWebServices : public QDialog { +class WebServices : public QDialog{ + Q_OBJECT +public: + explicit WebServices(QWidget* parent = 0, Qt::WindowFlags f = 0); + void hidePassword(); + void hideUpload(); + +private slots: + virtual void startDownload() = 0; + virtual void buttonClicked(QAbstractButton* button) = 0; + virtual void downloadFinished() = 0; + virtual void downloadError(QNetworkReply::NetworkError error) = 0; + +protected: + Ui::WebServices ui; + QNetworkReply *reply; + QNetworkAccessManager *manager; + QByteArray downloadedData; +}; + +class SubsurfaceWebServices : public WebServices { Q_OBJECT public: static SubsurfaceWebServices* instance(); - void runDialog(); private slots: void startDownload(); @@ -23,15 +42,10 @@ private slots: void downloadError(QNetworkReply::NetworkError error); private: + explicit SubsurfaceWebServices(QWidget* parent = 0, Qt::WindowFlags f = 0); void setStatusText(int status); void download_dialog_traverse_xml(xmlNodePtr node, unsigned int *download_status); unsigned int download_dialog_parse_response(const QByteArray& length); - - explicit SubsurfaceWebServices(QWidget* parent = 0, Qt::WindowFlags f = 0); - Ui::SubsurfaceWebServices ui; - QNetworkReply *reply; - QNetworkAccessManager *manager; - QByteArray downloadedData; }; #endif diff --git a/qt-ui/subsurfacewebservices.ui b/qt-ui/subsurfacewebservices.ui deleted file mode 100644 index 899eea909..000000000 --- a/qt-ui/subsurfacewebservices.ui +++ /dev/null @@ -1,106 +0,0 @@ - - - SubsurfaceWebServices - - - - 0 - 0 - 399 - 104 - - - - Download Location Data - - - - - - 0 - - - - - - - Qt::Horizontal - - - QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::Help - - - - - - - Download - - - - - - - Enter your ID here - - - - - - - User ID - - - - - - - Status: - - - - - - - - - - - - - - - - buttonBox - accepted() - SubsurfaceWebServices - accept() - - - 248 - 254 - - - 157 - 274 - - - - - buttonBox - rejected() - SubsurfaceWebServices - reject() - - - 316 - 260 - - - 286 - 274 - - - - - diff --git a/qt-ui/webservices.ui b/qt-ui/webservices.ui new file mode 100644 index 000000000..b190a7980 --- /dev/null +++ b/qt-ui/webservices.ui @@ -0,0 +1,127 @@ + + + WebServices + + + + 0 + 0 + 425 + 141 + + + + Download Location Data + + + + + + Status: + + + + + + + Enter your ID here + + + + + + + Download + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::Help + + + + + + + 0 + + + + + + + User ID + + + + + + + + + + + + + + Password + + + + + + + QLineEdit::Password + + + + + + + Upload + + + + + + + + + buttonBox + accepted() + WebServices + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + WebServices + reject() + + + 316 + 260 + + + 286 + 274 + + + + + -- cgit v1.2.3-70-g09d2