]> git.sur5r.net Git - glabels/blob - src/glabels-batch.c
Imported Upstream version 2.2.8
[glabels] / 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 "prefs.h"
37 #include "debug.h"
38
39 /*============================================*/
40 /* Private globals                            */
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;
51
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...]") },
71         { NULL }
72 };
73
74
75 \f
76 /*****************************************************************************/
77 /* Main                                                                      */
78 /*****************************************************************************/
79 int
80 main (int argc, char **argv)
81 {
82         GOptionContext    *option_context;
83         GnomeProgram      *program;
84         GList             *p, *file_list = NULL;
85         gchar             *abs_fn;
86         glLabel           *label = NULL;
87         glMerge           *merge = NULL;
88         glXMLLabelStatus   status;
89         glPrintOp         *print_op;
90         gchar             *utf8_filename;
91
92         bindtextdomain (GETTEXT_PACKAGE, GLABELS_LOCALEDIR);
93         bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
94         textdomain (GETTEXT_PACKAGE);
95
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);
98
99
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,
105                                       NULL);
106
107         /* create file list */
108         if (remaining_args != NULL) {
109                 gint i, num_args;
110
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);
114                         if (utf8_filename)
115                                 file_list = g_list_append (file_list, utf8_filename);
116                 }
117                 g_strfreev (remaining_args);
118                 remaining_args = NULL;
119         }
120
121         /* initialize components */
122         gl_debug_init ();
123         gl_merge_init ();
124         lgl_db_init ();
125         gl_prefs_init ();
126
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);
131
132
133                 if ( status == XML_LABEL_OK ) {
134
135                         if (input != NULL) {
136                                 merge = gl_label_get_merge (label);
137                                 if (merge != NULL) {
138                                         gl_merge_set_src(merge, input);
139                                         gl_label_set_merge(label, merge);
140                                 } else {
141                                         fprintf ( stderr,
142                                                   _("cannot perform document merge with glabels file %s\n"),
143                                                   (char *)p->data );
144                                 }
145                         }
146                         abs_fn = gl_util_make_absolute ( output );
147                         print_op = gl_print_op_new_batch (label,
148                                                           abs_fn,
149                                                           n_sheets,
150                                                           n_copies,
151                                                           first,
152                                                           outline_flag,
153                                                           reverse_flag,
154                                                           crop_marks_flag);
155
156                         gtk_print_operation_run (GTK_PRINT_OPERATION (print_op),
157                                                  GTK_PRINT_OPERATION_ACTION_EXPORT,
158                                                  NULL,
159                                                  NULL);
160
161                         g_object_unref (label);
162                 }
163                 else {
164                         fprintf ( stderr, _("cannot open glabels file %s\n"),
165                                   (char *)p->data );
166                 }
167         }
168
169         g_list_free (file_list);
170
171         return 0;
172 }
173