[quarkplayer] r1435 committed - Remove circular dependency between MainWindow plugin and Playlist plug...

0 views
Skip to first unread message

quark...@googlecode.com

unread,
Feb 24, 2011, 1:34:45 PM2/24/11
to quarkplay...@googlegroups.com
Revision: 1435
Author: tkrotoff
Date: Thu Feb 24 10:33:59 2011
Log: Remove circular dependency between MainWindow plugin and Playlist
plugin
http://code.google.com/p/quarkplayer/source/detail?r=1435

Modified:
/trunk/libs/TkUtil/ActionCollection.h
/trunk/quarkplayer-plugins/FileBrowser/FileBrowserTreeView.cpp
/trunk/quarkplayer-plugins/MainWindow/CMakeLists.txt
/trunk/quarkplayer-plugins/MainWindow/MainWindow.cpp
/trunk/quarkplayer-plugins/MainWindow/MainWindow.h
/trunk/quarkplayer-plugins/MediaController/MediaController.cpp
/trunk/quarkplayer-plugins/Playlist/PlaylistModel.h
/trunk/quarkplayer-plugins/Playlist/PlaylistWidget.cpp
/trunk/quarkplayer-plugins/Playlist/PlaylistWidget.h

=======================================
--- /trunk/libs/TkUtil/ActionCollection.h Wed Feb 23 18:38:25 2011
+++ /trunk/libs/TkUtil/ActionCollection.h Thu Feb 24 10:33:59 2011
@@ -1,6 +1,6 @@
/*
* QuarkPlayer, a Phonon media player
- * Copyright (C) 2008-2010 Tanguy Krotoff <tkro...@gmail.com>
+ * Copyright (C) 2008-2011 Tanguy Krotoff <tkro...@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
published by
@@ -29,14 +29,33 @@
struct QUuid;

/**
- * Contains all QuarkPlayer' QActions.
+ * A QActions container.
*
* This is code factorization, idea is to not duplicate QAction.
* QAction are defined once (with translation, icon...) and used
* everywhere via this class.
*
+ * There are two types of QAction:
+ *
+ * - Actions that are global
+ * Like play, pause, stop...
+ * These actions should not be duplicated and should call the same callback
+ * They must be added to the global/master ActionCollection (see
GlobalActionCollection)
+ *
+ * - Actions that are local
+ * When duplicated they should call different callbacks
+ * They should be added to a "local" ActionCollection that will be die
+ * when the widget that contains the actions is deleted
+ *
* Checks are done at runtime.
*
+ * Every ActionCollection object created is automatically registered to
+ * the global/master ActionCollection thus all QActions from every
ActionCollection
+ * can be easily retrieved.
+ *
+ * ActionCollection from KDE was a source of inspiration
+ * @see
http://api.kde.org/4.x-api/kdelibs-apidocs/kross/html/classKross_1_1ActionCollection.html
+ *
* @author Tanguy Krotoff
*/
class TKUTIL_API ActionCollection {
@@ -69,35 +88,57 @@


/**
- * Global variable ActionCollection.
+ * Global/master ActionCollection.
+ *
+ * Contains every ActionCollection object + contains the global/master
ActionCollection.
*
* Singleton Pattern.
+ *
+ * Should we split this class in two?
+ * One named ActionCollectionList that registers all the local
ActionCollections
+ * and one named MasterActionCollection that is used for global QActions?
+ *
+ * @see ActionCollection
+ * @author Tanguy Krotoff
*/
class TKUTIL_API GlobalActionCollection : public Singleton {
friend class ActionCollection;
public:

+ /** Singleton. */
static GlobalActionCollection & instance();

+ /** Gets the global/master ActionCollection. */
static ActionCollection & collection();

/**
* Gets all the QAction from all ActionCollection.
- *
- * Implementation removes all duplicated QAction (QAction with the same
names).
*/
QList<QAction *> allActions() const;

private:

+ /** Registers a ActionCollection. */
void registerCollection(ActionCollection * collection);

+ /** Unregisters a ActionCollection. */
void unregisterCollection(ActionCollection * collection);

+ /** The list of all ActionCollection. */
QList<ActionCollection *> _collections;
};

-/** Simplify the syntax. */
+/**
+ * Macro that simplifies the syntax.
+ *
+ * Gets the global/master ActionCollection.
+ *
+ * Instead of writing
<pre>GlobalActionCollection::collection()["MyQActionName"]</pre>
+ * You just have to write <pre>Actions["MyQActionName"]</pre>
+ *
+ * @see GlobalActionCollection
+ * @see ActionCollection
+ */
#define Actions GlobalActionCollection::collection()

#endif //ACTIONCOLLECTION_H
=======================================
--- /trunk/quarkplayer-plugins/FileBrowser/FileBrowserTreeView.cpp Wed Feb
23 10:23:21 2011
+++ /trunk/quarkplayer-plugins/FileBrowser/FileBrowserTreeView.cpp Thu Feb
24 10:33:59 2011
@@ -108,15 +108,15 @@
}

void FileBrowserTreeView::addToPlaylist() {
- QStringList filenames;
+ QStringList files;
QModelIndexList indexList = selectionModel()->selectedRows();
foreach (QModelIndex index, indexList) {
QFileInfo fileInfo(this->fileInfo(index));
//Sometimes, QFileInfo gives us this pattern: C://... that MPlayer does
not accept
- filenames += fileInfo.absoluteFilePath().replace("//", "/");
- }
- if (!filenames.isEmpty()) {
-
PlaylistWidgetFactory::playlistWidget()->addFilesToCurrentPlaylist(filenames);
+ files += fileInfo.absoluteFilePath().replace("//", "/");
+ }
+ if (!files.isEmpty()) {
+ PlaylistWidgetFactory::playlistWidget()->addFilesToPlaylist(files);
}
}

=======================================
--- /trunk/quarkplayer-plugins/MainWindow/CMakeLists.txt Wed Feb 23
10:23:21 2011
+++ /trunk/quarkplayer-plugins/MainWindow/CMakeLists.txt Thu Feb 24
10:33:59 2011
@@ -68,8 +68,6 @@

QuarkPlayerCore

- Playlist
-
${QTSINGLEAPPLICATION_LIBRARIES}

${QT_QTCORE_LIBRARY}
=======================================
--- /trunk/quarkplayer-plugins/MainWindow/MainWindow.cpp Wed Feb 23
18:38:25 2011
+++ /trunk/quarkplayer-plugins/MainWindow/MainWindow.cpp Thu Feb 24
10:33:59 2011
@@ -27,9 +27,6 @@
#include <quarkplayer/config/Config.h>
#include <quarkplayer/version.h>

-#include <quarkplayer-plugins/Playlist/PlaylistWidget.h>
-#include <quarkplayer-plugins/Playlist/PlaylistModel.h>
-
#include <Logger/LogWindow.h>

#include <TkUtil/ActionCollection.h>
@@ -171,16 +168,12 @@
);

if (!fileNames.isEmpty()) {
- QString fileToPlay(fileNames[0]);
- Config::instance().setValue(Config::LAST_DIR_OPENED_KEY,
QFileInfo(fileToPlay).absolutePath());
-
- PlaylistWidget * playlistWidget =
PlaylistWidgetFactory::playlistWidget();
- if (playlistWidget) {
- playlistWidget->addFilesToCurrentPlaylist(fileNames);
- playlistWidget->playlistModel()->play(0);
- } else {
- play(fileToPlay);
- }
+ QString file(fileNames[0]);
+ Config::instance().setValue(Config::LAST_DIR_OPENED_KEY,
QFileInfo(file).absolutePath());
+
+ play(file);
+
+ emit filesOpened(fileNames);
}
}

=======================================
--- /trunk/quarkplayer-plugins/MainWindow/MainWindow.h Tue Feb 22 16:25:52
2011
+++ /trunk/quarkplayer-plugins/MainWindow/MainWindow.h Thu Feb 24 10:33:59
2011
@@ -76,20 +76,16 @@
signals:

/**
- * A subtitle file has been dropped inside the main window.
+ * A subtitle file has been dropped by the user inside the main window.
*/
- void subtitleFileDropped(const QString & subtitle);
+ void subtitleFileDropped(const QString & fileName);

/**
- * The play toolbar has been added to the main window.
+ * Several files have been opened by the user.
*
- * Specific to the PlayToolBar plugin.
- *
- * @see setPlayToolBar()
- * @see PlayToolBar
- * @param playToolBar main window play toolbar (cannot be NULL or there
is a bug...)
+ * The first file from the list is already being played.
*/
- void playToolBarAdded(QToolBar * playToolBar);
+ void filesOpened(const QStringList & files);

/**
* The status bar has been added to the main window.
=======================================
--- /trunk/quarkplayer-plugins/MediaController/MediaController.cpp Wed Feb
23 18:38:25 2011
+++ /trunk/quarkplayer-plugins/MediaController/MediaController.cpp Thu Feb
24 10:33:59 2011
@@ -421,7 +421,7 @@
//if (discType == Phonon::Dvd
// &&

- //HACK this is a hack in order to add titles to the playlist
+ //FIXME HACK this is a hack in order to add titles to the playlist
//Yes MPlayer demands a lot of hacks :/
static QRegExp rx_dvd("^dvd://(\\d+)$");

@@ -430,7 +430,7 @@
files += "internal=dvd://" + QString::number(i);
}
PlaylistWidget * playlistWidget = PlaylistWidgetFactory::playlistWidget();
- playlistWidget->addFilesToCurrentPlaylist(files);
+ playlistWidget->addFilesToPlaylist(files);
///
}

=======================================
--- /trunk/quarkplayer-plugins/Playlist/PlaylistModel.h Tue Feb 22 16:25:52
2011
+++ /trunk/quarkplayer-plugins/Playlist/PlaylistModel.h Thu Feb 24 10:33:59
2011
@@ -112,7 +112,11 @@
/** Gets the current item position inside the model. */
int position() const;

- /** Returns the files inside the playlist. */
+ /**
+ * Returns the files inside the playlist.
+ *
+ * The number of files is equal to the number of rows inside the playlist.
+ */
const QList<MediaInfo> & files() const;

/**
=======================================
--- /trunk/quarkplayer-plugins/Playlist/PlaylistWidget.cpp Wed Feb 23
18:38:25 2011
+++ /trunk/quarkplayer-plugins/Playlist/PlaylistWidget.cpp Thu Feb 24
10:33:59 2011
@@ -76,6 +76,8 @@

Q_ASSERT(mainWindow);
_mainWindow = mainWindow;
+ connect(_mainWindow, SIGNAL(filesOpened(const QStringList &)),
+ SLOT(filesOpenedByMainWindow(const QStringList &)));

//Model
_playlistModel = new PlaylistModel(quarkPlayer, uuid, this);
@@ -295,11 +297,18 @@
if (!files.isEmpty()) {
Config::instance().setValue(Config::LAST_DIR_OPENED_KEY,
QFileInfo(files[0]).absolutePath());

- addFilesToCurrentPlaylist(files);
+ addFilesToPlaylist(files);
}
}

-void PlaylistWidget::addFilesToCurrentPlaylist(const QStringList & files) {
+void PlaylistWidget::filesOpenedByMainWindow(const QStringList & files) {
+ int position = _playlistModel->files().count();
+ addFilesToPlaylist(files);
+ _playlistModel->setPosition(position);
+ jumpToCurrent();
+}
+
+void PlaylistWidget::addFilesToPlaylist(const QStringList & files) {
if (!files.isEmpty()) {
if (PlaylistConfig::instance().activePlaylist() == uuid()) {
_playlistModel->addFiles(files);
=======================================
--- /trunk/quarkplayer-plugins/Playlist/PlaylistWidget.h Wed Feb 23
18:38:25 2011
+++ /trunk/quarkplayer-plugins/Playlist/PlaylistWidget.h Thu Feb 24
10:33:59 2011
@@ -73,14 +73,12 @@

PlaylistFilter * playlistFilter() const;

-public slots:
-
/**
- * Adds a list of files to the current playlist.
+ * Adds a list of files to the playlist.
*
- * @param files files to add to the current playlist
+ * @param files files to add to the playlist
*/
- void addFilesToCurrentPlaylist(const QStringList & files);
+ void addFilesToPlaylist(const QStringList & files);

private slots:

@@ -122,6 +120,11 @@

void activePlaylistChanged(const QUuid & uuid);

+ /**
+ * Some files have been opened by the user inside the main window.
+ */
+ void filesOpenedByMainWindow(const QStringList &);
+
private:

void populateActionCollection();

Reply all
Reply to author
Forward
0 new messages