mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-30 22:20:21 +00:00
Added initial support for download dive info from the subsurface web service.
Added initial support for download dive info from subsurface web service, the current code only downloads and output the xml downloaded in the debug area. Now I need to parse things up and plug the unplugged stuff. Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
This commit is contained in:
parent
74d23ed83b
commit
c1cf6c02a8
6 changed files with 202 additions and 2 deletions
|
@ -106,7 +106,7 @@ ifeq ($(strip $(QMAKE)),)
|
|||
$(error Could not find qmake or qmake-qt4 in $$PATH for the Qt4 version they failed)
|
||||
endif
|
||||
|
||||
QT_MODULES = QtGui QtSvg
|
||||
QT_MODULES = QtGui QtSvg QtNetwork
|
||||
QT_CORE = QtCore
|
||||
MOC = $(shell $(PKGCONFIG) --variable=moc_location QtCore)
|
||||
UIC = $(shell $(PKGCONFIG) --variable=uic_location QtGui)
|
||||
|
|
2
Makefile
2
Makefile
|
@ -48,6 +48,7 @@ HEADERS = \
|
|||
qt-ui/downloadfromdivecomputer.h \
|
||||
qt-ui/preferences.h \
|
||||
qt-ui/simplewidgets.h \
|
||||
qt-ui/subsurfacewebservices.h \
|
||||
|
||||
|
||||
SOURCES = \
|
||||
|
@ -80,6 +81,7 @@ SOURCES = \
|
|||
qt-ui/downloadfromdivecomputer.cpp \
|
||||
qt-ui/preferences.cpp \
|
||||
qt-ui/simplewidgets.cpp \
|
||||
qt-ui/subsurfacewebservices.cpp \
|
||||
$(RESFILE)
|
||||
|
||||
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
#include "models.h"
|
||||
#include "downloadfromdivecomputer.h"
|
||||
#include "preferences.h"
|
||||
#include "subsurfacewebservices.h"
|
||||
|
||||
static MainWindow* instance = 0;
|
||||
|
||||
|
@ -181,7 +182,8 @@ void MainWindow::on_actionDownloadDC_triggered()
|
|||
|
||||
void MainWindow::on_actionDownloadWeb_triggered()
|
||||
{
|
||||
qDebug("actionDownloadWeb");}
|
||||
SubsurfaceWebServices::instance()->runDialog();
|
||||
}
|
||||
|
||||
void MainWindow::on_actionEditDeviceNames_triggered()
|
||||
{
|
||||
|
|
59
qt-ui/subsurfacewebservices.cpp
Normal file
59
qt-ui/subsurfacewebservices.cpp
Normal file
|
@ -0,0 +1,59 @@
|
|||
#include "subsurfacewebservices.h"
|
||||
#include "ui_subsurfacewebservices.h"
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QNetworkReply>
|
||||
#include <QDebug>
|
||||
|
||||
SubsurfaceWebServices* SubsurfaceWebServices::instance()
|
||||
{
|
||||
static SubsurfaceWebServices *self = new SubsurfaceWebServices();
|
||||
return self;
|
||||
}
|
||||
|
||||
SubsurfaceWebServices::SubsurfaceWebServices(QWidget* parent, Qt::WindowFlags f)
|
||||
: ui( new Ui::SubsurfaceWebServices()){
|
||||
ui->setupUi(this);
|
||||
connect(ui->buttonBox, SIGNAL(clicked(QAbstractButton*)), this, SLOT(buttonClicked(QAbstractButton*)));
|
||||
connect(ui->download, SIGNAL(clicked(bool)), this, SLOT(startDownload()));
|
||||
}
|
||||
|
||||
void SubsurfaceWebServices::buttonClicked(QAbstractButton* button)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void SubsurfaceWebServices::startDownload()
|
||||
{
|
||||
QUrl url("http://api.hohndel.org/api/dive/get/");
|
||||
url.setQueryItems( QList<QPair<QString,QString> >() << qMakePair(QString("login"), ui->userID->text()));
|
||||
qDebug() << url;
|
||||
|
||||
QNetworkAccessManager *manager = new QNetworkAccessManager(this);
|
||||
QNetworkRequest request;
|
||||
request.setUrl(url);
|
||||
request.setRawHeader("Accept", "text/xml");
|
||||
reply = manager->get(request);
|
||||
ui->progressBar->setRange(0,0);
|
||||
connect(reply, SIGNAL(finished()), this, SLOT(downloadFinished()));
|
||||
connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(downloadError(QNetworkReply::NetworkError)));
|
||||
}
|
||||
|
||||
void SubsurfaceWebServices::downloadFinished()
|
||||
{
|
||||
ui->progressBar->setRange(0,1);
|
||||
QByteArray result = reply->readAll();
|
||||
qDebug() << result;
|
||||
ui->status->setText(tr("Download Finished"));
|
||||
}
|
||||
|
||||
void SubsurfaceWebServices::downloadError(QNetworkReply::NetworkError error)
|
||||
{
|
||||
ui->progressBar->setRange(0,1);
|
||||
ui->status->setText(QString::number((int)QNetworkRequest::HttpStatusCodeAttribute));
|
||||
}
|
||||
|
||||
|
||||
void SubsurfaceWebServices::runDialog()
|
||||
{
|
||||
show();
|
||||
}
|
31
qt-ui/subsurfacewebservices.h
Normal file
31
qt-ui/subsurfacewebservices.h
Normal file
|
@ -0,0 +1,31 @@
|
|||
#ifndef SUBSURFACEWEBSERVICES_H
|
||||
#define SUBSURFACEWEBSERVICES_H
|
||||
|
||||
#include <QDialog>
|
||||
#include <QNetworkReply>
|
||||
|
||||
namespace Ui{
|
||||
class SubsurfaceWebServices;
|
||||
};
|
||||
class QAbstractButton;
|
||||
class QNetworkReply;
|
||||
|
||||
class SubsurfaceWebServices : public QDialog {
|
||||
Q_OBJECT
|
||||
public:
|
||||
static SubsurfaceWebServices* instance();
|
||||
void runDialog();
|
||||
|
||||
private slots:
|
||||
void startDownload();
|
||||
void buttonClicked(QAbstractButton* button);
|
||||
void downloadFinished();
|
||||
void downloadError(QNetworkReply::NetworkError error);
|
||||
|
||||
private:
|
||||
explicit SubsurfaceWebServices(QWidget* parent = 0, Qt::WindowFlags f = 0);
|
||||
Ui::SubsurfaceWebServices *ui;
|
||||
QNetworkReply *reply;
|
||||
};
|
||||
|
||||
#endif
|
106
qt-ui/subsurfacewebservices.ui
Normal file
106
qt-ui/subsurfacewebservices.ui
Normal file
|
@ -0,0 +1,106 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>SubsurfaceWebServices</class>
|
||||
<widget class="QDialog" name="SubsurfaceWebServices">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>399</width>
|
||||
<height>104</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::Cancel|QDialogButtonBox::Help|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="2">
|
||||
<widget class="QPushButton" name="download">
|
||||
<property name="text">
|
||||
<string>Download</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLineEdit" name="userID">
|
||||
<property name="placeholderText">
|
||||
<string>Enter your ID here</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>User ID</string>
|
||||
</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">
|
||||
<widget class="QLabel" name="status">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>SubsurfaceWebServices</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>248</x>
|
||||
<y>254</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>157</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>SubsurfaceWebServices</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>316</x>
|
||||
<y>260</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>286</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
Loading…
Reference in a new issue