~indicator-applet-developers/hud/trunk.14.04

« back to all changes in this revision

Viewing changes to libqtgmenu/internal/QtGMenuImporterPrivate.cpp

  • Committer: CI bot
  • Author(s): Pete Woods, Marcus Tomlinson
  • Date: 2014-06-04 14:04:03 UTC
  • mfrom: (390.1.44 trunk)
  • Revision ID: ps-jenkins@lists.canonical.com-20140604140403-a70c33snru5b6k4x
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. Fixes: 1298656, 1316473, 1322050, 1325538

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
      m_service_watcher( service, QDBusConnection::sessionBus(),
31
31
          QDBusServiceWatcher::WatchForOwnerChange ),
32
32
      m_parent( parent ),
33
 
      m_connection( g_bus_get_sync( G_BUS_TYPE_SESSION, NULL, NULL ) ),
 
33
      m_connection( g_bus_get_sync( G_BUS_TYPE_SESSION, NULL, NULL ), &g_object_unref ),
34
34
      m_service( service ),
35
35
      m_menu_path( menu_path ),
36
36
      m_action_paths( action_paths )
48
48
{
49
49
  ClearMenuModel();
50
50
  ClearActionGroups();
51
 
 
52
 
  g_object_unref( m_connection );
53
51
}
54
52
 
55
 
GMenuModel* QtGMenuImporterPrivate::GetGMenuModel()
 
53
QSharedPointer<GMenuModel> QtGMenuImporterPrivate::GetGMenuModel()
56
54
{
57
55
  if( m_menu_model == nullptr )
58
56
  {
59
 
    return nullptr;
 
57
    return QSharedPointer<GMenuModel>();
60
58
  }
61
59
 
62
60
  return m_menu_model->Model();
63
61
}
64
62
 
65
 
GActionGroup* QtGMenuImporterPrivate::GetGActionGroup( int index )
 
63
QSharedPointer<GActionGroup> QtGMenuImporterPrivate::GetGActionGroup( int index )
66
64
{
67
65
  if( index >= m_action_groups.size() ||
68
66
      m_action_groups[index] == nullptr )
69
67
  {
70
 
    return nullptr;
 
68
    return QSharedPointer<GActionGroup>();
71
69
  }
72
70
 
73
71
  return m_action_groups[index]->ActionGroup();
160
158
  ClearMenuModel();
161
159
 
162
160
  QString menu_path = m_menu_path.path();
163
 
  m_menu_model =
164
 
      std::make_shared< QtGMenuModel > (
165
 
              G_MENU_MODEL( g_dbus_menu_model_get( m_connection, m_service.toUtf8().constData(), menu_path.toUtf8().constData() ) ),
166
 
              m_service, menu_path, m_action_paths );
 
161
  m_menu_model = std::make_shared< QtGMenuModel > ( m_connection, m_service, menu_path, m_action_paths );
167
162
 
168
163
  connect( m_menu_model.get(), SIGNAL( MenuItemsChanged( QtGMenuModel*, int, int,
169
164
          int ) ), &m_parent, SIGNAL( MenuItemsChanged()) );
 
165
 
 
166
  connect( m_menu_model.get(), SIGNAL( MenuInvalid() ), this, SLOT( MenuInvalid() ) );
170
167
}
171
168
 
172
169
void QtGMenuImporterPrivate::RefreshGActionGroup()
181
178
 
182
179
    QString action_path = action_path_it.value().path();
183
180
    m_action_groups.push_back(
184
 
        std::make_shared< QtGActionGroup > ( action_path_it.key(),
185
 
                G_ACTION_GROUP( g_dbus_action_group_get( m_connection, m_service.toUtf8().constData(), action_path.toUtf8().constData() ) ) ) );
 
181
                std::make_shared<QtGActionGroup>(m_connection,
 
182
                        action_path_it.key(), m_service, action_path));
186
183
 
187
184
    auto action_group = m_action_groups.back();
188
185
 
198
195
 
199
196
  LinkMenuActions();
200
197
}
 
198
 
 
199
void QtGMenuImporterPrivate::MenuInvalid()
 
200
{
 
201
  disconnect( &m_service_watcher, SIGNAL( serviceRegistered( const QString& ) ), this,
 
202
        SLOT( ServiceRegistered() ) );
 
203
 
 
204
  disconnect( &m_service_watcher, SIGNAL( serviceUnregistered( const QString& ) ), this,
 
205
        SLOT( ServiceUnregistered() ) );
 
206
 
 
207
  ServiceUnregistered();
 
208
}