summaryrefslogtreecommitdiffstats
path: root/configurationdialog.cpp
blob: 20e424b45c99259271f7082f1a4cd257a7a1b184 (plain)
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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
/*
  This program 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
  2 of the License, or (at your option) any later version.
*/

#include <QPushButton>
#include <QTabWidget>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QGridLayout>
#include <QLineEdit>
#include <QLabel>
#include <QComboBox>
#include <QDirModel>
#include <QCompleter>
#include <QApplication>
#include <QSettings>
#include <QRegExp>
#include <QFileInfo>
#include <QGroupBox>
#include <QCheckBox>
#include <QSpinBox>

#include "configurationdialog.h"
#include "programconfigurator.h"

ConfigurationDialog::ConfigurationDialog(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f){
	//setup
	mTab = new QTabWidget;
	QDirModel *model = new QDirModel(this);
	QCompleter *fsCompleter = new QCompleter(this);
	fsCompleter->setModel(model);
	fsCompleter->setCompletionMode(QCompleter::PopupCompletion);

	//misc tab
	QWidget *miscWidget = new QWidget;
	QVBoxLayout *miscLayout = new QVBoxLayout;
	miscLayout->setAlignment(Qt::AlignTop);

	//misc - icons
	QGroupBox *iconBox = new QGroupBox(tr("Icon for folders"));
	QHBoxLayout *iconLayout = new QHBoxLayout;
	mIconForFolder = new QComboBox;
	QStringList icons = QStringList() << tr("Dildo") << tr("Normal");
	mIconForFolder->addItems(icons);
	iconLayout->addWidget(mIconForFolder);
	iconBox->setLayout(iconLayout);

	//misc - directories
	QGroupBox *pathBox = new QGroupBox(tr("Directories"));
	QGridLayout *pathGrid = new QGridLayout;
	QLabel *miscl2 = new QLabel(tr("Archive directory"));
	mArchiveDir = new QLineEdit;
	mArchiveDir->setCompleter(fsCompleter);
	pathGrid->addWidget(miscl2, 0, 0);
	pathGrid->addWidget(mArchiveDir, 0, 1);
	QLabel *miscl3 = new QLabel(tr("Burn Directory"));
	mBurnDir = new QLineEdit;
	mBurnDir->setCompleter(fsCompleter);
	pathGrid->addWidget(miscl3, 1, 0);
	pathGrid->addWidget(mBurnDir, 1, 1);
	QLabel *miscl4 = new QLabel(tr("Path to ffprobe"));
	mFfProbePath = new QLineEdit;
	mFfProbePath->setCompleter(fsCompleter);
	pathGrid->addWidget(miscl4, 2, 0);
	pathGrid->addWidget(mFfProbePath, 2, 1);
	pathBox->setLayout(pathGrid);

	//misc - hover
	QGroupBox *hoverBox = new QGroupBox(tr("Hover options"));
	QVBoxLayout *hoverLayout = new QVBoxLayout;
	mHoverPics = new QCheckBox(tr("Show picture when hovering"));
	hoverLayout->addWidget(mHoverPics);
	mHoverArchive = new QCheckBox(tr("Show further information when hovering over archive"));
	hoverLayout->addWidget(mHoverArchive);
	mHoverOpacity = new QSpinBox;
	mHoverOpacity->setMinimum(1);
	mHoverOpacity->setMaximum(10);
	QLabel *miscl5 = new QLabel(tr("Opacity of hover window"));
	QHBoxLayout *opacityLayout = new QHBoxLayout;
	opacityLayout->addWidget(miscl5);
	opacityLayout->addWidget(mHoverOpacity);
	hoverLayout->addLayout(opacityLayout);
	hoverBox->setLayout(hoverLayout);

	//misc - assemble
	miscLayout->addWidget(iconBox);
	miscLayout->addWidget(pathBox);
	miscLayout->addWidget(hoverBox);
	miscWidget->setLayout(miscLayout);
	mTab->addTab(miscWidget, tr("Misc. settings"));

	// movie viewer
	mMovieConfig = new ProgramConfigurator("movieviewer", "Movie viewer");
	mTab->addTab(mMovieConfig, tr("Movies"));

	// picture viewer
	mPicConfig = new ProgramConfigurator("pictureviewer", "Picture viewer");
	mTab->addTab(mPicConfig, tr("Pictures"));

	//database tab
	QWidget *databaseWidget = new QWidget;
	QGridLayout *dbGrid = new QGridLayout;
	QLabel *dbl1 = new QLabel(tr("Database &host"));
	mDatabaseHost = new QLineEdit;
	dbl1->setBuddy(mDatabaseHost);
	dbGrid->addWidget(dbl1, 0, 0);
	dbGrid->addWidget(mDatabaseHost, 0, 1);
	QLabel *dbl2 = new QLabel(tr("Database &name"));
	mDatabaseName = new QLineEdit;
	dbl2->setBuddy(mDatabaseName);
	dbGrid->addWidget(dbl2, 1, 0);
	dbGrid->addWidget(mDatabaseName, 1, 1);
	QLabel *dbl3 = new QLabel(tr("Database &user"));
	mDatabaseUsername = new QLineEdit;
	dbl3->setBuddy(mDatabaseUsername);
	dbGrid->addWidget(dbl3, 2, 0);
	dbGrid->addWidget(mDatabaseUsername, 2, 1);
	QLabel *dbl4 = new QLabel(tr("Database &password"));
	mDatabasePassword = new QLineEdit;
	dbl4->setBuddy(mDatabasePassword);
	mDatabasePassword->setEchoMode(QLineEdit::Password);
	dbGrid->addWidget(dbl4, 3, 0);
	dbGrid->addWidget(mDatabasePassword, 3, 1);
	dbGrid->addLayout(new QHBoxLayout, 4, 0, 2, 4);
	databaseWidget->setLayout(dbGrid);
	mTab->addTab(databaseWidget, tr("Database"));

	//main layout
	mOk = new QPushButton(tr("Ok"));
	connect(mOk, SIGNAL(clicked()), this, SLOT(accept()));
	mCancel = new QPushButton(tr("Cancel"));
	connect(mCancel, SIGNAL(clicked()), this, SLOT(reject()));
	QHBoxLayout *mainButtonLayout = new QHBoxLayout;
	mainButtonLayout->addStretch();
	mainButtonLayout->addWidget(mOk);
	mainButtonLayout->addWidget(mCancel);
	QVBoxLayout *mainLayout = new QVBoxLayout;
	mainLayout->addWidget(mTab);
	mainLayout->addLayout(mainButtonLayout);
	setLayout(mainLayout);
	QString winTitle = QString(tr("%1 - Configure")).arg(qApp->applicationName());
	setWindowTitle(winTitle);
	readSettings();
}

void ConfigurationDialog::accept(){
	writeSettings();
	QDialog::accept();
}

void ConfigurationDialog::readSettings(){
	QSettings s;

	//read misc
	QString icon = s.value("ui/foldericon", "Normal").toString();
	int pos = mIconForFolder->findText(icon);
	if(pos != -1){
		mIconForFolder->setCurrentIndex(pos);
	}
	mArchiveDir->setText(s.value("paths/archivedir").toString());
	mBurnDir->setText(s.value("paths/burn").toString());
	mFfProbePath->setText(s.value("paths/ffprobe").toString());
	mHoverPics->setChecked(s.value("ui/hoverpics", false).toBool());
	mHoverArchive->setChecked(s.value("ui/hoverarchive", false).toBool());
	mHoverOpacity->setValue(s.value("ui/hoveropacity", 10).toInt());

	//read database
	mDatabaseHost->setText(s.value("database/hostname").toString());
	mDatabaseName->setText(s.value("database/dbname").toString());
	mDatabaseUsername->setText(s.value("database/dbuser").toString());
	mDatabasePassword->setText(s.value("database/dbpass").toString());

}

void ConfigurationDialog::writeSettings(){
	QSettings s;

	//write misc
	s.setValue("ui/folderIcon", mIconForFolder->currentText());
	s.setValue("paths/archivedir", mArchiveDir->text());
	s.setValue("paths/burn", mBurnDir->text());
	QString ffprobe = mFfProbePath->text();
	QFileInfo ffProbeInfo(ffprobe);
	if(ffProbeInfo.exists() && ffProbeInfo.isExecutable()){
		s.setValue("paths/ffprobe", ffprobe);
	}
	s.setValue("ui/hoverpics", (mHoverPics->checkState() == Qt::Checked));
	s.setValue("ui/hoverarchive", (mHoverArchive->checkState() == Qt::Checked));
	s.setValue("ui/hoveropacity", mHoverOpacity->value());

	//write database
	s.setValue("database/hostname", mDatabaseHost->text());
	s.setValue("database/dbname", mDatabaseName->text());
	s.setValue("database/dbuser", mDatabaseUsername->text());
	s.setValue("database/dbpass", mDatabasePassword->text());

	//write movies
	mMovieConfig->writeSettings();

	//write pics
	mPicConfig->writeSettings();
}