~kroq-gar78/ubuntu/precise/gnome-control-center/fix-885947

« back to all changes in this revision

Viewing changes to panels/info/cc-info-panel.c

  • Committer: Bazaar Package Importer
  • Author(s): Rodrigo Moya
  • Date: 2011-05-17 10:47:27 UTC
  • mfrom: (0.1.11 experimental) (1.1.45 upstream)
  • Revision ID: james.westby@ubuntu.com-20110517104727-lqel6m8vhfw5jby1
Tags: 1:3.0.1.1-1ubuntu1
* Rebase on Debian, remaining Ubuntu changes:
* debian/control:
  - Build-Depend on hardening-wrapper, dpkg-dev and dh-autoreconf
  - Add dependency on ubuntu-system-service
  - Remove dependency on gnome-icon-theme-symbolic
  - Move dependency on apg, gnome-icon-theme-symbolic and accountsservice to
    be a Recommends: until we get them in main
* debian/rules:
  - Use autoreconf
  - Add binary-post-install rule for gnome-control-center-data
  - Run dh-autoreconf
* debian/gnome-control-center.dirs:
* debian/gnome-control-center.links:
  - Add a link to the control center shell for indicators
* debian/patches/00_disable-nm.patch:
  - Temporary patch to disable building with NetworkManager until we get
    the new one in the archive
* debian/patches/01_git_remove_gettext_calls.patch:
  - Remove calls to AM_GNU_GETTEXT, IT_PROG_INTLTOOL should be enough
* debian/patches/01_git_kill_warning.patch:
  - Kill warning
* debian/patches/50_ubuntu_systemwide_prefs.patch:
  - Ubuntu specific proxy preferences
* debian/patches/51_ubuntu_system_keyboard.patch:
  - Implement the global keyboard spec at https://wiki.ubuntu.com/DefaultKeyboardSettings

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
 
2
 *
 
3
 * Copyright (C) 2010 Red Hat, Inc
 
4
 * Copyright (C) 2008 William Jon McCann <jmccann@redhat.com>
 
5
 *
 
6
 * This program is free software; you can redistribute it and/or modify
 
7
 * it under the terms of the GNU General Public License as published by
 
8
 * the Free Software Foundation; either version 2 of the License, or
 
9
 * (at your option) any later version.
 
10
 *
 
11
 * This program is distributed in the hope that it will be useful,
 
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 * GNU General Public License for more details.
 
15
 *
 
16
 * You should have received a copy of the GNU General Public License
 
17
 * along with this program; if not, write to the Free Software
 
18
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
19
 *
 
20
 */
 
21
 
 
22
#include <config.h>
 
23
 
 
24
#include "cc-info-panel.h"
 
25
 
 
26
#include <sys/vfs.h>
 
27
 
 
28
#include <glib.h>
 
29
#include <glib/gi18n.h>
 
30
#include <gio/gio.h>
 
31
#include <gio/gunixmounts.h>
 
32
 
 
33
#include <glibtop/fsusage.h>
 
34
#include <glibtop/mountlist.h>
 
35
#include <glibtop/mem.h>
 
36
#include <glibtop/sysinfo.h>
 
37
 
 
38
#define GNOME_SESSION_MANAGER_SCHEMA        "org.gnome.desktop.session"
 
39
#define KEY_SESSION_NAME          "session-name"
 
40
 
 
41
#define WID(b, w) (GtkWidget *) gtk_builder_get_object (b, w)
 
42
 
 
43
G_DEFINE_DYNAMIC_TYPE (CcInfoPanel, cc_info_panel, CC_TYPE_PANEL)
 
44
 
 
45
#define INFO_PANEL_PRIVATE(o) \
 
46
  (G_TYPE_INSTANCE_GET_PRIVATE ((o), CC_TYPE_INFO_PANEL, CcInfoPanelPrivate))
 
47
 
 
48
typedef struct {
 
49
  /* Will be one of the other two below, or "Unknown" */ 
 
50
  const char *hardware_string;
 
51
 
 
52
  char *xorg_vesa_hardware;
 
53
  char *glx_renderer;
 
54
} GraphicsData;
 
55
 
 
56
struct _CcInfoPanelPrivate
 
57
{
 
58
  GtkBuilder    *builder;
 
59
  char          *gnome_version;
 
60
  char          *gnome_distributor;
 
61
  char          *gnome_date;
 
62
  gboolean       updates_available;
 
63
  gboolean       is_fallback;
 
64
 
 
65
  /* Free space */
 
66
  GList         *primary_mounts;
 
67
  guint64        total_bytes;
 
68
  GCancellable  *cancellable;
 
69
 
 
70
  GDBusConnection     *session_bus;
 
71
  GDBusProxy    *pk_proxy;
 
72
  GDBusProxy    *pk_transaction_proxy;
 
73
  GSettings     *session_settings;
 
74
 
 
75
  GraphicsData  *graphics_data;
 
76
};
 
77
 
 
78
static void get_primary_disc_info_start (CcInfoPanel *self);
 
79
 
 
80
typedef struct
 
81
{
 
82
  char *major;
 
83
  char *minor;
 
84
  char *micro;
 
85
  char *distributor;
 
86
  char *date;
 
87
  char **current;
 
88
} VersionData;
 
89
 
 
90
static void
 
91
version_start_element_handler (GMarkupParseContext      *ctx,
 
92
                               const char               *element_name,
 
93
                               const char              **attr_names,
 
94
                               const char              **attr_values,
 
95
                               gpointer                  user_data,
 
96
                               GError                  **error)
 
97
{
 
98
  VersionData *data = user_data;
 
99
  if (g_str_equal (element_name, "platform"))
 
100
    data->current = &data->major;
 
101
  else if (g_str_equal (element_name, "minor"))
 
102
    data->current = &data->minor;
 
103
  else if (g_str_equal (element_name, "micro"))
 
104
    data->current = &data->micro;
 
105
  else if (g_str_equal (element_name, "distributor"))
 
106
    data->current = &data->distributor;
 
107
  else if (g_str_equal (element_name, "date"))
 
108
    data->current = &data->date;
 
109
  else
 
110
    data->current = NULL;
 
111
}
 
112
 
 
113
static void
 
114
version_end_element_handler (GMarkupParseContext      *ctx,
 
115
                             const char               *element_name,
 
116
                             gpointer                  user_data,
 
117
                             GError                  **error)
 
118
{
 
119
  VersionData *data = user_data;
 
120
  data->current = NULL;
 
121
}
 
122
 
 
123
static void
 
124
version_text_handler (GMarkupParseContext *ctx,
 
125
                      const char          *text,
 
126
                      gsize                text_len,
 
127
                      gpointer             user_data,
 
128
                      GError             **error)
 
129
{
 
130
  VersionData *data = user_data;
 
131
  if (data->current != NULL)
 
132
    *data->current = g_strstrip (g_strdup (text));
 
133
}
 
134
 
 
135
static gboolean
 
136
load_gnome_version (char **version,
 
137
                    char **distributor,
 
138
                    char **date)
 
139
{
 
140
  GMarkupParser version_parser = {
 
141
    version_start_element_handler,
 
142
    version_end_element_handler,
 
143
    version_text_handler,
 
144
    NULL,
 
145
    NULL,
 
146
  };
 
147
  GError              *error;
 
148
  GMarkupParseContext *ctx;
 
149
  char                *contents;
 
150
  gsize                length;
 
151
  VersionData         *data;
 
152
  gboolean             ret;
 
153
 
 
154
  ret = FALSE;
 
155
 
 
156
  error = NULL;
 
157
  if (!g_file_get_contents (DATADIR "/gnome/gnome-version.xml",
 
158
                            &contents,
 
159
                            &length,
 
160
                            &error))
 
161
    return FALSE;
 
162
 
 
163
  data = g_new0 (VersionData, 1);
 
164
  ctx = g_markup_parse_context_new (&version_parser, 0, data, NULL);
 
165
 
 
166
  if (!g_markup_parse_context_parse (ctx, contents, length, &error))
 
167
    {
 
168
      g_warning ("Invalid version file: '%s'", error->message);
 
169
    }
 
170
  else
 
171
    {
 
172
      if (version != NULL)
 
173
        *version = g_strdup_printf ("%s.%s.%s", data->major, data->minor, data->micro);
 
174
      if (distributor != NULL)
 
175
        *distributor = g_strdup (data->distributor);
 
176
      if (date != NULL)
 
177
        *date = g_strdup (data->date);
 
178
 
 
179
      ret = TRUE;
 
180
    }
 
181
 
 
182
  g_markup_parse_context_free (ctx);
 
183
  g_free (data->major);
 
184
  g_free (data->minor);
 
185
  g_free (data->micro);
 
186
  g_free (data->distributor);
 
187
  g_free (data->date);
 
188
  g_free (data);
 
189
  g_free (contents);
 
190
 
 
191
  return ret;
 
192
};
 
193
 
 
194
typedef struct
 
195
{
 
196
  char *regex;
 
197
  char *replacement;
 
198
} ReplaceStrings;
 
199
 
 
200
static char *
 
201
prettify_info (const char *info)
 
202
{
 
203
  char *pretty;
 
204
  int   i;
 
205
  static const ReplaceStrings rs[] = {
 
206
    { "Mesa DRI ", ""},
 
207
    { "Intel[(]R[)]", "Intel<sup>\302\256</sup>"},
 
208
    { "Core[(]TM[)]", "Core<sup>\342\204\242</sup>"},
 
209
    { "Atom[(]TM[)]", "Atom<sup>\342\204\242</sup>"},
 
210
    { "Graphics Controller", "Graphics"},
 
211
  };
 
212
 
 
213
  pretty = g_markup_escape_text (info, -1);
 
214
 
 
215
  for (i = 0; i < G_N_ELEMENTS (rs); i++)
 
216
    {
 
217
      GError *error;
 
218
      GRegex *re;
 
219
      char   *new;
 
220
 
 
221
      error = NULL;
 
222
 
 
223
      re = g_regex_new (rs[i].regex, 0, 0, &error);
 
224
      if (re == NULL)
 
225
        {
 
226
          g_warning ("Error building regex: %s", error->message);
 
227
          g_error_free (error);
 
228
          continue;
 
229
        }
 
230
 
 
231
      new = g_regex_replace_literal (re,
 
232
                                     pretty,
 
233
                                     -1,
 
234
                                     0,
 
235
                                     rs[i].replacement,
 
236
                                     0,
 
237
                                     &error);
 
238
 
 
239
      g_regex_unref (re);
 
240
 
 
241
      if (error != NULL)
 
242
        {
 
243
          g_warning ("Error replacing %s: %s", rs[i].regex, error->message);
 
244
          g_error_free (error);
 
245
          continue;
 
246
        }
 
247
 
 
248
      g_free (pretty);
 
249
      pretty = new;
 
250
    }
 
251
 
 
252
  return pretty;
 
253
}
 
254
 
 
255
static void
 
256
graphics_data_free (GraphicsData *gdata)
 
257
{
 
258
  g_free (gdata->xorg_vesa_hardware);
 
259
  g_free (gdata->glx_renderer);
 
260
  g_slice_free (GraphicsData, gdata);
 
261
}
 
262
 
 
263
static char *
 
264
get_graphics_data_glx_renderer (void)
 
265
{
 
266
  GError     *error;
 
267
  GRegex     *re;
 
268
  GMatchInfo *match_info;
 
269
  char       *output;
 
270
  char       *result;
 
271
  GString    *info;
 
272
 
 
273
  info = g_string_new (NULL);
 
274
 
 
275
  error = NULL;
 
276
  g_spawn_command_line_sync ("glxinfo -l", &output, NULL, NULL, &error);
 
277
  if (error != NULL)
 
278
    {
 
279
      g_warning ("Unable to get graphics info: %s", error->message);
 
280
      g_error_free (error);
 
281
      return NULL;
 
282
    }
 
283
 
 
284
  re = g_regex_new ("^OpenGL renderer string: (.+)$", G_REGEX_MULTILINE, 0, &error);
 
285
  if (re == NULL)
 
286
    {
 
287
      g_warning ("Error building regex: %s", error->message);
 
288
      g_error_free (error);
 
289
      goto out;
 
290
    }
 
291
 
 
292
  g_regex_match (re, output, 0, &match_info);
 
293
  while (g_match_info_matches (match_info))
 
294
    {
 
295
      char *device;
 
296
 
 
297
      device = g_match_info_fetch (match_info, 1);
 
298
      g_string_append_printf (info, "%s ", device);
 
299
      g_free (device);
 
300
 
 
301
      g_match_info_next (match_info, NULL);
 
302
    }
 
303
  g_match_info_free (match_info);
 
304
  g_regex_unref (re);
 
305
 
 
306
 out:
 
307
  g_free (output);
 
308
  result = prettify_info (info->str);
 
309
  g_string_free (info, TRUE);
 
310
 
 
311
  return result;
 
312
}
 
313
 
 
314
static char *
 
315
get_graphics_data_xorg_vesa_hardware (void)
 
316
{
 
317
  char *display_num;
 
318
  char *log_path;
 
319
  char *log_contents;
 
320
  gsize log_len;
 
321
  GError *error = NULL;
 
322
  GRegex *re;
 
323
  GMatchInfo *match;
 
324
  char *result = NULL;
 
325
 
 
326
  {
 
327
    const char *display;
 
328
 
 
329
    display = g_getenv ("DISPLAY");
 
330
    if (!display)
 
331
      return NULL;
 
332
 
 
333
    re = g_regex_new ("^:([0-9]+)", 0, 0, NULL);
 
334
    g_assert (re != NULL);
 
335
 
 
336
    g_regex_match (re, display, 0, &match);
 
337
 
 
338
    if (!g_match_info_matches (match))
 
339
      {
 
340
        g_regex_unref (re);
 
341
        g_match_info_free (match);
 
342
        return NULL;
 
343
      }
 
344
 
 
345
    display_num = g_match_info_fetch (match, 1);
 
346
 
 
347
    g_regex_unref (re);
 
348
    re = NULL;
 
349
    g_match_info_free (match);
 
350
    match = NULL;
 
351
  }
 
352
 
 
353
  log_path = g_strdup_printf ("/var/log/Xorg.%s.log", display_num);
 
354
  g_free (display_num);
 
355
  log_contents = NULL;
 
356
  g_file_get_contents (log_path, &log_contents, &log_len, &error);
 
357
  g_free (log_path);
 
358
  if (!log_contents)
 
359
    return NULL;
 
360
 
 
361
  re = g_regex_new ("VESA VBE OEM Product: (.*)$", G_REGEX_MULTILINE, 0, NULL);
 
362
  g_assert (re != NULL);
 
363
 
 
364
  g_regex_match (re, log_contents, 0, &match);
 
365
  if (g_match_info_matches (match))
 
366
    {
 
367
      char *tmp;
 
368
      char *pretty_tmp;
 
369
      tmp = g_match_info_fetch (match, 1);
 
370
      pretty_tmp = prettify_info (tmp);
 
371
      g_free (tmp);
 
372
      /* Translators: VESA is an techncial acronym, don't translate it. */
 
373
      result = g_strdup_printf (_("VESA: %s"), pretty_tmp); 
 
374
      g_free (pretty_tmp);
 
375
    }
 
376
  g_match_info_free (match);
 
377
  g_regex_unref (re);
 
378
 
 
379
  return result;
 
380
}
 
381
 
 
382
static GraphicsData *
 
383
get_graphics_data (void)
 
384
{
 
385
  GraphicsData *result;
 
386
 
 
387
  result = g_slice_new0 (GraphicsData);
 
388
 
 
389
  result->glx_renderer = get_graphics_data_glx_renderer ();
 
390
  result->xorg_vesa_hardware = get_graphics_data_xorg_vesa_hardware ();
 
391
 
 
392
  if (result->xorg_vesa_hardware != NULL)
 
393
    result->hardware_string = result->xorg_vesa_hardware;
 
394
  else if (result->glx_renderer != NULL)
 
395
    result->hardware_string = result->glx_renderer;
 
396
  else
 
397
    result->hardware_string = _("Unknown");
 
398
 
 
399
  return result;
 
400
}
 
401
 
 
402
static gboolean
 
403
get_current_is_fallback (CcInfoPanel  *self)
 
404
{
 
405
  GError   *error;
 
406
  GVariant *reply;
 
407
  GVariant *reply_str;
 
408
  gboolean  is_fallback;
 
409
 
 
410
  error = NULL;
 
411
  if (!(reply = g_dbus_connection_call_sync (self->priv->session_bus,
 
412
                                             "org.gnome.SessionManager",
 
413
                                             "/org/gnome/SessionManager",
 
414
                                             "org.freedesktop.DBus.Properties",
 
415
                                             "Get",
 
416
                                             g_variant_new ("(ss)", "org.gnome.SessionManager", "session-name"),
 
417
                                             (GVariantType*)"(v)",
 
418
                                             0,
 
419
                                             -1,
 
420
                                             NULL, &error)))
 
421
    {
 
422
      g_warning ("Failed to get fallback mode: %s", error->message);
 
423
      g_clear_error (&error);
 
424
      return FALSE;
 
425
    }
 
426
 
 
427
  g_variant_get (reply, "(v)", &reply_str);
 
428
  is_fallback = g_strcmp0 ("gnome-fallback", g_variant_get_string (reply_str, NULL)) == 0;
 
429
  g_variant_unref (reply_str);
 
430
  g_variant_unref (reply);
 
431
 
 
432
  return is_fallback;
 
433
}
 
434
 
 
435
static void
 
436
cc_info_panel_get_property (GObject    *object,
 
437
                            guint       property_id,
 
438
                            GValue     *value,
 
439
                            GParamSpec *pspec)
 
440
{
 
441
  switch (property_id)
 
442
    {
 
443
    default:
 
444
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
 
445
    }
 
446
}
 
447
 
 
448
static void
 
449
cc_info_panel_set_property (GObject      *object,
 
450
                            guint         property_id,
 
451
                            const GValue *value,
 
452
                            GParamSpec   *pspec)
 
453
{
 
454
  switch (property_id)
 
455
    {
 
456
    default:
 
457
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
 
458
    }
 
459
}
 
460
 
 
461
static void
 
462
cc_info_panel_dispose (GObject *object)
 
463
{
 
464
  CcInfoPanelPrivate *priv = CC_INFO_PANEL (object)->priv;
 
465
 
 
466
  if (priv->builder != NULL)
 
467
    {
 
468
      g_object_unref (priv->builder);
 
469
      priv->builder = NULL;
 
470
    }
 
471
 
 
472
  if (priv->pk_proxy != NULL)
 
473
    {
 
474
      g_object_unref (priv->pk_proxy);
 
475
      priv->pk_proxy = NULL;
 
476
    }
 
477
 
 
478
  if (priv->pk_transaction_proxy != NULL)
 
479
    {
 
480
      g_object_unref (priv->pk_transaction_proxy);
 
481
      priv->pk_transaction_proxy = NULL;
 
482
    }
 
483
 
 
484
  if (priv->graphics_data != NULL)
 
485
    {
 
486
      graphics_data_free (priv->graphics_data);
 
487
      priv->graphics_data = NULL;
 
488
    }
 
489
 
 
490
  G_OBJECT_CLASS (cc_info_panel_parent_class)->dispose (object);
 
491
}
 
492
 
 
493
static void
 
494
cc_info_panel_finalize (GObject *object)
 
495
{
 
496
  CcInfoPanelPrivate *priv = CC_INFO_PANEL (object)->priv;
 
497
 
 
498
  if (priv->cancellable != NULL)
 
499
    {
 
500
      g_cancellable_cancel (priv->cancellable);
 
501
      priv->cancellable = NULL;
 
502
    }
 
503
  g_free (priv->gnome_version);
 
504
  g_free (priv->gnome_date);
 
505
  g_free (priv->gnome_distributor);
 
506
 
 
507
  G_OBJECT_CLASS (cc_info_panel_parent_class)->finalize (object);
 
508
}
 
509
 
 
510
static void
 
511
cc_info_panel_class_init (CcInfoPanelClass *klass)
 
512
{
 
513
  GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
514
 
 
515
  g_type_class_add_private (klass, sizeof (CcInfoPanelPrivate));
 
516
 
 
517
  object_class->get_property = cc_info_panel_get_property;
 
518
  object_class->set_property = cc_info_panel_set_property;
 
519
  object_class->dispose = cc_info_panel_dispose;
 
520
  object_class->finalize = cc_info_panel_finalize;
 
521
}
 
522
 
 
523
static void
 
524
cc_info_panel_class_finalize (CcInfoPanelClass *klass)
 
525
{
 
526
}
 
527
 
 
528
static char *
 
529
get_os_type (void)
 
530
{
 
531
  int bits;
 
532
 
 
533
  if (GLIB_SIZEOF_VOID_P == 8)
 
534
    bits = 64;
 
535
  else
 
536
    bits = 32;
 
537
 
 
538
  /* translators: This is the type of architecture, for example:
 
539
   * "64-bit" or "32-bit" */
 
540
  return g_strdup_printf (_("%d-bit"), bits);
 
541
}
 
542
 
 
543
#define KILOBYTE_FACTOR (G_GOFFSET_CONSTANT (1000))
 
544
#define MEGABYTE_FACTOR (KILOBYTE_FACTOR * KILOBYTE_FACTOR)
 
545
#define GIGABYTE_FACTOR (MEGABYTE_FACTOR * KILOBYTE_FACTOR)
 
546
#define TERABYTE_FACTOR (GIGABYTE_FACTOR * KILOBYTE_FACTOR)
 
547
#define PETABYTE_FACTOR (TERABYTE_FACTOR * KILOBYTE_FACTOR)
 
548
#define EXABYTE_FACTOR  (PETABYTE_FACTOR * KILOBYTE_FACTOR)
 
549
 
 
550
static char *
 
551
format_size_for_display (goffset size)
 
552
{
 
553
  if (size < (goffset) KILOBYTE_FACTOR)
 
554
    return g_strdup_printf (g_dngettext(NULL, "%u byte", "%u bytes",(guint) size), (guint) size);
 
555
  else
 
556
    {
 
557
      gdouble displayed_size;
 
558
 
 
559
      if (size < (goffset) MEGABYTE_FACTOR)
 
560
        {
 
561
          displayed_size = (gdouble) size / (gdouble) KILOBYTE_FACTOR;
 
562
          return g_strdup_printf (_("%.1f KB"), displayed_size);
 
563
        }
 
564
      else if (size < (goffset) GIGABYTE_FACTOR)
 
565
        {
 
566
          displayed_size = (gdouble) size / (gdouble) MEGABYTE_FACTOR;
 
567
          return g_strdup_printf (_("%.1f MB"), displayed_size);
 
568
        }
 
569
      else if (size < (goffset) TERABYTE_FACTOR)
 
570
        {
 
571
          displayed_size = (gdouble) size / (gdouble) GIGABYTE_FACTOR;
 
572
          return g_strdup_printf (_("%.1f GB"), displayed_size);
 
573
        }
 
574
      else if (size < (goffset) PETABYTE_FACTOR)
 
575
        {
 
576
          displayed_size = (gdouble) size / (gdouble) TERABYTE_FACTOR;
 
577
          return g_strdup_printf (_("%.1f TB"), displayed_size);
 
578
        }
 
579
      else if (size < (goffset) EXABYTE_FACTOR)
 
580
        {
 
581
          displayed_size = (gdouble) size / (gdouble) PETABYTE_FACTOR;
 
582
          return g_strdup_printf (_("%.1f PB"), displayed_size);
 
583
        }
 
584
      else
 
585
        {
 
586
          displayed_size = (gdouble) size / (gdouble) EXABYTE_FACTOR;
 
587
          return g_strdup_printf (_("%.1f EB"), displayed_size);
 
588
        }
 
589
    }
 
590
}
 
591
 
 
592
static void
 
593
query_done (GFile        *file,
 
594
            GAsyncResult *res,
 
595
            CcInfoPanel  *self)
 
596
{
 
597
  GFileInfo *info;
 
598
  GError *error = NULL;
 
599
 
 
600
  self->priv->cancellable = NULL;
 
601
  info = g_file_query_filesystem_info_finish (file, res, &error);
 
602
  if (info == NULL)
 
603
    {
 
604
      char *path;
 
605
      path = g_file_get_path (file);
 
606
      g_warning ("Failed to get filesystem free space for '%s': %s", path, error->message);
 
607
      g_free (path);
 
608
      g_error_free (error);
 
609
      return;
 
610
    }
 
611
 
 
612
  self->priv->total_bytes += g_file_info_get_attribute_uint64 (info, G_FILE_ATTRIBUTE_FILESYSTEM_FREE);
 
613
  g_object_unref (info);
 
614
 
 
615
  /* And onto the next element */
 
616
  get_primary_disc_info_start (self);
 
617
}
 
618
 
 
619
static void
 
620
get_primary_disc_info_start (CcInfoPanel *self)
 
621
{
 
622
  GUnixMountEntry *mount;
 
623
  GFile *file;
 
624
 
 
625
  if (self->priv->primary_mounts == NULL)
 
626
    {
 
627
      char *size;
 
628
      GtkWidget *widget;
 
629
 
 
630
      size = format_size_for_display (self->priv->total_bytes);
 
631
      widget = WID (self->priv->builder, "disk_label");
 
632
      gtk_label_set_text (GTK_LABEL (widget), size);
 
633
      g_free (size);
 
634
 
 
635
      return;
 
636
    }
 
637
 
 
638
  mount = self->priv->primary_mounts->data;
 
639
  self->priv->primary_mounts = g_list_remove (self->priv->primary_mounts, mount);
 
640
  file = g_file_new_for_path (g_unix_mount_get_mount_path (mount));
 
641
  g_unix_mount_free (mount);
 
642
 
 
643
  self->priv->cancellable = g_cancellable_new ();
 
644
 
 
645
  g_file_query_filesystem_info_async (file,
 
646
                                      G_FILE_ATTRIBUTE_FILESYSTEM_FREE,
 
647
                                      0,
 
648
                                      self->priv->cancellable,
 
649
                                      (GAsyncReadyCallback) query_done,
 
650
                                      self);
 
651
  g_object_unref (file);
 
652
}
 
653
 
 
654
static void
 
655
get_primary_disc_info (CcInfoPanel *self)
 
656
{
 
657
  GList        *points;
 
658
  GList        *p;
 
659
 
 
660
  points = g_unix_mount_points_get (NULL);
 
661
  for (p = points; p != NULL; p = p->next)
 
662
    {
 
663
      GUnixMountEntry *mount = p->data;
 
664
      const char *mount_path;
 
665
 
 
666
      mount_path = g_unix_mount_get_mount_path (mount);
 
667
 
 
668
      if (g_str_has_prefix (mount_path, "/media/")
 
669
          || g_str_has_prefix (mount_path, g_get_home_dir ()))
 
670
        {
 
671
          g_unix_mount_free (mount);
 
672
          continue;
 
673
        }
 
674
 
 
675
      self->priv->primary_mounts = g_list_prepend (self->priv->primary_mounts, mount);
 
676
    }
 
677
  g_list_free (points);
 
678
 
 
679
  get_primary_disc_info_start (self);
 
680
}
 
681
 
 
682
static char *
 
683
remove_duplicate_whitespace (const char *old)
 
684
{
 
685
  char   *new;
 
686
  GRegex *re;
 
687
  GError *error;
 
688
 
 
689
  error = NULL;
 
690
  re = g_regex_new ("[ \t\n\r]+", G_REGEX_MULTILINE, 0, &error);
 
691
  if (re == NULL)
 
692
    {
 
693
      g_warning ("Error building regex: %s", error->message);
 
694
      g_error_free (error);
 
695
      return g_strdup (old);
 
696
    }
 
697
  new = g_regex_replace (re,
 
698
                         old,
 
699
                         -1,
 
700
                         0,
 
701
                         " ",
 
702
                         0,
 
703
                         &error);
 
704
  g_regex_unref (re);
 
705
  if (new == NULL)
 
706
    {
 
707
      g_warning ("Error replacing string: %s", error->message);
 
708
      g_error_free (error);
 
709
      return g_strdup (old);
 
710
    }
 
711
 
 
712
  return new;
 
713
}
 
714
 
 
715
 
 
716
static char *
 
717
get_cpu_info (const glibtop_sysinfo *info)
 
718
{
 
719
  GHashTable    *counts;
 
720
  GString       *cpu;
 
721
  char          *ret;
 
722
  GHashTableIter iter;
 
723
  gpointer       key, value;
 
724
  int            i;
 
725
  int            j;
 
726
 
 
727
  counts = g_hash_table_new (g_str_hash, g_str_equal);
 
728
 
 
729
  /* count duplicates */
 
730
  for (i = 0; i != info->ncpu; ++i)
 
731
    {
 
732
      const char * const keys[] = { "model name", "cpu" };
 
733
      char *model;
 
734
      int  *count;
 
735
 
 
736
      model = NULL;
 
737
 
 
738
      for (j = 0; model == NULL && j != G_N_ELEMENTS (keys); ++j)
 
739
        {
 
740
          model = g_hash_table_lookup (info->cpuinfo[i].values,
 
741
                                       keys[j]);
 
742
        }
 
743
 
 
744
      if (model == NULL)
 
745
          model = _("Unknown model");
 
746
 
 
747
      count = g_hash_table_lookup (counts, model);
 
748
      if (count == NULL)
 
749
        g_hash_table_insert (counts, model, GINT_TO_POINTER (1));
 
750
      else
 
751
        g_hash_table_replace (counts, model, GINT_TO_POINTER (GPOINTER_TO_INT (count) + 1));
 
752
    }
 
753
 
 
754
  cpu = g_string_new (NULL);
 
755
  g_hash_table_iter_init (&iter, counts);
 
756
  while (g_hash_table_iter_next (&iter, &key, &value))
 
757
    {
 
758
      char *stripped;
 
759
      int   count;
 
760
 
 
761
      count = GPOINTER_TO_INT (value);
 
762
      stripped = remove_duplicate_whitespace ((const char *)key);
 
763
      if (count > 1)
 
764
        g_string_append_printf (cpu, "%s \303\227 %d ", stripped, count);
 
765
      else
 
766
        g_string_append_printf (cpu, "%s ", stripped);
 
767
      g_free (stripped);
 
768
    }
 
769
 
 
770
  g_hash_table_destroy (counts);
 
771
 
 
772
  ret = prettify_info (cpu->str);
 
773
  g_string_free (cpu, TRUE);
 
774
 
 
775
  return ret;
 
776
}
 
777
 
 
778
static void
 
779
on_section_changed (GtkTreeSelection  *selection,
 
780
                    gpointer           data)
 
781
{
 
782
  CcInfoPanel *self = CC_INFO_PANEL (data);
 
783
  GtkTreeIter iter;
 
784
  GtkTreeModel *model;
 
785
  GtkTreePath *path;
 
786
  gint *indices;
 
787
  int index;
 
788
 
 
789
  if (!gtk_tree_selection_get_selected (selection, &model, &iter))
 
790
    return;
 
791
 
 
792
  path = gtk_tree_model_get_path (model, &iter);
 
793
 
 
794
  indices = gtk_tree_path_get_indices (path);
 
795
  index = indices[0];
 
796
 
 
797
  if (index >= 0)
 
798
    {
 
799
      g_object_set (G_OBJECT (WID (self->priv->builder, "notebook")),
 
800
                    "page", index, NULL);
 
801
    }
 
802
 
 
803
  gtk_tree_path_free (path);
 
804
}
 
805
 
 
806
static gboolean
 
807
switch_fallback_get_mapping (GValue    *value,
 
808
                             GVariant  *variant,
 
809
                             gpointer   data)
 
810
{
 
811
  const char *setting;
 
812
 
 
813
  setting = g_variant_get_string (variant, NULL);
 
814
  g_value_set_boolean (value, strcmp (setting, "gnome") != 0);
 
815
  return TRUE;
 
816
}
 
817
 
 
818
static void
 
819
toggle_fallback_warning_label (CcInfoPanel *self,
 
820
                               gboolean     visible)
 
821
{
 
822
  GtkWidget  *widget;
 
823
  const char *text;
 
824
 
 
825
  widget = WID (self->priv->builder, "graphics_logout_warning_label");
 
826
 
 
827
  if (self->priv->is_fallback)
 
828
    text = _("The next login will attempt to use the standard experience.");
 
829
  else
 
830
    text = _("The next login will use the fallback mode intended for unsupported graphics hardware.");
 
831
 
 
832
  gtk_label_set_text (GTK_LABEL (widget), text);
 
833
 
 
834
  if (visible)
 
835
    gtk_widget_show (widget);
 
836
  else
 
837
    gtk_widget_hide (widget);
 
838
}
 
839
 
 
840
static GVariant *
 
841
switch_fallback_set_mapping (const GValue        *value,
 
842
                             const GVariantType  *expected_type,
 
843
                             gpointer             data)
 
844
{
 
845
  CcInfoPanel *self = data;
 
846
  gboolean     is_set;
 
847
 
 
848
  is_set = g_value_get_boolean (value);
 
849
  if (is_set != self->priv->is_fallback)
 
850
    toggle_fallback_warning_label (self, TRUE);
 
851
  else
 
852
    toggle_fallback_warning_label (self, FALSE);
 
853
 
 
854
  return g_variant_new_string (is_set ? "gnome-fallback" : "gnome");
 
855
}
 
856
 
 
857
static void
 
858
info_panel_setup_graphics (CcInfoPanel  *self)
 
859
{
 
860
  GtkWidget *widget;
 
861
  GtkSwitch *sw;
 
862
  char *text;
 
863
 
 
864
  widget = WID (self->priv->builder, "graphics_driver_label");
 
865
  gtk_label_set_markup (GTK_LABEL (widget), self->priv->graphics_data->hardware_string);
 
866
 
 
867
  self->priv->is_fallback = get_current_is_fallback (self);
 
868
  if (self->priv->is_fallback)
 
869
    {
 
870
      /* translators: The hardware is not able to run GNOME 3's
 
871
       * shell, so we use the GNOME "Fallback" session */
 
872
      text = g_strdup (C_("Experience", "Fallback"));
 
873
    }
 
874
  else
 
875
    {
 
876
      /* translators: The hardware is able to run GNOME 3's
 
877
       * shell, also called "Standard" experience */
 
878
      text = g_strdup (C_("Experience", "Standard"));
 
879
    }
 
880
  widget = WID (self->priv->builder, "graphics_experience_label");
 
881
  gtk_label_set_markup (GTK_LABEL (widget), text ? text : "");
 
882
  g_free (text);
 
883
 
 
884
  widget = WID (self->priv->builder, "graphics_fallback_switch_box");
 
885
  sw = GTK_SWITCH (gtk_switch_new ());
 
886
  g_settings_bind_with_mapping (self->priv->session_settings, KEY_SESSION_NAME,
 
887
                                sw, "active", 0,
 
888
                                switch_fallback_get_mapping,
 
889
                                switch_fallback_set_mapping, self, NULL);
 
890
  gtk_box_pack_start (GTK_BOX (widget), GTK_WIDGET (sw), FALSE, FALSE, 0);
 
891
  gtk_widget_show_all (GTK_WIDGET (sw));
 
892
}
 
893
 
 
894
static void
 
895
default_app_changed (GtkAppChooserButton *button,
 
896
                     CcInfoPanel         *self)
 
897
{
 
898
  GAppInfo *info;
 
899
  char *content_type;
 
900
  GError *error = NULL;
 
901
 
 
902
  info = gtk_app_chooser_get_app_info (GTK_APP_CHOOSER (button));
 
903
  content_type = gtk_app_chooser_get_content_type (GTK_APP_CHOOSER (button));
 
904
  if (g_app_info_set_as_default_for_type (info, content_type, &error) == FALSE)
 
905
    {
 
906
      g_warning ("Failed to set '%s' as the default application for '%s': %s",
 
907
                 g_app_info_get_name (info), content_type, error->message);
 
908
      g_error_free (error);
 
909
      error = NULL;
 
910
    }
 
911
 
 
912
  /* Set https support for the browser as well */
 
913
  if (g_str_equal (content_type, "x-scheme-handler/https"))
 
914
    {
 
915
      if (g_app_info_set_as_default_for_type (info, "x-scheme-handler/https", &error) == FALSE)
 
916
        {
 
917
          g_warning ("Failed to set '%s' as the default application for '%s': %s",
 
918
                     g_app_info_get_name (info), "x-scheme-handler/https", error->message);
 
919
          g_error_free (error);
 
920
        }
 
921
    }
 
922
 
 
923
  g_free (content_type);
 
924
  g_object_unref (info);
 
925
}
 
926
 
 
927
static void
 
928
info_panel_setup_default_app (CcInfoPanel *self,
 
929
                              const char  *content_type,
 
930
                              guint        left_attach,
 
931
                              guint        right_attach,
 
932
                              guint        top_attach,
 
933
                              guint        bottom_attach)
 
934
{
 
935
  GtkWidget *button;
 
936
  GtkWidget *table;
 
937
  GAppInfo  *info;
 
938
  GError    *error = NULL;
 
939
 
 
940
  table = WID (self->priv->builder, "default_apps_table");
 
941
 
 
942
  /* FIXME: We need to do this because GtkAppChooser doesn't
 
943
   * give us the opportunity to select what app should be selected
 
944
   * by default.
 
945
   * https://bugzilla.gnome.org/show_bug.cgi?id=642706 */
 
946
  info = g_app_info_get_default_for_type (content_type, FALSE);
 
947
  if (info != NULL && g_app_info_set_as_last_used_for_type (info, content_type, &error) == FALSE)
 
948
    {
 
949
      g_warning ("Failed to set '%s' as the default application for '%s': %s",
 
950
                 g_app_info_get_name (info), content_type, error->message);
 
951
      g_error_free (error);
 
952
    }
 
953
  if (info != NULL)
 
954
    g_object_unref (info);
 
955
 
 
956
  button = gtk_app_chooser_button_new (content_type);
 
957
  gtk_table_attach (GTK_TABLE (table), button,
 
958
                    left_attach, right_attach,
 
959
                    top_attach, bottom_attach, GTK_FILL, 0, 0, 0);
 
960
  g_signal_connect (G_OBJECT (button), "changed",
 
961
                    G_CALLBACK (default_app_changed), self);
 
962
  gtk_widget_show (button);
 
963
}
 
964
 
 
965
static void
 
966
info_panel_setup_default_apps (CcInfoPanel  *self)
 
967
{
 
968
  info_panel_setup_default_app (self, "x-scheme-handler/http",
 
969
                                1, 2, 0, 1);
 
970
 
 
971
  info_panel_setup_default_app (self, "x-scheme-handler/mailto",
 
972
                                1, 2, 1, 2);
 
973
 
 
974
  info_panel_setup_default_app (self, "text/calendar",
 
975
                                1, 2, 2, 3);
 
976
 
 
977
  info_panel_setup_default_app (self, "audio/x-vorbis+ogg",
 
978
                                1, 2, 3, 4);
 
979
 
 
980
  info_panel_setup_default_app (self, "video/x-ogm+ogg",
 
981
                                1, 2, 4, 5);
 
982
 
 
983
  info_panel_setup_default_app (self, "image/jpeg",
 
984
                                1, 2, 5, 6);
 
985
}
 
986
 
 
987
static void
 
988
info_panel_setup_selector (CcInfoPanel  *self)
 
989
{
 
990
  GtkTreeView *view;
 
991
  GtkListStore *model;
 
992
  GtkTreeSelection *selection;
 
993
  GtkTreeViewColumn *column;
 
994
  GtkCellRenderer *renderer;
 
995
  GtkTreeIter iter;
 
996
  int section_name_column = 0;
 
997
 
 
998
  view = GTK_TREE_VIEW (WID (self->priv->builder, "overview_treeview"));
 
999
  selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (view));
 
1000
 
 
1001
  model = gtk_list_store_new (1, G_TYPE_STRING);
 
1002
  gtk_tree_view_set_model (view, GTK_TREE_MODEL (model));
 
1003
  g_object_unref (model);
 
1004
 
 
1005
  renderer = gtk_cell_renderer_text_new ();
 
1006
  g_object_set (renderer,
 
1007
                "width-chars", 20,
 
1008
                "ellipsize", PANGO_ELLIPSIZE_END,
 
1009
                NULL);
 
1010
  column = gtk_tree_view_column_new_with_attributes (_("Section"),
 
1011
                                                     renderer,
 
1012
                                                     "text", section_name_column,
 
1013
                                                     NULL);
 
1014
  gtk_tree_view_append_column (view, column);
 
1015
 
 
1016
 
 
1017
  gtk_list_store_append (model, &iter);
 
1018
  gtk_list_store_set (model, &iter, section_name_column,
 
1019
                      _("Overview"),
 
1020
                      -1);
 
1021
  gtk_tree_selection_select_iter (selection, &iter);
 
1022
 
 
1023
  gtk_list_store_append (model, &iter);
 
1024
  gtk_list_store_set (model, &iter, section_name_column,
 
1025
                      _("Default Applications"),
 
1026
                      -1);
 
1027
 
 
1028
  gtk_list_store_append (model, &iter);
 
1029
  gtk_list_store_set (model, &iter, section_name_column,
 
1030
                      _("Graphics"),
 
1031
                      -1);
 
1032
 
 
1033
  g_signal_connect (selection, "changed",
 
1034
                    G_CALLBACK (on_section_changed), self);
 
1035
  on_section_changed (selection, self);
 
1036
 
 
1037
  gtk_widget_show_all (GTK_WIDGET (view));
 
1038
}
 
1039
 
 
1040
static void
 
1041
info_panel_setup_overview (CcInfoPanel  *self)
 
1042
{
 
1043
  GtkWidget  *widget;
 
1044
  gboolean    res;
 
1045
  glibtop_mem mem;
 
1046
  const glibtop_sysinfo *info;
 
1047
  char       *text;
 
1048
 
 
1049
  res = load_gnome_version (&self->priv->gnome_version,
 
1050
                            &self->priv->gnome_distributor,
 
1051
                            &self->priv->gnome_date);
 
1052
  if (res)
 
1053
    {
 
1054
      widget = WID (self->priv->builder, "version_label");
 
1055
      text = g_strdup_printf (_("Version %s"), self->priv->gnome_version);
 
1056
      gtk_label_set_text (GTK_LABEL (widget), text);
 
1057
      g_free (text);
 
1058
    }
 
1059
 
 
1060
  glibtop_get_mem (&mem);
 
1061
  text = g_format_size_for_display (mem.total);
 
1062
  widget = WID (self->priv->builder, "memory_label");
 
1063
  gtk_label_set_text (GTK_LABEL (widget), text ? text : "");
 
1064
  g_free (text);
 
1065
 
 
1066
  info = glibtop_get_sysinfo ();
 
1067
 
 
1068
  widget = WID (self->priv->builder, "processor_label");
 
1069
  text = get_cpu_info (info);
 
1070
  gtk_label_set_markup (GTK_LABEL (widget), text ? text : "");
 
1071
  g_free (text);
 
1072
 
 
1073
  widget = WID (self->priv->builder, "os_type_label");
 
1074
  text = get_os_type ();
 
1075
  gtk_label_set_text (GTK_LABEL (widget), text ? text : "");
 
1076
  g_free (text);
 
1077
 
 
1078
  get_primary_disc_info (self);
 
1079
 
 
1080
  widget = WID (self->priv->builder, "graphics_label");
 
1081
  gtk_label_set_markup (GTK_LABEL (widget), self->priv->graphics_data->hardware_string);
 
1082
 
 
1083
  widget = WID (self->priv->builder, "info_vbox");
 
1084
  gtk_widget_reparent (widget, (GtkWidget *) self);
 
1085
}
 
1086
 
 
1087
static void
 
1088
refresh_update_button (CcInfoPanel  *self)
 
1089
{
 
1090
  GtkWidget *widget;
 
1091
 
 
1092
  widget = WID (self->priv->builder, "updates_button");
 
1093
  if (self->priv->updates_available)
 
1094
    gtk_widget_show (widget);
 
1095
  else
 
1096
    gtk_widget_hide (widget);
 
1097
}
 
1098
 
 
1099
static void
 
1100
on_pk_transaction_signal (GDBusProxy *proxy,
 
1101
                          char *sender_name,
 
1102
                          char *signal_name,
 
1103
                          GVariant *parameters,
 
1104
                          CcInfoPanel *self)
 
1105
{
 
1106
  if (g_strcmp0 (signal_name, "Package") == 0)
 
1107
    {
 
1108
      self->priv->updates_available = TRUE;
 
1109
    }
 
1110
  else if (g_strcmp0 (signal_name, "Finished") == 0)
 
1111
    {
 
1112
      refresh_update_button (self);
 
1113
    }
 
1114
  else if (g_strcmp0 (signal_name, "Destroy") == 0)
 
1115
    {
 
1116
      g_object_unref (self->priv->pk_transaction_proxy);
 
1117
      self->priv->pk_transaction_proxy = NULL;
 
1118
    }
 
1119
}
 
1120
 
 
1121
static void
 
1122
on_pk_get_updates_ready (GObject      *source,
 
1123
                         GAsyncResult *res,
 
1124
                         CcInfoPanel  *self)
 
1125
{
 
1126
  GError     *error;
 
1127
  GVariant   *result;
 
1128
 
 
1129
  error = NULL;
 
1130
  result = g_dbus_proxy_call_finish (G_DBUS_PROXY (source), res, &error);
 
1131
  if (result == NULL)
 
1132
    {
 
1133
      g_warning ("Error getting PackageKit updates list: %s", error->message);
 
1134
      g_error_free (error);
 
1135
      return;
 
1136
    }
 
1137
}
 
1138
 
 
1139
static void
 
1140
on_pk_get_tid_ready (GObject      *source,
 
1141
                     GAsyncResult *res,
 
1142
                     CcInfoPanel  *self)
 
1143
{
 
1144
  GError     *error;
 
1145
  GVariant   *result;
 
1146
  char       *tid;
 
1147
 
 
1148
  error = NULL;
 
1149
  result = g_dbus_proxy_call_finish (G_DBUS_PROXY (source), res, &error);
 
1150
  if (result == NULL)
 
1151
    {
 
1152
      g_warning ("Error getting PackageKit transaction ID: %s", error->message);
 
1153
      g_error_free (error);
 
1154
      return;
 
1155
    }
 
1156
 
 
1157
  g_variant_get (result, "(s)", &tid);
 
1158
 
 
1159
  self->priv->pk_transaction_proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
 
1160
                                                                    G_DBUS_PROXY_FLAGS_NONE,
 
1161
                                                                    NULL,
 
1162
                                                                    "org.freedesktop.PackageKit",
 
1163
                                                                    tid,
 
1164
                                                                    "org.freedesktop.PackageKit.Transaction",
 
1165
                                                                    NULL,
 
1166
                                                                    NULL);
 
1167
  g_free (tid);
 
1168
  g_variant_unref (result);
 
1169
 
 
1170
  if (self->priv->pk_transaction_proxy == NULL)
 
1171
    {
 
1172
      g_warning ("Unable to get PackageKit transaction proxy object");
 
1173
      return;
 
1174
    }
 
1175
 
 
1176
  g_signal_connect (self->priv->pk_transaction_proxy,
 
1177
                    "g-signal",
 
1178
                    G_CALLBACK (on_pk_transaction_signal),
 
1179
                    self);
 
1180
 
 
1181
  g_dbus_proxy_call (self->priv->pk_transaction_proxy,
 
1182
                     "GetUpdates",
 
1183
                     g_variant_new ("(s)", "none"),
 
1184
                     G_DBUS_CALL_FLAGS_NONE,
 
1185
                     -1,
 
1186
                     NULL,
 
1187
                     (GAsyncReadyCallback) on_pk_get_updates_ready,
 
1188
                     self);
 
1189
}
 
1190
 
 
1191
static void
 
1192
refresh_updates (CcInfoPanel *self)
 
1193
{
 
1194
  self->priv->updates_available = FALSE;
 
1195
 
 
1196
  g_assert (self->priv->pk_proxy != NULL);
 
1197
  g_dbus_proxy_call (self->priv->pk_proxy,
 
1198
                     "GetTid",
 
1199
                     NULL,
 
1200
                     G_DBUS_CALL_FLAGS_NONE,
 
1201
                     -1,
 
1202
                     NULL,
 
1203
                     (GAsyncReadyCallback) on_pk_get_tid_ready,
 
1204
                     self);
 
1205
}
 
1206
 
 
1207
static void
 
1208
on_pk_signal (GDBusProxy *proxy,
 
1209
              char *sender_name,
 
1210
              char *signal_name,
 
1211
              GVariant *parameters,
 
1212
              CcInfoPanel *self)
 
1213
{
 
1214
  if (g_strcmp0 (signal_name, "UpdatesChanged") == 0)
 
1215
    {
 
1216
      refresh_updates (self);
 
1217
    }
 
1218
}
 
1219
 
 
1220
static void
 
1221
on_updates_button_clicked (GtkWidget   *widget,
 
1222
                           CcInfoPanel *self)
 
1223
{
 
1224
  GError *error;
 
1225
  error = NULL;
 
1226
  g_spawn_command_line_async ("gpk-update-viewer", &error);
 
1227
  if (error != NULL)
 
1228
    {
 
1229
      g_warning ("unable to launch Software Updates: %s", error->message);
 
1230
      g_error_free (error);
 
1231
    }
 
1232
}
 
1233
 
 
1234
static void
 
1235
cc_info_panel_init (CcInfoPanel *self)
 
1236
{
 
1237
  GError *error = NULL;
 
1238
  GtkWidget *widget;
 
1239
 
 
1240
  self->priv = INFO_PANEL_PRIVATE (self);
 
1241
 
 
1242
  self->priv->builder = gtk_builder_new ();
 
1243
 
 
1244
  self->priv->session_settings = g_settings_new (GNOME_SESSION_MANAGER_SCHEMA);
 
1245
 
 
1246
  self->priv->session_bus = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL);
 
1247
 
 
1248
  g_assert (self->priv->session_bus);
 
1249
 
 
1250
  self->priv->pk_proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
 
1251
                                                        G_DBUS_PROXY_FLAGS_NONE,
 
1252
                                                        NULL,
 
1253
                                                        "org.freedesktop.PackageKit",
 
1254
                                                        "/org/freedesktop/PackageKit",
 
1255
                                                        "org.freedesktop.PackageKit",
 
1256
                                                        NULL,
 
1257
                                                        NULL);
 
1258
  if (self->priv->pk_proxy == NULL)
 
1259
    g_warning ("Unable to get PackageKit proxy object");
 
1260
  else
 
1261
    {
 
1262
      g_signal_connect (self->priv->pk_proxy,
 
1263
                        "g-signal",
 
1264
                        G_CALLBACK (on_pk_signal),
 
1265
                        self);
 
1266
      refresh_updates (self);
 
1267
    }
 
1268
 
 
1269
  gtk_builder_add_from_file (self->priv->builder,
 
1270
                             GNOMECC_UI_DIR "/info.ui",
 
1271
                             &error);
 
1272
 
 
1273
  if (error != NULL)
 
1274
    {
 
1275
      g_warning ("Could not load interface file: %s", error->message);
 
1276
      g_error_free (error);
 
1277
      return;
 
1278
    }
 
1279
 
 
1280
  self->priv->graphics_data = get_graphics_data ();
 
1281
 
 
1282
  widget = WID (self->priv->builder, "updates_button");
 
1283
  g_signal_connect (widget, "clicked", G_CALLBACK (on_updates_button_clicked), self);
 
1284
 
 
1285
  info_panel_setup_selector (self);
 
1286
  info_panel_setup_overview (self);
 
1287
  info_panel_setup_default_apps (self);
 
1288
  info_panel_setup_graphics (self);
 
1289
}
 
1290
 
 
1291
void
 
1292
cc_info_panel_register (GIOModule *module)
 
1293
{
 
1294
  cc_info_panel_register_type (G_TYPE_MODULE (module));
 
1295
  g_io_extension_point_implement (CC_SHELL_PANEL_EXTENSION_POINT,
 
1296
                                  CC_TYPE_INFO_PANEL,
 
1297
                                  "info", 0);
 
1298
}
 
1299