summaryrefslogtreecommitdiffstats
path: root/configurationdialog.cpp
blob: f4537007297876b3e012e59984b0b361348a9885 (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
/*
  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 "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;
	QGridLayout *miscGrid = new QGridLayout;
	miscGrid->setAlignment(Qt::AlignTop);
	QLabel *miscl1 = new QLabel(tr("Select icon for &folders"));
	mIconForFolder = new QComboBox;
	miscl1->setBuddy(mIconForFolder);
	QStringList icons = QStringList() << tr("Dildo") << tr("Normal");
	mIconForFolder->addItems(icons);
	miscGrid->addWidget(miscl1, 0, 0);
	miscGrid->addWidget(mIconForFolder, 0, 1);
	QLabel *miscl2 = new QLabel(tr("Archive directory"));
	mArchiveDir = new QLineEdit;
	mArchiveDir->setCompleter(fsCompleter);
	miscGrid->addWidget(miscl2, 1, 0);
	miscGrid->addWidget(mArchiveDir, 1, 1);
	miscWidget->setLayout(miscGrid);
	QLabel *miscl3 = new QLabel(tr("Burn Directory"));
	mBurnDir = new QLineEdit;
	mBurnDir->setCompleter(fsCompleter);
	miscGrid->addWidget(miscl3, 2, 0);
	miscGrid->addWidget(mBurnDir, 2, 1);
	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());

	//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());

	//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();
}