diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2014-02-27 20:09:57 -0800 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2014-02-27 20:09:57 -0800 |
commit | 76e6420f6b3503b76bd3eec00ab0e53d6ea17a20 (patch) | |
tree | 8b50298f41bd29d55bbd6f4301f36ad31dc0b008 /qt-ui/subsurfacewebservices.cpp | |
parent | 006265d7a088cff4fea665159dbb454956c2cd76 (diff) | |
download | subsurface-76e6420f6b3503b76bd3eec00ab0e53d6ea17a20.tar.gz |
Massive automated whitespace cleanup
I know everyone will hate it.
Go ahead. Complain. Call me names.
At least now things are consistent and reproducible.
If you want changes, have your complaint come with a patch to
scripts/whitespace.pl so that we can automate it.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-ui/subsurfacewebservices.cpp')
-rw-r--r-- | qt-ui/subsurfacewebservices.cpp | 102 |
1 files changed, 53 insertions, 49 deletions
diff --git a/qt-ui/subsurfacewebservices.cpp b/qt-ui/subsurfacewebservices.cpp index 1fcfca15f..25aa56cb2 100644 --- a/qt-ui/subsurfacewebservices.cpp +++ b/qt-ui/subsurfacewebservices.cpp @@ -19,11 +19,11 @@ #include "../divelist.h" #ifdef Q_OS_UNIX -# include <unistd.h> // for dup(2) +#include <unistd.h> // for dup(2) #endif -#if QT_VERSION >= QT_VERSION_CHECK(5,0,0) -# include <QUrlQuery> +#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) +#include <QUrlQuery> #endif struct dive_table gps_location_table; @@ -32,13 +32,13 @@ static bool merge_locations_into_dives(void); static bool is_automatic_fix(struct dive *gpsfix) { if (gpsfix && gpsfix->location && - (!strcmp(gpsfix->location, "automatic fix") || - !strcmp(gpsfix->location, "Auto-created dive"))) + (!strcmp(gpsfix->location, "automatic fix") || + !strcmp(gpsfix->location, "Auto-created dive"))) return true; return false; } -#define SAME_GROUP 6 * 3600 // six hours +#define SAME_GROUP 6 * 3600 // six hours static bool merge_locations_into_dives(void) { @@ -56,7 +56,7 @@ static bool merge_locations_into_dives(void) utc_mkdate(gpsfix->when, &tm); printf("found dive named %s @ %04d-%02d-%02d %02d:%02d:%02d\n", gpsfix->location, - tm.tm_year+1900, tm.tm_mon+1, tm.tm_mday, + tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec); #endif changed++; @@ -85,7 +85,7 @@ static bool merge_locations_into_dives(void) #if DEBUG_WEBSERVICE printf("didn't find dive matching gps fix named %s @ %04d-%02d-%02d %02d:%02d:%02d\n", gpsfix->location, - tm.tm_year+1900, tm.tm_mon+1, tm.tm_mday, + tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec); #endif } @@ -126,7 +126,7 @@ bool DivelogsDeWebServices::prepare_dives_for_divelogs(const QString &tempfile, char buffer[1024]; zip_error_to_str(buffer, sizeof buffer, error_code, errno); *errorMsg = tr("failed to create zip file for upload: %1") - .arg(QString::fromLocal8Bit(buffer)); + .arg(QString::fromLocal8Bit(buffer)); return false; } @@ -183,7 +183,7 @@ bool DivelogsDeWebServices::prepare_dives_for_divelogs(const QString &tempfile, free((void *)membuf); transformed = xsltApplyStylesheet(xslt, doc, NULL); - xmlDocDumpMemory(transformed, (xmlChar **) &membuf, &streamsize); + xmlDocDumpMemory(transformed, (xmlChar **)&membuf, &streamsize); xmlFreeDoc(doc); xmlFreeDoc(transformed); @@ -209,11 +209,10 @@ error_close_zip: return false; } -WebServices::WebServices(QWidget* parent, Qt::WindowFlags f): QDialog(parent, f) -, reply(0) +WebServices::WebServices(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f), reply(0) { ui.setupUi(this); - connect(ui.buttonBox, SIGNAL(clicked(QAbstractButton*)), this, SLOT(buttonClicked(QAbstractButton*))); + connect(ui.buttonBox, SIGNAL(clicked(QAbstractButton *)), this, SLOT(buttonClicked(QAbstractButton *))); connect(ui.download, SIGNAL(clicked(bool)), this, SLOT(startDownload())); connect(ui.upload, SIGNAL(clicked(bool)), this, SLOT(startUpload())); connect(&timeout, SIGNAL(timeout()), this, SLOT(downloadTimedOut())); @@ -286,8 +285,8 @@ void WebServices::connectSignalsForDownload(QNetworkReply *reply) connect(reply, SIGNAL(finished()), this, SLOT(downloadFinished())); connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(downloadError(QNetworkReply::NetworkError))); - connect(reply, SIGNAL(downloadProgress(qint64,qint64)), this, - SLOT(updateProgress(qint64,qint64))); + connect(reply, SIGNAL(downloadProgress(qint64, qint64)), this, + SLOT(updateProgress(qint64, qint64))); timeout.start(30000); // 30s } @@ -299,7 +298,7 @@ void WebServices::resetState() ui.userID->setEnabled(true); ui.password->setEnabled(true); ui.progressBar->reset(); - ui.progressBar->setRange(0,1); + ui.progressBar->setRange(0, 1); ui.status->setText(QString()); ui.buttonBox->button(QDialogButtonBox::Apply)->setText(defaultApplyText); } @@ -310,18 +309,18 @@ void WebServices::resetState() // # // # -SubsurfaceWebServices::SubsurfaceWebServices(QWidget* parent, Qt::WindowFlags f) : WebServices(parent, f) +SubsurfaceWebServices::SubsurfaceWebServices(QWidget *parent, Qt::WindowFlags f) : WebServices(parent, f) { QSettings s; ui.userID->setText(s.value("subsurface_webservice_uid").toString().toUpper()); hidePassword(); hideUpload(); ui.progressBar->setFormat("Enter User ID and click Download"); - ui.progressBar->setRange(0,1); + ui.progressBar->setRange(0, 1); ui.progressBar->setValue(-1); } -void SubsurfaceWebServices::buttonClicked(QAbstractButton* button) +void SubsurfaceWebServices::buttonClicked(QAbstractButton *button) { ui.buttonBox->button(QDialogButtonBox::Apply)->setEnabled(false); switch (ui.buttonBox->buttonRole(button)) { @@ -345,8 +344,7 @@ void SubsurfaceWebServices::buttonClicked(QAbstractButton* button) hide(); close(); resetState(); - } - break; + } break; case QDialogButtonBox::RejectRole: if (reply != NULL && reply->isOpen()) { reply->abort(); @@ -366,7 +364,7 @@ void SubsurfaceWebServices::buttonClicked(QAbstractButton* button) void SubsurfaceWebServices::startDownload() { QUrl url("http://api.hohndel.org/api/dive/get/"); -#if QT_VERSION < QT_VERSION_CHECK(5,0,0) +#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) url.addQueryItem("login", ui.userID->text().toUpper()); #else QUrlQuery query; @@ -380,7 +378,7 @@ void SubsurfaceWebServices::startDownload() 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.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); @@ -391,7 +389,7 @@ void SubsurfaceWebServices::downloadFinished() if (!reply) return; - ui.progressBar->setRange(0,1); + ui.progressBar->setRange(0, 1); ui.progressBar->setValue(1); ui.progressBar->setFormat("%p%"); downloadedData = reply->readAll(); @@ -420,10 +418,18 @@ 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 Success!"); break; + 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 Success!"); + break; } ui.status->setText(text); } @@ -434,17 +440,17 @@ void SubsurfaceWebServices::download_dialog_traverse_xml(xmlNodePtr node, unsign 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"))) { + (!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")) { + } else if (!strcmp((const char *)cur_node->name, (const char *)"error")) { *download_status = DD_STATUS_ERROR_ID; return; } } } -unsigned int SubsurfaceWebServices::download_dialog_parse_response(const QByteArray& xml) +unsigned int SubsurfaceWebServices::download_dialog_parse_response(const QByteArray &xml) { xmlNodePtr root; xmlDocPtr doc = xmlParseMemory(xml.data(), xml.length()); @@ -470,8 +476,7 @@ end: // # // # -struct DiveListResult -{ +struct DiveListResult { QString errorCondition; QString errorDetails; QByteArray idList; // comma-separated, suitable to be sent in the fetch request @@ -497,8 +502,8 @@ static DiveListResult parseDiveLogsDeDiveList(const QByteArray &xmlData) if (reader.readNextStartElement() && reader.name() != "DiveDateReader") { result.errorCondition = invalidXmlError; result.errorDetails = - DivelogsDeWebServices::tr("Expected XML tag 'DiveDateReader', got instead '%1") - .arg(reader.name().toString()); + DivelogsDeWebServices::tr("Expected XML tag 'DiveDateReader', got instead '%1") + .arg(reader.name().toString()); goto out; } @@ -551,12 +556,13 @@ out: // if there was an XML error, overwrite the result or other error conditions result.errorCondition = invalidXmlError; result.errorDetails = DivelogsDeWebServices::tr("Malformed XML response. Line %1: %2") - .arg(reader.lineNumber()).arg(reader.errorString()); + .arg(reader.lineNumber()) + .arg(reader.errorString()); } return result; } -DivelogsDeWebServices* DivelogsDeWebServices::instance() +DivelogsDeWebServices *DivelogsDeWebServices::instance() { static DivelogsDeWebServices *self = new DivelogsDeWebServices(MainWindow::instance()); self->setAttribute(Qt::WA_QuitOnClose, false); @@ -617,7 +623,7 @@ void DivelogsDeWebServices::uploadDives(QIODevice *dldContent) } } -DivelogsDeWebServices::DivelogsDeWebServices(QWidget* parent, Qt::WindowFlags f) : WebServices(parent, f), uploadMode(false) +DivelogsDeWebServices::DivelogsDeWebServices(QWidget *parent, Qt::WindowFlags f) : WebServices(parent, f), uploadMode(false) { QSettings s; ui.userID->setText(s.value("divelogde_user").toString()); @@ -633,7 +639,7 @@ void DivelogsDeWebServices::startUpload() s.sync(); ui.status->setText(tr("Uploading dive list...")); - ui.progressBar->setRange(0,0); // this makes the progressbar do an 'infinite spin' + ui.progressBar->setRange(0, 0); // this makes the progressbar do an 'infinite spin' ui.upload->setEnabled(false); ui.userID->setEnabled(false); ui.password->setEnabled(false); @@ -655,8 +661,8 @@ void DivelogsDeWebServices::startUpload() connect(reply, SIGNAL(finished()), this, SLOT(uploadFinished())); connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(uploadError(QNetworkReply::NetworkError))); - connect(reply, SIGNAL(uploadProgress(qint64,qint64)), this, - SLOT(updateProgress(qint64,qint64))); + connect(reply, SIGNAL(uploadProgress(qint64, qint64)), this, + SLOT(updateProgress(qint64, qint64))); timeout.start(30000); // 30s } @@ -664,7 +670,7 @@ void DivelogsDeWebServices::startUpload() void DivelogsDeWebServices::startDownload() { ui.status->setText(tr("Downloading dive list...")); - ui.progressBar->setRange(0,0); // this makes the progressbar do an 'infinite spin' + ui.progressBar->setRange(0, 0); // this makes the progressbar do an 'infinite spin' ui.download->setEnabled(false); ui.userID->setEnabled(false); ui.password->setEnabled(false); @@ -674,7 +680,7 @@ void DivelogsDeWebServices::startDownload() request.setRawHeader("Accept", "text/xml, application/xml"); request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded"); -#if QT_VERSION < QT_VERSION_CHECK(5,0,0) +#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) QUrl body; body.addQueryItem("user", ui.userID->text()); body.addQueryItem("pass", ui.password->text()); @@ -718,7 +724,7 @@ void DivelogsDeWebServices::listDownloadFinished() request.setRawHeader("Accept", "application/zip, */*"); request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded"); -#if QT_VERSION < QT_VERSION_CHECK(5,0,0) +#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) QUrl body; body.addQueryItem("user", ui.userID->text()); body.addQueryItem("pass", ui.password->text()); @@ -788,7 +794,7 @@ void DivelogsDeWebServices::uploadFinished() if (!reply) return; - ui.progressBar->setRange(0,1); + ui.progressBar->setRange(0, 1); ui.upload->setEnabled(true); ui.userID->setEnabled(true); ui.password->setEnabled(true); @@ -823,7 +829,6 @@ void DivelogsDeWebServices::uploadFinished() void DivelogsDeWebServices::setStatusText(int status) { - } void DivelogsDeWebServices::downloadError(QNetworkReply::NetworkError) @@ -839,7 +844,7 @@ void DivelogsDeWebServices::uploadError(QNetworkReply::NetworkError error) downloadError(error); } -void DivelogsDeWebServices::buttonClicked(QAbstractButton* button) +void DivelogsDeWebServices::buttonClicked(QAbstractButton *button) { ui.buttonBox->button(QDialogButtonBox::Apply)->setEnabled(false); switch (ui.buttonBox->buttonRole(button)) { @@ -869,8 +874,7 @@ void DivelogsDeWebServices::buttonClicked(QAbstractButton* button) hide(); close(); resetState(); - } - break; + } break; case QDialogButtonBox::RejectRole: // these two seem to be causing a crash: // reply->deleteLater(); |