xed/pluma/pluma-prefs-manager.c

942 lines
20 KiB
C
Raw Normal View History

2011-11-07 13:46:58 -06:00
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
2011-11-07 16:52:18 -06:00
* pluma-prefs-manager.c
* This file is part of pluma
2011-11-07 13:46:58 -06:00
*
* Copyright (C) 2002 Paolo Maggi
*
* 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, write to the Free Software
2012-11-18 19:54:49 -06:00
* Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
2011-11-07 13:46:58 -06:00
*/
/*
2011-11-07 16:52:18 -06:00
* Modified by the pluma Team, 2002. See the AUTHORS file for a
* list of people on the pluma Team.
2011-11-07 13:46:58 -06:00
* See the ChangeLog files for a list of changes.
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <string.h>
#include <glib/gi18n.h>
2013-01-24 14:03:53 -06:00
#include <gio/gio.h>
2011-11-07 13:46:58 -06:00
2011-11-07 16:52:18 -06:00
#include "pluma-prefs-manager.h"
#include "pluma-prefs-manager-private.h"
#include "pluma-debug.h"
#include "pluma-encodings.h"
#include "pluma-utils.h"
2011-11-07 13:46:58 -06:00
2013-01-24 14:03:53 -06:00
#define DEFINE_BOOL_PREF(name, key) gboolean \
2011-11-07 16:52:18 -06:00
pluma_prefs_manager_get_ ## name (void) \
2011-11-07 13:46:58 -06:00
{ \
2011-11-07 16:52:18 -06:00
pluma_debug (DEBUG_PREFS); \
2011-11-07 13:46:58 -06:00
\
2013-01-24 14:03:53 -06:00
return pluma_prefs_manager_get_bool (key); \
2011-11-07 13:46:58 -06:00
} \
\
void \
2011-11-07 16:52:18 -06:00
pluma_prefs_manager_set_ ## name (gboolean v) \
2011-11-07 13:46:58 -06:00
{ \
2011-11-07 16:52:18 -06:00
pluma_debug (DEBUG_PREFS); \
2011-11-07 13:46:58 -06:00
\
2011-11-07 16:52:18 -06:00
pluma_prefs_manager_set_bool (key, \
2011-11-07 13:46:58 -06:00
v); \
} \
\
gboolean \
2011-11-07 16:52:18 -06:00
pluma_prefs_manager_ ## name ## _can_set (void) \
2011-11-07 13:46:58 -06:00
{ \
2011-11-07 16:52:18 -06:00
pluma_debug (DEBUG_PREFS); \
2011-11-07 13:46:58 -06:00
\
2011-11-07 16:52:18 -06:00
return pluma_prefs_manager_key_is_writable (key); \
2011-11-07 13:46:58 -06:00
}
2013-01-24 14:03:53 -06:00
#define DEFINE_INT_PREF(name, key) gint \
2011-11-07 16:52:18 -06:00
pluma_prefs_manager_get_ ## name (void) \
2011-11-07 13:46:58 -06:00
{ \
2011-11-07 16:52:18 -06:00
pluma_debug (DEBUG_PREFS); \
2011-11-07 13:46:58 -06:00
\
2013-01-24 14:03:53 -06:00
return pluma_prefs_manager_get_int (key); \
2011-11-07 13:46:58 -06:00
} \
\
void \
2011-11-07 16:52:18 -06:00
pluma_prefs_manager_set_ ## name (gint v) \
2011-11-07 13:46:58 -06:00
{ \
2011-11-07 16:52:18 -06:00
pluma_debug (DEBUG_PREFS); \
2011-11-07 13:46:58 -06:00
\
2011-11-07 16:52:18 -06:00
pluma_prefs_manager_set_int (key, \
2011-11-07 13:46:58 -06:00
v); \
} \
\
gboolean \
2011-11-07 16:52:18 -06:00
pluma_prefs_manager_ ## name ## _can_set (void) \
2011-11-07 13:46:58 -06:00
{ \
2011-11-07 16:52:18 -06:00
pluma_debug (DEBUG_PREFS); \
2011-11-07 13:46:58 -06:00
\
2011-11-07 16:52:18 -06:00
return pluma_prefs_manager_key_is_writable (key); \
2011-11-07 13:46:58 -06:00
}
2013-01-24 14:03:53 -06:00
#define DEFINE_STRING_PREF(name, key) gchar* \
2011-11-07 16:52:18 -06:00
pluma_prefs_manager_get_ ## name (void) \
2011-11-07 13:46:58 -06:00
{ \
2011-11-07 16:52:18 -06:00
pluma_debug (DEBUG_PREFS); \
2011-11-07 13:46:58 -06:00
\
2013-01-24 14:03:53 -06:00
return pluma_prefs_manager_get_string (key); \
2011-11-07 13:46:58 -06:00
} \
\
void \
2011-11-07 16:52:18 -06:00
pluma_prefs_manager_set_ ## name (const gchar* v) \
2011-11-07 13:46:58 -06:00
{ \
2011-11-07 16:52:18 -06:00
pluma_debug (DEBUG_PREFS); \
2011-11-07 13:46:58 -06:00
\
2011-11-07 16:52:18 -06:00
pluma_prefs_manager_set_string (key, \
2011-11-07 13:46:58 -06:00
v); \
} \
\
gboolean \
2011-11-07 16:52:18 -06:00
pluma_prefs_manager_ ## name ## _can_set (void) \
2011-11-07 13:46:58 -06:00
{ \
2011-11-07 16:52:18 -06:00
pluma_debug (DEBUG_PREFS); \
2011-11-07 13:46:58 -06:00
\
2011-11-07 16:52:18 -06:00
return pluma_prefs_manager_key_is_writable (key); \
2011-11-07 13:46:58 -06:00
}
2011-11-07 16:52:18 -06:00
PlumaPrefsManager *pluma_prefs_manager = NULL;
2011-11-07 13:46:58 -06:00
static GtkWrapMode get_wrap_mode_from_string (const gchar* str);
2013-01-24 14:03:53 -06:00
static gboolean pluma_prefs_manager_get_bool (const gchar* key);
2011-11-07 13:46:58 -06:00
2013-01-24 14:03:53 -06:00
static gint pluma_prefs_manager_get_int (const gchar* key);
2011-11-07 13:46:58 -06:00
2013-01-24 14:03:53 -06:00
static gchar *pluma_prefs_manager_get_string (const gchar* key);
2011-11-07 13:46:58 -06:00
gboolean
2011-11-07 16:52:18 -06:00
pluma_prefs_manager_init (void)
2011-11-07 13:46:58 -06:00
{
2011-11-07 16:52:18 -06:00
pluma_debug (DEBUG_PREFS);
2011-11-07 13:46:58 -06:00
2011-11-07 16:52:18 -06:00
if (pluma_prefs_manager == NULL)
2011-11-07 13:46:58 -06:00
{
2011-11-07 16:52:18 -06:00
pluma_prefs_manager = g_new0 (PlumaPrefsManager, 1);
2013-01-24 14:03:53 -06:00
pluma_prefs_manager->settings = g_settings_new (PLUMA_SCHEMA);
pluma_prefs_manager->lockdown_settings = g_settings_new (GPM_LOCKDOWN_SCHEMA);
pluma_prefs_manager->interface_settings = g_settings_new (GPM_INTERFACE_SCHEMA);
2011-11-07 13:46:58 -06:00
}
2011-11-07 16:52:18 -06:00
return pluma_prefs_manager != NULL;
2011-11-07 13:46:58 -06:00
}
void
2011-11-07 16:52:18 -06:00
pluma_prefs_manager_shutdown (void)
2011-11-07 13:46:58 -06:00
{
2011-11-07 16:52:18 -06:00
pluma_debug (DEBUG_PREFS);
2011-11-07 13:46:58 -06:00
2011-11-07 16:52:18 -06:00
g_return_if_fail (pluma_prefs_manager != NULL);
2011-11-07 13:46:58 -06:00
2013-01-24 14:03:53 -06:00
g_object_unref (pluma_prefs_manager->settings);
pluma_prefs_manager->settings = NULL;
g_object_unref (pluma_prefs_manager->lockdown_settings);
pluma_prefs_manager->lockdown_settings = NULL;
g_object_unref (pluma_prefs_manager->interface_settings);
pluma_prefs_manager->interface_settings = NULL;
2011-11-07 13:46:58 -06:00
}
static gboolean
2013-01-24 14:03:53 -06:00
pluma_prefs_manager_get_bool (const gchar* key)
2011-11-07 13:46:58 -06:00
{
2011-11-07 16:52:18 -06:00
pluma_debug (DEBUG_PREFS);
2011-11-07 13:46:58 -06:00
2013-01-24 14:03:53 -06:00
return g_settings_get_boolean (pluma_prefs_manager->settings, key);
2011-11-07 13:46:58 -06:00
}
static gint
2013-01-24 14:03:53 -06:00
pluma_prefs_manager_get_int (const gchar* key)
2011-11-07 13:46:58 -06:00
{
2011-11-07 16:52:18 -06:00
pluma_debug (DEBUG_PREFS);
2011-11-07 13:46:58 -06:00
2013-01-24 14:03:53 -06:00
return g_settings_get_int (pluma_prefs_manager->settings, key);
}
2011-11-07 13:46:58 -06:00
static gchar *
2013-01-24 14:03:53 -06:00
pluma_prefs_manager_get_string (const gchar* key)
2011-11-07 13:46:58 -06:00
{
2011-11-07 16:52:18 -06:00
pluma_debug (DEBUG_PREFS);
2011-11-07 13:46:58 -06:00
2013-01-24 14:03:53 -06:00
return g_settings_get_string (pluma_prefs_manager->settings, key);
}
2011-11-07 13:46:58 -06:00
static void
2011-11-07 16:52:18 -06:00
pluma_prefs_manager_set_bool (const gchar* key, gboolean value)
2011-11-07 13:46:58 -06:00
{
2011-11-07 16:52:18 -06:00
pluma_debug (DEBUG_PREFS);
2011-11-07 13:46:58 -06:00
2013-01-24 14:03:53 -06:00
g_return_if_fail (g_settings_is_writable (
pluma_prefs_manager->settings, key));
g_settings_set_boolean (pluma_prefs_manager->settings, key, value);
2011-11-07 13:46:58 -06:00
}
static void
2011-11-07 16:52:18 -06:00
pluma_prefs_manager_set_int (const gchar* key, gint value)
2011-11-07 13:46:58 -06:00
{
2011-11-07 16:52:18 -06:00
pluma_debug (DEBUG_PREFS);
2011-11-07 13:46:58 -06:00
2013-01-24 14:03:53 -06:00
g_return_if_fail (g_settings_is_writable (
pluma_prefs_manager->settings, key));
g_settings_set_int (pluma_prefs_manager->settings, key, value);
2011-11-07 13:46:58 -06:00
}
static void
2011-11-07 16:52:18 -06:00
pluma_prefs_manager_set_string (const gchar* key, const gchar* value)
2011-11-07 13:46:58 -06:00
{
2011-11-07 16:52:18 -06:00
pluma_debug (DEBUG_PREFS);
2011-11-07 13:46:58 -06:00
g_return_if_fail (value != NULL);
2013-01-24 14:03:53 -06:00
g_return_if_fail (g_settings_is_writable (
pluma_prefs_manager->settings, key));
g_settings_set_string (pluma_prefs_manager->settings, key, value);
2011-11-07 13:46:58 -06:00
}
static gboolean
2011-11-07 16:52:18 -06:00
pluma_prefs_manager_key_is_writable (const gchar* key)
2011-11-07 13:46:58 -06:00
{
2011-11-07 16:52:18 -06:00
pluma_debug (DEBUG_PREFS);
2011-11-07 13:46:58 -06:00
2011-11-07 16:52:18 -06:00
g_return_val_if_fail (pluma_prefs_manager != NULL, FALSE);
2013-01-24 14:03:53 -06:00
g_return_val_if_fail (pluma_prefs_manager->settings != NULL, FALSE);
2011-11-07 13:46:58 -06:00
2013-01-24 14:03:53 -06:00
return g_settings_is_writable (pluma_prefs_manager->settings, key);
2011-11-07 13:46:58 -06:00
}
/* Use default font */
DEFINE_BOOL_PREF (use_default_font,
2013-01-24 14:03:53 -06:00
GPM_USE_DEFAULT_FONT)
2011-11-07 13:46:58 -06:00
/* Editor font */
DEFINE_STRING_PREF (editor_font,
2013-01-24 14:03:53 -06:00
GPM_EDITOR_FONT)
2011-11-07 13:46:58 -06:00
/* System font */
gchar *
2011-11-07 16:52:18 -06:00
pluma_prefs_manager_get_system_font (void)
2011-11-07 13:46:58 -06:00
{
2011-11-07 16:52:18 -06:00
pluma_debug (DEBUG_PREFS);
2011-11-07 13:46:58 -06:00
2013-01-24 14:03:53 -06:00
return g_settings_get_string (pluma_prefs_manager->interface_settings,
GPM_SYSTEM_FONT);
2011-11-07 13:46:58 -06:00
}
/* Create backup copy */
DEFINE_BOOL_PREF (create_backup_copy,
2013-01-24 14:03:53 -06:00
GPM_CREATE_BACKUP_COPY)
2011-11-07 13:46:58 -06:00
/* Auto save */
DEFINE_BOOL_PREF (auto_save,
2013-01-24 14:03:53 -06:00
GPM_AUTO_SAVE)
2011-11-07 13:46:58 -06:00
/* Auto save interval */
DEFINE_INT_PREF (auto_save_interval,
2013-01-24 14:03:53 -06:00
GPM_AUTO_SAVE_INTERVAL)
2011-11-07 13:46:58 -06:00
/* Undo actions limit: if < 1 then no limits */
DEFINE_INT_PREF (undo_actions_limit,
2013-01-24 14:03:53 -06:00
GPM_UNDO_ACTIONS_LIMIT)
2011-11-07 13:46:58 -06:00
static GtkWrapMode
get_wrap_mode_from_string (const gchar* str)
{
GtkWrapMode res;
g_return_val_if_fail (str != NULL, GTK_WRAP_WORD);
if (strcmp (str, "GTK_WRAP_NONE") == 0)
res = GTK_WRAP_NONE;
else
{
if (strcmp (str, "GTK_WRAP_CHAR") == 0)
res = GTK_WRAP_CHAR;
else
res = GTK_WRAP_WORD;
}
return res;
}
/* Wrap mode */
GtkWrapMode
2011-11-07 16:52:18 -06:00
pluma_prefs_manager_get_wrap_mode (void)
2011-11-07 13:46:58 -06:00
{
gchar *str;
GtkWrapMode res;
2011-11-07 16:52:18 -06:00
pluma_debug (DEBUG_PREFS);
2011-11-07 13:46:58 -06:00
2013-01-24 14:03:53 -06:00
str = pluma_prefs_manager_get_string (GPM_WRAP_MODE);
2011-11-07 13:46:58 -06:00
res = get_wrap_mode_from_string (str);
g_free (str);
return res;
}
void
2011-11-07 16:52:18 -06:00
pluma_prefs_manager_set_wrap_mode (GtkWrapMode wp)
2011-11-07 13:46:58 -06:00
{
const gchar * str;
2011-11-07 16:52:18 -06:00
pluma_debug (DEBUG_PREFS);
2011-11-07 13:46:58 -06:00
switch (wp)
{
case GTK_WRAP_NONE:
str = "GTK_WRAP_NONE";
break;
case GTK_WRAP_CHAR:
str = "GTK_WRAP_CHAR";
break;
default: /* GTK_WRAP_WORD */
str = "GTK_WRAP_WORD";
}
2011-11-07 16:52:18 -06:00
pluma_prefs_manager_set_string (GPM_WRAP_MODE,
2011-11-07 13:46:58 -06:00
str);
}
gboolean
2011-11-07 16:52:18 -06:00
pluma_prefs_manager_wrap_mode_can_set (void)
2011-11-07 13:46:58 -06:00
{
2011-11-07 16:52:18 -06:00
pluma_debug (DEBUG_PREFS);
2011-11-07 13:46:58 -06:00
2011-11-07 16:52:18 -06:00
return pluma_prefs_manager_key_is_writable (GPM_WRAP_MODE);
2011-11-07 13:46:58 -06:00
}
/* Tabs size */
DEFINE_INT_PREF (tabs_size,
2013-01-24 14:03:53 -06:00
GPM_TABS_SIZE)
2011-11-07 13:46:58 -06:00
/* Insert spaces */
DEFINE_BOOL_PREF (insert_spaces,
2013-01-24 14:03:53 -06:00
GPM_INSERT_SPACES)
2011-11-07 13:46:58 -06:00
/* Auto indent */
DEFINE_BOOL_PREF (auto_indent,
2013-01-24 14:03:53 -06:00
GPM_AUTO_INDENT)
2011-11-07 13:46:58 -06:00
/* Display line numbers */
DEFINE_BOOL_PREF (display_line_numbers,
2013-01-24 14:03:53 -06:00
GPM_DISPLAY_LINE_NUMBERS)
2011-11-07 13:46:58 -06:00
/* Toolbar visibility */
DEFINE_BOOL_PREF (toolbar_visible,
2013-01-24 14:03:53 -06:00
GPM_TOOLBAR_VISIBLE)
2011-11-07 13:46:58 -06:00
/* Toolbar suttons style */
2011-11-07 16:52:18 -06:00
PlumaToolbarSetting
pluma_prefs_manager_get_toolbar_buttons_style (void)
2011-11-07 13:46:58 -06:00
{
gchar *str;
2011-11-07 16:52:18 -06:00
PlumaToolbarSetting res;
2011-11-07 13:46:58 -06:00
2011-11-07 16:52:18 -06:00
pluma_debug (DEBUG_PREFS);
2011-11-07 13:46:58 -06:00
2013-01-24 14:03:53 -06:00
str = pluma_prefs_manager_get_string (GPM_TOOLBAR_BUTTONS_STYLE);
2011-11-07 13:46:58 -06:00
2011-11-07 16:52:18 -06:00
if (strcmp (str, "PLUMA_TOOLBAR_ICONS") == 0)
res = PLUMA_TOOLBAR_ICONS;
2011-11-07 13:46:58 -06:00
else
{
2011-11-07 16:52:18 -06:00
if (strcmp (str, "PLUMA_TOOLBAR_ICONS_AND_TEXT") == 0)
res = PLUMA_TOOLBAR_ICONS_AND_TEXT;
2011-11-07 13:46:58 -06:00
else
{
2011-11-07 16:52:18 -06:00
if (strcmp (str, "PLUMA_TOOLBAR_ICONS_BOTH_HORIZ") == 0)
res = PLUMA_TOOLBAR_ICONS_BOTH_HORIZ;
2011-11-07 13:46:58 -06:00
else
2011-11-07 16:52:18 -06:00
res = PLUMA_TOOLBAR_SYSTEM;
2011-11-07 13:46:58 -06:00
}
}
g_free (str);
return res;
}
void
2011-11-07 16:52:18 -06:00
pluma_prefs_manager_set_toolbar_buttons_style (PlumaToolbarSetting tbs)
2011-11-07 13:46:58 -06:00
{
const gchar * str;
2011-11-07 16:52:18 -06:00
pluma_debug (DEBUG_PREFS);
2011-11-07 13:46:58 -06:00
switch (tbs)
{
2011-11-07 16:52:18 -06:00
case PLUMA_TOOLBAR_ICONS:
str = "PLUMA_TOOLBAR_ICONS";
2011-11-07 13:46:58 -06:00
break;
2011-11-07 16:52:18 -06:00
case PLUMA_TOOLBAR_ICONS_AND_TEXT:
str = "PLUMA_TOOLBAR_ICONS_AND_TEXT";
2011-11-07 13:46:58 -06:00
break;
2011-11-07 16:52:18 -06:00
case PLUMA_TOOLBAR_ICONS_BOTH_HORIZ:
str = "PLUMA_TOOLBAR_ICONS_BOTH_HORIZ";
2011-11-07 13:46:58 -06:00
break;
2011-11-07 16:52:18 -06:00
default: /* PLUMA_TOOLBAR_SYSTEM */
str = "PLUMA_TOOLBAR_SYSTEM";
2011-11-07 13:46:58 -06:00
}
2011-11-07 16:52:18 -06:00
pluma_prefs_manager_set_string (GPM_TOOLBAR_BUTTONS_STYLE,
2011-11-07 13:46:58 -06:00
str);
}
gboolean
2011-11-07 16:52:18 -06:00
pluma_prefs_manager_toolbar_buttons_style_can_set (void)
2011-11-07 13:46:58 -06:00
{
2011-11-07 16:52:18 -06:00
pluma_debug (DEBUG_PREFS);
2011-11-07 13:46:58 -06:00
2011-11-07 16:52:18 -06:00
return pluma_prefs_manager_key_is_writable (GPM_TOOLBAR_BUTTONS_STYLE);
2011-11-07 13:46:58 -06:00
}
/* Statusbar visiblity */
DEFINE_BOOL_PREF (statusbar_visible,
2013-01-24 14:03:53 -06:00
GPM_STATUSBAR_VISIBLE)
2011-11-07 13:46:58 -06:00
/* Side Pane visiblity */
DEFINE_BOOL_PREF (side_pane_visible,
2013-01-24 14:03:53 -06:00
GPM_SIDE_PANE_VISIBLE)
2011-11-07 13:46:58 -06:00
/* Bottom Panel visiblity */
DEFINE_BOOL_PREF (bottom_panel_visible,
2013-01-24 14:03:53 -06:00
GPM_BOTTOM_PANEL_VISIBLE)
2011-11-07 13:46:58 -06:00
/* Print syntax highlighting */
DEFINE_BOOL_PREF (print_syntax_hl,
2013-01-24 14:03:53 -06:00
GPM_PRINT_SYNTAX)
2011-11-07 13:46:58 -06:00
/* Print header */
DEFINE_BOOL_PREF (print_header,
2013-01-24 14:03:53 -06:00
GPM_PRINT_HEADER)
2011-11-07 13:46:58 -06:00
/* Print Wrap mode */
GtkWrapMode
2011-11-07 16:52:18 -06:00
pluma_prefs_manager_get_print_wrap_mode (void)
2011-11-07 13:46:58 -06:00
{
gchar *str;
GtkWrapMode res;
2011-11-07 16:52:18 -06:00
pluma_debug (DEBUG_PREFS);
2011-11-07 13:46:58 -06:00
2013-01-24 14:03:53 -06:00
str = pluma_prefs_manager_get_string (GPM_PRINT_WRAP_MODE);
2011-11-07 13:46:58 -06:00
if (strcmp (str, "GTK_WRAP_NONE") == 0)
res = GTK_WRAP_NONE;
else
{
if (strcmp (str, "GTK_WRAP_WORD") == 0)
res = GTK_WRAP_WORD;
else
res = GTK_WRAP_CHAR;
}
g_free (str);
return res;
}
void
2011-11-07 16:52:18 -06:00
pluma_prefs_manager_set_print_wrap_mode (GtkWrapMode pwp)
2011-11-07 13:46:58 -06:00
{
const gchar *str;
2011-11-07 16:52:18 -06:00
pluma_debug (DEBUG_PREFS);
2011-11-07 13:46:58 -06:00
switch (pwp)
{
case GTK_WRAP_NONE:
str = "GTK_WRAP_NONE";
break;
case GTK_WRAP_WORD:
str = "GTK_WRAP_WORD";
break;
default: /* GTK_WRAP_CHAR */
str = "GTK_WRAP_CHAR";
}
2011-11-07 16:52:18 -06:00
pluma_prefs_manager_set_string (GPM_PRINT_WRAP_MODE, str);
2011-11-07 13:46:58 -06:00
}
gboolean
2011-11-07 16:52:18 -06:00
pluma_prefs_manager_print_wrap_mode_can_set (void)
2011-11-07 13:46:58 -06:00
{
2011-11-07 16:52:18 -06:00
pluma_debug (DEBUG_PREFS);
2011-11-07 13:46:58 -06:00
2011-11-07 16:52:18 -06:00
return pluma_prefs_manager_key_is_writable (GPM_PRINT_WRAP_MODE);
2011-11-07 13:46:58 -06:00
}
/* Print line numbers */
DEFINE_INT_PREF (print_line_numbers,
2013-01-24 14:03:53 -06:00
GPM_PRINT_LINE_NUMBERS)
2011-11-07 13:46:58 -06:00
/* Printing fonts */
DEFINE_STRING_PREF (print_font_body,
2013-01-24 14:03:53 -06:00
GPM_PRINT_FONT_BODY)
2011-11-07 13:46:58 -06:00
2013-01-24 14:03:53 -06:00
gchar *
pluma_prefs_manager_get_default_string_value (const gchar *key)
{
gchar *font = NULL;
g_settings_delay (pluma_prefs_manager->settings);
g_settings_reset (pluma_prefs_manager->settings, key);
font = g_settings_get_string (pluma_prefs_manager->settings, key);
g_settings_revert (pluma_prefs_manager->settings);
return font;
}
gchar *
2011-11-07 16:52:18 -06:00
pluma_prefs_manager_get_default_print_font_body (void)
2011-11-07 13:46:58 -06:00
{
2013-01-24 14:03:53 -06:00
return pluma_prefs_manager_get_default_string_value (GPM_PRINT_FONT_BODY);
2011-11-07 13:46:58 -06:00
}
DEFINE_STRING_PREF (print_font_header,
2013-01-24 14:03:53 -06:00
GPM_PRINT_FONT_HEADER)
2011-11-07 13:46:58 -06:00
2013-01-24 14:03:53 -06:00
gchar *
2011-11-07 16:52:18 -06:00
pluma_prefs_manager_get_default_print_font_header (void)
2011-11-07 13:46:58 -06:00
{
2013-01-24 14:03:53 -06:00
return pluma_prefs_manager_get_default_string_value (GPM_PRINT_FONT_HEADER);
2011-11-07 13:46:58 -06:00
}
DEFINE_STRING_PREF (print_font_numbers,
2013-01-24 14:03:53 -06:00
GPM_PRINT_FONT_NUMBERS)
2011-11-07 13:46:58 -06:00
2013-01-24 14:03:53 -06:00
gchar *
2011-11-07 16:52:18 -06:00
pluma_prefs_manager_get_default_print_font_numbers (void)
2011-11-07 13:46:58 -06:00
{
2013-01-24 14:03:53 -06:00
return pluma_prefs_manager_get_default_string_value (GPM_PRINT_FONT_NUMBERS);
2011-11-07 13:46:58 -06:00
}
/* Max number of files in "Recent Files" menu.
2013-01-24 14:03:53 -06:00
* This is configurable only using gsettings, dconf or dconf-editor
2011-11-07 13:46:58 -06:00
*/
gint
2011-11-07 16:52:18 -06:00
pluma_prefs_manager_get_max_recents (void)
2011-11-07 13:46:58 -06:00
{
2011-11-07 16:52:18 -06:00
pluma_debug (DEBUG_PREFS);
2011-11-07 13:46:58 -06:00
2013-01-24 14:03:53 -06:00
return pluma_prefs_manager_get_int (GPM_MAX_RECENTS);
}
/* GSettings/GSList utility functions from mate-panel */
GSList*
pluma_prefs_manager_get_gslist (GSettings *settings, const gchar *key)
{
gchar **array;
GSList *list = NULL;
gint i;
array = g_settings_get_strv (settings, key);
if (array != NULL) {
for (i = 0; array[i]; i++) {
list = g_slist_append (list, g_strdup (array[i]));
}
}
g_strfreev (array);
return list;
}
2011-11-07 13:46:58 -06:00
2013-01-24 14:03:53 -06:00
void
pluma_prefs_manager_set_gslist (GSettings *settings, const gchar *key, GSList *list)
{
GArray *array;
GSList *l;
array = g_array_new (TRUE, TRUE, sizeof (gchar *));
for (l = list; l; l = l->next) {
array = g_array_append_val (array, l->data);
}
g_settings_set_strv (settings, key, (const gchar **) array->data);
g_array_free (array, TRUE);
2011-11-07 13:46:58 -06:00
}
2013-01-24 14:03:53 -06:00
2011-11-07 13:46:58 -06:00
/* Encodings */
static gboolean
data_exists (GSList *list,
const gpointer data)
{
while (list != NULL)
{
if (list->data == data)
return TRUE;
list = g_slist_next (list);
}
return FALSE;
}
GSList *
2011-11-07 16:52:18 -06:00
pluma_prefs_manager_get_auto_detected_encodings (void)
2011-11-07 13:46:58 -06:00
{
GSList *strings;
GSList *res = NULL;
2011-11-07 16:52:18 -06:00
pluma_debug (DEBUG_PREFS);
2011-11-07 13:46:58 -06:00
2011-11-07 16:52:18 -06:00
g_return_val_if_fail (pluma_prefs_manager != NULL, NULL);
2013-01-24 14:03:53 -06:00
g_return_val_if_fail (pluma_prefs_manager->settings != NULL, NULL);
2011-11-07 13:46:58 -06:00
2013-01-24 14:03:53 -06:00
strings = pluma_prefs_manager_get_gslist (pluma_prefs_manager->settings, GPM_AUTO_DETECTED_ENCODINGS);
2011-11-07 13:46:58 -06:00
if (strings != NULL)
{
GSList *tmp;
2011-11-07 16:52:18 -06:00
const PlumaEncoding *enc;
2011-11-07 13:46:58 -06:00
tmp = strings;
while (tmp)
{
const char *charset = tmp->data;
if (strcmp (charset, "CURRENT") == 0)
g_get_charset (&charset);
g_return_val_if_fail (charset != NULL, NULL);
2011-11-07 16:52:18 -06:00
enc = pluma_encoding_get_from_charset (charset);
2011-11-07 13:46:58 -06:00
if (enc != NULL)
{
if (!data_exists (res, (gpointer)enc))
res = g_slist_prepend (res, (gpointer)enc);
}
tmp = g_slist_next (tmp);
}
g_slist_foreach (strings, (GFunc) g_free, NULL);
g_slist_free (strings);
res = g_slist_reverse (res);
}
2011-11-07 16:52:18 -06:00
pluma_debug_message (DEBUG_PREFS, "Done");
2011-11-07 13:46:58 -06:00
return res;
}
GSList *
2011-11-07 16:52:18 -06:00
pluma_prefs_manager_get_shown_in_menu_encodings (void)
2011-11-07 13:46:58 -06:00
{
GSList *strings;
GSList *res = NULL;
2011-11-07 16:52:18 -06:00
pluma_debug (DEBUG_PREFS);
2011-11-07 13:46:58 -06:00
2011-11-07 16:52:18 -06:00
g_return_val_if_fail (pluma_prefs_manager != NULL, NULL);
2013-01-24 14:03:53 -06:00
g_return_val_if_fail (pluma_prefs_manager->settings != NULL, NULL);
2011-11-07 13:46:58 -06:00
2013-01-24 14:03:53 -06:00
strings = pluma_prefs_manager_get_gslist (pluma_prefs_manager->settings, GPM_SHOWN_IN_MENU_ENCODINGS);
2011-11-07 13:46:58 -06:00
if (strings != NULL)
{
GSList *tmp;
2011-11-07 16:52:18 -06:00
const PlumaEncoding *enc;
2011-11-07 13:46:58 -06:00
tmp = strings;
while (tmp)
{
const char *charset = tmp->data;
if (strcmp (charset, "CURRENT") == 0)
g_get_charset (&charset);
g_return_val_if_fail (charset != NULL, NULL);
2011-11-07 16:52:18 -06:00
enc = pluma_encoding_get_from_charset (charset);
2011-11-07 13:46:58 -06:00
if (enc != NULL)
{
if (!data_exists (res, (gpointer)enc))
res = g_slist_prepend (res, (gpointer)enc);
}
tmp = g_slist_next (tmp);
}
g_slist_foreach (strings, (GFunc) g_free, NULL);
g_slist_free (strings);
res = g_slist_reverse (res);
}
return res;
}
void
2011-11-07 16:52:18 -06:00
pluma_prefs_manager_set_shown_in_menu_encodings (const GSList *encs)
2011-11-07 13:46:58 -06:00
{
GSList *list = NULL;
2011-11-07 16:52:18 -06:00
g_return_if_fail (pluma_prefs_manager != NULL);
2013-01-24 14:03:53 -06:00
g_return_if_fail (pluma_prefs_manager->settings != NULL);
2011-11-07 16:52:18 -06:00
g_return_if_fail (pluma_prefs_manager_shown_in_menu_encodings_can_set ());
2011-11-07 13:46:58 -06:00
while (encs != NULL)
{
2011-11-07 16:52:18 -06:00
const PlumaEncoding *enc;
2011-11-07 13:46:58 -06:00
const gchar *charset;
2011-11-07 16:52:18 -06:00
enc = (const PlumaEncoding *)encs->data;
2011-11-07 13:46:58 -06:00
2011-11-07 16:52:18 -06:00
charset = pluma_encoding_get_charset (enc);
2011-11-07 13:46:58 -06:00
g_return_if_fail (charset != NULL);
list = g_slist_prepend (list, (gpointer)charset);
encs = g_slist_next (encs);
}
list = g_slist_reverse (list);
2013-01-24 14:03:53 -06:00
pluma_prefs_manager_set_gslist (pluma_prefs_manager->settings, GPM_SHOWN_IN_MENU_ENCODINGS, list);
2011-11-07 13:46:58 -06:00
g_slist_free (list);
}
gboolean
2011-11-07 16:52:18 -06:00
pluma_prefs_manager_shown_in_menu_encodings_can_set (void)
2011-11-07 13:46:58 -06:00
{
2011-11-07 16:52:18 -06:00
pluma_debug (DEBUG_PREFS);
2011-11-07 13:46:58 -06:00
2011-11-07 16:52:18 -06:00
return pluma_prefs_manager_key_is_writable (GPM_SHOWN_IN_MENU_ENCODINGS);
2011-11-07 13:46:58 -06:00
}
/* Highlight current line */
DEFINE_BOOL_PREF (highlight_current_line,
2013-01-24 14:03:53 -06:00
GPM_HIGHLIGHT_CURRENT_LINE)
2011-11-07 13:46:58 -06:00
/* Highlight matching bracket */
DEFINE_BOOL_PREF (bracket_matching,
2013-01-24 14:03:53 -06:00
GPM_BRACKET_MATCHING)
2011-11-07 13:46:58 -06:00
/* Display Right Margin */
DEFINE_BOOL_PREF (display_right_margin,
2013-01-24 14:03:53 -06:00
GPM_DISPLAY_RIGHT_MARGIN)
2011-11-07 13:46:58 -06:00
/* Right Margin Position */
DEFINE_INT_PREF (right_margin_position,
2013-01-24 14:03:53 -06:00
GPM_RIGHT_MARGIN_POSITION)
2011-11-07 13:46:58 -06:00
static GtkSourceSmartHomeEndType
get_smart_home_end_from_string (const gchar *str)
{
GtkSourceSmartHomeEndType res;
g_return_val_if_fail (str != NULL, GTK_SOURCE_SMART_HOME_END_AFTER);
if (strcmp (str, "DISABLED") == 0)
res = GTK_SOURCE_SMART_HOME_END_DISABLED;
else if (strcmp (str, "BEFORE") == 0)
res = GTK_SOURCE_SMART_HOME_END_BEFORE;
else if (strcmp (str, "ALWAYS") == 0)
res = GTK_SOURCE_SMART_HOME_END_ALWAYS;
else
res = GTK_SOURCE_SMART_HOME_END_AFTER;
return res;
}
GtkSourceSmartHomeEndType
2011-11-07 16:52:18 -06:00
pluma_prefs_manager_get_smart_home_end (void)
2011-11-07 13:46:58 -06:00
{
gchar *str;
GtkSourceSmartHomeEndType res;
2011-11-07 16:52:18 -06:00
pluma_debug (DEBUG_PREFS);
2011-11-07 13:46:58 -06:00
2013-01-24 14:03:53 -06:00
str = pluma_prefs_manager_get_string (GPM_SMART_HOME_END);
2011-11-07 13:46:58 -06:00
res = get_smart_home_end_from_string (str);
g_free (str);
return res;
}
void
2011-11-07 16:52:18 -06:00
pluma_prefs_manager_set_smart_home_end (GtkSourceSmartHomeEndType smart_he)
2011-11-07 13:46:58 -06:00
{
const gchar *str;
2011-11-07 16:52:18 -06:00
pluma_debug (DEBUG_PREFS);
2011-11-07 13:46:58 -06:00
switch (smart_he)
{
case GTK_SOURCE_SMART_HOME_END_DISABLED:
str = "DISABLED";
break;
case GTK_SOURCE_SMART_HOME_END_BEFORE:
str = "BEFORE";
break;
case GTK_SOURCE_SMART_HOME_END_ALWAYS:
str = "ALWAYS";
break;
default: /* GTK_SOURCE_SMART_HOME_END_AFTER */
str = "AFTER";
}
2011-11-07 16:52:18 -06:00
pluma_prefs_manager_set_string (GPM_WRAP_MODE, str);
2011-11-07 13:46:58 -06:00
}
gboolean
2011-11-07 16:52:18 -06:00
pluma_prefs_manager_smart_home_end_can_set (void)
2011-11-07 13:46:58 -06:00
{
2011-11-07 16:52:18 -06:00
pluma_debug (DEBUG_PREFS);
2011-11-07 13:46:58 -06:00
2011-11-07 16:52:18 -06:00
return pluma_prefs_manager_key_is_writable (GPM_SMART_HOME_END);
2011-11-07 13:46:58 -06:00
}
/* Enable syntax highlighting */
DEFINE_BOOL_PREF (enable_syntax_highlighting,
2013-01-24 14:03:53 -06:00
GPM_SYNTAX_HL_ENABLE)
2011-11-07 13:46:58 -06:00
/* Enable search highlighting */
DEFINE_BOOL_PREF (enable_search_highlighting,
2013-01-24 14:03:53 -06:00
GPM_SEARCH_HIGHLIGHTING_ENABLE)
2011-11-07 13:46:58 -06:00
/* Source style scheme */
DEFINE_STRING_PREF (source_style_scheme,
2013-01-24 14:03:53 -06:00
GPM_SOURCE_STYLE_SCHEME)
2011-11-07 13:46:58 -06:00
GSList *
2011-11-07 16:52:18 -06:00
pluma_prefs_manager_get_writable_vfs_schemes (void)
2011-11-07 13:46:58 -06:00
{
GSList *strings;
2011-11-07 16:52:18 -06:00
pluma_debug (DEBUG_PREFS);
2011-11-07 13:46:58 -06:00
2011-11-07 16:52:18 -06:00
g_return_val_if_fail (pluma_prefs_manager != NULL, NULL);
2013-01-24 14:03:53 -06:00
g_return_val_if_fail (pluma_prefs_manager->settings != NULL, NULL);
2011-11-07 13:46:58 -06:00
2013-01-24 14:03:53 -06:00
strings = pluma_prefs_manager_get_gslist (pluma_prefs_manager->settings, GPM_WRITABLE_VFS_SCHEMES);
2011-11-07 13:46:58 -06:00
/* The 'file' scheme is writable by default. */
strings = g_slist_prepend (strings, g_strdup ("file"));
2011-11-07 16:52:18 -06:00
pluma_debug_message (DEBUG_PREFS, "Done");
2011-11-07 13:46:58 -06:00
return strings;
}
gboolean
2011-11-07 16:52:18 -06:00
pluma_prefs_manager_get_restore_cursor_position (void)
2011-11-07 13:46:58 -06:00
{
2011-11-07 16:52:18 -06:00
pluma_debug (DEBUG_PREFS);
2011-11-07 13:46:58 -06:00
2013-01-24 14:03:53 -06:00
return pluma_prefs_manager_get_bool (GPM_RESTORE_CURSOR_POSITION);
2011-11-07 13:46:58 -06:00
}
/* Plugins: we just store/return a list of strings, all the magic has to
* happen in the plugin engine */
GSList *
2011-11-07 16:52:18 -06:00
pluma_prefs_manager_get_active_plugins (void)
2011-11-07 13:46:58 -06:00
{
GSList *plugins;
2011-11-07 16:52:18 -06:00
pluma_debug (DEBUG_PREFS);
2011-11-07 13:46:58 -06:00
2011-11-07 16:52:18 -06:00
g_return_val_if_fail (pluma_prefs_manager != NULL, NULL);
2013-01-24 14:03:53 -06:00
g_return_val_if_fail (pluma_prefs_manager->settings != NULL, NULL);
2011-11-07 13:46:58 -06:00
2013-01-24 14:03:53 -06:00
plugins = pluma_prefs_manager_get_gslist (pluma_prefs_manager->settings, GPM_ACTIVE_PLUGINS);
2011-11-07 13:46:58 -06:00
return plugins;
}
void
2011-11-07 16:52:18 -06:00
pluma_prefs_manager_set_active_plugins (const GSList *plugins)
2011-11-07 13:46:58 -06:00
{
2011-11-07 16:52:18 -06:00
g_return_if_fail (pluma_prefs_manager != NULL);
2013-01-24 14:03:53 -06:00
g_return_if_fail (pluma_prefs_manager->settings != NULL);
2011-11-07 16:52:18 -06:00
g_return_if_fail (pluma_prefs_manager_active_plugins_can_set ());
2011-11-07 13:46:58 -06:00
2013-01-24 14:03:53 -06:00
pluma_prefs_manager_set_gslist (pluma_prefs_manager->settings, GPM_ACTIVE_PLUGINS, (GSList *) plugins);
2011-11-07 13:46:58 -06:00
}
gboolean
2011-11-07 16:52:18 -06:00
pluma_prefs_manager_active_plugins_can_set (void)
2011-11-07 13:46:58 -06:00
{
2011-11-07 16:52:18 -06:00
pluma_debug (DEBUG_PREFS);
2011-11-07 13:46:58 -06:00
2011-11-07 16:52:18 -06:00
return pluma_prefs_manager_key_is_writable (GPM_ACTIVE_PLUGINS);
2011-11-07 13:46:58 -06:00
}
/* Global Lockdown */
2011-11-07 16:52:18 -06:00
PlumaLockdownMask
pluma_prefs_manager_get_lockdown (void)
2011-11-07 13:46:58 -06:00
{
guint lockdown = 0;
2013-01-24 14:03:53 -06:00
if (g_settings_get_boolean (pluma_prefs_manager->lockdown_settings, GPM_LOCKDOWN_COMMAND_LINE))
2011-11-07 16:52:18 -06:00
lockdown |= PLUMA_LOCKDOWN_COMMAND_LINE;
2011-11-07 13:46:58 -06:00
2013-01-24 14:03:53 -06:00
if (g_settings_get_boolean (pluma_prefs_manager->lockdown_settings, GPM_LOCKDOWN_PRINTING))
2011-11-07 16:52:18 -06:00
lockdown |= PLUMA_LOCKDOWN_PRINTING;
2011-11-07 13:46:58 -06:00
2013-01-24 14:03:53 -06:00
if (g_settings_get_boolean (pluma_prefs_manager->lockdown_settings, GPM_LOCKDOWN_PRINT_SETUP))
2011-11-07 16:52:18 -06:00
lockdown |= PLUMA_LOCKDOWN_PRINT_SETUP;
2011-11-07 13:46:58 -06:00
2013-01-24 14:03:53 -06:00
if (g_settings_get_boolean (pluma_prefs_manager->lockdown_settings, GPM_LOCKDOWN_SAVE_TO_DISK))
2011-11-07 16:52:18 -06:00
lockdown |= PLUMA_LOCKDOWN_SAVE_TO_DISK;
2011-11-07 13:46:58 -06:00
return lockdown;
}