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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
|
#include <QTabWidget>
#include <QGridLayout>
#include <QLabel>
#include <QSettings>
#include <QPushButton>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QLineEdit>
#include <QFileDialog>
#include <QStandardItemModel>
#include <QListView>
#include <QItemSelectionModel>
#include "configurationwidget.h"
ConfigurationWidget::ConfigurationWidget(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f) {
//database setup
QGridLayout *dbLayout = new QGridLayout;
mDbHost = new QLineEdit;
dbLayout->addWidget(new QLabel(tr("Hostname")), 0, 0);
dbLayout->addWidget(mDbHost, 0, 1);
mDbUser = new QLineEdit;
dbLayout->addWidget(new QLabel(tr("Username")), 1, 0);
dbLayout->addWidget(mDbUser, 1, 1);
mDbPass = new QLineEdit;
mDbPass->setEchoMode(QLineEdit::Password);
dbLayout->addWidget(new QLabel(tr("Password")), 2, 0);
dbLayout->addWidget(mDbPass, 2, 1);
mDbName = new QLineEdit;
dbLayout->addWidget(new QLabel(tr("DB Name")), 3, 0);
dbLayout->addWidget(mDbName, 3, 1);
dbLayout->setAlignment(Qt::AlignTop);
QWidget *dbWidget = new QWidget;
dbWidget->setLayout(dbLayout);
//exernal programs
QGridLayout *extL = new QGridLayout;
mFfProbe = new QLineEdit;
extL->addWidget(new QLabel(tr("ffprobe")), 0, 0);
extL->addWidget(mFfProbe, 0, 1);
QPushButton *browseFfProbeBtn = new QPushButton(tr("Browse..."));
connect(browseFfProbeBtn, SIGNAL(clicked()), this, SLOT(browseFfProbe()));
extL->addWidget(browseFfProbeBtn, 0, 2);
mFfMpeg = new QLineEdit;
extL->addWidget(new QLabel(tr("ffmpeg")), 1, 0);
extL->addWidget(mFfMpeg, 1, 1);
QPushButton *browseFfMpegBtn = new QPushButton(tr("Browse..."));
connect(browseFfMpegBtn, SIGNAL(clicked()), this, SLOT(browseFfMpeg()));
extL->addWidget(browseFfMpegBtn, 1, 2);
mMkvInfo = new QLineEdit;
extL->addWidget(new QLabel(tr("mkvinfo")), 2, 0);
extL->addWidget(mMkvInfo, 2, 1);
QPushButton *browsemkvBtn = new QPushButton(tr("Browse..."));
connect(browsemkvBtn, SIGNAL(clicked()), this, SLOT(browseMkvInfo()));
extL->addWidget(browsemkvBtn, 2, 2);
extL->setAlignment(Qt::AlignTop);
QWidget *extWidget = new QWidget;
extWidget->setLayout(extL);
//copy directories
QHBoxLayout *newDirL = new QHBoxLayout;
newDirL->addWidget(new QLabel(tr("Directory")));
mDir = new QLineEdit;
newDirL->addWidget(mDir);
QPushButton *browseCopyDirBtn = new QPushButton(tr("Browse..."));
connect(browseCopyDirBtn, SIGNAL(clicked()), this, SLOT(browseCopyDir()));
newDirL->addWidget(browseCopyDirBtn);
QPushButton *addDir = new QPushButton(tr("Add"));
connect(addDir, SIGNAL(clicked()), this, SLOT(addCopyDir()));
QPushButton *removeDir = new QPushButton(tr("Remove"));
connect(removeDir, SIGNAL(clicked()), this, SLOT(removeCopyDir()));
QHBoxLayout *addRemL = new QHBoxLayout;
addRemL->addStretch();
addRemL->addWidget(addDir);
addRemL->addWidget(removeDir);
mCopyDirM = new QStandardItemModel;
mCopyDirV = new QListView;
mCopyDirV->setModel(mCopyDirM);
connect(mCopyDirV->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)), this, SLOT(selectCopyDir(QModelIndex,QModelIndex)));
QVBoxLayout *newDirTabL = new QVBoxLayout;
newDirTabL->addLayout(newDirL);
newDirTabL->addLayout(addRemL);
newDirTabL->addWidget(mCopyDirV);
QWidget *dirWidget = new QWidget;
dirWidget->setLayout(newDirTabL);
//buttons
mAccept = new QPushButton(tr("Save"));
connect(mAccept, SIGNAL(clicked()), this, SLOT(accept()));
mCancel = new QPushButton(tr("Cancel"));
connect(mCancel, SIGNAL(clicked()), this, SLOT(reject()));
QHBoxLayout *bLayout = new QHBoxLayout;
bLayout->addStretch();
bLayout->addWidget(mAccept);
bLayout->addWidget(mCancel);
bLayout->addStretch();
//dialog layout
QVBoxLayout *mainLayout = new QVBoxLayout;
QTabWidget *tab = new QTabWidget;
tab->addTab(dbWidget, tr("Database"));
tab->addTab(extWidget, tr("Programs"));
tab->addTab(dirWidget, tr("Copy dirs"));
mainLayout->addWidget(tab);
mainLayout->addLayout(bLayout);
readSettings();
setLayout(mainLayout);
setMinimumWidth(400);
}
void ConfigurationWidget::accept(){
QSettings s;
s.setValue("dbhost", mDbHost->text());
s.setValue("dbuser", mDbUser->text());
s.setValue("dbpass", mDbPass->text());
s.setValue("dbname", mDbName->text());
s.setValue("ext/ffprobe", mFfProbe->text());
s.setValue("ext/ffmpeg", mFfMpeg->text());
s.setValue("ext/mkvinfo", mMkvInfo->text());
QStringList copyDirs;
for(int i = 0; i < mCopyDirM->rowCount(); ++i){
auto item = mCopyDirM->item(i);
copyDirs << item->text();
}
s.setValue("copydirs", copyDirs);
QDialog::accept();
}
void ConfigurationWidget::browseFfProbe(){
QString ffprobe = QFileDialog::getOpenFileName(this, tr("Select ffprobe"), QDir::homePath());
mFfProbe->setText(QDir::toNativeSeparators(ffprobe));
}
void ConfigurationWidget::browseFfMpeg(){
QString ffmpeg = QFileDialog::getOpenFileName(this, tr("Select ffmpeg"), QDir::homePath());
mFfMpeg->setText(QDir::toNativeSeparators(ffmpeg));
}
void ConfigurationWidget::browseMkvInfo(){
QString mkvinfo = QFileDialog::getOpenFileName(this, tr("Select mkvinfo"), QDir::homePath());
mMkvInfo->setText(QDir::toNativeSeparators(mkvinfo));
}
void ConfigurationWidget::browseCopyDir(){
QString copyDir = QFileDialog::getExistingDirectory(this, tr("Select Directory"), QDir::homePath());
mDir->setText(QDir::toNativeSeparators(copyDir));
}
void ConfigurationWidget::addCopyDir(){
QString dir = mDir->text();
QFileInfo dinfo(dir);
if(dinfo.exists() && dinfo.isDir()){
auto search = mCopyDirM->findItems(dir);
if(search.isEmpty()){
QStandardItem *newDir = new QStandardItem(QIcon(":/folder.png"), dir);
mCopyDirM->insertRow(mCopyDirM->rowCount(), newDir);
}
}
}
void ConfigurationWidget::removeCopyDir(){
QString dir = mDir->text();
auto search = mCopyDirM->findItems(dir);
if(!search.isEmpty()){
mCopyDirM->removeRow(search.first()->row());
}
}
void ConfigurationWidget::selectCopyDir(const QModelIndex &cur, const QModelIndex &prev){
Q_UNUSED(prev);
mDir->setText(cur.data().toString());
}
void ConfigurationWidget::readSettings(){
QSettings s;
mDbHost->setText(s.value("dbhost").toString());
mDbUser->setText(s.value("dbuser").toString());
mDbPass->setText(s.value("dbpass").toString());
mDbName->setText(s.value("dbname").toString());
mFfProbe->setText(s.value("ext/ffprobe").toString());
mFfMpeg->setText(s.value("ext/ffmpeg").toString());
mMkvInfo->setText(s.value("ext/mkvinfo").toString());
QStringList copyDirs = s.value("copydirs").toStringList();
foreach(auto d, copyDirs){
mDir->setText(d);
addCopyDir();
}
}
|