/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. #ifndef TOMAHAWKACTIONCOLLECTION_H
  21. #define TOMAHAWKACTIONCOLLECTION_H
  22. #include "DllMacro.h"
  23. #include <QAction>
  24. #include <QMenuBar>
  25. class DLLEXPORT ActionCollection : public QObject
  26. {
  27. Q_OBJECT
  28. public:
  29. // Categories for custom-registered actions
  30. enum ActionDestination {
  31. // Tracks, TODO
  32. LocalPlaylists = 0
  33. };
  34. static ActionCollection* instance();
  35. ActionCollection( QObject* parent );
  36. ~ActionCollection();
  37. void initActions();
  38. /**
  39. * This method returns a main menu bar, suitable for Windows, Mac and X11.
  40. */
  41. QMenuBar* createMenuBar( QWidget* parent );
  42. /**
  43. * Returns a QMenu with all the entries that would normally be in the main menu,
  44. * arranged in a sensible way. The compressed menu makes absolutely no sense on Mac,
  45. * and fairly little sense on Unity and other X11 desktop configurations which pull
  46. * out the menu bar from the window.
  47. */
  48. QMenu* createCompactMenu( QWidget* parent );
  49. QAction* getAction( const QString& name );
  50. QList< QAction* > getAction( ActionDestination category );
  51. QObject* actionNotifier( QAction* );
  52. /**
  53. * Add an action for a specific category. The action will show up
  54. * where the relevant category is displayed.
  55. *
  56. * e.g. if you register a Playlist action, it will be shown when
  57. * there is a context menu shown for a playlist.
  58. *
  59. * When the QAction* is shown, it will have a "payload" property that is set
  60. * to the <specific type> that is being shown.
  61. *
  62. * Additionally you can pass a QObject* that will be notified before the given
  63. * action is shown. The slot "aboutToShow( QAction*, <specific type> ) will be called,
  64. *
  65. *
  66. * <specific type> corresponds to the category: playlist_ptr for Playlists, etc.
  67. *
  68. * The Action Collection takes ownership of the action. It's time to let go.
  69. */
  70. void addAction( ActionDestination category, QAction* action, QObject* notify = 0 );
  71. /**
  72. * Remove an action from one or all specific categories
  73. */
  74. void removeAction( QAction* action );
  75. void removeAction( QAction* action, ActionDestination category );
  76. public slots:
  77. void togglePrivateListeningMode();
  78. signals:
  79. void privacyModeChanged();
  80. private:
  81. static ActionCollection* s_instance;
  82. QHash< QString, QAction* > m_actionCollection;
  83. QHash< ActionDestination, QList< QAction* > > m_categoryActions;
  84. QHash< QAction*, QObject* > m_actionNotifiers;
  85. };
  86. #endif