This repository was archived by the owner on Mar 5, 2026. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathSettingsDialog.cpp
More file actions
159 lines (136 loc) · 7 KB
/
Copy pathSettingsDialog.cpp
File metadata and controls
159 lines (136 loc) · 7 KB
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#include "SettingsDialog.h"
#include <QFile>
#include <QFileInfo>
SettingsDialog::SettingsDialog(QWidget *parent) : QDialog(parent)
{
setWindowTitle("⚙️ Settings");
setMinimumWidth(500);
resize(1280, 720);
QVBoxLayout *mainLayout = new QVBoxLayout(this);
QFormLayout *formLayout = new QFormLayout();
defaultCodecComboBox = new QComboBox();
defaultCodecComboBox->addItems({"AV1", "x265", "VP9", "Combine Videos", "Trim", "Information", "Console"});
defaultCodecComboBox->setCurrentIndex(0);
formLayout->addRow("Default Tab:", defaultCodecComboBox);
ffmpegPathButton = new QPushButton("📁 Browse...");
ffmpegPathLineEdit = new QLineEdit();
ffmpegPathLineEdit->setReadOnly(true);
QHBoxLayout *ffmpegLayout = new QHBoxLayout();
ffmpegLayout->addWidget(ffmpegPathLineEdit);
ffmpegLayout->addWidget(ffmpegPathButton);
formLayout->addRow("FFmpeg Path:", ffmpegLayout);
svtAv1PathButton = new QPushButton("📁 Browse...");
svtAv1PathLineEdit = new QLineEdit();
svtAv1PathLineEdit->setReadOnly(true);
svtAv1PathLineEdit->setPlaceholderText("Leave blank to use system default");
QHBoxLayout *svtAv1Layout = new QHBoxLayout();
svtAv1Layout->addWidget(svtAv1PathLineEdit);
svtAv1Layout->addWidget(svtAv1PathButton);
formLayout->addRow("SVT-AV1 Library Path:", svtAv1Layout);
notifyOnFinishCheck = new QCheckBox("Show notification when conversion finishes");
formLayout->addRow(notifyOnFinishCheck);
defaultOutputDirButton = new QPushButton("📁 Browse...");
defaultOutputDirLineEdit = new QLineEdit();
defaultOutputDirLineEdit->setReadOnly(true);
QHBoxLayout *outputDirLayout = new QHBoxLayout();
outputDirLayout->addWidget(defaultOutputDirLineEdit);
outputDirLayout->addWidget(defaultOutputDirButton);
formLayout->addRow("Default Output Directory:", outputDirLayout);
mainLayout->addLayout(formLayout);
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
mainLayout->addWidget(buttonBox);
connect(buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
connect(defaultOutputDirButton, &QPushButton::clicked, this, &SettingsDialog::browseOutputDirectory);
connect(ffmpegPathButton, &QPushButton::clicked, this, &SettingsDialog::browseFFmpegPath);
connect(svtAv1PathButton, &QPushButton::clicked, this, &SettingsDialog::browseSvtAv1Path);
loadSettings();
}
QString SettingsDialog::getDefaultOutputDir() const { return defaultOutputDirLineEdit->text(); }
int SettingsDialog::getDefaultCodecTab() const { return defaultCodecComboBox->currentIndex(); }
QString SettingsDialog::getFFmpegPath() const { return ffmpegPathLineEdit->text(); }
bool SettingsDialog::getNotifyOnFinish() const { return notifyOnFinishCheck->isChecked(); }
QString SettingsDialog::getSvtAv1Path() const { return svtAv1PathLineEdit->text(); }
void SettingsDialog::browseOutputDirectory()
{
QFileDialog dialog(this);
dialog.setFileMode(QFileDialog::Directory);
dialog.setWindowTitle("Select Default Output Directory");
QSettings s("FFmpegConverter", "Settings");
QString last = s.value("lastSettingsBrowseDir", QStandardPaths::writableLocation(QStandardPaths::HomeLocation)).toString();
dialog.setDirectory(last);
if (dialog.exec()) {
QString dir = dialog.selectedFiles().first();
defaultOutputDirLineEdit->setText(dir);
s.setValue("lastSettingsBrowseDir", QFileInfo(dir).absolutePath());
}
}
void SettingsDialog::browseFFmpegPath()
{
QFileDialog dialog(this);
dialog.setFileMode(QFileDialog::ExistingFile);
dialog.setNameFilters({"FFmpeg Executables (ffmpeg, ffprobe)", "All Files (*.*)"});
dialog.setWindowTitle("Select FFmpeg Executable");
QSettings s("FFmpegConverter", "Settings");
QString last = s.value("lastFFmpegDir", QStandardPaths::writableLocation(QStandardPaths::HomeLocation)).toString();
dialog.setDirectory(last);
if (dialog.exec()) {
QString selectedPath = dialog.selectedFiles().first();
QProcess testProcess;
testProcess.start(selectedPath, QStringList() << "-version");
if (!testProcess.waitForFinished(5000) || testProcess.exitCode() != 0) {
QMessageBox::warning(this, "Error", "Invalid FFmpeg executable selected.");
return;
}
QString versionOutput = testProcess.readAllStandardOutput().trimmed();
if (!versionOutput.startsWith("ffmpeg version")) {
QMessageBox::warning(this, "Error", QString("This is not FFmpeg! Output starts with: \"%1\"").arg(versionOutput.left(20)));
return;
}
// Check ffprobe too
QString ffprobePath = selectedPath;
if (ffprobePath.contains("ffmpeg", Qt::CaseInsensitive))
ffprobePath.replace("ffmpeg", "ffprobe", Qt::CaseInsensitive);
testProcess.start(ffprobePath, QStringList() << "-version");
if (!testProcess.waitForFinished(5000) || testProcess.exitCode() != 0) {
QMessageBox::warning(this, "Error", "FFprobe not found or invalid at: " + ffprobePath);
return;
}
QString ffprobeVersionOutput = testProcess.readAllStandardOutput().trimmed();
if (!ffprobeVersionOutput.startsWith("ffprobe version")) {
QMessageBox::warning(this, "Error", QString("This is not ffprobe! Output starts with: \"%1\"").arg(ffprobeVersionOutput.left(20)));
return;
}
ffmpegPathLineEdit->setText(selectedPath);
s.setValue("lastFFmpegDir", QFileInfo(selectedPath).absolutePath());
}
}
void SettingsDialog::browseSvtAv1Path()
{
QFileDialog dialog(this);
dialog.setFileMode(QFileDialog::Directory);
dialog.setWindowTitle("Select SVT-AV1 Library Directory");
QSettings s("FFmpegConverter", "Settings");
QString last = s.value("lastSvtAv1Dir", QStandardPaths::writableLocation(QStandardPaths::HomeLocation)).toString();
dialog.setDirectory(last);
if (dialog.exec()) {
QString dir = dialog.selectedFiles().first();
svtAv1PathLineEdit->setText(dir);
s.setValue("lastSvtAv1Dir", QFileInfo(dir).absolutePath());
}
}
void SettingsDialog::loadSettings()
{
QSettings s("FFmpegConverter", "Settings");
defaultCodecComboBox->setCurrentIndex(s.value("defaultCodecTab", 0).toInt());
QString savedFFmpeg = s.value("ffmpegPath", "/usr/bin/ffmpeg").toString();
ffmpegPathLineEdit->setText(savedFFmpeg);
if (savedFFmpeg.contains("ffprobe", Qt::CaseInsensitive) || !QFile::exists(savedFFmpeg)) {
ffmpegPathLineEdit->setText("/usr/bin/ffmpeg");
s.setValue("ffmpegPath", "/usr/bin/ffmpeg");
}
svtAv1PathLineEdit->setText(s.value("svtAv1Path", "").toString());
defaultOutputDirLineEdit->setText(s.value("defaultOutputDir",
QStandardPaths::writableLocation(QStandardPaths::DownloadLocation)).toString());
notifyOnFinishCheck->setChecked(s.value("notifyOnFinish", true).toBool());
}