Commit 60b23575 authored by Georges Basile Stavracas Neto's avatar Georges Basile Stavracas Neto
Browse files

keyboard: move keyboard management code to custom class

Instead of having CcKeyboardPanel managing both UI and backend code,
factor the backend code to a new CcKeyboardManager class and drop
backend management from the panel itself.

The new backend class handles the loading, creation and removal and
search of keyboard shortcuts. It also resolves reversible shortcuts
when searching.

This patch moves the code to this new class, and updates the rest of
the Keyboard panel to use it instead.

https://bugzilla.gnome.org/show_bug.cgi?id=769063
parent 70bba2bb
......@@ -9,6 +9,8 @@ BUILT_SOURCES = \
libkeyboard_la_SOURCES = \
$(BUILT_SOURCES) \
cc-keyboard-manager.c \
cc-keyboard-manager.h \
cc-keyboard-panel.c \
cc-keyboard-panel.h \
cc-keyboard-item.c \
......
This diff is collapsed.
/*
* Copyright (C) 2010 Intel, Inc
* Copyright (C) 2016 Endless, Inc
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/>.
*
* Author: Thomas Wood <thomas.wood@intel.com>
* Georges Basile Stavracas Neto <georges.stavracas@gmail.com>
*
*/
#ifndef CC_KEYBOARD_MANAGER_H
#define CC_KEYBOARD_MANAGER_H
#include <glib-object.h>
#include "cc-keyboard-item.h"
G_BEGIN_DECLS
#define CC_TYPE_KEYBOARD_MANAGER (cc_keyboard_manager_get_type())
G_DECLARE_FINAL_TYPE (CcKeyboardManager, cc_keyboard_manager, CC, KEYBOARD_MANAGER, GObject)
CcKeyboardManager* cc_keyboard_manager_new (void);
void cc_keyboard_manager_load_shortcuts (CcKeyboardManager *self);
CcKeyboardItem* cc_keyboard_manager_create_custom_shortcut (CcKeyboardManager *self);
void cc_keyboard_manager_add_custom_shortcut (CcKeyboardManager *self,
CcKeyboardItem *item);
void cc_keyboard_manager_remove_custom_shortcut (CcKeyboardManager *self,
CcKeyboardItem *item);
G_END_DECLS
#endif /* CC_KEYBOARD_MANAGER_H */
This diff is collapsed.
......@@ -50,7 +50,7 @@ struct _CcKeyboardShortcutEditor
GdkDevice *grab_device;
CcKeyboardPanel *panel;
CcKeyboardManager *manager;
CcKeyboardItem *item;
/* Custom shortcuts */
......@@ -72,19 +72,11 @@ enum
{
PROP_0,
PROP_KEYBOARD_ITEM,
PROP_PANEL,
PROP_MANAGER,
N_PROPS
};
enum
{
ADD_CUSTOM_SHORTCUT,
REMOVE_CUSTOM_SHORTCUT,
LAST_SIGNAL
};
static GParamSpec *properties [N_PROPS] = { NULL, };
static guint signals[LAST_SIGNAL] = { 0, };
static void
apply_custom_item_fields (CcKeyboardShortcutEditor *self,
......@@ -271,7 +263,7 @@ add_button_clicked_cb (CcKeyboardShortcutEditor *self)
{
CcKeyboardItem *item;
item = cc_keyboard_panel_create_custom_item (self->panel);
item = cc_keyboard_manager_create_custom_shortcut (self->manager);
/* Apply the custom shortcut setup at the new item */
apply_custom_item_fields (self, item);
......@@ -279,7 +271,7 @@ add_button_clicked_cb (CcKeyboardShortcutEditor *self)
/* Cleanup everything once we're done */
clear_custom_entries (self);
g_signal_emit (self, signals[ADD_CUSTOM_SHORTCUT], 0, item);
cc_keyboard_manager_add_custom_shortcut (self->manager, item);
gtk_widget_hide (GTK_WIDGET (self));
}
......@@ -322,7 +314,7 @@ remove_button_clicked_cb (CcKeyboardShortcutEditor *self)
{
gtk_widget_hide (GTK_WIDGET (self));
g_signal_emit (self, signals[REMOVE_CUSTOM_SHORTCUT], 0, self->item);
cc_keyboard_manager_remove_custom_shortcut (self->manager, self->item);
}
static void
......@@ -389,6 +381,7 @@ cc_keyboard_shortcut_editor_finalize (GObject *object)
CcKeyboardShortcutEditor *self = (CcKeyboardShortcutEditor *)object;
g_clear_object (&self->item);
g_clear_object (&self->manager);
G_OBJECT_CLASS (cc_keyboard_shortcut_editor_parent_class)->finalize (object);
}
......@@ -407,8 +400,8 @@ cc_keyboard_shortcut_editor_get_property (GObject *object,
g_value_set_object (value, self->item);
break;
case PROP_PANEL:
g_value_set_pointer (value, self->panel);
case PROP_MANAGER:
g_value_set_object (value, self->manager);
break;
default:
......@@ -430,8 +423,8 @@ cc_keyboard_shortcut_editor_set_property (GObject *object,
cc_keyboard_shortcut_editor_set_item (self, g_value_get_object (value));
break;
case PROP_PANEL:
self->panel = g_value_get_pointer (value);
case PROP_MANAGER:
g_set_object (&self->manager, g_value_get_object (value));
break;
default:
......@@ -562,36 +555,11 @@ cc_keyboard_shortcut_editor_class_init (CcKeyboardShortcutEditorClass *klass)
*
* The current keyboard panel.
*/
properties[PROP_PANEL] = g_param_spec_pointer ("panel",
"Keyboard panel",
"The keyboard panel being edited",
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
/**
* CcKeyboardShortcutEditor:add-custom-shortcut:
*
* Emited when the user asks to add a custom shortcut.
*/
signals[ADD_CUSTOM_SHORTCUT] = g_signal_new ("add-custom-shortcut",
CC_TYPE_KEYBOARD_SHORTCUT_EDITOR,
G_SIGNAL_RUN_FIRST,
0, NULL, NULL, NULL,
G_TYPE_NONE,
1,
CC_TYPE_KEYBOARD_ITEM);
/**
* CcKeyboardShortcutEditor:remove-custom-shortcut:
*
* Emited when the user asks to remove a custom shortcut.
*/
signals[REMOVE_CUSTOM_SHORTCUT] = g_signal_new ("remove-custom-shortcut",
CC_TYPE_KEYBOARD_SHORTCUT_EDITOR,
G_SIGNAL_RUN_FIRST,
0, NULL, NULL, NULL,
G_TYPE_NONE,
1,
CC_TYPE_KEYBOARD_ITEM);
properties[PROP_MANAGER] = g_param_spec_object ("manager",
"Keyboard manager",
"The keyboard manager",
CC_TYPE_KEYBOARD_MANAGER,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
g_object_class_install_properties (object_class, N_PROPS, properties);
......@@ -635,10 +603,10 @@ cc_keyboard_shortcut_editor_init (CcKeyboardShortcutEditor *self)
* Returns: (transfer full): a newly created #CcKeyboardShortcutEditor.
*/
GtkWidget*
cc_keyboard_shortcut_editor_new (CcKeyboardPanel *panel)
cc_keyboard_shortcut_editor_new (CcKeyboardManager *manager)
{
return g_object_new (CC_TYPE_KEYBOARD_SHORTCUT_EDITOR,
"panel", panel,
"manager", manager,
"use-header-bar", 1,
NULL);
}
......
......@@ -24,7 +24,7 @@
#include <gtk/gtk.h>
#include "cc-keyboard-item.h"
#include "cc-keyboard-panel.h"
#include "cc-keyboard-manager.h"
G_BEGIN_DECLS
......@@ -38,7 +38,7 @@ typedef enum
G_DECLARE_FINAL_TYPE (CcKeyboardShortcutEditor, cc_keyboard_shortcut_editor, CC, KEYBOARD_SHORTCUT_EDITOR, GtkDialog)
GtkWidget* cc_keyboard_shortcut_editor_new (CcKeyboardPanel *panel);
GtkWidget* cc_keyboard_shortcut_editor_new (CcKeyboardManager *manager);
CcKeyboardItem* cc_keyboard_shortcut_editor_get_item (CcKeyboardShortcutEditor *self);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment