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