aboutsummaryrefslogtreecommitdiff
path: root/src/plugins/General/rdetect/removablehelper.cpp
diff options
context:
space:
mode:
authortrialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38>2018-12-01 21:38:21 +0000
committertrialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38>2018-12-01 21:38:21 +0000
commit366eb153e82063a1157695e6c0873a7a64bee3af (patch)
tree5b672b76cdace7182175696a17538d02d79cba7e /src/plugins/General/rdetect/removablehelper.cpp
parent7bdd84eec98430e71a4a73fe46561a20d1dc75e3 (diff)
downloadqmmp-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/General/rdetect/removablehelper.cpp')
-rw-r--r--src/plugins/General/rdetect/removablehelper.cpp59
1 files changed, 58 insertions, 1 deletions
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;
+ }
+}
+