1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
4 * (GLABELS) Label and Business Card Creation program for GNOME
6 * glabels.c: main program module
8 * Copyright (C) 2001 Jim Evins <evins@snaught.com>.
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.
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.
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
27 #include <glib/gi18n.h>
28 #include <libgnome/libgnome.h>
30 #include "merge-init.h"
31 #include "xml-label.h"
34 #include <libglabels/db.h>
39 /*============================================*/
41 /*============================================*/
42 static gchar *output = "output.pdf";
43 static gint n_copies = 1;
44 static gint n_sheets = 1;
45 static gint first = 1;
46 static gboolean outline_flag = FALSE;
47 static gboolean reverse_flag = FALSE;
48 static gboolean crop_marks_flag = FALSE;
49 static gchar *input = NULL;
50 static gchar **remaining_args = NULL;
52 static GOptionEntry option_entries[] = {
53 {"output", 'o', 0, G_OPTION_ARG_STRING, &output,
54 N_("set output filename (default=\"output.pdf\")"), N_("filename")},
55 {"sheets", 's', 0, G_OPTION_ARG_INT, &n_sheets,
56 N_("number of sheets (default=1)"), N_("sheets")},
57 {"copies", 'c', 0, G_OPTION_ARG_INT, &n_copies,
58 N_("number of copies (default=1)"), N_("copies")},
59 {"first", 'f', 0, G_OPTION_ARG_INT, &first,
60 N_("first label on first sheet (default=1)"), N_("first")},
61 {"outline", 'l', 0, G_OPTION_ARG_NONE, &outline_flag,
62 N_("print outlines (to test printer alignment)"), NULL},
63 {"reverse", 'r', 0, G_OPTION_ARG_NONE, &reverse_flag,
64 N_("print in reverse (i.e. a mirror image)"), NULL},
65 {"cropmarks", 'C', 0, G_OPTION_ARG_NONE, &crop_marks_flag,
66 N_("print crop marks"), NULL},
67 {"input", 'i', 0, G_OPTION_ARG_STRING, &input,
68 N_("input file for merging"), N_("filename")},
69 { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY,
70 &remaining_args, NULL, N_("[FILE...]") },
76 /*****************************************************************************/
78 /*****************************************************************************/
80 main (int argc, char **argv)
82 GOptionContext *option_context;
83 GnomeProgram *program;
84 GList *p, *file_list = NULL;
86 glLabel *label = NULL;
87 glMerge *merge = NULL;
88 glXMLLabelStatus status;
92 bindtextdomain (GETTEXT_PACKAGE, GLABELS_LOCALEDIR);
93 bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
94 textdomain (GETTEXT_PACKAGE);
96 option_context = g_option_context_new (_("- batch process gLabels label files"));
97 g_option_context_add_main_entries (option_context, option_entries, GETTEXT_PACKAGE);
100 /* Initialize minimal gnome program */
101 program = gnome_program_init ("glabels-batch", VERSION,
102 LIBGNOME_MODULE, argc, argv,
103 GNOME_PARAM_GOPTION_CONTEXT, option_context,
104 GNOME_PROGRAM_STANDARD_PROPERTIES,
107 /* create file list */
108 if (remaining_args != NULL) {
111 num_args = g_strv_length (remaining_args);
112 for (i = 0; i < num_args; ++i) {
113 utf8_filename = g_filename_to_utf8 (remaining_args[i], -1, NULL, NULL, NULL);
115 file_list = g_list_append (file_list, utf8_filename);
117 g_strfreev (remaining_args);
118 remaining_args = NULL;
121 /* initialize components */
127 /* now print the files */
128 for (p = file_list; p; p = p->next) {
129 g_print ("LABEL FILE = %s\n", (gchar *) p->data);
130 label = gl_xml_label_open (p->data, &status);
133 if ( status == XML_LABEL_OK ) {
136 merge = gl_label_get_merge (label);
138 gl_merge_set_src(merge, input);
139 gl_label_set_merge(label, merge);
142 _("cannot perform document merge with glabels file %s\n"),
146 abs_fn = gl_util_make_absolute ( output );
147 print_op = gl_print_op_new_batch (label,
156 gtk_print_operation_run (GTK_PRINT_OPERATION (print_op),
157 GTK_PRINT_OPERATION_ACTION_EXPORT,
161 g_object_unref (label);
164 fprintf ( stderr, _("cannot open glabels file %s\n"),
169 g_list_free (file_list);