2010-05-19 11:11:26 +01:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2009, 2010 Intel, Inc.
|
|
|
|
* Copyright (c) 2010 Red Hat, Inc.
|
|
|
|
*
|
|
|
|
* 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>
|
|
|
|
*/
|
|
|
|
|
2012-12-11 11:46:28 +01:00
|
|
|
#include <config.h>
|
2010-05-19 11:11:26 +01:00
|
|
|
|
|
|
|
#include "gnome-control-center.h"
|
|
|
|
|
|
|
|
#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>
|
2010-05-19 11:11:26 +01:00
|
|
|
#include <string.h>
|
2013-01-11 16:21:26 +01:00
|
|
|
#include <libgd/gd-styled-text-renderer.h>
|
|
|
|
|
2010-05-19 11:11:26 +01:00
|
|
|
#include "cc-panel.h"
|
|
|
|
#include "cc-shell.h"
|
|
|
|
#include "cc-shell-category-view.h"
|
|
|
|
#include "cc-shell-model.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-02-17 00:30:43 -05:00
|
|
|
static void cc_shell_iface_init (CcShellInterface *iface);
|
|
|
|
|
|
|
|
G_DEFINE_TYPE_WITH_CODE (GnomeControlCenter, gnome_control_center, GTK_TYPE_APPLICATION_WINDOW,
|
|
|
|
G_IMPLEMENT_INTERFACE (CC_TYPE_SHELL, cc_shell_iface_init))
|
2010-05-19 11:11:26 +01:00
|
|
|
|
|
|
|
#define CONTROL_CENTER_PRIVATE(o) \
|
|
|
|
(G_TYPE_INSTANCE_GET_PRIVATE ((o), GNOME_TYPE_CONTROL_CENTER, GnomeControlCenterPrivate))
|
|
|
|
|
|
|
|
#define W(b,x) GTK_WIDGET (gtk_builder_get_object (b, x))
|
|
|
|
|
2011-09-08 16:37:14 +01:00
|
|
|
/* Use a fixed width for the shell, since resizing horizontally is more awkward
|
|
|
|
* for the user than resizing vertically
|
|
|
|
* Both sizes are defined in https://live.gnome.org/Design/SystemSettings/ */
|
2012-05-08 16:43:57 +01:00
|
|
|
#define FIXED_WIDTH 740
|
|
|
|
#define FIXED_HEIGHT 636
|
2012-05-08 19:12:46 +01:00
|
|
|
#define SMALL_SCREEN_FIXED_HEIGHT 400
|
2011-09-08 16:37:14 +01:00
|
|
|
|
|
|
|
#define MIN_ICON_VIEW_HEIGHT 300
|
2011-09-02 14:36:58 +01:00
|
|
|
|
2013-02-17 00:30:43 -05:00
|
|
|
#define DEFAULT_WINDOW_TITLE N_("Settings")
|
|
|
|
#define DEFAULT_WINDOW_ICON_NAME "preferences-desktop"
|
|
|
|
|
2012-05-21 16:01:28 +01:00
|
|
|
typedef enum {
|
|
|
|
SMALL_SCREEN_UNSET,
|
|
|
|
SMALL_SCREEN_TRUE,
|
|
|
|
SMALL_SCREEN_FALSE
|
|
|
|
} CcSmallScreen;
|
|
|
|
|
2010-05-19 11:11:26 +01:00
|
|
|
struct _GnomeControlCenterPrivate
|
|
|
|
{
|
|
|
|
GtkBuilder *builder;
|
|
|
|
GtkWidget *notebook;
|
2010-10-31 17:55:20 -04:00
|
|
|
GtkWidget *main_vbox;
|
|
|
|
GtkWidget *scrolled_window;
|
2012-04-30 16:29:07 +01:00
|
|
|
GtkWidget *search_scrolled;
|
2012-09-20 20:51:14 +02:00
|
|
|
GtkWidget *current_panel_box;
|
2012-09-20 20:58:28 +02:00
|
|
|
GtkWidget *current_panel;
|
|
|
|
char *current_panel_id;
|
2010-05-19 11:11:26 +01:00
|
|
|
GtkWidget *search_entry;
|
2011-05-20 21:27:09 -04:00
|
|
|
GtkWidget *lock_button;
|
2012-01-09 15:19:13 +00:00
|
|
|
GPtrArray *custom_widgets;
|
2010-05-19 11:11:26 +01:00
|
|
|
|
|
|
|
GtkListStore *store;
|
|
|
|
|
|
|
|
GtkTreeModel *search_filter;
|
|
|
|
GtkWidget *search_view;
|
|
|
|
gchar *filter_string;
|
|
|
|
|
2013-02-17 00:30:43 -05:00
|
|
|
CcPanel *active_panel;
|
2012-05-08 16:56:20 +01:00
|
|
|
|
|
|
|
int monitor_num;
|
2012-05-21 16:01:28 +01:00
|
|
|
CcSmallScreen small_screen;
|
2010-05-19 11:11:26 +01:00
|
|
|
};
|
|
|
|
|
2013-02-17 00:30:43 -05:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
|
|
|
PROP_ACTIVE_PANEL
|
|
|
|
};
|
|
|
|
|
2012-08-18 16:02:39 +01:00
|
|
|
/* Notebook helpers */
|
|
|
|
static GtkWidget *
|
|
|
|
notebook_get_selected_page (GtkWidget *notebook)
|
|
|
|
{
|
|
|
|
int curr;
|
|
|
|
|
|
|
|
curr = gtk_notebook_get_current_page (GTK_NOTEBOOK (notebook));
|
|
|
|
if (curr == -1)
|
|
|
|
return NULL;
|
|
|
|
return gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook), curr);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
notebook_select_page (GtkWidget *notebook,
|
|
|
|
GtkWidget *page)
|
|
|
|
{
|
|
|
|
int i, num;
|
|
|
|
|
|
|
|
num = gtk_notebook_get_n_pages (GTK_NOTEBOOK (notebook));
|
|
|
|
for (i = 0; i < num; i++)
|
|
|
|
{
|
|
|
|
if (gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook), i) == page)
|
|
|
|
{
|
|
|
|
gtk_notebook_set_current_page (GTK_NOTEBOOK (notebook), i);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
g_warning ("Couldn't select GtkNotebook page %p", page);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
notebook_remove_page (GtkWidget *notebook,
|
|
|
|
GtkWidget *page)
|
|
|
|
{
|
|
|
|
int i, num;
|
|
|
|
|
|
|
|
num = gtk_notebook_get_n_pages (GTK_NOTEBOOK (notebook));
|
|
|
|
for (i = 0; i < num; i++)
|
|
|
|
{
|
|
|
|
if (gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook), i) == page)
|
|
|
|
{
|
|
|
|
gtk_notebook_remove_page (GTK_NOTEBOOK (notebook), i);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
g_warning ("Couldn't find GtkNotebook page to remove %p", page);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
notebook_add_page (GtkWidget *notebook,
|
|
|
|
GtkWidget *page)
|
|
|
|
{
|
|
|
|
gtk_notebook_append_page (GTK_NOTEBOOK (notebook), page, NULL);
|
|
|
|
}
|
|
|
|
|
2011-07-22 13:05:01 +02:00
|
|
|
static const gchar *
|
|
|
|
get_icon_name_from_g_icon (GIcon *gicon)
|
|
|
|
{
|
|
|
|
const gchar * const *names;
|
|
|
|
GtkIconTheme *icon_theme;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (!G_IS_THEMED_ICON (gicon))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
names = g_themed_icon_get_names (G_THEMED_ICON (gicon));
|
|
|
|
icon_theme = gtk_icon_theme_get_default ();
|
|
|
|
|
|
|
|
for (i = 0; names[i] != NULL; i++)
|
|
|
|
{
|
|
|
|
if (gtk_icon_theme_has_icon (icon_theme, names[i]))
|
|
|
|
return names[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-04-30 17:05:15 +01:00
|
|
|
static gboolean
|
2013-02-17 00:30:43 -05:00
|
|
|
activate_panel (GnomeControlCenter *self,
|
2010-06-03 11:47:36 +01:00
|
|
|
const gchar *id,
|
2011-08-22 14:22:37 +02:00
|
|
|
const gchar **argv,
|
2010-05-25 14:38:36 +01:00
|
|
|
const gchar *name,
|
2011-07-22 13:05:01 +02:00
|
|
|
GIcon *gicon)
|
2010-05-19 11:11:26 +01:00
|
|
|
{
|
2013-02-17 00:30:43 -05:00
|
|
|
GnomeControlCenterPrivate *priv = self->priv;
|
2012-04-30 17:00:33 +01:00
|
|
|
GtkWidget *box;
|
|
|
|
const gchar *icon_name;
|
2010-05-19 16:53:15 +01:00
|
|
|
|
2012-04-30 17:00:33 +01:00
|
|
|
if (!id)
|
2012-04-30 17:05:15 +01:00
|
|
|
return FALSE;
|
2010-06-02 16:20:45 +01:00
|
|
|
|
2013-02-17 00:30:43 -05:00
|
|
|
priv->current_panel = GTK_WIDGET (cc_panel_loader_load_by_name (CC_SHELL (self), id, argv));
|
|
|
|
cc_shell_set_active_panel (CC_SHELL (self), CC_PANEL (priv->current_panel));
|
2012-09-20 20:58:28 +02:00
|
|
|
gtk_widget_show (priv->current_panel);
|
2010-05-25 14:22:25 +01:00
|
|
|
|
2012-04-30 17:00:33 +01:00
|
|
|
gtk_lock_button_set_permission (GTK_LOCK_BUTTON (priv->lock_button),
|
2012-09-20 20:58:28 +02:00
|
|
|
cc_panel_get_permission (CC_PANEL (priv->current_panel)));
|
2010-05-25 14:22:25 +01:00
|
|
|
|
2012-04-30 17:00:33 +01:00
|
|
|
box = gtk_alignment_new (0, 0, 1, 1);
|
2010-07-14 16:22:06 +01:00
|
|
|
|
2012-09-20 20:58:28 +02:00
|
|
|
gtk_container_add (GTK_CONTAINER (box), priv->current_panel);
|
2010-05-19 16:53:15 +01:00
|
|
|
|
2012-04-30 19:24:45 +01:00
|
|
|
gtk_widget_set_name (box, id);
|
2012-08-18 16:03:19 +01:00
|
|
|
notebook_add_page (priv->notebook, box);
|
2010-05-25 14:38:36 +01:00
|
|
|
|
2012-04-30 17:00:33 +01:00
|
|
|
/* switch to the new panel */
|
|
|
|
gtk_widget_show (box);
|
2012-08-18 16:03:19 +01:00
|
|
|
notebook_select_page (priv->notebook, box);
|
2010-07-14 16:22:06 +01:00
|
|
|
|
2012-04-30 17:00:33 +01:00
|
|
|
/* set the title of the window */
|
|
|
|
icon_name = get_icon_name_from_g_icon (gicon);
|
2013-02-17 00:30:43 -05:00
|
|
|
|
|
|
|
gtk_window_set_role (GTK_WINDOW (self), id);
|
|
|
|
gtk_window_set_title (GTK_WINDOW (self), name);
|
2012-04-30 17:00:33 +01:00
|
|
|
gtk_window_set_default_icon_name (icon_name);
|
2013-02-17 00:30:43 -05:00
|
|
|
gtk_window_set_icon_name (GTK_WINDOW (self), icon_name);
|
2012-04-30 16:29:07 +01:00
|
|
|
|
2012-09-20 20:51:14 +02:00
|
|
|
priv->current_panel_box = box;
|
2012-04-30 17:05:15 +01:00
|
|
|
|
|
|
|
return TRUE;
|
2010-05-19 11:11:26 +01:00
|
|
|
}
|
|
|
|
|
2012-01-09 15:19:13 +00:00
|
|
|
static void
|
|
|
|
_shell_remove_all_custom_widgets (GnomeControlCenterPrivate *priv)
|
|
|
|
{
|
|
|
|
GtkBox *box;
|
|
|
|
GtkWidget *widget;
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
/* remove from the header */
|
|
|
|
box = GTK_BOX (W (priv->builder, "topright"));
|
|
|
|
for (i = 0; i < priv->custom_widgets->len; i++)
|
|
|
|
{
|
|
|
|
widget = g_ptr_array_index (priv->custom_widgets, i);
|
|
|
|
gtk_container_remove (GTK_CONTAINER (box), widget);
|
|
|
|
}
|
|
|
|
g_ptr_array_set_size (priv->custom_widgets, 0);
|
|
|
|
}
|
|
|
|
|
2010-05-19 11:11:26 +01:00
|
|
|
static void
|
2013-02-17 00:30:43 -05:00
|
|
|
shell_show_overview_page (GnomeControlCenter *self)
|
2010-05-19 11:11:26 +01:00
|
|
|
{
|
2013-02-17 00:30:43 -05:00
|
|
|
GnomeControlCenterPrivate *priv = self->priv;
|
2012-05-18 16:53:41 +02:00
|
|
|
|
2012-08-18 16:03:19 +01:00
|
|
|
notebook_select_page (priv->notebook, priv->scrolled_window);
|
2010-05-19 11:11:26 +01:00
|
|
|
|
2012-09-20 20:51:14 +02:00
|
|
|
if (priv->current_panel_box)
|
|
|
|
notebook_remove_page (priv->notebook, priv->current_panel_box);
|
2012-09-20 20:58:28 +02:00
|
|
|
priv->current_panel = NULL;
|
2012-09-20 20:51:14 +02:00
|
|
|
priv->current_panel_box = NULL;
|
2012-09-25 21:23:57 +02:00
|
|
|
g_clear_pointer (&priv->current_panel_id, g_free);
|
2010-05-19 11:11:26 +01:00
|
|
|
|
|
|
|
/* clear the search text */
|
|
|
|
g_free (priv->filter_string);
|
|
|
|
priv->filter_string = g_strdup ("");
|
|
|
|
gtk_entry_set_text (GTK_ENTRY (priv->search_entry), "");
|
2011-10-13 13:10:42 +02:00
|
|
|
gtk_widget_grab_focus (priv->search_entry);
|
2010-05-25 14:38:36 +01:00
|
|
|
|
2011-05-20 21:27:09 -04:00
|
|
|
gtk_lock_button_set_permission (GTK_LOCK_BUTTON (priv->lock_button), NULL);
|
|
|
|
|
2010-05-25 14:38:36 +01:00
|
|
|
/* reset window title and icon */
|
2013-02-17 00:30:43 -05:00
|
|
|
gtk_window_set_role (GTK_WINDOW (self), NULL);
|
|
|
|
gtk_window_set_title (GTK_WINDOW (self), _(DEFAULT_WINDOW_TITLE));
|
|
|
|
gtk_window_set_default_icon_name (DEFAULT_WINDOW_ICON_NAME);
|
|
|
|
gtk_window_set_icon_name (GTK_WINDOW (self), DEFAULT_WINDOW_ICON_NAME);
|
2012-01-09 15:19:13 +00:00
|
|
|
|
2013-02-17 00:30:43 -05:00
|
|
|
cc_shell_set_active_panel (CC_SHELL (self), NULL);
|
2012-05-08 18:45:25 +02:00
|
|
|
|
2012-01-09 15:19:13 +00:00
|
|
|
/* clear any custom widgets */
|
|
|
|
_shell_remove_all_custom_widgets (priv);
|
2010-05-19 11:11:26 +01:00
|
|
|
}
|
|
|
|
|
2010-12-02 19:17:38 +00:00
|
|
|
void
|
|
|
|
gnome_control_center_set_overview_page (GnomeControlCenter *center)
|
|
|
|
{
|
2012-05-18 16:53:41 +02:00
|
|
|
shell_show_overview_page (center);
|
2010-12-02 19:17:38 +00:00
|
|
|
}
|
|
|
|
|
2013-01-07 18:10:48 +01:00
|
|
|
void
|
|
|
|
gnome_control_center_set_search_item (GnomeControlCenter *center,
|
|
|
|
const char *search)
|
|
|
|
{
|
|
|
|
shell_show_overview_page (center);
|
|
|
|
gtk_entry_set_text (GTK_ENTRY (center->priv->search_entry), search);
|
|
|
|
gtk_editable_set_position (GTK_EDITABLE (center->priv->search_entry), -1);
|
|
|
|
}
|
|
|
|
|
2010-05-19 11:11:26 +01:00
|
|
|
static void
|
|
|
|
item_activated_cb (CcShellCategoryView *view,
|
|
|
|
gchar *name,
|
|
|
|
gchar *id,
|
|
|
|
GnomeControlCenter *shell)
|
|
|
|
{
|
2012-12-11 13:25:25 +01:00
|
|
|
cc_shell_set_active_panel_from_id (CC_SHELL (shell), id, NULL, NULL);
|
2010-05-19 11:11:26 +01:00
|
|
|
}
|
|
|
|
|
2010-06-01 08:38:34 -04:00
|
|
|
static gboolean
|
|
|
|
category_focus_out (GtkWidget *view,
|
|
|
|
GdkEventFocus *event,
|
|
|
|
GnomeControlCenter *shell)
|
|
|
|
{
|
|
|
|
gtk_icon_view_unselect_all (GTK_ICON_VIEW (view));
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
category_focus_in (GtkWidget *view,
|
|
|
|
GdkEventFocus *event,
|
|
|
|
GnomeControlCenter *shell)
|
|
|
|
{
|
|
|
|
GtkTreePath *path;
|
|
|
|
|
|
|
|
if (!gtk_icon_view_get_cursor (GTK_ICON_VIEW (view), &path, NULL))
|
|
|
|
{
|
|
|
|
path = gtk_tree_path_new_from_indices (0, -1);
|
|
|
|
gtk_icon_view_set_cursor (GTK_ICON_VIEW (view), path, NULL, FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_icon_view_select_path (GTK_ICON_VIEW (view), path);
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GList *
|
|
|
|
get_item_views (GnomeControlCenter *shell)
|
|
|
|
{
|
|
|
|
GList *list, *l;
|
|
|
|
GList *res;
|
|
|
|
|
2010-10-31 17:55:20 -04:00
|
|
|
list = gtk_container_get_children (GTK_CONTAINER (shell->priv->main_vbox));
|
2010-06-01 08:38:34 -04:00
|
|
|
res = NULL;
|
|
|
|
for (l = list; l; l = l->next)
|
|
|
|
{
|
2012-06-06 16:11:26 +01:00
|
|
|
if (!CC_IS_SHELL_CATEGORY_VIEW (l->data))
|
|
|
|
continue;
|
2010-06-01 08:38:34 -04:00
|
|
|
res = g_list_append (res, cc_shell_category_view_get_item_view (CC_SHELL_CATEGORY_VIEW (l->data)));
|
|
|
|
}
|
|
|
|
|
|
|
|
g_list_free (list);
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2013-01-14 17:22:31 +01:00
|
|
|
static gboolean
|
|
|
|
is_prev_direction (GtkWidget *widget,
|
|
|
|
GtkDirectionType direction)
|
|
|
|
{
|
|
|
|
if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR &&
|
|
|
|
direction == GTK_DIR_LEFT)
|
|
|
|
return TRUE;
|
|
|
|
if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL &&
|
|
|
|
direction == GTK_DIR_RIGHT)
|
|
|
|
return TRUE;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
is_next_direction (GtkWidget *widget,
|
|
|
|
GtkDirectionType direction)
|
|
|
|
{
|
|
|
|
if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR &&
|
|
|
|
direction == GTK_DIR_RIGHT)
|
|
|
|
return TRUE;
|
|
|
|
if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL &&
|
|
|
|
direction == GTK_DIR_LEFT)
|
|
|
|
return TRUE;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GtkTreePath *
|
|
|
|
get_first_path (GtkIconView *view)
|
|
|
|
{
|
|
|
|
GtkTreeModel *model;
|
|
|
|
GtkTreeIter iter;
|
|
|
|
|
|
|
|
model = gtk_icon_view_get_model (view);
|
|
|
|
if (!gtk_tree_model_get_iter_first (model, &iter))
|
|
|
|
return NULL;
|
|
|
|
return gtk_tree_model_get_path (model, &iter);
|
|
|
|
}
|
|
|
|
|
|
|
|
static GtkTreePath *
|
|
|
|
get_last_path (GtkIconView *view)
|
|
|
|
{
|
|
|
|
GtkTreeModel *model;
|
|
|
|
GtkTreeIter iter;
|
|
|
|
GtkTreePath *path;
|
|
|
|
gboolean ret;
|
|
|
|
|
|
|
|
model = gtk_icon_view_get_model (view);
|
|
|
|
if (!gtk_tree_model_get_iter_first (model, &iter))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
ret = TRUE;
|
|
|
|
path = NULL;
|
|
|
|
|
|
|
|
while (ret)
|
|
|
|
{
|
|
|
|
g_clear_pointer (&path, gtk_tree_path_free);
|
|
|
|
path = gtk_tree_model_get_path (model, &iter);
|
|
|
|
ret = gtk_tree_model_iter_next (model, &iter);
|
|
|
|
}
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
2010-06-01 08:38:34 -04:00
|
|
|
static gboolean
|
2013-01-10 17:51:06 +01:00
|
|
|
categories_keynav_failed (GtkIconView *current_view,
|
|
|
|
GtkDirectionType direction,
|
|
|
|
GnomeControlCenter *shell)
|
2010-06-01 08:38:34 -04:00
|
|
|
{
|
|
|
|
GList *views, *v;
|
|
|
|
GtkIconView *new_view;
|
|
|
|
GtkTreePath *path;
|
|
|
|
GtkTreeModel *model;
|
|
|
|
GtkTreeIter iter;
|
|
|
|
gint col, c, dist, d;
|
|
|
|
GtkTreePath *sel;
|
|
|
|
gboolean res;
|
|
|
|
|
|
|
|
res = FALSE;
|
|
|
|
|
|
|
|
views = get_item_views (shell);
|
|
|
|
|
|
|
|
for (v = views; v; v = v->next)
|
|
|
|
{
|
|
|
|
if (v->data == current_view)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-01-14 17:22:31 +01:00
|
|
|
new_view = NULL;
|
|
|
|
|
2011-02-24 19:55:32 +01:00
|
|
|
if (direction == GTK_DIR_DOWN && v != NULL && v->next != NULL)
|
2010-06-01 08:38:34 -04:00
|
|
|
{
|
|
|
|
new_view = v->next->data;
|
|
|
|
|
|
|
|
if (gtk_icon_view_get_cursor (current_view, &path, NULL))
|
|
|
|
{
|
|
|
|
col = gtk_icon_view_get_item_column (current_view, path);
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
|
|
|
|
sel = NULL;
|
|
|
|
dist = 1000;
|
|
|
|
model = gtk_icon_view_get_model (new_view);
|
|
|
|
gtk_tree_model_get_iter_first (model, &iter);
|
|
|
|
do {
|
|
|
|
path = gtk_tree_model_get_path (model, &iter);
|
|
|
|
c = gtk_icon_view_get_item_column (new_view, path);
|
|
|
|
d = ABS (c - col);
|
|
|
|
if (d < dist)
|
|
|
|
{
|
|
|
|
if (sel)
|
|
|
|
gtk_tree_path_free (sel);
|
|
|
|
sel = path;
|
|
|
|
dist = d;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
} while (gtk_tree_model_iter_next (model, &iter));
|
|
|
|
|
|
|
|
gtk_icon_view_set_cursor (new_view, sel, NULL, FALSE);
|
|
|
|
gtk_tree_path_free (sel);
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_widget_grab_focus (GTK_WIDGET (new_view));
|
|
|
|
|
|
|
|
res = TRUE;
|
|
|
|
}
|
|
|
|
|
2011-02-24 19:55:32 +01:00
|
|
|
if (direction == GTK_DIR_UP && v != NULL && v->prev != NULL)
|
2010-06-01 08:38:34 -04:00
|
|
|
{
|
|
|
|
new_view = v->prev->data;
|
|
|
|
|
|
|
|
if (gtk_icon_view_get_cursor (current_view, &path, NULL))
|
|
|
|
{
|
|
|
|
col = gtk_icon_view_get_item_column (current_view, path);
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
|
|
|
|
sel = NULL;
|
|
|
|
dist = 1000;
|
|
|
|
model = gtk_icon_view_get_model (new_view);
|
|
|
|
gtk_tree_model_get_iter_first (model, &iter);
|
|
|
|
do {
|
|
|
|
path = gtk_tree_model_get_path (model, &iter);
|
|
|
|
c = gtk_icon_view_get_item_column (new_view, path);
|
|
|
|
d = ABS (c - col);
|
|
|
|
if (d <= dist)
|
|
|
|
{
|
|
|
|
if (sel)
|
|
|
|
gtk_tree_path_free (sel);
|
|
|
|
sel = path;
|
|
|
|
dist = d;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
} while (gtk_tree_model_iter_next (model, &iter));
|
|
|
|
|
|
|
|
gtk_icon_view_set_cursor (new_view, sel, NULL, FALSE);
|
|
|
|
gtk_tree_path_free (sel);
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_widget_grab_focus (GTK_WIDGET (new_view));
|
|
|
|
|
|
|
|
res = TRUE;
|
|
|
|
}
|
|
|
|
|
2013-01-14 17:22:31 +01:00
|
|
|
if (is_prev_direction (GTK_WIDGET (current_view), direction) && v != NULL)
|
|
|
|
{
|
|
|
|
if (gtk_icon_view_get_cursor (current_view, &path, NULL))
|
|
|
|
{
|
|
|
|
if (v->prev)
|
|
|
|
new_view = v->prev->data;
|
|
|
|
|
|
|
|
if (gtk_tree_path_prev (path))
|
|
|
|
{
|
|
|
|
new_view = current_view;
|
|
|
|
}
|
|
|
|
else if (new_view != NULL)
|
|
|
|
{
|
|
|
|
path = get_last_path (new_view);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_icon_view_set_cursor (new_view, path, NULL, FALSE);
|
|
|
|
gtk_icon_view_select_path (new_view, path);
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
gtk_widget_grab_focus (GTK_WIDGET (new_view));
|
|
|
|
|
|
|
|
res = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_next_direction (GTK_WIDGET (current_view), direction) && v != NULL)
|
|
|
|
{
|
|
|
|
if (gtk_icon_view_get_cursor (current_view, &path, NULL))
|
|
|
|
{
|
|
|
|
GtkTreeIter iter;
|
|
|
|
|
|
|
|
if (v->next)
|
|
|
|
new_view = v->next->data;
|
|
|
|
|
|
|
|
gtk_tree_path_next (path);
|
|
|
|
model = gtk_icon_view_get_model (current_view);
|
|
|
|
|
|
|
|
if (gtk_tree_model_get_iter (model, &iter, path))
|
|
|
|
{
|
|
|
|
new_view = current_view;
|
|
|
|
}
|
|
|
|
else if (new_view != NULL)
|
|
|
|
{
|
|
|
|
path = get_first_path (new_view);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_icon_view_set_cursor (new_view, path, NULL, FALSE);
|
|
|
|
gtk_icon_view_select_path (new_view, path);
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
gtk_widget_grab_focus (GTK_WIDGET (new_view));
|
|
|
|
|
|
|
|
res = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
2010-06-01 08:38:34 -04:00
|
|
|
g_list_free (views);
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2010-05-19 11:11:26 +01:00
|
|
|
static gboolean
|
|
|
|
model_filter_func (GtkTreeModel *model,
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
GnomeControlCenterPrivate *priv)
|
|
|
|
{
|
2013-01-15 11:37:24 +01:00
|
|
|
if (!priv->filter_string)
|
|
|
|
return FALSE;
|
2010-05-19 11:11:26 +01:00
|
|
|
|
2013-01-15 11:37:24 +01:00
|
|
|
return cc_shell_model_iter_matches_search (CC_SHELL_MODEL (model),
|
|
|
|
iter,
|
|
|
|
priv->filter_string);
|
2010-05-19 11:11:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2012-12-13 17:16:57 +01:00
|
|
|
category_filter_func (GtkTreeModel *model,
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
CcPanelCategory filter)
|
2010-05-19 11:11:26 +01:00
|
|
|
{
|
2012-12-13 17:16:57 +01:00
|
|
|
guint category;
|
2010-05-19 11:11:26 +01:00
|
|
|
|
|
|
|
gtk_tree_model_get (model, iter, COL_CATEGORY, &category, -1);
|
|
|
|
|
2012-12-13 17:16:57 +01:00
|
|
|
return (category == filter);
|
2010-05-19 11:11:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-05-18 16:53:41 +02:00
|
|
|
search_entry_changed_cb (GtkEntry *entry,
|
|
|
|
GnomeControlCenter *center)
|
2010-05-19 11:11:26 +01:00
|
|
|
{
|
2012-05-18 16:53:41 +02:00
|
|
|
GnomeControlCenterPrivate *priv = center->priv;
|
2011-06-21 16:56:41 +01:00
|
|
|
char *str;
|
2010-05-19 11:11:26 +01:00
|
|
|
|
|
|
|
/* if the entry text was set manually (not by the user) */
|
|
|
|
if (!g_strcmp0 (priv->filter_string, gtk_entry_get_text (entry)))
|
|
|
|
return;
|
|
|
|
|
2011-06-21 16:56:41 +01:00
|
|
|
/* Don't re-filter for added trailing or leading spaces */
|
2013-01-15 11:37:24 +01:00
|
|
|
str = cc_util_normalize_casefold_and_unaccent (gtk_entry_get_text (entry));
|
2011-06-21 16:56:41 +01:00
|
|
|
g_strstrip (str);
|
|
|
|
if (!g_strcmp0 (str, priv->filter_string))
|
|
|
|
{
|
|
|
|
g_free (str);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-05-19 11:11:26 +01:00
|
|
|
g_free (priv->filter_string);
|
2011-06-21 16:56:41 +01:00
|
|
|
priv->filter_string = str;
|
2010-05-19 11:11:26 +01:00
|
|
|
|
|
|
|
if (!g_strcmp0 (priv->filter_string, ""))
|
|
|
|
{
|
2012-05-18 16:53:41 +02:00
|
|
|
shell_show_overview_page (center);
|
2010-05-19 11:11:26 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (priv->search_filter));
|
2012-08-18 16:03:19 +01:00
|
|
|
notebook_select_page (priv->notebook, priv->search_scrolled);
|
2010-05-19 11:11:26 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
search_entry_key_press_event_cb (GtkEntry *entry,
|
|
|
|
GdkEventKey *event,
|
|
|
|
GnomeControlCenterPrivate *priv)
|
|
|
|
{
|
2010-09-10 19:09:48 +03:00
|
|
|
if (event->keyval == GDK_KEY_Return)
|
2010-05-19 11:11:26 +01:00
|
|
|
{
|
|
|
|
GtkTreePath *path;
|
2013-01-30 08:41:20 +01:00
|
|
|
GtkTreeSelection *selection;
|
2010-05-19 11:11:26 +01:00
|
|
|
|
|
|
|
path = gtk_tree_path_new_first ();
|
|
|
|
|
2013-01-30 08:41:20 +01:00
|
|
|
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->search_view));
|
|
|
|
gtk_tree_selection_select_path (selection, path);
|
2010-05-19 11:11:26 +01:00
|
|
|
|
2013-01-30 08:41:20 +01:00
|
|
|
if (!gtk_tree_selection_path_is_selected (selection, path))
|
|
|
|
{
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_tree_view_row_activated (GTK_TREE_VIEW (priv->search_view), path,
|
|
|
|
gtk_tree_view_get_column (GTK_TREE_VIEW (priv->search_view), 0));
|
2010-05-19 11:11:26 +01:00
|
|
|
gtk_tree_path_free (path);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2010-09-10 19:09:48 +03:00
|
|
|
if (event->keyval == GDK_KEY_Escape)
|
2010-05-19 11:11:26 +01:00
|
|
|
{
|
|
|
|
gtk_entry_set_text (entry, "");
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2012-05-21 23:01:50 -04:00
|
|
|
static void
|
2013-01-07 16:33:22 +01:00
|
|
|
on_search_row_activated (GtkTreeView *treeview,
|
|
|
|
GtkTreePath *path,
|
|
|
|
GtkTreeViewColumn *column,
|
|
|
|
GnomeControlCenter *shell)
|
2012-05-21 23:01:50 -04:00
|
|
|
{
|
2013-01-07 16:33:22 +01:00
|
|
|
GtkTreeSelection *selection;
|
2012-05-21 23:01:50 -04:00
|
|
|
GtkTreeModel *model;
|
|
|
|
GtkTreeIter iter;
|
|
|
|
char *id = NULL;
|
|
|
|
|
2013-01-07 16:33:22 +01:00
|
|
|
selection = gtk_tree_view_get_selection (treeview);
|
|
|
|
|
2012-05-21 23:01:50 -04:00
|
|
|
if (!gtk_tree_selection_get_selected (selection, &model, &iter))
|
|
|
|
return;
|
|
|
|
|
|
|
|
gtk_tree_model_get (model, &iter,
|
|
|
|
COL_ID, &id,
|
|
|
|
-1);
|
|
|
|
|
|
|
|
if (id)
|
|
|
|
cc_shell_set_active_panel_from_id (CC_SHELL (shell), id, NULL, NULL);
|
|
|
|
|
|
|
|
gtk_tree_selection_unselect_all (selection);
|
|
|
|
|
|
|
|
g_free (id);
|
|
|
|
}
|
|
|
|
|
2013-01-07 16:33:22 +01:00
|
|
|
static gboolean
|
|
|
|
on_search_button_press_event (GtkTreeView *treeview,
|
|
|
|
GdkEventButton *event,
|
|
|
|
GnomeControlCenter *shell)
|
|
|
|
{
|
|
|
|
if (event->type == GDK_BUTTON_PRESS && event->button == 1)
|
|
|
|
{
|
|
|
|
GtkTreePath *path = NULL;
|
|
|
|
GtkTreeSelection *selection;
|
|
|
|
GtkTreeModel *model;
|
|
|
|
GtkTreeIter iter;
|
|
|
|
|
|
|
|
/* We don't check for the position being blank,
|
|
|
|
* it could be the dead space between columns */
|
|
|
|
gtk_tree_view_is_blank_at_pos (treeview,
|
|
|
|
event->x, event->y,
|
|
|
|
&path,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL);
|
|
|
|
if (path == NULL)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
model = gtk_tree_view_get_model (treeview);
|
|
|
|
if (gtk_tree_model_get_iter (model, &iter, path) == FALSE)
|
|
|
|
{
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
selection = gtk_tree_view_get_selection (treeview);
|
|
|
|
gtk_tree_selection_select_iter (selection, &iter);
|
|
|
|
|
|
|
|
on_search_row_activated (treeview, NULL, NULL, shell);
|
|
|
|
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2010-05-19 11:11:26 +01:00
|
|
|
static void
|
|
|
|
setup_search (GnomeControlCenter *shell)
|
|
|
|
{
|
2012-04-30 16:29:07 +01:00
|
|
|
GtkWidget *search_view, *widget;
|
2011-09-14 17:36:05 -04:00
|
|
|
GtkCellRenderer *renderer;
|
2012-05-21 23:01:50 -04:00
|
|
|
GtkTreeViewColumn *column;
|
2010-05-19 11:11:26 +01:00
|
|
|
GnomeControlCenterPrivate *priv = shell->priv;
|
|
|
|
|
|
|
|
g_return_if_fail (priv->store != NULL);
|
|
|
|
|
|
|
|
/* create the search filter */
|
|
|
|
priv->search_filter = gtk_tree_model_filter_new (GTK_TREE_MODEL (priv->store),
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
gtk_tree_model_filter_set_visible_func (GTK_TREE_MODEL_FILTER (priv->search_filter),
|
|
|
|
(GtkTreeModelFilterVisibleFunc)
|
2012-05-21 23:01:50 -04:00
|
|
|
model_filter_func,
|
2010-05-19 11:11:26 +01:00
|
|
|
priv, NULL);
|
|
|
|
|
|
|
|
/* set up the search view */
|
2012-05-21 23:01:50 -04:00
|
|
|
priv->search_view = search_view = gtk_tree_view_new ();
|
|
|
|
gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (search_view), FALSE);
|
|
|
|
gtk_tree_view_set_model (GTK_TREE_VIEW (search_view),
|
2010-05-19 11:11:26 +01:00
|
|
|
GTK_TREE_MODEL (priv->search_filter));
|
2011-09-14 17:36:05 -04:00
|
|
|
|
|
|
|
renderer = gtk_cell_renderer_pixbuf_new ();
|
|
|
|
g_object_set (renderer,
|
2012-05-21 23:01:50 -04:00
|
|
|
"xpad", 15,
|
|
|
|
"ypad", 10,
|
|
|
|
"stock-size", GTK_ICON_SIZE_DIALOG,
|
|
|
|
NULL);
|
|
|
|
column = gtk_tree_view_column_new_with_attributes ("Icon", renderer,
|
|
|
|
"gicon", COL_GICON,
|
|
|
|
NULL);
|
|
|
|
gtk_tree_view_column_set_expand (column, FALSE);
|
|
|
|
gtk_tree_view_append_column (GTK_TREE_VIEW (priv->search_view), column);
|
|
|
|
|
|
|
|
renderer = gtk_cell_renderer_text_new ();
|
|
|
|
g_object_set (renderer,
|
|
|
|
"xpad", 0,
|
2011-09-14 17:36:05 -04:00
|
|
|
NULL);
|
2012-05-21 23:01:50 -04:00
|
|
|
column = gtk_tree_view_column_new_with_attributes ("Name", renderer,
|
|
|
|
"text", COL_NAME,
|
|
|
|
NULL);
|
|
|
|
gtk_tree_view_column_set_expand (column, FALSE);
|
|
|
|
gtk_tree_view_append_column (GTK_TREE_VIEW (priv->search_view), column);
|
|
|
|
|
2013-01-11 16:21:26 +01:00
|
|
|
renderer = gd_styled_text_renderer_new ();
|
|
|
|
gd_styled_text_renderer_add_class (GD_STYLED_TEXT_RENDERER (renderer), "dim-label");
|
2012-05-21 23:01:50 -04:00
|
|
|
g_object_set (renderer,
|
|
|
|
"xpad", 15,
|
|
|
|
NULL);
|
|
|
|
column = gtk_tree_view_column_new_with_attributes ("Description", renderer,
|
|
|
|
"text", COL_DESCRIPTION,
|
|
|
|
NULL);
|
|
|
|
gtk_tree_view_column_set_expand (column, TRUE);
|
|
|
|
gtk_tree_view_append_column (GTK_TREE_VIEW (priv->search_view), column);
|
2010-05-19 11:11:26 +01:00
|
|
|
|
2012-04-30 16:29:07 +01:00
|
|
|
priv->search_scrolled = W (priv->builder, "search-scrolled-window");
|
2012-06-21 10:36:08 +01:00
|
|
|
gtk_container_add (GTK_CONTAINER (priv->search_scrolled), search_view);
|
2010-05-19 11:11:26 +01:00
|
|
|
|
2013-01-07 16:33:22 +01:00
|
|
|
g_signal_connect (priv->search_view, "row-activated",
|
|
|
|
G_CALLBACK (on_search_row_activated), shell);
|
|
|
|
g_signal_connect (priv->search_view, "button-press-event",
|
|
|
|
G_CALLBACK (on_search_button_press_event), shell);
|
2010-05-19 11:11:26 +01:00
|
|
|
|
|
|
|
/* setup the search entry widget */
|
|
|
|
widget = (GtkWidget*) gtk_builder_get_object (priv->builder, "search-entry");
|
|
|
|
priv->search_entry = widget;
|
2011-06-21 16:56:41 +01:00
|
|
|
priv->filter_string = g_strdup ("");
|
2010-05-19 11:11:26 +01:00
|
|
|
|
|
|
|
g_signal_connect (widget, "changed", G_CALLBACK (search_entry_changed_cb),
|
2012-05-18 16:53:41 +02:00
|
|
|
shell);
|
2010-05-19 11:11:26 +01:00
|
|
|
g_signal_connect (widget, "key-press-event",
|
|
|
|
G_CALLBACK (search_entry_key_press_event_cb), priv);
|
|
|
|
|
2011-09-28 13:33:06 +02:00
|
|
|
gtk_widget_show (priv->search_view);
|
2010-05-19 11:11:26 +01:00
|
|
|
}
|
|
|
|
|
2011-05-20 21:27:09 -04:00
|
|
|
static void
|
|
|
|
setup_lock (GnomeControlCenter *shell)
|
|
|
|
{
|
|
|
|
GnomeControlCenterPrivate *priv = shell->priv;
|
|
|
|
|
|
|
|
priv->lock_button = W (priv->builder, "lock-button");
|
|
|
|
}
|
|
|
|
|
2010-05-19 11:11:26 +01:00
|
|
|
static void
|
2012-12-13 17:16:57 +01:00
|
|
|
add_category_view (GnomeControlCenter *shell,
|
|
|
|
CcPanelCategory category,
|
|
|
|
const char *name)
|
2010-05-19 11:11:26 +01:00
|
|
|
{
|
2011-03-06 05:01:29 -05:00
|
|
|
GtkTreeModel *filter;
|
|
|
|
GtkWidget *categoryview;
|
2010-05-19 11:11:26 +01:00
|
|
|
|
2012-12-13 17:16:57 +01:00
|
|
|
if (category > 0)
|
2012-04-10 16:55:26 -04:00
|
|
|
{
|
|
|
|
GtkWidget *separator;
|
|
|
|
separator = gtk_separator_new (GTK_ORIENTATION_HORIZONTAL);
|
|
|
|
gtk_widget_set_margin_top (separator, 11);
|
|
|
|
gtk_widget_set_margin_bottom (separator, 10);
|
|
|
|
gtk_box_pack_start (GTK_BOX (shell->priv->main_vbox), separator, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (separator);
|
|
|
|
}
|
|
|
|
|
2011-03-06 05:01:29 -05:00
|
|
|
/* create new category view for this category */
|
|
|
|
filter = gtk_tree_model_filter_new (GTK_TREE_MODEL (shell->priv->store),
|
|
|
|
NULL);
|
|
|
|
gtk_tree_model_filter_set_visible_func (GTK_TREE_MODEL_FILTER (filter),
|
|
|
|
(GtkTreeModelFilterVisibleFunc) category_filter_func,
|
2012-12-13 17:16:57 +01:00
|
|
|
GINT_TO_POINTER (category), NULL);
|
2010-05-19 11:11:26 +01:00
|
|
|
|
2011-03-06 05:01:29 -05:00
|
|
|
categoryview = cc_shell_category_view_new (name, filter);
|
|
|
|
gtk_box_pack_start (GTK_BOX (shell->priv->main_vbox), categoryview, FALSE, TRUE, 0);
|
2010-05-19 11:11:26 +01:00
|
|
|
|
2011-03-06 05:01:29 -05:00
|
|
|
g_signal_connect (cc_shell_category_view_get_item_view (CC_SHELL_CATEGORY_VIEW (categoryview)),
|
|
|
|
"desktop-item-activated",
|
|
|
|
G_CALLBACK (item_activated_cb), shell);
|
2010-05-19 11:11:26 +01:00
|
|
|
|
2011-03-06 05:01:29 -05:00
|
|
|
gtk_widget_show (categoryview);
|
2010-05-19 11:11:26 +01:00
|
|
|
|
2011-03-06 05:01:29 -05:00
|
|
|
g_signal_connect (cc_shell_category_view_get_item_view (CC_SHELL_CATEGORY_VIEW (categoryview)),
|
|
|
|
"focus-in-event",
|
|
|
|
G_CALLBACK (category_focus_in), shell);
|
|
|
|
g_signal_connect (cc_shell_category_view_get_item_view (CC_SHELL_CATEGORY_VIEW (categoryview)),
|
|
|
|
"focus-out-event",
|
|
|
|
G_CALLBACK (category_focus_out), shell);
|
|
|
|
g_signal_connect (cc_shell_category_view_get_item_view (CC_SHELL_CATEGORY_VIEW (categoryview)),
|
|
|
|
"keynav-failed",
|
2013-01-10 17:51:06 +01:00
|
|
|
G_CALLBACK (categories_keynav_failed), shell);
|
2011-03-06 05:01:29 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
setup_model (GnomeControlCenter *shell)
|
|
|
|
{
|
|
|
|
GnomeControlCenterPrivate *priv = shell->priv;
|
|
|
|
|
2012-05-08 16:56:20 +01:00
|
|
|
gtk_widget_set_margin_top (shell->priv->main_vbox, 8);
|
|
|
|
gtk_widget_set_margin_bottom (shell->priv->main_vbox, 8);
|
|
|
|
gtk_widget_set_margin_left (shell->priv->main_vbox, 12);
|
|
|
|
gtk_widget_set_margin_right (shell->priv->main_vbox, 12);
|
2011-03-06 05:01:29 -05:00
|
|
|
gtk_container_set_focus_vadjustment (GTK_CONTAINER (shell->priv->main_vbox),
|
|
|
|
gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (shell->priv->scrolled_window)));
|
|
|
|
|
|
|
|
priv->store = (GtkListStore *) cc_shell_model_new ();
|
|
|
|
|
2012-12-13 17:16:57 +01:00
|
|
|
/* Add categories */
|
|
|
|
add_category_view (shell, CC_CATEGORY_PERSONAL, C_("category", "Personal"));
|
|
|
|
add_category_view (shell, CC_CATEGORY_HARDWARE, C_("category", "Hardware"));
|
|
|
|
add_category_view (shell, CC_CATEGORY_SYSTEM, C_("category", "System"));
|
2011-03-06 05:01:29 -05:00
|
|
|
|
2012-12-13 17:16:57 +01:00
|
|
|
cc_panel_loader_fill_model (CC_SHELL_MODEL (shell->priv->store));
|
2010-05-19 16:53:15 +01:00
|
|
|
}
|
|
|
|
|
2010-05-19 11:11:26 +01:00
|
|
|
static void
|
|
|
|
home_button_clicked_cb (GtkButton *button,
|
|
|
|
GnomeControlCenter *shell)
|
|
|
|
{
|
2012-05-18 16:53:41 +02:00
|
|
|
shell_show_overview_page (shell);
|
2010-05-19 11:11:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-02-17 00:30:43 -05:00
|
|
|
notebook_page_notify_cb (GtkNotebook *notebook,
|
|
|
|
GParamSpec *spec,
|
|
|
|
GnomeControlCenter *self)
|
2010-05-19 11:11:26 +01:00
|
|
|
{
|
2013-02-17 00:30:43 -05:00
|
|
|
GnomeControlCenterPrivate *priv = self->priv;
|
2012-05-08 16:37:51 +01:00
|
|
|
int nat_height;
|
2012-04-30 19:24:45 +01:00
|
|
|
GtkWidget *child;
|
|
|
|
|
2012-08-18 16:03:19 +01:00
|
|
|
child = notebook_get_selected_page (GTK_WIDGET (notebook));
|
2012-05-08 16:37:51 +01:00
|
|
|
|
2010-05-19 11:11:26 +01:00
|
|
|
/* make sure the home button is shown on all pages except the overview page */
|
|
|
|
|
2012-04-30 16:29:07 +01:00
|
|
|
if (child == priv->scrolled_window || child == priv->search_scrolled)
|
2011-02-12 19:37:27 +00:00
|
|
|
{
|
|
|
|
gtk_widget_hide (W (priv->builder, "home-button"));
|
|
|
|
gtk_widget_show (W (priv->builder, "search-entry"));
|
2011-05-20 21:27:09 -04:00
|
|
|
gtk_widget_hide (W (priv->builder, "lock-button"));
|
2012-05-08 16:37:51 +01:00
|
|
|
|
|
|
|
gtk_widget_get_preferred_height_for_width (GTK_WIDGET (priv->main_vbox),
|
|
|
|
FIXED_WIDTH, NULL, &nat_height);
|
2012-05-08 18:48:06 +01:00
|
|
|
gtk_scrolled_window_set_min_content_height (GTK_SCROLLED_WINDOW (priv->scrolled_window),
|
2012-05-21 16:01:28 +01:00
|
|
|
priv->small_screen == SMALL_SCREEN_TRUE ? SMALL_SCREEN_FIXED_HEIGHT : nat_height);
|
2011-02-12 19:37:27 +00:00
|
|
|
}
|
2010-05-19 11:11:26 +01:00
|
|
|
else
|
2011-02-12 19:37:27 +00:00
|
|
|
{
|
|
|
|
gtk_widget_show (W (priv->builder, "home-button"));
|
|
|
|
gtk_widget_hide (W (priv->builder, "search-entry"));
|
2012-05-08 16:37:51 +01:00
|
|
|
/* set the scrolled window small so that it doesn't force
|
|
|
|
the window to be larger than this panel */
|
2013-02-17 00:30:43 -05:00
|
|
|
gtk_widget_get_preferred_height_for_width (GTK_WIDGET (self),
|
2012-05-08 16:37:51 +01:00
|
|
|
FIXED_WIDTH, NULL, &nat_height);
|
2012-05-08 18:48:06 +01:00
|
|
|
gtk_scrolled_window_set_min_content_height (GTK_SCROLLED_WINDOW (priv->scrolled_window), MIN_ICON_VIEW_HEIGHT);
|
2013-02-17 00:30:43 -05:00
|
|
|
gtk_window_resize (GTK_WINDOW (self),
|
2012-05-08 16:37:51 +01:00
|
|
|
FIXED_WIDTH,
|
|
|
|
nat_height);
|
2011-02-12 19:37:27 +00:00
|
|
|
}
|
2010-05-19 11:11:26 +01:00
|
|
|
}
|
|
|
|
|
2012-01-09 15:19:13 +00:00
|
|
|
/* CcShell implementation */
|
|
|
|
static void
|
|
|
|
_shell_embed_widget_in_header (CcShell *shell,
|
|
|
|
GtkWidget *widget)
|
|
|
|
{
|
|
|
|
GnomeControlCenterPrivate *priv = GNOME_CONTROL_CENTER (shell)->priv;
|
|
|
|
GtkBox *box;
|
|
|
|
|
|
|
|
/* add to header */
|
|
|
|
box = GTK_BOX (W (priv->builder, "topright"));
|
|
|
|
gtk_box_pack_end (box, widget, FALSE, FALSE, 0);
|
|
|
|
g_ptr_array_add (priv->custom_widgets, g_object_ref (widget));
|
|
|
|
}
|
|
|
|
|
2010-05-19 11:11:26 +01:00
|
|
|
/* CcShell implementation */
|
|
|
|
static gboolean
|
|
|
|
_shell_set_active_panel_from_id (CcShell *shell,
|
|
|
|
const gchar *start_id,
|
2011-08-22 14:22:37 +02:00
|
|
|
const gchar **argv,
|
2010-05-19 11:11:26 +01:00
|
|
|
GError **err)
|
|
|
|
{
|
|
|
|
GtkTreeIter iter;
|
|
|
|
gboolean iter_valid;
|
|
|
|
gchar *name = NULL;
|
2012-06-12 17:53:08 -04:00
|
|
|
GIcon *gicon = NULL;
|
2010-05-19 11:11:26 +01:00
|
|
|
GnomeControlCenterPrivate *priv = GNOME_CONTROL_CENTER (shell)->priv;
|
2012-06-12 17:53:08 -04:00
|
|
|
GtkWidget *old_panel;
|
2010-05-19 11:11:26 +01:00
|
|
|
|
2012-09-20 20:58:28 +02:00
|
|
|
/* When loading the same panel again, just set the argv */
|
|
|
|
if (g_strcmp0 (priv->current_panel_id, start_id) == 0)
|
|
|
|
{
|
|
|
|
g_object_set (G_OBJECT (priv->current_panel), "argv", argv, NULL);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2012-01-09 15:19:13 +00:00
|
|
|
/* clear any custom widgets */
|
|
|
|
_shell_remove_all_custom_widgets (priv);
|
2010-05-19 11:11:26 +01:00
|
|
|
|
|
|
|
iter_valid = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (priv->store),
|
|
|
|
&iter);
|
|
|
|
|
|
|
|
/* find the details for this item */
|
|
|
|
while (iter_valid)
|
|
|
|
{
|
|
|
|
gchar *id;
|
|
|
|
|
|
|
|
gtk_tree_model_get (GTK_TREE_MODEL (priv->store), &iter,
|
|
|
|
COL_NAME, &name,
|
2011-07-22 13:05:01 +02:00
|
|
|
COL_GICON, &gicon,
|
2010-06-03 11:47:36 +01:00
|
|
|
COL_ID, &id,
|
2010-05-19 11:11:26 +01:00
|
|
|
-1);
|
2010-06-02 17:53:42 +01:00
|
|
|
|
2010-05-19 11:11:26 +01:00
|
|
|
if (id && !strcmp (id, start_id))
|
|
|
|
{
|
|
|
|
g_free (id);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_free (id);
|
|
|
|
g_free (name);
|
2011-07-22 13:05:01 +02:00
|
|
|
if (gicon)
|
|
|
|
g_object_unref (gicon);
|
2010-05-19 11:11:26 +01:00
|
|
|
|
|
|
|
name = NULL;
|
|
|
|
id = NULL;
|
2012-06-12 17:53:08 -04:00
|
|
|
gicon = NULL;
|
2010-05-19 11:11:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
iter_valid = gtk_tree_model_iter_next (GTK_TREE_MODEL (priv->store),
|
|
|
|
&iter);
|
|
|
|
}
|
|
|
|
|
2012-10-30 23:48:29 +01:00
|
|
|
old_panel = priv->current_panel_box;
|
|
|
|
|
2010-05-19 11:11:26 +01:00
|
|
|
if (!name)
|
|
|
|
{
|
|
|
|
g_warning ("Could not find settings panel \"%s\"", start_id);
|
|
|
|
}
|
2013-01-15 11:37:24 +01:00
|
|
|
else if (activate_panel (GNOME_CONTROL_CENTER (shell), start_id, argv,
|
2012-06-12 17:53:08 -04:00
|
|
|
name, gicon) == FALSE)
|
2010-05-19 11:11:26 +01:00
|
|
|
{
|
2012-11-02 17:25:07 +01:00
|
|
|
/* Failed to activate the panel for some reason,
|
|
|
|
* let's keep the old panel around instead */
|
2012-06-12 17:53:08 -04:00
|
|
|
}
|
2012-09-20 20:58:28 +02:00
|
|
|
else
|
|
|
|
{
|
2012-10-30 23:48:29 +01:00
|
|
|
/* Successful activation */
|
|
|
|
g_free (priv->current_panel_id);
|
2012-09-20 20:58:28 +02:00
|
|
|
priv->current_panel_id = g_strdup (start_id);
|
2012-10-30 23:48:29 +01:00
|
|
|
|
|
|
|
if (old_panel)
|
|
|
|
notebook_remove_page (priv->notebook, old_panel);
|
2012-09-20 20:58:28 +02:00
|
|
|
}
|
2010-05-19 11:11:26 +01:00
|
|
|
|
2012-06-12 17:53:08 -04:00
|
|
|
g_free (name);
|
|
|
|
if (gicon)
|
|
|
|
g_object_unref (gicon);
|
2010-05-19 11:11:26 +01:00
|
|
|
|
2012-06-12 17:53:08 -04:00
|
|
|
return TRUE;
|
2010-05-19 11:11:26 +01:00
|
|
|
}
|
|
|
|
|
2010-10-16 15:26:35 +02:00
|
|
|
static GtkWidget *
|
|
|
|
_shell_get_toplevel (CcShell *shell)
|
|
|
|
{
|
2013-02-17 00:30:43 -05:00
|
|
|
return GTK_WIDGET (shell);
|
2010-10-16 15:26:35 +02:00
|
|
|
}
|
2010-05-19 11:11:26 +01:00
|
|
|
|
|
|
|
/* GObject Implementation */
|
|
|
|
static void
|
|
|
|
gnome_control_center_get_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
2013-02-17 00:30:43 -05:00
|
|
|
GnomeControlCenterPrivate *priv = GNOME_CONTROL_CENTER (object)->priv;
|
|
|
|
|
2010-05-19 11:11:26 +01:00
|
|
|
switch (property_id)
|
|
|
|
{
|
2013-02-17 00:30:43 -05:00
|
|
|
case PROP_ACTIVE_PANEL:
|
|
|
|
g_value_set_object (value, priv->active_panel);
|
|
|
|
break;
|
2010-05-19 11:11:26 +01:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-17 00:30:43 -05:00
|
|
|
static void
|
|
|
|
set_active_panel (GnomeControlCenter *shell,
|
|
|
|
CcPanel *panel)
|
|
|
|
{
|
|
|
|
g_return_if_fail (CC_IS_SHELL (shell));
|
|
|
|
g_return_if_fail (panel == NULL || CC_IS_PANEL (panel));
|
|
|
|
|
|
|
|
if (panel != shell->priv->active_panel)
|
|
|
|
{
|
|
|
|
/* remove the old panel */
|
|
|
|
g_clear_object (&shell->priv->active_panel);
|
|
|
|
|
|
|
|
/* set the new panel */
|
|
|
|
if (panel)
|
|
|
|
{
|
|
|
|
shell->priv->active_panel = g_object_ref (panel);
|
|
|
|
}
|
|
|
|
g_object_notify (G_OBJECT (shell), "active-panel");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-19 11:11:26 +01:00
|
|
|
static void
|
|
|
|
gnome_control_center_set_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
2013-02-17 00:30:43 -05:00
|
|
|
GnomeControlCenter *shell = GNOME_CONTROL_CENTER (object);
|
|
|
|
|
2010-05-19 11:11:26 +01:00
|
|
|
switch (property_id)
|
|
|
|
{
|
2013-02-17 00:30:43 -05:00
|
|
|
case PROP_ACTIVE_PANEL:
|
|
|
|
set_active_panel (shell, g_value_get_object (value));
|
|
|
|
break;
|
2010-05-19 11:11:26 +01:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gnome_control_center_dispose (GObject *object)
|
|
|
|
{
|
|
|
|
GnomeControlCenterPrivate *priv = GNOME_CONTROL_CENTER (object)->priv;
|
|
|
|
|
2012-09-20 20:58:28 +02:00
|
|
|
g_free (priv->current_panel_id);
|
|
|
|
|
2012-01-09 15:19:13 +00:00
|
|
|
if (priv->custom_widgets)
|
|
|
|
{
|
|
|
|
g_ptr_array_unref (priv->custom_widgets);
|
|
|
|
priv->custom_widgets = NULL;
|
|
|
|
}
|
2010-05-19 11:11:26 +01:00
|
|
|
|
|
|
|
if (priv->builder)
|
|
|
|
{
|
|
|
|
g_object_unref (priv->builder);
|
|
|
|
priv->builder = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (priv->store)
|
|
|
|
{
|
|
|
|
g_object_unref (priv->store);
|
|
|
|
priv->store = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (priv->search_filter)
|
|
|
|
{
|
|
|
|
g_object_unref (priv->search_filter);
|
|
|
|
priv->search_filter = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (gnome_control_center_parent_class)->dispose (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gnome_control_center_finalize (GObject *object)
|
|
|
|
{
|
|
|
|
GnomeControlCenterPrivate *priv = GNOME_CONTROL_CENTER (object)->priv;
|
|
|
|
|
|
|
|
if (priv->filter_string)
|
|
|
|
{
|
|
|
|
g_free (priv->filter_string);
|
|
|
|
priv->filter_string = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (gnome_control_center_parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
2013-02-17 00:30:43 -05:00
|
|
|
static void
|
|
|
|
cc_shell_iface_init (CcShellInterface *iface)
|
|
|
|
{
|
|
|
|
iface->set_active_panel_from_id = _shell_set_active_panel_from_id;
|
|
|
|
iface->embed_widget_in_header = _shell_embed_widget_in_header;
|
|
|
|
iface->get_toplevel = _shell_get_toplevel;
|
|
|
|
}
|
|
|
|
|
2010-05-19 11:11:26 +01:00
|
|
|
static void
|
|
|
|
gnome_control_center_class_init (GnomeControlCenterClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
|
|
|
g_type_class_add_private (klass, sizeof (GnomeControlCenterPrivate));
|
|
|
|
|
|
|
|
object_class->get_property = gnome_control_center_get_property;
|
|
|
|
object_class->set_property = gnome_control_center_set_property;
|
|
|
|
object_class->dispose = gnome_control_center_dispose;
|
|
|
|
object_class->finalize = gnome_control_center_finalize;
|
|
|
|
|
2013-02-17 00:30:43 -05:00
|
|
|
g_object_class_override_property (object_class, PROP_ACTIVE_PANEL, "active-panel");
|
2010-05-19 11:11:26 +01:00
|
|
|
}
|
|
|
|
|
2011-02-01 13:41:01 +00:00
|
|
|
static gboolean
|
|
|
|
window_key_press_event (GtkWidget *win,
|
|
|
|
GdkEventKey *event,
|
|
|
|
GnomeControlCenter *self)
|
|
|
|
{
|
2012-07-16 18:05:04 +01:00
|
|
|
GdkKeymap *keymap;
|
2011-02-01 13:41:01 +00:00
|
|
|
gboolean retval;
|
2012-07-16 18:05:04 +01:00
|
|
|
GdkModifierType state;
|
|
|
|
|
|
|
|
if (event->state == 0)
|
|
|
|
return FALSE;
|
2011-02-01 13:41:01 +00:00
|
|
|
|
|
|
|
retval = FALSE;
|
2012-07-16 18:05:04 +01:00
|
|
|
state = event->state;
|
|
|
|
keymap = gdk_keymap_get_default ();
|
|
|
|
gdk_keymap_add_virtual_modifiers (keymap, &state);
|
|
|
|
state = state & gtk_accelerator_get_default_mod_mask ();
|
2011-02-01 13:41:01 +00: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:
|
2011-10-13 10:53:08 +01:00
|
|
|
if (gtk_widget_get_visible (self->priv->search_entry))
|
|
|
|
{
|
|
|
|
gtk_widget_grab_focus (self->priv->search_entry);
|
|
|
|
retval = TRUE;
|
|
|
|
}
|
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:
|
2013-02-17 00:30:43 -05:00
|
|
|
gtk_widget_destroy (GTK_WIDGET (self));
|
2011-08-26 15:43:57 +01:00
|
|
|
retval = TRUE;
|
|
|
|
break;
|
2011-10-13 10:55:24 +01:00
|
|
|
case GDK_KEY_W:
|
|
|
|
case GDK_KEY_w:
|
2012-08-18 16:03:19 +01:00
|
|
|
if (notebook_get_selected_page (self->priv->notebook) != self->priv->scrolled_window)
|
2012-05-18 16:53:41 +02:00
|
|
|
shell_show_overview_page (self);
|
2011-10-13 10:55:24 +01:00
|
|
|
retval = TRUE;
|
|
|
|
break;
|
2011-02-01 13:41:01 +00:00
|
|
|
}
|
|
|
|
}
|
2013-01-14 15:24:33 +01:00
|
|
|
else if ((state == GDK_MOD1_MASK && event->keyval == GDK_KEY_Up) ||
|
|
|
|
event->keyval == GDK_KEY_Back)
|
|
|
|
{
|
|
|
|
if (notebook_get_selected_page (self->priv->notebook) != self->priv->scrolled_window)
|
|
|
|
shell_show_overview_page (self);
|
|
|
|
retval = TRUE;
|
|
|
|
}
|
2011-02-01 13:41:01 +00:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2012-05-08 16:56:20 +01:00
|
|
|
static gint
|
|
|
|
get_monitor_height (GnomeControlCenter *self)
|
|
|
|
{
|
|
|
|
GdkScreen *screen;
|
|
|
|
GdkRectangle rect;
|
|
|
|
|
2012-05-21 14:23:00 +01:00
|
|
|
/* We cannot use workarea here, as this wouldn't
|
|
|
|
* be updated when we read it after a monitors-changed signal */
|
2013-02-17 00:30:43 -05:00
|
|
|
screen = gtk_widget_get_screen (GTK_WIDGET (self));
|
2012-05-08 16:56:20 +01:00
|
|
|
gdk_screen_get_monitor_geometry (screen, self->priv->monitor_num, &rect);
|
|
|
|
|
|
|
|
return rect.height;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
update_monitor_number (GnomeControlCenter *self)
|
|
|
|
{
|
|
|
|
gboolean changed = FALSE;
|
|
|
|
GtkWidget *widget;
|
|
|
|
GdkScreen *screen;
|
|
|
|
GdkWindow *window;
|
|
|
|
int monitor;
|
|
|
|
|
2013-02-17 00:30:43 -05:00
|
|
|
widget = GTK_WIDGET (self);
|
2012-05-08 16:56:20 +01:00
|
|
|
|
|
|
|
window = gtk_widget_get_window (widget);
|
|
|
|
screen = gtk_widget_get_screen (widget);
|
|
|
|
monitor = gdk_screen_get_monitor_at_window (screen, window);
|
|
|
|
if (self->priv->monitor_num != monitor)
|
|
|
|
{
|
|
|
|
self->priv->monitor_num = monitor;
|
|
|
|
changed = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return changed;
|
|
|
|
}
|
|
|
|
|
2012-05-21 16:01:28 +01:00
|
|
|
static CcSmallScreen
|
|
|
|
is_small (GnomeControlCenter *self)
|
|
|
|
{
|
|
|
|
if (get_monitor_height (self) <= FIXED_HEIGHT)
|
|
|
|
return SMALL_SCREEN_TRUE;
|
|
|
|
return SMALL_SCREEN_FALSE;
|
|
|
|
}
|
|
|
|
|
2012-05-08 16:56:20 +01:00
|
|
|
static void
|
|
|
|
update_small_screen_settings (GnomeControlCenter *self)
|
|
|
|
{
|
2012-05-21 16:01:28 +01:00
|
|
|
CcSmallScreen small;
|
2012-05-08 16:56:20 +01:00
|
|
|
|
|
|
|
update_monitor_number (self);
|
2012-05-21 16:01:28 +01:00
|
|
|
small = is_small (self);
|
2012-05-08 16:56:20 +01:00
|
|
|
|
2012-05-21 16:01:28 +01:00
|
|
|
if (small == SMALL_SCREEN_TRUE)
|
2012-05-08 16:56:20 +01:00
|
|
|
{
|
2013-02-17 00:30:43 -05:00
|
|
|
gtk_window_set_resizable (GTK_WINDOW (self), TRUE);
|
2012-05-08 16:56:20 +01:00
|
|
|
|
2012-05-21 16:01:28 +01:00
|
|
|
if (self->priv->small_screen != small)
|
2013-02-17 00:30:43 -05:00
|
|
|
gtk_window_maximize (GTK_WINDOW (self));
|
2012-05-08 16:56:20 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-05-21 16:01:28 +01:00
|
|
|
if (self->priv->small_screen != small)
|
2013-02-17 00:30:43 -05:00
|
|
|
gtk_window_unmaximize (GTK_WINDOW (self));
|
2012-05-08 16:56:20 +01:00
|
|
|
|
2013-02-17 00:30:43 -05:00
|
|
|
gtk_window_set_resizable (GTK_WINDOW (self), FALSE);
|
2012-05-08 16:56:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
self->priv->small_screen = small;
|
2012-05-21 16:08:52 +01:00
|
|
|
|
|
|
|
/* And update the minimum sizes */
|
2013-02-17 00:30:43 -05:00
|
|
|
notebook_page_notify_cb (GTK_NOTEBOOK (self->priv->notebook), NULL, self);
|
2012-05-08 16:56:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
main_window_configure_cb (GtkWidget *widget,
|
|
|
|
GdkEvent *event,
|
|
|
|
GnomeControlCenter *self)
|
|
|
|
{
|
|
|
|
update_small_screen_settings (self);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2012-05-18 16:40:31 +02:00
|
|
|
static void
|
|
|
|
application_set_cb (GObject *object,
|
|
|
|
GParamSpec *pspec,
|
|
|
|
GnomeControlCenter *self)
|
|
|
|
{
|
|
|
|
/* update small screen settings now - to avoid visible resizing, we want
|
|
|
|
* to do it before showing the window, and GtkApplicationWindow cannot be
|
|
|
|
* realized unless its application property has been set */
|
2013-02-17 00:30:43 -05:00
|
|
|
if (gtk_window_get_application (GTK_WINDOW (self)))
|
2012-05-18 16:40:31 +02:00
|
|
|
{
|
2013-02-17 00:30:43 -05:00
|
|
|
gtk_widget_realize (GTK_WIDGET (self));
|
2012-05-18 16:40:31 +02:00
|
|
|
update_small_screen_settings (self);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-08 16:56:20 +01:00
|
|
|
static void
|
|
|
|
monitors_changed_cb (GdkScreen *screen,
|
|
|
|
GnomeControlCenter *self)
|
|
|
|
{
|
2012-05-08 18:54:28 +01:00
|
|
|
/* We reset small_screen_set to make sure that the
|
|
|
|
* window gets maximised if need be, in update_small_screen_settings() */
|
2012-05-21 16:01:28 +01:00
|
|
|
self->priv->small_screen = SMALL_SCREEN_UNSET;
|
2012-05-08 16:56:20 +01:00
|
|
|
update_small_screen_settings (self);
|
|
|
|
}
|
|
|
|
|
2013-01-20 15:17:20 +01:00
|
|
|
static void
|
|
|
|
gdk_window_set_cb (GObject *object,
|
|
|
|
GParamSpec *pspec,
|
|
|
|
GnomeControlCenter *self)
|
|
|
|
{
|
|
|
|
GdkWindow *window;
|
|
|
|
gchar *str;
|
|
|
|
|
|
|
|
if (!GDK_IS_X11_DISPLAY (gdk_display_get_default ()))
|
|
|
|
return;
|
|
|
|
|
2013-02-17 00:30:43 -05:00
|
|
|
window = gtk_widget_get_window (GTK_WIDGET (self));
|
2013-01-20 15:17:20 +01:00
|
|
|
|
|
|
|
if (!window)
|
|
|
|
return;
|
|
|
|
|
|
|
|
str = g_strdup_printf ("%u", (guint) GDK_WINDOW_XID (window));
|
|
|
|
g_setenv ("GNOME_CONTROL_CENTER_XID", str, TRUE);
|
|
|
|
g_free (str);
|
|
|
|
}
|
|
|
|
|
2010-05-19 11:11:26 +01:00
|
|
|
static void
|
|
|
|
gnome_control_center_init (GnomeControlCenter *self)
|
|
|
|
{
|
|
|
|
GError *err = NULL;
|
|
|
|
GnomeControlCenterPrivate *priv;
|
2012-05-08 16:56:20 +01:00
|
|
|
GdkScreen *screen;
|
2012-12-06 09:30:44 +01:00
|
|
|
GtkWidget *frame;
|
2013-02-17 00:30:43 -05:00
|
|
|
GtkWidget *box;
|
2010-05-19 11:11:26 +01:00
|
|
|
|
|
|
|
priv = self->priv = CONTROL_CENTER_PRIVATE (self);
|
|
|
|
|
2012-05-08 16:56:20 +01:00
|
|
|
priv->monitor_num = -1;
|
2012-05-21 16:01:28 +01:00
|
|
|
self->priv->small_screen = SMALL_SCREEN_UNSET;
|
2012-05-08 16:56:20 +01:00
|
|
|
|
2010-05-19 11:11:26 +01:00
|
|
|
/* load the user interface */
|
|
|
|
priv->builder = gtk_builder_new ();
|
|
|
|
|
2013-01-04 17:10:52 +01:00
|
|
|
if (!gtk_builder_add_from_resource (priv->builder, "/org/gnome/control-center/shell/shell.ui", &err))
|
2010-05-19 11:11:26 +01:00
|
|
|
{
|
|
|
|
g_critical ("Could not build interface: %s", err->message);
|
|
|
|
g_error_free (err);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-02-17 00:30:43 -05:00
|
|
|
box = W(priv->builder, "vbox1");
|
|
|
|
gtk_widget_reparent (box, GTK_WIDGET (self));
|
|
|
|
|
2010-05-19 11:11:26 +01:00
|
|
|
/* connect various signals */
|
2013-02-17 00:30:43 -05:00
|
|
|
screen = gtk_widget_get_screen (GTK_WIDGET (self));
|
2012-05-08 16:56:20 +01:00
|
|
|
g_signal_connect (screen, "monitors-changed", G_CALLBACK (monitors_changed_cb), self);
|
2013-02-17 00:30:43 -05:00
|
|
|
|
|
|
|
g_signal_connect (self, "configure-event", G_CALLBACK (main_window_configure_cb), self);
|
|
|
|
g_signal_connect (self, "notify::application", G_CALLBACK (application_set_cb), self);
|
|
|
|
g_signal_connect_after (self, "key_press_event",
|
2012-07-16 17:03:36 +01:00
|
|
|
G_CALLBACK (window_key_press_event), self);
|
2013-02-17 00:30:43 -05:00
|
|
|
g_signal_connect (self, "notify::window", G_CALLBACK (gdk_window_set_cb), self);
|
2010-05-19 11:11:26 +01:00
|
|
|
|
|
|
|
priv->notebook = W (priv->builder, "notebook");
|
2012-04-30 19:24:45 +01:00
|
|
|
|
|
|
|
/* Main scrolled window */
|
2010-10-31 17:55:20 -04:00
|
|
|
priv->scrolled_window = W (priv->builder, "scrolledwindow1");
|
2012-04-30 19:24:45 +01:00
|
|
|
|
2012-05-08 18:48:06 +01:00
|
|
|
gtk_widget_set_size_request (priv->scrolled_window, FIXED_WIDTH, -1);
|
2010-10-31 17:55:20 -04:00
|
|
|
priv->main_vbox = W (priv->builder, "main-vbox");
|
2012-08-18 16:03:19 +01:00
|
|
|
g_signal_connect (priv->notebook, "notify::page",
|
2013-02-17 00:30:43 -05:00
|
|
|
G_CALLBACK (notebook_page_notify_cb), self);
|
2010-05-19 11:11:26 +01:00
|
|
|
|
2012-12-06 09:30:44 +01:00
|
|
|
/* Set the alignment for the home button */
|
|
|
|
frame = W(priv->builder, "home-aspect-frame");
|
|
|
|
if (gtk_widget_get_direction (frame) == GTK_TEXT_DIR_RTL)
|
|
|
|
g_object_set (frame, "xalign", 1.0, NULL);
|
|
|
|
|
2010-05-19 11:11:26 +01:00
|
|
|
g_signal_connect (gtk_builder_get_object (priv->builder, "home-button"),
|
|
|
|
"clicked", G_CALLBACK (home_button_clicked_cb), self);
|
|
|
|
|
2012-01-09 15:19:13 +00:00
|
|
|
/* keep a list of custom widgets to unload on panel change */
|
|
|
|
priv->custom_widgets = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref);
|
|
|
|
|
2010-05-19 11:11:26 +01:00
|
|
|
/* load the available settings panels */
|
2011-03-06 05:01:29 -05:00
|
|
|
setup_model (self);
|
2010-05-19 11:11:26 +01:00
|
|
|
|
|
|
|
/* setup search functionality */
|
|
|
|
setup_search (self);
|
|
|
|
|
2011-05-20 21:27:09 -04:00
|
|
|
setup_lock (self);
|
|
|
|
|
2013-02-17 00:30:43 -05:00
|
|
|
notebook_page_notify_cb (GTK_NOTEBOOK (priv->notebook), NULL, self);
|
2010-05-19 11:11:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
GnomeControlCenter *
|
2013-02-17 00:30:43 -05:00
|
|
|
gnome_control_center_new (GtkApplication *application)
|
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);
|
|
|
|
|
|
|
|
return g_object_new (GNOME_TYPE_CONTROL_CENTER,
|
|
|
|
"application", application,
|
|
|
|
"hide-titlebar-when-maximized", TRUE,
|
|
|
|
"resizable", TRUE,
|
|
|
|
"title", DEFAULT_WINDOW_TITLE,
|
|
|
|
"icon-name", DEFAULT_WINDOW_ICON_NAME,
|
|
|
|
"window-position", GTK_WIN_POS_CENTER,
|
|
|
|
NULL);
|
2010-05-19 11:11:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gnome_control_center_present (GnomeControlCenter *center)
|
|
|
|
{
|
2013-02-17 00:30:43 -05:00
|
|
|
gtk_window_present (GTK_WINDOW (center));
|
2010-05-19 11:11:26 +01:00
|
|
|
}
|
2010-10-22 14:08:11 +01:00
|
|
|
|
|
|
|
void
|
2013-02-17 00:30:43 -05:00
|
|
|
gnome_control_center_show (GnomeControlCenter *center)
|
2010-10-22 14:08:11 +01:00
|
|
|
{
|
2013-02-17 00:30:43 -05:00
|
|
|
gtk_widget_show (GTK_WIDGET (center));
|
2010-10-22 14:08:11 +01:00
|
|
|
}
|