From 366eb153e82063a1157695e6c0873a7a64bee3af Mon Sep 17 00:00:00 2001 From: trialuser02 Date: Sat, 1 Dec 2018 21:38:21 +0000 Subject: rdetect: added settings dialog git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@8471 90c681e8-e032-0410-971d-27865f9a5e38 --- src/plugins/General/rdetect/rdetect.pro | 10 +- src/plugins/General/rdetect/rdetectfactory.cpp | 6 +- src/plugins/General/rdetect/removablehelper.cpp | 59 +++++++++++- src/plugins/General/rdetect/removablehelper.h | 7 ++ src/plugins/General/rdetect/settingsdialog.cpp | 55 +++++++++++ src/plugins/General/rdetect/settingsdialog.h | 45 +++++++++ src/plugins/General/rdetect/settingsdialog.ui | 122 ++++++++++++++++++++++++ 7 files changed, 298 insertions(+), 6 deletions(-) create mode 100644 src/plugins/General/rdetect/settingsdialog.cpp create mode 100644 src/plugins/General/rdetect/settingsdialog.h create mode 100644 src/plugins/General/rdetect/settingsdialog.ui (limited to 'src') diff --git a/src/plugins/General/rdetect/rdetect.pro b/src/plugins/General/rdetect/rdetect.pro index ebbb4a67e..6e62b8401 100644 --- a/src/plugins/General/rdetect/rdetect.pro +++ b/src/plugins/General/rdetect/rdetect.pro @@ -3,10 +3,14 @@ include(../../plugins.pri) TARGET = $$PLUGINS_PREFIX/General/rdetect HEADERS += rdetectfactory.h \ - removablehelper.h + removablehelper.h \ + settingsdialog.h SOURCES += rdetectfactory.cpp \ - removablehelper.cpp + removablehelper.cpp \ + settingsdialog.cpp + +FORMS += settingsdialog.ui #RESOURCES = translations/translations.qrc @@ -14,3 +18,5 @@ LIBS += $$QMMPUI_LIB target.path = $$PLUGIN_DIR/General INSTALLS += target + + diff --git a/src/plugins/General/rdetect/rdetectfactory.cpp b/src/plugins/General/rdetect/rdetectfactory.cpp index 26e912cd7..f329d8ace 100644 --- a/src/plugins/General/rdetect/rdetectfactory.cpp +++ b/src/plugins/General/rdetect/rdetectfactory.cpp @@ -20,6 +20,7 @@ #include #include +#include "settingsdialog.h" #include "removablehelper.h" #include "rdetectfactory.h" @@ -29,7 +30,7 @@ GeneralProperties RDetectFactory::properties() const properties.name = tr("Volume Detection Plugin"); properties.shortName = "rdetect"; properties.hasAbout = true; - properties.hasSettings = false; + properties.hasSettings = true; properties.visibilityControl = false; return properties; } @@ -41,8 +42,7 @@ QObject *RDetectFactory::create(QObject *parent) QDialog *RDetectFactory::createConfigDialog(QWidget *parent) { - Q_UNUSED(parent); - return nullptr; + return new SettingsDialog(parent); } void RDetectFactory::showAbout(QWidget *parent) diff --git a/src/plugins/General/rdetect/removablehelper.cpp b/src/plugins/General/rdetect/removablehelper.cpp index 1ed0ee609..8dcb16500 100644 --- a/src/plugins/General/rdetect/removablehelper.cpp +++ b/src/plugins/General/rdetect/removablehelper.cpp @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -33,7 +34,22 @@ RemovableHelper::RemovableHelper(QObject *parent): QObject(parent) qApp->installNativeEventFilter(this); m_actions = new QActionGroup(this); connect(m_actions,SIGNAL(triggered(QAction *)), SLOT(processAction(QAction *))); + //load settings + QSettings settings(Qmmp::configFile(), QSettings::IniFormat); + settings.beginGroup("rdetect"); + m_detectCDA = settings.value("cda", true).toBool(); + m_detectRemovable = settings.value("removable", true).toBool(); + m_addTracks = false; //do not load tracks on startup + m_addFiles = false; + //find existing devices updateActions(); + //load remaining settings + m_addTracks = settings.value("add_tracks", false).toBool(); + m_removeTracks = settings.value("remove_tracks", false).toBool(); + m_addFiles = settings.value("add_files", false).toBool(); + m_removeFiles = settings.value("remove_files", false).toBool(); + settings.endGroup(); + } RemovableHelper::~RemovableHelper() @@ -92,7 +108,7 @@ void RemovableHelper::updateActions() qDebug() << storage.fileSystemType(); - if(storage.bytesTotal() < 40000000000LL && + if(m_detectRemovable && storage.bytesTotal() < 40000000000LL && (storage.fileSystemType() == "NTFS" || storage.fileSystemType() == "FAT32" || storage.fileSystemType() == "CDFS" || @@ -128,6 +144,7 @@ void RemovableHelper::updateActions() action->setData(dev_path); m_actions->addAction(action); UiHelper::instance()->addAction(action, UiHelper::ADD_MENU); + addPath(dev_path); } } // remove action if device is unmounted/removed @@ -149,6 +166,7 @@ void RemovableHelper::updateActions() qDebug("RemovableHelper: removed menu item: \"%s\"", qPrintable(action->data().toString())); m_actions->removeAction(action); UiHelper::instance()->removeAction(action); + removePath(action->data().toString()); action->deleteLater(); } } @@ -164,3 +182,42 @@ QAction *RemovableHelper::findAction(const QString &dev_path) return nullptr; } +void RemovableHelper::addPath(const QString &path) +{ + PlayListModel *model = PlayListManager::instance()->selectedPlayList(); + + foreach(PlayListItem *item, model->items()) // Is it already exist? + { + if(item->isGroup()) + continue; + if (dynamic_cast(item)->path().startsWith(path)) + return; + } + + if (path.startsWith("cdda://") && m_addTracks) + { + PlayListManager::instance()->selectedPlayList()->add(path); + return; + } + else if (!path.startsWith("cdda://") && m_addFiles) + PlayListManager::instance()->selectedPlayList()->add(path); +} + +void RemovableHelper::removePath(const QString &path) +{ + if ((path.startsWith("cdda://") && !m_removeTracks) || + (!path.startsWith("cdda://") && !m_removeFiles)) //process settings + return; + + PlayListModel *model = PlayListManager::instance()->selectedPlayList(); + + int i = 0; + while (model->count() > 0 && i < model->count()) + { + if (model->isTrack(i) && model->track(i)->path().startsWith(path)) + model->removeTrack(i); + else + ++i; + } +} + diff --git a/src/plugins/General/rdetect/removablehelper.h b/src/plugins/General/rdetect/removablehelper.h index c1740aaa9..c97b1b749 100644 --- a/src/plugins/General/rdetect/removablehelper.h +++ b/src/plugins/General/rdetect/removablehelper.h @@ -41,7 +41,14 @@ private slots: private: void updateActions(); QAction *findAction(const QString &dev_path); + void addPath(const QString &path); + void removePath(const QString &path); + QActionGroup *m_actions; + bool m_detectCDA; + bool m_detectRemovable; + bool m_addTracks, m_removeTracks; + bool m_addFiles, m_removeFiles; }; diff --git a/src/plugins/General/rdetect/settingsdialog.cpp b/src/plugins/General/rdetect/settingsdialog.cpp new file mode 100644 index 000000000..dbe7b0f5b --- /dev/null +++ b/src/plugins/General/rdetect/settingsdialog.cpp @@ -0,0 +1,55 @@ +/*************************************************************************** + * Copyright (C) 2018 by Ilya Kotov * + * forkotov02@ya.ru * + * * + * 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. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ +#include +#include +#include "settingsdialog.h" + +SettingsDialog::SettingsDialog(QWidget *parent) + : QDialog(parent) +{ + m_ui.setupUi(this); + QSettings settings(Qmmp::configFile(), QSettings::IniFormat); + settings.beginGroup("rdetect"); + m_ui.cdGroupBox->setChecked(settings.value("cda", true).toBool()); + m_ui.addTracksCheckBox->setChecked(settings.value("add_tracks", false).toBool()); + m_ui.removeTracksCheckBox->setChecked(settings.value("remove_tracks", false).toBool()); + m_ui.removableGroupBox->setChecked(settings.value("removable", true).toBool()); + m_ui.addFilesCheckBox->setChecked(settings.value("add_files", false).toBool()); + m_ui.removeFilesCheckBox->setChecked(settings.value("remove_files", false).toBool()); + settings.endGroup(); +} + + +SettingsDialog::~SettingsDialog() +{} + +void SettingsDialog::accept() +{ + QSettings settings(Qmmp::configFile(), QSettings::IniFormat); + settings.beginGroup("rdetect"); + settings.setValue("cda", m_ui.cdGroupBox->isChecked()); + settings.setValue("add_tracks", m_ui.addTracksCheckBox->isChecked()); + settings.setValue("remove_tracks", m_ui.removeTracksCheckBox->isChecked()); + settings.setValue("removable", m_ui.removableGroupBox->isChecked()); + settings.setValue("add_files", m_ui.addFilesCheckBox->isChecked()); + settings.setValue("remove_files", m_ui.removeFilesCheckBox->isChecked()); + settings.endGroup(); + QDialog::accept(); +} diff --git a/src/plugins/General/rdetect/settingsdialog.h b/src/plugins/General/rdetect/settingsdialog.h new file mode 100644 index 000000000..85ab9ed4b --- /dev/null +++ b/src/plugins/General/rdetect/settingsdialog.h @@ -0,0 +1,45 @@ +/*************************************************************************** + * Copyright (C) 2018 by Ilya Kotov * + * forkotov02@ya.ru * + * * + * 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. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ +#ifndef SETTINGSDIALOG_H +#define SETTINGSDIALOG_H + +#include +#include "ui_settingsdialog.h" + +/** + @author Ilya Kotov +*/ +class SettingsDialog : public QDialog +{ +Q_OBJECT +public: + SettingsDialog(QWidget *parent = 0); + + ~SettingsDialog(); + + +public slots: + virtual void accept(); + +private: + Ui::SettingsDialog m_ui; +}; + +#endif diff --git a/src/plugins/General/rdetect/settingsdialog.ui b/src/plugins/General/rdetect/settingsdialog.ui new file mode 100644 index 000000000..d19aa5f35 --- /dev/null +++ b/src/plugins/General/rdetect/settingsdialog.ui @@ -0,0 +1,122 @@ + + + SettingsDialog + + + + 0 + 0 + 348 + 247 + + + + Volume Detection Plugin Settings + + + + 6 + + + 6 + + + 6 + + + + + CD Audio Detection + + + true + + + + + + Add tracks to playlist automatically + + + + + + + Remove tracks from playlist automatically + + + + + + + + + + Removable Device Detection + + + true + + + + + + Add files to playlist automatically + + + + + + + Remove files from playlist automatically + + + + + + + + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + SettingsDialog + accept() + + + 199 + 221 + + + 22 + 242 + + + + + buttonBox + rejected() + SettingsDialog + reject() + + + 247 + 225 + + + 273 + 229 + + + + + -- cgit v1.2.3-13-gbd6f