-
Notifications
You must be signed in to change notification settings - Fork 5
/
settingsdialog.cpp
110 lines (82 loc) · 3.76 KB
/
settingsdialog.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/*
Copyright 2016 Adam Reichold
This file is part of QMediathekView.
QMediathekView is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
QMediathekView is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with QMediathekView. If not, see <http://www.gnu.org/licenses/>.
*/
#include "settingsdialog.h"
#include <QAction>
#include <QComboBox>
#include <QDialogButtonBox>
#include <QFileDialog>
#include <QFormLayout>
#include <QLineEdit>
#include <QSpinBox>
#include "settings.h"
namespace QMediathekView
{
SettingsDialog::SettingsDialog(
Settings& settings,
QWidget* parent)
: QDialog(parent)
, m_settings(settings)
{
auto layout = new QFormLayout(this);
setLayout(layout);
m_databaseUpdateAfterHoursBox = new QSpinBox(this);
m_databaseUpdateAfterHoursBox->setValue(m_settings.databaseUpdateAfterHours());
m_databaseUpdateAfterHoursBox->setRange(3, 30);
m_databaseUpdateAfterHoursBox->setPrefix(tr("after "));
m_databaseUpdateAfterHoursBox->setSuffix(tr(" hours"));
layout->addRow(tr("Database update"), m_databaseUpdateAfterHoursBox);
m_playCommandEdit = new QLineEdit(this);
m_playCommandEdit->setText(m_settings.playCommand());
layout->addRow(tr("Play command"), m_playCommandEdit);
m_downloadCommandEdit = new QLineEdit(this);
m_downloadCommandEdit->setText(m_settings.downloadCommand());
layout->addRow(tr("Download command"), m_downloadCommandEdit);
m_downloadFolderEdit = new QLineEdit(this);
m_downloadFolderEdit->setText(m_settings.downloadFolder().absolutePath());
layout->addRow(tr("Download folder"), m_downloadFolderEdit);
const auto selectDownloadFolderAction = m_downloadFolderEdit->addAction(QIcon::fromTheme(QStringLiteral("document-open")), QLineEdit::TrailingPosition);
connect(selectDownloadFolderAction, &QAction::triggered, this, &SettingsDialog::selectDownloadFolder);
m_preferredUrlBox = new QComboBox(this);
m_preferredUrlBox->addItem(tr("Default"), int(Url::Default));
m_preferredUrlBox->addItem(tr("Small"), int(Url::Small));
m_preferredUrlBox->addItem(tr("Large"), int(Url::Large));
m_preferredUrlBox->setCurrentIndex(m_preferredUrlBox->findData(int(m_settings.preferredUrl())));
layout->addRow(tr("Preferred URL"), m_preferredUrlBox);
auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this);
layout->addWidget(buttonBox);
connect(buttonBox, &QDialogButtonBox::accepted, this, &SettingsDialog::accept);
connect(buttonBox, &QDialogButtonBox::rejected, this, &SettingsDialog::reject);
}
SettingsDialog::~SettingsDialog() = default;
void SettingsDialog::accept()
{
QDialog::accept();
m_settings.setDatabaseUpdateAfterHours(m_databaseUpdateAfterHoursBox->value());
m_settings.setPlayCommand(m_playCommandEdit->text());
m_settings.setDownloadCommand(m_downloadCommandEdit->text());
m_settings.setDownloadFolder(m_downloadFolderEdit->text());
m_settings.setPreferredUrl(Url(m_preferredUrlBox->currentData().toInt()));
}
void SettingsDialog::selectDownloadFolder()
{
const auto downloadFolder = QFileDialog::getExistingDirectory(
this, tr("Select download folder"),
m_downloadFolderEdit->text());
if (!downloadFolder.isNull())
{
m_downloadFolderEdit->setText(downloadFolder);
}
}
} // QMediathekView