]> git.sur5r.net Git - glabels/blob - glabels2/src/glabels-batch.c
61e9c9765abb3a5434bbef76791b80926519fa07
[glabels] / glabels2 / src / glabels-batch.c
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
2
3 /*
4  *  (GLABELS) Label and Business Card Creation program for GNOME
5  *
6  *  glabels.c: main program module
7  *
8  *  Copyright (C) 2001  Jim Evins <evins@snaught.com>.
9  *
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.
14  *
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.
19  *
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
23  */
24
25 #include <config.h>
26
27 #include <glib/gi18n.h>
28 #include <libgnome/libgnome.h>
29
30 #include "merge-init.h"
31 #include "xml-label.h"
32 #include "print.h"
33 #include "print-op.h"
34 #include <libglabels/db.h>
35 #include "util.h"
36 #include "debug.h"
37
38 /*============================================*/
39 /* Private globals                            */
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;
50
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...]") },
70         { NULL }
71 };
72
73
74 \f
75 /*****************************************************************************/
76 /* Main                                                                      */
77 /*****************************************************************************/
78 int
79 main (int argc, char **argv)
80 {
81         GOptionContext    *option_context;
82         GnomeProgram      *program;
83         GList             *p, *file_list = NULL;
84         gchar             *abs_fn;
85         glLabel           *label = NULL;
86         glMerge           *merge = NULL;
87         glXMLLabelStatus   status;
88         glPrintOp         *print_op;
89         gchar             *utf8_filename;
90
91         bindtextdomain (GETTEXT_PACKAGE, GLABELS_LOCALEDIR);
92         bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
93         textdomain (GETTEXT_PACKAGE);
94
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);
97
98
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,
104                                       NULL);
105
106         /* create file list */
107         if (remaining_args != NULL) {
108                 gint i, num_args;
109
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);
113                         if (utf8_filename)
114                                 file_list = g_list_append (file_list, utf8_filename);
115                 }
116                 g_strfreev (remaining_args);
117                 remaining_args = NULL;
118         }
119
120         /* initialize components */
121         gl_debug_init ();
122         gl_merge_init ();
123         lgl_db_init ();
124         gl_prefs_init ();
125
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);
130
131
132                 if ( status == XML_LABEL_OK ) {
133
134                         if (input != NULL) {
135                                 merge = gl_label_get_merge (label);
136                                 if (merge != NULL) {
137                                         gl_merge_set_src(merge, input);
138                                         gl_label_set_merge(label, merge);
139                                 } else {
140                                         fprintf ( stderr,
141                                                   _("cannot perform document merge with glabels file %s\n"),
142                                                   (char *)p->data );
143                                 }
144                         }
145                         abs_fn = gl_util_make_absolute ( output );
146                         print_op = gl_print_op_new_batch (label,
147                                                           abs_fn,
148                                                           n_sheets,
149                                                           n_copies,
150                                                           first,
151                                                           outline_flag,
152                                                           reverse_flag,
153                                                           crop_marks_flag);
154
155                         gtk_print_operation_run (GTK_PRINT_OPERATION (print_op),
156                                                  GTK_PRINT_OPERATION_ACTION_EXPORT,
157                                                  NULL,
158                                                  NULL);
159
160                         g_object_unref (label);
161                 }
162                 else {
163                         fprintf ( stderr, _("cannot open glabels file %s\n"),
164                                   (char *)p->data );
165                 }
166         }
167
168         g_list_free (file_list);
169
170         return 0;
171 }
172