3 * Copyright (C) 2001-2009 Jim Evins <evins@snaught.com>.
5 * This file is part of gLabels.
7 * gLabels is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
12 * gLabels is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with gLabels. If not, see <http://www.gnu.org/licenses/>.
23 #include <glib/gi18n.h>
27 #include <libglabels.h>
28 #include "merge-init.h"
29 #include "template-history.h"
30 #include "xml-label.h"
33 #include "file-util.h"
37 /*============================================*/
39 /*============================================*/
40 static gchar *output = "output.pdf";
41 static gint n_copies = 1;
42 static gint n_sheets = 1;
43 static gint first = 1;
44 static gboolean outline_flag = FALSE;
45 static gboolean reverse_flag = FALSE;
46 static gboolean crop_marks_flag = FALSE;
47 static gchar *input = NULL;
48 static gchar **remaining_args = NULL;
50 static GOptionEntry option_entries[] = {
51 {"output", 'o', 0, G_OPTION_ARG_STRING, &output,
52 N_("set output filename (default=\"output.pdf\")"), N_("filename")},
53 {"sheets", 's', 0, G_OPTION_ARG_INT, &n_sheets,
54 N_("number of sheets (default=1)"), N_("sheets")},
55 {"copies", 'c', 0, G_OPTION_ARG_INT, &n_copies,
56 N_("number of copies (default=1)"), N_("copies")},
57 {"first", 'f', 0, G_OPTION_ARG_INT, &first,
58 N_("first label on first sheet (default=1)"), N_("first")},
59 {"outline", 'l', 0, G_OPTION_ARG_NONE, &outline_flag,
60 N_("print outlines (to test printer alignment)"), NULL},
61 {"reverse", 'r', 0, G_OPTION_ARG_NONE, &reverse_flag,
62 N_("print in reverse (i.e. a mirror image)"), NULL},
63 {"cropmarks", 'C', 0, G_OPTION_ARG_NONE, &crop_marks_flag,
64 N_("print crop marks"), NULL},
65 {"input", 'i', 0, G_OPTION_ARG_STRING, &input,
66 N_("input file for merging"), N_("filename")},
67 { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY,
68 &remaining_args, NULL, N_("[FILE...]") },
74 /*****************************************************************************/
76 /*****************************************************************************/
78 main (int argc, char **argv)
80 GOptionContext *option_context;
81 GList *p, *file_list = NULL;
83 glLabel *label = NULL;
84 glMerge *merge = NULL;
85 const lglTemplate *template;
86 lglTemplateFrame *frame;
87 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 (NULL);
97 g_option_context_set_summary (option_context,
98 _("Print files created with gLabels."));
99 g_option_context_add_main_entries (option_context, option_entries, GETTEXT_PACKAGE);
102 /* Initialize minimal gnome program */
103 gtk_init (&argc, &argv);
104 if (!g_option_context_parse (option_context, &argc, &argv, &error))
106 g_print(_("%s\nRun '%s --help' to see a full list of available command line options.\n"),
107 error->message, argv[0]);
108 g_error_free (error);
113 /* create file list */
114 if (remaining_args != NULL) {
117 num_args = g_strv_length (remaining_args);
118 for (i = 0; i < num_args; ++i) {
119 utf8_filename = g_filename_to_utf8 (remaining_args[i], -1, NULL, NULL, NULL);
121 file_list = g_list_append (file_list, utf8_filename);
123 g_strfreev (remaining_args);
124 remaining_args = NULL;
127 /* initialize components */
132 gl_template_history_init ();
134 /* now print the files */
135 for (p = file_list; p; p = p->next) {
136 g_print ("LABEL FILE = %s\n", (gchar *) p->data);
137 label = gl_xml_label_open (p->data, &status);
140 if ( status == XML_LABEL_OK ) {
142 merge = gl_label_get_merge (label);
145 gl_merge_set_src(merge, input);
146 gl_label_set_merge(label, merge, FALSE);
149 _("cannot perform document merge with glabels file %s\n"),
153 abs_fn = gl_file_util_make_absolute ( output );
154 template = gl_label_get_template (label);
155 frame = (lglTemplateFrame *)template->frames->data;
157 print_op = gl_print_op_new (label);
158 gl_print_op_set_filename (print_op, abs_fn);
159 gl_print_op_set_n_copies (print_op, n_copies);
160 gl_print_op_set_first (print_op, first);
161 gl_print_op_set_outline_flag (print_op, outline_flag);
162 gl_print_op_set_reverse_flag (print_op, reverse_flag);
163 gl_print_op_set_crop_marks_flag (print_op, crop_marks_flag);
166 gl_print_op_set_n_sheets (print_op,
167 ceil ((double)(first-1 + n_copies * gl_merge_get_record_count(merge))
168 / lgl_template_frame_get_n_labels (frame)));
172 gl_print_op_set_n_sheets (print_op, n_sheets);
173 gl_print_op_set_last (print_op,
174 lgl_template_frame_get_n_labels (frame));
176 gtk_print_operation_run (GTK_PRINT_OPERATION (print_op),
177 GTK_PRINT_OPERATION_ACTION_EXPORT,
181 g_object_unref (label);
184 fprintf ( stderr, _("cannot open glabels file %s\n"),
189 g_list_free (file_list);
198 * Local Variables: -- emacs
200 * c-basic-offset: 8 -- emacs
201 * tab-width: 8 -- emacs
202 * indent-tabs-mode: nil -- emacs