Sayonara Player
PlayerPlugin.h
1 /* PlayerPlugin.h */
2 
3 /* Copyright (C) 2011-2016 Lucio Carreras
4  *
5  * This file is part of sayonara player
6  *
7  * This program 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  * This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
21 
22 
23 #ifndef PLAYERPLUGIN_H
24 #define PLAYERPLUGIN_H
25 
26 #include <QAction>
27 #include <QCloseEvent>
28 #include <QLabel>
29 #include <QPushButton>
30 #include <QLayout>
31 
32 #include "GUI/Helper/SayonaraWidget/SayonaraWidget.h"
33 #include "GUI/Helper/Shortcuts/ShortcutWidget.h"
34 #include "GUI/Helper/Shortcuts/ShortcutHandler.h"
35 #include "GUI/Helper/IconLoader/IconLoader.h"
36 
37 #include "Components/PlayManager/PlayManager.h"
38 
39 
40 
42 
50  public SayonaraWidget,
51  public ShortcutWidget
52 {
53 
54  friend class PlayerPluginHandler;
55 
56  Q_OBJECT
57 
58 public:
59  PlayerPluginInterface(QWidget *parent=nullptr);
60  virtual ~PlayerPluginInterface();
61 
62 signals:
69  void sig_action_triggered(PlayerPluginInterface* plugin, bool checked);
70 
76 
77 
78 private slots:
84  void action_triggered(bool checked);
85 
86  void _sl_lang_changed();
87 
88 private:
89  bool _pp_is_closed;
90  bool _is_initialized;
91 
92  void set_size(QSize size);
93 
94 
95 protected:
96 
101 
105  QAction* _pp_action=nullptr;
106 
107 
108 
109 
110 protected:
111 
116  void closeEvent(QCloseEvent* e) override;
117 
118 
122  virtual void language_changed() override=0;
123 
127  virtual void init_ui()=0;
128 
133  bool is_ui_initialized() const;
134 
138  void set_ui_initialized();
139 
140 
141  template<typename T>
142  void setup_parent(T* widget){
143 
144  if(is_ui_initialized()){
145  return;
146  }
147 
148  QLayout* widget_layout;
149 
150  widget->setupUi(widget);
151  this->set_ui_initialized();
152 
153  widget_layout = layout();
154  if(widget_layout){
155  widget_layout->setContentsMargins(3, 3, 3, 3);
156  }
157 
158  ShortcutHandler* sch = ShortcutHandler::getInstance();
159  Shortcut sc = sch->get_shortcut("close_plugin");
160  if(!sc.is_valid()){
161  sc = sch->add(Shortcut(this, "close_plugin", tr("Close plugin"), "Ctrl+Esc"));
162  }
163 
164  sc.create_qt_shortcut(this, this, SLOT(close()));
165 
166  REGISTER_LISTENER(Set::Player_Language, _sl_lang_changed);
167  REGISTER_LISTENER(Set::Player_Style, skin_changed);
168  }
169 
170 protected slots:
171 
176  virtual void playstate_changed(PlayManager::PlayState state);
177 
181  virtual void played();
182 
186  virtual void paused();
187 
191  virtual void stopped();
192 
193 
194 
195 public:
200  virtual QSize get_size() const final;
201 
206  virtual QAction* get_action() const final;
207 
212  virtual bool is_closed() const final;
213 
218  virtual QString get_name() const=0;
219 
224  virtual QString get_display_name() const=0;
225 
226 
230  virtual void show();
231 
232 
233  virtual bool is_title_shown() const;
234 
235 
241  QString get_shortcut_text(const QString &shortcut_identifier) const override;
242 };
243 
244 Q_DECLARE_INTERFACE(PlayerPluginInterface, "com.sayonara-player.playerplugin")
245 
246 #endif // PLAYERPLUGIN_H
virtual void language_changed() override=0
language_changed Has to be implemented and is called when language has changed
virtual QString get_name() const =0
must be overwritten
virtual void playstate_changed(PlayManager::PlayState state)
Playstate has changed, this does nothing in default implementation.
A singleton class for retrieving shortcuts.
Definition: ShortcutHandler.h:41
PlayState
Current Playing state.
Definition: PlayManager.h:91
virtual void init_ui()=0
GUI will be initialized on first show up. Please use this to make Sayonara starting fast...
bool is_valid() const
Check if the shortcut is valid or if it was retrieved via getInvalid()
virtual void paused()
Playstate has changed to paused.
A single shortcut managed by ShortcutHandler. This class holds information about the default shortcut...
Definition: Shortcut.h:42
virtual QAction * get_action() const final
needed by the player ui, final
virtual void show()
show Plugin
Widget with Settings connection. Also contains triggers for language_changed() and skin_changed() wi...
Definition: SayonaraWidget.h:41
Global handler for current playback state (Singleton)
Definition: PlayManager.h:79
void set_ui_initialized()
mark ui as initialized
void sig_action_triggered(PlayerPluginInterface *plugin, bool checked)
signal is emitted when the plugin action is triggered also emitted for when closeEvent is fired ...
virtual QSize get_size() const final
needed by the player ui, final
QAction * _pp_action
_pp_action already allocated, displays name of the plugin by calling get_name()
Definition: PlayerPlugin.h:105
void create_qt_shortcut(QWidget *parent, T func)
create a qt shortcut for a widget
Definition: Shortcut.h:142
virtual bool is_closed() const final
needed by the player ui, final
QString get_shortcut_text(const QString &shortcut_identifier) const override
get translated text of shortcut (overridden)
Interface for PlayerPlugin classes. get_name() and language_changed() must be overwritten.
Definition: PlayerPlugin.h:49
PlayManager * _play_manager
_play_manager Notifies about playstate
Definition: PlayerPlugin.h:100
Shortcut add(const Shortcut &shortcut)
add a new shortcut instance to the handler. This is usually done by the widget the shortcut is attach...
bool is_ui_initialized() const
Check if ui already was initialized.
void sig_reload(PlayerPluginInterface *)
emitted when reloading is requested, after firing this signal the plugin will be painted new...
Shortcut get_shortcut(const QString &identifier) const
get a shortcut by its unique identifier
void closeEvent(QCloseEvent *e) override
Event fired when closed overrides QWidget::closeEvent.
virtual void stopped()
Playstate has changed to stop.
Definition: PlayerPluginHandler.h:34
virtual void played()
Playstate has changed to playing.
Interface that should be implemented when using configurable shortcuts.
Definition: ShortcutWidget.h:33
virtual QString get_display_name() const =0
must be overwritten