diff options
| author | trialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38> | 2018-12-01 21:38:21 +0000 |
|---|---|---|
| committer | trialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38> | 2018-12-01 21:38:21 +0000 |
| commit | 366eb153e82063a1157695e6c0873a7a64bee3af (patch) | |
| tree | 5b672b76cdace7182175696a17538d02d79cba7e /src/plugins | |
| parent | 7bdd84eec98430e71a4a73fe46561a20d1dc75e3 (diff) | |
| download | qmmp-366eb153e82063a1157695e6c0873a7a64bee3af.tar.gz qmmp-366eb153e82063a1157695e6c0873a7a64bee3af.tar.bz2 qmmp-366eb153e82063a1157695e6c0873a7a64bee3af.zip | |
rdetect: added settings dialog
git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@8471 90c681e8-e032-0410-971d-27865f9a5e38
Diffstat (limited to 'src/plugins')
| -rw-r--r-- | src/plugins/General/rdetect/rdetect.pro | 10 | ||||
| -rw-r--r-- | src/plugins/General/rdetect/rdetectfactory.cpp | 6 | ||||
| -rw-r--r-- | src/plugins/General/rdetect/removablehelper.cpp | 59 | ||||
| -rw-r--r-- | src/plugins/General/rdetect/removablehelper.h | 7 | ||||
| -rw-r--r-- | src/plugins/General/rdetect/settingsdialog.cpp | 55 | ||||
| -rw-r--r-- | src/plugins/General/rdetect/settingsdialog.h | 45 | ||||
| -rw-r--r-- | src/plugins/General/rdetect/settingsdialog.ui | 122 |
7 files changed, 298 insertions, 6 deletions
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 <QMessageBox> #include <qmmp/qmmp.h> +#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 <QActionGroup>
#include <QtDebug>
#include <QStyle>
+#include <QSettings>
#include <qmmpui/playlistmanager.h>
#include <windows.h>
#include <dbt.h>
@@ -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<PlayListTrack *>(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 <QSettings> +#include <qmmp/qmmp.h> +#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 <QDialog> +#include "ui_settingsdialog.h" + +/** + @author Ilya Kotov <forkotov02@ya.ru> +*/ +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 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>SettingsDialog</class> + <widget class="QDialog" name="SettingsDialog"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>348</width> + <height>247</height> + </rect> + </property> + <property name="windowTitle"> + <string>Volume Detection Plugin Settings</string> + </property> + <layout class="QVBoxLayout" name="verticalLayout_3"> + <property name="leftMargin"> + <number>6</number> + </property> + <property name="rightMargin"> + <number>6</number> + </property> + <property name="bottomMargin"> + <number>6</number> + </property> + <item> + <widget class="QGroupBox" name="cdGroupBox"> + <property name="title"> + <string>CD Audio Detection</string> + </property> + <property name="checkable"> + <bool>true</bool> + </property> + <layout class="QVBoxLayout" name="verticalLayout_2"> + <item> + <widget class="QCheckBox" name="addTracksCheckBox"> + <property name="text"> + <string>Add tracks to playlist automatically</string> + </property> + </widget> + </item> + <item> + <widget class="QCheckBox" name="removeTracksCheckBox"> + <property name="text"> + <string>Remove tracks from playlist automatically</string> + </property> + </widget> + </item> + </layout> + </widget> + </item> + <item> + <widget class="QGroupBox" name="removableGroupBox"> + <property name="title"> + <string>Removable Device Detection</string> + </property> + <property name="checkable"> + <bool>true</bool> + </property> + <layout class="QVBoxLayout" name="verticalLayout"> + <item> + <widget class="QCheckBox" name="addFilesCheckBox"> + <property name="text"> + <string>Add files to playlist automatically</string> + </property> + </widget> + </item> + <item> + <widget class="QCheckBox" name="removeFilesCheckBox"> + <property name="text"> + <string>Remove files from playlist automatically</string> + </property> + </widget> + </item> + </layout> + </widget> + </item> + <item> + <widget class="QDialogButtonBox" name="buttonBox"> + <property name="standardButtons"> + <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set> + </property> + </widget> + </item> + </layout> + </widget> + <resources/> + <connections> + <connection> + <sender>buttonBox</sender> + <signal>accepted()</signal> + <receiver>SettingsDialog</receiver> + <slot>accept()</slot> + <hints> + <hint type="sourcelabel"> + <x>199</x> + <y>221</y> + </hint> + <hint type="destinationlabel"> + <x>22</x> + <y>242</y> + </hint> + </hints> + </connection> + <connection> + <sender>buttonBox</sender> + <signal>rejected()</signal> + <receiver>SettingsDialog</receiver> + <slot>reject()</slot> + <hints> + <hint type="sourcelabel"> + <x>247</x> + <y>225</y> + </hint> + <hint type="destinationlabel"> + <x>273</x> + <y>229</y> + </hint> + </hints> + </connection> + </connections> +</ui> |
