void MainWindow::on_actionOpen_triggered() { QString filename = QFileDialog::getOpenFileName(this, tr("Open File"), QDir::homePath(), filter()); if (filename.isEmpty()) return; // Needed to convert to char* QByteArray fileNamePtr = filename.toLocal8Bit(); on_actionClose_triggered(); char *error = NULL; parse_file(fileNamePtr.data(), &error); set_filename(fileNamePtr.data(), TRUE); if (error != NULL) { showError(error); free(error); } process_dives(FALSE, FALSE); ui->InfoWidget->reload(); ui->globe->reload(); ui->ListWidget->reload(); ui->ListWidget->setFocus(); }
void DownloadThread::run() { DownloadFromDCWidget *dfdcw = DownloadFromDCWidget::instance(); do_libdivecomputer_import(data); process_dives(TRUE, dfdcw->preferDownloaded()); dfdcw->stoppedDownloading(); }
void QMLManager::openLocalThenRemote(QString url) { clear_dive_file_data(); QByteArray fileNamePrt = QFile::encodeName(url); bool glo = prefs.git_local_only; prefs.git_local_only = true; int error = parse_file(fileNamePrt.data()); setAccessingCloud(-1); prefs.git_local_only = glo; if (error) { appendTextToLog(QStringLiteral("loading dives from cache failed %1").arg(error)); } else { // if we can load from the cache, we know that we have at least a valid email if (credentialStatus() == UNKNOWN) setCredentialStatus(VALID_EMAIL); prefs.unit_system = informational_prefs.unit_system; if (informational_prefs.unit_system == IMPERIAL) informational_prefs.units = IMPERIAL_units; prefs.units = informational_prefs.units; process_dives(false, false); DiveListModel::instance()->clear(); DiveListModel::instance()->addAllDives(); appendTextToLog(QStringLiteral("%1 dives loaded from cache").arg(dive_table.nr)); } set_filename(fileNamePrt.data(), true); appendTextToLog(QStringLiteral("have cloud credentials, trying to connect")); tryRetrieveDataFromBackend(); }
void MainWindow::on_actionCloudstorageopen_triggered() { if (!okToClose(tr("Please save or cancel the current dive edit before opening a new file."))) return; QString filename; if (getCloudURL(filename)) { getNotificationWidget()->showNotification(get_error_string(), KMessageWidget::Error); return; } qDebug() << filename; closeCurrentFile(); int error; QByteArray fileNamePtr = QFile::encodeName(filename); error = parse_file(fileNamePtr.data()); if (!error) { set_filename(fileNamePtr.data(), true); setTitle(MWTF_FILENAME); } getNotificationWidget()->hideNotification(); process_dives(false, false); refreshDisplay(); ui.actionAutoGroup->setChecked(autogroup); }
void MainWindow::loadFiles(const QStringList fileNames) { if (fileNames.isEmpty()) return; char *error = NULL; QByteArray fileNamePtr; for (int i = 0; i < fileNames.size(); ++i) { fileNamePtr = fileNames.at(i).toLocal8Bit(); parse_file(fileNamePtr.data(), &error); set_filename(fileNamePtr.data(), TRUE); setTitle(MWTF_FILENAME); if (error != NULL) { showError(error); free(error); } } process_dives(FALSE, FALSE); refreshDisplay(); ui.actionAutoGroup->setChecked(autogroup); }
void QMLManager::openLocalThenRemote(QString url) { clear_dive_file_data(); QByteArray fileNamePrt = QFile::encodeName(url); prefs.git_local_only = true; int error = parse_file(fileNamePrt.data()); prefs.git_local_only = false; if (error) { appendTextToLog(QStringLiteral("loading dives from cache failed %1").arg(error)); } else { // if we can load from the cache, we know that we have at least a valid email if (credentialStatus() == UNKNOWN) setCredentialStatus(VALID_EMAIL); prefs.unit_system = informational_prefs.unit_system; if (informational_prefs.unit_system == IMPERIAL) informational_prefs.units = IMPERIAL_units; prefs.units = informational_prefs.units; int i; struct dive *d; process_dives(false, false); DiveListModel::instance()->clear(); for_each_dive (i, d) { DiveListModel::instance()->addDive(d); } appendTextToLog(QStringLiteral("%1 dives loaded from cache").arg(i)); }
void DiveLogImportDialog::on_buttonBox_accepted() { if (ui->tabWidget->currentIndex() == 0) { for (int i = 0; i < fileNames.size(); ++i) { parse_csv_file(fileNames[i].toUtf8().data(), ui->CSVTime->value() - 1, ui->CSVDepth->value() - 1, VALUE_IF_CHECKED(CSVTemperature), VALUE_IF_CHECKED(CSVpo2), VALUE_IF_CHECKED(CSVcns), VALUE_IF_CHECKED(CSVstopdepth), ui->CSVSeparator->currentIndex(), specialCSV.contains(ui->knownImports->currentIndex()) ? CSVApps[ui->knownImports->currentIndex()].name.toUtf8().data() : "csv", ui->CSVUnits->currentIndex()); } } else { for (int i = 0; i < fileNames.size(); ++i) { parse_manual_file(fileNames[i].toUtf8().data(), ui->ManualSeparator->currentIndex(), ui->Units->currentIndex(), VALUE_IF_CHECKED(DiveNumber), VALUE_IF_CHECKED(Date), VALUE_IF_CHECKED(Time), VALUE_IF_CHECKED(Duration), VALUE_IF_CHECKED(Location), VALUE_IF_CHECKED(Gps), VALUE_IF_CHECKED(MaxDepth), VALUE_IF_CHECKED(MeanDepth), VALUE_IF_CHECKED(Buddy), VALUE_IF_CHECKED(Notes), VALUE_IF_CHECKED(Weight), VALUE_IF_CHECKED(Tags)); } } process_dives(true, false); MainWindow::instance()->refreshDisplay(); }
void QMLManager::loadDives() { qmlUiShowMessage("Loading dives..."); appendTextToLog("Loading dives..."); QString url; if (getCloudURL(url)) { qmlUiShowMessage(get_error_string()); appendTextToLog(get_error_string()); return; } clear_dive_file_data(); QByteArray fileNamePrt = QFile::encodeName(url); int error = parse_file(fileNamePrt.data()); if (!error) { report_error("filename is now %s", fileNamePrt.data()); qmlUiShowMessage(get_error_string()); appendTextToLog(get_error_string()); set_filename(fileNamePrt.data(), true); appendTextToLog(fileNamePrt.data()); } else { qmlUiShowMessage(get_error_string()); appendTextToLog(get_error_string()); } process_dives(false, false); int i; struct dive *d; DiveListModel::instance()->clear(); for_each_dive(i, d) { DiveListModel::instance()->addDive(d); }
void MainWindow::on_actionImportCSV_triggered() { CSVImportDialog *csvImport = new CSVImportDialog(); csvImport->show(); process_dives(TRUE, FALSE); refreshDisplay(); }
void TestRenumber::setup() { WindowTitleUpdate *wtu = new WindowTitleUpdate(); QCOMPARE(parse_file(SUBSURFACE_SOURCE "/dives/test47.xml"), 0); process_dives(false, false); dive_table.preexisting = dive_table.nr; }
void QMLManager::loadDivesWithValidCredentials() { QString url; if (getCloudURL(url)) { QString errorString(get_error_string()); appendTextToLog(errorString); setStartPageText(RED_FONT + tr("Cloud storage error: %1").arg(errorString) + END_FONT); setAccessingCloud(-1); alreadySaving = false; return; } QByteArray fileNamePrt = QFile::encodeName(url); git_repository *git; const char *branch; int error; if (check_git_sha(fileNamePrt.data(), &git, &branch) == 0) { qDebug() << "local cache was current, no need to modify dive list"; appendTextToLog("Cloud sync shows local cache was current"); setLoadFromCloud(true); setAccessingCloud(-1); alreadySaving = false; return; } appendTextToLog("Cloud sync brought newer data, reloading the dive list"); clear_dive_file_data(); if (git != dummy_git_repository) { appendTextToLog(QString("have repository and branch %1").arg(branch)); error = git_load_dives(git, branch); } else { appendTextToLog(QString("didn't receive valid git repo, try again")); error = parse_file(fileNamePrt.data()); } setAccessingCloud(-1); if (!error) { report_error("filename is now %s", fileNamePrt.data()); const char *error_string = get_error_string(); appendTextToLog(error_string); set_filename(fileNamePrt.data(), true); } else { report_error("failed to open file %s", fileNamePrt.data()); QString errorString(get_error_string()); appendTextToLog(errorString); setStartPageText(RED_FONT + tr("Cloud storage error: %1").arg(errorString) + END_FONT); alreadySaving = false; return; } prefs.unit_system = informational_prefs.unit_system; if (informational_prefs.unit_system == IMPERIAL) informational_prefs.units = IMPERIAL_units; prefs.units = informational_prefs.units; DiveListModel::instance()->clear(); process_dives(false, false); DiveListModel::instance()->addAllDives(); appendTextToLog(QStringLiteral("%1 dives loaded").arg(dive_table.nr)); if (dive_table.nr == 0) setStartPageText(tr("Cloud storage open successfully. No dives in dive list.")); setLoadFromCloud(true); alreadySaving = false; }
void TestRenumber::testMerge() { QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test47b.xml"), 0); process_dives(true, false); QCOMPARE(dive_table.nr, 1); QCOMPARE(unsaved_changes(), 1); mark_divelist_changed(false); dive_table.preexisting = dive_table.nr; }
void TestRenumber::testMergeAndAppend() { QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test47c.xml"), 0); process_dives(true, false); QCOMPARE(dive_table.nr, 2); QCOMPARE(unsaved_changes(), 1); struct dive *d = get_dive(1); QVERIFY(d != NULL); if (d) QCOMPARE(d->number, 2); }
void MainWindow::on_actionAddDive_triggered() { struct dive *dive; dive = alloc_dive(); record_dive(dive); process_dives(FALSE, FALSE); ui->InfoWidget->reload(); ui->globe->reload(); ui->ListWidget->reload(DiveTripModel::TREE); ui->ListWidget->setFocus(); }
void QMLManager::loadFile() { QUrl url(m_fileName); QString strippedFileName = url.toLocalFile(); parse_file(strippedFileName.toUtf8().data()); process_dives(false, false); int i; struct dive *d; for_each_dive(i, d) { DiveListModel::instance()->addDive(d); }
void DownloadFromDCWidget::onDownloadThreadFinished() { if (currentState == DOWNLOADING) { if (thread->error.isEmpty()) updateState(DONE); else updateState(ERROR); // I'm not sure if we should really call process_dives even // if there's an error or a cancelation process_dives(TRUE, preferDownloaded()); } else updateState(CANCELLED); }
void QMLManager::consumeFinishedLoad(timestamp_t currentDiveTimestamp) { prefs.unit_system = informational_prefs.unit_system; if (informational_prefs.unit_system == IMPERIAL) informational_prefs.units = IMPERIAL_units; prefs.units = informational_prefs.units; DiveListModel::instance()->clear(); process_dives(false, false); DiveListModel::instance()->addAllDives(); if (currentDiveTimestamp) setUpdateSelectedDive(dlSortModel->getIdxForId(get_dive_id_closest_to(currentDiveTimestamp))); appendTextToLog(QStringLiteral("%1 dives loaded").arg(dive_table.nr)); if (dive_table.nr == 0) setStartPageText(tr("Cloud storage open successfully. No dives in dive list.")); alreadySaving = false; }
void MainWindow::on_actionOpen_triggered() { QSettings settings; QString lastDir = QDir::homePath(); settings.beginGroup("FileDialog"); if (settings.contains("LastDir")) { if(QDir::setCurrent(settings.value("LastDir").toString())) { lastDir = settings.value("LastDir").toString(); } } settings.endGroup(); QString filename = QFileDialog::getOpenFileName(this, tr("Open File"), lastDir, filter()); if (filename.isEmpty()) return; // Keep last open dir QFileInfo fileInfo(filename); settings.beginGroup("FileDialog"); settings.setValue("LastDir",fileInfo.dir().path()); settings.endGroup(); // Needed to convert to char* QByteArray fileNamePtr = filename.toLocal8Bit(); on_actionClose_triggered(); char *error = NULL; parse_file(fileNamePtr.data(), &error); set_filename(fileNamePtr.data(), TRUE); setTitle(MWTF_FILENAME); if (error != NULL) { showError(error); free(error); } process_dives(FALSE, FALSE); ui->InfoWidget->reload(); ui->globe->reload(); ui->ListWidget->reload(DiveTripModel::TREE); ui->ListWidget->setFocus(); }
void MainWindow::importFiles(const QStringList fileNames) { if (fileNames.isEmpty()) return; QByteArray fileNamePtr; char *error = NULL; for (int i = 0; i < fileNames.size(); ++i) { fileNamePtr = fileNames.at(i).toLocal8Bit(); parse_file(fileNamePtr.data(), &error); if (error != NULL) { showError(error); free(error); error = NULL; } } process_dives(TRUE, FALSE); refreshDisplay(); }
void CSVImportDialog::on_buttonBox_accepted() { char *error = NULL; parse_csv_file(ui->CSVFile->text().toUtf8().data(), ui->CSVTime->value(), ui->CSVDepth->value(), VALUE_IF_CHECKED(CSVTemperature), VALUE_IF_CHECKED(CSVpo2), VALUE_IF_CHECKED(CSVcns), VALUE_IF_CHECKED(CSVstopdepth), &error); if (error != NULL) { mainWindow()->showError(error); free(error); error = NULL; } process_dives(TRUE, FALSE); mainWindow()->refreshDisplay(); }
void MainWindow::on_actionImport_triggered() { QSettings settings; QString lastDir = QDir::homePath(); settings.beginGroup("FileDialog"); if (settings.contains("LastDir")) if (QDir::setCurrent(settings.value("LastDir").toString())) lastDir = settings.value("LastDir").toString(); settings.endGroup(); QStringList fileNames = QFileDialog::getOpenFileNames(this, tr("Import Files"), lastDir, filter()); if (!fileNames.size()) return; // no selection // Keep last open dir QFileInfo fileInfo(fileNames.at(0)); settings.beginGroup("FileDialog"); settings.setValue("LastDir", fileInfo.dir().path()); settings.endGroup(); QByteArray fileNamePtr; char *error = NULL; for (int i = 0; i < fileNames.size(); ++i) { fileNamePtr = fileNames.at(i).toLocal8Bit(); parse_file(fileNamePtr.data(), &error); if (error != NULL) { showError(error); free(error); error = NULL; } } process_dives(FALSE, FALSE); ui->InfoWidget->reload(); ui->globe->reload(); ui->ListWidget->reload(DiveTripModel::TREE); ui->ListWidget->setFocus(); }
void TestRenumber::setup() { QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test47.xml"), 0); process_dives(false, false); dive_table.preexisting = dive_table.nr; }
static int parse_dan_format(const char *filename, char **params, int pnr) { int ret = 0, i; size_t end_ptr = 0; struct memblock mem, mem_csv; char tmpbuf[MAXCOLDIGITS]; char *ptr = NULL; char *NL = NULL; char *iter = NULL; if (readfile(filename, &mem) < 0) return report_error(translate("gettextFromC", "Failed to read '%s'"), filename); /* Determine NL (new line) character and the start of CSV data */ if ((ptr = strstr(mem.buffer, "\r\n")) != NULL) { NL = "\r\n"; } else if ((ptr = strstr(mem.buffer, "\n")) != NULL) { NL = "\n"; } else { fprintf(stderr, "DEBUG: failed to detect NL\n"); return -1; } while ((end_ptr < mem.size) && (ptr = strstr(mem.buffer + end_ptr, "ZDH"))) { char *iter_end = NULL; unsigned int pnr_local = pnr; /* * Process the dives, but let the last round be parsed * from C++ code */ if (end_ptr) process_dives(true, false); mem_csv.buffer = malloc(mem.size + 1); mem_csv.size = mem.size; iter = ptr + 4; iter = strchr(iter, '|'); if (iter) { memcpy(tmpbuf, ptr + 4, iter - ptr - 4); tmpbuf[iter - ptr - 4] = 0; params[pnr_local++] = "diveNro"; params[pnr_local++] = strdup(tmpbuf); } //fprintf(stderr, "DEBUG: BEGIN end_ptr %d round %d <%s>\n", end_ptr, j++, ptr); iter = ptr + 1; for (i = 0; i <= 4 && iter; ++i) { iter = strchr(iter, '|'); if (iter) ++iter; } if (!iter) { fprintf(stderr, "DEBUG: Data corrupt"); return -1; } /* Setting date */ memcpy(tmpbuf, iter, 8); tmpbuf[8] = 0; params[pnr_local++] = "date"; params[pnr_local++] = strdup(tmpbuf); /* Setting time, gotta prepend it with 1 to * avoid octal parsing (this is stripped out in * XSLT */ tmpbuf[0] = '1'; memcpy(tmpbuf + 1, iter + 8, 6); tmpbuf[7] = 0; params[pnr_local++] = "time"; params[pnr_local++] = strdup(tmpbuf); /* Air temperature */ memset(tmpbuf, 0, sizeof(tmpbuf)); iter = strchr(iter, '|'); if (iter && iter + 1) { iter = iter + 1; iter_end = strchr(iter, '|'); if (iter_end) { memcpy(tmpbuf, iter, iter_end - iter); params[pnr_local++] = "airTemp"; params[pnr_local++] = strdup(tmpbuf); } } params[pnr_local] = NULL; /* Search for the next line */ if (iter) iter = parse_dan_new_line(iter, NL); if (!iter) return -1; /* We got a trailer, no samples on this dive */ if (strncmp(iter, "ZDT", 3) == 0) { end_ptr = iter - (char *)mem.buffer; /* Water temperature */ memset(tmpbuf, 0, sizeof(tmpbuf)); for (i = 0; i < 5 && iter; ++i) iter = strchr(iter + 1, '|'); if (iter && iter + 1) { iter = iter + 1; iter_end = strchr(iter, '|'); if (iter_end) { memcpy(tmpbuf, iter, iter_end - iter); params[pnr_local++] = "waterTemp"; params[pnr_local++] = strdup(tmpbuf); } } params[pnr_local] = NULL; ret |= parse_xml_buffer(filename, "<csv></csv>", 11, &dive_table, (const char **)params); continue; } /* After ZDH we should get either ZDT (above) or ZDP */ if (strncmp(iter, "ZDP{", 4) != 0) { fprintf(stderr, "DEBUG: Input appears to violate DL7 specification\n"); end_ptr = iter - (char *)mem.buffer; continue; } if (ptr && ptr[4] == '}') { end_ptr += ptr - (char *)mem_csv.buffer; return report_error(translate("gettextFromC", "No dive profile found from '%s'"), filename); } if (ptr) ptr = parse_dan_new_line(ptr, NL); if (!ptr) return -1; end_ptr = ptr - (char *)mem.buffer; /* Copy the current dive data to start of mem_csv buffer */ memcpy(mem_csv.buffer, ptr, mem.size - (ptr - (char *)mem.buffer)); ptr = strstr(mem_csv.buffer, "ZDP}"); if (ptr) { *ptr = 0; } else { fprintf(stderr, "DEBUG: failed to find end ZDP\n"); return -1; } mem_csv.size = ptr - (char*)mem_csv.buffer; iter = parse_dan_new_line(ptr + 1, NL); if (iter && strncmp(iter, "ZDT", 3) == 0) { /* Water temperature */ memset(tmpbuf, 0, sizeof(tmpbuf)); for (i = 0; i < 5 && iter; ++i) iter = strchr(iter + 1, '|'); if (iter && iter + 1) { iter = iter + 1; iter_end = strchr(iter, '|'); if (iter_end) { memcpy(tmpbuf, iter, iter_end - iter); params[pnr_local++] = "waterTemp"; params[pnr_local++] = strdup(tmpbuf); } } params[pnr_local] = NULL; } if (try_to_xslt_open_csv(filename, &mem_csv, "csv")) return -1; ret |= parse_xml_buffer(filename, mem_csv.buffer, mem_csv.size, &dive_table, (const char **)params); end_ptr += ptr - (char *)mem_csv.buffer; free(mem_csv.buffer); } free(mem.buffer); for (i = 0; params[i]; i += 2) free(params[i + 1]); return ret; }
void QMLManager::mergeLocalRepo() { char *filename = NOCLOUD_LOCALSTORAGE; parse_file(filename); process_dives(true, false); }