~ubuntu-branches/ubuntu/precise/empathy/precise-proposed-201205180810

« back to all changes in this revision

Viewing changes to libempathy-gtk/empathy-cell-renderer-text.c

  • Committer: Bazaar Package Importer
  • Author(s): Brian Curtis, Brian Curtis, Ken VanDine
  • Date: 2011-06-01 10:35:24 UTC
  • mfrom: (1.1.70 upstream) (6.3.44 experimental)
  • Revision ID: james.westby@ubuntu.com-20110601103524-wx3wgp71394730jt
Tags: 3.1.1-1ubuntu1
[ Brian Curtis ]
* Merge with Debian experimental, remaining Ubuntu changes:
* debian/control:
  - Drop geoclue/mapping build-depends (they are in Universe)
  - Add Vcz-Bzr link
  - Add Suggests on telepathy-idle
  - Bump telepathy-butterfly, telepathy-haze to recommends
  - Don't recommend the freedesktop sound theme we have an ubuntu one
  - Add build depend for libunity-dev
* debian/rules:
  - Use autoreconf.mk
  - Disable map and location
* debian/empathy.install:
  - Install message indicator configuration
* debian/indicators/empathy:
  - Message indicator configuration
* debian/patches/01_lpi.patch:
  - Add Launchpad integration
* debian/patches/10_use_notify_osd_icons.patch:
  - Use the notify-osd image for new messages
* debian/patches/34_start_raised_execpt_in_session.patch
  - If not started with the session, we should always raise
* debian/patches/36_chat_window_default_size.patch:
  - Make the default chat window size larger
* debian/patches/37_facebook_default.patch:
  - Make facebook the default chat account type
* debian/patches/38_lp_569289.patch
  - Set freenode as default IRC network for new IRC accounts 
* debian/patches/41_unity_launcher_progress.patch
  - Display file transfer progress in the unity launcher

[ Ken VanDine ]
* debian/control
  - build depend on libgcr-3-dev instead of libgcr-dev
  - dropped build depends for libindicate, we will use telepathy-indicator
  - Depend on dconf-gsettings-backend | gsettings-backend
  - Added a Recommends for telepathy-indicator
* +debian/empathy.gsettings-override
  - Added an override for notifications-focus
* debian/patches/series
  - commented out 23_idomessagedialog_for_voip_and_ft.patch, until ido has 
    been ported to gtk3

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
        gboolean  is_valid;
39
39
        gboolean  is_selected;
40
40
 
 
41
        gchar   **types;
 
42
 
41
43
        gboolean  compact;
42
44
} EmpathyCellRendererTextPriv;
43
45
 
50
52
                                                  guint                        param_id,
51
53
                                                  const GValue                *value,
52
54
                                                  GParamSpec                  *pspec);
53
 
static void cell_renderer_text_get_size          (GtkCellRenderer             *cell,
54
 
                                                  GtkWidget                   *widget,
55
 
                                                  GdkRectangle                *cell_area,
56
 
                                                  gint                        *x_offset,
57
 
                                                  gint                        *y_offset,
58
 
                                                  gint                        *width,
59
 
                                                  gint                        *height);
60
55
static void cell_renderer_text_render            (GtkCellRenderer             *cell,
61
 
                                                  GdkDrawable                 *window,
 
56
                                                  cairo_t *cr,
62
57
                                                  GtkWidget                   *widget,
63
 
                                                  GdkRectangle                *background_area,
64
 
                                                  GdkRectangle                *cell_area,
65
 
                                                  GdkRectangle                *expose_area,
 
58
                                                  const GdkRectangle          *background_area,
 
59
                                                  const GdkRectangle          *cell_area,
66
60
                                                  GtkCellRendererState         flags);
67
61
static void cell_renderer_text_update_text       (EmpathyCellRendererText      *cell,
68
62
                                                  GtkWidget                   *widget,
75
69
        PROP_PRESENCE_TYPE,
76
70
        PROP_STATUS,
77
71
        PROP_IS_GROUP,
78
 
        PROP_COMPACT
 
72
        PROP_COMPACT,
 
73
        PROP_CLIENT_TYPES
79
74
};
80
75
 
81
76
G_DEFINE_TYPE (EmpathyCellRendererText, empathy_cell_renderer_text, GTK_TYPE_CELL_RENDERER_TEXT);
82
77
 
83
78
static void
 
79
cell_renderer_text_get_preferred_height_for_width (GtkCellRenderer *renderer,
 
80
                                                                GtkWidget *widget,
 
81
                                                                gint width,
 
82
                                                                gint *minimum_size,
 
83
                                                                gint *natural_size)
 
84
{
 
85
        EmpathyCellRendererText *self = EMPATHY_CELL_RENDERER_TEXT (renderer);
 
86
        EmpathyCellRendererTextPriv *priv = GET_PRIV (self);
 
87
 
 
88
        /* Only update if not already valid so we get the right size. */
 
89
        cell_renderer_text_update_text (self, widget, priv->is_selected);
 
90
 
 
91
        GTK_CELL_RENDERER_CLASS (empathy_cell_renderer_text_parent_class)->
 
92
                        get_preferred_height_for_width (renderer, widget, width,
 
93
                                        minimum_size, natural_size);
 
94
}
 
95
 
 
96
 
 
97
static void
84
98
empathy_cell_renderer_text_class_init (EmpathyCellRendererTextClass *klass)
85
99
{
86
100
        GObjectClass         *object_class;
95
109
        object_class->get_property = cell_renderer_text_get_property;
96
110
        object_class->set_property = cell_renderer_text_set_property;
97
111
 
98
 
        cell_class->get_size = cell_renderer_text_get_size;
 
112
        cell_class->get_preferred_height_for_width = cell_renderer_text_get_preferred_height_for_width;
99
113
        cell_class->render = cell_renderer_text_render;
100
114
 
101
115
        spec = g_param_spec_string ("name", "Name", "Contact name", NULL,
126
140
                FALSE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
127
141
        g_object_class_install_property (object_class, PROP_COMPACT, spec);
128
142
 
 
143
        spec = g_param_spec_boxed ("client-types", "Contact client types",
 
144
                "Client types of the contact",
 
145
                G_TYPE_STRV, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
 
146
        g_object_class_install_property (object_class, PROP_CLIENT_TYPES, spec);
 
147
 
129
148
        g_type_class_add_private (object_class, sizeof (EmpathyCellRendererTextPriv));
130
149
}
131
150
 
156
175
 
157
176
        g_free (priv->name);
158
177
        g_free (priv->status);
 
178
        g_strfreev (priv->types);
159
179
 
160
180
        (G_OBJECT_CLASS (empathy_cell_renderer_text_parent_class)->finalize) (object);
161
181
}
188
208
        case PROP_COMPACT:
189
209
                g_value_set_boolean (value, priv->compact);
190
210
                break;
 
211
        case PROP_CLIENT_TYPES:
 
212
                g_value_set_boxed (value, priv->types);
 
213
                break;
191
214
        default:
192
215
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
193
216
                break;
234
257
                priv->compact = g_value_get_boolean (value);
235
258
                priv->is_valid = FALSE;
236
259
                break;
 
260
        case PROP_CLIENT_TYPES:
 
261
                g_strfreev (priv->types);
 
262
                priv->types = g_value_dup_boxed (value);
 
263
                priv->is_valid = FALSE;
 
264
                break;
237
265
        default:
238
266
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
239
267
                break;
241
269
}
242
270
 
243
271
static void
244
 
cell_renderer_text_get_size (GtkCellRenderer *cell,
245
 
                             GtkWidget       *widget,
246
 
                             GdkRectangle    *cell_area,
247
 
                             gint            *x_offset,
248
 
                             gint            *y_offset,
249
 
                             gint            *width,
250
 
                             gint            *height)
251
 
{
252
 
        EmpathyCellRendererText     *celltext;
253
 
        EmpathyCellRendererTextPriv *priv;
254
 
 
255
 
        celltext = EMPATHY_CELL_RENDERER_TEXT (cell);
256
 
        priv = GET_PRIV (cell);
257
 
 
258
 
        /* Only update if not already valid so we get the right size. */
259
 
        cell_renderer_text_update_text (celltext, widget, priv->is_selected);
260
 
 
261
 
        (GTK_CELL_RENDERER_CLASS (empathy_cell_renderer_text_parent_class)->get_size) (cell, widget,
262
 
                                                                                      cell_area,
263
 
                                                                                      x_offset, y_offset,
264
 
                                                                                      width, height);
265
 
}
266
 
 
267
 
static void
268
272
cell_renderer_text_render (GtkCellRenderer      *cell,
269
 
                           GdkWindow            *window,
 
273
                           cairo_t *cr,
270
274
                           GtkWidget            *widget,
271
 
                           GdkRectangle         *background_area,
272
 
                           GdkRectangle         *cell_area,
273
 
                           GdkRectangle         *expose_area,
 
275
                           const GdkRectangle   *background_area,
 
276
                           const GdkRectangle   *cell_area,
274
277
                           GtkCellRendererState  flags)
275
278
{
276
279
        EmpathyCellRendererText *celltext;
282
285
                                        (flags & GTK_CELL_RENDERER_SELECTED));
283
286
 
284
287
        (GTK_CELL_RENDERER_CLASS (empathy_cell_renderer_text_parent_class)->render) (
285
 
                cell, window,
 
288
                cell, cr,
286
289
                widget,
287
290
                background_area,
288
291
                cell_area,
289
 
                expose_area, flags);
 
292
                flags);
290
293
}
291
294
 
292
295
static void
295
298
                                gboolean                selected)
296
299
{
297
300
        EmpathyCellRendererTextPriv *priv;
 
301
        const PangoFontDescription *font_desc;
298
302
        PangoAttrList              *attr_list;
299
 
        PangoAttribute             *attr_color, *attr_size;
300
 
        GtkStyle                   *style;
 
303
        PangoAttribute             *attr_color = NULL, *attr_size;
 
304
        GtkStyleContext            *style;
301
305
        gchar                      *str;
 
306
        gint                        font_size;
302
307
 
303
308
        priv = GET_PRIV (cell);
304
309
 
321
326
                return;
322
327
        }
323
328
 
324
 
        style = gtk_widget_get_style (widget);
 
329
        style = gtk_widget_get_style_context (widget);
325
330
 
326
331
        attr_list = pango_attr_list_new ();
327
332
 
328
 
        attr_size = pango_attr_size_new (pango_font_description_get_size (style->font_desc) / 1.2);
 
333
        font_desc = gtk_style_context_get_font (style, GTK_STATE_FLAG_NORMAL);
 
334
        font_size = pango_font_description_get_size (font_desc);
 
335
        attr_size = pango_attr_size_new (font_size / 1.2);
329
336
        attr_size->start_index = strlen (priv->name) + 1;
330
337
        attr_size->end_index = -1;
331
338
        pango_attr_list_insert (attr_list, attr_size);
332
339
 
333
340
        if (!selected) {
334
 
                GdkColor color;
335
 
 
336
 
                color = style->text_aa[GTK_STATE_NORMAL];
337
 
 
338
 
                attr_color = pango_attr_foreground_new (color.red, color.green, color.blue);
 
341
                GdkRGBA color;
 
342
 
 
343
                gtk_style_context_get_color (style, 0, &color);
 
344
 
 
345
                attr_color = pango_attr_foreground_new (color.red * 0xffff,
 
346
                                                        color.green * 0xffff,
 
347
                                                        color.blue * 0xffff);
339
348
                attr_color->start_index = attr_size->start_index;
340
349
                attr_color->end_index = -1;
341
350
                pango_attr_list_insert (attr_list, attr_color);
349
358
                }
350
359
        } else {
351
360
                const gchar *status = priv->status;
 
361
                gboolean on_a_phone = FALSE;
352
362
 
353
363
                if (EMP_STR_EMPTY (priv->status)) {
354
364
                        status = empathy_presence_get_default_message (priv->presence_type);
355
365
                }
356
366
 
 
367
                if (!priv->is_group && priv->types != NULL && g_strv_length (priv->types) > 0
 
368
                    && !tp_strdiff (priv->types[0], "phone")) {
 
369
                        on_a_phone = TRUE;
 
370
                        /* We want the phone black. */
 
371
                        if (attr_color)
 
372
                                attr_color->start_index += 3;
 
373
                }
 
374
 
357
375
                if (status == NULL)
358
376
                        str = g_strdup (priv->name);
359
377
                else
360
 
                        str = g_strdup_printf ("%s\n%s", priv->name, status);
 
378
                        str = g_strdup_printf ("%s\n%s%s", priv->name,
 
379
                                               on_a_phone ? "☎  " : "",
 
380
                                               status);
361
381
        }
362
382
 
363
383
        g_object_set (cell,