~3v1n0/unity/callgrind-improvements

« back to all changes in this revision

Viewing changes to src/IndicatorObjectEntryProxyRemote.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 "IndicatorObjectEntryProxyRemote.h"
 
20
 
 
21
#include <gtk/gtk.h>
 
22
 
 
23
enum
 
24
{
 
25
  COL_ID,
 
26
  COL_LABEL,
 
27
  COL_ICON_HINT,
 
28
  COL_ICON_DATA,
 
29
  COL_LABEL_VISIBLE,
 
30
  COL_ICON_VISIBLE,
 
31
  COL_LABEL_SENSITIVE,
 
32
  COL_ICON_SENSITIVE
 
33
};
 
34
 
 
35
IndicatorObjectEntryProxyRemote::IndicatorObjectEntryProxyRemote (DeeModel     *model,
 
36
                                                                  DeeModelIter *iter)
 
37
: _model (model),
 
38
  _iter (iter),
 
39
  _active (false)
 
40
{
 
41
  label_visible = false;
 
42
  label_sensitive = true;
 
43
  icon_visible = false;
 
44
  icon_sensitive = true;
 
45
  _active = false;
 
46
 
 
47
  Refresh ();
 
48
}
 
49
 
 
50
 
 
51
IndicatorObjectEntryProxyRemote::~IndicatorObjectEntryProxyRemote ()
 
52
{
 
53
 
 
54
}
 
55
 
 
56
const char *
 
57
IndicatorObjectEntryProxyRemote::GetLabel ()
 
58
{
 
59
  return dee_model_get_string (_model, _iter, COL_LABEL);
 
60
}
 
61
 
 
62
GdkPixbuf *
 
63
IndicatorObjectEntryProxyRemote::GetPixbuf ()
 
64
{
 
65
  GdkPixbuf *ret = NULL;
 
66
  guint32 icon_hint = dee_model_get_uint (_model, _iter, COL_ICON_HINT);
 
67
 
 
68
  if (icon_hint == GTK_IMAGE_PIXBUF)
 
69
    {
 
70
      guchar       *decoded;
 
71
      GInputStream *stream;
 
72
      gsize         len = 0;
 
73
     
 
74
      decoded = g_base64_decode (dee_model_get_string (_model, _iter, COL_ICON_DATA), &len);
 
75
      stream = g_memory_input_stream_new_from_data (decoded, len, NULL);
 
76
 
 
77
      ret = gdk_pixbuf_new_from_stream (stream, NULL, NULL);
 
78
 
 
79
      g_free (decoded);
 
80
      g_input_stream_close (stream, NULL, NULL);
 
81
    }
 
82
  else if (icon_hint == GTK_IMAGE_STOCK
 
83
           || icon_hint == GTK_IMAGE_ICON_NAME)
 
84
    {
 
85
      ret = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
 
86
                                      dee_model_get_string (_model, _iter, COL_ICON_DATA),
 
87
                                      22,
 
88
                                      (GtkIconLookupFlags)0,
 
89
                                      NULL);
 
90
    }
 
91
  else if (icon_hint == GTK_IMAGE_GICON)
 
92
    {
 
93
      GtkIconInfo *info;
 
94
      GIcon       *icon;
 
95
 
 
96
      icon = g_icon_new_for_string (dee_model_get_string (_model, _iter, COL_ICON_DATA), NULL);
 
97
      info = gtk_icon_theme_lookup_by_gicon (gtk_icon_theme_get_default (),
 
98
                                             icon,
 
99
                                             22,
 
100
                                             (GtkIconLookupFlags)0);
 
101
      if (info)
 
102
        ret = gtk_icon_info_load_icon (info, NULL);
 
103
 
 
104
      gtk_icon_info_free (info);
 
105
      g_object_unref (icon);
 
106
    }
 
107
 
 
108
  return ret;
 
109
}
 
110
 
 
111
void
 
112
IndicatorObjectEntryProxyRemote::SetActive (bool active)
 
113
{
 
114
  if (_active == active)
 
115
    return;
 
116
 
 
117
  _active = active;
 
118
 
 
119
  Updated.emit ();
 
120
}
 
121
 
 
122
bool
 
123
IndicatorObjectEntryProxyRemote::GetActive ()
 
124
{
 
125
  return _active;
 
126
}
 
127
 
 
128
void
 
129
IndicatorObjectEntryProxyRemote::Refresh ()
 
130
{
 
131
  label_visible = dee_model_get_bool (_model, _iter, COL_LABEL_VISIBLE);
 
132
  //label_sensitive = dee_model_get_bool (_model, _iter, COL_LABEL_SENSITIVE); FIXME: Re-enable these when the service supports them
 
133
  icon_visible = dee_model_get_bool (_model, _iter, COL_ICON_VISIBLE);
 
134
  //icon_sensitive = dee_model_get_bool (_model, _iter, COL_ICON_SENSITIVE);
 
135
 
 
136
  Updated.emit ();
 
137
}
 
138
 
 
139
const char *
 
140
IndicatorObjectEntryProxyRemote::GetId ()
 
141
{
 
142
  return dee_model_get_string (_model, _iter, COL_ID);
 
143
}
 
144
 
 
145
void
 
146
IndicatorObjectEntryProxyRemote::ShowMenu (int x, int y, guint32 timestamp)
 
147
{
 
148
  OnShowMenuRequest.emit (dee_model_get_string (_model, _iter, COL_ID), x, y, timestamp);  
 
149
}