~macslow/unity/backported-remote-add-to-5.0

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
/*
* Copyright (C) 2010 Canonical Ltd
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program.  If not, see <http://www.gnu.org/licenses/>.
*
* Authored by: Neil Jagdish Patel <neil.patel@canonical.com>
*              Marco Trevisan (TreviƱo) <mail@3v1n0.net>
*/

#include "IndicatorEntry.h"

#include <iostream>

namespace unity
{
namespace indicator
{

Entry::Entry(std::string const& id,
             std::string const &name_hint,
             std::string const& label,
             bool label_sensitive,
             bool label_visible,
             int  image_type,
             std::string const& image_data,
             bool image_sensitive,
             bool image_visible,
             int priority)
  : id_(id)
  , name_hint_(name_hint)
  , label_(label)
  , label_visible_(label_visible)
  , label_sensitive_(label_sensitive)
  , image_type_(image_type)
  , image_data_(image_data)
  , image_visible_(image_visible)
  , image_sensitive_(image_sensitive)
  , priority_(priority)
  , show_now_(false)
  , active_(false)
{
}

std::string const& Entry::name_hint() const
{
  return name_hint_;
}

std::string const& Entry::id() const
{
  return id_;
}

std::string const& Entry::label() const
{
  return label_;
}

bool Entry::image_visible() const
{
  return image_visible_;
}

bool Entry::image_sensitive() const
{
  return image_sensitive_;
}

bool Entry::label_visible() const
{
  return label_visible_;
}

bool Entry::label_sensitive() const
{
  return label_sensitive_;
}

int Entry::image_type() const
{
  return image_type_;
}

std::string const& Entry::image_data() const
{
  return image_data_;
}

int Entry::priority() const
{
  return priority_;
}

bool Entry::visible() const
{
  return ((label_visible_ && !label_.empty()) ||
          (image_type_ != 0 && image_visible_ && !image_data_.empty()));
}

void Entry::set_active(bool active)
{
  if (active_ == active)
    return;

  active_ = active;
  active_changed.emit(active);
  updated.emit();
}

void Entry::set_geometry(nux::Rect const& geometry)
{
  if (geometry_ == geometry)
    return;

  geometry_ = geometry;
  geometry_changed.emit(geometry);
  updated.emit();
}

void Entry::setLabel(std::string const& label, bool sensitive, bool visible)
{
  if (label_ == label && sensitive == label_sensitive_ && visible == label_visible_)
    return;

  label_ = label;
  label_sensitive_ = sensitive;
  label_visible_ = visible;
  updated.emit();
}

void Entry::setImage(int type, std::string const& data, bool sensitive, bool visible)
{
  if (image_type_ == type && image_data_ == data &&
      image_sensitive_ == sensitive && image_visible_ == visible)
  {
    return;
  }

  image_type_ = type;
  image_data_ = data;
  image_sensitive_ = sensitive;
  image_visible_ = visible;
  updated.emit();
}

void Entry::setPriority(int priority)
{
  if (priority_ == priority)
    return;

  priority_ = priority;
  updated.emit();
}

bool Entry::active() const
{
  return active_;
}

nux::Rect const& Entry::geometry() const
{
  return geometry_;
}

Entry& Entry::operator=(Entry const& rhs)
{
  id_ = rhs.id_;
  name_hint_ = rhs.name_hint_;
  label_ = rhs.label_;
  label_sensitive_ = rhs.label_sensitive_;
  label_visible_ = rhs.label_visible_;
  image_type_ = rhs.image_type_;
  image_data_ = rhs.image_data_;
  image_sensitive_ = rhs.image_sensitive_;
  image_visible_ = rhs.image_visible_;
  priority_ = rhs.priority_;

  updated.emit();
  return *this;
}

bool Entry::show_now() const
{
  return show_now_;
}

void Entry::set_show_now(bool show_now)
{
  if (show_now_ == show_now)
    return;

  show_now_ = show_now;
  show_now_changed.emit(show_now);
  updated.emit();
}

void Entry::ShowMenu(int x, int y, unsigned int button, unsigned int timestamp)
{
  ShowMenu(0, x, y, button, timestamp);
}

void Entry::ShowMenu(unsigned int xid, int x, int y, unsigned int button, unsigned int timestamp)
{
  on_show_menu.emit(id_, xid, x, y, button, timestamp);
}

void Entry::SecondaryActivate(unsigned int timestamp)
{
  on_secondary_activate.emit(id_, timestamp);
}

void Entry::Scroll(int delta)
{
  on_scroll.emit(id_, delta);
}

std::ostream& operator<<(std::ostream& out, Entry const& e)
{
  out << "<indicator::Entry " << e.id() << " hint: '" << e.name_hint() << "' "
      << std::boolalpha
      << " \"" << e.label() << "\" ("
      << e.label_sensitive() << ", " << e.label_visible() << ") image ("
      << e.image_sensitive() << ", " << e.image_visible() << ") "
      << (e.active() ? "active" : "not-active") << " "
      << (e.show_now() ? "show" : "dont-show") << " >";
  return out;
}


} // namespace indicator
} // namespace unity