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>
38 /*============================================*/
40 /*============================================*/
41 static gchar *output = "output.pdf";
42 static gint n_copies = 1;
43 static gint n_sheets = 1;
44 static gint first = 1;
45 static gboolean outline_flag = FALSE;
46 static gboolean reverse_flag = FALSE;
47 static gboolean crop_marks_flag = FALSE;
48 static gchar *input = NULL;
49 static gchar **remaining_args = NULL;
51 static GOptionEntry option_entries[] = {
52 {"output", 'o', 0, G_OPTION_ARG_STRING, &output,
53 N_("set output filename (default=\"output.pdf\")"), N_("filename")},
54 {"sheets", 's', 0, G_OPTION_ARG_INT, &n_sheets,
55 N_("number of sheets (default=1)"), N_("sheets")},
56 {"copies", 'c', 0, G_OPTION_ARG_INT, &n_copies,
57 N_("number of copies (default=1)"), N_("copies")},
58 {"first", 'f', 0, G_OPTION_ARG_INT, &first,
59 N_("first label on first sheet (default=1)"), N_("first")},
60 {"outline", 'l', 0, G_OPTION_ARG_NONE, &outline_flag,
61 N_("print outlines (to test printer alignment)"), NULL},
62 {"reverse", 'r', 0, G_OPTION_ARG_NONE, &reverse_flag,
63 N_("print in reverse (i.e. a mirror image)"), NULL},
64 {"cropmarks", 'C', 0, G_OPTION_ARG_NONE, &crop_marks_flag,
65 N_("print crop marks"), NULL},
66 {"input", 'i', 0, G_OPTION_ARG_STRING, &input,
67 N_("input file for merging"), N_("filename")},
68 { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY,
69 &remaining_args, NULL, N_("[FILE...]") },
75 /*****************************************************************************/
77 /*****************************************************************************/
79 main (int argc, char **argv)
81 GOptionContext *option_context;
82 GnomeProgram *program;
83 GList *p, *file_list = NULL;
85 glLabel *label = NULL;
86 glMerge *merge = NULL;
87 glXMLLabelStatus status;
91 bindtextdomain (GETTEXT_PACKAGE, GLABELS_LOCALEDIR);
92 bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
93 textdomain (GETTEXT_PACKAGE);
95 option_context = g_option_context_new (_("- batch process gLabels label files"));
96 g_option_context_add_main_entries (option_context, option_entries, GETTEXT_PACKAGE);
99 /* Initialize minimal gnome program */
100 program = gnome_program_init ("glabels-batch", VERSION,
101 LIBGNOME_MODULE, argc, argv,
102 GNOME_PARAM_GOPTION_CONTEXT, option_context,
103 GNOME_PROGRAM_STANDARD_PROPERTIES,
106 /* create file list */
107 if (remaining_args != NULL) {
110 num_args = g_strv_length (remaining_args);
111 for (i = 0; i < num_args; ++i) {
112 utf8_filename = g_filename_to_utf8 (remaining_args[i], -1, NULL, NULL, NULL);
114 file_list = g_list_append (file_list, utf8_filename);
116 g_strfreev (remaining_args);
117 remaining_args = NULL;
120 /* initialize components */
126 /* now print the files */
127 for (p = file_list; p; p = p->next) {
128 g_print ("LABEL FILE = %s\n", (gchar *) p->data);
129 label = gl_xml_label_open (p->data, &status);
132 if ( status == XML_LABEL_OK ) {
135 merge = gl_label_get_merge (label);
137 gl_merge_set_src(merge, input);
138 gl_label_set_merge(label, merge);
141 _("cannot perform document merge with glabels file %s\n"),
145 abs_fn = gl_util_make_absolute ( output );
146 print_op = gl_print_op_new_batch (label,
155 gtk_print_operation_run (GTK_PRINT_OPERATION (print_op),
156 GTK_PRINT_OPERATION_ACTION_EXPORT,
160 g_object_unref (label);
163 fprintf ( stderr, _("cannot open glabels file %s\n"),
168 g_list_free (file_list);