]> git.sur5r.net Git - glabels/blob - src/prefs.c
Imported Upstream version 2.2.8
[glabels] / src / prefs.c
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
2
3 /*
4  *  (GLABELS) Label and Business Card Creation program for GNOME
5  *
6  *  prefs.c:  Application preferences module
7  *
8  *  Copyright (C) 2001-2003  Jim Evins <evins@snaught.com>.
9  *
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.
14  *
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.
19  *
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
23  */
24 #include <config.h>
25
26 #include "prefs.h"
27
28 #include <glib/gi18n.h>
29 #include <libglabels/libglabels.h>
30
31 #include "debug.h"
32
33 glPrefsModel      *gl_prefs     = NULL;
34
35 /*========================================================*/
36 /* Private macros and constants.                          */
37 /*========================================================*/
38
39
40 /*========================================================*/
41 /* Private types.                                         */
42 /*========================================================*/
43
44
45 /*========================================================*/
46 /* Private globals.                                       */
47 /*========================================================*/
48
49
50 /*========================================================*/
51 /* Private function prototypes.                           */
52 /*========================================================*/
53
54
55 \f
56 /*****************************************************************************/
57 /* Initialize preferences module.                                            */
58 /*****************************************************************************/
59 void 
60 gl_prefs_init (void)
61 {
62         gl_debug (DEBUG_PREFS, "START");
63
64         gl_prefs = gl_prefs_model_new ();
65
66         gl_prefs_model_load_settings (gl_prefs);
67
68         gl_debug (DEBUG_PREFS, "END");
69 }
70
71 \f
72 /****************************************************************************/
73 /* Get string representing desired units.                                   */
74 /****************************************************************************/
75 const gchar *
76 gl_prefs_get_page_size (void)
77 {
78         return (gl_prefs->default_page_size);
79 }
80
81 /****************************************************************************/
82 /* Get desired units.                                                       */
83 /****************************************************************************/
84 lglUnitsType
85 gl_prefs_get_units (void)
86 {
87         return gl_prefs->units;
88 }
89
90 /****************************************************************************/
91 /* Get desired units per point.                                             */
92 /****************************************************************************/
93 gdouble
94 gl_prefs_get_units_per_point (void)
95 {
96
97         switch (gl_prefs->units) {
98         case LGL_UNITS_POINT:
99                 return 1.0;     /* points */
100         case LGL_UNITS_INCH:
101                 return 1.0 / 72.0;      /* inches */
102         case LGL_UNITS_MM:
103                 return 0.35277778;      /* mm */
104         default:
105                 g_message ("Illegal units");    /* Should not happen */
106                 return 1.0;
107         }
108 }
109
110 /****************************************************************************/
111 /* Get precision for desired units.                                         */
112 /****************************************************************************/
113 gint
114 gl_prefs_get_units_precision (void)
115 {
116
117         switch (gl_prefs->units) {
118         case LGL_UNITS_POINT:
119                 return 1;       /* points */
120         case LGL_UNITS_INCH:
121                 return 3;       /* inches */
122         case LGL_UNITS_MM:
123                 return 1;       /* mm */
124         default:
125                 g_message ("Illegal units");    /* Should not happen */
126                 return 1.0;
127         }
128 }
129
130 /****************************************************************************/
131 /* Get step size for desired units.                                         */
132 /****************************************************************************/
133 gdouble
134 gl_prefs_get_units_step_size (void)
135 {
136
137         switch (gl_prefs->units) {
138         case LGL_UNITS_POINT:
139                 return 0.1;     /* points */
140         case LGL_UNITS_INCH:
141                 return 0.001;   /* inches */
142         case LGL_UNITS_MM:
143                 return 0.1;     /* mm */
144         default:
145                 g_message ("Illegal units");    /* Should not happen */
146                 return 1.0;
147         }
148 }
149
150 /****************************************************************************/
151 /* Get string representing desired units.                                   */
152 /****************************************************************************/
153 const gchar *
154 gl_prefs_get_units_string (void)
155 {
156
157         switch (gl_prefs->units) {
158         case LGL_UNITS_POINT:
159                 return _("points");
160         case LGL_UNITS_INCH:
161                 return _("inches");
162         case LGL_UNITS_MM:
163                 return _("mm");
164         default:
165                 g_message ("Illegal units");    /* Should not happen */
166                 return _("points");
167         }
168 }
169
170 /****************************************************************************/
171 /* Add template to recent template list.                                    */
172 /****************************************************************************/
173 void
174 gl_prefs_add_recent_template (const gchar *name)
175 {
176         GSList *p;
177
178         /*
179          * If already in list, remove that entry.
180          */
181         p = g_slist_find_custom (gl_prefs->recent_templates,
182                                  name,
183                                  (GCompareFunc)lgl_str_utf8_casecmp);
184         if (p)
185         {
186                 gl_prefs->recent_templates =
187                         g_slist_remove_link (gl_prefs->recent_templates, p);
188                 g_free (p->data);
189                 g_slist_free_1 (p);
190         }
191
192         /*
193          * Now prepend to list.
194          */
195         gl_prefs->recent_templates =
196                 g_slist_prepend (gl_prefs->recent_templates, g_strdup (name));
197
198         /*
199          * Truncate list to maximum size
200          */
201         while (g_slist_length (gl_prefs->recent_templates) > gl_prefs->max_recent_templates)
202         {
203                 p = g_slist_last (gl_prefs->recent_templates);
204                 gl_prefs->recent_templates =
205                         g_slist_remove_link (gl_prefs->recent_templates, p);
206                 g_free (p->data);
207                 g_slist_free_1 (p);
208         }
209
210         /*
211          * Sync to disk.
212          */
213         gl_prefs_model_save_settings (gl_prefs);
214 }