2010-05-19 11:11:26 +01:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2009, 2010 Intel, Inc.
|
|
|
|
* Copyright (c) 2010 Red Hat, Inc.
|
2017-08-03 18:24:27 +01:00
|
|
|
* Copyright (c) 2016 Endless, Inc.
|
2010-05-19 11:11:26 +01:00
|
|
|
*
|
|
|
|
* The Control Center 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.
|
|
|
|
*
|
|
|
|
* The Control Center 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 the Control Center; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*
|
|
|
|
* Author: Thomas Wood <thos@gnome.org>
|
|
|
|
*/
|
|
|
|
|
2018-03-28 16:39:13 -03:00
|
|
|
#define G_LOG_DOMAIN "cc-window"
|
|
|
|
|
2012-12-11 11:46:28 +01:00
|
|
|
#include <config.h>
|
2010-05-19 11:11:26 +01:00
|
|
|
|
2018-05-28 22:23:35 -03:00
|
|
|
#include "cc-debug.h"
|
2013-02-17 00:54:58 -05:00
|
|
|
#include "cc-window.h"
|
2010-05-19 11:11:26 +01:00
|
|
|
|
|
|
|
#include <glib/gi18n.h>
|
|
|
|
#include <gio/gio.h>
|
|
|
|
#include <gio/gdesktopappinfo.h>
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
#include <gdk/gdkkeysyms.h>
|
2013-01-20 15:17:20 +01:00
|
|
|
#include <gdk/gdkx.h>
|
2018-11-27 15:59:17 +01:00
|
|
|
#define HANDY_USE_UNSTABLE_API
|
|
|
|
#include <handy.h>
|
2010-05-19 11:11:26 +01:00
|
|
|
#include <string.h>
|
2018-03-28 16:39:13 -03:00
|
|
|
#include <time.h>
|
2013-01-11 16:21:26 +01:00
|
|
|
|
2018-04-08 17:13:42 -03:00
|
|
|
#include "cc-application.h"
|
2010-05-19 11:11:26 +01:00
|
|
|
#include "cc-panel.h"
|
|
|
|
#include "cc-shell.h"
|
|
|
|
#include "cc-shell-model.h"
|
2017-08-03 18:24:27 +01:00
|
|
|
#include "cc-panel-list.h"
|
2012-12-13 17:16:57 +01:00
|
|
|
#include "cc-panel-loader.h"
|
2013-01-15 11:37:24 +01:00
|
|
|
#include "cc-util.h"
|
2010-05-19 11:11:26 +01:00
|
|
|
|
2013-03-26 14:39:34 +01:00
|
|
|
#define MOUSE_BACK_BUTTON 8
|
|
|
|
|
2017-11-08 16:51:42 +01:00
|
|
|
#define DEFAULT_WINDOW_ICON_NAME "gnome-control-center"
|
2013-02-17 00:30:43 -05:00
|
|
|
|
2016-05-22 00:40:55 -03:00
|
|
|
struct _CcWindow
|
2010-05-19 11:11:26 +01:00
|
|
|
{
|
2016-05-22 00:40:55 -03:00
|
|
|
GtkApplicationWindow parent;
|
|
|
|
|
2019-09-21 08:15:57 +04:00
|
|
|
GtkRevealer *back_revealer;
|
|
|
|
GtkMessageDialog *development_warning_dialog;
|
|
|
|
GtkHeaderBar *header;
|
|
|
|
HdyLeaflet *header_box;
|
|
|
|
HdyHeaderGroup *header_group;
|
|
|
|
GtkSizeGroup *header_sizegroup;
|
|
|
|
HdyLeaflet *main_leaflet;
|
|
|
|
GtkHeaderBar *panel_headerbar;
|
|
|
|
CcPanelList *panel_list;
|
|
|
|
GtkButton *previous_button;
|
|
|
|
GtkSearchBar *search_bar;
|
|
|
|
GtkToggleButton *search_button;
|
|
|
|
GtkSearchEntry *search_entry;
|
|
|
|
GtkBox *sidebar_box;
|
|
|
|
GtkStack *stack;
|
|
|
|
GtkBox *top_left_box;
|
|
|
|
GtkBox *top_right_box;
|
|
|
|
|
2012-09-20 20:58:28 +02:00
|
|
|
GtkWidget *current_panel;
|
|
|
|
char *current_panel_id;
|
2013-02-19 11:18:46 +01:00
|
|
|
GQueue *previous_panels;
|
2013-02-17 02:56:30 -05:00
|
|
|
|
2012-01-09 15:19:13 +00:00
|
|
|
GPtrArray *custom_widgets;
|
2010-05-19 11:11:26 +01:00
|
|
|
|
2019-09-21 08:15:57 +04:00
|
|
|
CcShellModel *store;
|
2010-05-19 11:11:26 +01:00
|
|
|
|
2013-02-17 00:30:43 -05:00
|
|
|
CcPanel *active_panel;
|
2017-08-22 18:10:25 +02:00
|
|
|
GSettings *settings;
|
2019-02-20 16:29:32 +01:00
|
|
|
|
|
|
|
CcPanelListView previous_list_view;
|
2010-05-19 11:11:26 +01:00
|
|
|
};
|
|
|
|
|
2016-05-22 00:40:55 -03:00
|
|
|
static void cc_shell_iface_init (CcShellInterface *iface);
|
|
|
|
|
|
|
|
G_DEFINE_TYPE_WITH_CODE (CcWindow, cc_window, GTK_TYPE_APPLICATION_WINDOW,
|
|
|
|
G_IMPLEMENT_INTERFACE (CC_TYPE_SHELL, cc_shell_iface_init))
|
|
|
|
|
2013-02-17 00:30:43 -05:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
2018-04-08 17:13:42 -03:00
|
|
|
PROP_ACTIVE_PANEL,
|
|
|
|
PROP_MODEL
|
2013-02-17 00:30:43 -05:00
|
|
|
};
|
|
|
|
|
2018-01-21 09:46:12 -02:00
|
|
|
/* Auxiliary methods */
|
2018-05-11 22:45:51 -03:00
|
|
|
static gboolean
|
|
|
|
in_flatpak_sandbox (void)
|
|
|
|
{
|
|
|
|
return g_file_test ("/.flatpak-info", G_FILE_TEST_EXISTS);
|
|
|
|
}
|
|
|
|
|
2018-05-29 20:46:03 -03:00
|
|
|
static void
|
|
|
|
remove_all_custom_widgets (CcWindow *self)
|
|
|
|
{
|
2019-05-21 12:57:45 -03:00
|
|
|
GtkWidget *parent;
|
2018-05-29 20:46:03 -03:00
|
|
|
GtkWidget *widget;
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
CC_ENTRY;
|
|
|
|
|
|
|
|
/* remove from the header */
|
|
|
|
for (i = 0; i < self->custom_widgets->len; i++)
|
|
|
|
{
|
|
|
|
widget = g_ptr_array_index (self->custom_widgets, i);
|
2019-05-21 12:57:45 -03:00
|
|
|
parent = gtk_widget_get_parent (widget);
|
|
|
|
|
2019-09-21 08:15:57 +04:00
|
|
|
g_assert (parent == GTK_WIDGET (self->top_right_box) || parent == GTK_WIDGET (self->top_left_box));
|
2019-05-21 12:57:45 -03:00
|
|
|
gtk_container_remove (GTK_CONTAINER (parent), widget);
|
2018-05-29 20:46:03 -03:00
|
|
|
}
|
|
|
|
g_ptr_array_set_size (self->custom_widgets, 0);
|
|
|
|
|
|
|
|
CC_EXIT;
|
|
|
|
}
|
|
|
|
|
2019-09-21 08:07:18 +04:00
|
|
|
static void
|
|
|
|
show_panel (CcWindow *self)
|
|
|
|
{
|
2019-09-21 08:15:57 +04:00
|
|
|
hdy_leaflet_set_visible_child (self->main_leaflet, GTK_WIDGET (self->stack));
|
|
|
|
hdy_leaflet_set_visible_child (self->header_box, GTK_WIDGET (self->panel_headerbar));
|
2019-09-21 08:07:18 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
show_sidebar (CcWindow *self)
|
|
|
|
{
|
2019-09-21 08:15:57 +04:00
|
|
|
hdy_leaflet_set_visible_child (self->main_leaflet, GTK_WIDGET (self->sidebar_box));
|
|
|
|
hdy_leaflet_set_visible_child (self->header_box, GTK_WIDGET (self->header));
|
2019-09-21 08:07:18 +04:00
|
|
|
}
|
|
|
|
|
2019-02-20 16:29:32 +01:00
|
|
|
static void
|
2019-09-21 08:35:14 +04:00
|
|
|
on_sidebar_activated_cb (CcWindow *self)
|
2019-02-20 16:29:32 +01:00
|
|
|
{
|
2019-09-21 08:07:18 +04:00
|
|
|
show_panel (self);
|
2019-02-20 16:29:32 +01:00
|
|
|
}
|
|
|
|
|
2012-04-30 17:05:15 +01:00
|
|
|
static gboolean
|
2018-04-08 19:10:25 -03:00
|
|
|
activate_panel (CcWindow *self,
|
|
|
|
const gchar *id,
|
|
|
|
GVariant *parameters,
|
|
|
|
const gchar *name,
|
|
|
|
GIcon *gicon,
|
|
|
|
CcPanelVisibility visibility)
|
2010-05-19 11:11:26 +01:00
|
|
|
{
|
2018-03-28 16:39:13 -03:00
|
|
|
g_autoptr (GTimer) timer = NULL;
|
2018-11-16 14:28:53 -02:00
|
|
|
GtkWidget *sidebar_widget;
|
2018-06-18 11:10:20 -03:00
|
|
|
GtkWidget *title_widget;
|
2018-03-28 16:39:13 -03:00
|
|
|
gdouble ellapsed_time;
|
2010-05-19 16:53:15 +01:00
|
|
|
|
2018-11-16 15:09:51 -02:00
|
|
|
CC_ENTRY;
|
|
|
|
|
2012-04-30 17:00:33 +01:00
|
|
|
if (!id)
|
2018-11-16 15:09:51 -02:00
|
|
|
CC_RETURN (FALSE);
|
2010-06-02 16:20:45 +01:00
|
|
|
|
2018-04-08 19:10:25 -03:00
|
|
|
if (visibility == CC_PANEL_HIDDEN)
|
2018-11-16 15:09:51 -02:00
|
|
|
CC_RETURN (FALSE);
|
2018-04-08 19:10:25 -03:00
|
|
|
|
2018-05-29 20:46:03 -03:00
|
|
|
/* clear any custom widgets */
|
|
|
|
remove_all_custom_widgets (self);
|
|
|
|
|
2018-03-28 16:39:13 -03:00
|
|
|
timer = g_timer_new ();
|
|
|
|
|
2017-08-22 18:10:25 +02:00
|
|
|
g_settings_set_string (self->settings, "last-panel", id);
|
|
|
|
|
2018-03-28 16:39:13 -03:00
|
|
|
/* Begin the profile */
|
|
|
|
g_timer_start (timer);
|
|
|
|
|
2019-02-20 16:29:32 +01:00
|
|
|
if (self->current_panel)
|
|
|
|
g_signal_handlers_disconnect_by_data (self->current_panel, self);
|
2016-05-22 00:40:55 -03:00
|
|
|
self->current_panel = GTK_WIDGET (cc_panel_loader_load_by_name (CC_SHELL (self), id, parameters));
|
|
|
|
cc_shell_set_active_panel (CC_SHELL (self), CC_PANEL (self->current_panel));
|
|
|
|
gtk_widget_show (self->current_panel);
|
2010-05-25 14:22:25 +01:00
|
|
|
|
2019-09-21 08:15:57 +04:00
|
|
|
gtk_stack_add_named (self->stack, self->current_panel, id);
|
2010-05-25 14:38:36 +01:00
|
|
|
|
2012-04-30 17:00:33 +01:00
|
|
|
/* switch to the new panel */
|
2018-06-18 11:10:20 -03:00
|
|
|
gtk_widget_show (self->current_panel);
|
2019-09-21 08:15:57 +04:00
|
|
|
gtk_stack_set_visible_child_name (self->stack, id);
|
2010-07-14 16:22:06 +01:00
|
|
|
|
2012-04-30 17:00:33 +01:00
|
|
|
/* set the title of the window */
|
2013-02-17 00:30:43 -05:00
|
|
|
gtk_window_set_role (GTK_WINDOW (self), id);
|
2019-09-21 08:15:57 +04:00
|
|
|
gtk_header_bar_set_title (self->panel_headerbar, name);
|
2012-04-30 16:29:07 +01:00
|
|
|
|
2016-06-06 13:01:37 +02:00
|
|
|
title_widget = cc_panel_get_title_widget (CC_PANEL (self->current_panel));
|
2019-09-21 08:15:57 +04:00
|
|
|
gtk_header_bar_set_custom_title (self->panel_headerbar, title_widget);
|
2016-06-06 13:01:37 +02:00
|
|
|
|
2018-11-16 14:28:53 -02:00
|
|
|
sidebar_widget = cc_panel_get_sidebar_widget (CC_PANEL (self->current_panel));
|
2019-09-21 08:15:57 +04:00
|
|
|
cc_panel_list_add_sidebar_widget (self->panel_list, sidebar_widget);
|
2019-02-20 16:29:32 +01:00
|
|
|
/* Ensure we show the panel when when the leaflet is folded and a sidebar
|
|
|
|
* widget's row is activated.
|
|
|
|
*/
|
2019-09-21 08:35:14 +04:00
|
|
|
g_signal_connect_object (self->current_panel, "sidebar-activated", G_CALLBACK (on_sidebar_activated_cb), self, G_CONNECT_SWAPPED);
|
2018-11-16 14:28:53 -02:00
|
|
|
|
2018-03-28 16:39:13 -03:00
|
|
|
/* Finish profiling */
|
|
|
|
g_timer_stop (timer);
|
|
|
|
|
|
|
|
ellapsed_time = g_timer_elapsed (timer, NULL);
|
|
|
|
|
|
|
|
g_debug ("Time to open panel '%s': %lfs", name, ellapsed_time);
|
|
|
|
|
2018-11-16 15:09:51 -02:00
|
|
|
CC_RETURN (TRUE);
|
2010-05-19 11:11:26 +01:00
|
|
|
}
|
|
|
|
|
2013-02-19 11:18:46 +01:00
|
|
|
static void
|
2019-09-21 08:41:01 +04:00
|
|
|
add_current_panel_to_history (CcWindow *self,
|
2013-02-19 11:18:46 +01:00
|
|
|
const char *start_id)
|
|
|
|
{
|
|
|
|
g_return_if_fail (start_id != NULL);
|
|
|
|
|
2018-01-21 09:12:51 -02:00
|
|
|
if (!self->current_panel_id || g_strcmp0 (self->current_panel_id, start_id) == 0)
|
2013-02-19 11:18:46 +01:00
|
|
|
return;
|
|
|
|
|
2016-05-22 00:40:55 -03:00
|
|
|
g_queue_push_head (self->previous_panels, g_strdup (self->current_panel_id));
|
|
|
|
g_debug ("Added '%s' to the previous panels", self->current_panel_id);
|
2013-02-19 11:18:46 +01:00
|
|
|
}
|
|
|
|
|
2018-11-12 00:30:55 -02:00
|
|
|
static gboolean
|
|
|
|
find_iter_for_panel_id (CcWindow *self,
|
|
|
|
const gchar *panel_id,
|
|
|
|
GtkTreeIter *out_iter)
|
|
|
|
{
|
|
|
|
GtkTreeIter iter;
|
|
|
|
gboolean valid;
|
|
|
|
|
|
|
|
valid = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (self->store), &iter);
|
|
|
|
|
|
|
|
while (valid)
|
|
|
|
{
|
|
|
|
g_autofree gchar *id = NULL;
|
|
|
|
|
|
|
|
gtk_tree_model_get (GTK_TREE_MODEL (self->store),
|
|
|
|
&iter,
|
|
|
|
COL_ID, &id,
|
|
|
|
-1);
|
|
|
|
|
|
|
|
if (g_strcmp0 (id, panel_id) == 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
valid = gtk_tree_model_iter_next (GTK_TREE_MODEL (self->store), &iter);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_assert (out_iter != NULL);
|
|
|
|
*out_iter = iter;
|
|
|
|
|
|
|
|
return valid;
|
|
|
|
}
|
|
|
|
|
2017-08-03 18:24:27 +01:00
|
|
|
static void
|
|
|
|
update_list_title (CcWindow *self)
|
2010-06-01 08:38:34 -04:00
|
|
|
{
|
2017-08-03 18:24:27 +01:00
|
|
|
CcPanelListView view;
|
2018-11-16 14:29:29 -02:00
|
|
|
GtkTreeIter iter;
|
|
|
|
g_autofree gchar *title = NULL;
|
2010-06-01 08:38:34 -04:00
|
|
|
|
2018-11-16 15:09:51 -02:00
|
|
|
CC_ENTRY;
|
|
|
|
|
2019-09-21 08:15:57 +04:00
|
|
|
view = cc_panel_list_get_view (self->panel_list);
|
2018-01-17 23:14:09 -02:00
|
|
|
title = NULL;
|
2010-06-01 08:38:34 -04:00
|
|
|
|
2017-08-03 18:24:27 +01:00
|
|
|
switch (view)
|
2010-06-01 08:38:34 -04:00
|
|
|
{
|
2017-08-03 18:24:27 +01:00
|
|
|
case CC_PANEL_LIST_DETAILS:
|
2018-11-16 14:29:29 -02:00
|
|
|
title = g_strdup (_("Details"));
|
2017-08-03 18:24:27 +01:00
|
|
|
break;
|
2010-06-01 08:38:34 -04:00
|
|
|
|
2017-08-03 18:24:27 +01:00
|
|
|
case CC_PANEL_LIST_DEVICES:
|
2018-11-16 14:29:29 -02:00
|
|
|
title = g_strdup (_("Devices"));
|
2017-08-03 18:24:27 +01:00
|
|
|
break;
|
2010-06-01 08:38:34 -04:00
|
|
|
|
2017-08-03 18:24:27 +01:00
|
|
|
case CC_PANEL_LIST_MAIN:
|
2018-11-16 14:29:29 -02:00
|
|
|
title = g_strdup (_("Settings"));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CC_PANEL_LIST_WIDGET:
|
|
|
|
find_iter_for_panel_id (self, self->current_panel_id, &iter);
|
|
|
|
gtk_tree_model_get (GTK_TREE_MODEL (self->store),
|
|
|
|
&iter,
|
|
|
|
COL_NAME, &title,
|
|
|
|
-1);
|
2017-08-03 18:24:27 +01:00
|
|
|
break;
|
2013-01-14 17:22:31 +01:00
|
|
|
|
2017-08-03 18:24:27 +01:00
|
|
|
case CC_PANEL_LIST_SEARCH:
|
|
|
|
title = NULL;
|
|
|
|
break;
|
2013-01-14 17:22:31 +01:00
|
|
|
}
|
|
|
|
|
2017-08-03 18:24:27 +01:00
|
|
|
if (title)
|
2019-09-21 08:15:57 +04:00
|
|
|
gtk_header_bar_set_title (self->header, title);
|
2018-11-16 15:09:51 -02:00
|
|
|
|
|
|
|
CC_EXIT;
|
2010-06-01 08:38:34 -04:00
|
|
|
}
|
|
|
|
|
2018-04-08 19:10:25 -03:00
|
|
|
static void
|
2019-09-21 08:35:14 +04:00
|
|
|
on_row_changed_cb (CcWindow *self,
|
2018-04-08 19:10:25 -03:00
|
|
|
GtkTreePath *path,
|
|
|
|
GtkTreeIter *iter,
|
2019-09-21 08:35:14 +04:00
|
|
|
GtkTreeModel *model)
|
2018-04-08 19:10:25 -03:00
|
|
|
{
|
|
|
|
g_autofree gchar *id = NULL;
|
|
|
|
CcPanelVisibility visibility;
|
|
|
|
|
|
|
|
gtk_tree_model_get (model, iter,
|
|
|
|
COL_ID, &id,
|
|
|
|
COL_VISIBILITY, &visibility,
|
|
|
|
-1);
|
|
|
|
|
2019-09-21 08:15:57 +04:00
|
|
|
cc_panel_list_set_panel_visibility (self->panel_list, id, visibility);
|
2018-04-08 19:10:25 -03:00
|
|
|
}
|
|
|
|
|
2012-05-21 23:01:50 -04:00
|
|
|
static void
|
2019-09-21 08:41:01 +04:00
|
|
|
setup_model (CcWindow *self)
|
2012-05-21 23:01:50 -04:00
|
|
|
{
|
|
|
|
GtkTreeModel *model;
|
2017-08-03 18:24:27 +01:00
|
|
|
GtkTreeIter iter;
|
|
|
|
gboolean valid;
|
2012-05-21 23:01:50 -04:00
|
|
|
|
2018-04-08 17:13:42 -03:00
|
|
|
/* CcApplication must have a valid model at this point */
|
2019-09-21 08:41:01 +04:00
|
|
|
g_assert (self->store != NULL);
|
2018-04-08 17:13:42 -03:00
|
|
|
|
2019-09-21 08:41:01 +04:00
|
|
|
model = GTK_TREE_MODEL (self->store);
|
2012-05-21 23:01:50 -04:00
|
|
|
|
2019-09-21 08:41:01 +04:00
|
|
|
cc_panel_loader_fill_model (self->store);
|
2012-05-21 23:01:50 -04:00
|
|
|
|
2017-08-03 18:24:27 +01:00
|
|
|
/* Create a row for each panel */
|
|
|
|
valid = gtk_tree_model_get_iter_first (model, &iter);
|
2012-05-21 23:01:50 -04:00
|
|
|
|
2017-08-03 18:24:27 +01:00
|
|
|
while (valid)
|
2013-01-07 16:33:22 +01:00
|
|
|
{
|
2017-08-03 18:24:27 +01:00
|
|
|
CcPanelCategory category;
|
2018-01-21 09:12:51 -02:00
|
|
|
g_autoptr(GIcon) icon = NULL;
|
|
|
|
g_autofree gchar *name = NULL;
|
|
|
|
g_autofree gchar *description = NULL;
|
|
|
|
g_autofree gchar *id = NULL;
|
2018-07-09 16:43:47 +02:00
|
|
|
g_auto(GStrv) keywords = NULL;
|
2018-04-08 19:10:25 -03:00
|
|
|
CcPanelVisibility visibility;
|
2018-07-24 17:13:42 +02:00
|
|
|
const gchar *icon_name = NULL;
|
2013-01-07 16:33:22 +01:00
|
|
|
|
2017-08-03 18:24:27 +01:00
|
|
|
gtk_tree_model_get (model, &iter,
|
|
|
|
COL_CATEGORY, &category,
|
|
|
|
COL_DESCRIPTION, &description,
|
|
|
|
COL_GICON, &icon,
|
|
|
|
COL_ID, &id,
|
|
|
|
COL_NAME, &name,
|
2017-11-27 11:05:19 +01:00
|
|
|
COL_KEYWORDS, &keywords,
|
2018-04-08 19:10:25 -03:00
|
|
|
COL_VISIBILITY, &visibility,
|
2017-08-03 18:24:27 +01:00
|
|
|
-1);
|
2013-01-07 16:33:22 +01:00
|
|
|
|
2018-07-24 17:13:42 +02:00
|
|
|
if (G_IS_THEMED_ICON (icon))
|
|
|
|
icon_name = g_themed_icon_get_names (G_THEMED_ICON (icon))[0];
|
2013-01-07 16:33:22 +01:00
|
|
|
|
2019-09-21 08:41:01 +04:00
|
|
|
cc_panel_list_add_panel (self->panel_list,
|
2017-08-03 18:24:27 +01:00
|
|
|
category,
|
|
|
|
id,
|
|
|
|
name,
|
|
|
|
description,
|
2017-11-27 11:05:19 +01:00
|
|
|
keywords,
|
2018-04-08 19:10:25 -03:00
|
|
|
icon_name,
|
|
|
|
visibility);
|
2010-05-19 11:11:26 +01:00
|
|
|
|
2017-08-03 18:24:27 +01:00
|
|
|
valid = gtk_tree_model_iter_next (model, &iter);
|
2012-04-10 16:55:26 -04:00
|
|
|
}
|
2018-04-08 19:10:25 -03:00
|
|
|
|
|
|
|
/* React to visibility changes */
|
2019-09-21 08:41:01 +04:00
|
|
|
g_signal_connect_object (model, "row-changed", G_CALLBACK (on_row_changed_cb), self, G_CONNECT_SWAPPED);
|
2010-05-19 16:53:15 +01:00
|
|
|
}
|
|
|
|
|
2018-11-16 15:10:11 -02:00
|
|
|
static void
|
|
|
|
update_headerbar_buttons (CcWindow *self)
|
|
|
|
{
|
|
|
|
gboolean is_main_view;
|
|
|
|
|
|
|
|
CC_ENTRY;
|
|
|
|
|
2019-09-21 08:15:57 +04:00
|
|
|
is_main_view = cc_panel_list_get_view (self->panel_list) == CC_PANEL_LIST_MAIN;
|
2018-11-16 15:10:11 -02:00
|
|
|
|
2019-09-21 08:15:57 +04:00
|
|
|
gtk_widget_set_visible (GTK_WIDGET (self->previous_button), !is_main_view);
|
|
|
|
gtk_widget_set_visible (GTK_WIDGET (self->search_button), is_main_view);
|
2018-11-16 15:10:11 -02:00
|
|
|
|
|
|
|
update_list_title (self);
|
|
|
|
|
|
|
|
CC_EXIT;
|
|
|
|
}
|
|
|
|
|
2010-05-19 11:11:26 +01:00
|
|
|
static gboolean
|
2019-09-21 08:41:01 +04:00
|
|
|
set_active_panel_from_id (CcWindow *self,
|
2018-01-21 09:46:12 -02:00
|
|
|
const gchar *start_id,
|
|
|
|
GVariant *parameters,
|
2018-05-28 22:23:35 -03:00
|
|
|
gboolean add_to_history,
|
2019-02-20 16:29:32 +01:00
|
|
|
gboolean force_moving_to_the_panel,
|
2018-01-21 09:46:12 -02:00
|
|
|
GError **error)
|
2010-05-19 11:11:26 +01:00
|
|
|
{
|
2018-03-28 10:44:46 -03:00
|
|
|
g_autoptr(GIcon) gicon = NULL;
|
|
|
|
g_autofree gchar *name = NULL;
|
2018-04-08 19:10:25 -03:00
|
|
|
CcPanelVisibility visibility;
|
2010-05-19 11:11:26 +01:00
|
|
|
GtkTreeIter iter;
|
2012-06-12 17:53:08 -04:00
|
|
|
GtkWidget *old_panel;
|
2019-02-20 16:29:32 +01:00
|
|
|
CcPanelListView view;
|
2018-03-28 10:44:46 -03:00
|
|
|
gboolean activated;
|
2018-11-12 00:30:55 -02:00
|
|
|
gboolean found;
|
2018-03-28 10:44:46 -03:00
|
|
|
|
2018-11-16 15:09:51 -02:00
|
|
|
CC_ENTRY;
|
|
|
|
|
2019-09-21 08:15:57 +04:00
|
|
|
view = cc_panel_list_get_view (self->panel_list);
|
2010-05-19 11:11:26 +01:00
|
|
|
|
2013-03-01 11:18:08 +01:00
|
|
|
/* When loading the same panel again, just set its parameters */
|
2016-05-22 00:40:55 -03:00
|
|
|
if (g_strcmp0 (self->current_panel_id, start_id) == 0)
|
2012-09-20 20:58:28 +02:00
|
|
|
{
|
2016-05-22 00:40:55 -03:00
|
|
|
g_object_set (G_OBJECT (self->current_panel), "parameters", parameters, NULL);
|
2019-02-20 16:29:32 +01:00
|
|
|
if (force_moving_to_the_panel || self->previous_list_view == view)
|
2019-09-21 08:07:18 +04:00
|
|
|
show_panel (self);
|
2019-02-20 16:29:32 +01:00
|
|
|
self->previous_list_view = view;
|
2018-11-16 15:09:51 -02:00
|
|
|
CC_RETURN (TRUE);
|
2012-09-20 20:58:28 +02:00
|
|
|
}
|
|
|
|
|
2018-11-12 00:30:55 -02:00
|
|
|
found = find_iter_for_panel_id (self, start_id, &iter);
|
|
|
|
if (!found)
|
2010-05-19 11:11:26 +01:00
|
|
|
{
|
2018-11-12 00:30:55 -02:00
|
|
|
g_warning ("Could not find settings panel \"%s\"", start_id);
|
2018-11-16 15:09:51 -02:00
|
|
|
CC_RETURN (TRUE);
|
2010-05-19 11:11:26 +01:00
|
|
|
}
|
|
|
|
|
2018-06-18 11:10:20 -03:00
|
|
|
old_panel = self->current_panel;
|
2012-10-30 23:48:29 +01:00
|
|
|
|
2018-11-12 00:30:55 -02:00
|
|
|
gtk_tree_model_get (GTK_TREE_MODEL (self->store),
|
|
|
|
&iter,
|
|
|
|
COL_NAME, &name,
|
|
|
|
COL_GICON, &gicon,
|
|
|
|
COL_VISIBILITY, &visibility,
|
|
|
|
-1);
|
2012-10-30 23:48:29 +01:00
|
|
|
|
2018-03-28 10:44:46 -03:00
|
|
|
/* Activate the panel */
|
2019-09-21 08:41:01 +04:00
|
|
|
activated = activate_panel (self, start_id, parameters, name, gicon, visibility);
|
2017-08-03 18:24:27 +01:00
|
|
|
|
2018-03-28 10:44:46 -03:00
|
|
|
/* Failed to activate the panel for some reason, let's keep the old
|
|
|
|
* panel around instead */
|
|
|
|
if (!activated)
|
2018-05-03 11:27:12 -03:00
|
|
|
{
|
|
|
|
g_debug ("Failed to activate panel");
|
2018-11-16 15:09:51 -02:00
|
|
|
CC_RETURN (TRUE);
|
2018-05-03 11:27:12 -03:00
|
|
|
}
|
|
|
|
|
2018-05-28 22:23:35 -03:00
|
|
|
if (add_to_history)
|
2019-09-21 08:41:01 +04:00
|
|
|
add_current_panel_to_history (self, start_id);
|
2018-05-28 22:23:35 -03:00
|
|
|
|
2019-02-20 16:29:32 +01:00
|
|
|
if (force_moving_to_the_panel)
|
2019-09-21 08:07:18 +04:00
|
|
|
show_panel (self);
|
2019-02-20 16:29:32 +01:00
|
|
|
|
2018-03-28 10:44:46 -03:00
|
|
|
g_free (self->current_panel_id);
|
|
|
|
self->current_panel_id = g_strdup (start_id);
|
|
|
|
|
2018-11-16 15:09:51 -02:00
|
|
|
CC_TRACE_MSG ("Current panel id: %s", start_id);
|
|
|
|
|
2018-03-28 10:44:46 -03:00
|
|
|
if (old_panel)
|
|
|
|
gtk_container_remove (GTK_CONTAINER (self->stack), old_panel);
|
|
|
|
|
2019-09-21 08:15:57 +04:00
|
|
|
cc_panel_list_set_active_panel (self->panel_list, start_id);
|
2010-05-19 11:11:26 +01:00
|
|
|
|
2018-11-16 15:10:11 -02:00
|
|
|
update_headerbar_buttons (self);
|
|
|
|
|
2018-11-16 15:09:51 -02:00
|
|
|
CC_RETURN (TRUE);
|
2010-05-19 11:11:26 +01:00
|
|
|
}
|
|
|
|
|
2013-02-17 00:30:43 -05:00
|
|
|
static void
|
2019-09-21 08:41:01 +04:00
|
|
|
set_active_panel (CcWindow *self,
|
2018-01-21 09:46:12 -02:00
|
|
|
CcPanel *panel)
|
2013-02-17 00:30:43 -05:00
|
|
|
{
|
2019-09-21 08:41:01 +04:00
|
|
|
g_return_if_fail (CC_IS_SHELL (self));
|
2013-02-17 00:30:43 -05:00
|
|
|
g_return_if_fail (panel == NULL || CC_IS_PANEL (panel));
|
|
|
|
|
2019-09-21 08:41:01 +04:00
|
|
|
if (panel != self->active_panel)
|
2013-02-17 00:30:43 -05:00
|
|
|
{
|
|
|
|
/* remove the old panel */
|
2019-09-21 08:41:01 +04:00
|
|
|
g_clear_object (&self->active_panel);
|
2013-02-17 00:30:43 -05:00
|
|
|
|
|
|
|
/* set the new panel */
|
|
|
|
if (panel)
|
2019-09-21 08:41:01 +04:00
|
|
|
self->active_panel = g_object_ref (panel);
|
2018-03-28 10:44:46 -03:00
|
|
|
|
2019-09-21 08:41:01 +04:00
|
|
|
g_object_notify (G_OBJECT (self), "active-panel");
|
2013-02-17 00:30:43 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-28 22:23:35 -03:00
|
|
|
static void
|
|
|
|
switch_to_previous_panel (CcWindow *self)
|
|
|
|
{
|
|
|
|
g_autofree gchar *previous_panel_id = NULL;
|
|
|
|
|
|
|
|
CC_ENTRY;
|
|
|
|
|
|
|
|
if (g_queue_get_length (self->previous_panels) == 0)
|
|
|
|
CC_RETURN ();
|
|
|
|
|
|
|
|
previous_panel_id = g_queue_pop_head (self->previous_panels);
|
|
|
|
|
|
|
|
g_debug ("Going to previous panel (%s)", previous_panel_id);
|
|
|
|
|
2019-09-21 08:41:01 +04:00
|
|
|
set_active_panel_from_id (self, previous_panel_id, NULL, FALSE, FALSE, NULL);
|
2018-05-28 22:23:35 -03:00
|
|
|
|
|
|
|
CC_EXIT;
|
|
|
|
}
|
|
|
|
|
2018-01-21 09:46:12 -02:00
|
|
|
/* Callbacks */
|
2019-02-20 16:29:32 +01:00
|
|
|
static void
|
2019-09-21 08:41:01 +04:00
|
|
|
update_fold_state (CcWindow *self)
|
2019-02-20 16:29:32 +01:00
|
|
|
{
|
2019-09-21 08:41:01 +04:00
|
|
|
GtkWidget *header_child = hdy_leaflet_get_visible_child (self->header_box);
|
|
|
|
HdyFold fold = hdy_leaflet_get_fold (self->header_box);
|
2019-02-20 16:29:32 +01:00
|
|
|
|
2019-09-21 08:41:01 +04:00
|
|
|
hdy_header_group_set_focus (self->header_group, fold == HDY_FOLD_FOLDED ? GTK_HEADER_BAR (header_child) : NULL);
|
2019-02-20 16:29:32 +01:00
|
|
|
|
2019-09-21 08:41:01 +04:00
|
|
|
gtk_widget_set_visible (GTK_WIDGET (self->back_revealer), fold == HDY_FOLD_FOLDED);
|
|
|
|
gtk_revealer_set_reveal_child (self->back_revealer, fold == HDY_FOLD_FOLDED);
|
2019-02-20 16:29:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-09-21 08:35:14 +04:00
|
|
|
notify_header_visible_child_cb (CcWindow *self)
|
2019-02-20 16:29:32 +01:00
|
|
|
{
|
2019-09-21 08:35:14 +04:00
|
|
|
update_fold_state (self);
|
2019-02-20 16:29:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-09-21 08:35:14 +04:00
|
|
|
notify_fold_cb (CcWindow *self)
|
2019-02-20 16:29:32 +01:00
|
|
|
{
|
2019-09-21 08:35:14 +04:00
|
|
|
update_fold_state (self);
|
2019-02-20 16:29:32 +01:00
|
|
|
}
|
|
|
|
|
2019-07-25 21:48:35 +05:30
|
|
|
static void
|
|
|
|
on_main_leaflet_fold_changed_cb (CcWindow *self)
|
|
|
|
{
|
|
|
|
GtkSelectionMode selection_mode;
|
|
|
|
|
|
|
|
g_assert (CC_IS_WINDOW (self));
|
|
|
|
|
|
|
|
selection_mode = GTK_SELECTION_SINGLE;
|
|
|
|
|
2019-09-21 08:15:57 +04:00
|
|
|
if (hdy_leaflet_get_fold (self->main_leaflet) == HDY_FOLD_FOLDED)
|
2019-07-25 21:48:35 +05:30
|
|
|
selection_mode = GTK_SELECTION_NONE;
|
|
|
|
|
2019-09-21 08:15:57 +04:00
|
|
|
cc_panel_list_set_selection_mode (self->panel_list, selection_mode);
|
2019-07-25 21:48:35 +05:30
|
|
|
}
|
|
|
|
|
2010-05-19 11:11:26 +01:00
|
|
|
static void
|
2019-09-21 08:35:14 +04:00
|
|
|
show_panel_cb (CcWindow *self,
|
|
|
|
const gchar *panel_id)
|
2010-05-19 11:11:26 +01:00
|
|
|
{
|
2018-05-28 22:07:49 -03:00
|
|
|
if (!panel_id)
|
|
|
|
return;
|
|
|
|
|
2019-09-21 08:41:01 +04:00
|
|
|
set_active_panel_from_id (self, panel_id, NULL, TRUE, FALSE, NULL);
|
2018-01-21 09:46:12 -02:00
|
|
|
}
|
2010-05-19 11:11:26 +01:00
|
|
|
|
|
|
|
static void
|
2019-09-21 08:35:14 +04:00
|
|
|
search_entry_activate_cb (CcWindow *self)
|
2010-05-19 11:11:26 +01:00
|
|
|
{
|
2018-01-21 09:46:12 -02:00
|
|
|
gboolean changed;
|
2010-05-19 11:11:26 +01:00
|
|
|
|
2019-09-21 08:15:57 +04:00
|
|
|
changed = cc_panel_list_activate (self->panel_list);
|
2010-05-19 11:11:26 +01:00
|
|
|
|
2019-09-21 08:15:57 +04:00
|
|
|
gtk_search_bar_set_search_mode (self->search_bar, !changed);
|
2010-05-19 11:11:26 +01:00
|
|
|
}
|
|
|
|
|
2019-02-20 16:29:32 +01:00
|
|
|
static void
|
2019-09-21 08:35:14 +04:00
|
|
|
back_button_clicked_cb (CcWindow *self)
|
2019-02-20 16:29:32 +01:00
|
|
|
{
|
2019-09-21 08:07:18 +04:00
|
|
|
show_sidebar (self);
|
2019-02-20 16:29:32 +01:00
|
|
|
}
|
|
|
|
|
2013-02-17 00:30:43 -05:00
|
|
|
static void
|
2019-09-21 08:41:01 +04:00
|
|
|
previous_button_clicked_cb (CcWindow *self)
|
2013-02-17 00:30:43 -05:00
|
|
|
{
|
2019-09-21 08:41:01 +04:00
|
|
|
g_debug ("Num previous panels? %d", g_queue_get_length (self->previous_panels));
|
2018-01-21 09:46:12 -02:00
|
|
|
|
|
|
|
/* When in search, simply unsed the search mode */
|
2019-09-21 08:41:01 +04:00
|
|
|
if (gtk_search_bar_get_search_mode (self->search_bar))
|
|
|
|
gtk_search_bar_set_search_mode (self->search_bar, FALSE);
|
2018-01-21 09:46:12 -02:00
|
|
|
else
|
2019-09-21 08:41:01 +04:00
|
|
|
cc_panel_list_go_previous (self->panel_list);
|
2018-11-16 15:10:11 -02:00
|
|
|
|
2019-09-21 08:41:01 +04:00
|
|
|
update_headerbar_buttons (self);
|
2013-02-17 00:30:43 -05:00
|
|
|
}
|
|
|
|
|
2010-05-19 11:11:26 +01:00
|
|
|
static void
|
2019-09-21 08:35:14 +04:00
|
|
|
gdk_window_set_cb (CcWindow *self)
|
2010-05-19 11:11:26 +01:00
|
|
|
{
|
2018-01-21 09:46:12 -02:00
|
|
|
GdkWindow *window;
|
2018-07-09 16:43:47 +02:00
|
|
|
g_autofree gchar *str = NULL;
|
2010-05-19 11:11:26 +01:00
|
|
|
|
2018-01-21 09:46:12 -02:00
|
|
|
if (!GDK_IS_X11_DISPLAY (gdk_display_get_default ()))
|
|
|
|
return;
|
2010-05-19 11:11:26 +01:00
|
|
|
|
2018-01-21 09:46:12 -02:00
|
|
|
window = gtk_widget_get_window (GTK_WIDGET (self));
|
2017-08-03 18:24:27 +01:00
|
|
|
|
2018-01-21 09:46:12 -02:00
|
|
|
if (!window)
|
|
|
|
return;
|
2017-08-03 18:24:27 +01:00
|
|
|
|
2018-01-21 09:46:12 -02:00
|
|
|
str = g_strdup_printf ("%u", (guint) GDK_WINDOW_XID (window));
|
|
|
|
g_setenv ("GNOME_CONTROL_CENTER_XID", str, TRUE);
|
|
|
|
}
|
2017-08-03 18:24:27 +01:00
|
|
|
|
2018-01-21 09:46:12 -02:00
|
|
|
static gboolean
|
2019-09-21 08:35:14 +04:00
|
|
|
window_map_event_cb (CcWindow *self)
|
2018-01-21 09:46:12 -02:00
|
|
|
{
|
|
|
|
/* If focus ends up in a category icon view one of the items is
|
|
|
|
* immediately selected which looks odd when we are starting up, so
|
|
|
|
* we explicitly unset the focus here. */
|
|
|
|
gtk_window_set_focus (GTK_WINDOW (self), NULL);
|
|
|
|
return GDK_EVENT_PROPAGATE;
|
2010-05-19 11:11:26 +01:00
|
|
|
}
|
|
|
|
|
2011-02-01 13:41:01 +00:00
|
|
|
static gboolean
|
2019-09-21 08:35:14 +04:00
|
|
|
window_key_press_event_cb (CcWindow *self,
|
|
|
|
GdkEventKey *event)
|
2011-02-01 13:41:01 +00:00
|
|
|
{
|
2012-07-16 18:05:04 +01:00
|
|
|
GdkModifierType state;
|
2017-08-03 18:24:27 +01:00
|
|
|
CcPanelListView view;
|
2018-03-06 22:55:01 -03:00
|
|
|
GdkKeymap *keymap;
|
|
|
|
gboolean retval;
|
2013-02-19 11:25:33 +01:00
|
|
|
gboolean is_rtl;
|
2011-02-01 13:41:01 +00:00
|
|
|
|
2013-08-20 00:17:58 +02:00
|
|
|
retval = GDK_EVENT_PROPAGATE;
|
2012-07-16 18:05:04 +01:00
|
|
|
state = event->state;
|
2019-09-21 08:35:14 +04:00
|
|
|
keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (self)));
|
2012-07-16 18:05:04 +01:00
|
|
|
gdk_keymap_add_virtual_modifiers (keymap, &state);
|
2018-03-06 22:55:01 -03:00
|
|
|
|
2012-07-16 18:05:04 +01:00
|
|
|
state = state & gtk_accelerator_get_default_mod_mask ();
|
2019-09-21 08:35:14 +04:00
|
|
|
is_rtl = gtk_widget_get_direction (GTK_WIDGET (self)) == GTK_TEXT_DIR_RTL;
|
2019-09-21 08:15:57 +04:00
|
|
|
view = cc_panel_list_get_view (self->panel_list);
|
2011-02-01 13:41:01 +00:00
|
|
|
|
2017-08-03 18:24:27 +01:00
|
|
|
/* The search only happens when we're in the MAIN view */
|
|
|
|
if (view == CC_PANEL_LIST_MAIN &&
|
2019-09-21 08:15:57 +04:00
|
|
|
gtk_search_bar_handle_event (self->search_bar, (GdkEvent*) event) == GDK_EVENT_STOP)
|
2017-08-03 18:24:27 +01:00
|
|
|
{
|
|
|
|
return GDK_EVENT_STOP;
|
|
|
|
}
|
2013-08-20 02:28:02 +01:00
|
|
|
|
2012-07-16 18:05:04 +01:00
|
|
|
if (state == GDK_CONTROL_MASK)
|
2011-02-01 13:41:01 +00:00
|
|
|
{
|
|
|
|
switch (event->keyval)
|
|
|
|
{
|
|
|
|
case GDK_KEY_s:
|
|
|
|
case GDK_KEY_S:
|
|
|
|
case GDK_KEY_f:
|
|
|
|
case GDK_KEY_F:
|
2017-08-03 18:24:27 +01:00
|
|
|
/* The search only happens when we're in the MAIN view */
|
|
|
|
if (view != CC_PANEL_LIST_MAIN &&
|
|
|
|
view != CC_PANEL_LIST_SEARCH)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-09-21 08:15:57 +04:00
|
|
|
retval = !gtk_search_bar_get_search_mode (self->search_bar);
|
|
|
|
gtk_search_bar_set_search_mode (self->search_bar, retval);
|
2013-08-18 23:13:46 +03:00
|
|
|
if (retval)
|
2019-09-21 08:15:57 +04:00
|
|
|
gtk_widget_grab_focus (GTK_WIDGET (self->search_entry));
|
2013-08-20 02:28:02 +01:00
|
|
|
retval = GDK_EVENT_STOP;
|
2011-02-01 13:41:01 +00:00
|
|
|
break;
|
2011-08-26 15:43:57 +01:00
|
|
|
case GDK_KEY_Q:
|
|
|
|
case GDK_KEY_q:
|
2011-10-13 10:55:24 +01:00
|
|
|
case GDK_KEY_W:
|
|
|
|
case GDK_KEY_w:
|
2017-08-03 18:24:27 +01:00
|
|
|
gtk_widget_destroy (GTK_WIDGET (self));
|
2013-08-20 00:17:58 +02:00
|
|
|
retval = GDK_EVENT_STOP;
|
2011-10-13 10:55:24 +01:00
|
|
|
break;
|
2011-02-01 13:41:01 +00:00
|
|
|
}
|
|
|
|
}
|
2013-02-19 11:25:33 +01:00
|
|
|
else if ((!is_rtl && state == GDK_MOD1_MASK && event->keyval == GDK_KEY_Left) ||
|
|
|
|
(is_rtl && state == GDK_MOD1_MASK && event->keyval == GDK_KEY_Right) ||
|
|
|
|
event->keyval == GDK_KEY_Back)
|
|
|
|
{
|
2018-05-28 22:23:35 -03:00
|
|
|
g_debug ("Going to previous panel");
|
|
|
|
switch_to_previous_panel (self);
|
2013-08-20 00:17:58 +02:00
|
|
|
retval = GDK_EVENT_STOP;
|
2013-02-19 11:25:33 +01:00
|
|
|
}
|
2013-02-17 02:56:30 -05:00
|
|
|
|
2017-08-03 18:24:27 +01:00
|
|
|
return retval;
|
2013-02-17 02:56:30 -05:00
|
|
|
}
|
|
|
|
|
2018-05-11 22:45:51 -03:00
|
|
|
static void
|
2019-09-21 08:35:14 +04:00
|
|
|
on_development_warning_dialog_responded_cb (CcWindow *self)
|
2018-05-11 22:45:51 -03:00
|
|
|
{
|
|
|
|
g_debug ("Disabling development build warning dialog");
|
|
|
|
g_settings_set_boolean (self->settings, "show-development-warning", FALSE);
|
|
|
|
|
2019-09-21 08:35:14 +04:00
|
|
|
gtk_widget_hide (GTK_WIDGET (self->development_warning_dialog));
|
2018-05-11 22:45:51 -03:00
|
|
|
}
|
|
|
|
|
2018-01-21 09:46:12 -02:00
|
|
|
/* CcShell implementation */
|
|
|
|
static gboolean
|
|
|
|
cc_window_set_active_panel_from_id (CcShell *shell,
|
|
|
|
const gchar *start_id,
|
|
|
|
GVariant *parameters,
|
|
|
|
GError **error)
|
|
|
|
{
|
2019-09-21 08:41:01 +04:00
|
|
|
return set_active_panel_from_id (CC_WINDOW (shell), start_id, parameters, TRUE, TRUE, error);
|
2018-01-21 09:46:12 -02:00
|
|
|
}
|
|
|
|
|
2013-02-17 02:56:30 -05:00
|
|
|
static void
|
2019-05-21 12:57:45 -03:00
|
|
|
cc_window_embed_widget_in_header (CcShell *shell,
|
|
|
|
GtkWidget *widget,
|
|
|
|
GtkPositionType position)
|
2013-02-17 02:56:30 -05:00
|
|
|
{
|
2018-01-21 09:46:12 -02:00
|
|
|
CcWindow *self = CC_WINDOW (shell);
|
2013-02-17 02:56:30 -05:00
|
|
|
|
2018-05-29 20:44:21 -03:00
|
|
|
CC_ENTRY;
|
|
|
|
|
2018-01-21 09:46:12 -02:00
|
|
|
/* add to header */
|
2019-05-21 12:57:45 -03:00
|
|
|
switch (position)
|
|
|
|
{
|
|
|
|
case GTK_POS_RIGHT:
|
|
|
|
gtk_container_add (GTK_CONTAINER (self->top_right_box), widget);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GTK_POS_LEFT:
|
|
|
|
gtk_container_add (GTK_CONTAINER (self->top_left_box), widget);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GTK_POS_TOP:
|
|
|
|
case GTK_POS_BOTTOM:
|
|
|
|
default:
|
|
|
|
g_warning ("Invalid position passed");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-01-21 09:46:12 -02:00
|
|
|
g_ptr_array_add (self->custom_widgets, g_object_ref (widget));
|
2010-05-19 11:11:26 +01:00
|
|
|
|
2018-01-21 09:46:12 -02:00
|
|
|
gtk_size_group_add_widget (self->header_sizegroup, widget);
|
2018-05-29 20:44:21 -03:00
|
|
|
|
|
|
|
CC_EXIT;
|
2018-01-21 09:46:12 -02:00
|
|
|
}
|
2012-05-08 16:56:20 +01:00
|
|
|
|
2018-01-21 09:46:12 -02:00
|
|
|
static GtkWidget *
|
2019-09-21 08:41:01 +04:00
|
|
|
cc_window_get_toplevel (CcShell *self)
|
2018-01-21 09:46:12 -02:00
|
|
|
{
|
2019-09-21 08:41:01 +04:00
|
|
|
return GTK_WIDGET (self);
|
2018-01-21 09:46:12 -02:00
|
|
|
}
|
2017-08-03 18:24:27 +01:00
|
|
|
|
2018-01-21 09:46:12 -02:00
|
|
|
static void
|
|
|
|
cc_shell_iface_init (CcShellInterface *iface)
|
|
|
|
{
|
|
|
|
iface->set_active_panel_from_id = cc_window_set_active_panel_from_id;
|
|
|
|
iface->embed_widget_in_header = cc_window_embed_widget_in_header;
|
|
|
|
iface->get_toplevel = cc_window_get_toplevel;
|
|
|
|
}
|
2017-08-03 18:24:27 +01:00
|
|
|
|
2018-05-11 22:45:51 -03:00
|
|
|
/* GtkWidget overrides */
|
|
|
|
static void
|
|
|
|
cc_window_map (GtkWidget *widget)
|
|
|
|
{
|
|
|
|
CcWindow *self = (CcWindow *) widget;
|
|
|
|
|
|
|
|
GTK_WIDGET_CLASS (cc_window_parent_class)->map (widget);
|
|
|
|
|
|
|
|
/* Show a warning for Flatpak builds */
|
|
|
|
if (in_flatpak_sandbox () && g_settings_get_boolean (self->settings, "show-development-warning"))
|
|
|
|
gtk_window_present (GTK_WINDOW (self->development_warning_dialog));
|
|
|
|
}
|
|
|
|
|
2018-01-21 09:46:12 -02:00
|
|
|
/* GObject Implementation */
|
|
|
|
static void
|
|
|
|
cc_window_get_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
CcWindow *self = CC_WINDOW (object);
|
2013-08-18 23:13:46 +03:00
|
|
|
|
2018-01-21 09:46:12 -02:00
|
|
|
switch (property_id)
|
|
|
|
{
|
|
|
|
case PROP_ACTIVE_PANEL:
|
|
|
|
g_value_set_object (value, self->active_panel);
|
|
|
|
break;
|
2018-04-08 17:13:42 -03:00
|
|
|
|
|
|
|
case PROP_MODEL:
|
|
|
|
g_value_set_object (value, self->store);
|
|
|
|
break;
|
|
|
|
|
2018-01-21 09:46:12 -02:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
}
|
|
|
|
}
|
2010-05-19 11:11:26 +01:00
|
|
|
|
2018-01-21 09:46:12 -02:00
|
|
|
static void
|
|
|
|
cc_window_set_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
2019-09-21 08:41:01 +04:00
|
|
|
CcWindow *self = CC_WINDOW (object);
|
2013-02-17 00:30:43 -05:00
|
|
|
|
2018-01-21 09:46:12 -02:00
|
|
|
switch (property_id)
|
|
|
|
{
|
|
|
|
case PROP_ACTIVE_PANEL:
|
2019-09-21 08:41:01 +04:00
|
|
|
set_active_panel (self, g_value_get_object (value));
|
2018-01-21 09:46:12 -02:00
|
|
|
break;
|
2018-04-08 17:13:42 -03:00
|
|
|
|
|
|
|
case PROP_MODEL:
|
2019-09-21 08:41:01 +04:00
|
|
|
g_assert (self->store == NULL);
|
|
|
|
self->store = g_value_dup_object (value);
|
2018-04-08 17:13:42 -03:00
|
|
|
break;
|
|
|
|
|
2018-01-21 09:46:12 -02:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
}
|
|
|
|
}
|
2013-02-17 00:30:43 -05:00
|
|
|
|
2018-04-08 17:13:42 -03:00
|
|
|
static void
|
|
|
|
cc_window_constructed (GObject *object)
|
|
|
|
{
|
2019-09-21 08:41:01 +04:00
|
|
|
CcWindow *self = CC_WINDOW (object);
|
2018-04-08 17:13:42 -03:00
|
|
|
g_autofree char *id = NULL;
|
|
|
|
|
|
|
|
/* Add the panels */
|
|
|
|
setup_model (self);
|
|
|
|
|
|
|
|
/* After everything is loaded, select the last used panel, if any,
|
|
|
|
* or the first visible panel */
|
|
|
|
id = g_settings_get_string (self->settings, "last-panel");
|
2019-09-21 08:15:57 +04:00
|
|
|
if (id != NULL && cc_shell_model_has_panel (self->store, id))
|
|
|
|
cc_panel_list_set_active_panel (self->panel_list, id);
|
2018-04-08 17:13:42 -03:00
|
|
|
else
|
2019-09-21 08:15:57 +04:00
|
|
|
cc_panel_list_activate (self->panel_list);
|
2018-04-08 17:13:42 -03:00
|
|
|
|
2019-02-14 13:42:03 +00:00
|
|
|
g_signal_connect_swapped (self->panel_list,
|
|
|
|
"notify::view",
|
|
|
|
G_CALLBACK (update_headerbar_buttons),
|
|
|
|
self);
|
|
|
|
|
2018-11-16 15:10:11 -02:00
|
|
|
update_headerbar_buttons (self);
|
2019-09-21 08:07:18 +04:00
|
|
|
show_sidebar (self);
|
2018-11-16 15:10:11 -02:00
|
|
|
|
2018-04-08 17:13:42 -03:00
|
|
|
G_OBJECT_CLASS (cc_window_parent_class)->constructed (object);
|
|
|
|
}
|
|
|
|
|
2018-01-21 09:46:12 -02:00
|
|
|
static void
|
|
|
|
cc_window_dispose (GObject *object)
|
|
|
|
{
|
|
|
|
CcWindow *self = CC_WINDOW (object);
|
2018-01-21 09:12:51 -02:00
|
|
|
|
2018-01-21 09:46:12 -02:00
|
|
|
g_clear_pointer (&self->current_panel_id, g_free);
|
|
|
|
g_clear_pointer (&self->custom_widgets, g_ptr_array_unref);
|
|
|
|
g_clear_object (&self->store);
|
|
|
|
g_clear_object (&self->active_panel);
|
2017-09-03 15:27:25 +02:00
|
|
|
|
2018-01-21 09:46:12 -02:00
|
|
|
G_OBJECT_CLASS (cc_window_parent_class)->dispose (object);
|
|
|
|
}
|
2017-09-03 15:27:25 +02:00
|
|
|
|
2018-01-21 09:46:12 -02:00
|
|
|
static void
|
|
|
|
cc_window_finalize (GObject *object)
|
|
|
|
{
|
|
|
|
CcWindow *self = CC_WINDOW (object);
|
|
|
|
|
|
|
|
if (self->previous_panels)
|
|
|
|
{
|
|
|
|
g_queue_free_full (self->previous_panels, g_free);
|
|
|
|
self->previous_panels = NULL;
|
|
|
|
}
|
|
|
|
|
2017-08-22 18:10:25 +02:00
|
|
|
g_clear_object (&self->settings);
|
|
|
|
|
2018-01-21 09:46:12 -02:00
|
|
|
G_OBJECT_CLASS (cc_window_parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
cc_window_class_init (CcWindowClass *klass)
|
|
|
|
{
|
|
|
|
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
|
|
|
object_class->get_property = cc_window_get_property;
|
|
|
|
object_class->set_property = cc_window_set_property;
|
2018-04-08 17:13:42 -03:00
|
|
|
object_class->constructed = cc_window_constructed;
|
2018-01-21 09:46:12 -02:00
|
|
|
object_class->dispose = cc_window_dispose;
|
|
|
|
object_class->finalize = cc_window_finalize;
|
|
|
|
|
2018-05-11 22:45:51 -03:00
|
|
|
widget_class->map = cc_window_map;
|
|
|
|
|
2018-01-21 09:46:12 -02:00
|
|
|
g_object_class_override_property (object_class, PROP_ACTIVE_PANEL, "active-panel");
|
|
|
|
|
2018-04-08 17:13:42 -03:00
|
|
|
g_object_class_install_property (object_class,
|
|
|
|
PROP_MODEL,
|
|
|
|
g_param_spec_object ("model",
|
|
|
|
"Model",
|
|
|
|
"The CcShellModel of this application",
|
|
|
|
CC_TYPE_SHELL_MODEL,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
2018-07-16 22:14:36 -03:00
|
|
|
gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/ControlCenter/gtk/cc-window.ui");
|
2018-01-21 09:46:12 -02:00
|
|
|
|
2019-02-20 16:29:32 +01:00
|
|
|
gtk_widget_class_bind_template_child (widget_class, CcWindow, back_revealer);
|
2018-05-11 22:45:51 -03:00
|
|
|
gtk_widget_class_bind_template_child (widget_class, CcWindow, development_warning_dialog);
|
2018-01-21 09:46:12 -02:00
|
|
|
gtk_widget_class_bind_template_child (widget_class, CcWindow, header);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, CcWindow, header_box);
|
2018-11-27 15:59:17 +01:00
|
|
|
gtk_widget_class_bind_template_child (widget_class, CcWindow, header_group);
|
2018-01-21 09:46:12 -02:00
|
|
|
gtk_widget_class_bind_template_child (widget_class, CcWindow, header_sizegroup);
|
2019-02-20 16:29:32 +01:00
|
|
|
gtk_widget_class_bind_template_child (widget_class, CcWindow, main_leaflet);
|
2018-01-21 09:46:12 -02:00
|
|
|
gtk_widget_class_bind_template_child (widget_class, CcWindow, panel_headerbar);
|
2018-01-21 10:14:12 -02:00
|
|
|
gtk_widget_class_bind_template_child (widget_class, CcWindow, panel_list);
|
2018-01-21 09:46:12 -02:00
|
|
|
gtk_widget_class_bind_template_child (widget_class, CcWindow, previous_button);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, CcWindow, search_bar);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, CcWindow, search_button);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, CcWindow, search_entry);
|
2019-09-21 08:15:57 +04:00
|
|
|
gtk_widget_class_bind_template_child (widget_class, CcWindow, sidebar_box);
|
2018-01-21 09:46:12 -02:00
|
|
|
gtk_widget_class_bind_template_child (widget_class, CcWindow, stack);
|
2019-05-21 12:57:45 -03:00
|
|
|
gtk_widget_class_bind_template_child (widget_class, CcWindow, top_left_box);
|
2018-01-21 09:46:12 -02:00
|
|
|
gtk_widget_class_bind_template_child (widget_class, CcWindow, top_right_box);
|
|
|
|
|
2019-02-20 16:29:32 +01:00
|
|
|
gtk_widget_class_bind_template_callback (widget_class, back_button_clicked_cb);
|
2018-01-21 09:46:12 -02:00
|
|
|
gtk_widget_class_bind_template_callback (widget_class, gdk_window_set_cb);
|
2019-02-20 16:29:32 +01:00
|
|
|
gtk_widget_class_bind_template_callback (widget_class, notify_header_visible_child_cb);
|
|
|
|
gtk_widget_class_bind_template_callback (widget_class, notify_fold_cb);
|
2019-07-25 21:48:35 +05:30
|
|
|
gtk_widget_class_bind_template_callback (widget_class, on_main_leaflet_fold_changed_cb);
|
2018-05-11 22:45:51 -03:00
|
|
|
gtk_widget_class_bind_template_callback (widget_class, on_development_warning_dialog_responded_cb);
|
2018-01-21 10:14:12 -02:00
|
|
|
gtk_widget_class_bind_template_callback (widget_class, previous_button_clicked_cb);
|
2018-01-21 09:46:12 -02:00
|
|
|
gtk_widget_class_bind_template_callback (widget_class, search_entry_activate_cb);
|
2018-01-21 10:14:12 -02:00
|
|
|
gtk_widget_class_bind_template_callback (widget_class, show_panel_cb);
|
2018-01-21 09:46:12 -02:00
|
|
|
gtk_widget_class_bind_template_callback (widget_class, update_list_title);
|
2018-01-21 10:14:12 -02:00
|
|
|
gtk_widget_class_bind_template_callback (widget_class, window_key_press_event_cb);
|
2018-01-21 09:46:12 -02:00
|
|
|
gtk_widget_class_bind_template_callback (widget_class, window_map_event_cb);
|
2018-01-21 10:14:12 -02:00
|
|
|
|
|
|
|
g_type_ensure (CC_TYPE_PANEL_LIST);
|
2013-02-17 02:56:30 -05:00
|
|
|
}
|
2012-12-06 09:30:44 +01:00
|
|
|
|
2013-02-17 02:56:30 -05:00
|
|
|
static void
|
|
|
|
cc_window_init (CcWindow *self)
|
|
|
|
{
|
2017-08-03 18:24:27 +01:00
|
|
|
gtk_widget_init_template (GTK_WIDGET (self));
|
2010-05-19 11:11:26 +01:00
|
|
|
|
2018-01-21 10:14:12 -02:00
|
|
|
gtk_widget_add_events (GTK_WIDGET (self), GDK_BUTTON_RELEASE_MASK);
|
2010-05-19 11:11:26 +01:00
|
|
|
|
2017-08-22 18:10:25 +02:00
|
|
|
self->settings = g_settings_new ("org.gnome.ControlCenter");
|
2016-05-22 00:40:55 -03:00
|
|
|
self->custom_widgets = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref);
|
2018-01-21 10:14:12 -02:00
|
|
|
self->previous_panels = g_queue_new ();
|
2019-09-21 08:15:57 +04:00
|
|
|
self->previous_list_view = cc_panel_list_get_view (self->panel_list);
|
2018-01-21 10:14:12 -02:00
|
|
|
|
2018-05-11 22:45:51 -03:00
|
|
|
/* Add a custom CSS class on development builds */
|
|
|
|
if (in_flatpak_sandbox ())
|
2019-01-21 20:44:44 -05:00
|
|
|
gtk_style_context_add_class (gtk_widget_get_style_context (GTK_WIDGET (self)), "devel");
|
2019-02-20 16:29:32 +01:00
|
|
|
|
|
|
|
update_fold_state (self);
|
2010-05-19 11:11:26 +01:00
|
|
|
}
|
|
|
|
|
2013-02-17 00:54:58 -05:00
|
|
|
CcWindow *
|
2018-04-08 17:13:42 -03:00
|
|
|
cc_window_new (GtkApplication *application,
|
|
|
|
CcShellModel *model)
|
2010-05-19 11:11:26 +01:00
|
|
|
{
|
2013-02-17 00:30:43 -05:00
|
|
|
g_return_val_if_fail (GTK_IS_APPLICATION (application), NULL);
|
|
|
|
|
2013-02-17 00:54:58 -05:00
|
|
|
return g_object_new (CC_TYPE_WINDOW,
|
2013-02-17 00:30:43 -05:00
|
|
|
"application", application,
|
|
|
|
"resizable", TRUE,
|
2013-08-18 23:11:43 +03:00
|
|
|
"title", _("Settings"),
|
2013-02-17 00:30:43 -05:00
|
|
|
"icon-name", DEFAULT_WINDOW_ICON_NAME,
|
|
|
|
"window-position", GTK_WIN_POS_CENTER,
|
2017-09-03 15:53:40 +02:00
|
|
|
"show-menubar", FALSE,
|
2018-04-08 17:13:42 -03:00
|
|
|
"model", model,
|
2013-02-17 00:30:43 -05:00
|
|
|
NULL);
|
2010-05-19 11:11:26 +01:00
|
|
|
}
|
|
|
|
|
2018-01-21 09:46:12 -02:00
|
|
|
void
|
|
|
|
cc_window_set_search_item (CcWindow *center,
|
|
|
|
const char *search)
|
|
|
|
{
|
2019-09-21 08:15:57 +04:00
|
|
|
gtk_search_bar_set_search_mode (center->search_bar, TRUE);
|
2018-01-21 09:46:12 -02:00
|
|
|
gtk_entry_set_text (GTK_ENTRY (center->search_entry), search);
|
|
|
|
gtk_editable_set_position (GTK_EDITABLE (center->search_entry), -1);
|
2018-03-28 16:39:13 -03:00
|
|
|
}
|