2017-04-27 18:26:05 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2015-09-25 19:15:37 +00:00
|
|
|
#include "preferences_defaults.h"
|
|
|
|
#include "ui_preferences_defaults.h"
|
2018-06-29 06:57:27 +00:00
|
|
|
#include "core/dive.h"
|
2018-07-05 18:37:53 +00:00
|
|
|
#include "core/settings/qPref.h"
|
2015-09-25 19:15:37 +00:00
|
|
|
|
|
|
|
#include <QFileDialog>
|
|
|
|
|
2017-11-29 09:57:08 +00:00
|
|
|
PreferencesDefaults::PreferencesDefaults(): AbstractPreferencesWidget(tr("General"), QIcon(":preferences-other-icon"), 0 ), ui(new Ui::PreferencesDefaults())
|
2015-09-25 19:15:37 +00:00
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
PreferencesDefaults::~PreferencesDefaults()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PreferencesDefaults::on_chooseFile_clicked()
|
|
|
|
{
|
|
|
|
QFileInfo fi(system_default_filename());
|
2017-10-27 12:52:27 +00:00
|
|
|
QString choosenFileName = QFileDialog::getOpenFileName(this, tr("Open default log file"), fi.absolutePath(), tr("Subsurface files") + " (*.ssrf *.xml)");
|
2015-09-25 19:15:37 +00:00
|
|
|
|
|
|
|
if (!choosenFileName.isEmpty())
|
|
|
|
ui->defaultfilename->setText(choosenFileName);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PreferencesDefaults::on_btnUseDefaultFile_toggled(bool toggle)
|
|
|
|
{
|
|
|
|
if (toggle) {
|
|
|
|
ui->defaultfilename->setText(system_default_filename());
|
|
|
|
ui->defaultfilename->setEnabled(false);
|
|
|
|
} else {
|
|
|
|
ui->defaultfilename->setEnabled(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PreferencesDefaults::on_localDefaultFile_toggled(bool toggle)
|
|
|
|
{
|
|
|
|
ui->defaultfilename->setEnabled(toggle);
|
|
|
|
ui->btnUseDefaultFile->setEnabled(toggle);
|
|
|
|
ui->chooseFile->setEnabled(toggle);
|
|
|
|
}
|
|
|
|
|
2018-07-10 13:04:35 +00:00
|
|
|
void PreferencesDefaults::on_ffmpegFile_clicked()
|
|
|
|
{
|
|
|
|
QFileInfo fi(system_default_filename());
|
|
|
|
QString ffmpegFileName = QFileDialog::getOpenFileName(this, tr("Select ffmpeg executable"));
|
|
|
|
|
|
|
|
if (!ffmpegFileName.isEmpty())
|
|
|
|
ui->ffmpegExecutable->setText(ffmpegFileName);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PreferencesDefaults::on_extractVideoThumbnails_toggled(bool toggled)
|
|
|
|
{
|
|
|
|
ui->videoThumbnailPosition->setEnabled(toggled);
|
|
|
|
ui->ffmpegExecutable->setEnabled(toggled);
|
|
|
|
ui->ffmpegFile->setEnabled(toggled);
|
|
|
|
}
|
|
|
|
|
2015-09-25 19:15:37 +00:00
|
|
|
void PreferencesDefaults::refreshSettings()
|
|
|
|
{
|
2018-08-15 09:50:53 +00:00
|
|
|
ui->font->setCurrentFont(qPrefDisplay::divelist_font());
|
|
|
|
ui->fontsize->setValue(qPrefDisplay::font_size());
|
|
|
|
ui->defaultfilename->setText(qPrefGeneral::default_filename());
|
|
|
|
ui->noDefaultFile->setChecked(qPrefGeneral::default_file_behavior() == NO_DEFAULT_FILE);
|
|
|
|
ui->cloudDefaultFile->setChecked(qPrefGeneral::default_file_behavior() == CLOUD_DEFAULT_FILE);
|
|
|
|
ui->localDefaultFile->setChecked(qPrefGeneral::default_file_behavior() == LOCAL_DEFAULT_FILE);
|
2015-09-25 19:15:37 +00:00
|
|
|
|
|
|
|
ui->default_cylinder->clear();
|
2018-06-19 00:19:56 +00:00
|
|
|
for (int i = 0; tank_info[i].name != NULL && i < MAX_TANK_INFO; i++) {
|
2015-09-25 19:15:37 +00:00
|
|
|
ui->default_cylinder->addItem(tank_info[i].name);
|
2018-08-15 09:50:53 +00:00
|
|
|
if (qPrefGeneral::default_cylinder() == tank_info[i].name)
|
2015-09-25 19:15:37 +00:00
|
|
|
ui->default_cylinder->setCurrentIndex(i);
|
|
|
|
}
|
2018-08-15 09:50:53 +00:00
|
|
|
ui->displayinvalid->setChecked(qPrefDisplay::display_invalid_dives());
|
|
|
|
ui->velocitySlider->setValue(qPrefAnimations::animation_speed());
|
|
|
|
ui->btnUseDefaultFile->setChecked(qPrefGeneral::use_default_file());
|
2015-09-25 19:15:37 +00:00
|
|
|
|
2018-08-15 09:50:53 +00:00
|
|
|
if (qPrefCloudStorage::cloud_verification_status() == qPref::CS_VERIFIED) {
|
2015-09-25 19:15:37 +00:00
|
|
|
ui->cloudDefaultFile->setEnabled(true);
|
|
|
|
} else {
|
|
|
|
if (ui->cloudDefaultFile->isChecked())
|
|
|
|
ui->noDefaultFile->setChecked(true);
|
|
|
|
ui->cloudDefaultFile->setEnabled(false);
|
|
|
|
}
|
|
|
|
|
2018-08-15 09:50:53 +00:00
|
|
|
ui->defaultfilename->setEnabled(qPrefGeneral::default_file_behavior() == LOCAL_DEFAULT_FILE);
|
|
|
|
ui->btnUseDefaultFile->setEnabled(qPrefGeneral::default_file_behavior() == LOCAL_DEFAULT_FILE);
|
|
|
|
ui->chooseFile->setEnabled(qPrefGeneral::default_file_behavior() == LOCAL_DEFAULT_FILE);
|
2018-07-10 13:04:35 +00:00
|
|
|
|
2018-08-15 09:50:53 +00:00
|
|
|
ui->videoThumbnailPosition->setEnabled(qPrefGeneral::extract_video_thumbnails());
|
|
|
|
ui->ffmpegExecutable->setEnabled(qPrefGeneral::extract_video_thumbnails());
|
|
|
|
ui->ffmpegFile->setEnabled(qPrefGeneral::extract_video_thumbnails());
|
2018-07-10 13:04:35 +00:00
|
|
|
|
2018-08-15 09:50:53 +00:00
|
|
|
ui->extractVideoThumbnails->setChecked(qPrefGeneral::extract_video_thumbnails());
|
|
|
|
ui->videoThumbnailPosition->setValue(qPrefGeneral::extract_video_thumbnails_position());
|
|
|
|
ui->ffmpegExecutable->setText(qPrefGeneral::ffmpeg_executable());
|
2015-09-25 19:15:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PreferencesDefaults::syncSettings()
|
|
|
|
{
|
2018-08-12 19:58:25 +00:00
|
|
|
auto general = qPrefGeneral::instance();
|
|
|
|
general->set_default_filename(ui->defaultfilename->text());
|
|
|
|
general->set_default_cylinder(ui->default_cylinder->currentText());
|
|
|
|
general->set_use_default_file(ui->btnUseDefaultFile->isChecked());
|
2015-09-25 19:15:37 +00:00
|
|
|
if (ui->noDefaultFile->isChecked())
|
2018-08-12 19:58:25 +00:00
|
|
|
general->set_default_file_behavior(NO_DEFAULT_FILE);
|
2015-09-25 19:15:37 +00:00
|
|
|
else if (ui->localDefaultFile->isChecked())
|
2018-08-12 19:58:25 +00:00
|
|
|
general->set_default_file_behavior(LOCAL_DEFAULT_FILE);
|
2015-09-25 19:15:37 +00:00
|
|
|
else if (ui->cloudDefaultFile->isChecked())
|
2018-08-12 19:58:25 +00:00
|
|
|
general->set_default_file_behavior(CLOUD_DEFAULT_FILE);
|
|
|
|
general->set_extract_video_thumbnails(ui->extractVideoThumbnails->isChecked());
|
|
|
|
general->set_extract_video_thumbnails_position(ui->videoThumbnailPosition->value());
|
|
|
|
general->set_ffmpeg_executable(ui->ffmpegExecutable->text());
|
2015-09-25 19:15:37 +00:00
|
|
|
|
2018-08-15 09:50:53 +00:00
|
|
|
qPrefDisplay::set_divelist_font(ui->font->currentFont().toString());
|
|
|
|
qPrefDisplay::set_font_size(ui->fontsize->value());
|
|
|
|
qPrefDisplay::set_display_invalid_dives(ui->displayinvalid->isChecked());
|
|
|
|
qPrefAnimations::set_animation_speed(ui->velocitySlider->value());
|
2015-09-25 19:15:37 +00:00
|
|
|
}
|