Compare commits
8 Commits
46.beta.1
...
unify-host
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9ec876c794 | ||
|
|
188a74ac48 | ||
|
|
53c8d71ce3 | ||
|
|
5f4e398150 | ||
|
|
0c1a30ae79 | ||
|
|
9df12a0e41 | ||
|
|
1e10433089 | ||
|
|
2e264b5d82 |
@@ -20,6 +20,7 @@
|
||||
|
||||
|
||||
#include "cc-common-resources.h"
|
||||
#include "cc-hostname.h"
|
||||
#include "cc-hostname-entry.h"
|
||||
#include "hostname-helper.h"
|
||||
|
||||
@@ -29,7 +30,6 @@ struct _CcHostnameEntry
|
||||
{
|
||||
AdwEntryRow parent;
|
||||
|
||||
GDBusProxy *hostnamed_proxy;
|
||||
guint set_hostname_timeout_source_id;
|
||||
};
|
||||
|
||||
@@ -37,102 +37,15 @@ G_DEFINE_TYPE (CcHostnameEntry, cc_hostname_entry, ADW_TYPE_ENTRY_ROW)
|
||||
|
||||
#define SET_HOSTNAME_TIMEOUT 1
|
||||
|
||||
static void
|
||||
cc_hostname_entry_set_hostname (CcHostnameEntry *self)
|
||||
{
|
||||
g_autofree gchar *hostname = NULL;
|
||||
g_autoptr(GVariant) pretty_result = NULL;
|
||||
g_autoptr(GVariant) static_result = NULL;
|
||||
g_autoptr(GError) pretty_error = NULL;
|
||||
g_autoptr(GError) static_error = NULL;
|
||||
const gchar *text;
|
||||
|
||||
text = gtk_editable_get_text (GTK_EDITABLE (self));
|
||||
|
||||
g_debug ("Setting PrettyHostname to '%s'", text);
|
||||
pretty_result = g_dbus_proxy_call_sync (self->hostnamed_proxy,
|
||||
"SetPrettyHostname",
|
||||
g_variant_new ("(sb)", text, FALSE),
|
||||
G_DBUS_CALL_FLAGS_NONE,
|
||||
-1, NULL, &pretty_error);
|
||||
if (pretty_result == NULL)
|
||||
g_warning ("Could not set PrettyHostname: %s", pretty_error->message);
|
||||
|
||||
/* Set the static hostname */
|
||||
hostname = pretty_hostname_to_static (text, FALSE);
|
||||
g_assert (hostname);
|
||||
|
||||
g_debug ("Setting StaticHostname to '%s'", hostname);
|
||||
static_result = g_dbus_proxy_call_sync (self->hostnamed_proxy,
|
||||
"SetStaticHostname",
|
||||
g_variant_new ("(sb)", hostname, FALSE),
|
||||
G_DBUS_CALL_FLAGS_NONE,
|
||||
-1, NULL, &static_error);
|
||||
if (static_result == NULL)
|
||||
g_warning ("Could not set StaticHostname: %s", static_error->message);
|
||||
}
|
||||
|
||||
static char *
|
||||
get_hostname_property (CcHostnameEntry *self,
|
||||
const char *property)
|
||||
{
|
||||
g_autoptr(GVariant) variant = NULL;
|
||||
|
||||
if (!self->hostnamed_proxy)
|
||||
return g_strdup ("");
|
||||
|
||||
variant = g_dbus_proxy_get_cached_property (self->hostnamed_proxy,
|
||||
property);
|
||||
if (!variant)
|
||||
{
|
||||
g_autoptr(GError) error = NULL;
|
||||
g_autoptr(GVariant) inner = NULL;
|
||||
|
||||
/* Work around systemd-hostname not sending us back
|
||||
* the property value when changing values */
|
||||
variant = g_dbus_proxy_call_sync (self->hostnamed_proxy,
|
||||
"org.freedesktop.DBus.Properties.Get",
|
||||
g_variant_new ("(ss)", "org.freedesktop.hostname1", property),
|
||||
G_DBUS_CALL_FLAGS_NONE,
|
||||
-1,
|
||||
NULL,
|
||||
&error);
|
||||
if (variant == NULL)
|
||||
{
|
||||
g_warning ("Failed to get property '%s': %s", property, error->message);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
g_variant_get (variant, "(v)", &inner);
|
||||
return g_variant_dup_string (inner, NULL);
|
||||
}
|
||||
else
|
||||
{
|
||||
return g_variant_dup_string (variant, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
static char *
|
||||
cc_hostname_entry_get_display_hostname (CcHostnameEntry *self)
|
||||
{
|
||||
g_autofree gchar *str = NULL;
|
||||
|
||||
str = get_hostname_property (self, "PrettyHostname");
|
||||
|
||||
/* Empty strings means that we need to fallback */
|
||||
if (str != NULL &&
|
||||
*str == '\0')
|
||||
return get_hostname_property (self, "Hostname");
|
||||
|
||||
return g_steal_pointer (&str);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
set_hostname_timeout (CcHostnameEntry *self)
|
||||
{
|
||||
const gchar *text = NULL;
|
||||
|
||||
self->set_hostname_timeout_source_id = 0;
|
||||
|
||||
cc_hostname_entry_set_hostname (self);
|
||||
text = gtk_editable_get_text (GTK_EDITABLE (self));
|
||||
cc_hostname_set_hostname (cc_hostname_get_default (), text);
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
@@ -173,8 +86,6 @@ cc_hostname_entry_dispose (GObject *object)
|
||||
set_hostname_timeout (self);
|
||||
}
|
||||
|
||||
g_clear_object (&self->hostnamed_proxy);
|
||||
|
||||
G_OBJECT_CLASS (cc_hostname_entry_parent_class)->dispose (object);
|
||||
}
|
||||
|
||||
@@ -207,25 +118,7 @@ cc_hostname_entry_constructed (GObject *object)
|
||||
gtk_widget_set_sensitive (GTK_WIDGET (self), FALSE);
|
||||
}
|
||||
|
||||
self->hostnamed_proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
|
||||
G_DBUS_PROXY_FLAGS_NONE,
|
||||
NULL,
|
||||
"org.freedesktop.hostname1",
|
||||
"/org/freedesktop/hostname1",
|
||||
"org.freedesktop.hostname1",
|
||||
NULL,
|
||||
&error);
|
||||
|
||||
/* This could only happen if the policy file was installed
|
||||
* but not hostnamed, which points to a system bug */
|
||||
if (self->hostnamed_proxy == NULL)
|
||||
{
|
||||
g_debug ("Couldn't get hostnamed to start, bailing: %s", error->message);
|
||||
return;
|
||||
}
|
||||
|
||||
str = cc_hostname_entry_get_display_hostname (CC_HOSTNAME_ENTRY (self));
|
||||
|
||||
str = cc_hostname_get_display_hostname (cc_hostname_get_default ());
|
||||
if (str != NULL)
|
||||
gtk_editable_set_text (GTK_EDITABLE (self), str);
|
||||
else
|
||||
@@ -256,9 +149,3 @@ cc_hostname_entry_new (void)
|
||||
{
|
||||
return g_object_new (CC_TYPE_HOSTNAME_ENTRY, NULL);
|
||||
}
|
||||
|
||||
gchar*
|
||||
cc_hostname_entry_get_hostname (CcHostnameEntry *entry)
|
||||
{
|
||||
return get_hostname_property (entry, "Hostname");
|
||||
}
|
||||
|
||||
@@ -28,6 +28,5 @@ G_BEGIN_DECLS
|
||||
G_DECLARE_FINAL_TYPE (CcHostnameEntry, cc_hostname_entry, CC, HOSTNAME_ENTRY, AdwEntryRow)
|
||||
|
||||
CcHostnameEntry *cc_hostname_entry_new (void);
|
||||
gchar* cc_hostname_entry_get_hostname (CcHostnameEntry *entry);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
211
panels/common/cc-hostname.c
Normal file
211
panels/common/cc-hostname.c
Normal file
@@ -0,0 +1,211 @@
|
||||
/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* cc-hostname.c
|
||||
*
|
||||
* Copyright 2023 Red Hat Inc
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Author(s):
|
||||
* Felipe Borges <felipeborges@gnome.org>
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
|
||||
#undef G_LOG_DOMAIN
|
||||
#define G_LOG_DOMAIN "cc-hostname"
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#include "cc-hostname.h"
|
||||
#include "hostname-helper.h"
|
||||
#include "shell/cc-object-storage.h"
|
||||
|
||||
#define HOSTNAME_BUS_NAME "org.freedesktop.hostname1"
|
||||
#define HOSTNAME_OBJECT_PATH "/org/freedesktop/hostname1"
|
||||
|
||||
struct _CcHostname
|
||||
{
|
||||
GObject parent_instance;
|
||||
|
||||
GDBusProxy *proxy;
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE (CcHostname, cc_hostname, G_TYPE_OBJECT)
|
||||
|
||||
static void
|
||||
cc_hostname_dispose (GObject *object)
|
||||
{
|
||||
CcHostname *self = CC_HOSTNAME (object);
|
||||
|
||||
g_clear_object (&self->proxy);
|
||||
|
||||
G_OBJECT_CLASS (cc_hostname_parent_class)->dispose (object);
|
||||
}
|
||||
|
||||
static void
|
||||
cc_hostname_constructed (GObject *object)
|
||||
{
|
||||
CcHostname *self = CC_HOSTNAME (object);
|
||||
g_autoptr(GError) error = NULL;
|
||||
|
||||
self->proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
|
||||
G_DBUS_PROXY_FLAGS_NONE,
|
||||
NULL,
|
||||
HOSTNAME_BUS_NAME,
|
||||
HOSTNAME_OBJECT_PATH,
|
||||
HOSTNAME_BUS_NAME,
|
||||
NULL,
|
||||
&error);
|
||||
if (self->proxy == NULL) {
|
||||
g_critical ("Couldn't connect to hostnamed: %s", error->message);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
cc_hostname_init (CcHostname *self)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
cc_hostname_class_init (CcHostnameClass *klass)
|
||||
{
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
||||
|
||||
object_class->constructed = cc_hostname_constructed;
|
||||
object_class->dispose = cc_hostname_dispose;
|
||||
}
|
||||
|
||||
CcHostname *
|
||||
cc_hostname_get_default (void)
|
||||
{
|
||||
g_autoptr(CcHostname) self = NULL;
|
||||
|
||||
if (cc_object_storage_has_object (CC_OBJECT_HOSTNAME)) {
|
||||
self = cc_object_storage_get_object (CC_OBJECT_HOSTNAME);
|
||||
} else {
|
||||
self = g_object_new (CC_TYPE_HOSTNAME, NULL);
|
||||
cc_object_storage_add_object (CC_OBJECT_HOSTNAME, self);
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
gchar *
|
||||
cc_hostname_get_property (CcHostname *self,
|
||||
const gchar *property)
|
||||
{
|
||||
g_autoptr(GVariant) variant = NULL;
|
||||
g_autoptr(GVariant) inner = NULL;
|
||||
g_autoptr(GError) error = NULL;
|
||||
|
||||
g_return_val_if_fail (CC_IS_HOSTNAME (self), NULL);
|
||||
g_return_val_if_fail (property != NULL, NULL);
|
||||
|
||||
if (!self->proxy)
|
||||
return g_strdup ("");
|
||||
|
||||
variant = g_dbus_proxy_get_cached_property (self->proxy, property);
|
||||
if (variant)
|
||||
return g_variant_dup_string (variant, NULL);
|
||||
|
||||
variant = g_dbus_proxy_call_sync (self->proxy,
|
||||
"org.freedesktop.DBus.Properties.Get",
|
||||
g_variant_new ("(ss)", HOSTNAME_BUS_NAME, property),
|
||||
G_DBUS_CALL_FLAGS_NONE,
|
||||
-1,
|
||||
NULL,
|
||||
&error);
|
||||
if (variant == NULL) {
|
||||
g_warning ("Failed to get property '%s': %s", property, error->message);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
g_variant_get (variant, "(v)", &inner);
|
||||
return g_variant_dup_string (inner, NULL);
|
||||
}
|
||||
|
||||
gchar *
|
||||
cc_hostname_get_display_hostname (CcHostname *self)
|
||||
{
|
||||
g_autofree gchar *str = NULL;
|
||||
|
||||
g_return_val_if_fail (CC_IS_HOSTNAME (self), NULL);
|
||||
|
||||
str = cc_hostname_get_property (self, "PrettyHostname");
|
||||
/* Empty strings means that we need to fallback */
|
||||
if (str != NULL && *str == '\0')
|
||||
return cc_hostname_get_property (self, "Hostname");
|
||||
|
||||
return g_steal_pointer (&str);
|
||||
}
|
||||
|
||||
void
|
||||
cc_hostname_set_hostname (CcHostname *self,
|
||||
const gchar *hostname)
|
||||
{
|
||||
g_autofree gchar *static_hostname = NULL;
|
||||
g_autoptr(GVariant) pretty_result = NULL;
|
||||
g_autoptr(GVariant) static_result = NULL;
|
||||
g_autoptr(GError) pretty_error = NULL;
|
||||
g_autoptr(GError) static_error = NULL;
|
||||
|
||||
g_return_if_fail (CC_IS_HOSTNAME (self));
|
||||
g_return_if_fail (hostname != NULL);
|
||||
|
||||
g_debug ("Setting PrettyHostname to '%s'", hostname);
|
||||
pretty_result = g_dbus_proxy_call_sync (self->proxy,
|
||||
"SetPrettyHostname",
|
||||
g_variant_new ("(sb)", hostname, FALSE),
|
||||
G_DBUS_CALL_FLAGS_NONE,
|
||||
-1, NULL, &pretty_error);
|
||||
if (pretty_result == NULL)
|
||||
g_warning ("Could not set PrettyHostname: %s", pretty_error->message);
|
||||
|
||||
/* Set the static hostname */
|
||||
static_hostname = pretty_hostname_to_static (hostname, FALSE);
|
||||
g_assert (hostname);
|
||||
|
||||
g_debug ("Setting StaticHostname to '%s'", static_hostname);
|
||||
static_result = g_dbus_proxy_call_sync (self->proxy,
|
||||
"SetStaticHostname",
|
||||
g_variant_new ("(sb)", static_hostname, FALSE),
|
||||
G_DBUS_CALL_FLAGS_NONE,
|
||||
-1, NULL, &static_error);
|
||||
if (static_result == NULL)
|
||||
g_warning ("Could not set StaticHostname: %s", static_error->message);
|
||||
}
|
||||
|
||||
gchar *
|
||||
cc_hostname_get_chassis_type (CcHostname *self)
|
||||
{
|
||||
g_return_val_if_fail (CC_IS_HOSTNAME (self), NULL);
|
||||
|
||||
return cc_hostname_get_property (self, "Chassis");
|
||||
}
|
||||
|
||||
gboolean
|
||||
cc_hostname_is_vm_chassis (CcHostname *self)
|
||||
{
|
||||
g_autofree gchar *chassis_type = NULL;
|
||||
|
||||
g_return_val_if_fail (CC_IS_HOSTNAME (self), FALSE);
|
||||
|
||||
chassis_type = cc_hostname_get_chassis_type (self);
|
||||
return g_strcmp0 (chassis_type, "vm") == 0;
|
||||
}
|
||||
48
panels/common/cc-hostname.h
Normal file
48
panels/common/cc-hostname.h
Normal file
@@ -0,0 +1,48 @@
|
||||
/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* cc-hostname.h
|
||||
*
|
||||
* Copyright 2023 Red Hat Inc
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Author(s):
|
||||
* Felipe Borges <felipeborges@gnome.org>
|
||||
*
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <glib-object.h>
|
||||
#include <gio/gio.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define CC_TYPE_HOSTNAME (cc_hostname_get_type())
|
||||
G_DECLARE_FINAL_TYPE (CcHostname, cc_hostname, CC, HOSTNAME, GObject)
|
||||
|
||||
CcHostname *cc_hostname_get_default (void);
|
||||
|
||||
gchar *cc_hostname_get_display_hostname (CcHostname *self);
|
||||
|
||||
void cc_hostname_set_hostname (CcHostname *self, const gchar *hostname);
|
||||
|
||||
gchar *cc_hostname_get_property (CcHostname *self, const gchar *property);
|
||||
|
||||
gchar *cc_hostname_get_chassis_type (CcHostname *self);
|
||||
|
||||
gboolean cc_hostname_is_vm_chassis (CcHostname *self);
|
||||
|
||||
G_END_DECLS
|
||||
@@ -54,6 +54,7 @@ libwidgets_dep = declare_dependency(
|
||||
|
||||
sources = common_sources + files(
|
||||
'cc-common-language.c',
|
||||
'cc-hostname.c',
|
||||
'cc-illustrated-row.c',
|
||||
'cc-language-chooser.c',
|
||||
'cc-language-row.c',
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
#include "cc-night-light-page.h"
|
||||
|
||||
#include "shell/cc-object-storage.h"
|
||||
#include "cc-hostname.h"
|
||||
#include "cc-display-config-manager-dbus.h"
|
||||
|
||||
struct _CcNightLightPage {
|
||||
@@ -125,49 +126,6 @@ dialog_adjustments_set_frac_hours (CcNightLightPage *self,
|
||||
gtk_stack_set_visible_child (stack, is_pm ? GTK_WIDGET (button_pm) : GTK_WIDGET (button_am));
|
||||
}
|
||||
|
||||
static gboolean
|
||||
is_virtualized ()
|
||||
{
|
||||
g_autoptr(GDBusConnection) connection = NULL;
|
||||
g_autoptr(GError) error = NULL;
|
||||
g_autoptr(GVariant) variant = NULL;
|
||||
g_autoptr(GVariant) chassis_variant = NULL;
|
||||
const gchar *chassis_type;
|
||||
|
||||
connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error);
|
||||
if (!connection)
|
||||
{
|
||||
g_warning ("System bus not available: %s", error->message);
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
variant = g_dbus_connection_call_sync (connection,
|
||||
"org.freedesktop.hostname1",
|
||||
"/org/freedesktop/hostname1",
|
||||
"org.freedesktop.DBus.Properties",
|
||||
"Get",
|
||||
g_variant_new ("(ss)",
|
||||
"org.freedesktop.hostname1",
|
||||
"Chassis"),
|
||||
NULL,
|
||||
G_DBUS_CALL_FLAGS_NONE,
|
||||
-1,
|
||||
NULL,
|
||||
&error);
|
||||
if (!variant)
|
||||
{
|
||||
g_warning ("Cannot get org.freedesktop.hostname1.Chassis: %s", error->message);
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
g_variant_get (variant, "(v)", &chassis_variant);
|
||||
chassis_type = g_variant_get_string (chassis_variant, NULL);
|
||||
|
||||
return (g_strcmp0 (chassis_type, "vm") == 0);
|
||||
}
|
||||
|
||||
static void
|
||||
dialog_update_state (CcNightLightPage *self)
|
||||
{
|
||||
@@ -262,7 +220,7 @@ dialog_update_state (CcNightLightPage *self)
|
||||
gtk_widget_set_visible (self->infobar_disabled, FALSE);
|
||||
gtk_widget_set_sensitive (self->night_light_settings, FALSE);
|
||||
|
||||
if (is_virtualized ())
|
||||
if (cc_hostname_is_vm_chassis (cc_hostname_get_default ()))
|
||||
{
|
||||
gtk_label_set_text (GTK_LABEL (self->infobar_unsupported_description),
|
||||
_("Night Light cannot be used from a virtual machine."));
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
#include <polkit/polkit.h>
|
||||
|
||||
#include "cc-wifi-hotspot-dialog.h"
|
||||
#include "cc-hostname.h"
|
||||
#include "hostname-helper.h"
|
||||
#include "network-dialogs.h"
|
||||
#include "panel-common.h"
|
||||
@@ -530,42 +531,6 @@ wireless_try_to_connect (NetDeviceWifi *self,
|
||||
}
|
||||
}
|
||||
|
||||
static gchar *
|
||||
get_hostname (void)
|
||||
{
|
||||
g_autoptr(GDBusConnection) bus = NULL;
|
||||
g_autoptr(GVariant) res = NULL;
|
||||
g_autoptr(GVariant) inner = NULL;
|
||||
g_autoptr(GError) error = NULL;
|
||||
|
||||
bus = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error);
|
||||
if (bus == NULL) {
|
||||
g_warning ("Failed to get system bus connection: %s", error->message);
|
||||
return NULL;
|
||||
}
|
||||
res = g_dbus_connection_call_sync (bus,
|
||||
"org.freedesktop.hostname1",
|
||||
"/org/freedesktop/hostname1",
|
||||
"org.freedesktop.DBus.Properties",
|
||||
"Get",
|
||||
g_variant_new ("(ss)",
|
||||
"org.freedesktop.hostname1",
|
||||
"PrettyHostname"),
|
||||
(GVariantType*)"(v)",
|
||||
G_DBUS_CALL_FLAGS_NONE,
|
||||
-1,
|
||||
NULL,
|
||||
&error);
|
||||
|
||||
if (res == NULL) {
|
||||
g_warning ("Getting pretty hostname failed: %s", error->message);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
g_variant_get (res, "(v)", &inner);
|
||||
return g_variant_dup_string (inner, NULL);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
is_hotspot_connection (NMConnection *connection)
|
||||
{
|
||||
@@ -735,7 +700,7 @@ start_hotspot (NetDeviceWifi *self)
|
||||
g_object_ref_sink (self->hotspot_dialog);
|
||||
}
|
||||
cc_wifi_hotspot_dialog_set_device (self->hotspot_dialog, NM_DEVICE_WIFI (self->device));
|
||||
hostname = get_hostname ();
|
||||
hostname = cc_hostname_get_display_hostname (cc_hostname_get_default ());
|
||||
ssid = pretty_hostname_to_ssid (hostname);
|
||||
cc_wifi_hotspot_dialog_set_hostname (self->hotspot_dialog, ssid);
|
||||
c = net_device_wifi_get_hotspot_connection (self);
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
|
||||
#include "shell/cc-object-storage.h"
|
||||
#include "cc-battery-row.h"
|
||||
#include "cc-hostname.h"
|
||||
#include "cc-power-profile-row.h"
|
||||
#include "cc-power-profile-info-row.h"
|
||||
#include "cc-power-panel.h"
|
||||
@@ -97,48 +98,6 @@ cc_power_panel_get_help_uri (CcPanel *panel)
|
||||
return "help:gnome-help/power";
|
||||
}
|
||||
|
||||
static char *
|
||||
get_chassis_type (GCancellable *cancellable)
|
||||
{
|
||||
g_autoptr(GError) error = NULL;
|
||||
g_autoptr(GVariant) inner = NULL;
|
||||
g_autoptr(GVariant) variant = NULL;
|
||||
g_autoptr(GDBusConnection) connection = NULL;
|
||||
|
||||
connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM,
|
||||
cancellable,
|
||||
&error);
|
||||
if (!connection)
|
||||
{
|
||||
if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
|
||||
g_warning ("system bus not available: %s", error->message);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
variant = g_dbus_connection_call_sync (connection,
|
||||
"org.freedesktop.hostname1",
|
||||
"/org/freedesktop/hostname1",
|
||||
"org.freedesktop.DBus.Properties",
|
||||
"Get",
|
||||
g_variant_new ("(ss)",
|
||||
"org.freedesktop.hostname1",
|
||||
"Chassis"),
|
||||
NULL,
|
||||
G_DBUS_CALL_FLAGS_NONE,
|
||||
-1,
|
||||
cancellable,
|
||||
&error);
|
||||
if (!variant)
|
||||
{
|
||||
if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
|
||||
g_debug ("Failed to get property '%s': %s", "Chassis", error->message);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
g_variant_get (variant, "(v)", &inner);
|
||||
return g_variant_dup_string (inner, NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
load_custom_css (CcPowerPanel *self,
|
||||
const char *path)
|
||||
@@ -1489,7 +1448,7 @@ cc_power_panel_init (CcPowerPanel *self)
|
||||
load_custom_css (self, "/org/gnome/control-center/power/battery-levels.css");
|
||||
load_custom_css (self, "/org/gnome/control-center/power/power-profiles.css");
|
||||
|
||||
self->chassis_type = get_chassis_type (cc_panel_get_cancellable (CC_PANEL (self)));
|
||||
self->chassis_type = cc_hostname_get_chassis_type (cc_hostname_get_default ());
|
||||
|
||||
self->up_client = up_client_new ();
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
#include "cc-firmware-security-boot-dialog.h"
|
||||
#include "cc-firmware-security-help-dialog.h"
|
||||
#include "cc-firmware-security-utils.h"
|
||||
#include "cc-hostname.h"
|
||||
#include "cc-util.h"
|
||||
|
||||
#include <gio/gdesktopappinfo.h>
|
||||
@@ -630,44 +631,15 @@ on_properties_bus_ready_cb (GObject *source_object,
|
||||
static void
|
||||
update_page_visibility (CcFirmwareSecurityPage *self)
|
||||
{
|
||||
g_autoptr(GDBusConnection) connection = NULL;
|
||||
g_autoptr(GError) error = NULL;
|
||||
g_autoptr(GVariant) inner = NULL;
|
||||
g_autoptr(GVariant) variant = NULL;
|
||||
CcHostname *hostname;
|
||||
gboolean visible = TRUE;
|
||||
const gchar *chassis_type;
|
||||
g_autofree gchar *chassis_type = NULL;
|
||||
|
||||
connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM, self->cancellable, &error);
|
||||
if (!connection)
|
||||
{
|
||||
g_warning ("system bus not available: %s", error->message);
|
||||
return;
|
||||
}
|
||||
variant = g_dbus_connection_call_sync (connection,
|
||||
"org.freedesktop.hostname1",
|
||||
"/org/freedesktop/hostname1",
|
||||
"org.freedesktop.DBus.Properties",
|
||||
"Get",
|
||||
g_variant_new ("(ss)",
|
||||
"org.freedesktop.hostname1",
|
||||
"Chassis"),
|
||||
NULL,
|
||||
G_DBUS_CALL_FLAGS_NONE,
|
||||
-1,
|
||||
self->cancellable,
|
||||
&error);
|
||||
if (!variant)
|
||||
{
|
||||
g_warning ("Cannot get org.freedesktop.hostname1.Chassis: %s", error->message);
|
||||
return;
|
||||
}
|
||||
g_variant_get (variant, "(v)", &inner);
|
||||
|
||||
chassis_type = g_variant_get_string (inner, NULL);
|
||||
|
||||
/* there's no point showing this */
|
||||
if (g_strcmp0 (chassis_type, "vm") == 0 || g_strcmp0 (chassis_type, "") == 0)
|
||||
hostname = cc_hostname_get_default ();
|
||||
chassis_type = cc_hostname_get_chassis_type (hostname);
|
||||
if (cc_hostname_is_vm_chassis (hostname) || g_strcmp0 (chassis_type, "") == 0)
|
||||
visible = FALSE;
|
||||
|
||||
gtk_widget_set_visible (GTK_WIDGET (self), visible);
|
||||
g_debug ("Firmware Security page visible: %s as chassis was %s",
|
||||
visible ? "yes" : "no",
|
||||
|
||||
@@ -46,6 +46,7 @@
|
||||
#endif
|
||||
|
||||
#include "cc-system-details-window.h"
|
||||
#include "cc-hostname.h"
|
||||
#include "cc-info-entry.h"
|
||||
|
||||
struct _CcSystemDetailsWindow
|
||||
@@ -390,48 +391,17 @@ get_primary_disk_info (void)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static char *
|
||||
get_hostnamed_property (const char *property_name)
|
||||
{
|
||||
g_autoptr(GDBusProxy) hostnamed_proxy = NULL;
|
||||
g_autoptr(GVariant) property_variant = NULL;
|
||||
g_autoptr(GError) error = NULL;
|
||||
|
||||
hostnamed_proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
|
||||
G_DBUS_PROXY_FLAGS_NONE,
|
||||
NULL,
|
||||
"org.freedesktop.hostname1",
|
||||
"/org/freedesktop/hostname1",
|
||||
"org.freedesktop.hostname1",
|
||||
NULL,
|
||||
&error);
|
||||
if (hostnamed_proxy == NULL)
|
||||
{
|
||||
g_debug ("Couldn't get hostnamed to start, bailing: %s", error->message);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
property_variant = g_dbus_proxy_get_cached_property (hostnamed_proxy, property_name);
|
||||
if (!property_variant)
|
||||
{
|
||||
g_debug ("Unable to retrieve org.freedesktop.hostname1.%s property", property_name);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return g_variant_dup_string (property_variant, NULL);
|
||||
}
|
||||
|
||||
char *
|
||||
get_hardware_model_string (void)
|
||||
{
|
||||
g_autofree char *vendor_string = NULL;
|
||||
g_autofree char *model_string = NULL;
|
||||
|
||||
vendor_string = get_hostnamed_property ("HardwareVendor");
|
||||
vendor_string = cc_hostname_get_property (cc_hostname_get_default (), "HardwareVendor");
|
||||
if (!vendor_string || g_strcmp0 (vendor_string, "") == 0)
|
||||
return NULL;
|
||||
|
||||
model_string = get_hostnamed_property ("HardwareModel");
|
||||
model_string = cc_hostname_get_property (cc_hostname_get_default (), "HardwareModel");
|
||||
if (!model_string || g_strcmp0 (model_string, "") == 0)
|
||||
return NULL;
|
||||
|
||||
@@ -443,7 +413,7 @@ get_firmware_version_string ()
|
||||
{
|
||||
g_autofree char *firmware_version_string = NULL;
|
||||
|
||||
firmware_version_string = get_hostnamed_property ("FirmwareVersion");
|
||||
firmware_version_string = cc_hostname_get_property (cc_hostname_get_default (), "FirmwareVersion");
|
||||
if (!firmware_version_string || g_strcmp0 (firmware_version_string, "") == 0)
|
||||
return NULL;
|
||||
|
||||
@@ -456,11 +426,11 @@ get_kernel_version_string ()
|
||||
g_autofree char *kernel_name = NULL;
|
||||
g_autofree char *kernel_release = NULL;
|
||||
|
||||
kernel_name = get_hostnamed_property ("KernelName");
|
||||
kernel_name = cc_hostname_get_property (cc_hostname_get_default (), "KernelName");
|
||||
if (!kernel_name || g_strcmp0 (kernel_name, "") == 0)
|
||||
return NULL;
|
||||
|
||||
kernel_release = get_hostnamed_property ("KernelRelease");
|
||||
kernel_release = cc_hostname_get_property (cc_hostname_get_default (), "KernelRelease");
|
||||
if (!kernel_release || g_strcmp0 (kernel_release, "") == 0)
|
||||
return NULL;
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#define G_LOG_DOMAIN "cc-remote-desktop-page"
|
||||
|
||||
#include "cc-gnome-remote-desktop.h"
|
||||
#include "cc-hostname.h"
|
||||
#include "cc-list-row.h"
|
||||
#include "cc-remote-desktop-page.h"
|
||||
#include "cc-tls-certificate.h"
|
||||
@@ -143,68 +144,7 @@ remote_desktop_show_encryption_fingerprint (CcRemoteDesktopPage *self)
|
||||
static char *
|
||||
get_hostname (void)
|
||||
{
|
||||
g_autoptr(GDBusConnection) bus = NULL;
|
||||
g_autoptr(GVariant) res = NULL;
|
||||
g_autoptr(GVariant) inner = NULL;
|
||||
g_autoptr(GError) error = NULL;
|
||||
const char *hostname;
|
||||
|
||||
bus = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error);
|
||||
if (bus == NULL)
|
||||
{
|
||||
g_warning ("Failed to get system bus connection: %s", error->message);
|
||||
return NULL;
|
||||
}
|
||||
res = g_dbus_connection_call_sync (bus,
|
||||
"org.freedesktop.hostname1",
|
||||
"/org/freedesktop/hostname1",
|
||||
"org.freedesktop.DBus.Properties",
|
||||
"Get",
|
||||
g_variant_new ("(ss)",
|
||||
"org.freedesktop.hostname1",
|
||||
"PrettyHostname"),
|
||||
(GVariantType*)"(v)",
|
||||
G_DBUS_CALL_FLAGS_NONE,
|
||||
-1,
|
||||
NULL,
|
||||
&error);
|
||||
|
||||
if (res == NULL)
|
||||
{
|
||||
g_warning ("Getting pretty hostname failed: %s", error->message);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
g_variant_get (res, "(v)", &inner);
|
||||
hostname = g_variant_get_string (inner, NULL);
|
||||
if (g_strcmp0 (hostname, "") != 0)
|
||||
return g_strdup (hostname);
|
||||
|
||||
g_clear_pointer (&inner, g_variant_unref);
|
||||
g_clear_pointer (&res, g_variant_unref);
|
||||
|
||||
res = g_dbus_connection_call_sync (bus,
|
||||
"org.freedesktop.hostname1",
|
||||
"/org/freedesktop/hostname1",
|
||||
"org.freedesktop.DBus.Properties",
|
||||
"Get",
|
||||
g_variant_new ("(ss)",
|
||||
"org.freedesktop.hostname1",
|
||||
"Hostname"),
|
||||
(GVariantType*)"(v)",
|
||||
G_DBUS_CALL_FLAGS_NONE,
|
||||
-1,
|
||||
NULL,
|
||||
&error);
|
||||
|
||||
if (res == NULL)
|
||||
{
|
||||
g_warning ("Getting hostname failed: %s", error->message);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
g_variant_get (res, "(v)", &inner);
|
||||
return g_variant_dup_string (inner, NULL);
|
||||
return cc_hostname_get_display_hostname (cc_hostname_get_default ());
|
||||
}
|
||||
|
||||
static void
|
||||
|
||||
@@ -25,7 +25,7 @@ G_BEGIN_DECLS
|
||||
|
||||
/* Default storage keys */
|
||||
#define CC_OBJECT_NMCLIENT "CcObjectStorage::nm-client"
|
||||
|
||||
#define CC_OBJECT_HOSTNAME "CcObjectStorage::hostname"
|
||||
|
||||
#define CC_TYPE_OBJECT_STORAGE (cc_object_storage_get_type())
|
||||
|
||||
|
||||
Reference in New Issue
Block a user