Back to index

unity  6.0.0
IndicatorEntry.cpp
Go to the documentation of this file.
00001 // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
00002 /*
00003 * Copyright (C) 2010 Canonical Ltd
00004 *
00005 * This program is free software: you can redistribute it and/or modify
00006 * it under the terms of the GNU General Public License version 3 as
00007 * published by the Free Software Foundation.
00008 *
00009 * This program is distributed in the hope that it will be useful,
00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 * GNU General Public License for more details.
00013 *
00014 * You should have received a copy of the GNU General Public License
00015 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00016 *
00017 * Authored by: Neil Jagdish Patel <neil.patel@canonical.com>
00018 *              Marco Trevisan (TreviƱo) <mail@3v1n0.net>
00019 */
00020 
00021 #include "IndicatorEntry.h"
00022 
00023 #include <iostream>
00024 
00025 namespace unity
00026 {
00027 namespace indicator
00028 {
00029 
00030 Entry::Entry(std::string const& id,
00031              std::string const &name_hint,
00032              std::string const& label,
00033              bool label_sensitive,
00034              bool label_visible,
00035              int  image_type,
00036              std::string const& image_data,
00037              bool image_sensitive,
00038              bool image_visible,
00039              int priority)
00040   : id_(id)
00041   , name_hint_(name_hint)
00042   , label_(label)
00043   , label_visible_(label_visible)
00044   , label_sensitive_(label_sensitive)
00045   , image_type_(image_type)
00046   , image_data_(image_data)
00047   , image_visible_(image_visible)
00048   , image_sensitive_(image_sensitive)
00049   , priority_(priority)
00050   , show_now_(false)
00051   , active_(false)
00052 {
00053 }
00054 
00055 std::string const& Entry::name_hint() const
00056 {
00057   return name_hint_;
00058 }
00059 
00060 std::string const& Entry::id() const
00061 {
00062   return id_;
00063 }
00064 
00065 std::string const& Entry::label() const
00066 {
00067   return label_;
00068 }
00069 
00070 bool Entry::image_visible() const
00071 {
00072   return image_visible_;
00073 }
00074 
00075 bool Entry::image_sensitive() const
00076 {
00077   return image_sensitive_;
00078 }
00079 
00080 bool Entry::label_visible() const
00081 {
00082   return label_visible_;
00083 }
00084 
00085 bool Entry::label_sensitive() const
00086 {
00087   return label_sensitive_;
00088 }
00089 
00090 int Entry::image_type() const
00091 {
00092   return image_type_;
00093 }
00094 
00095 std::string const& Entry::image_data() const
00096 {
00097   return image_data_;
00098 }
00099 
00100 int Entry::priority() const
00101 {
00102   return priority_;
00103 }
00104 
00105 bool Entry::visible() const
00106 {
00107   return ((label_visible_ && !label_.empty()) ||
00108           (image_type_ != 0 && image_visible_ && !image_data_.empty()));
00109 }
00110 
00111 void Entry::set_active(bool active)
00112 {
00113   if (active_ == active)
00114     return;
00115 
00116   active_ = active;
00117   active_changed.emit(active);
00118   updated.emit();
00119 }
00120 
00121 void Entry::set_geometry(nux::Rect const& geometry)
00122 {
00123   if (geometry_ == geometry)
00124     return;
00125 
00126   geometry_ = geometry;
00127   geometry_changed.emit(geometry);
00128   updated.emit();
00129 }
00130 
00131 void Entry::setLabel(std::string const& label, bool sensitive, bool visible)
00132 {
00133   if (label_ == label && sensitive == label_sensitive_ && visible == label_visible_)
00134     return;
00135 
00136   label_ = label;
00137   label_sensitive_ = sensitive;
00138   label_visible_ = visible;
00139   updated.emit();
00140 }
00141 
00142 void Entry::setImage(int type, std::string const& data, bool sensitive, bool visible)
00143 {
00144   if (image_type_ == type && image_data_ == data &&
00145       image_sensitive_ == sensitive && image_visible_ == visible)
00146   {
00147     return;
00148   }
00149 
00150   image_type_ = type;
00151   image_data_ = data;
00152   image_sensitive_ = sensitive;
00153   image_visible_ = visible;
00154   updated.emit();
00155 }
00156 
00157 void Entry::setPriority(int priority)
00158 {
00159   if (priority_ == priority)
00160     return;
00161 
00162   priority_ = priority;
00163   updated.emit();
00164 }
00165 
00166 bool Entry::active() const
00167 {
00168   return active_;
00169 }
00170 
00171 nux::Rect const& Entry::geometry() const
00172 {
00173   return geometry_;
00174 }
00175 
00176 Entry& Entry::operator=(Entry const& rhs)
00177 {
00178   id_ = rhs.id_;
00179   name_hint_ = rhs.name_hint_;
00180   label_ = rhs.label_;
00181   label_sensitive_ = rhs.label_sensitive_;
00182   label_visible_ = rhs.label_visible_;
00183   image_type_ = rhs.image_type_;
00184   image_data_ = rhs.image_data_;
00185   image_sensitive_ = rhs.image_sensitive_;
00186   image_visible_ = rhs.image_visible_;
00187   priority_ = rhs.priority_;
00188 
00189   updated.emit();
00190   return *this;
00191 }
00192 
00193 bool Entry::show_now() const
00194 {
00195   return show_now_;
00196 }
00197 
00198 void Entry::set_show_now(bool show_now)
00199 {
00200   if (show_now_ == show_now)
00201     return;
00202 
00203   show_now_ = show_now;
00204   show_now_changed.emit(show_now);
00205   updated.emit();
00206 }
00207 
00208 void Entry::ShowMenu(int x, int y, unsigned int button, unsigned int timestamp)
00209 {
00210   ShowMenu(0, x, y, button, timestamp);
00211 }
00212 
00213 void Entry::ShowMenu(unsigned int xid, int x, int y, unsigned int button, unsigned int timestamp)
00214 {
00215   on_show_menu.emit(id_, xid, x, y, button, timestamp);
00216 }
00217 
00218 void Entry::SecondaryActivate(unsigned int timestamp)
00219 {
00220   on_secondary_activate.emit(id_, timestamp);
00221 }
00222 
00223 void Entry::Scroll(int delta)
00224 {
00225   on_scroll.emit(id_, delta);
00226 }
00227 
00228 std::ostream& operator<<(std::ostream& out, Entry const& e)
00229 {
00230   out << "<indicator::Entry " << e.id() << " hint: '" << e.name_hint() << "' "
00231       << std::boolalpha
00232       << " \"" << e.label() << "\" ("
00233       << e.label_sensitive() << ", " << e.label_visible() << ") image ("
00234       << e.image_sensitive() << ", " << e.image_visible() << ") "
00235       << (e.active() ? "active" : "not-active") << " "
00236       << (e.show_now() ? "show" : "dont-show") << " >";
00237   return out;
00238 }
00239 
00240 
00241 } // namespace indicator
00242 } // namespace unity