/* 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 "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); QLabel *miscl4 = new QLabel(tr("Path to ffprobe")); mFfProbePath = new QLineEdit; mFfProbePath->setCompleter(fsCompleter); miscGrid->addWidget(miscl4, 3, 0); miscGrid->addWidget(mFfProbePath, 3, 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()); mFfProbePath->setText(s.value("paths/ffprobe").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()); QString ffprobe = mFfProbePath->text(); QFileInfo ffProbeInfo(ffprobe); if(ffProbeInfo.exists() && ffProbeInfo.isExecutable()){ s.setValue("paths/ffprobe", ffprobe); } //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(); }