diff options
author | Arno <am@disconnect.de> | 2010-05-14 13:52:30 +0200 |
---|---|---|
committer | Arno <am@disconnect.de> | 2010-05-14 13:52:30 +0200 |
commit | 92c0ab74e931ba8846de50cb0572df94472a40ce (patch) | |
tree | 05feada2ba3b69e241d1607a65a389c40d541c28 | |
parent | 43b98379feb790d695157155324a32cd902ac01b (diff) | |
download | SheMov-92c0ab74e931ba8846de50cb0572df94472a40ce.tar.gz SheMov-92c0ab74e931ba8846de50cb0572df94472a40ce.tar.bz2 SheMov-92c0ab74e931ba8846de50cb0572df94472a40ce.zip |
Added "Play selected" and "Open with" to ArchiveViewWidget
Implemented "Play selected movies" and "Open with" functions in
ArchiveViewWidget.
Also fixed a potential crash when re-creating the "Open with"-submenus.
It's not possible to remove actions from an ActionGroup while iterating
over the group with foreach. The ActionGroup is modified when calling
removeAction() thus throwing the iterator of the loop off.
Solution:
First remove the actions from the ActionGroup and then delete the
ActionGroup itself. The QObject destructor will take care of the
contained Actions.
-rw-r--r-- | archiveviewwidget.cpp | 50 | ||||
-rw-r--r-- | archiveviewwidget.h | 4 | ||||
-rw-r--r-- | shemov.cpp | 101 | ||||
-rw-r--r-- | shemov.h | 18 |
4 files changed, 130 insertions, 43 deletions
diff --git a/archiveviewwidget.cpp b/archiveviewwidget.cpp index 22a51f1..42532c5 100644 --- a/archiveviewwidget.cpp +++ b/archiveviewwidget.cpp @@ -18,6 +18,7 @@ #include <QProcess> #include <QDir> #include <QRegExp> +#include <QHash> #include "archiveviewwidget.h" #include "archivefileview.h" @@ -155,9 +156,9 @@ void ArchiveViewWidget::showMovie(const QModelIndex &movie){ emit statusbarMessage(tr("Movie is not present on filesystem")); return; } - QSettings s; - QString playerPath = s.value("paths/movieviewer").toString(); - QStringList args = s.value("paths/movieviewerargs").toStringList(); + QPair<QString, QStringList> pData = playerData(QString()); + QString playerPath = pData.first; + QStringList args = pData.second; args << real.data(MovieModel::FullPathRole).toString(); QProcess::startDetached(playerPath, args); } @@ -295,6 +296,18 @@ void ArchiveViewWidget::deleteFromArchive(){ } } +void ArchiveViewWidget::playSelected(const QString &player){ + QStringList selectedMovies = selectedFiles(); + if(selectedMovies.isEmpty()){ + return; + } + QPair<QString, QStringList> pData = playerData(player); + QString prog = pData.first; + QStringList args = pData.second; + args << selectedMovies; + QProcess::startDetached(prog, args); +} + void ArchiveViewWidget::rowChanged(const QModelIndex &/*current*/, const QModelIndex & /*prev*/){ QModelIndex idx = getSourceColumnZero(); mWindowTitle = QString(tr("%1 - %2")).arg(qApp->applicationName()).arg(idx.data().toString()); @@ -324,3 +337,34 @@ const QModelIndex ArchiveViewWidget::getSourceColumnZero(){ return retval; } +QPair<QString, QStringList> ArchiveViewWidget::playerData(const QString &preferred){ + QSettings s; + QHash<QString, QVariant> data = s.value("programs_movieviewer/data").toHash(); + if(!preferred.isEmpty()){ + if(data.keys().contains(preferred)){ + QHash<QString, QVariant> pData = data.value(preferred).toHash(); + return qMakePair(pData.value("path").toString(), pData.value("args").toStringList()); + } + return QPair<QString, QStringList>(); + } + QString defaultPlayer = s.value("programs_movieviewer/default").toString(); + if(data.keys().contains(defaultPlayer)){ + QHash<QString, QVariant> pData = data.value(defaultPlayer).toHash(); + return qMakePair(pData.value("path").toString(), pData.value("args").toStringList()); + } + return QPair<QString, QStringList>(); +} + +QStringList ArchiveViewWidget::selectedFiles(){ + QModelIndexList selected = fileView()->selectionModel()->selectedRows(); + if(selected.isEmpty()){ + return QStringList(); + } + QStringList retval; + foreach(QModelIndex idx, selected){ + if(idx.data(MovieModel::DvdRole).toInt() == -1){ + retval << idx.data(MovieModel::FullPathRole).toString(); + } + } + return retval; +} diff --git a/archiveviewwidget.h b/archiveviewwidget.h index 6a9823b..4f56af5 100644 --- a/archiveviewwidget.h +++ b/archiveviewwidget.h @@ -9,6 +9,7 @@ #define ARCHIVEVIEWWIDGET_H #include <QWidget> +#include <QPair> #include "archivefileview.h" @@ -46,6 +47,7 @@ class ArchiveViewWidget : public QWidget { void moveBurn(); void setDvdNo(); void deleteFromArchive(); + void playSelected(const QString &player = QString()); signals: void statusbarMessage(const QString &message); @@ -58,6 +60,8 @@ class ArchiveViewWidget : public QWidget { private: const QModelIndex getSourceColumnZero(); + QPair<QString, QStringList> playerData(const QString &preferred); + QStringList selectedFiles(); QComboBox *mGenre; QComboBox *mActors; QLineEdit *mName; @@ -43,7 +43,7 @@ #include "statisticsdialog.h" #include "filesystemfileproxy.h" -SheMov::SheMov(QWidget *parent, Qt::WindowFlags flags) : QMainWindow(parent, flags) { +SheMov::SheMov(QWidget *parent, Qt::WindowFlags flags) : QMainWindow(parent, flags), mOpenWithGroupFS(0), mOpenWithGroupAV(0) { qApp->setWindowIcon(QIcon(":/shemov.png")); QSettings s; @@ -161,6 +161,8 @@ void SheMov::configure(){ ConfigurationDialog dlg(this); dlg.exec(); createExtractMenu(); + createOpenWithMenuFS(); + createOpenWithMenuAV(); } void SheMov::tabChanged(int newTab){ @@ -258,8 +260,8 @@ void SheMov::createStatusbar(){ void SheMov::createActions(){ //File menu - mPlaySelectedA = new QAction(tr("Play selected movies..."), this); - connect(mPlaySelectedA, SIGNAL(triggered()), mFSWidget, SLOT(playSelected())); + mPlaySelectedFSA = new QAction(tr("Play selected movies..."), this); + connect(mPlaySelectedFSA, SIGNAL(triggered()), mFSWidget, SLOT(playSelected())); mQuitA = new QAction(tr("Quit"), this); mQuitA->setShortcut(tr("CTRL+q")); @@ -324,6 +326,8 @@ void SheMov::createActions(){ createExtractMenu(); //Edit menu (archive) + mPlaySelectedAVA = new QAction(tr("Play selected movies..."), this); + connect(mPlaySelectedAVA, SIGNAL(triggered()), mAVWidget, SLOT(playSelected())); mEditArchiveFileA = new QAction(tr("Edit file..."), this); mEditArchiveFileA->setShortcut(tr("CTRL+e")); connect(mEditArchiveFileA, SIGNAL(triggered()), mAVWidget, SLOT(editFile())); @@ -350,16 +354,17 @@ void SheMov::createActions(){ connect(mStatisticsA, SIGNAL(triggered()), this, SLOT(showStatistics())); // misc - mOpenWithGroup = new QActionGroup(this); - mOpenWithMapper = new QSignalMapper(this); - connect(mOpenWithMapper, SIGNAL(mapped(QString)), mFSWidget, SLOT(playSelected(QString))); + mOpenWithMapperFS = new QSignalMapper(this); + mOpenWithMapperAV = new QSignalMapper(this); + connect(mOpenWithMapperFS, SIGNAL(mapped(QString)), mFSWidget, SLOT(playSelected(QString))); + connect(mOpenWithMapperAV, SIGNAL(mapped(QString)), mAVWidget, SLOT(playSelected(QString))); connect(mFSWidget->dirModel(), SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(setFsFree())); connect(mFSWidget->dirModel(), SIGNAL(layoutChanged()), this, SLOT(setFsFree())); } void SheMov::createMenus(){ QMenu *fileMenu = new QMenu(tr("&File"), this); - fileMenu->addAction(mPlaySelectedA); + fileMenu->addAction(mPlaySelectedFSA); fileMenu->addSeparator(); fileMenu->addAction(mQuitA); mEditFSMenu = new QMenu(tr("&Edit"), this); @@ -412,12 +417,12 @@ void SheMov::createMenus(){ menuBar()->addMenu(helpMenu); // FilesystemWidget context menu - mOpenWithMenu = new QMenu(tr("Open with"), this); - mFSWidget->fileView()->addAction(mPlaySelectedA); - createOpenWithMenu(); - mOpenWithMenuA = new QAction(tr("Open with"), this); - mOpenWithMenuA->setMenu(mOpenWithMenu); - mFSWidget->fileView()->addAction(mOpenWithMenuA); + mOpenWithMenuFS = new QMenu(tr("Open with"), this); + mFSWidget->fileView()->addAction(mPlaySelectedFSA); + createOpenWithMenuFS(); + mOpenWithMenuFSA = new QAction(tr("Open with"), this); + mOpenWithMenuFSA->setMenu(mOpenWithMenuFS); + mFSWidget->fileView()->addAction(mOpenWithMenuFSA); QAction *sep1 = new QAction(this); sep1->setSeparator(true); mFSWidget->fileView()->addAction(sep1); @@ -442,48 +447,76 @@ void SheMov::createMenus(){ mFSWidget->fileView()->addAction(mArchiveA); //ArchiveViewWidget context menu + mOpenWithMenuAV = new QMenu(tr("Open with"), this); + mAVWidget->fileView()->addAction(mPlaySelectedAVA); + createOpenWithMenuAV(); + mOpenWithMenuAVA = new QAction(tr("Open with"), this); + mOpenWithMenuAVA->setMenu(mOpenWithMenuAV); + mAVWidget->fileView()->addAction(mOpenWithMenuAVA); + QAction *sep5 = new QAction(this); + sep5->setSeparator(true); + mAVWidget->fileView()->addAction(sep5); mAVWidget->fileView()->addAction(mEditArchiveFileA); mAVWidget->fileView()->addAction(mEditArchiveCoverA); mAVWidget->fileView()->addAction(mAddMovieManuallyA); mAVWidget->fileView()->addAction(mDeleteFromArchiveA); mAVWidget->fileView()->addAction(mSetDvdA); - QAction *sep5 = new QAction(this); - sep5->setSeparator(true); - mAVWidget->fileView()->addAction(sep5); - mAVWidget->fileView()->addAction(mMoveBurnA); QAction *sep6 = new QAction(this); sep6->setSeparator(true); mAVWidget->fileView()->addAction(sep6); + mAVWidget->fileView()->addAction(mMoveBurnA); + QAction *sep7 = new QAction(this); + sep7->setSeparator(true); + mAVWidget->fileView()->addAction(sep7); mAVWidget->fileView()->addAction(mPropertiesA); } -void SheMov::createOpenWithMenu(){ - foreach(QAction *a, mOpenWithGroup->actions()){ - mOpenWithMenu->removeAction(a); - mOpenWithGroup->removeAction(a); - delete a; +void SheMov::createOpenWithMenuFS(){ + if(mOpenWithGroupFS){ + foreach(QAction *a, mOpenWithGroupFS->actions()){ + mOpenWithMenuFS->removeAction(a); + } } + mOpenWithGroupFS->deleteLater(); + mOpenWithGroupFS = new QActionGroup(this); QSettings s; QStringList moviePlayers = s.value("programs_movieviewer/data").toHash().keys(); moviePlayers.sort(); foreach(QString p, moviePlayers){ - QAction *a = new QAction(p, this); - mOpenWithGroup->addAction(a); - mOpenWithMenu->addAction(a); - mOpenWithMapper->setMapping(a, p); - connect(a, SIGNAL(triggered()), mOpenWithMapper, SLOT(map())); + QAction *a = new QAction(p, mOpenWithGroupFS); + mOpenWithMenuFS->addAction(a); + mOpenWithMapperFS->setMapping(a, p); + connect(a, SIGNAL(triggered()), mOpenWithMapperFS, SLOT(map())); } - QAction *sep = new QAction(this); + QAction *sep = new QAction(mOpenWithGroupFS); sep->setSeparator(true); - mOpenWithMenu->addAction(sep); + mOpenWithMenuFS->addAction(sep); QStringList picViewers = s.value("programs_pictureviewer/data").toHash().keys(); picViewers.sort(); foreach(QString p, picViewers){ - QAction *a = new QAction(p, this); - mOpenWithGroup->addAction(a); - mOpenWithMenu->addAction(a); - mOpenWithMapper->setMapping(a, p); - connect(a, SIGNAL(triggered()), mOpenWithMapper, SLOT(map())); + QAction *a = new QAction(p, mOpenWithGroupFS); + mOpenWithMenuFS->addAction(a); + mOpenWithMapperFS->setMapping(a, p); + connect(a, SIGNAL(triggered()), mOpenWithMapperFS, SLOT(map())); + } +} + +void SheMov::createOpenWithMenuAV(){ + if(mOpenWithGroupAV){ + foreach(QAction *a, mOpenWithGroupAV->actions()){ + mOpenWithMenuAV->removeAction(a); + } + } + //this deletes all actions in the group also! + mOpenWithGroupAV->deleteLater(); + mOpenWithGroupAV = new QActionGroup(this); + QSettings s; + QStringList players = s.value("programs_movieviewer/data").toHash().keys(); + foreach(QString p, players){ + QAction *a = new QAction(p, mOpenWithGroupAV); + mOpenWithMenuAV->addAction(a); + mOpenWithMapperAV->setMapping(a, p); + connect(a, SIGNAL(triggered()), mOpenWithMapperAV, SLOT(map())); } } @@ -51,7 +51,8 @@ class SheMov : public QMainWindow { void createStatusbar(); void createActions(); void createMenus(); - void createOpenWithMenu(); + void createOpenWithMenuFS(); + void createOpenWithMenuAV(); void createExtractMenu(); void writeSettings(); void readSettings(); @@ -89,21 +90,26 @@ class SheMov : public QMainWindow { QAction *mAboutShemovA; QAction *mAboutQtA; QAction *mStatisticsA; - QAction *mPlaySelectedA; - QAction *mOpenWithMenuA; + QAction *mPlaySelectedFSA; + QAction *mPlaySelectedAVA; + QAction *mOpenWithMenuFSA; + QAction *mOpenWithMenuAVA; QAction *mRenameMenuA; QList<QAction*> mExtractToA; - QActionGroup *mOpenWithGroup; + QActionGroup *mOpenWithGroupFS; + QActionGroup *mOpenWithGroupAV; //EndActions QSignalMapper *mRenameMapper; QSignalMapper *mExtractMapper; - QSignalMapper *mOpenWithMapper; + QSignalMapper *mOpenWithMapperFS; + QSignalMapper *mOpenWithMapperAV; QMenu *mExtractMenu; QMenu *mEditFSMenu; QMenu *mEditArchiveMenu; - QMenu *mOpenWithMenu; + QMenu *mOpenWithMenuFS; + QMenu *mOpenWithMenuAV; QMenu *mRenameMenu; QAction *mEditFSMenuA; QAction *mEditArchiveMenuA; |