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 /shemov.cpp | |
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.
Diffstat (limited to 'shemov.cpp')
-rw-r--r-- | shemov.cpp | 101 |
1 files changed, 67 insertions, 34 deletions
@@ -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())); } } |