~canonical-dx-team/unity/unity.fix-ql-losing-focus

« back to all changes in this revision

Viewing changes to src/IndicatorObjectProxyRemote.cpp

  • Committer: Neil Jagdish Patel
  • Date: 2010-11-11 18:51:08 UTC
  • mfrom: (572.1.58 unity-3.0)
  • Revision ID: neil.patel@canonical.com-20101111185108-71923a90txzvxbit
[merge] Unity 3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2010 Canonical Ltd
 
3
 *
 
4
 * This program is free software: you can redistribute it and/or modify
 
5
 * it under the terms of the GNU General Public License version 3 as
 
6
 * published by the Free Software Foundation.
 
7
 *
 
8
 * This program is distributed in the hope that it will be useful,
 
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
 * GNU General Public License for more details.
 
12
 *
 
13
 * You should have received a copy of the GNU General Public License
 
14
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
15
 *
 
16
 * Authored by: Neil Jagdish Patel <neil.patel@canonical.com>
 
17
 */
 
18
 
 
19
#include "IndicatorObjectProxyRemote.h"
 
20
 
 
21
#include "IndicatorObjectEntryProxyRemote.h"
 
22
 
 
23
IndicatorObjectProxyRemote::IndicatorObjectProxyRemote (const char *name)
 
24
: _name (name)
 
25
{
 
26
}
 
27
 
 
28
IndicatorObjectProxyRemote::~IndicatorObjectProxyRemote ()
 
29
{
 
30
  std::vector<IndicatorObjectEntryProxy*>::iterator it;
 
31
  
 
32
  for (it = _entries.begin(); it != _entries.end(); it++)
 
33
  {
 
34
    IndicatorObjectEntryProxyRemote *remote = static_cast<IndicatorObjectEntryProxyRemote *> (*it);
 
35
    delete remote;
 
36
  }
 
37
 
 
38
  _entries.erase (_entries.begin (), _entries.end ());
 
39
}
 
40
  
 
41
std::string&
 
42
IndicatorObjectProxyRemote::GetName ()
 
43
{
 
44
  return _name;
 
45
}
 
46
 
 
47
std::vector<IndicatorObjectEntryProxy *>&
 
48
IndicatorObjectProxyRemote::GetEntries ()
 
49
{
 
50
  return _entries;
 
51
}
 
52
 
 
53
 
 
54
void
 
55
IndicatorObjectProxyRemote::BeginSync ()
 
56
{
 
57
  std::vector<IndicatorObjectEntryProxy*>::iterator it;
 
58
  
 
59
  for (it = _entries.begin(); it != _entries.end(); it++)
 
60
  {
 
61
    IndicatorObjectEntryProxyRemote *remote = static_cast<IndicatorObjectEntryProxyRemote *> (*it);
 
62
    remote->_dirty = true;
 
63
  }
 
64
}
 
65
 
 
66
void
 
67
IndicatorObjectProxyRemote::AddEntry (const gchar *entry_id,
 
68
                                      const gchar *label,
 
69
                                      bool         label_sensitive,
 
70
                                      bool         label_visible,
 
71
                                      guint32      image_type,
 
72
                                      const gchar *image_data,
 
73
                                      bool         image_sensitive,
 
74
                                      bool         image_visible)
 
75
{
 
76
  IndicatorObjectEntryProxyRemote *remote = NULL;
 
77
  std::vector<IndicatorObjectEntryProxy*>::iterator it;
 
78
  
 
79
  for (it = _entries.begin(); it != _entries.end(); it++)
 
80
  {
 
81
    IndicatorObjectEntryProxyRemote *r = static_cast<IndicatorObjectEntryProxyRemote *> (*it);
 
82
    if (r->_dirty == true)
 
83
      {
 
84
        remote = r;
 
85
        break;
 
86
      }
 
87
  }
 
88
  
 
89
  /* Create a new one */
 
90
  if (remote == NULL)
 
91
    {
 
92
      remote = new IndicatorObjectEntryProxyRemote ();
 
93
      remote->OnShowMenuRequest.connect (sigc::mem_fun (this,
 
94
                                                        &IndicatorObjectProxyRemote::OnShowMenuRequestReceived));
 
95
      _entries.push_back (remote);
 
96
    }
 
97
 
 
98
  remote->Refresh (entry_id,
 
99
                   label,
 
100
                   label_sensitive,
 
101
                   label_visible,
 
102
                   image_type,
 
103
                   image_data,
 
104
                   image_sensitive,
 
105
                   image_visible);
 
106
  if (remote->_dirty)
 
107
    remote->_dirty = false;
 
108
  else
 
109
    OnEntryAdded.emit (remote);
 
110
}
 
111
 
 
112
void
 
113
IndicatorObjectProxyRemote::EndSync ()
 
114
{
 
115
  std::vector<IndicatorObjectEntryProxy*>::iterator it;
 
116
 
 
117
  for (it = _entries.begin(); it != _entries.end(); it++)
 
118
  {
 
119
    IndicatorObjectEntryProxyRemote *remote = static_cast<IndicatorObjectEntryProxyRemote *> (*it);
 
120
    if (remote->_dirty == true)
 
121
      {
 
122
        /* We don't get rid of the entries as there's no real need to, and it saves us
 
123
         * having to do a bunch of object creation everytime the menu changes
 
124
         */
 
125
        remote->Refresh ("|",
 
126
                         "",
 
127
                         false,
 
128
                         false,
 
129
                         0,
 
130
                         "",
 
131
                         false,
 
132
                         false);
 
133
      }
 
134
  }
 
135
}
 
136
 
 
137
void
 
138
IndicatorObjectProxyRemote::OnShowMenuRequestReceived (const char *entry_id,
 
139
                                                       int         x,
 
140
                                                       int         y,
 
141
                                                       guint32     timestamp,
 
142
                                                       guint32     button)
 
143
{
 
144
  OnShowMenuRequest.emit (entry_id, x, y, timestamp, button);
 
145
}