Qmmp
uihelper.h
1 /***************************************************************************
2  * Copyright (C) 2008-2022 by Ilya Kotov *
3  * forkotov02@ya.ru *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
19  ***************************************************************************/
20 #ifndef UIHELPER_H
21 #define UIHELPER_H
22 
23 #include <QObject>
24 #include <QMap>
25 #include <QList>
26 #include <QPointer>
27 #include <QStringList>
28 #include <QApplication>
29 #include <QPointer>
30 #include "playlistmanager.h"
31 #include "playlistmodel.h"
32 #include "qmmpui_export.h"
33 
34 class QAction;
35 class QMenu;
36 class QWidget;
37 class General;
38 class GeneralFactory;
39 class JumpToTrackDialog;
40 
44 class QMMPUI_EXPORT UiHelper : public QObject
45 {
46  Q_OBJECT
47 public:
52  UiHelper(QObject *parent = nullptr);
60  enum MenuType
61  {
62  TOOLS_MENU = 0,
64  ADD_MENU
65  };
76  void addAction(QAction *action, MenuType type = TOOLS_MENU);
80  void removeAction(QAction *action);
84  QList<QAction *> actions(MenuType type = TOOLS_MENU);
92  QMenu *createMenu(MenuType type, const QString &title = QString(), bool autoHide = true, QWidget *parent = nullptr);
100  void registerMenu(MenuType type, QMenu *menu, bool autoHide = false, QAction *before = nullptr);
106  void addFiles(QWidget *parent = qApp->activeWindow(),
113  void playFiles(QWidget *parent = qApp->activeWindow(),
120  void addDirectory(QWidget *parent = qApp->activeWindow(),
127  void addUrl(QWidget *parent = qApp->activeWindow(),
134  void loadPlayList(QWidget *parent = qApp->activeWindow(),
141  void savePlayList(QWidget *parent = qApp->activeWindow(),
148  void jumpToTrack(QWidget *parent = qApp->activeWindow(),
154  void about(QWidget *parent = nullptr);
158  static UiHelper* instance();
159 
160 public slots:
172  void exit();
173 
174 signals:
189  void widgetAdded(const QString &id);
194  void widgetRemoved(const QString &id);
199  void widgetUpdated(const QString &id);
200 
201 private slots:
202  void removeAction(QObject *action);
203  void addSelectedFiles(const QStringList &files, bool play);
204  void playSelectedFiles(const QStringList &files);
205  void disconnectPl();
206 
207 private:
208  QMap <GeneralFactory*, General*> m_generals;
209  struct MenuData
210  {
211  QPointer<QMenu> menu;
212  QPointer<QAction> before;
213  QList<QAction*> actions;
214  bool autoHide = false;
215  };
216  QMap<MenuType, MenuData> m_menus;
217  QString m_lastDir;
218  QPointer <JumpToTrackDialog> m_jumpDialog;
219  PlayListModel *m_model = nullptr;
220  static UiHelper* m_instance;
221 };
222 
223 #endif
General plugin interface.
Definition: generalfactory.h:61
The General class provides simple access to general plugins.
Definition: general.h:35
static PlayListManager * instance()
PlayListModel * selectedPlayList() const
The PlayListModel class provides a data model for the playlist.
Definition: playlistmodel.h:97
The UiHelper class provides simple api to access general plugins and some gui features.
Definition: uihelper.h:45
static UiHelper * instance()
void showMainWindow()
QList< QAction * > actions(MenuType type=TOOLS_MENU)
void about(QWidget *parent=nullptr)
QMenu * createMenu(MenuType type, const QString &title=QString(), bool autoHide=true, QWidget *parent=nullptr)
void savePlayList(QWidget *parent=qApp->activeWindow(), PlayListModel *model=PlayListManager::instance() ->selectedPlayList())
void toggleVisibility()
void exit()
void removeAction(QAction *action)
void showMainWindowCalled()
void addUrl(QWidget *parent=qApp->activeWindow(), PlayListModel *model=PlayListManager::instance() ->selectedPlayList())
void widgetRemoved(const QString &id)
UiHelper(QObject *parent=nullptr)
void addAction(QAction *action, MenuType type=TOOLS_MENU)
void widgetUpdated(const QString &id)
void addFiles(QWidget *parent=qApp->activeWindow(), PlayListModel *model=PlayListManager::instance() ->selectedPlayList())
void playFiles(QWidget *parent=qApp->activeWindow(), PlayListModel *model=PlayListManager::instance() ->selectedPlayList())
void widgetAdded(const QString &id)
void registerMenu(MenuType type, QMenu *menu, bool autoHide=false, QAction *before=nullptr)
void jumpToTrack(QWidget *parent=qApp->activeWindow(), PlayListModel *model=PlayListManager::instance() ->selectedPlayList())
void addDirectory(QWidget *parent=qApp->activeWindow(), PlayListModel *model=PlayListManager::instance() ->selectedPlayList())
void toggleVisibilityCalled()
MenuType
Definition: uihelper.h:61
@ PLAYLIST_MENU
Definition: uihelper.h:63
bool visibilityControl()
void loadPlayList(QWidget *parent=qApp->activeWindow(), PlayListModel *model=PlayListManager::instance() ->selectedPlayList())