]> git.sur5r.net Git - glabels/commitdiff
Add properties dialog
authorMarek Černocký <marek@manet.cz>
Thu, 18 Feb 2016 09:47:46 +0000 (10:47 +0100)
committerJim Evins <evins@snaught.com>
Sun, 21 Feb 2016 20:59:57 +0000 (15:59 -0500)
data/ui/Makefile.am
data/ui/label-properties-dialog.ui [new file with mode: 0644]
src/Makefile.am
src/file.c
src/file.h
src/label-properties-dialog.c [new file with mode: 0644]
src/label-properties-dialog.h [new file with mode: 0644]
src/label.c
src/label.h

index 833eb26b28b9dcde7819b64d70fd0c44b369e3ea..411371776b674d8f3b6096213cfda0ce0b473999 100644 (file)
@@ -10,6 +10,7 @@ builder_DATA = \
        merge-properties-dialog.ui              \
        template-designer.ui                    \
        prefs-dialog.ui                         \
-       object-editor.ui
+       object-editor.ui                        \
+       label-properties-dialog.ui
 
 EXTRA_DIST = $(builder_DATA)
diff --git a/data/ui/label-properties-dialog.ui b/data/ui/label-properties-dialog.ui
new file mode 100644 (file)
index 0000000..e407e44
--- /dev/null
@@ -0,0 +1,316 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <requires lib="gtk+" version="2.20"/>
+  <object class="GtkBox" id="label_properties_box">
+    <property name="visible">true</property>
+    <property name="can-focus">false</property>
+    <property name="orientation">horizontal</property>
+    <property name="baseline-position">top</property>
+    <property name="spacing">18</property>
+    <property name="margin">18</property>
+    
+    <child>
+      <object class="GtkGrid" id="label_properties_grid">
+        <property name="visible">true</property>
+        <property name="row-spacing">6</property>
+        <property name="column-spacing">6</property>
+        <child>
+          <object class="GtkLabel" id="label_label">
+            <property name="visible">true</property>
+            <property name="label" translatable="yes">Label</property>
+            <property name="xalign">0</property>
+            <attributes>
+              <attribute name="weight" value="bold"/>
+            </attributes>
+          </object>
+          <packing>
+            <property name="left-attach">0</property>
+            <property name="top-attach">0</property>
+            <property name="width">2</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkLabel" id="vendor_label">
+            <property name="visible">true</property>
+            <property name="label" translatable="yes">Vendor:</property>
+            <property name="xalign">1</property>
+            <style>
+              <class name="dim-label"/>
+            </style>
+          </object>
+          <packing>
+            <property name="left-attach">0</property>
+            <property name="top-attach">1</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkLabel" id="vendor_value">
+            <property name="visible">true</property>
+            <property name="can-focus">false</property>
+            <property name="xalign">0</property>
+            <property name="selectable">true</property>
+          </object>
+          <packing>
+            <property name="left-attach">1</property>
+            <property name="top-attach">1</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkLabel" id="partnum_label">
+            <property name="visible">true</property>
+            <property name="label" translatable="yes">Part #:</property>
+            <property name="xalign">1</property>
+            <style>
+              <class name="dim-label"/>
+            </style>
+          </object>
+          <packing>
+            <property name="left-attach">0</property>
+            <property name="top-attach">2</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkLabel" id="partnum_value">
+            <property name="visible">true</property>
+            <property name="can-focus">false</property>
+            <property name="xalign">0</property>
+            <property name="selectable">true</property>
+          </object>
+          <packing>
+            <property name="left-attach">1</property>
+            <property name="top-attach">2</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkLabel" id="description_label">
+            <property name="visible">true</property>
+            <property name="label" translatable="yes">Description:</property>
+            <property name="xalign">1</property>
+            <style>
+              <class name="dim-label"/>
+            </style>
+          </object>
+          <packing>
+            <property name="left-attach">0</property>
+            <property name="top-attach">3</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkLabel" id="description_value">
+            <property name="visible">true</property>
+            <property name="can-focus">false</property>
+            <property name="xalign">0</property>
+            <property name="selectable">true</property>
+          </object>
+          <packing>
+            <property name="left-attach">1</property>
+            <property name="top-attach">3</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkLabel" id="dimensions_label">
+            <property name="visible">true</property>
+            <property name="label" translatable="yes">Dimensions:</property>
+            <property name="xalign">1</property>
+            <property name="yalign">0</property>
+            <property name="margin-top">6</property>
+            <style>
+              <class name="dim-label"/>
+            </style>
+          </object>
+          <packing>
+            <property name="left-attach">0</property>
+            <property name="top-attach">4</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkLabel" id="dimensions_value">
+            <property name="visible">true</property>
+            <property name="can-focus">false</property>
+            <property name="label">17,8 × 10 / 2 mm (width × height / round)</property>
+            <property name="xalign">0</property>
+            <property name="yalign">0</property>
+            <property name="selectable">true</property>
+            <property name="margin-top">6</property>
+          </object>
+          <packing>
+            <property name="left-attach">1</property>
+            <property name="top-attach">4</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkLabel" id="medium_label">
+            <property name="visible">true</property>
+            <property name="label" translatable="yes">Medium size:</property>
+            <property name="xalign">1</property>
+            <property name="margin-top">6</property>
+            <style>
+              <class name="dim-label"/>
+            </style>
+          </object>
+          <packing>
+            <property name="left-attach">0</property>
+            <property name="top-attach">5</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkLabel" id="medium_value">
+            <property name="visible">true</property>
+            <property name="can-focus">false</property>
+            <property name="xalign">0</property>
+            <property name="selectable">true</property>
+            <property name="margin-top">6</property>
+          </object>
+          <packing>
+            <property name="left-attach">1</property>
+            <property name="top-attach">5</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkLabel" id="layout_label">
+            <property name="visible">true</property>
+            <property name="label" translatable="yes">Layout:</property>
+            <property name="xalign">1</property>
+            <style>
+              <class name="dim-label"/>
+            </style>
+          </object>
+          <packing>
+            <property name="left-attach">0</property>
+            <property name="top-attach">6</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkLabel" id="layout_value">
+            <property name="visible">true</property>
+            <property name="can-focus">false</property>
+            <property name="xalign">0</property>
+            <property name="selectable">true</property>
+          </object>
+          <packing>
+            <property name="left-attach">1</property>
+            <property name="top-attach">6</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkLabel" id="margins_label">
+            <property name="visible">true</property>
+            <property name="label" translatable="yes">Margins:</property>
+            <property name="xalign">1</property>
+            <style>
+              <class name="dim-label"/>
+            </style>
+          </object>
+          <packing>
+            <property name="left-attach">0</property>
+            <property name="top-attach">7</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkLabel" id="margins_value">
+            <property name="visible">true</property>
+            <property name="can-focus">false</property>
+            <property name="xalign">0</property>
+            <property name="selectable">true</property>
+          </object>
+          <packing>
+            <property name="left-attach">1</property>
+            <property name="top-attach">7</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkLabel" id="similar_label">
+            <property name="visible">true</property>
+            <property name="label" translatable="yes">Similar products:</property>
+            <property name="xalign">1</property>
+            <property name="yalign">0</property>
+            <property name="margin-top">6</property>
+            <style>
+              <class name="dim-label"/>
+            </style>
+          </object>
+          <packing>
+            <property name="left-attach">0</property>
+            <property name="top-attach">8</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkLabel" id="similar_value">
+            <property name="visible">true</property>
+            <property name="can-focus">false</property>
+            <property name="xalign">0</property>
+            <property name="yalign">0</property>
+            <property name="selectable">true</property>
+            <property name="margin-top">6</property>
+          </object>
+          <packing>
+            <property name="left-attach">1</property>
+            <property name="top-attach">8</property>
+          </packing>
+        </child>
+        
+        <child>
+          <object class="GtkLabel" id="options_label">
+            <property name="visible">true</property>
+            <property name="label" translatable="yes">Options</property>
+            <property name="xalign">0</property>
+            <property name="margin-top">8</property>
+            <attributes>
+              <attribute name="weight" value="bold"/>
+            </attributes>
+          </object>
+          <packing>
+            <property name="left-attach">0</property>
+            <property name="top-attach">9</property>
+            <property name="width">2</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkLabel" id="orientation_label">
+            <property name="visible">true</property>
+            <property name="label" translatable="yes">Orientation:</property>
+            <property name="xalign">1</property>
+            <style>
+              <class name="dim-label"/>
+            </style>
+          </object>
+          <packing>
+            <property name="left-attach">0</property>
+            <property name="top-attach">10</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkBox" id="orientation_box">
+            <property name="visible">true</property>
+            <property name="can-focus">false</property>
+            <property name="orientation">horizontal</property>
+            <child>
+              <object class="GtkRadioButton" id="orientation_normal_radio">
+                <property name="label" translatable="yes">_Normal</property>
+                <property name="use_underline">true</property>
+                <property name="visible">true</property>
+                <property name="can_focus">true</property>
+              </object>
+            </child>
+            <child>
+              <object class="GtkRadioButton" id="orientation_rotated_radio">
+                <property name="label" translatable="yes">_Rotated</property>
+                <property name="use_underline">true</property>
+                <property name="visible">true</property>
+                <property name="can_focus">true</property>
+                <property name="group">orientation_normal_radio</property>
+              </object>
+            </child>
+          </object>
+          <packing>
+            <property name="left-attach">1</property>
+            <property name="top-attach">10</property>
+          </packing>
+        </child>
+      </object>
+      <packing>
+        <property name="pack_type">end</property>
+      </packing>
+    </child>
+  </object>
+</interface>
index e63f32d983b5f6af4fe703d3a2582235280fef3f..49e87a4f43689fa0811ab16cfa81463597d3f8af 100644 (file)
@@ -152,6 +152,8 @@ glabels_3_SOURCES =                         \
        label-image.h                   \
        label-barcode.c                 \
        label-barcode.h                 \
+       label-properties-dialog.c       \
+       label-properties-dialog.h       \
        pixbuf-util.c                   \
        pixbuf-util.h                   \
        xml-label.c                     \
index ffe82b508050a4f7edc53397c418cbaf5dfc33fd..6668a12b2430ed0d50cbc90571f3b0071b335294 100644 (file)
@@ -30,6 +30,7 @@
 #include "recent.h"
 #include "file-util.h"
 #include "window.h"
+#include "label-properties-dialog.h"
 #include "new-label-dialog.h"
 #include <libglabels.h>
 
@@ -57,7 +58,7 @@ static gchar *save_path = NULL;
 static void new_complete                     (GtkDialog         *dialog,
                                              gpointer           user_data);
 
-static void properties_complete              (GtkDialog         *dialog,
+static void properties_choose_complete       (GtkDialog         *dialog,
                                              gpointer           user_data);
 
 static void open_response                    (GtkDialog         *chooser,
@@ -153,13 +154,39 @@ new_complete (GtkDialog *dialog,
        gl_debug (DEBUG_FILE, "END");
 }
 
-
 /*****************************************************************************/
 /* "Properties" menu callback.                                               */
 /*****************************************************************************/
 void
 gl_file_properties (glLabel   *label,
                    glWindow  *window)
+{
+       GtkWidget *dialog;
+       gint       response;
+
+       gl_debug (DEBUG_FILE, "START");
+
+       g_return_if_fail (label && GL_IS_LABEL (label));
+       g_return_if_fail (window && GTK_IS_WINDOW (window));
+
+       dialog = gl_label_properties_dialog_new (label, GTK_WINDOW (window));
+       /*Translators: dialog title*/
+       gtk_window_set_title (GTK_WINDOW (dialog), _("Label properties"));
+
+       response = gtk_dialog_run (GTK_DIALOG (dialog));
+       gtk_widget_destroy (GTK_WIDGET (dialog));
+       if (response == GL_RESPONSE_SELECT_OTHER)
+               gl_file_choose_properties (label, window);
+
+       gl_debug (DEBUG_FILE, "END");
+}
+
+/*****************************************************************************/
+/* Choose properties assistent.                                              */
+/*****************************************************************************/
+void
+gl_file_choose_properties (glLabel   *label,
+                           glWindow  *window)
 {
         const lglTemplate *template;
         gboolean           rotate_flag;
@@ -172,11 +199,12 @@ gl_file_properties (glLabel   *label,
        g_return_if_fail (window && GTK_IS_WINDOW (window));
 
        dialog = gl_new_label_dialog_new (GTK_WINDOW (window));
-       gtk_window_set_title (GTK_WINDOW (dialog), _("Label properties"));
+       /*Translators: assistent dialog title*/
+       gtk_window_set_title (GTK_WINDOW (dialog), _("Choose label properties"));
 
        g_object_set_data (G_OBJECT (dialog), "label", label);
 
-       g_signal_connect (G_OBJECT(dialog), "complete", G_CALLBACK (properties_complete), dialog);
+       g_signal_connect (G_OBJECT(dialog), "complete", G_CALLBACK (properties_choose_complete), dialog);
 
         template    = gl_label_get_template (label);
         rotate_flag = gl_label_get_rotate_flag (label);
@@ -201,11 +229,11 @@ gl_file_properties (glLabel   *label,
 
 
 /*---------------------------------------------------------------------------*/
-/* PRIVATE.  Properties "ok" button callback.                                */
+/* PRIVATE.  Properties assistant "OK" button callback.                                */
 /*---------------------------------------------------------------------------*/
 static void
-properties_complete (GtkDialog *dialog,
-                     gpointer   user_data)
+properties_choose_complete (GtkDialog *dialog,
+                            gpointer   user_data)
 {
        lglTemplate *template;
        glLabel     *label;
index 3ac975e1cb688f7678b27285cad9a88e3bdcc995..1aa2a9dde65ffea0b7126ae2cf2249f14a2441b2 100644 (file)
 
 G_BEGIN_DECLS
 
-void     gl_file_new         (glWindow        *window);
+void     gl_file_new               (glWindow        *window);
 
 
-void     gl_file_properties  (glLabel         *label,
-                             glWindow        *window);
+void     gl_file_properties        (glLabel         *label,
+                                    glWindow        *window);
 
+void     gl_file_choose_properties (glLabel         *label,
+                                    glWindow        *window);
 
-void     gl_file_open        (glWindow        *window);
 
+void     gl_file_open              (glWindow        *window);
 
-void     gl_file_open_recent (const gchar     *filename,
-                             glWindow        *window);
 
-gboolean gl_file_open_real   (const gchar     *filename,
-                             glWindow        *window);
+void     gl_file_open_recent       (const gchar     *filename,
+                                    glWindow        *window);
 
+gboolean gl_file_open_real         (const gchar     *filename,
+                                    glWindow        *window);
 
-gboolean gl_file_save        (glLabel         *label,
-                             glWindow        *window);
 
-gboolean gl_file_save_as     (glLabel         *label,
-                             glWindow        *window);
+gboolean gl_file_save              (glLabel         *label,
+                                    glWindow        *window);
 
+gboolean gl_file_save_as           (glLabel         *label,
+                                    glWindow        *window);
 
-gboolean gl_file_close       (glWindow        *window);
 
-void     gl_file_exit        (void);
+gboolean gl_file_close             (glWindow        *window);
+
+void     gl_file_exit              (void);
 
 G_END_DECLS
 
diff --git a/src/label-properties-dialog.c b/src/label-properties-dialog.c
new file mode 100644 (file)
index 0000000..595ec5f
--- /dev/null
@@ -0,0 +1,480 @@
+/*
+ *  label-properties-dialog.c
+ *  Copyright (C) 2001-2009  Jim Evins <evins@snaught.com>.
+ *
+ *  This file is part of gLabels.
+ *
+ *  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 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  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 gLabels.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <config.h>
+
+#include "label-properties-dialog.h"
+
+#include <glib/gi18n.h>
+#include <gtk/gtk.h>
+
+#include "builder-util.h"
+#include "prefs.h"
+#include "mini-preview.h"
+#include "window.h"
+#include "debug.h"
+
+
+#define MINI_PREVIEW_MIN_WIDTH  270
+#define MINI_PREVIEW_MIN_HEIGHT 360
+
+
+/*========================================================*/
+/* Private types.                                         */
+/*========================================================*/
+
+typedef struct
+{
+       glLabel        *label;
+       GtkBox         *box;
+       GtkWidget      *preview;
+       GtkLabel       *vendor;
+       GtkLabel       *partnum;
+       GtkLabel       *description;
+       GtkLabel       *dimensions;
+       GtkLabel       *medium;
+       GtkLabel       *layout;
+       GtkLabel       *margins;
+       GtkLabel       *similar_label;
+       GtkLabel       *similar;
+       GtkLabel       *orientation_label;
+       GtkBox         *orientation_box;
+       GtkRadioButton *normal_orientation;
+       GtkRadioButton *rotated_orientation;
+
+} glLabelPropertiesDialogPrivate;
+
+
+struct _glLabelPropertiesDialog
+{
+       GtkDialog                       parent;
+
+       glLabelPropertiesDialogPrivate *priv;
+};
+
+
+
+/*========================================================*/
+/* Private function prototypes                            */
+/*========================================================*/
+
+static void gl_label_properties_dialog_finalize    (GObject *object);
+
+static void gl_label_properties_dialog_rotation_cb (glLabelPropertiesDialog *dialog);
+
+static void gl_label_properties_dialog_response_cb (glLabelPropertiesDialog *dialog,
+                                                    gint                     response);
+
+static void gl_label_properties_dialog_construct   (glLabelPropertiesDialog *dialog,
+                                                    glLabel                 *label);
+
+
+/*========================================================*/
+/* Private globals.                                       */
+/*========================================================*/
+
+
+/*****************************************************************************/
+/* Boilerplate object stuff.                                                 */
+/*****************************************************************************/
+
+G_DEFINE_TYPE_WITH_PRIVATE (glLabelPropertiesDialog, gl_label_properties_dialog, GTK_TYPE_DIALOG)
+
+
+
+static void
+gl_label_properties_dialog_class_init (glLabelPropertiesDialogClass *class)
+{
+       GObjectClass *object_class = G_OBJECT_CLASS (class);
+
+       gl_debug (DEBUG_UI, "");
+
+       object_class->finalize = gl_label_properties_dialog_finalize;
+}
+
+
+static void
+gl_label_properties_dialog_rotation_cb (glLabelPropertiesDialog *dialog)
+{
+       gboolean  rotate_flag;
+       glWindow *window;
+       glView   *view;
+
+       gl_debug (DEBUG_UI, "START");
+
+       rotate_flag = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->priv->rotated_orientation));
+       gl_mini_preview_set_rotate (GL_MINI_PREVIEW (dialog->priv->preview), rotate_flag);
+       gl_label_set_rotate_flag (dialog->priv->label, rotate_flag, TRUE);
+
+       window = GL_WINDOW (gtk_window_get_transient_for (GTK_WINDOW (dialog)));
+       view = GL_VIEW (window->view);
+       if (view->zoom_to_fit_flag)
+               gl_view_zoom_to_fit (view);
+
+       gl_debug (DEBUG_UI, "END");
+}
+
+
+static void
+gl_label_properties_dialog_response_cb (glLabelPropertiesDialog *dialog,
+                                        gint                     response)
+{
+       gl_debug (DEBUG_UI, "START");
+
+       switch (response)
+       {
+       case GL_RESPONSE_SELECT_OTHER:
+       case GTK_RESPONSE_CLOSE:
+       case GTK_RESPONSE_DELETE_EVENT:
+               gtk_widget_hide (GTK_WIDGET (dialog));
+               break;
+       default:
+               g_print ("response = %d", response);
+               g_assert_not_reached ();
+       }
+
+       gl_debug (DEBUG_UI, "END");
+}
+
+
+static void
+gl_label_properties_dialog_init (glLabelPropertiesDialog *dialog)
+{
+        gchar             *builder_filename;
+       GtkBuilder        *builder;
+        static gchar      *object_ids[] = {"label_properties_box", NULL};
+        GError            *error = NULL;
+       GtkWidget         *vbox;
+
+       gl_debug (DEBUG_UI, "START");
+
+       dialog->priv = gl_label_properties_dialog_get_instance_private (dialog);
+
+        vbox = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
+
+       /*Translators: Button label to choose different template*/
+       gtk_dialog_add_button (GTK_DIALOG (dialog), _("Choose _other…"), GL_RESPONSE_SELECT_OTHER);
+       gtk_dialog_add_button (GTK_DIALOG (dialog), _("_Close"), GTK_RESPONSE_CLOSE);
+       gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_CLOSE);
+
+       builder = gtk_builder_new ();
+       builder_filename = g_build_filename (GLABELS_DATA_DIR, "ui", "label-properties-dialog.ui", NULL);
+       gtk_builder_add_objects_from_file (builder, builder_filename, object_ids, &error);
+       g_free (builder_filename);
+       if (error) {
+               g_critical ("%s\n\ngLabels may not be installed correctly!", error->message);
+               g_error_free (error);
+               return;
+       }
+
+        gl_builder_util_get_widgets (builder,
+                                    "label_properties_box", &dialog->priv->box,
+                                    "vendor_value", &dialog->priv->vendor,
+                                    "partnum_value", &dialog->priv->partnum,
+                                    "description_value", &dialog->priv->description,
+                                    "dimensions_value", &dialog->priv->dimensions,
+                                    "medium_value", &dialog->priv->medium,
+                                    "layout_value", &dialog->priv->layout,
+                                    "margins_value", &dialog->priv->margins,
+                                    "similar_label", &dialog->priv->similar_label,
+                                    "similar_value", &dialog->priv->similar,
+                                    "orientation_label", &dialog->priv->orientation_label,
+                                    "orientation_box", &dialog->priv->orientation_box,
+                                    "orientation_normal_radio", &dialog->priv->normal_orientation,
+                                    "orientation_rotated_radio", &dialog->priv->rotated_orientation,
+                                    NULL);
+
+       gtk_container_add (GTK_CONTAINER (vbox), GTK_WIDGET (dialog->priv->box));
+
+       dialog->priv->preview = gl_mini_preview_new (MINI_PREVIEW_MIN_HEIGHT, MINI_PREVIEW_MIN_WIDTH);
+        gtk_box_pack_start (dialog->priv->box, GTK_WIDGET (dialog->priv->preview), FALSE, FALSE, 0);
+       gtk_widget_show_all (dialog->priv->preview);
+
+       g_object_unref (G_OBJECT (builder));
+
+       gl_debug (DEBUG_UI, "END");
+}
+
+
+static void
+gl_label_properties_dialog_finalize (GObject *object)
+{
+       glLabelPropertiesDialog* dialog = GL_LABEL_PROPERTIES_DIALOG (object);
+
+       gl_debug (DEBUG_UI, "START");
+
+       g_return_if_fail (object != NULL);
+       g_return_if_fail (GL_IS_LABEL_PROPERTIES_DIALOG (dialog));
+       g_return_if_fail (dialog->priv != NULL);
+
+
+       G_OBJECT_CLASS (gl_label_properties_dialog_parent_class)->finalize (object);
+
+       gl_debug (DEBUG_UI, "END");
+}
+
+
+/* FIXME: Move this function to library */
+static void
+lgl_template_get_margins (const lglTemplate *template,
+                          gdouble           *hmargin,
+                          gdouble           *vmargin)
+{
+       GList                   *p, *q;
+       const lglTemplateFrame  *frame;
+       const lglTemplateLayout *layout;
+
+       /* Set margins to maximum */
+       *hmargin = template->page_width;
+       *vmargin = template->page_height;
+
+       /* and search lowest margin in layouts */
+       for (p = template->frames; p; p = p->next)
+       {
+               frame = (lglTemplateFrame *)p->data;
+               for (q = frame->all.layouts; q; q = q->next)
+               {
+                       layout = (lglTemplateLayout *)q->data;
+                       if (layout->x0 < *hmargin)
+                               *hmargin = layout->x0;
+                       if (layout->y0 < *vmargin)
+                               *vmargin = layout->y0;
+               }
+       }
+}
+
+/* FIXME: Move this function to library */
+gchar *
+lgl_template_get_margins_string (const lglTemplate *template)
+{
+       lglUnits  units;
+       gdouble   units_per_point;
+       gdouble   hmargin, vmargin;
+       gchar    *hmargin_str, *vmargin_str;
+       gchar    *margins_str;
+
+       units = gl_prefs_model_get_units (gl_prefs);
+       units_per_point = lgl_units_get_units_per_point (units);
+
+       lgl_template_get_margins (template, &hmargin, &vmargin);
+
+       if (units == LGL_UNITS_INCH)
+       {
+               hmargin_str = lgl_str_format_fraction (hmargin*units_per_point);
+               vmargin_str = lgl_str_format_fraction (vmargin*units_per_point);
+       }
+       else
+       {
+               hmargin_str = g_strdup_printf ("%.5g", hmargin*units_per_point);
+               vmargin_str = g_strdup_printf ("%.5g", vmargin*units_per_point);
+       }
+
+       /*Translators: first param is numeric value of horizontal margine, second*/
+       /*is numeric value of vertical margine and third is unit. Example:       */
+       /*"10 / 12.5 mm (horizontal / vertical)"*/
+       margins_str = g_strdup_printf (_("%s / %s %s (horizontal / vertical)"),
+                                      hmargin_str, vmargin_str, lgl_units_get_name (units));
+
+       g_free (hmargin_str);
+       g_free (vmargin_str);
+
+       return margins_str;
+}
+
+/*--------------------------------------------------------------------------*/
+/* PRIVATE.  Create properties widgets.                                          */
+/*--------------------------------------------------------------------------*/
+static void
+gl_label_properties_dialog_construct (glLabelPropertiesDialog *dialog,
+                                     glLabel                 *label)
+{
+       const lglTemplate *template;
+       gchar             *template_name;
+       lglUnits           units;
+       gdouble            units_per_point;
+       lglVendor         *vendor;
+       gchar             *text;
+       gchar             *link;
+       gchar             *escaped_url;
+       GList             *list, *p;
+       GString           *list_text;
+       gboolean           rotate_flag;
+       gdouble            w, h;
+
+       gl_debug (DEBUG_UI, "START");
+
+       dialog->priv->label = label;
+
+       template = gl_label_get_template (label);
+       template_name = lgl_template_get_name (template);
+       units = gl_prefs_model_get_units (gl_prefs);
+       units_per_point = lgl_units_get_units_per_point (units);
+
+       /* Vendor */
+       vendor = lgl_db_lookup_vendor_from_name (template->brand);
+       if (vendor && vendor->url)
+       {
+               escaped_url = g_markup_escape_text (vendor->url, -1);
+               link = g_strconcat ("<a href=\"", escaped_url , "\">", template->brand, "</a>", NULL);
+               gtk_label_set_markup (dialog->priv->vendor, link);
+               g_free (escaped_url);
+               g_free (link);
+       }
+       else
+       {
+               gtk_label_set_label (dialog->priv->vendor, template->brand);
+       }
+
+       /* Part number */
+       if (template->product_url)
+       {
+               escaped_url = g_markup_escape_text (template->product_url, -1);
+               link = g_strconcat ("<a href=\"", escaped_url, "\">", template->part, "</a>", NULL);
+               gtk_label_set_markup (dialog->priv->partnum, link);
+               g_free (escaped_url);
+               g_free (link);
+       }
+       else
+       {
+               gtk_label_set_label (dialog->priv->partnum, template->part);
+       }
+
+       /* Description */
+       gtk_label_set_label (dialog->priv->description, template->description);
+
+       /* Dimensions */
+       text = gl_label_get_dimensions_string (label);
+       gtk_label_set_label (dialog->priv->dimensions, text);
+       g_free (text);
+
+       /* Medium */
+       text = lgl_db_lookup_paper_name_from_id (template->paper_id);
+       gtk_label_set_label (dialog->priv->medium, text);
+       g_free (text);
+
+       /* Layout */
+       text = lgl_template_frame_get_layout_description (template->frames->data);
+       gtk_label_set_label (dialog->priv->layout, text);
+       g_free (text);
+
+       /* Margins */
+       text = lgl_template_get_margins_string (template);
+       gtk_label_set_label (dialog->priv->margins, text);
+       g_free (text);
+
+       /* Similar products */
+       list = lgl_db_get_similar_template_name_list (template_name);
+       if (list)
+       {
+               list_text = g_string_new ("");
+               for (p = list; p; p = p->next)
+               {
+                       g_string_append (list_text, (char *)p->data);
+                       if (p->next)
+                               g_string_append_c (list_text, '\n');
+               }
+               gtk_label_set_text (dialog->priv->similar, list_text->str);
+               g_string_free (list_text, TRUE);
+       }
+       else
+       {
+               gtk_widget_hide (GTK_WIDGET (dialog->priv->similar_label));
+               gtk_widget_hide (GTK_WIDGET (dialog->priv->similar));
+       }
+
+       /* Orientation */
+       gl_label_get_size (label, &w, &h);
+       if (w == h)
+       {
+               gtk_widget_hide (GTK_WIDGET (dialog->priv->orientation_label));
+               gtk_widget_hide (GTK_WIDGET (dialog->priv->orientation_box));
+               gl_mini_preview_set_draw_arrow (GL_MINI_PREVIEW (dialog->priv->preview), FALSE);
+       }
+       else
+       {
+               rotate_flag = gl_label_get_rotate_flag (label);
+               if (rotate_flag)
+                       gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->priv->rotated_orientation), TRUE);
+               else
+                       gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->priv->normal_orientation), TRUE);
+               gl_mini_preview_set_draw_arrow (GL_MINI_PREVIEW (dialog->priv->preview), TRUE);
+               gl_mini_preview_set_rotate (GL_MINI_PREVIEW (dialog->priv->preview), rotate_flag);
+       }
+
+       /* Preview */
+       gl_mini_preview_set_template (GL_MINI_PREVIEW (dialog->priv->preview), template);
+
+       g_free (template_name);
+       g_free (vendor);
+
+       g_signal_connect_swapped (G_OBJECT (dialog->priv->normal_orientation),
+                                 "toggled",
+                                 G_CALLBACK (gl_label_properties_dialog_rotation_cb),
+                                 dialog);
+       g_signal_connect_swapped (G_OBJECT (dialog->priv->rotated_orientation),
+                                 "toggled",
+                                 G_CALLBACK (gl_label_properties_dialog_rotation_cb),
+                                 dialog);
+       g_signal_connect (G_OBJECT (dialog),
+                         "response",
+                         G_CALLBACK (gl_label_properties_dialog_response_cb),
+                         NULL);
+
+       gl_debug (DEBUG_UI, "END");
+}
+
+
+/*****************************************************************************/
+/* NEW document properties dialog.                                                   */
+/*****************************************************************************/
+GtkWidget*
+gl_label_properties_dialog_new (glLabel *label,
+                               GtkWindow *parent)
+{
+       glLabelPropertiesDialog *dialog;
+
+       g_assert (GL_IS_LABEL (label));
+
+       gl_debug (DEBUG_UI, "START");
+
+       dialog = GL_LABEL_PROPERTIES_DIALOG (g_object_new (GL_TYPE_LABEL_PROPERTIES_DIALOG, NULL));
+
+       if (parent)
+               gtk_window_set_transient_for (GTK_WINDOW (dialog), parent);
+
+       gl_label_properties_dialog_construct (GL_LABEL_PROPERTIES_DIALOG (dialog),
+                                             label);
+
+       gl_debug (DEBUG_UI, "END");
+
+       return GTK_WIDGET (dialog);
+}
+
+
+
+
+/*
+ * Local Variables:       -- emacs
+ * mode: C                -- emacs
+ * c-basic-offset: 8      -- emacs
+ * tab-width: 8           -- emacs
+ * indent-tabs-mode: nil  -- emacs
+ * End:                   -- emacs
+ */
diff --git a/src/label-properties-dialog.h b/src/label-properties-dialog.h
new file mode 100644 (file)
index 0000000..53c98cc
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+ *  label-properties-dialog.h
+ *  Copyright (C) 2001-2009  Jim Evins <evins@snaught.com>.
+ *
+ *  This file is part of gLabels.
+ *
+ *  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 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  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 gLabels.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __LABEL_PROPERTIES_DIALOG_H__
+#define __LABEL_PROPERTIES_DIALOG_H__
+
+
+#include <gtk/gtk.h>
+
+#include "label.h"
+
+
+G_BEGIN_DECLS
+
+#define GL_RESPONSE_SELECT_OTHER 1
+
+#define GL_TYPE_LABEL_PROPERTIES_DIALOG (gl_label_properties_dialog_get_type ())
+
+G_DECLARE_FINAL_TYPE (glLabelPropertiesDialog, gl_label_properties_dialog, GL, LABEL_PROPERTIES_DIALOG, GtkDialog)
+
+GtkWidget *gl_label_properties_dialog_new (glLabel *label, GtkWindow *parent);
+
+G_END_DECLS
+
+
+#endif /* __LABEL_PROPERTIES_DIALOG_H__ */
+
+
+
+
+/*
+ * Local Variables:       -- emacs
+ * mode: C                -- emacs
+ * c-basic-offset: 8      -- emacs
+ * tab-width: 8           -- emacs
+ * indent-tabs-mode: nil  -- emacs
+ * End:                   -- emacs
+ */
index 48df06a43511380a274981455801baa85cb328a1..52292a5797f380c0c0c59e3524eec465aa12301d 100644 (file)
@@ -703,6 +703,121 @@ gl_label_get_size (glLabel *label,
 }
 
 
+/****************************************************************************/
+/* get string with info about dimensions                                    */
+/****************************************************************************/
+gchar *
+gl_label_get_dimensions_string (glLabel *label)
+{
+       gchar                  *dims;
+       lglTemplate            *template;
+       const lglTemplateFrame *frame;
+       lglUnits                units;
+       gdouble                 units_per_point;
+       gchar                  *s1 = NULL;
+       gchar                  *s2 = NULL;
+       gchar                  *s3 = NULL;
+
+       gl_debug (DEBUG_LABEL, "START");
+
+       g_return_val_if_fail (label && GL_IS_LABEL (label), NULL);
+
+       template = label->priv->template;
+       if (!template)
+               return g_strdup("");
+        frame = (lglTemplateFrame *)template->frames->data;
+       units = gl_prefs_model_get_units (gl_prefs);
+       units_per_point = lgl_units_get_units_per_point (units);
+
+       switch (frame->shape)
+       {
+       case LGL_TEMPLATE_FRAME_SHAPE_RECT:
+               if (units == LGL_UNITS_INCH)
+               {
+                       s1 = lgl_str_format_fraction (frame->rect.w*units_per_point);
+                       s2 = lgl_str_format_fraction (frame->rect.h*units_per_point);
+                       s3 = lgl_str_format_fraction (frame->rect.r*units_per_point);
+               }
+               else
+               {
+                       s1 = g_strdup_printf ("%.5g", frame->rect.w*units_per_point);
+                       s2 = g_strdup_printf ("%.5g", frame->rect.h*units_per_point);
+                       s3 = g_strdup_printf ("%.5g", frame->rect.r*units_per_point);
+               }
+               if (frame->rect.r == 0)
+                       /*Translators: first param is numeric value of width, second is numeric*/
+                       /*value of height and third is unit. Example:*/
+                       /*"60 mm × 22.5 mm (width / height)"*/
+                       dims = g_strdup_printf (_("%s × %s %s (width × height)"),
+                                               s1, s2, lgl_units_get_name (units));
+               else
+                       /*Translators: first param is numeric value of width, second is numeric*/
+                       /*value of height, third is numeric value of round and fourth is unit. */
+                       /*Example:*/
+                       /*"50 mm × 30 / 1.5 mm (width × height / round)"*/
+                       dims = g_strdup_printf (_("%s × %s / %s %s (width × height / round)"),
+                                               s1, s2, s3, lgl_units_get_name (units));
+               break;
+
+       case LGL_TEMPLATE_FRAME_SHAPE_ELLIPSE:
+               if (units == LGL_UNITS_INCH)
+               {
+                       s1 = lgl_str_format_fraction (frame->ellipse.w*units_per_point);
+                       s2 = lgl_str_format_fraction (frame->ellipse.h*units_per_point);
+               }
+               else
+               {
+                       s1 = g_strdup_printf ("%.5g", frame->ellipse.w*units_per_point);
+                       s2 = g_strdup_printf ("%.5g", frame->ellipse.h*units_per_point);
+               }
+               /*Translators: first param is numeric value of width, second is numeric*/
+               /*value of height and third is unit. Example:*/
+               /*"60 mm × 22.5 mm (width / height)"*/
+               dims = g_strdup_printf (_("%s × %s %s (width × height)"),
+                                       s1, s2, lgl_units_get_name (units));
+               break;
+
+       case LGL_TEMPLATE_FRAME_SHAPE_ROUND:
+               if (units == LGL_UNITS_INCH)
+                       s1 = lgl_str_format_fraction (2*frame->round.r*units_per_point);
+               else
+                       s1 = g_strdup_printf ("%.5g", 2*frame->round.r*units_per_point);
+               /*Translators: first param is numeric value of diameter and secons is*/
+               /*unit. Example:*/
+               /*"120.5 mm (diameter)"*/
+               dims = g_strdup_printf (_("%s %s (diameter)"),
+                                       s1, lgl_units_get_name (units));
+               break;
+
+       case LGL_TEMPLATE_FRAME_SHAPE_CD:
+               if (units == LGL_UNITS_INCH)
+               {
+                       s1 = lgl_str_format_fraction (2*frame->cd.r1*units_per_point);
+                       s2 = lgl_str_format_fraction (2*frame->cd.r2*units_per_point);
+               }
+               else
+               {
+                       s1 = g_strdup_printf ("%.5g", 2*frame->cd.r1*units_per_point);
+                       s2 = g_strdup_printf ("%.5g", 2*frame->cd.r2*units_per_point);
+               }
+               /*Translators: first param is numeric value of diameter, second is numeric*/
+               /*value of whole and third is unit. Example:*/
+               /*"120.5 mm / 30 mm (diameter / hole)"*/
+               dims = g_strdup_printf (_("%s / %s %s (diameter / hole)"),
+                                       s1, s2, lgl_units_get_name (units));
+               break;
+       }
+
+       g_free (s1);
+       g_free (s2);
+       g_free (s3);
+
+       gl_debug (DEBUG_LABEL, "END");
+
+       return dims;
+}
+
+
 /****************************************************************************/
 /* set merge information structure.                                         */
 /****************************************************************************/
index f93f6f4e406cb6b35b005ef1fb1abf5e2e547091..003e27bd6a2fc090cab71596260133336abbc0ab 100644 (file)
@@ -124,6 +124,7 @@ void          gl_label_get_size                (glLabel       *label,
                                                gdouble       *w,
                                                gdouble       *h);
 
+gchar        *gl_label_get_dimensions_string   (glLabel       *label);
 
 void          gl_label_set_merge               (glLabel       *label,
                                                glMerge       *merge,