Qmmp
uihelper.h
1 /***************************************************************************
2  * Copyright (C) 2008-2020 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);
56  ~UiHelper();
60  enum MenuType
61  {
62  TOOLS_MENU = 0,
64  ADD_MENU
65  };
69  bool visibilityControl();
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:
164  void toggleVisibility();
168  void showMainWindow();
172  void exit();
173 
174 signals:
179  void toggleVisibilityCalled();
184  void showMainWindowCalled();
185 
186 private slots:
187  void removeAction(QObject *action);
188  void addSelectedFiles(const QStringList &files, bool play);
189  void playSelectedFiles(const QStringList &files);
190  void disconnectPl();
191 
192 private:
193  QMap <GeneralFactory*, General*> m_generals;
194  struct MenuData
195  {
196  QPointer<QMenu> menu;
197  QPointer<QAction> before;
198  QList<QAction*> actions;
199  bool autoHide = false;
200  };
201  QMap<MenuType, MenuData> m_menus;
202  QString m_lastDir;
203  QPointer <JumpToTrackDialog> m_jumpDialog;
204  PlayListModel *m_model = nullptr;
205  static UiHelper* m_instance;
206 };
207 
208 #endif
The General class provides simple access to general plugins.
Definition: general.h:34
The PlayListModel class provides a data model for the playlist.
Definition: playlistmodel.h:103
static PlayListManager * instance()
PlayListModel * selectedPlayList() const
Definition: uihelper.h:63
General plugin interface.
Definition: generalfactory.h:46
The UiHelper class provides simple api to access general plugins and some gui features.
Definition: uihelper.h:44
MenuType
Definition: uihelper.h:60