|
| 1 | +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- |
| 2 | + * |
| 3 | + * Copyright (C) 2006-2011 Richard Hughes <richard@hughsie.com> |
| 4 | + * |
| 5 | + * Licensed under the GNU General Public License Version 2 |
| 6 | + * |
| 7 | + * This program is free software; you can redistribute it and/or modify |
| 8 | + * it under the terms of the GNU General Public License as published by |
| 9 | + * the Free Software Foundation; either version 2 of the License, or |
| 10 | + * (at your option) any later version. |
| 11 | + * |
| 12 | + * This program is distributed in the hope that it will be useful, |
| 13 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | + * GNU General Public License for more details. |
| 16 | + * |
| 17 | + * You should have received a copy of the GNU General Public License |
| 18 | + * along with this program; if not, write to the Free Software |
| 19 | + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 20 | + */ |
| 21 | + |
| 22 | +#include "config.h" |
| 23 | + |
| 24 | +#include <string.h> |
| 25 | +#include <unistd.h> |
| 26 | +#include <stdio.h> |
| 27 | +#include <glib.h> |
| 28 | +#include <gio/gio.h> |
| 29 | + |
| 30 | +#include "mate-settings-bus.h" |
| 31 | + |
| 32 | +char * |
| 33 | +mate_settings_get_chassis_type (void) |
| 34 | +{ |
| 35 | + char *ret = NULL; |
| 36 | + GError *error = NULL; |
| 37 | + GVariant *inner; |
| 38 | + GVariant *variant = NULL; |
| 39 | + GDBusConnection *connection; |
| 40 | + |
| 41 | + connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM, |
| 42 | + NULL, |
| 43 | + &error); |
| 44 | + if (connection == NULL) { |
| 45 | + g_warning ("system bus not available: %s", error->message); |
| 46 | + g_error_free (error); |
| 47 | + goto out; |
| 48 | + } |
| 49 | + |
| 50 | + variant = g_dbus_connection_call_sync (connection, |
| 51 | + "org.freedesktop.hostname1", |
| 52 | + "/org/freedesktop/hostname1", |
| 53 | + "org.freedesktop.DBus.Properties", |
| 54 | + "Get", |
| 55 | + g_variant_new ("(ss)", |
| 56 | + "org.freedesktop.hostname1", |
| 57 | + "Chassis"), |
| 58 | + NULL, |
| 59 | + G_DBUS_CALL_FLAGS_NONE, |
| 60 | + -1, |
| 61 | + NULL, |
| 62 | + &error); |
| 63 | + if (variant == NULL) { |
| 64 | + g_debug ("Failed to get property '%s': %s", "Chassis", error->message); |
| 65 | + g_error_free (error); |
| 66 | + goto out; |
| 67 | + } |
| 68 | + |
| 69 | + g_variant_get (variant, "(v)", &inner); |
| 70 | + ret = g_variant_dup_string (inner, NULL); |
| 71 | + g_debug ("Get property '%s': %s", "Chassis", ret); |
| 72 | + g_variant_unref (inner); |
| 73 | +out: |
| 74 | + g_clear_object (&connection); |
| 75 | + g_clear_pointer (&variant, g_variant_unref); |
| 76 | + return ret; |
| 77 | +} |
0 commit comments