~ubuntu-branches/ubuntu/trusty/hud/trusty-proposed

« back to all changes in this revision

Viewing changes to libqtgmenu/internal/QtGMenuModel.h

  • Committer: Package Import Robot
  • Author(s): Ubuntu daily release, Pete Woods, Marcus Tomlinson
  • Date: 2014-04-25 08:48:46 UTC
  • mfrom: (1.1.34)
  • Revision ID: package-import@ubuntu.com-20140425084846-ou5d0qsm18g6lyrv
Tags: 13.10.1+14.04.20140425-0ubuntu1
[ Pete Woods ]
* Harden HUD against misbehaving applications Report the offending
  applications using Apport's recoverable problem tool. Switch to
  using shared pointers where possible for managing memory. (LP:
  #1298656)

[ Marcus Tomlinson ]
* Harden HUD against misbehaving applications Report the offending
  applications using Apport's recoverable problem tool. Switch to
  using shared pointers where possible for managing memory. (LP:
  #1298656)

Show diffs side-by-side

added added

removed removed

Lines of Context:
43
43
    Root, Section, SubMenu
44
44
  };
45
45
 
46
 
  explicit QtGMenuModel( GMenuModel* model );
47
 
  QtGMenuModel( GMenuModel* model, const QString& bus_name, const QString& menu_path, const QMap<QString, QDBusObjectPath>& action_paths );
 
46
  QtGMenuModel( QSharedPointer<GDBusConnection> connection, const QString& bus_name, const QString& menu_path, const QMap<QString, QDBusObjectPath>& action_paths );
48
47
  virtual ~QtGMenuModel();
49
48
 
50
 
  GMenuModel* Model() const;
 
49
  QSharedPointer<GMenuModel> Model() const;
51
50
  LinkType Type() const;
52
51
 
53
 
  int Size() const;
54
 
 
55
52
  QtGMenuModel* Parent() const;
56
 
  QtGMenuModel* Child( int index ) const;
 
53
  QSharedPointer<QtGMenuModel> Child( int index ) const;
57
54
 
58
55
  std::shared_ptr< QMenu > GetQMenu();
59
56
 
68
65
Q_SIGNALS:
69
66
  void MenuItemsChanged( QtGMenuModel* model, int index, int removed, int added );
70
67
  void ActionTriggered( QString action_name, bool checked );
 
68
  void MenuInvalid();
71
69
 
72
70
public Q_SLOTS:
73
71
  void ActionEnabled( QString action_name, bool enabled );
77
75
  void ActionTriggered( bool );
78
76
 
79
77
private:
80
 
  QtGMenuModel( GMenuModel* model, LinkType link_type, QtGMenuModel* parent, int index );
 
78
  QtGMenuModel( QSharedPointer<GMenuModel> model, LinkType link_type, QtGMenuModel* parent, int index );
81
79
 
82
 
  static QtGMenuModel* CreateChild( QtGMenuModel* parent, GMenuModel* model, int index );
 
80
  static QSharedPointer<QtGMenuModel> CreateChild( QtGMenuModel* parent_qtgmenu, QSharedPointer<GMenuModel> parent_gmenu, int child_index );
83
81
 
84
82
  static void MenuItemsChangedCallback( GMenuModel* model, gint index, gint removed, gint added,
85
83
      gpointer user_data );
86
84
 
87
 
  void ChangeMenuItems( int index, int added, int removed );
 
85
  void ChangeMenuItems( const int index, const int added, const int removed );
88
86
 
89
87
  void ConnectCallback();
90
88
  void DisconnectCallback();
91
89
 
92
 
  void InsertChild( QtGMenuModel* child, int index );
93
 
  int ChildIndex( QtGMenuModel* child );
 
90
  void InsertChild( QSharedPointer<QtGMenuModel> child, int index );
94
91
 
95
92
  QAction* CreateAction( int index );
96
93
 
100
97
  void ActionAdded( const QString& name, QAction* action );
101
98
  void ActionRemoved( const QString& name );
102
99
 
 
100
  void ReportRecoverableError(const int index, const int added, const int removed);
 
101
 
103
102
private:
104
103
  QtGMenuModel* m_parent = nullptr;
105
 
  QMap< int, QtGMenuModel* > m_children;
 
104
  QMap< int, QSharedPointer<QtGMenuModel>> m_children;
106
105
 
107
 
  GMenuModel* m_model = nullptr;
 
106
  QSharedPointer<GMenuModel> m_model;
108
107
  gulong m_items_changed_handler = 0;
109
108
 
110
109
  LinkType m_link_type;
111
110
  int m_size = 0;
112
111
 
113
 
  QMenu* m_menu = new QMenu();
114
 
  QMenu* m_ext_menu = new QMenu();
 
112
  QScopedPointer<QMenu> m_menu;
 
113
  QScopedPointer<QMenu> m_ext_menu;
115
114
 
 
115
  QSharedPointer<GDBusConnection> m_connection;
116
116
  QString m_bus_name;
117
117
  QString m_menu_path;
118
118
  QMap<QString, QDBusObjectPath> m_action_paths;
119
119
 
120
 
  std::map< QString, QAction* > m_actions;
 
120
  // a map of QActions indexed by their name and stored with a reference count
 
121
  std::map< QString, std::pair< int, QAction* > > m_actions;
 
122
 
 
123
  bool m_error_reported = false;
121
124
};
122
125
 
123
126
} // namespace qtgmenu