1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
4 * (GLABELS) Label and Business Card Creation program for GNOME
6 * prefs.c: Application preferences module
8 * Copyright (C) 2001-2003 Jim Evins <evins@snaught.com>.
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 #include <glib/gi18n.h>
29 #include <libglabels/libglabels.h>
33 glPrefsModel *gl_prefs = NULL;
35 /*========================================================*/
36 /* Private macros and constants. */
37 /*========================================================*/
40 /*========================================================*/
42 /*========================================================*/
45 /*========================================================*/
46 /* Private globals. */
47 /*========================================================*/
50 /*========================================================*/
51 /* Private function prototypes. */
52 /*========================================================*/
56 /*****************************************************************************/
57 /* Initialize preferences module. */
58 /*****************************************************************************/
62 gl_debug (DEBUG_PREFS, "START");
64 gl_prefs = gl_prefs_model_new ();
66 gl_prefs_model_load_settings (gl_prefs);
68 gl_debug (DEBUG_PREFS, "END");
72 /****************************************************************************/
73 /* Get string representing desired units. */
74 /****************************************************************************/
76 gl_prefs_get_page_size (void)
78 return (gl_prefs->default_page_size);
81 /****************************************************************************/
82 /* Get desired units. */
83 /****************************************************************************/
85 gl_prefs_get_units (void)
87 return gl_prefs->units;
90 /****************************************************************************/
91 /* Get desired units per point. */
92 /****************************************************************************/
94 gl_prefs_get_units_per_point (void)
97 switch (gl_prefs->units) {
99 return 1.0; /* points */
101 return 1.0 / 72.0; /* inches */
103 return 0.35277778; /* mm */
105 g_message ("Illegal units"); /* Should not happen */
110 /****************************************************************************/
111 /* Get precision for desired units. */
112 /****************************************************************************/
114 gl_prefs_get_units_precision (void)
117 switch (gl_prefs->units) {
118 case LGL_UNITS_POINT:
119 return 1; /* points */
121 return 3; /* inches */
125 g_message ("Illegal units"); /* Should not happen */
130 /****************************************************************************/
131 /* Get step size for desired units. */
132 /****************************************************************************/
134 gl_prefs_get_units_step_size (void)
137 switch (gl_prefs->units) {
138 case LGL_UNITS_POINT:
139 return 0.1; /* points */
141 return 0.001; /* inches */
145 g_message ("Illegal units"); /* Should not happen */
150 /****************************************************************************/
151 /* Get string representing desired units. */
152 /****************************************************************************/
154 gl_prefs_get_units_string (void)
157 switch (gl_prefs->units) {
158 case LGL_UNITS_POINT:
165 g_message ("Illegal units"); /* Should not happen */
170 /****************************************************************************/
171 /* Add template to recent template list. */
172 /****************************************************************************/
174 gl_prefs_add_recent_template (const gchar *name)
179 * If already in list, remove that entry.
181 p = g_slist_find_custom (gl_prefs->recent_templates,
183 (GCompareFunc)lgl_str_utf8_casecmp);
186 gl_prefs->recent_templates =
187 g_slist_remove_link (gl_prefs->recent_templates, p);
193 * Now prepend to list.
195 gl_prefs->recent_templates =
196 g_slist_prepend (gl_prefs->recent_templates, g_strdup (name));
199 * Truncate list to maximum size
201 while (g_slist_length (gl_prefs->recent_templates) > gl_prefs->max_recent_templates)
203 p = g_slist_last (gl_prefs->recent_templates);
204 gl_prefs->recent_templates =
205 g_slist_remove_link (gl_prefs->recent_templates, p);
213 gl_prefs_model_save_settings (gl_prefs);