~ubuntu-branches/ubuntu/trusty/tomahawk/trusty-proposed

« back to all changes in this revision

Viewing changes to src/libtomahawk/ActionCollection.h

  • Committer: Package Import Robot
  • Author(s): Harald Sitter
  • Date: 2013-03-07 21:50:13 UTC
  • Revision ID: package-import@ubuntu.com-20130307215013-6gdjkdds7i9uenvs
Tags: upstream-0.6.0+dfsg
ImportĀ upstreamĀ versionĀ 0.6.0+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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 <QtGui/QAction>
 
27
#include <QtGui/QMenuBar>
 
28
 
 
29
class DLLEXPORT ActionCollection : public QObject
 
30
{
 
31
    Q_OBJECT
 
32
 
 
33
public:
 
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
 
 
90
public slots:
 
91
    void togglePrivateListeningMode();
 
92
 
 
93
signals:
 
94
    void privacyModeChanged();
 
95
 
 
96
private:
 
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