/* 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 #include #include #include #include #include #include #include #include #include #include #include #include #include "configurationdialog.h" #include "programconfigurator.h" #include "smglobals.h" #include "helper.h" ConfigurationDialog::ConfigurationDialog(QWidget *parent, Qt::WindowFlags f) : SmDialog(parent, f){ //setup mTab = new QTabWidget; QDirModel *model = new QDirModel(this); QCompleter *fsCompleter = new QCompleter(this); fsCompleter->setModel(model); fsCompleter->setCompletionMode(QCompleter::PopupCompletion); //directories tab //directories QWidget *pathWidget = new QWidget; QGroupBox *pathBox = new QGroupBox(tr("Paths")); QGridLayout *pathGrid = new QGridLayout; QLabel *pathl1 = new QLabel(tr("Archive directory")); mArchiveDir = new QLineEdit; mArchiveDir->setCompleter(fsCompleter); pathGrid->addWidget(pathl1, 0, 0); pathGrid->addWidget(mArchiveDir, 0, 1); QLabel *pathl2 = new QLabel(tr("Burn Directory")); mBurnDir = new QLineEdit; mBurnDir->setCompleter(fsCompleter); pathGrid->addWidget(pathl2, 1, 0); pathGrid->addWidget(mBurnDir, 1, 1); QLabel *pathl3 = new QLabel(tr("Path to ffprobe")); mFfProbePath = new QLineEdit; mFfProbePath->setCompleter(fsCompleter); pathGrid->addWidget(pathl3, 2, 0); pathGrid->addWidget(mFfProbePath, 2, 1); QLabel *pathl4 = new QLabel(tr("Path to ffmpeg")); mFfMpegPath = new QLineEdit; mFfMpegPath->setCompleter(fsCompleter); pathGrid->addWidget(pathl4, 3, 0); pathGrid->addWidget(mFfMpegPath, 3, 1); QLabel *pathl5 = new QLabel(tr("DVD mount directory")); mDvdMountPath = new QLineEdit; pathGrid->addWidget(pathl5, 4, 0); pathGrid->addWidget(mDvdMountPath, 4, 1); QLabel *pathl6 = new QLabel(tr("Cover directory")); mCoverPath = new QLineEdit; mCoverPath->setCompleter(fsCompleter); pathGrid->addWidget(pathl6, 5, 0); pathGrid->addWidget(mCoverPath, 5, 1); pathGrid->setAlignment(Qt::AlignTop); pathBox->setLayout(pathGrid); QVBoxLayout *pathLayout = new QVBoxLayout; pathLayout->addWidget(pathBox); pathWidget->setLayout(pathLayout); //copy path options QGroupBox *copyBox = new QGroupBox(tr("Copy path options")); QGridLayout *copyGrid = new QGridLayout; QLabel *pathl7 = new QLabel(tr("Windows drive")); mWindowsDrive = new QLineEdit; QRegExp pathValid("[a-z]{1}:"); pathValid.setCaseSensitivity(Qt::CaseInsensitive); QRegExpValidator *pathValidator = new QRegExpValidator(pathValid, this); mWindowsDrive->setValidator(pathValidator); copyGrid->addWidget(pathl7, 0, 0); copyGrid->addWidget(mWindowsDrive, 0, 1); QLabel *pathl8 = new QLabel(tr("Strip from path")); mStripPath = new QLineEdit; copyGrid->addWidget(pathl8, 1, 0); copyGrid->addWidget(mStripPath, 1, 1); copyGrid->setAlignment(Qt::AlignTop); copyBox->setLayout(copyGrid); pathLayout->addWidget(copyBox); mTab->addTab(pathWidget, tr("Directories")); //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; mIconModel = new QStandardItemModel; const QHash icons = SmGlobals::instance()->icons(); for(QHash::const_iterator it = icons.constBegin(); it != icons.constEnd(); ++it){ QStandardItem *item = new QStandardItem(QIcon(it.value()), it.key()); mIconModel->appendRow(item); } mIconForFolder->setModel(mIconModel); iconLayout->addWidget(mIconForFolder); iconBox->setLayout(iconLayout); //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); mHoverMovies = new QCheckBox(tr("Show frame when hovering over movie")); connect(mHoverMovies, SIGNAL(clicked(bool)), this, SLOT(setGrabFrameEnabled(bool))); hoverLayout->addWidget(mHoverMovies); QGridLayout *miscInputGrid = new QGridLayout; QLabel *miscl6 = new QLabel(tr("Opacity of hover window")); miscInputGrid->addWidget(miscl6, 0, 0); miscInputGrid->addWidget(mHoverOpacity, 0, 1); QLabel *miscl7 = new QLabel(tr("Grab frame at ([hh:mm:ss])")); mGrabFrameFrom = new QLineEdit; QRegExp frameValid("\\d{2}:\\d{2}:\\d{2}"); QRegExpValidator *frameValidator = new QRegExpValidator(frameValid, this); mGrabFrameFrom->setValidator(frameValidator); miscInputGrid->addWidget(miscl7, 1, 0); miscInputGrid->addWidget(mGrabFrameFrom, 1, 1); QLabel *miscl8 = new QLabel(tr("Y cursor offset (hover)")); mCursorOffset = new QSpinBox; mCursorOffset->setMinimum(-100); mCursorOffset->setMaximum(100); miscInputGrid->addWidget(miscl8, 2, 0); miscInputGrid->addWidget(mCursorOffset, 2, 1); hoverLayout->addLayout(miscInputGrid); hoverBox->setLayout(hoverLayout); //misc - archiving movies QGroupBox *archiveBox = new QGroupBox(tr("Archiving options")); QVBoxLayout *archiveLayout = new QVBoxLayout; mAutoAddCovers = new QCheckBox(tr("Automatically add covers")); archiveLayout->addWidget(mAutoAddCovers); mIconizeCovers = new QCheckBox(tr("Iconize covers")); archiveLayout->addWidget(mIconizeCovers); archiveBox->setLayout(archiveLayout); //misc - assemble miscLayout->addWidget(iconBox); miscLayout->addWidget(hoverBox); miscLayout->addWidget(archiveBox); miscWidget->setLayout(miscLayout); mTab->addTab(miscWidget, tr("Misc. settings")); // movie viewer mMovieConfig = new ProgramConfigurator("movieviewer", "Movie viewer"); mTab->addTab(mMovieConfig, tr("Movies")); // picture viewer QGroupBox *picViewerBox = new QGroupBox(tr("Picture viewer options (external)")); QHBoxLayout *picViewerBoxLayout = new QHBoxLayout; mPicConfig = new ProgramConfigurator("pictureviewer", "Picture viewer"); picViewerBoxLayout->addWidget(mPicConfig); picViewerBox->setLayout(picViewerBoxLayout); QGroupBox *miscPicBox = new QGroupBox(tr("Misc. options (internal)")); QVBoxLayout *miscPicBoxLayout = new QVBoxLayout; mResizePicViewer = new QCheckBox(tr("Resize picture viewer to image size")); miscPicBoxLayout->addWidget(mResizePicViewer); miscPicBox->setLayout(miscPicBoxLayout); // picture viewer - assemble QVBoxLayout *picViewerLayout = new QVBoxLayout; picViewerLayout->addWidget(picViewerBox); picViewerLayout->addWidget(miscPicBox); QWidget *picViewerWidget = new QWidget; picViewerWidget->setLayout(picViewerLayout); mTab->addTab(picViewerWidget, 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")); //colors tab QWidget *colorsWidget = new QWidget; QGridLayout *colorGrid = new QGridLayout; QSignalMapper *colorMapper = new QSignalMapper(this); QLabel *colorl1 = new QLabel(tr("Files marked as seen")); mSeenColor = new QLabel; mSeenColor->setFrameStyle(QFrame::Sunken | QFrame::Panel); mSeenColor->setScaledContents(true); mSeenButton = new QPushButton(tr("Choose...")); colorGrid->addWidget(colorl1, 0, 0); colorGrid->addWidget(mSeenColor, 0, 1); colorGrid->addWidget(mSeenButton, 0, 2); colorMapper->setMapping(mSeenButton, mSeenColor); connect(mSeenButton, SIGNAL(clicked()), colorMapper, SLOT(map())); QLabel *colorl2 = new QLabel(tr("Files in clipboard")); mClipboardColor = new QLabel; mClipboardColor->setFrameStyle(QFrame::Sunken | QFrame::Panel); mClipboardColor->setScaledContents(true); mClipboardButton = new QPushButton(tr("Choose...")); colorGrid->addWidget(colorl2, 1, 0); colorGrid->addWidget(mClipboardColor, 1, 1); colorGrid->addWidget(mClipboardButton, 1, 2); colorMapper->setMapping(mClipboardButton, mClipboardColor); connect(mClipboardButton, SIGNAL(clicked()), colorMapper, SLOT(map())); QLabel *colorl3 = new QLabel(tr("Base color for rows")); mBaseColor = new QLabel; mBaseColor->setFrameStyle(QFrame::Sunken | QFrame::Panel); mBaseColor->setScaledContents(true); mBaseButton = new QPushButton(tr("Choose...")); colorGrid->addWidget(colorl3, 2, 0); colorGrid->addWidget(mBaseColor, 2, 1); colorGrid->addWidget(mBaseButton, 2, 2); colorMapper->setMapping(mBaseButton, mBaseColor); connect(mBaseButton, SIGNAL(clicked()), colorMapper, SLOT(map())); QLabel *colorl4 = new QLabel(tr("Alternate base for rows")); mAlternateBaseColor = new QLabel; mAlternateBaseColor->setFrameStyle(QFrame::Sunken | QFrame::Panel); mAlternateBaseColor->setScaledContents(true); mAlternateBaseButton = new QPushButton(tr("Choose...")); colorGrid->addWidget(colorl4, 3, 0); colorGrid->addWidget(mAlternateBaseColor, 3, 1); colorGrid->addWidget(mAlternateBaseButton, 3, 2); colorMapper->setMapping(mAlternateBaseButton, mAlternateBaseColor); connect(mAlternateBaseButton, SIGNAL(clicked()), colorMapper, SLOT(map())); QLabel *colorl5 = new QLabel(tr("Font color")); mFontColor = new QLabel; mFontColor->setFrameStyle(QFrame::Sunken | QFrame::Panel); mFontColor->setScaledContents(true); mFontColorButton = new QPushButton(tr("Choose...")); colorGrid->addWidget(colorl5, 4, 0); colorGrid->addWidget(mFontColor, 4, 1); colorGrid->addWidget(mFontColorButton, 4, 2); colorMapper->setMapping(mFontColorButton, mFontColor); connect(mFontColorButton, SIGNAL(clicked()), colorMapper, SLOT(map())); QLabel *colorl6 = new QLabel(tr("Local files")); mLocalColor = new QLabel; mLocalColor->setFrameStyle(QFrame::Sunken | QFrame::Panel); mLocalColor->setScaledContents(true); mLocalColorButton = new QPushButton(tr("Choose...")); colorGrid->addWidget(colorl6, 5, 0); colorGrid->addWidget(mLocalColor, 5, 1); colorGrid->addWidget(mLocalColorButton, 5, 2); colorMapper->setMapping(mLocalColorButton, mLocalColor); connect(mLocalColorButton, SIGNAL(clicked()), colorMapper, SLOT(map())); QLabel *colorl7 = new QLabel(tr("Archived Files")); mArchivedColor = new QLabel; mArchivedColor->setFrameStyle(QFrame::Sunken | QFrame::Panel); mArchivedColor->setScaledContents(true); mArchivedColorButton = new QPushButton(tr("Choose...")); colorGrid->addWidget(colorl7, 6, 0); colorGrid->addWidget(mArchivedColor, 6, 1); colorGrid->addWidget(mArchivedColorButton, 6, 2); colorMapper->setMapping(mArchivedColorButton, mArchivedColor); connect(mArchivedColorButton, SIGNAL(clicked()), colorMapper, SLOT(map())); QLabel *colorl8 = new QLabel(tr("Favorites")); mFavoriteColor = new QLabel; mFavoriteColor->setFrameStyle(QFrame::Sunken | QFrame::Panel); mFavoriteColor->setScaledContents(true); mFavoriteColorButton = new QPushButton(tr("Choose...")); colorGrid->addWidget(colorl8, 7, 0); colorGrid->addWidget(mFavoriteColor, 7, 1); colorGrid->addWidget(mFavoriteColorButton, 7, 2); colorMapper->setMapping(mFavoriteColorButton, mFavoriteColor); connect(mFavoriteColorButton, SIGNAL(clicked()), colorMapper, SLOT(map())); connect(colorMapper, SIGNAL(mapped(QWidget*)), this, SLOT(chooseColor(QWidget*))); mAlternateColors = new QCheckBox(tr("Use alternating row colors")); mAlternateColors->setTristate(false); connect(mAlternateColors, SIGNAL(stateChanged(int)), this, SLOT(alternateColorsChanged(int))); colorGrid->addWidget(mAlternateColors, 8, 1, 1, 2, Qt::AlignLeft); QVBoxLayout *colorStretchLayout = new QVBoxLayout; colorStretchLayout->addStretch(); colorGrid->addLayout(colorStretchLayout, 9, 1, 3, Qt::AlignLeft); colorsWidget->setLayout(colorGrid); mTab->addTab(colorsWidget, tr("Colors")); //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::setGrabFrameEnabled(bool enabled){ mGrabFrameFrom->setEnabled(enabled); } void ConfigurationDialog::readSettings(){ QSettings s; //read misc QString icon = s.value("ui/foldericon", "Dildo").toString(); int pos = mIconForFolder->findText(icon); if(pos != -1){ mIconForFolder->setCurrentIndex(pos); } mHoverPics->setChecked(s.value("ui/hoverpics", false).toBool()); mHoverArchive->setChecked(s.value("ui/hoverarchive", false).toBool()); mHoverMovies->setChecked(s.value("ui/hovermovies", false).toBool()); mHoverOpacity->setValue(s.value("ui/hoveropacity", 10).toInt()); mGrabFrameFrom->setText(s.value("ui/grabframe", "00:00:00").toString()); mGrabFrameFrom->setEnabled(s.value("ui/hovermovies", false).toBool()); mAutoAddCovers->setChecked(s.value("ui/autoaddcovers", false).toBool()); mIconizeCovers->setChecked(s.value("ui/iconizecovers", false).toBool()); mCursorOffset->setValue(s.value("ui/cursoroffset", SmGlobals::instance()->cursorSize().height()).toInt()); //read picture viewer mResizePicViewer->setChecked(s.value("ui/resizepicviewer", false).toBool()); //read paths mArchiveDir->setText(s.value("paths/archivedir").toString()); mBurnDir->setText(s.value("paths/burn").toString()); mFfProbePath->setText(s.value("paths/ffprobe").toString()); mFfMpegPath->setText(s.value("paths/ffmpeg").toString()); mDvdMountPath->setText(s.value("paths/dvdmount").toString()); mCoverPath->setText(s.value("paths/coverpath").toString()); mWindowsDrive->setText(s.value("paths/windowsdrive").toString()); mStripPath->setText(s.value("paths/strippath").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()); //read colors QVariant seen = s.value("ui/seencolor", Qt::red); mColors.insert(mSeenColor, seen.value()); QVariant clip = s.value("ui/clipcolor", Qt::darkBlue); mColors.insert(mClipboardColor, clip.value()); QVariant base = s.value("ui/basecolor", qApp->palette().base().color()); mColors.insert(mBaseColor, base.value()); QVariant alternate = s.value("ui/alternatecolor", qApp->palette().alternateBase().color()); mColors.insert(mAlternateBaseColor, alternate.value()); QVariant font = s.value("ui/fontcolor", qApp->palette().foreground().color()); mColors.insert(mFontColor, font.value()); QVariant local = s.value("ui/localcolor", Qt::darkBlue); mColors.insert(mLocalColor, local.value()); QVariant archived = s.value("ui/archivedcolor", Qt::black); mColors.insert(mArchivedColor, archived.value()); QVariant favorite = s.value("ui/favoritecolor", Qt::red); mColors.insert(mFavoriteColor, favorite.value()); QHash::const_iterator it; for(it = mColors.constBegin(); it != mColors.constEnd(); ++it){ setColor(it.key()); } bool allowAlternate = s.value("ui/allowalternate", true).toBool(); mAlternateColors->setChecked(allowAlternate); alternateColorsChanged(mAlternateColors->checkState()); } void ConfigurationDialog::writeSettings(){ QSettings s; //write paths 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); } QString ffmpeg = mFfMpegPath->text(); QFileInfo ffMpegInfo(ffmpeg); if(ffMpegInfo.exists() && ffMpegInfo.isExecutable()){ s.setValue("paths/ffmpeg", ffmpeg); } if(checkDvdPath()){ s.setValue("paths/dvdmount", mDvdMountPath->text()); } s.setValue("paths/windowsdrive", mWindowsDrive->text()); s.setValue("paths/strippath", mStripPath->text()); s.setValue("paths/coverpath", mCoverPath->text()); s.setValue("ui/folderIcon", mIconForFolder->currentText()); s.setValue("ui/hoverpics", (mHoverPics->checkState() == Qt::Checked)); s.setValue("ui/hoverarchive", (mHoverArchive->checkState() == Qt::Checked)); s.setValue("ui/hoveropacity", mHoverOpacity->value()); s.setValue("ui/hovermovies", (mHoverMovies->checkState() == Qt::Checked)); s.setValue("ui/grabframe", mGrabFrameFrom->text()); s.setValue("ui/autoaddcovers", (mAutoAddCovers->checkState() == Qt::Checked)); s.setValue("ui/iconizecovers", (mIconizeCovers->checkState() == Qt::Checked)); s.setValue("ui/cursoroffset", mCursorOffset->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(); s.setValue("ui/resizepicviewer", (mResizePicViewer->checkState() == Qt::Checked)); //write colors s.setValue("ui/seencolor", mColors.value(mSeenColor)); s.setValue("ui/clipcolor", mColors.value(mClipboardColor)); s.setValue("ui/basecolor", mColors.value(mBaseColor)); s.setValue("ui/alternatecolor", mColors.value(mAlternateBaseColor)); s.setValue("ui/fontcolor", mColors.value(mFontColor)); s.setValue("ui/localcolor", mColors.value(mLocalColor)); s.setValue("ui/archivedcolor", mColors.value(mArchivedColor)); s.setValue("ui/favoritecolor", mColors.value(mFavoriteColor)); s.setValue("ui/allowalternate", mAlternateColors->isChecked()); } bool ConfigurationDialog::checkDvdPath(){ QString path = mDvdMountPath->text(); if(path.isEmpty()){ return true; } QFileInfo mountInfo(path); if(!mountInfo.exists() || !mountInfo.isDir()){ QString message = QString(tr("%1 does not exist or is not a directory. Ignoring.")).arg(path); mountError(message); return false; } QFile fstab("/etc/fstab"); if(!fstab.exists() || !fstab.open(QFile::ReadOnly)){ mountError(QString()); return true; } QTextStream fStream(&fstab); QString line; bool ok = false; do { line = fStream.readLine(); if(line.contains(path)){ QStringList fsParts = line.split(QRegExp("\\s+")); if(fsParts.isEmpty() || (fsParts.size() < 4)){ continue; } QStringList options = fsParts.at(3).split(','); foreach(QString opt, options){ if(opt.toLower().trimmed() == "user"){ ok = true; break; } } } } while(!line.isNull()); if(!ok){ QString message = QString(tr("Didn't find %1 in fstab or it isn't user mountable. Ignoring.")).arg(path); mountError(message); return false; } return true; } void ConfigurationDialog::mountError(const QString &error){ if(!error.isEmpty()){ QMessageBox::critical(this, tr("Mount Path Error"), error); } QSettings s; s.setValue("paths/dvdmount", QString()); } void ConfigurationDialog::chooseColor(QWidget *label){ QColor newColor = QColorDialog::getColor(mColors.value(label), this); if(newColor.isValid()){ mColors[label] = newColor; setColor(label); } } void ConfigurationDialog::alternateColorsChanged(int state){ mBaseButton->setEnabled(state == Qt::Checked); mBaseColor->setEnabled(state == Qt::Checked); mAlternateBaseButton->setEnabled(state == Qt::Checked); mAlternateBaseColor->setEnabled(state == Qt::Checked); } void ConfigurationDialog::setColor(QWidget *label){ QLabel *curLabel = qobject_cast(label); if(!curLabel){ return; } QColor curColor = mColors.value(label); QPixmap pm(curLabel->sizeHint()); pm.fill(curColor); curLabel->setPixmap(pm); }