2005-07-23 21:58:57 -07:00
|
|
|
/*
|
|
|
|
* mooterm/mooterm-prefs.c
|
|
|
|
*
|
2006-02-23 06:03:17 -08:00
|
|
|
* Copyright (C) 2004-2006 by Yevgen Muntyan <muntyan@math.tamu.edu>
|
2005-07-23 21:58:57 -07:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* See COPYING file that comes with this distribution.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define MOOTERM_COMPILATION
|
|
|
|
|
|
|
|
#ifdef __WIN32__
|
|
|
|
#define WIN32_LEAN_AND_MEAN
|
|
|
|
#include <windows.h>
|
2005-07-28 12:25:10 -07:00
|
|
|
#endif
|
2005-07-23 21:58:57 -07:00
|
|
|
|
|
|
|
#include "mooterm/mooterm-private.h"
|
|
|
|
#include "mooterm/mooterm-prefs.h"
|
2005-09-11 06:44:14 -07:00
|
|
|
#include "mooterm/mootermprefs-glade.h"
|
2005-07-23 21:58:57 -07:00
|
|
|
#include "mooterm/mooterm.h"
|
|
|
|
#include "mooutils/mooprefs.h"
|
|
|
|
#include "mooutils/mooprefsdialog.h"
|
|
|
|
#include "mooutils/moostock.h"
|
2006-06-14 12:04:34 -07:00
|
|
|
#include "mooutils/moofontsel.h"
|
2005-09-11 06:44:14 -07:00
|
|
|
#include "mooutils/mooglade.h"
|
2006-08-03 00:29:39 -07:00
|
|
|
#include "mooutils/mooi18n.h"
|
2005-07-23 21:58:57 -07:00
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
|
2005-10-13 07:08:18 -07:00
|
|
|
#define NEW_KEY_BOOL(s__,v__) moo_prefs_new_key_bool (MOO_TERM_PREFS_PREFIX "/" s__, v__)
|
|
|
|
#define NEW_KEY_INT(s__,v__) moo_prefs_new_key_int (MOO_TERM_PREFS_PREFIX "/" s__, v__)
|
|
|
|
#define NEW_KEY_STRING(s__,v__) moo_prefs_new_key_string (MOO_TERM_PREFS_PREFIX "/" s__, v__)
|
|
|
|
#define NEW_KEY_COLOR(s__,v__) moo_prefs_new_key_color (MOO_TERM_PREFS_PREFIX "/" s__, v__)
|
2005-07-23 21:58:57 -07:00
|
|
|
|
2005-10-13 07:08:18 -07:00
|
|
|
#define GET_STRING(s__) moo_prefs_get_string (MOO_TERM_PREFS_PREFIX "/" s__)
|
|
|
|
#define GET_INT(s__) moo_prefs_get_int (MOO_TERM_PREFS_PREFIX "/" s__)
|
|
|
|
#define GET_BOOL(s__) moo_prefs_get_bool (MOO_TERM_PREFS_PREFIX "/" s__)
|
|
|
|
#define GET_COLOR(s__) moo_prefs_get_color (MOO_TERM_PREFS_PREFIX "/" s__)
|
2005-07-23 21:58:57 -07:00
|
|
|
|
|
|
|
|
|
|
|
#ifdef __WIN32__
|
2005-09-14 00:06:17 -07:00
|
|
|
#define DEFAULT_BLINK_TIME ((int)GetCaretBlinkTime())
|
2005-07-23 21:58:57 -07:00
|
|
|
#else /* ! __WIN32__ */
|
2005-09-14 00:06:17 -07:00
|
|
|
#define DEFAULT_BLINK_TIME ((int)530)
|
2005-07-23 21:58:57 -07:00
|
|
|
#endif /* ! __WIN32__ */
|
|
|
|
|
|
|
|
|
2006-04-08 19:09:02 -07:00
|
|
|
void
|
|
|
|
_moo_term_init_settings (void)
|
2005-07-23 21:58:57 -07:00
|
|
|
{
|
|
|
|
GtkSettings *settings;
|
|
|
|
GtkStyle *style;
|
|
|
|
|
2005-07-28 12:25:10 -07:00
|
|
|
NEW_KEY_STRING (MOO_TERM_PREFS_FONT, DEFAULT_MONOSPACE_FONT);
|
|
|
|
NEW_KEY_BOOL (MOO_TERM_PREFS_CURSOR_BLINKS, FALSE);
|
|
|
|
NEW_KEY_INT (MOO_TERM_PREFS_CURSOR_BLINK_TIME, DEFAULT_BLINK_TIME);
|
2005-07-23 21:58:57 -07:00
|
|
|
|
|
|
|
settings = gtk_settings_get_default ();
|
|
|
|
style = gtk_rc_get_style_by_paths (settings, "MooTerm", "MooTerm", MOO_TYPE_TERM);
|
|
|
|
|
|
|
|
if (!style)
|
|
|
|
style = gtk_style_new ();
|
|
|
|
else
|
|
|
|
g_object_ref (G_OBJECT (style));
|
|
|
|
|
|
|
|
g_return_if_fail (style != NULL);
|
|
|
|
|
2005-07-28 12:25:10 -07:00
|
|
|
NEW_KEY_COLOR (MOO_TERM_PREFS_FOREGROUND, &(style->text[GTK_STATE_NORMAL]));
|
|
|
|
NEW_KEY_COLOR (MOO_TERM_PREFS_BACKGROUND, &(style->base[GTK_STATE_NORMAL]));
|
2005-07-23 21:58:57 -07:00
|
|
|
|
|
|
|
g_object_unref (G_OBJECT (style));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-10-13 07:08:18 -07:00
|
|
|
void
|
|
|
|
_moo_term_apply_settings (MooTerm *term)
|
2005-07-23 21:58:57 -07:00
|
|
|
{
|
2005-07-28 12:25:10 -07:00
|
|
|
moo_term_set_font_from_string (term, GET_STRING (MOO_TERM_PREFS_FONT));
|
2005-07-23 21:58:57 -07:00
|
|
|
|
2006-04-08 19:09:02 -07:00
|
|
|
gtk_widget_modify_text (GTK_WIDGET (term), GTK_STATE_NORMAL,
|
|
|
|
GET_COLOR (MOO_TERM_PREFS_FOREGROUND));
|
|
|
|
gtk_widget_modify_base (GTK_WIDGET (term), GTK_STATE_NORMAL,
|
|
|
|
GET_COLOR (MOO_TERM_PREFS_BACKGROUND));
|
|
|
|
|
2005-07-23 21:58:57 -07:00
|
|
|
if (GET_BOOL (MOO_TERM_PREFS_CURSOR_BLINKS))
|
|
|
|
{
|
|
|
|
int t = GET_INT (MOO_TERM_PREFS_CURSOR_BLINK_TIME);
|
|
|
|
if (t <= 0)
|
|
|
|
{
|
2005-07-28 12:25:10 -07:00
|
|
|
moo_prefs_set_bool (moo_term_setting (MOO_TERM_PREFS_CURSOR_BLINKS),
|
|
|
|
FALSE);
|
|
|
|
moo_prefs_set_int (moo_term_setting (MOO_TERM_PREFS_CURSOR_BLINK_TIME),
|
|
|
|
DEFAULT_BLINK_TIME);
|
2005-07-23 21:58:57 -07:00
|
|
|
moo_term_set_cursor_blink_time (term, 0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
moo_term_set_cursor_blink_time (term, (guint)t);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
moo_term_set_cursor_blink_time (term, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
GtkWidget *moo_term_prefs_page_new (void)
|
|
|
|
{
|
2006-08-16 18:24:45 -07:00
|
|
|
MooPrefsDialogPage *page;
|
2006-06-14 12:04:34 -07:00
|
|
|
MooGladeXML *xml;
|
2005-07-23 21:58:57 -07:00
|
|
|
|
2006-04-16 03:10:49 -07:00
|
|
|
_moo_term_init_settings ();
|
|
|
|
|
2006-08-03 00:29:39 -07:00
|
|
|
xml = moo_glade_xml_new_empty (GETTEXT_PACKAGE);
|
2006-06-14 12:04:34 -07:00
|
|
|
moo_glade_xml_map_id (xml, "font", MOO_TYPE_FONT_BUTTON);
|
|
|
|
moo_glade_xml_set_property (xml, "font", "monospace", "True");
|
2006-06-14 12:29:30 -07:00
|
|
|
moo_glade_xml_set_property (xml, "font", "filter-visible", "False");
|
2005-07-23 21:58:57 -07:00
|
|
|
|
2006-06-14 12:04:34 -07:00
|
|
|
page = moo_prefs_dialog_page_new_from_xml ("Terminal", MOO_STOCK_TERMINAL,
|
|
|
|
xml, MOO_TERM_PREFS_GLADE_UI,
|
2006-08-17 21:48:50 -07:00
|
|
|
"page", MOO_TERM_PREFS_PREFIX);
|
2006-06-14 12:04:34 -07:00
|
|
|
|
|
|
|
g_object_unref (xml);
|
2006-08-16 18:24:45 -07:00
|
|
|
return GTK_WIDGET (page);
|
2005-07-23 21:58:57 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-07-28 12:25:10 -07:00
|
|
|
#define STR_STACK_SIZE 4
|
|
|
|
|
2005-07-23 21:58:57 -07:00
|
|
|
const char *moo_term_setting (const char *setting_name)
|
|
|
|
{
|
2005-07-28 12:25:10 -07:00
|
|
|
static GString *stack[STR_STACK_SIZE];
|
|
|
|
static guint p;
|
2005-07-23 21:58:57 -07:00
|
|
|
|
|
|
|
g_return_val_if_fail (setting_name != NULL, NULL);
|
|
|
|
|
2005-07-28 12:25:10 -07:00
|
|
|
if (!stack[0])
|
|
|
|
{
|
|
|
|
for (p = 0; p < STR_STACK_SIZE; ++p)
|
|
|
|
stack[p] = g_string_new ("");
|
|
|
|
p = STR_STACK_SIZE - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (p == STR_STACK_SIZE - 1)
|
|
|
|
p = 0;
|
|
|
|
else
|
|
|
|
p++;
|
|
|
|
|
2005-09-11 06:44:14 -07:00
|
|
|
g_string_printf (stack[p], MOO_TERM_PREFS_PREFIX "/%s", setting_name);
|
2005-07-28 12:25:10 -07:00
|
|
|
return stack[p]->str;
|
2005-07-23 21:58:57 -07:00
|
|
|
}
|