~ken-vandine/unity/make-quicklists-work-again

« back to all changes in this revision

Viewing changes to src/IndicatorObjectProxyRemote.cpp

Import the work done so far with Compiz

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
static void on_row_added   (DeeModel                   *model,
 
24
                            DeeModelIter               *iter,
 
25
                            IndicatorObjectProxyRemote *remote);
 
26
 
 
27
static void on_row_changed (DeeModel                   *model,
 
28
                            DeeModelIter               *iter,
 
29
                            IndicatorObjectProxyRemote *remote);
 
30
 
 
31
static void on_row_removed (DeeModel                   *model,
 
32
                            DeeModelIter               *iter,
 
33
                            IndicatorObjectProxyRemote *remote);
 
34
 
 
35
IndicatorObjectProxyRemote::IndicatorObjectProxyRemote (const char *name,
 
36
                                                        const char *model_name)
 
37
: _name (name),
 
38
  _model_name (model_name)
 
39
{
 
40
  _model = dee_shared_model_new_with_name (model_name);
 
41
  g_signal_connect (_model, "row-added",
 
42
                    G_CALLBACK (on_row_added), this);
 
43
  g_signal_connect (_model, "row-changed",
 
44
                    G_CALLBACK (on_row_changed), this);
 
45
  g_signal_connect (_model, "row-removed",
 
46
                    G_CALLBACK (on_row_removed), this);
 
47
 
 
48
  dee_shared_model_connect (DEE_SHARED_MODEL (_model));
 
49
}
 
50
 
 
51
IndicatorObjectProxyRemote::~IndicatorObjectProxyRemote ()
 
52
{
 
53
  std::vector<IndicatorObjectEntryProxy*>::iterator it;
 
54
  
 
55
  for (it = _entries.begin(); it != _entries.end(); it++)
 
56
  {
 
57
    IndicatorObjectEntryProxyRemote *remote = static_cast<IndicatorObjectEntryProxyRemote *> (*it);
 
58
    delete remote;
 
59
  }
 
60
 
 
61
  _entries.erase (_entries.begin (), _entries.end ());
 
62
}
 
63
  
 
64
std::string&
 
65
IndicatorObjectProxyRemote::GetName ()
 
66
{
 
67
  return _name;
 
68
}
 
69
 
 
70
std::vector<IndicatorObjectEntryProxy *>&
 
71
IndicatorObjectProxyRemote::GetEntries ()
 
72
{
 
73
  return _entries;
 
74
}
 
75
 
 
76
void
 
77
IndicatorObjectProxyRemote::OnRowAdded (DeeModelIter *iter)
 
78
{
 
79
  IndicatorObjectEntryProxyRemote *remote;
 
80
 
 
81
  remote = new IndicatorObjectEntryProxyRemote (_model, iter);
 
82
  remote->OnShowMenuRequest.connect (sigc::mem_fun (this, &IndicatorObjectProxyRemote::OnShowMenuRequestReceived));
 
83
  _entries.push_back (remote);
 
84
 
 
85
  OnEntryAdded.emit (remote);
 
86
}
 
87
 
 
88
void
 
89
IndicatorObjectProxyRemote::OnShowMenuRequestReceived (const char *id,
 
90
                                                       int         x,
 
91
                                                       int         y,
 
92
                                                       guint32     timestamp)
 
93
{
 
94
  OnShowMenuRequest.emit (id, x, y, timestamp);
 
95
}
 
96
 
 
97
void
 
98
IndicatorObjectProxyRemote::OnRowChanged (DeeModelIter *iter)
 
99
{
 
100
  std::vector<IndicatorObjectEntryProxy*>::iterator it;
 
101
  
 
102
  for (it = _entries.begin(); it != _entries.end(); it++)
 
103
  {
 
104
    IndicatorObjectEntryProxyRemote *remote = static_cast<IndicatorObjectEntryProxyRemote *> (*it);
 
105
    if (remote->_iter == iter)
 
106
      remote->Refresh ();
 
107
  }
 
108
}
 
109
 
 
110
void
 
111
IndicatorObjectProxyRemote::OnRowRemoved (DeeModelIter *iter)
 
112
{
 
113
  std::vector<IndicatorObjectEntryProxy*>::iterator it;
 
114
  
 
115
  for (it = _entries.begin(); it != _entries.end(); it++)
 
116
  {
 
117
    IndicatorObjectEntryProxyRemote *remote = static_cast<IndicatorObjectEntryProxyRemote *> (*it);
 
118
    if (remote->_iter == iter)
 
119
      {
 
120
        _entries.erase (it);
 
121
        OnEntryRemoved.emit (remote);
 
122
        delete remote;
 
123
 
 
124
        break;
 
125
      }
 
126
  }
 
127
}
 
128
 
 
129
//
 
130
// C callbacks, they just link to class methods and aren't interesting
 
131
//
 
132
static void
 
133
on_row_added (DeeModel *model, DeeModelIter *iter, IndicatorObjectProxyRemote *remote)
 
134
{
 
135
  remote->OnRowAdded (iter);
 
136
}
 
137
 
 
138
static void
 
139
on_row_changed (DeeModel *model, DeeModelIter *iter, IndicatorObjectProxyRemote *remote)
 
140
{
 
141
  remote->OnRowChanged (iter);
 
142
}
 
143
 
 
144
static void
 
145
on_row_removed (DeeModel *model, DeeModelIter *iter, IndicatorObjectProxyRemote *remote)
 
146
{
 
147
  remote->OnRowRemoved (iter);
 
148
}