]> git.sur5r.net Git - glabels/blob - glabels2/src/glabels-batch.c
1bad5d6e1d41216f27a7a834a3adef0a4fff7115
[glabels] / glabels2 / src / glabels-batch.c
1 /*
2  *  (GLABELS) Label and Business Card Creation program for GNOME
3  *
4  *  glabels.c: main program module
5  *
6  *  Copyright (C) 2001  Jim Evins <evins@snaught.com>.
7  *
8  *  This program is free software; you can redistribute it and/or modify
9  *  it under the terms of the GNU General Public License as published by
10  *  the Free Software Foundation; either version 2 of the License, or
11  *  (at your option) any later version.
12  *
13  *  This program is distributed in the hope that it will be useful,
14  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  *  GNU General Public License for more details.
17  *
18  *  You should have received a copy of the GNU General Public License
19  *  along with this program; if not, write to the Free Software
20  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
21  */
22
23 #include <config.h>
24
25 #include <gnome.h>
26 #include <libgnomeprint/gnome-print-master.h>
27
28 #include "merge.h"
29 #include "xml-label.h"
30 #include "template.h"
31 #include "print.h"
32 #include "util.h"
33
34 /*============================================*/
35 /* Private globals                            */
36 /*============================================*/
37 static gboolean help_flag    = FALSE;
38 static gboolean version_flag = FALSE;
39 static gchar    *output      = "output.ps";
40 static gint     n_copies     = 1;
41 static gint     n_sheets     = 1;
42 static gboolean outline_flag = FALSE;
43 static gboolean reverse_flag = FALSE;
44
45 static struct poptOption options[] = {
46         {"help", 'h', POPT_ARG_NONE, &help_flag, 1,
47          N_("print this message"), NULL},
48         {"version", 'v', POPT_ARG_NONE, &version_flag, 0,
49          N_("print the version of glabels-batch being used"), NULL},
50         {"output", 'o', POPT_ARG_STRING, &output, 0,
51          N_("set output filename (default=\"output.ps\")"), N_("filename")},
52         {"sheets", 's', POPT_ARG_INT, &n_sheets, 0,
53          N_("number of sheets (default=1)"), N_("sheets")},
54         {"copies", 'c', POPT_ARG_INT, &n_copies, 0,
55          N_("number of copies (default=1)"), N_("copies")},
56         {"outline", 'l', POPT_ARG_NONE, &outline_flag, 0,
57          N_("print outlines (to test printer alignment)"), NULL},
58         {"reverse", 'r', POPT_ARG_NONE, &reverse_flag, 0,
59          N_("print in reverse (i.e. a mirror image)"), NULL},
60         {NULL, '\0', 0, NULL, 0, NULL, NULL}
61 };
62
63
64 \f
65 /*****************************************************************************/
66 /* Main                                                                      */
67 /*****************************************************************************/
68 int
69 main (int argc, char **argv)
70 {
71         GnomeProgram      *program;
72         poptContext        pctx;
73         gchar            **args;
74         gint               rc;
75         GSList            *p, *file_list = NULL;
76         gint               n_files;
77         GnomePrintMaster  *master = NULL;
78         gchar             *abs_fn;
79         GnomePrintConfig  *config = NULL;
80         glLabel           *label = NULL;
81         glXMLLabelStatus   status;
82
83         bindtextdomain (GETTEXT_PACKAGE, GLABELS_LOCALEDIR);
84         textdomain (GETTEXT_PACKAGE);
85
86         /* Initialize minimal gnome program */
87         program = gnome_program_init ("glabels-batch", VERSION,
88                                       LIBGNOME_MODULE, 1, argv,
89                                       GNOME_PROGRAM_STANDARD_PROPERTIES,
90                                       NULL);
91
92         /* argument parsing */
93         pctx = poptGetContext (NULL, argc, (const char **)argv, options, 0);
94         poptSetOtherOptionHelp (pctx, _("[OPTION...] GLABELS_FILE...") );
95         if ( (rc = poptGetNextOpt(pctx)) < -1 ) {
96                 fprintf (stderr, "%s: %s\n",
97                          poptBadOption (pctx,0), poptStrerror(rc));
98                 poptPrintUsage (pctx, stderr, 0);
99                 return -1;
100         }
101         if ( version_flag ) {
102                 fprintf ( stderr, "glabels-batch %s\n", VERSION );
103         }
104         if ( help_flag ) {
105                 poptPrintHelp (pctx, stderr, 0);
106                 return -1;
107         }
108         args = (char **) poptGetArgs (pctx);
109         for (n_files = 0; args && args[n_files]; n_files++) {
110                 file_list = g_slist_append (file_list, args[n_files]);
111         }
112         if ( !n_files ) {
113                 fprintf ( stderr, _("missing glabels file\n") );
114                 poptPrintHelp (pctx, stderr, 0);
115                 return -1;
116         }
117         poptFreeContext (pctx);
118
119         /* initialize components */
120         gl_merge_init ();
121         gl_template_init ();
122
123         /* now print the files */
124         for (p = file_list; p; p = p->next) {
125                 g_print ("LABEL FILE = %s\n", p->data);
126                 label = gl_xml_label_open (p->data, &status);
127                 if ( status == XML_LABEL_OK ) {
128
129                         if ( master == NULL ) {
130                                 master = gnome_print_master_new ();
131                         }
132
133                         gl_print_batch (master, label, n_sheets, n_copies,
134                                         outline_flag, reverse_flag);
135
136                         g_object_unref (label);
137                 }
138                 else {
139                         fprintf ( stderr, _("cannot open glabels file %s\n"),
140                                   (char *)p->data );
141                 }
142         }
143         if ( master != NULL ) {
144
145                 abs_fn = gl_util_make_absolute ( output );
146                 gnome_print_master_print_to_file (master, abs_fn);
147                 g_free( abs_fn );
148
149                 gnome_print_master_close (master);
150                 gnome_print_master_print (master);
151
152                 g_object_unref (master);
153         }
154
155         g_slist_free (file_list);
156
157         return 0;
158 }
159