PageRenderTime 102ms CodeModel.GetById 40ms app.highlight 4ms RepoModel.GetById 56ms app.codeStats 0ms

/src/libtomahawk/ActionCollection.h

http://github.com/tomahawk-player/tomahawk
C Header | 104 lines | 35 code | 18 blank | 51 comment | 0 complexity | 0551dc34b8028e1c5cdd42ed991fe35c MD5 | raw file
  1/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
  2 *
  3 *   Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org
  4 *   Copyright 2010-2012, Jeff Mitchell <jeff@tomahawk-player.org>>
  5 *   Copyright 2012,      Leo Franchi   <lfranchi@kde.org>
  6 *
  7 *   Tomahawk is free software: you can redistribute it and/or modify
  8 *   it under the terms of the GNU General Public License as published by
  9 *   the Free Software Foundation, either version 3 of the License, or
 10 *   (at your option) any later version.
 11 *
 12 *   Tomahawk is distributed in the hope that it will be useful,
 13 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 14 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 15 *   GNU General Public License for more details.
 16 *
 17 *   You should have received a copy of the GNU General Public License
 18 *   along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
 19 */
 20
 21#ifndef TOMAHAWKACTIONCOLLECTION_H
 22#define TOMAHAWKACTIONCOLLECTION_H
 23
 24#include "DllMacro.h"
 25
 26#include <QAction>
 27#include <QMenuBar>
 28
 29class DLLEXPORT ActionCollection : public QObject
 30{
 31    Q_OBJECT
 32
 33public:
 34    // Categories for custom-registered actions
 35    enum ActionDestination {
 36//         Tracks, TODO
 37        LocalPlaylists = 0
 38    };
 39
 40    static ActionCollection* instance();
 41
 42    ActionCollection( QObject* parent );
 43    ~ActionCollection();
 44
 45    void initActions();
 46
 47    /**
 48     * This method returns a main menu bar, suitable for Windows, Mac and X11.
 49     */
 50    QMenuBar* createMenuBar( QWidget* parent );
 51
 52    /**
 53     * Returns a QMenu with all the entries that would normally be in the main menu,
 54     * arranged in a sensible way. The compressed menu makes absolutely no sense on Mac,
 55     * and fairly little sense on Unity and other X11 desktop configurations which pull
 56     * out the menu bar from the window.
 57     */
 58    QMenu* createCompactMenu( QWidget* parent );
 59
 60    QAction* getAction( const QString& name );
 61    QList< QAction* > getAction( ActionDestination category );
 62    QObject* actionNotifier( QAction* );
 63
 64    /**
 65     * Add an action for a specific category. The action will show up
 66     *  where the relevant category is displayed.
 67     *
 68     *  e.g. if you register a Playlist action, it will be shown when
 69     *       there is a context menu shown for a playlist.
 70     *
 71     * When the QAction* is shown, it will have a "payload" property that is set
 72     *  to the <specific type> that is being shown.
 73     *
 74     * Additionally you can pass a QObject* that will be notified before the given
 75     *  action is shown. The slot "aboutToShow( QAction*, <specific type> ) will be called,
 76     *
 77     *
 78     * <specific type> corresponds to the category: playlist_ptr for Playlists, etc.
 79     *
 80     * The Action Collection takes ownership of the action. It's time to let go.
 81     */
 82    void addAction( ActionDestination category, QAction* action, QObject* notify = 0 );
 83
 84    /**
 85     * Remove an action from one or all specific categories
 86     */
 87    void removeAction( QAction* action );
 88    void removeAction( QAction* action, ActionDestination category );
 89
 90public slots:
 91    void togglePrivateListeningMode();
 92
 93signals:
 94    void privacyModeChanged();
 95
 96private:
 97    static ActionCollection* s_instance;
 98
 99    QHash< QString, QAction* > m_actionCollection;
100    QHash< ActionDestination, QList< QAction* > > m_categoryActions;
101    QHash< QAction*, QObject* > m_actionNotifiers;
102};
103
104#endif