]> git.sur5r.net Git - glabels/blobdiff - src/glabels-batch.c
Imported Upstream version 3.0.0
[glabels] / src / glabels-batch.c
index 41ebf9d657d75f837a441d86a9b76299e7205810..fb5cc7afa376253b3ebf099579dd5edc3f401667 100644 (file)
@@ -1,38 +1,37 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
-
 /*
- *  (GLABELS) Label and Business Card Creation program for GNOME
- *
- *  glabels.c: main program module
+ *  glabels-batch.c
+ *  Copyright (C) 2001-2009  Jim Evins <evins@snaught.com>.
  *
- *  Copyright (C) 2001  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 <glib/gi18n.h>
-#include <libgnome/libgnome.h>
 
+#include <math.h>
+
+#include <libglabels.h>
 #include "merge-init.h"
+#include "template-history.h"
+#include "font-history.h"
 #include "xml-label.h"
 #include "print.h"
 #include "print-op.h"
-#include <libglabels/db.h>
-#include "util.h"
+#include "file-util.h"
 #include "prefs.h"
 #include "debug.h"
 
@@ -80,29 +79,37 @@ int
 main (int argc, char **argv)
 {
        GOptionContext    *option_context;
-        GnomeProgram      *program;
         GList             *p, *file_list = NULL;
         gchar             *abs_fn;
         glLabel           *label = NULL;
         glMerge           *merge = NULL;
+        const lglTemplate *template;
+        lglTemplateFrame  *frame;
         glXMLLabelStatus   status;
         glPrintOp         *print_op;
        gchar             *utf8_filename;
+        GError            *error = NULL;
 
-        bindtextdomain (GETTEXT_PACKAGE, GLABELS_LOCALEDIR);
+        bindtextdomain (GETTEXT_PACKAGE, GLABELS_LOCALE_DIR);
        bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
         textdomain (GETTEXT_PACKAGE);
 
-       option_context = g_option_context_new (_("- batch process gLabels label files"));
+       option_context = g_option_context_new (NULL);
+        g_option_context_set_summary (option_context,
+                                      _("Print files created with gLabels."));
        g_option_context_add_main_entries (option_context, option_entries, GETTEXT_PACKAGE);
 
 
         /* Initialize minimal gnome program */
-        program = gnome_program_init ("glabels-batch", VERSION,
-                                      LIBGNOME_MODULE, argc, argv,
-                                     GNOME_PARAM_GOPTION_CONTEXT, option_context,
-                                      GNOME_PROGRAM_STANDARD_PROPERTIES,
-                                      NULL);
+        gtk_init_check (&argc, &argv);
+        if (!g_option_context_parse (option_context, &argc, &argv, &error))
+       {
+               g_print(_("%s\nRun '%s --help' to see a full list of available command line options.\n"),
+                       error->message, argv[0]);
+               g_error_free (error);
+               return 1;
+       }
+
 
         /* create file list */
        if (remaining_args != NULL) {
@@ -123,6 +130,8 @@ main (int argc, char **argv)
         gl_merge_init ();
         lgl_db_init ();
        gl_prefs_init ();
+       gl_template_history_init ();
+       gl_font_history_init ();
 
         /* now print the files */
         for (p = file_list; p; p = p->next) {
@@ -132,27 +141,40 @@ main (int argc, char **argv)
 
                 if ( status == XML_LABEL_OK ) {
 
+                        merge = gl_label_get_merge (label);
                         if (input != NULL) {
-                                merge = gl_label_get_merge (label);
                                 if (merge != NULL) {
                                         gl_merge_set_src(merge, input);
-                                        gl_label_set_merge(label, merge);
+                                        gl_label_set_merge(label, merge, FALSE);
                                 } else {
                                         fprintf ( stderr,
                                                   _("cannot perform document merge with glabels file %s\n"),
                                                   (char *)p->data );
                                 }
                         }
-                        abs_fn = gl_util_make_absolute ( output );
-                        print_op = gl_print_op_new_batch (label,
-                                                          abs_fn,
-                                                          n_sheets,
-                                                          n_copies,
-                                                          first,
-                                                          outline_flag,
-                                                          reverse_flag,
-                                                          crop_marks_flag);
-
+                        abs_fn = gl_file_util_make_absolute ( output );
+                        template = gl_label_get_template (label);
+                        frame = (lglTemplateFrame *)template->frames->data;
+
+                        print_op = gl_print_op_new (label);
+                        gl_print_op_set_filename        (print_op, abs_fn);
+                        gl_print_op_set_n_copies        (print_op, n_copies);
+                        gl_print_op_set_first           (print_op, first);
+                        gl_print_op_set_outline_flag    (print_op, outline_flag);
+                        gl_print_op_set_reverse_flag    (print_op, reverse_flag);
+                        gl_print_op_set_crop_marks_flag (print_op, crop_marks_flag);
+                        if (merge)
+                        {
+                                gl_print_op_set_n_sheets (print_op,
+                                                          ceil ((double)(first-1 + n_copies * gl_merge_get_record_count(merge))
+                                                                / lgl_template_frame_get_n_labels (frame)));
+                        }
+                        else
+                        {
+                                gl_print_op_set_n_sheets (print_op, n_sheets);
+                                gl_print_op_set_last     (print_op,
+                                                          lgl_template_frame_get_n_labels (frame));
+                        }
                         gtk_print_operation_run (GTK_PRINT_OPERATION (print_op),
                                                  GTK_PRINT_OPERATION_ACTION_EXPORT,
                                                  NULL,
@@ -171,3 +193,14 @@ main (int argc, char **argv)
         return 0;
 }
 
+
+
+
+/*
+ * Local Variables:       -- emacs
+ * mode: C                -- emacs
+ * c-basic-offset: 8      -- emacs
+ * tab-width: 8           -- emacs
+ * indent-tabs-mode: nil  -- emacs
+ * End:                   -- emacs
+ */