mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Desktop: Remove webservice, remove UI components (2)
Actually remove the Subsurface webservice UI from the source, and deal with all the fallout. Notice that a part of the change in subsurfacewebservices.cpp is a block of code that becomes unused, but might contain some valid logic to be used later. Very similar code is in core/gpslocation.cpp. And as I earlier broke something here, the unused code is ifdef-ed for now. Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
This commit is contained in:
parent
90fb34baab
commit
876e6adf74
4 changed files with 2 additions and 249 deletions
|
@ -844,13 +844,6 @@ void MainWindow::on_actionDownloadDC_triggered()
|
||||||
dlg.exec();
|
dlg.exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::on_actionDownloadWeb_triggered()
|
|
||||||
{
|
|
||||||
SubsurfaceWebServices dlg(this);
|
|
||||||
|
|
||||||
dlg.exec();
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainWindow::on_actionDivelogs_de_triggered()
|
void MainWindow::on_actionDivelogs_de_triggered()
|
||||||
{
|
{
|
||||||
DivelogsDeWebServices::instance()->downloadDives();
|
DivelogsDeWebServices::instance()->downloadDives();
|
||||||
|
|
|
@ -109,7 +109,6 @@ slots:
|
||||||
|
|
||||||
/* log menu actions */
|
/* log menu actions */
|
||||||
void on_actionDownloadDC_triggered();
|
void on_actionDownloadDC_triggered();
|
||||||
void on_actionDownloadWeb_triggered();
|
|
||||||
void on_actionDivelogs_de_triggered();
|
void on_actionDivelogs_de_triggered();
|
||||||
void on_actionEditDeviceNames_triggered();
|
void on_actionEditDeviceNames_triggered();
|
||||||
void on_actionAddDive_triggered();
|
void on_actionAddDive_triggered();
|
||||||
|
|
|
@ -33,6 +33,7 @@
|
||||||
#define PATH_MAX 4096
|
#define PATH_MAX 4096
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef RM_OBSOLETE_CODE
|
||||||
struct dive_table gps_location_table;
|
struct dive_table gps_location_table;
|
||||||
|
|
||||||
// we don't overwrite any existing GPS info in the dive
|
// we don't overwrite any existing GPS info in the dive
|
||||||
|
@ -146,6 +147,7 @@ static bool merge_locations_into_dives(void)
|
||||||
}
|
}
|
||||||
return changed > 0;
|
return changed > 0;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
// TODO: This looks like should be ported to C code. or a big part of it.
|
// TODO: This looks like should be ported to C code. or a big part of it.
|
||||||
bool DivelogsDeWebServices::prepare_dives_for_divelogs(const QString &tempfile, const bool selected)
|
bool DivelogsDeWebServices::prepare_dives_for_divelogs(const QString &tempfile, const bool selected)
|
||||||
|
@ -374,227 +376,6 @@ void WebServices::resetState()
|
||||||
ui.buttonBox->button(QDialogButtonBox::Apply)->setText(defaultApplyText);
|
ui.buttonBox->button(QDialogButtonBox::Apply)->setText(defaultApplyText);
|
||||||
}
|
}
|
||||||
|
|
||||||
// #
|
|
||||||
// #
|
|
||||||
// # Subsurface Web Service Implementation.
|
|
||||||
// #
|
|
||||||
// #
|
|
||||||
|
|
||||||
SubsurfaceWebServices::SubsurfaceWebServices(QWidget *parent, Qt::WindowFlags f) : WebServices(parent, f)
|
|
||||||
{
|
|
||||||
// figure out if we know (or can determine) the user's web service userid
|
|
||||||
QString userid(prefs.userid);
|
|
||||||
|
|
||||||
if (userid.isEmpty() &&
|
|
||||||
!empty_string(prefs.cloud_storage_email) &&
|
|
||||||
!empty_string(prefs.cloud_storage_password) &&
|
|
||||||
GpsLocation::hasInstance())
|
|
||||||
userid = GpsLocation::instance()->getUserid(prefs.cloud_storage_email, prefs.cloud_storage_password);
|
|
||||||
|
|
||||||
ui.userID->setText(userid);
|
|
||||||
|
|
||||||
hidePassword();
|
|
||||||
hideUpload();
|
|
||||||
ui.progressBar->setFormat(tr("Enter User ID and click Download"));
|
|
||||||
ui.progressBar->setRange(0, 1);
|
|
||||||
ui.progressBar->setValue(-1);
|
|
||||||
ui.progressBar->setAlignment(Qt::AlignCenter);
|
|
||||||
ui.saveUidLocal->setChecked(prefs.save_userid_local);
|
|
||||||
QShortcut *close = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_W), this);
|
|
||||||
connect(close, SIGNAL(activated()), this, SLOT(close()));
|
|
||||||
QShortcut *quit = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_Q), this);
|
|
||||||
connect(quit, SIGNAL(activated()), parent, SLOT(close()));
|
|
||||||
}
|
|
||||||
|
|
||||||
void SubsurfaceWebServices::buttonClicked(QAbstractButton *button)
|
|
||||||
{
|
|
||||||
ui.buttonBox->button(QDialogButtonBox::Apply)->setEnabled(false);
|
|
||||||
switch (ui.buttonBox->buttonRole(button)) {
|
|
||||||
case QDialogButtonBox::ApplyRole: {
|
|
||||||
int i;
|
|
||||||
struct dive *d;
|
|
||||||
struct dive_site *ds;
|
|
||||||
bool changed = false;
|
|
||||||
clear_table(&gps_location_table);
|
|
||||||
QByteArray url = tr("Webservice").toUtf8();
|
|
||||||
parse_xml_buffer(url.data(), downloadedData.data(), downloadedData.length(), &gps_location_table, NULL);
|
|
||||||
// make sure we mark all the dive sites that were created
|
|
||||||
for (i = 0; i < gps_location_table.nr; i++) {
|
|
||||||
d = get_dive_from_table(i, &gps_location_table);
|
|
||||||
ds = get_dive_site_by_uuid(d->dive_site_uuid);
|
|
||||||
if (ds)
|
|
||||||
ds->notes = strdup("SubsurfaceWebservice");
|
|
||||||
}
|
|
||||||
/* now merge the data in the gps_location table into the dive_table */
|
|
||||||
if (merge_locations_into_dives()) {
|
|
||||||
changed = true;
|
|
||||||
mark_divelist_changed(true);
|
|
||||||
MainWindow::instance()->information()->updateDiveInfo();
|
|
||||||
}
|
|
||||||
|
|
||||||
/* store last entered uid in config */
|
|
||||||
QSettings s;
|
|
||||||
QString qDialogUid = ui.userID->text().toUpper();
|
|
||||||
bool qSaveUid = ui.saveUidLocal->checkState();
|
|
||||||
qPrefCloudStorage::instance()->set_save_userid_local(qSaveUid);
|
|
||||||
|
|
||||||
//WARN: Dirk, this seems to be wrong, I coundn't really understand the code.
|
|
||||||
if (qSaveUid) {
|
|
||||||
QString qSettingUid = s.value("subsurface_webservice_uid").toString();
|
|
||||||
QString qFileUid = QString(prefs.userid);
|
|
||||||
bool s_eq_d = (qSettingUid == qDialogUid);
|
|
||||||
bool d_eq_f = (qDialogUid == qFileUid);
|
|
||||||
if (!d_eq_f || s_eq_d)
|
|
||||||
s.setValue("subsurface_webservice_uid", qDialogUid);
|
|
||||||
set_userid(qPrintable(qDialogUid));
|
|
||||||
}
|
|
||||||
s.sync();
|
|
||||||
hide();
|
|
||||||
close();
|
|
||||||
resetState();
|
|
||||||
/* and now clean up and remove all the extra dive sites that were created */
|
|
||||||
QSet<uint32_t> usedUuids;
|
|
||||||
for_each_dive(i, d) {
|
|
||||||
if (d->dive_site_uuid)
|
|
||||||
usedUuids.insert(d->dive_site_uuid);
|
|
||||||
}
|
|
||||||
for_each_dive_site(i, ds) {
|
|
||||||
if (!usedUuids.contains(ds->uuid) && same_string(ds->notes, "SubsurfaceWebservice")) {
|
|
||||||
delete_dive_site(ds->uuid);
|
|
||||||
i--; // otherwise we skip one site
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// finally now that all the extra GPS fixes that weren't used have been deleted
|
|
||||||
// we can update the map
|
|
||||||
if (changed) {
|
|
||||||
MapWidget::instance()->repopulateLabels();
|
|
||||||
MapWidget::instance()->centerOnDiveSite(get_dive_site_by_uuid(current_dive->dive_site_uuid));
|
|
||||||
}
|
|
||||||
|
|
||||||
} break;
|
|
||||||
case QDialogButtonBox::RejectRole:
|
|
||||||
if (reply != NULL && reply->isOpen()) {
|
|
||||||
reply->abort();
|
|
||||||
delete reply;
|
|
||||||
reply = NULL;
|
|
||||||
}
|
|
||||||
resetState();
|
|
||||||
break;
|
|
||||||
case QDialogButtonBox::HelpRole:
|
|
||||||
QDesktopServices::openUrl(QUrl("http://api.subsurface-divelog.org"));
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void SubsurfaceWebServices::startDownload()
|
|
||||||
{
|
|
||||||
QUrl url("http://api.subsurface-divelog.org/api/dive/get/");
|
|
||||||
QUrlQuery query;
|
|
||||||
query.addQueryItem("login", ui.userID->text().toUpper());
|
|
||||||
url.setQuery(query);
|
|
||||||
|
|
||||||
QNetworkRequest request;
|
|
||||||
request.setUrl(url);
|
|
||||||
request.setRawHeader("Accept", "text/xml");
|
|
||||||
request.setRawHeader("User-Agent", userAgent.toUtf8());
|
|
||||||
reply = manager()->get(request);
|
|
||||||
ui.status->setText(tr("Connecting..."));
|
|
||||||
ui.progressBar->setEnabled(true);
|
|
||||||
ui.progressBar->setRange(0, 0); // this makes the progressbar do an 'infinite spin'
|
|
||||||
ui.download->setEnabled(false);
|
|
||||||
ui.buttonBox->button(QDialogButtonBox::Apply)->setEnabled(false);
|
|
||||||
connectSignalsForDownload(reply);
|
|
||||||
}
|
|
||||||
|
|
||||||
void SubsurfaceWebServices::downloadFinished()
|
|
||||||
{
|
|
||||||
if (!reply)
|
|
||||||
return;
|
|
||||||
|
|
||||||
ui.progressBar->setRange(0, 1);
|
|
||||||
ui.progressBar->setValue(1);
|
|
||||||
ui.progressBar->setFormat("%p%");
|
|
||||||
downloadedData = reply->readAll();
|
|
||||||
|
|
||||||
ui.download->setEnabled(true);
|
|
||||||
ui.status->setText(tr("Download finished"));
|
|
||||||
|
|
||||||
uint resultCode = download_dialog_parse_response(downloadedData);
|
|
||||||
setStatusText(resultCode);
|
|
||||||
if (resultCode == DD_STATUS_OK) {
|
|
||||||
ui.buttonBox->button(QDialogButtonBox::Apply)->setEnabled(true);
|
|
||||||
}
|
|
||||||
reply->deleteLater();
|
|
||||||
reply = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SubsurfaceWebServices::downloadError(QNetworkReply::NetworkError)
|
|
||||||
{
|
|
||||||
resetState();
|
|
||||||
ui.status->setText(tr("Download error: %1").arg(reply->errorString()));
|
|
||||||
reply->deleteLater();
|
|
||||||
reply = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SubsurfaceWebServices::setStatusText(int status)
|
|
||||||
{
|
|
||||||
QString text;
|
|
||||||
switch (status) {
|
|
||||||
case DD_STATUS_ERROR_CONNECT:
|
|
||||||
text = tr("Connection error: ");
|
|
||||||
break;
|
|
||||||
case DD_STATUS_ERROR_ID:
|
|
||||||
text = tr("Invalid user identifier!");
|
|
||||||
break;
|
|
||||||
case DD_STATUS_ERROR_PARSE:
|
|
||||||
text = tr("Cannot parse response!");
|
|
||||||
break;
|
|
||||||
case DD_STATUS_OK:
|
|
||||||
text = tr("Download successful");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
ui.status->setText(text);
|
|
||||||
}
|
|
||||||
|
|
||||||
//TODO: C-Code.
|
|
||||||
/* 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)
|
|
||||||
{
|
|
||||||
xmlNodePtr cur_node;
|
|
||||||
for (cur_node = node; cur_node; cur_node = cur_node->next) {
|
|
||||||
if ((!strcmp((const char *)cur_node->name, (const char *)"download")) &&
|
|
||||||
(!strcmp((const char *)xmlNodeGetContent(cur_node), (const char *)"ok"))) {
|
|
||||||
*download_status = DD_STATUS_OK;
|
|
||||||
return;
|
|
||||||
} else if (!strcmp((const char *)cur_node->name, (const char *)"error")) {
|
|
||||||
*download_status = DD_STATUS_ERROR_ID;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: C-Code
|
|
||||||
unsigned int SubsurfaceWebServices::download_dialog_parse_response(const QByteArray &xml)
|
|
||||||
{
|
|
||||||
xmlNodePtr root;
|
|
||||||
xmlDocPtr doc = xmlParseMemory(xml.data(), xml.length());
|
|
||||||
unsigned int status = DD_STATUS_ERROR_PARSE;
|
|
||||||
|
|
||||||
if (!doc)
|
|
||||||
return DD_STATUS_ERROR_PARSE;
|
|
||||||
root = xmlDocGetRootElement(doc);
|
|
||||||
if (!root) {
|
|
||||||
status = DD_STATUS_ERROR_PARSE;
|
|
||||||
goto end;
|
|
||||||
}
|
|
||||||
if (root->children)
|
|
||||||
download_dialog_traverse_xml(root->children, &status);
|
|
||||||
end:
|
|
||||||
xmlFreeDoc(doc);
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
|
|
||||||
// #
|
// #
|
||||||
// #
|
// #
|
||||||
|
|
|
@ -45,26 +45,6 @@ protected:
|
||||||
QString userAgent;
|
QString userAgent;
|
||||||
};
|
};
|
||||||
|
|
||||||
class SubsurfaceWebServices : public WebServices {
|
|
||||||
Q_OBJECT
|
|
||||||
public:
|
|
||||||
explicit SubsurfaceWebServices(QWidget *parent = 0, Qt::WindowFlags f = 0);
|
|
||||||
|
|
||||||
private
|
|
||||||
slots:
|
|
||||||
void startDownload();
|
|
||||||
void buttonClicked(QAbstractButton *button);
|
|
||||||
void downloadFinished();
|
|
||||||
void downloadError(QNetworkReply::NetworkError error);
|
|
||||||
void startUpload()
|
|
||||||
{
|
|
||||||
} /*no op*/
|
|
||||||
private:
|
|
||||||
void setStatusText(int status);
|
|
||||||
void download_dialog_traverse_xml(xmlNodePtr node, unsigned int *download_status);
|
|
||||||
unsigned int download_dialog_parse_response(const QByteArray &length);
|
|
||||||
};
|
|
||||||
|
|
||||||
class DivelogsDeWebServices : public WebServices {
|
class DivelogsDeWebServices : public WebServices {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
|
|
Loading…
Add table
Reference in a new issue