]> git.sur5r.net Git - glabels/blob - src/prefs.c
Organized master branch to be top-level directory for glabels, instead of
[glabels] / src / prefs.c
1 /*
2  *  prefs.c
3  *  Copyright (C) 2001-2009  Jim Evins <evins@snaught.com>.
4  *
5  *  This file is part of gLabels.
6  *
7  *  gLabels is free software: you can redistribute it and/or modify
8  *  it under the terms of the GNU General Public License as published by
9  *  the Free Software Foundation, either version 3 of the License, or
10  *  (at your option) any later version.
11  *
12  *  gLabels is distributed in the hope that it will be useful,
13  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *  GNU General Public License for more details.
16  *
17  *  You should have received a copy of the GNU General Public License
18  *  along with gLabels.  If not, see <http://www.gnu.org/licenses/>.
19  */
20
21 #include <config.h>
22
23 #include "prefs.h"
24
25 #include <glib/gi18n.h>
26 #include <libglabels/libglabels.h>
27
28 #include "debug.h"
29
30 glPrefsModel      *gl_prefs     = NULL;
31
32 /*========================================================*/
33 /* Private macros and constants.                          */
34 /*========================================================*/
35
36
37 /*========================================================*/
38 /* Private types.                                         */
39 /*========================================================*/
40
41
42 /*========================================================*/
43 /* Private globals.                                       */
44 /*========================================================*/
45
46
47 /*========================================================*/
48 /* Private function prototypes.                           */
49 /*========================================================*/
50
51
52 \f
53 /*****************************************************************************/
54 /* Initialize preferences module.                                            */
55 /*****************************************************************************/
56 void 
57 gl_prefs_init (void)
58 {
59         gl_debug (DEBUG_PREFS, "START");
60
61         gl_prefs = gl_prefs_model_new ();
62
63         gl_prefs_model_load_settings (gl_prefs);
64
65         gl_debug (DEBUG_PREFS, "END");
66 }
67
68 \f
69 /****************************************************************************/
70 /* Get string representing desired units.                                   */
71 /****************************************************************************/
72 const gchar *
73 gl_prefs_get_page_size (void)
74 {
75         return (gl_prefs->default_page_size);
76 }
77
78 /****************************************************************************/
79 /* Get desired units.                                                       */
80 /****************************************************************************/
81 lglUnitsType
82 gl_prefs_get_units (void)
83 {
84         return gl_prefs->units;
85 }
86
87 /****************************************************************************/
88 /* Get desired units per point.                                             */
89 /****************************************************************************/
90 gdouble
91 gl_prefs_get_units_per_point (void)
92 {
93
94         switch (gl_prefs->units) {
95         case LGL_UNITS_POINT:
96                 return 1.0;     /* points */
97         case LGL_UNITS_INCH:
98                 return 1.0 / 72.0;      /* inches */
99         case LGL_UNITS_MM:
100                 return 0.35277778;      /* mm */
101         default:
102                 g_message ("Illegal units");    /* Should not happen */
103                 return 1.0;
104         }
105 }
106
107 /****************************************************************************/
108 /* Get precision for desired units.                                         */
109 /****************************************************************************/
110 gint
111 gl_prefs_get_units_precision (void)
112 {
113
114         switch (gl_prefs->units) {
115         case LGL_UNITS_POINT:
116                 return 1;       /* points */
117         case LGL_UNITS_INCH:
118                 return 3;       /* inches */
119         case LGL_UNITS_MM:
120                 return 1;       /* mm */
121         default:
122                 g_message ("Illegal units");    /* Should not happen */
123                 return 1.0;
124         }
125 }
126
127 /****************************************************************************/
128 /* Get step size for desired units.                                         */
129 /****************************************************************************/
130 gdouble
131 gl_prefs_get_units_step_size (void)
132 {
133
134         switch (gl_prefs->units) {
135         case LGL_UNITS_POINT:
136                 return 0.1;     /* points */
137         case LGL_UNITS_INCH:
138                 return 0.001;   /* inches */
139         case LGL_UNITS_MM:
140                 return 0.1;     /* mm */
141         default:
142                 g_message ("Illegal units");    /* Should not happen */
143                 return 1.0;
144         }
145 }
146
147 /****************************************************************************/
148 /* Get string representing desired units.                                   */
149 /****************************************************************************/
150 const gchar *
151 gl_prefs_get_units_string (void)
152 {
153
154         switch (gl_prefs->units) {
155         case LGL_UNITS_POINT:
156                 return _("points");
157         case LGL_UNITS_INCH:
158                 return _("inches");
159         case LGL_UNITS_MM:
160                 return _("mm");
161         default:
162                 g_message ("Illegal units");    /* Should not happen */
163                 return _("points");
164         }
165 }
166
167 /****************************************************************************/
168 /* Add template to recent template list.                                    */
169 /****************************************************************************/
170 void
171 gl_prefs_add_recent_template (const gchar *name)
172 {
173         GSList *p;
174
175         /*
176          * If already in list, remove that entry.
177          */
178         p = g_slist_find_custom (gl_prefs->recent_templates,
179                                  name,
180                                  (GCompareFunc)lgl_str_utf8_casecmp);
181         if (p)
182         {
183                 gl_prefs->recent_templates =
184                         g_slist_remove_link (gl_prefs->recent_templates, p);
185                 g_free (p->data);
186                 g_slist_free_1 (p);
187         }
188
189         /*
190          * Now prepend to list.
191          */
192         gl_prefs->recent_templates =
193                 g_slist_prepend (gl_prefs->recent_templates, g_strdup (name));
194
195         /*
196          * Truncate list to maximum size
197          */
198         while (g_slist_length (gl_prefs->recent_templates) > gl_prefs->max_recent_templates)
199         {
200                 p = g_slist_last (gl_prefs->recent_templates);
201                 gl_prefs->recent_templates =
202                         g_slist_remove_link (gl_prefs->recent_templates, p);
203                 g_free (p->data);
204                 g_slist_free_1 (p);
205         }
206
207         /*
208          * Sync to disk.
209          */
210         gl_prefs_model_save_settings (gl_prefs);
211 }
212
213
214
215
216 /*
217  * Local Variables:       -- emacs
218  * mode: C                -- emacs
219  * c-basic-offset: 8      -- emacs
220  * tab-width: 8           -- emacs
221  * indent-tabs-mode: nil  -- emacs
222  * End:                   -- emacs
223  */