aboutsummaryrefslogtreecommitdiff
path: root/src/plugins/General/fileops/fileops.cpp
diff options
context:
space:
mode:
authortrialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38>2009-05-09 19:22:00 +0000
committertrialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38>2009-05-09 19:22:00 +0000
commit08de867fc96c121b518523fb2e832f9c80539f01 (patch)
tree49b05a4382c610ef1360fab89144cc857e1014a2 /src/plugins/General/fileops/fileops.cpp
parent5c583bfdd4a74273576867191d0145227a5d63d7 (diff)
downloadqmmp-08de867fc96c121b518523fb2e832f9c80539f01.tar.gz
qmmp-08de867fc96c121b518523fb2e832f9c80539f01.tar.bz2
qmmp-08de867fc96c121b518523fb2e832f9c80539f01.zip
updated fileops plugin, fixed file dialog bugs
git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@934 90c681e8-e032-0410-971d-27865f9a5e38
Diffstat (limited to 'src/plugins/General/fileops/fileops.cpp')
-rw-r--r--src/plugins/General/fileops/fileops.cpp104
1 files changed, 97 insertions, 7 deletions
diff --git a/src/plugins/General/fileops/fileops.cpp b/src/plugins/General/fileops/fileops.cpp
index 86122b127..3bb32b1e4 100644
--- a/src/plugins/General/fileops/fileops.cpp
+++ b/src/plugins/General/fileops/fileops.cpp
@@ -19,7 +19,12 @@
***************************************************************************/
#include <QAction>
+#include <QSettings>
#include <QApplication>
+#include <QSignalMapper>
+#include <QProgressDialog>
+#include <QMessageBox>
+#include <QFile>
#include <qmmp/soundcore.h>
#include <qmmpui/generalhandler.h>
@@ -28,25 +33,110 @@
#include <qmmpui/mediaplayer.h>
#include "fileops.h"
+#define COPY_BLOCK_SIZE 102400
+
FileOps::FileOps(QObject *parent)
: General(parent)
{
- m_copyAction = new QAction(tr("Copy"), this);
- m_moveAction = new QAction(tr("Move"), this);
- m_removeAction = new QAction(tr("Remove"), this);
//separators
QAction *separator1 = new QAction(this);
separator1->setSeparator (TRUE);
QAction *separator2 = new QAction(this);
separator2->setSeparator (TRUE);
+ //load settings
+ QSignalMapper *mapper = new QSignalMapper(this);
+ QSettings settings(Qmmp::configFile(), QSettings::IniFormat);
+ settings.beginGroup("FileOps");
+ int count = settings.value("count", 0).toInt();
+ if (count > 0)
+ GeneralHandler::instance()->addAction(separator1, GeneralHandler::PLAYLIST_MENU);
+ else
+ return;
+
+ for (int i = 0; i < count; ++i)
+ {
- GeneralHandler::instance()->addAction(separator1, GeneralHandler::PLAYLIST_MENU);
- GeneralHandler::instance()->addAction(m_copyAction, GeneralHandler::PLAYLIST_MENU);
- GeneralHandler::instance()->addAction(m_moveAction, GeneralHandler::PLAYLIST_MENU);
- GeneralHandler::instance()->addAction(m_removeAction, GeneralHandler::PLAYLIST_MENU);
+ if (settings.value(QString("enabled_%1").arg(i), TRUE).toBool())
+ {
+ m_types << settings.value(QString("action_%1").arg(i), FileOps::COPY).toInt();
+ QString name = settings.value(QString("name_%1").arg(i), "Action").toString();
+ m_patterns << settings.value(QString("pattern_%1").arg(i)).toString();
+ m_destinations << settings.value(QString("destination_%1").arg(i)).toString();
+ QAction *action = new QAction(name, this);
+ connect (action, SIGNAL (triggered (bool)), mapper, SLOT (map()));
+ mapper->setMapping(action, i);
+ GeneralHandler::instance()->addAction(action, GeneralHandler::PLAYLIST_MENU);
+ }
+ }
+ settings.endGroup();
+ connect(mapper, SIGNAL(mapped(int)), SLOT(execAction(int)));
GeneralHandler::instance()->addAction(separator2, GeneralHandler::PLAYLIST_MENU);
}
FileOps::~FileOps()
{}
+void FileOps::execAction(int n)
+{
+ int type = m_types.at(n);
+ QString pattern = m_patterns.at(n);
+ QString destination = m_destinations.at(n);
+
+ PlayListModel *model = MediaPlayer::instance()->playListModel();
+ QList<PlayListItem*> items = model->getSelectedItems();
+
+ switch (type)
+ {
+ case COPY:
+ {
+ QProgressDialog progress(qApp->activeWindow ());
+ progress.setWindowModality(Qt::WindowModal);
+ progress.setWindowTitle(tr("Copying"));
+ progress.setCancelButtonText(tr("Stop"));
+ progress.show();
+ progress.setAutoClose (FALSE);
+ int i = 0;
+ foreach(PlayListItem *item, items)
+ {
+ if (!QFile::exists(item->url()))
+ continue;
+
+ QFile in(item->url());
+ QFile out(destination + "/" + pattern);
+ in.open(QIODevice::ReadOnly);
+ out.open(QIODevice::WriteOnly);
+
+ progress.setMaximum(int(in.size()/COPY_BLOCK_SIZE));
+ progress.setValue(0);
+ progress.setLabelText (QString(tr("Copying file %1/%2")).arg(++i).arg(items.size()));
+ progress.update();
+
+ while (!in.atEnd ())
+ {
+ progress.wasCanceled ();
+ out.write(in.read(COPY_BLOCK_SIZE));
+ progress.setValue(int(out.size()/COPY_BLOCK_SIZE));
+ qApp->processEvents();
+ }
+ }
+ progress.close();
+ break;
+ }
+ case RENAME:
+ break;
+ case MOVE:
+ break;
+ case REMOVE:
+ if (QMessageBox::question (qApp->activeWindow (), tr("Remove files"),
+ QString(tr("Are you sure you want to remove %1 file(s) from disk"))
+ .arg(items.size()),
+ QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes)
+ break;
+
+ foreach(PlayListItem *item, items)
+ {
+ if (QFile::exists(item->url()) && QFile::remove(item->url()))
+ model->removeAt (model->row(item));
+ }
+ }
+}