]> git.sur5r.net Git - glabels/blobdiff - glabels2/src/prefs-dialog.c
2009-09-17 Jim Evins <evins@snaught.com>
[glabels] / glabels2 / src / prefs-dialog.c
index e5f79d3d98062f985e9611bd1b9999bb4ef4f4b8..97c0546bd4213d7af347feeedb0f24bdb72cd22e 100644 (file)
@@ -1,45 +1,41 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
-
 /*
- *  (GLABELS) Label and Business Card Creation program for GNOME
- *
- *  prefs-dialog.c:  Preferences dialog module
+ *  prefs-dialog.c
+ *  Copyright (C) 2001-2009  Jim Evins <evins@snaught.com>.
  *
- *  Copyright (C) 2001-2002  Jim Evins <evins@snaught.com>.
+ *  This file is part of gLabels.
  *
- *  This program is free software; you can redistribute it and/or modify
+ *  gLabels 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
+ *  the Free Software Foundation, either version 3 of the License, or
  *  (at your option) any later version.
  *
- *  This program is distributed in the hope that it will be useful,
+ *  gLabels 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
- *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+ *  along with gLabels.  If not, see <http://www.gnu.org/licenses/>.
  */
+
 #include <config.h>
 
 #include "prefs-dialog.h"
 
 #include <glib/gi18n.h>
-#include <gtk/gtkbuilder.h>
-#include <gtk/gtktogglebutton.h>
-#include <gtk/gtkstock.h>
-#include <gtk/gtkcombobox.h>
-#include <gtk/gtkspinbutton.h>
+#include <gtk/gtk.h>
 
 #include "prefs.h"
 #include "hig.h"
 #include "color-combo.h"
 #include "color.h"
+#include "font-combo.h"
+#include "font-util.h"
 #include "util.h"
 
 #include "debug.h"
 
+
 /*========================================================*/
 /* Private macros and constants.                          */
 /*========================================================*/
 #define US_LETTER_ID "US-Letter"
 #define A4_ID        "A4"
 
+
 /*========================================================*/
 /* Private types.                                         */
 /*========================================================*/
 
 struct _glPrefsDialogPrivate
 {
-       GtkBuilder      *gui;
+       GtkBuilder      *builder;
 
        /* Units properties */
        GtkWidget       *units_points_radio;
@@ -65,6 +62,7 @@ struct _glPrefsDialogPrivate
        GtkWidget       *page_size_a4_radio;
 
        /* Default text properties */
+       GtkWidget       *text_family_hbox;
        GtkWidget       *text_family_combo;
        GtkWidget       *text_size_spin;
        GtkWidget       *text_bold_toggle;
@@ -89,6 +87,7 @@ struct _glPrefsDialogPrivate
        gboolean    stop_signals;
 };
 
+
 /*========================================================*/
 /* Private globals.                                       */
 /*========================================================*/
@@ -117,12 +116,13 @@ static void update_object_page_from_prefs (glPrefsDialog      *dialog);
 static void update_prefs_from_locale_page (glPrefsDialog      *dialog);
 static void update_prefs_from_object_page (glPrefsDialog      *dialog);
 
-\f
+
 /*****************************************************************************/
 /* Boilerplate object stuff.                                                 */
 /*****************************************************************************/
 G_DEFINE_TYPE (glPrefsDialog, gl_prefs_dialog, GTK_TYPE_DIALOG);
 
+
 static void
 gl_prefs_dialog_class_init (glPrefsDialogClass *class)
 {
@@ -135,19 +135,24 @@ gl_prefs_dialog_class_init (glPrefsDialogClass *class)
        object_class->finalize = gl_prefs_dialog_finalize;      
 }
 
+
 static void
 gl_prefs_dialog_init (glPrefsDialog *dialog)
 {
+        static gchar *object_ids[] = { "prefs_notebook",
+                                       "adjustment1",  "adjustment2",  "adjustment3",
+                                       NULL };
         GError *error = NULL;
 
        gl_debug (DEBUG_PREFS, "START");
 
        dialog->priv = g_new0 (glPrefsDialogPrivate, 1);
 
-        dialog->priv->gui = gtk_builder_new ();
-       gtk_builder_add_from_file (dialog->priv->gui,
-                                   GLABELS_BUILDER_DIR "prefs-dialog.builder",
-                                   &error);
+        dialog->priv->builder = gtk_builder_new ();
+        gtk_builder_add_objects_from_file (dialog->priv->builder,
+                                           GLABELS_BUILDER_DIR "prefs-dialog.builder",
+                                           object_ids,
+                                           &error);
        if (error) {
                g_critical ("%s\n\ngLabels may not be installed correctly!", error->message);
                 g_error_free (error);
@@ -170,6 +175,7 @@ gl_prefs_dialog_init (glPrefsDialog *dialog)
        gl_debug (DEBUG_PREFS, "END");
 }
 
+
 static void 
 gl_prefs_dialog_finalize (GObject *object)
 {
@@ -181,9 +187,9 @@ gl_prefs_dialog_finalize (GObject *object)
        g_return_if_fail (GL_IS_PREFS_DIALOG (dialog));
        g_return_if_fail (dialog->priv != NULL);
 
-       if (dialog->priv->gui)
+       if (dialog->priv->builder)
         {
-               g_object_unref (G_OBJECT (dialog->priv->gui));
+               g_object_unref (G_OBJECT (dialog->priv->builder));
        }
        g_free (dialog->priv);
 
@@ -192,6 +198,7 @@ gl_prefs_dialog_finalize (GObject *object)
        gl_debug (DEBUG_PREFS, "END");
 }
 
+
 /*****************************************************************************/
 /* NEW preferences dialog.                                                   */
 /*****************************************************************************/
@@ -216,6 +223,7 @@ gl_prefs_dialog_new (GtkWindow *parent)
        return dialog;
 }
 
+
 /*---------------------------------------------------------------------------*/
 /* PRIVATE.  Construct composite widget.                                     */
 /*---------------------------------------------------------------------------*/
@@ -227,7 +235,7 @@ gl_prefs_dialog_construct (glPrefsDialog *dialog)
        g_return_if_fail (GL_IS_PREFS_DIALOG (dialog));
        g_return_if_fail (dialog->priv != NULL);
 
-        gl_util_get_builder_widgets (dialog->priv->gui,
+        gl_util_get_builder_widgets (dialog->priv->builder,
                                      "prefs_notebook", &notebook,
                                      NULL);
        gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), notebook, FALSE, FALSE, 0);
@@ -241,6 +249,7 @@ gl_prefs_dialog_construct (glPrefsDialog *dialog)
         gtk_widget_show_all (GTK_DIALOG (dialog)->vbox);   
 }
 
+
 /*---------------------------------------------------------------------------*/
 /* PRIVATE.  "Response" callback.                                            */
 /*---------------------------------------------------------------------------*/
@@ -268,6 +277,7 @@ response_cb (glPrefsDialog *dialog,
        gl_debug (DEBUG_VIEW, "END");
 }
 
+
 /*--------------------------------------------------------------------------*/
 /* PRIVATE.  Build Locale Properties Notebook Tab                           */
 /*--------------------------------------------------------------------------*/
@@ -275,7 +285,7 @@ static void
 construct_locale_page (glPrefsDialog *dialog)
 {
 
-        gl_util_get_builder_widgets (dialog->priv->gui,
+        gl_util_get_builder_widgets (dialog->priv->builder,
                                      "units_points_radio",        &dialog->priv->units_points_radio,
                                      "units_inches_radio",        &dialog->priv->units_inches_radio,
                                      "units_mm_radio",            &dialog->priv->units_mm_radio,
@@ -300,16 +310,15 @@ construct_locale_page (glPrefsDialog *dialog)
                "toggled", G_CALLBACK(update_prefs_from_locale_page), G_OBJECT(dialog));
 }
 
+
 /*--------------------------------------------------------------------------*/
 /* PRIVATE.  Build Default Object Properties Notebook Tab                   */
 /*--------------------------------------------------------------------------*/
 static void
 construct_object_page (glPrefsDialog *dialog)
 {
-        GList    *family_names;
-
-        gl_util_get_builder_widgets (dialog->priv->gui,
-                                     "text_family_combo",      &dialog->priv->text_family_combo,
+        gl_util_get_builder_widgets (dialog->priv->builder,
+                                     "text_family_hbox",       &dialog->priv->text_family_hbox,
                                      "text_size_spin",         &dialog->priv->text_size_spin,
                                      "text_bold_toggle",       &dialog->priv->text_bold_toggle,
                                      "text_italic_toggle",     &dialog->priv->text_italic_toggle,
@@ -323,30 +332,30 @@ construct_object_page (glPrefsDialog *dialog)
                                      "fill_color_hbox",        &dialog->priv->fill_color_hbox,
                                      NULL);
 
-       gl_util_combo_box_add_text_model (GTK_COMBO_BOX (dialog->priv->text_family_combo));
+        dialog->priv->text_family_combo = gl_font_combo_new ("Sans");
 
-       dialog->priv->text_color_combo = gl_color_combo_new (NULL, _("Default"),
+       dialog->priv->text_color_combo = gl_color_combo_new (_("Default"),
                                                              GL_COLOR_TEXT_DEFAULT,
                                                              gl_prefs->default_text_color);
-       dialog->priv->line_color_combo = gl_color_combo_new (NULL, _("No Line"),
+       dialog->priv->line_color_combo = gl_color_combo_new (_("No Line"),
                                                              GL_COLOR_NO_LINE,
                                                              gl_prefs->default_line_color);
-       dialog->priv->fill_color_combo = gl_color_combo_new (NULL, _("No Fill"),
+       dialog->priv->fill_color_combo = gl_color_combo_new (_("No Fill"),
                                                              GL_COLOR_NO_FILL,
                                                              gl_prefs->default_fill_color);
 
-        gtk_container_add (GTK_CONTAINER (dialog->priv->text_color_hbox),
-                           dialog->priv->text_color_combo);
-        gtk_container_add (GTK_CONTAINER (dialog->priv->line_color_hbox),
-                           dialog->priv->line_color_combo);
-        gtk_container_add (GTK_CONTAINER (dialog->priv->fill_color_hbox),
-                           dialog->priv->fill_color_combo);
-
-        /* Load family names */
-        family_names = gl_util_get_font_family_list ();
-       gl_util_combo_box_set_strings (GTK_COMBO_BOX (dialog->priv->text_family_combo),
-                                      family_names);
-                                                                                
+        gtk_box_pack_start (GTK_BOX (dialog->priv->text_family_hbox),
+                            dialog->priv->text_family_combo,
+                            FALSE, FALSE, 0);
+        gtk_box_pack_start (GTK_BOX (dialog->priv->text_color_hbox),
+                            dialog->priv->text_color_combo,
+                            FALSE, FALSE, 0);
+        gtk_box_pack_start (GTK_BOX (dialog->priv->line_color_hbox),
+                            dialog->priv->line_color_combo,
+                            FALSE, FALSE, 0);
+        gtk_box_pack_start (GTK_BOX (dialog->priv->fill_color_hbox),
+                            dialog->priv->fill_color_combo,
+                            FALSE, FALSE, 0);
 
        g_signal_connect_swapped (G_OBJECT(dialog->priv->text_family_combo),
                                  "changed",
@@ -476,12 +485,12 @@ update_locale_page_from_prefs (glPrefsDialog *dialog)
                break;
        }
 
-       if ( g_strcasecmp(gl_prefs->default_page_size, US_LETTER_ID) == 0)
+       if ( g_ascii_strcasecmp(gl_prefs->default_page_size, US_LETTER_ID) == 0)
         {
                gtk_toggle_button_set_active (
                        GTK_TOGGLE_BUTTON(dialog->priv->page_size_us_letter_radio), TRUE);
        }
-        else if ( g_strcasecmp(gl_prefs->default_page_size, A4_ID) == 0)
+        else if ( g_ascii_strcasecmp(gl_prefs->default_page_size, A4_ID) == 0)
         {
                gtk_toggle_button_set_active (
                        GTK_TOGGLE_BUTTON(dialog->priv->page_size_a4_radio), TRUE);
@@ -494,40 +503,18 @@ update_locale_page_from_prefs (glPrefsDialog *dialog)
        dialog->priv->stop_signals = FALSE;
 }
 
+
 /*--------------------------------------------------------------------------*/
 /* PRIVATE.  Update object page widgets from current prefs.                 */
 /*--------------------------------------------------------------------------*/
 static void
 update_object_page_from_prefs (glPrefsDialog *dialog)
 {
-        GList    *family_names;
-        gchar    *good_font_family;
  
        dialog->priv->stop_signals = TRUE;
 
-
-        /* Make sure we have a valid font family.  if not provide a good default. */
-        family_names = gl_util_get_font_family_list ();
-        if (g_list_find_custom (family_names,
-                               gl_prefs->default_font_family,
-                               (GCompareFunc)g_utf8_collate))
-        {
-                good_font_family = g_strdup (gl_prefs->default_font_family);
-        }
-        else
-        {
-                if (family_names != NULL)
-                {
-                        good_font_family = g_strdup (family_names->data); /* 1st entry */
-                }
-                else
-                {
-                        good_font_family = NULL;
-                }
-        }
-       gl_util_combo_box_set_active_text (GTK_COMBO_BOX (dialog->priv->text_family_combo),
-                                          good_font_family);
-        g_free (good_font_family);
+       gl_font_combo_set_family (GL_FONT_COMBO (dialog->priv->text_family_combo),
+                                  gl_prefs->default_font_family);
 
         gtk_spin_button_set_value (GTK_SPIN_BUTTON (dialog->priv->text_size_spin),
                                    gl_prefs->default_font_size);
@@ -565,6 +552,7 @@ update_object_page_from_prefs (glPrefsDialog *dialog)
        dialog->priv->stop_signals = FALSE;
 }
 
+
 /*--------------------------------------------------------------------------*/
 /* PRIVATE.  Update prefs from current state of locale page widgets.        */
 /*--------------------------------------------------------------------------*/
@@ -605,6 +593,7 @@ update_prefs_from_locale_page (glPrefsDialog *dialog)
        gl_prefs_model_save_settings (gl_prefs);
 }
 
+
 /*--------------------------------------------------------------------------*/
 /* PRIVATE.  Update prefs from current state of object page widgets.        */
 /*--------------------------------------------------------------------------*/
@@ -618,7 +607,7 @@ update_prefs_from_object_page (glPrefsDialog *dialog)
 
         g_free (gl_prefs->default_font_family);
         gl_prefs->default_font_family =
-               gtk_combo_box_get_active_text (GTK_COMBO_BOX (dialog->priv->text_family_combo));
+               gl_font_combo_get_family (GL_FONT_COMBO (dialog->priv->text_family_combo));
         gl_prefs->default_font_size =
                 gtk_spin_button_get_value (GTK_SPIN_BUTTON(dialog->priv->text_size_spin));
 
@@ -690,4 +679,12 @@ update_prefs_from_object_page (glPrefsDialog *dialog)
 }
 
 
-       
+
+/*
+ * Local Variables:       -- emacs
+ * mode: C                -- emacs
+ * c-basic-offset: 8      -- emacs
+ * tab-width: 8           -- emacs
+ * indent-tabs-mode: nil  -- emacs
+ * End:                   -- emacs
+ */