2017-02-25 14:38:00 +05:30
|
|
|
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
|
|
|
|
*
|
2019-10-12 14:51:00 +05:30
|
|
|
* Copyright (C) 2019 Purism SPC
|
2017-02-25 14:38:00 +05:30
|
|
|
* Copyright (C) 2017 Mohammed Sadiq <sadiq@sadiqpk.org>
|
|
|
|
* Copyright (C) 2010 Red Hat, Inc
|
|
|
|
* Copyright (C) 2008 William Jon McCann <jmccann@redhat.com>
|
|
|
|
*
|
|
|
|
* 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 2 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/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2018-04-06 13:38:40 +02:00
|
|
|
#include "cc-hostname-entry.h"
|
2018-01-17 22:13:27 -02:00
|
|
|
|
2019-08-12 16:36:14 +12:00
|
|
|
#include "cc-info-overview-resources.h"
|
2017-02-25 14:38:00 +05:30
|
|
|
|
|
|
|
#include <glib/gi18n.h>
|
|
|
|
|
2019-10-12 14:51:00 +05:30
|
|
|
#include "cc-list-row.h"
|
2023-03-26 12:39:48 +05:30
|
|
|
#include "cc-system-details-window.h"
|
2017-02-25 14:38:00 +05:30
|
|
|
#include "cc-info-overview-panel.h"
|
|
|
|
|
2019-10-29 09:47:38 +13:00
|
|
|
struct _CcInfoOverviewPanel
|
2017-02-25 14:38:00 +05:30
|
|
|
{
|
2019-10-12 14:51:00 +05:30
|
|
|
CcPanel parent_instance;
|
|
|
|
|
|
|
|
CcListRow *disk_row;
|
2020-11-26 19:04:22 +01:00
|
|
|
CcListRow *hardware_model_row;
|
2019-10-12 14:51:00 +05:30
|
|
|
CcListRow *memory_row;
|
2021-10-19 23:07:53 -03:00
|
|
|
GtkPicture *os_logo;
|
2019-10-12 14:51:00 +05:30
|
|
|
CcListRow *os_name_row;
|
|
|
|
CcListRow *processor_row;
|
2023-07-18 11:33:43 +02:00
|
|
|
AdwPreferencesGroup *software_updates_group;
|
2020-11-26 19:04:22 +01:00
|
|
|
|
2023-03-26 12:39:48 +05:30
|
|
|
GtkWindow *system_details_window;
|
2017-02-25 14:38:00 +05:30
|
|
|
};
|
|
|
|
|
2023-03-26 12:39:48 +05:30
|
|
|
G_DEFINE_TYPE (CcInfoOverviewPanel, cc_info_overview_panel, CC_TYPE_PANEL)
|
2022-05-04 09:54:34 +02:00
|
|
|
|
2017-02-25 14:38:00 +05:30
|
|
|
static void
|
|
|
|
info_overview_panel_setup_overview (CcInfoOverviewPanel *self)
|
|
|
|
{
|
2022-01-25 22:52:19 +01:00
|
|
|
guint64 ram_size;
|
2017-09-25 16:52:58 -04:00
|
|
|
g_autofree char *memory_text = NULL;
|
|
|
|
g_autofree char *cpu_text = NULL;
|
|
|
|
g_autofree char *os_name_text = NULL;
|
2022-10-13 11:05:46 +02:00
|
|
|
g_autofree char *hardware_model_text = NULL;
|
2023-03-26 12:39:48 +05:30
|
|
|
g_autofree gchar *disk_capacity_string = NULL;
|
|
|
|
GtkWindow *parent;
|
2017-02-25 14:38:00 +05:30
|
|
|
|
2022-10-13 11:05:46 +02:00
|
|
|
hardware_model_text = get_hardware_model_string ();
|
|
|
|
cc_list_row_set_secondary_label (self->hardware_model_row, hardware_model_text);
|
|
|
|
gtk_widget_set_visible (GTK_WIDGET (self->hardware_model_row), hardware_model_text != NULL);
|
2020-11-26 19:04:22 +01:00
|
|
|
|
2022-01-25 23:12:58 +01:00
|
|
|
ram_size = get_ram_size_dmi ();
|
|
|
|
if (ram_size == 0)
|
|
|
|
ram_size = get_ram_size_libgtop ();
|
2022-01-25 22:52:19 +01:00
|
|
|
memory_text = g_format_size_full (ram_size, G_FORMAT_SIZE_IEC_UNITS);
|
2019-10-12 14:51:00 +05:30
|
|
|
cc_list_row_set_secondary_label (self->memory_row, memory_text);
|
2017-02-25 14:38:00 +05:30
|
|
|
|
2023-03-26 12:39:48 +05:30
|
|
|
cpu_text = get_cpu_info ();
|
2019-10-12 14:51:00 +05:30
|
|
|
cc_list_row_set_secondary_markup (self->processor_row, cpu_text);
|
2017-02-25 14:38:00 +05:30
|
|
|
|
2023-03-26 12:39:48 +05:30
|
|
|
disk_capacity_string = get_primary_disk_info ();
|
|
|
|
if (disk_capacity_string == NULL)
|
|
|
|
disk_capacity_string = g_strdup (_("Unknown"));
|
|
|
|
cc_list_row_set_secondary_label (self->disk_row, disk_capacity_string);
|
2017-02-25 14:38:00 +05:30
|
|
|
|
2017-09-25 16:52:58 -04:00
|
|
|
os_name_text = get_os_name ();
|
2019-10-12 14:51:00 +05:30
|
|
|
cc_list_row_set_secondary_label (self->os_name_row, os_name_text);
|
2016-08-30 13:47:45 +02:00
|
|
|
|
2023-03-26 12:39:48 +05:30
|
|
|
self->system_details_window = GTK_WINDOW (cc_system_details_window_new());
|
|
|
|
parent = (GtkWindow *) gtk_widget_get_native (GTK_WIDGET (self));
|
|
|
|
gtk_window_set_transient_for (GTK_WINDOW (self->system_details_window), parent);
|
2017-02-25 14:38:00 +05:30
|
|
|
}
|
|
|
|
|
2021-01-21 13:15:03 +01:00
|
|
|
static gboolean
|
|
|
|
does_gnome_software_allow_updates (void)
|
|
|
|
{
|
|
|
|
const gchar *schema_id = "org.gnome.software";
|
|
|
|
GSettingsSchemaSource *source;
|
2021-08-10 16:45:45 +05:30
|
|
|
g_autoptr(GSettingsSchema) schema = NULL;
|
|
|
|
g_autoptr(GSettings) settings = NULL;
|
|
|
|
|
2021-01-21 13:15:03 +01:00
|
|
|
source = g_settings_schema_source_get_default ();
|
|
|
|
|
|
|
|
if (source == NULL)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
schema = g_settings_schema_source_lookup (source, schema_id, FALSE);
|
|
|
|
|
|
|
|
if (schema == NULL)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
settings = g_settings_new (schema_id);
|
|
|
|
return g_settings_get_boolean (settings, "allow-updates");
|
|
|
|
}
|
|
|
|
|
2017-02-25 14:38:00 +05:30
|
|
|
static gboolean
|
|
|
|
does_gnome_software_exist (void)
|
|
|
|
{
|
2020-04-17 11:29:20 +12:00
|
|
|
g_autofree gchar *path = g_find_program_in_path ("gnome-software");
|
|
|
|
return path != NULL;
|
2017-02-25 14:38:00 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
does_gpk_update_viewer_exist (void)
|
|
|
|
{
|
2020-04-17 11:29:20 +12:00
|
|
|
g_autofree gchar *path = g_find_program_in_path ("gpk-update-viewer");
|
|
|
|
return path != NULL;
|
2017-02-25 14:38:00 +05:30
|
|
|
}
|
|
|
|
|
2023-03-26 12:39:48 +05:30
|
|
|
static void
|
|
|
|
cc_info_panel_open_system_details (CcInfoOverviewPanel *self)
|
|
|
|
{
|
|
|
|
GtkWidget *parent;
|
|
|
|
|
|
|
|
parent = cc_shell_get_toplevel (cc_panel_get_shell (CC_PANEL (self)));
|
|
|
|
|
|
|
|
gtk_window_set_transient_for (self->system_details_window, GTK_WINDOW (parent));
|
|
|
|
gtk_window_present (GTK_WINDOW (self->system_details_window));
|
|
|
|
}
|
|
|
|
|
2017-02-25 14:38:00 +05:30
|
|
|
static void
|
2022-12-02 11:37:34 +01:00
|
|
|
cc_info_panel_open_software_update (CcInfoOverviewPanel *self)
|
2017-02-25 14:38:00 +05:30
|
|
|
{
|
2017-09-25 16:52:58 -04:00
|
|
|
g_autoptr(GError) error = NULL;
|
2017-02-25 14:38:00 +05:30
|
|
|
gboolean ret;
|
2020-04-17 11:29:20 +12:00
|
|
|
char *argv[3];
|
2017-02-25 14:38:00 +05:30
|
|
|
|
|
|
|
if (does_gnome_software_exist ())
|
|
|
|
{
|
2020-04-17 11:29:20 +12:00
|
|
|
argv[0] = "gnome-software";
|
|
|
|
argv[1] = "--mode=updates";
|
|
|
|
argv[2] = NULL;
|
2017-02-25 14:38:00 +05:30
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-04-17 11:29:20 +12:00
|
|
|
argv[0] = "gpk-update-viewer";
|
|
|
|
argv[1] = NULL;
|
2017-02-25 14:38:00 +05:30
|
|
|
}
|
2020-04-17 11:29:20 +12:00
|
|
|
ret = g_spawn_async (NULL, argv, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, &error);
|
2017-02-25 14:38:00 +05:30
|
|
|
if (!ret)
|
|
|
|
g_warning ("Failed to spawn %s: %s", argv[0], error->message);
|
|
|
|
}
|
|
|
|
|
2021-03-09 14:51:54 -06:00
|
|
|
#if !defined(DISTRIBUTOR_LOGO) || defined(DARK_MODE_DISTRIBUTOR_LOGO)
|
2021-08-23 17:10:41 +02:00
|
|
|
static gboolean
|
2023-05-31 15:25:15 +12:00
|
|
|
use_dark_theme (CcInfoOverviewPanel *self)
|
2021-04-23 12:30:15 +02:00
|
|
|
{
|
2021-10-19 23:07:53 -03:00
|
|
|
AdwStyleManager *style_manager = adw_style_manager_get_default ();
|
2021-04-23 12:30:15 +02:00
|
|
|
|
2021-10-19 23:07:53 -03:00
|
|
|
return adw_style_manager_get_dark (style_manager);
|
2021-04-23 12:30:15 +02:00
|
|
|
}
|
2021-03-09 14:51:54 -06:00
|
|
|
#endif
|
2021-04-23 12:30:15 +02:00
|
|
|
|
2020-12-19 21:53:24 +01:00
|
|
|
static void
|
2023-05-31 15:25:15 +12:00
|
|
|
setup_os_logo (CcInfoOverviewPanel *self)
|
2020-12-19 21:53:24 +01:00
|
|
|
{
|
2021-03-09 14:51:54 -06:00
|
|
|
#ifdef DISTRIBUTOR_LOGO
|
|
|
|
#ifdef DARK_MODE_DISTRIBUTOR_LOGO
|
2023-05-31 15:25:15 +12:00
|
|
|
if (use_dark_theme (self))
|
2021-03-09 14:51:54 -06:00
|
|
|
{
|
2023-05-31 15:25:15 +12:00
|
|
|
gtk_picture_set_filename (self->os_logo, DARK_MODE_DISTRIBUTOR_LOGO);
|
2021-03-09 14:51:54 -06:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
2023-05-31 15:25:15 +12:00
|
|
|
gtk_picture_set_filename (self->os_logo, DISTRIBUTOR_LOGO);
|
2021-03-09 14:51:54 -06:00
|
|
|
return;
|
|
|
|
#else
|
2021-10-19 23:07:53 -03:00
|
|
|
GtkIconTheme *icon_theme;
|
2020-12-19 21:53:24 +01:00
|
|
|
g_autofree char *logo_name = g_get_os_info ("LOGO");
|
2021-10-19 23:07:53 -03:00
|
|
|
g_autoptr(GtkIconPaintable) icon_paintable = NULL;
|
2021-08-23 17:10:41 +02:00
|
|
|
g_autoptr(GPtrArray) array = NULL;
|
|
|
|
g_autoptr(GIcon) icon = NULL;
|
|
|
|
gboolean dark;
|
2021-04-23 12:30:15 +02:00
|
|
|
|
2023-05-31 15:25:15 +12:00
|
|
|
dark = use_dark_theme (self);
|
2021-04-23 12:41:21 +02:00
|
|
|
if (logo_name == NULL)
|
|
|
|
logo_name = g_strdup ("gnome-logo");
|
|
|
|
|
2021-08-23 17:10:41 +02:00
|
|
|
array = g_ptr_array_new_with_free_func (g_free);
|
|
|
|
if (dark)
|
|
|
|
g_ptr_array_add (array, (gpointer) g_strdup_printf ("%s-text-dark", logo_name));
|
|
|
|
g_ptr_array_add (array, (gpointer) g_strdup_printf ("%s-text", logo_name));
|
|
|
|
if (dark)
|
|
|
|
g_ptr_array_add (array, (gpointer) g_strdup_printf ("%s-dark", logo_name));
|
|
|
|
g_ptr_array_add (array, (gpointer) g_strdup_printf ("%s", logo_name));
|
|
|
|
|
|
|
|
icon = g_themed_icon_new_from_names ((char **) array->pdata, array->len);
|
2021-10-19 23:07:53 -03:00
|
|
|
icon_theme = gtk_icon_theme_get_for_display (gdk_display_get_default ());
|
|
|
|
icon_paintable = gtk_icon_theme_lookup_by_gicon (icon_theme, icon,
|
|
|
|
192,
|
2023-05-31 15:25:15 +12:00
|
|
|
gtk_widget_get_scale_factor (GTK_WIDGET (self)),
|
|
|
|
gtk_widget_get_direction (GTK_WIDGET (self)),
|
2021-10-19 23:07:53 -03:00
|
|
|
0);
|
2023-05-31 15:25:15 +12:00
|
|
|
gtk_picture_set_paintable (self->os_logo, GDK_PAINTABLE (icon_paintable));
|
2021-03-09 14:51:54 -06:00
|
|
|
#endif
|
2020-12-19 21:53:24 +01:00
|
|
|
}
|
|
|
|
|
2017-02-25 14:38:00 +05:30
|
|
|
static void
|
|
|
|
cc_info_overview_panel_class_init (CcInfoOverviewPanelClass *klass)
|
|
|
|
{
|
|
|
|
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
|
|
|
|
2023-03-27 19:22:34 +01:00
|
|
|
g_type_ensure (CC_TYPE_HOSTNAME_ENTRY);
|
|
|
|
|
2019-08-12 16:36:14 +12:00
|
|
|
gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/control-center/info-overview/cc-info-overview-panel.ui");
|
2017-02-25 14:38:00 +05:30
|
|
|
|
2019-10-12 14:51:00 +05:30
|
|
|
gtk_widget_class_bind_template_child (widget_class, CcInfoOverviewPanel, disk_row);
|
2020-11-26 19:04:22 +01:00
|
|
|
gtk_widget_class_bind_template_child (widget_class, CcInfoOverviewPanel, hardware_model_row);
|
2019-10-12 14:51:00 +05:30
|
|
|
gtk_widget_class_bind_template_child (widget_class, CcInfoOverviewPanel, memory_row);
|
2020-12-19 21:53:24 +01:00
|
|
|
gtk_widget_class_bind_template_child (widget_class, CcInfoOverviewPanel, os_logo);
|
2019-10-12 14:51:00 +05:30
|
|
|
gtk_widget_class_bind_template_child (widget_class, CcInfoOverviewPanel, os_name_row);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, CcInfoOverviewPanel, processor_row);
|
2023-07-18 11:33:43 +02:00
|
|
|
gtk_widget_class_bind_template_child (widget_class, CcInfoOverviewPanel, software_updates_group);
|
2019-10-12 14:51:00 +05:30
|
|
|
|
2022-12-02 11:37:34 +01:00
|
|
|
gtk_widget_class_bind_template_callback (widget_class, cc_info_panel_open_software_update);
|
2023-03-26 12:39:48 +05:30
|
|
|
gtk_widget_class_bind_template_callback (widget_class, cc_info_panel_open_system_details);
|
2019-10-12 14:51:00 +05:30
|
|
|
|
|
|
|
g_type_ensure (CC_TYPE_LIST_ROW);
|
2017-02-25 14:38:00 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
cc_info_overview_panel_init (CcInfoOverviewPanel *self)
|
|
|
|
{
|
2022-12-02 12:12:48 +01:00
|
|
|
AdwStyleManager *style_manager;
|
|
|
|
|
2017-02-25 14:38:00 +05:30
|
|
|
gtk_widget_init_template (GTK_WIDGET (self));
|
|
|
|
|
2019-08-12 16:36:14 +12:00
|
|
|
g_resources_register (cc_info_overview_get_resource ());
|
2017-11-11 01:22:40 -02:00
|
|
|
|
2021-01-21 13:15:03 +01:00
|
|
|
if ((!does_gnome_software_exist () || !does_gnome_software_allow_updates ()) && !does_gpk_update_viewer_exist ())
|
2023-07-18 11:33:43 +02:00
|
|
|
gtk_widget_set_visible (GTK_WIDGET (self->software_updates_group), FALSE);
|
2017-02-25 14:38:00 +05:30
|
|
|
|
|
|
|
info_overview_panel_setup_overview (self);
|
2020-12-19 21:53:24 +01:00
|
|
|
|
2022-12-02 12:12:48 +01:00
|
|
|
style_manager = adw_style_manager_get_default ();
|
|
|
|
g_signal_connect_swapped (style_manager, "notify::dark", G_CALLBACK (setup_os_logo), self);
|
2020-12-19 21:53:24 +01:00
|
|
|
setup_os_logo (self);
|
2017-02-25 14:38:00 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
GtkWidget *
|
|
|
|
cc_info_overview_panel_new (void)
|
|
|
|
{
|
|
|
|
return g_object_new (CC_TYPE_INFO_OVERVIEW_PANEL,
|
|
|
|
NULL);
|
|
|
|
}
|