/* 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" ConfigurationDialog::ConfigurationDialog(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f){ //paths tab QWidget *pathWidget = new QWidget; QGridLayout *pathGrid = new QGridLayout; mTab = new QTabWidget; QDirModel *model = new QDirModel(this); QCompleter *fsCompleter = new QCompleter(this); fsCompleter->setModel(model); fsCompleter->setCompletionMode(QCompleter::PopupCompletion); QLabel *l1 = new QLabel(tr("Path to &picture viewer")); mPictureViewer = new QLineEdit; mPictureViewer->setCompleter(fsCompleter); l1->setBuddy(mPictureViewer); pathGrid->addWidget(l1, 0, 0); pathGrid->addWidget(mPictureViewer, 0, 1); QLabel *l2 = new QLabel(tr("Arguments for picture viewer")); mPictureViewerArgs = new QLineEdit; pathGrid->addWidget(l2, 1, 0); pathGrid->addWidget(mPictureViewerArgs, 1, 1); QLabel *l3 = new QLabel(tr("Path to movie viewer")); mMovieViewer = new QLineEdit; mMovieViewer->setCompleter(fsCompleter); l2->setBuddy(mMovieViewer); pathGrid->addWidget(l3, 2, 0); pathGrid->addWidget(mMovieViewer, 2, 1); QLabel *l4 = new QLabel(tr("Arguments for movie viewer")); mMovieViewerArgs = new QLineEdit; pathGrid->addWidget(l4, 3, 0); pathGrid->addWidget(mMovieViewerArgs, 3, 1); QLabel *l5 = new QLabel(tr("Path to &archive program")); mArchiver = new QLineEdit; mArchiver->setCompleter(fsCompleter); l5->setBuddy(mArchiver); pathGrid->addWidget(l5, 4, 0); pathGrid->addWidget(mArchiver, 4, 1); QLabel *l6 = new QLabel(tr("Arguments for archive program")); mArchiverArgs = new QLineEdit; l6->setBuddy(mArchiverArgs); pathGrid->addWidget(l6, 5, 0); pathGrid->addWidget(mArchiverArgs, 5, 1); QLabel *l7 = new QLabel(tr("Extraction paths")); mArchivePaths = new QComboBox; pathGrid->addWidget(l7, 6, 0); pathGrid->addWidget(mArchivePaths); QLabel *l8 = new QLabel(tr("Enter new &extraction path")); mExtractPath = new QLineEdit; mExtractPath->setCompleter(fsCompleter); l8->setBuddy(mExtractPath); pathGrid->addWidget(l8, 7, 0); pathGrid->addWidget(mExtractPath, 7, 1); mAddPath = new QPushButton(tr("Add path")); connect(mAddPath, SIGNAL(clicked()), this, SLOT(addPath())); mRemovePath = new QPushButton(tr("Remove path")); connect(mRemovePath, SIGNAL(clicked()), this, SLOT(removePath())); QHBoxLayout *pathButtonLayout = new QHBoxLayout; pathButtonLayout->addStretch(); pathButtonLayout->addWidget(mAddPath); pathButtonLayout->addWidget(mRemovePath); pathGrid->addLayout(pathButtonLayout, 8, 1); pathWidget->setLayout(pathGrid); mTab->addTab(pathWidget, tr("Paths")); //ui tab QWidget *uiWidget = new QWidget; QGridLayout *uiGrid = new QGridLayout; QLabel *ui1 = new QLabel(tr("Select icon for &folders")); mIconForFolder = new QComboBox; ui1->setBuddy(mIconForFolder); QStringList icons = QStringList() << tr("Dildo") << tr("Normal"); mIconForFolder->addItems(icons); uiGrid->addWidget(ui1, 0, 0); uiGrid->addWidget(mIconForFolder, 0, 1); QLabel *ui2 = new QLabel(tr("Expand paths in directory tree")); mExpandPaths = new QComboBox; uiGrid->addWidget(ui2, 1, 0); uiGrid->addWidget(mExpandPaths, 1, 1); mSelect = new QPushButton(tr("Open directory at Startup")); connect(mSelect, SIGNAL(clicked()), this, SLOT(selectStartup())); uiGrid->addWidget(mSelect, 2, 1); QLabel *ui3 = new QLabel(tr("Add &new path to expand")); mExpandPath = new QLineEdit; mExpandPath->setCompleter(fsCompleter); ui3->setBuddy(mExpandPath); uiGrid->addWidget(ui3, 3, 0); uiGrid->addWidget(mExpandPath, 3, 1); mAddExpandPath = new QPushButton(tr("Add path")); connect(mAddExpandPath, SIGNAL(clicked()), this, SLOT(addExpandPath())); mRemoveExpandPath = new QPushButton(tr("Remove path")); connect(mRemoveExpandPath, SIGNAL(clicked()), this, SLOT(removeExpandPath())); QHBoxLayout *expandButtons = new QHBoxLayout; expandButtons->addWidget(mAddExpandPath); expandButtons->addWidget(mRemoveExpandPath); uiGrid->addLayout(expandButtons, 4, 1); uiGrid->addLayout(new QHBoxLayout, 5, 0, 2, 3); uiWidget->setLayout(uiGrid); mTab->addTab(uiWidget, tr("User interface")); //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::addPath(){ QString newPath = mExtractPath->text(); if(!newPath.isEmpty() && !mPaths.contains(newPath)){ mArchivePaths->addItem(newPath); mPaths.append(newPath); } } void ConfigurationDialog::removePath(){ QString removePath = mArchivePaths->currentText(); int current = mArchivePaths->currentIndex(); if(!removePath.isEmpty()){ if(mPaths.contains(removePath)){ mPaths.removeOne(removePath); mArchivePaths->removeItem(current); } } } void ConfigurationDialog::addExpandPath(){ QString newPath = mExpandPath->text(); if(!newPath.isEmpty() && !mEPaths.contains(newPath)){ mExpandPaths->addItem(newPath); mEPaths.append(newPath); } } void ConfigurationDialog::removeExpandPath(){ QString removePath = mExpandPaths->currentText(); int current = mExpandPaths->currentIndex(); if(!removePath.isEmpty()){ if(mEPaths.contains(removePath)){ mEPaths.removeOne(removePath); mExpandPaths->removeItem(current); } } } void ConfigurationDialog::selectStartup(){ QString startup = mExpandPaths->currentText(); if(!startup.isEmpty()){ mSelectStartup = startup; } } void ConfigurationDialog::readSettings(){ QSettings s; //read paths mPictureViewer->setText(s.value("paths/pictureviewer", "/usr/bin/gwenview").toString()); QStringList pvArgs = s.value("paths/pictureviewerargs").toStringList(); mPictureViewerArgs->setText(pvArgs.join(" ")); mMovieViewer->setText(s.value("paths/movieviewer", "/usr/bin/mplayer").toString()); QStringList mvArgs = s.value("paths/movieviewerargs").toStringList(); mMovieViewerArgs->setText(mvArgs.join(" ")); mArchiver->setText(s.value("paths/archiver", "/usr/bin/7z").toString()); QStringList arArgs = s.value("paths/archiverargs").toStringList(); mArchiverArgs->setText(arArgs.join(" ")); QStringList extractPaths = s.value("paths/extractpaths").toStringList(); mArchivePaths->addItems(extractPaths); mPaths = extractPaths; //read ui QStringList expandPaths = s.value("ui/expandpaths").toStringList(); mExpandPaths->addItems(expandPaths); mEPaths = expandPaths; QString icon = s.value("ui/foldericon", "Normal").toString(); int pos = mIconForFolder->findText(icon); if(pos != -1){ mIconForFolder->setCurrentIndex(pos); } //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 paths QRegExp splitAt("\\s+"); s.setValue("paths/pictureviewer", mPictureViewer->text()); QStringList pvArgs = mPictureViewerArgs->text().split(splitAt, QString::SkipEmptyParts); s.setValue("paths/pictureviewerargs", pvArgs); s.setValue("paths/movieviewer", mMovieViewer->text()); QStringList mvArgs = mMovieViewerArgs->text().split(splitAt, QString::SkipEmptyParts); s.setValue("paths/movieviewerargs", mvArgs); s.setValue("paths/archiver", mArchiver->text()); QStringList aArgs = mArchiverArgs->text().split(splitAt, QString::SkipEmptyParts); s.setValue("paths/archiverargs", aArgs); s.setValue("paths/extractpaths", mPaths); //write ui s.setValue("ui/expandpaths", mEPaths); s.setValue("ui/folderIcon", mIconForFolder->currentText()); s.setValue("ui/selectstartup", mSelectStartup); //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()); }