~ubuntu-branches/ubuntu/trusty/hud/trusty-updates

« back to all changes in this revision

Viewing changes to libqtgmenu/internal/QtGMenuModel.h

  • Committer: Package Import Robot
  • Author(s): Ubuntu daily release
  • Date: 2014-01-20 19:43:59 UTC
  • mfrom: (1.1.26)
  • Revision ID: package-import@ubuntu.com-20140120194359-jxxxqtd4ql9elvpf
Tags: 13.10.1+14.04.20140120-0ubuntu1
* New rebuild forced
* Automatic snapshot from revision 362

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2013 Canonical, Ltd.
 
3
 *
 
4
 * This program is free software: you can redistribute it and/or modify it
 
5
 * under the terms of the GNU General Public License version 3, as published
 
6
 * by the Free Software Foundation.
 
7
 *
 
8
 * This program is distributed in the hope that it will be useful, but
 
9
 * WITHOUT ANY WARRANTY; without even the implied warranties of
 
10
 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
 
11
 * PURPOSE.  See the GNU General Public License for more details.
 
12
 *
 
13
 * You should have received a copy of the GNU General Public License along
 
14
 * with this program.  If not, see <http://www.gnu.org/licenses/>.
 
15
 *
 
16
 * Author: Marcus Tomlinson <marcus.tomlinson@canonical.com>
 
17
 */
 
18
 
 
19
#ifndef QTGMENUMODEL_H
 
20
#define QTGMENUMODEL_H
 
21
 
 
22
#include <QObject>
 
23
#include <QMap>
 
24
#include <QMenu>
 
25
 
 
26
#include <memory>
 
27
#include <deque>
 
28
 
 
29
#undef signals
 
30
#include <gio/gio.h>
 
31
 
 
32
namespace qtgmenu
 
33
{
 
34
 
 
35
class QtGMenuModel : public QObject
 
36
{
 
37
Q_OBJECT
 
38
 
 
39
public:
 
40
  enum class LinkType
 
41
  {
 
42
    Root, Section, SubMenu
 
43
  };
 
44
 
 
45
  explicit QtGMenuModel( GMenuModel* model );
 
46
  QtGMenuModel( GMenuModel* model, const QString& bus_name, const QString& menu_path,
 
47
      const QString& actions_path );
 
48
  virtual ~QtGMenuModel();
 
49
 
 
50
  GMenuModel* Model() const;
 
51
  LinkType Type() const;
 
52
 
 
53
  int Size() const;
 
54
 
 
55
  QtGMenuModel* Parent() const;
 
56
  QtGMenuModel* Child( int index ) const;
 
57
 
 
58
  std::shared_ptr< QMenu > GetQMenu();
 
59
 
 
60
  constexpr static const char* c_property_actionName = "actionName";
 
61
  constexpr static const char* c_property_isParameterized = "isParameterized";
 
62
  constexpr static const char* c_property_busName = "busName";
 
63
  constexpr static const char* c_property_menuPath = "menuPath";
 
64
  constexpr static const char* c_property_actionsPath = "actionsPath";
 
65
  constexpr static const char* c_property_keywords = "keywords";
 
66
  constexpr static const char* c_property_hud_toolbar_item = "hud-toolbar-item";
 
67
 
 
68
Q_SIGNALS:
 
69
  void MenuItemsChanged( QtGMenuModel* model, int index, int removed, int added );
 
70
  void ActionTriggered( QString action_name, bool checked );
 
71
 
 
72
public Q_SLOTS:
 
73
  void ActionEnabled( QString action_name, bool enabled );
 
74
  void ActionParameterized( QString action_name, bool parameterized );
 
75
 
 
76
private Q_SLOTS:
 
77
  void ActionTriggered( bool );
 
78
 
 
79
private:
 
80
  QtGMenuModel( GMenuModel* model, LinkType link_type, QtGMenuModel* parent, int index );
 
81
 
 
82
  static QtGMenuModel* CreateChild( QtGMenuModel* parent, GMenuModel* model, int index );
 
83
 
 
84
  static void MenuItemsChangedCallback( GMenuModel* model, gint index, gint removed, gint added,
 
85
      gpointer user_data );
 
86
 
 
87
  void ChangeMenuItems( int index, int added, int removed );
 
88
 
 
89
  void ConnectCallback();
 
90
  void DisconnectCallback();
 
91
 
 
92
  void InsertChild( QtGMenuModel* child, int index );
 
93
  int ChildIndex( QtGMenuModel* child );
 
94
 
 
95
  QAction* CreateAction( int index );
 
96
  QAction* FindAction( QString name );
 
97
 
 
98
  void AppendQMenu( std::shared_ptr< QMenu > top_menu );
 
99
  void UpdateExtQMenu();
 
100
 
 
101
private:
 
102
  QtGMenuModel* m_parent = nullptr;
 
103
  QMap< int, QtGMenuModel* > m_children;
 
104
 
 
105
  GMenuModel* m_model = nullptr;
 
106
  gulong m_items_changed_handler = 0;
 
107
 
 
108
  LinkType m_link_type;
 
109
  int m_size = 0;
 
110
 
 
111
  QMenu* m_menu = new QMenu();
 
112
  QMenu* m_ext_menu = new QMenu();
 
113
 
 
114
  QString m_bus_name;
 
115
  QString m_menu_path;
 
116
  QString m_actions_path;
 
117
};
 
118
 
 
119
} // namespace qtgmenu
 
120
 
 
121
#endif // QTGMENUMODEL_H