mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-28 05:00:20 +00:00
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 <tcanabrava@kde.org>
This commit is contained in:
parent
695f64a23a
commit
5eb2cc4594
5 changed files with 103 additions and 55 deletions
|
@ -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()
|
||||
|
|
|
@ -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 <download> or <error> tag under the <root> tag */
|
||||
void SubsurfaceWebServices::download_dialog_traverse_xml(xmlNodePtr node, unsigned int *download_status)
|
||||
{
|
||||
|
|
|
@ -5,16 +5,35 @@
|
|||
#include <QNetworkReply>
|
||||
#include <libxml/tree.h>
|
||||
|
||||
#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
|
||||
|
|
|
@ -1,40 +1,23 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>SubsurfaceWebServices</class>
|
||||
<widget class="QDialog" name="SubsurfaceWebServices">
|
||||
<class>WebServices</class>
|
||||
<widget class="QDialog" name="WebServices">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>399</width>
|
||||
<height>104</height>
|
||||
<width>425</width>
|
||||
<height>141</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Download Location Data</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="1" column="0" colspan="3">
|
||||
<widget class="QProgressBar" name="progressBar">
|
||||
<property name="value">
|
||||
<number>0</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0" colspan="3">
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::Help</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="2">
|
||||
<widget class="QPushButton" name="download">
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Download</string>
|
||||
<string>Status:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
@ -45,6 +28,30 @@
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="2">
|
||||
<widget class="QPushButton" name="download">
|
||||
<property name="text">
|
||||
<string>Download</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="0" colspan="3">
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::Help</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0" colspan="3">
|
||||
<widget class="QProgressBar" name="progressBar">
|
||||
<property name="value">
|
||||
<number>0</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
|
@ -52,20 +59,34 @@
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Status:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1" colspan="2">
|
||||
<item row="3" column="1" colspan="2">
|
||||
<widget class="QLabel" name="status">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="passLabel">
|
||||
<property name="text">
|
||||
<string>Password</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QLineEdit" name="password">
|
||||
<property name="echoMode">
|
||||
<enum>QLineEdit::Password</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="2">
|
||||
<widget class="QPushButton" name="upload">
|
||||
<property name="text">
|
||||
<string>Upload</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
|
@ -73,7 +94,7 @@
|
|||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>SubsurfaceWebServices</receiver>
|
||||
<receiver>WebServices</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
|
@ -89,7 +110,7 @@
|
|||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>SubsurfaceWebServices</receiver>
|
||||
<receiver>WebServices</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
|
@ -119,7 +119,7 @@ FORMS = \
|
|||
qt-ui/preferences.ui \
|
||||
qt-ui/printoptions.ui \
|
||||
qt-ui/renumber.ui \
|
||||
qt-ui/subsurfacewebservices.ui \
|
||||
qt-ui/webservices.ui \
|
||||
qt-ui/tableview.ui \
|
||||
qt-ui/csvimportdialog.ui
|
||||
|
||||
|
|
Loading…
Reference in a new issue