Commit 8ab4fb79 authored by Daiki Ueno's avatar Daiki Ueno
Browse files

Implement preferences dialog.

parent e91a059f
......@@ -26,7 +26,8 @@ eekboard_CFLAGS = \
$(GTK_CFLAGS) \
$(XKB_CFLAGS) \
$(LIBXKLAVIER_CFLAGS) \
-DKEYBOARDDIR=\"$(pkgdatadir)/keyboards\"
-DKEYBOARDDIR=\"$(pkgdatadir)/keyboards\" \
-DPKGDATADIR=\"$(pkgdatadir)\"
eekboard_LDADD = \
$(top_builddir)/eekboard/libeekboard.la \
......@@ -58,8 +59,8 @@ eekboard_LDADD += \
$(IBUS_LIBS)
endif
eekboard_headers = client.h
eekboard_SOURCES = client.c client-main.c
eekboard_headers = client.h preferences-dialog.h
eekboard_SOURCES = client.c preferences-dialog.c client-main.c
eekboard_server_CFLAGS = \
-I$(top_srcdir) \
......@@ -98,3 +99,5 @@ eekboard_HEADERS = \
noinst_HEADERS = \
$(eekboard_headers) \
$(eekboard_server_headers)
dist_pkgdata_DATA = preferences-dialog.ui
\ No newline at end of file
......@@ -42,6 +42,7 @@
#include "eekboard/eekboard-client.h"
#include "eekboard/eekboard-xklutil.h"
#include "client.h"
#include "preferences-dialog.h"
#include <string.h>
......@@ -715,6 +716,9 @@ set_keyboard (Client *client,
GSList *keyboards = NULL;
gchar **strv, **p;
g_return_val_if_fail (keyboard != NULL, FALSE);
g_return_val_if_fail (*keyboard != '\0', FALSE);
if (client->keyboards)
g_slist_free (client->keyboards);
......@@ -962,8 +966,15 @@ on_key_pressed (EekboardContext *context,
eekboard_context_set_keyboard (client->context,
GPOINTER_TO_UINT(client->keyboards->data),
NULL);
return;
}
if (g_strcmp0 (eek_symbol_get_name (symbol), "preferences") == 0) {
PreferencesDialog *dialog = preferences_dialog_new ();
preferences_dialog_run (dialog);
}
send_fake_key_event (client, symbol, modifiers, TRUE);
send_fake_key_event (client, symbol, modifiers, FALSE);
}
......
/*
* Copyright (C) 2011 Daiki Ueno <ueno@unixuser.org>
* Copyright (C) 2011 Red Hat, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif /* HAVE_CONFIG_H */
#include <gtk/gtk.h>
#include "preferences-dialog.h"
struct _PreferencesDialog {
GtkWidget *dialog;
GtkWidget *repeat_toggle;
GtkWidget *repeat_delay_scale;
GtkWidget *repeat_speed_scale;
GtkWidget *auto_hide_toggle;
GtkWidget *auto_hide_delay_scale;
GtkWidget *start_fullscreen_toggle;
GtkWidget *keyboard_entry;
GSettings *settings;
};
static gboolean
get_rate (GValue *value,
GVariant *variant,
gpointer user_data)
{
int rate;
gdouble fraction;
rate = g_variant_get_uint32 (variant);
fraction = 1.0 / ((gdouble) rate / 1000.0);
g_value_set_double (value, fraction);
g_debug ("Getting fraction %f for msecs %d", fraction, rate);
return TRUE;
}
static GVariant *
set_rate (const GValue *value,
const GVariantType *expected_type,
gpointer user_data)
{
gdouble rate;
int msecs;
rate = g_value_get_double (value);
msecs = (1 / rate) * 1000;
g_debug ("Setting repeat rate to %d", msecs);
return g_variant_new_uint32 (msecs);
}
PreferencesDialog *
preferences_dialog_new (void)
{
PreferencesDialog *dialog;
gchar *ui_path;
GtkBuilder *builder;
GObject *object;
GError *error;
dialog = g_slice_new0 (PreferencesDialog);
dialog->settings = g_settings_new ("org.fedorahosted.eekboard");
builder = gtk_builder_new ();
gtk_builder_set_translation_domain (builder, "eekboard");
ui_path = g_strdup_printf ("%s/%s", PKGDATADIR, "preferences-dialog.ui");
error = NULL;
gtk_builder_add_from_file (builder, ui_path, &error);
g_free (ui_path);
object =
gtk_builder_get_object (builder, "dialog");
dialog->dialog = GTK_WIDGET(object);
object =
gtk_builder_get_object (builder, "repeat_toggle");
dialog->repeat_toggle = GTK_WIDGET(object);
g_settings_bind (dialog->settings, "repeat",
dialog->repeat_toggle, "active",
G_SETTINGS_BIND_DEFAULT);
object =
gtk_builder_get_object (builder, "repeat_delay_scale");
dialog->repeat_delay_scale = GTK_WIDGET(object);
g_settings_bind (dialog->settings, "repeat-delay",
gtk_range_get_adjustment (GTK_RANGE (dialog->repeat_delay_scale)), "value",
G_SETTINGS_BIND_DEFAULT);
object =
gtk_builder_get_object (builder, "repeat_speed_scale");
dialog->repeat_speed_scale = GTK_WIDGET(object);
g_settings_bind_with_mapping (dialog->settings, "repeat-interval",
gtk_range_get_adjustment (GTK_RANGE (gtk_builder_get_object (builder, "repeat_speed_scale"))), "value",
G_SETTINGS_BIND_DEFAULT,
get_rate, set_rate, NULL, NULL);
object =
gtk_builder_get_object (builder, "auto_hide_toggle");
dialog->auto_hide_toggle = GTK_WIDGET(object);
g_settings_bind (dialog->settings, "auto-hide",
dialog->auto_hide_toggle, "active",
G_SETTINGS_BIND_DEFAULT);
object =
gtk_builder_get_object (builder, "auto_hide_delay_scale");
dialog->auto_hide_delay_scale = GTK_WIDGET(object);
g_settings_bind (dialog->settings, "auto-hide-delay",
gtk_range_get_adjustment (GTK_RANGE (dialog->auto_hide_delay_scale)), "value",
G_SETTINGS_BIND_DEFAULT);
object =
gtk_builder_get_object (builder, "start_fullscreen_toggle");
dialog->start_fullscreen_toggle = GTK_WIDGET(object);
g_settings_bind (dialog->settings, "start-fullscreen",
dialog->start_fullscreen_toggle, "active",
G_SETTINGS_BIND_DEFAULT);
object =
gtk_builder_get_object (builder, "keyboard_entry");
dialog->keyboard_entry = GTK_WIDGET(object);
g_settings_bind (dialog->settings, "keyboard",
GTK_ENTRY(dialog->keyboard_entry), "text",
G_SETTINGS_BIND_DEFAULT);
return dialog;
}
void
preferences_dialog_run (PreferencesDialog *dialog)
{
gtk_dialog_run (GTK_DIALOG(dialog->dialog));
gtk_widget_destroy (dialog->dialog);
}
/*
* Copyright (C) 2011 Daiki Ueno <ueno@unixuser.org>
* Copyright (C) 2011 Red Hat, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef PREFERENCES_DIALOG_H
#define PREFERENCES_DIALOG_H 1
G_BEGIN_DECLS
typedef struct _PreferencesDialog PreferencesDialog;
PreferencesDialog *preferences_dialog_new (void);
void preferences_dialog_run (PreferencesDialog *dialog);
G_END_DECLS
#endif /* PREFERENCES_DIALOG_H */
This diff is collapsed.
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