~ubuntu-branches/ubuntu/karmic/photoprint/karmic

« back to all changes in this revision

Viewing changes to photoprint.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Milan Zamazal
  • Date: 2007-05-01 16:32:13 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20070501163213-ni1933khtg9fdvn5
Tags: 0.3.5-2
Move to unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * PhotoPrint
3
 
 * Copyright (c) 2004-2006 by Alastair M. Robinson
4
 
 * Distributed under the terms of the GNU General Public License -
5
 
 * see the file named "COPYING" for more details.
6
 
 *
7
 
 */
8
 
 
9
 
#include <iostream>
10
 
 
11
 
#include <getopt.h>
12
 
#include <stdio.h>
13
 
#include <stdlib.h>
14
 
#include <gtk/gtk.h>
15
 
 
16
 
#include "support/configdb.h"
17
 
#include "photoprint_state.h"
18
 
 
19
 
#include "pp_mainwindow.h"
20
 
#include "support/progressbar.h"
21
 
#include "dialogs.h"
22
 
#include "support/generaldialogs.h"
23
 
#include "splashscreen/splashscreen.h"
24
 
#include "util.h"
25
 
 
26
 
#include "config.h"
27
 
 
28
 
using namespace std;
29
 
 
30
 
bool ParseOptions(int argc,char *argv[],char **presetname)
31
 
{
32
 
        int batchmode=false;
33
 
        static struct option long_options[] =
34
 
        {
35
 
                {"help",no_argument,NULL,'h'},
36
 
                {"version",no_argument,NULL,'v'},
37
 
                {"preset",required_argument,NULL,'p'},
38
 
                {"batch",no_argument,NULL,'b'},
39
 
                {0, 0, 0, 0}
40
 
        };
41
 
 
42
 
        while(1)
43
 
        {
44
 
                int c;
45
 
                c = getopt_long(argc,argv,"hvp:b",long_options,NULL);
46
 
                if(c==-1)
47
 
                        break;
48
 
                switch (c)
49
 
                {
50
 
                        case 'h':
51
 
                                printf("Usage: %s [options] image1 [image2] ... \n",argv[0]);
52
 
                                printf("\t -h --help\t\tdisplay this message\n");
53
 
                                printf("\t -v --version\t\tdisplay version\n");
54
 
                                printf("\t -p --preset\t\tread a specific preset file\n");
55
 
                                printf("\t -b --batch\t\trun without user interface\n");
56
 
                                throw 0;
57
 
                                break;
58
 
                        case 'v':
59
 
                                printf("%s\n",PACKAGE_STRING);
60
 
                                throw 0;
61
 
                                break;
62
 
                        case 'p':
63
 
                                *presetname=optarg;
64
 
                                break;
65
 
                        case 'b':
66
 
                                batchmode=true;
67
 
                                break;
68
 
                }
69
 
        }
70
 
        return(batchmode);
71
 
}
72
 
 
73
 
 
74
 
static void destroy( GtkWidget *widget,
75
 
                     gpointer   data )
76
 
{
77
 
    gtk_main_quit ();
78
 
}
79
 
 
80
 
 
81
 
int main(int argc,char **argv)
82
 
{
83
 
        try
84
 
        {
85
 
                cerr << "Photoprint starting..." << endl;
86
 
                gboolean have_gtk=false;
87
 
                char *presetname=NULL;
88
 
 
89
 
                bool batchmode=ParseOptions(argc,argv,&presetname);
90
 
                if(!batchmode)
91
 
                        have_gtk=gtk_init_check (&argc, &argv);
92
 
 
93
 
                SplashScreen *splash=NULL;
94
 
                if(have_gtk)
95
 
                {
96
 
                        splash=new SplashScreen;
97
 
                        splash->SetMessage("Initializing...");
98
 
                }
99
 
 
100
 
                cerr << "SplashScreen displayed..." << endl;
101
 
 
102
 
                PhotoPrint_State state(batchmode);
103
 
 
104
 
                cerr << "State created..." << endl;
105
 
 
106
 
                if(presetname)
107
 
                        state.SetFilename(presetname);
108
 
                cerr << "Set initial filename" << endl;
109
 
 
110
 
                if(have_gtk)
111
 
                        splash->SetMessage("Checking .photoprint directory...");
112
 
 
113
 
                CheckSettingsDir(".photoprint");
114
 
 
115
 
                if(have_gtk)
116
 
                        splash->SetMessage("Loading preset...");
117
 
                state.ParseFile();
118
 
 
119
 
                if(have_gtk)
120
 
                {
121
 
                        splash->SetMessage("Creating layout...");
122
 
                        delete splash;
123
 
                }
124
 
 
125
 
                state.NewLayout();
126
 
 
127
 
                if(batchmode)
128
 
                {
129
 
                        try
130
 
                        {
131
 
                                cerr << "Running in batch mode" << endl;
132
 
                                if(argc>optind)
133
 
                                {
134
 
                                        for(int i=optind;i<argc;++i)
135
 
                                        {
136
 
                                                cerr << "Adding file: " << argv[i] << endl;
137
 
                                                state.layout->AddImage(argv[i]);
138
 
                                        }
139
 
                                        Progress p;
140
 
                                        state.layout->Print(&p);
141
 
                                }
142
 
                        }
143
 
                        catch(const char *err)
144
 
                        {
145
 
                                cerr << "Error: " << err << endl;
146
 
                        }
147
 
                }
148
 
                else
149
 
                {
150
 
                        try
151
 
                        {
152
 
                                GtkWidget *mainwindow;
153
 
                                mainwindow = pp_mainwindow_new(&state);
154
 
                                g_signal_connect (G_OBJECT (mainwindow), "destroy",
155
 
                                            G_CALLBACK (destroy), NULL);
156
 
                                gtk_widget_show (mainwindow);
157
 
                
158
 
                                if(argc>optind)
159
 
                                {
160
 
                                        ProgressBar p("Loading images...",true,mainwindow);
161
 
                                        int lastpage=0;
162
 
                                        for(int i=optind;i<argc;++i)
163
 
                                        {
164
 
                                                if(!p.DoProgress(i-optind,argc-optind))
165
 
                                                        break;
166
 
                                                lastpage=state.layout->AddImage(argv[i]);
167
 
                                        }
168
 
                                        state.layout->SetCurrentPage(lastpage);
169
 
                                }
170
 
        
171
 
                                pp_mainwindow_refresh(PP_MAINWINDOW(mainwindow));
172
 
        
173
 
                                gtk_main ();
174
 
                        }
175
 
                        catch (const char *err)
176
 
                        {
177
 
                                ErrorMessage_Dialog(err);
178
 
                        }
179
 
                }
180
 
        }
181
 
        catch(const char *err)
182
 
        {
183
 
                cerr << "Error: " << err << endl;
184
 
        }
185
 
        catch(int retcode)
186
 
        {
187
 
                return(retcode);
188
 
        }
189
 
        return(0);
190
 
}
 
1
/*
 
2
 * PhotoPrint
 
3
 * Copyright (c) 2004-2006 by Alastair M. Robinson
 
4
 * Distributed under the terms of the GNU General Public License -
 
5
 * see the file named "COPYING" for more details.
 
6
 *
 
7
 */
 
8
 
 
9
#include <iostream>
 
10
 
 
11
#include <getopt.h>
 
12
#include <stdio.h>
 
13
#include <stdlib.h>
 
14
#include <locale.h>
 
15
#include <gtk/gtk.h>
 
16
#include <gutenprint/gutenprint.h>
 
17
 
 
18
#include "config.h"
 
19
#include "gettext.h"
 
20
 
 
21
 
 
22
#include "support/configdb.h"
 
23
#include "photoprint_state.h"
 
24
 
 
25
#include "pp_mainwindow.h"
 
26
#include "support/progressbar.h"
 
27
#include "dialogs.h"
 
28
#include "support/generaldialogs.h"
 
29
#include "splashscreen/splashscreen.h"
 
30
#include "profilemanager/profileselector.h"
 
31
#include "profilemanager/intentselector.h"
 
32
#include "support/patheditor.h"
 
33
#include "util.h"
 
34
 
 
35
 
 
36
#define _(x) gettext(x)
 
37
#define N_(x) gettext_noop(x)
 
38
 
 
39
using namespace std;
 
40
 
 
41
bool ParseOptions(int argc,char *argv[],char **presetname)
 
42
{
 
43
        int batchmode=false;
 
44
        static struct option long_options[] =
 
45
        {
 
46
                {"help",no_argument,NULL,'h'},
 
47
                {"version",no_argument,NULL,'v'},
 
48
                {"preset",required_argument,NULL,'p'},
 
49
                {"batch",no_argument,NULL,'b'},
 
50
                {0, 0, 0, 0}
 
51
        };
 
52
 
 
53
        while(1)
 
54
        {
 
55
                int c;
 
56
                c = getopt_long(argc,argv,"hvp:b",long_options,NULL);
 
57
                if(c==-1)
 
58
                        break;
 
59
                switch (c)
 
60
                {
 
61
                        case 'h':
 
62
                                printf("Usage: %s [options] image1 [image2] ... \n",argv[0]);
 
63
                                printf("\t -h --help\t\tdisplay this message\n");
 
64
                                printf("\t -v --version\t\tdisplay version\n");
 
65
                                printf("\t -p --preset\t\tread a specific preset file\n");
 
66
                                printf("\t -b --batch\t\trun without user interface\n");
 
67
                                throw 0;
 
68
                                break;
 
69
                        case 'v':
 
70
                                printf("%s\n",PACKAGE_STRING);
 
71
                                throw 0;
 
72
                                break;
 
73
                        case 'p':
 
74
                                *presetname=optarg;
 
75
                                break;
 
76
                        case 'b':
 
77
                                batchmode=true;
 
78
                                break;
 
79
                }
 
80
        }
 
81
        return(batchmode);
 
82
}
 
83
 
 
84
 
 
85
static void destroy( GtkWidget *widget,
 
86
                     gpointer   data )
 
87
{
 
88
    gtk_main_quit ();
 
89
}
 
90
 
 
91
 
 
92
int main(int argc,char **argv)
 
93
{
 
94
        cerr << "Photoprint starting..." << endl;
 
95
        gboolean have_gtk=false;
 
96
        char *presetname=NULL;
 
97
 
 
98
        stp_init();
 
99
 
 
100
        bool batchmode=ParseOptions(argc,argv,&presetname);
 
101
        if(!batchmode)
 
102
                have_gtk=gtk_init_check (&argc, &argv);
 
103
 
 
104
        if(have_gtk)
 
105
                gtk_set_locale();
 
106
        else
 
107
                setlocale(LC_ALL,"");
 
108
 
 
109
        cerr << "Setting up gettext... " << PACKAGE << ", " << LOCALEDIR << endl;
 
110
        bindtextdomain(PACKAGE,LOCALEDIR);
 
111
        bind_textdomain_codeset(PACKAGE, "UTF-8");
 
112
        textdomain(PACKAGE);
 
113
 
 
114
        try
 
115
        {
 
116
                SplashScreen *splash=NULL;
 
117
                if(have_gtk)
 
118
                {
 
119
                        splash=new SplashScreen;
 
120
                        splash->SetMessage(_("Initializing..."));
 
121
                }
 
122
 
 
123
                PhotoPrint_State state(batchmode);
 
124
 
 
125
                cerr << "State created..." << endl;
 
126
 
 
127
                if(presetname)
 
128
                        state.SetFilename(presetname);
 
129
                cerr << "Set initial filename" << endl;
 
130
 
 
131
                if(have_gtk)
 
132
                        splash->SetMessage(_("Checking .photoprint directory..."));
 
133
 
 
134
                CheckSettingsDir(".photoprint");
 
135
 
 
136
                if(have_gtk)
 
137
                        splash->SetMessage(_("Loading preset..."));
 
138
                state.ParseFile();
 
139
 
 
140
                if(have_gtk)
 
141
                {
 
142
                        splash->SetMessage(_("Creating layout..."));
 
143
                        delete splash;
 
144
                }
 
145
 
 
146
                cerr << "Translation test: " << _("Initializing...") << endl;
 
147
 
 
148
                state.NewLayout();
 
149
 
 
150
                cerr << "Translation test: " << _("Initializing...") << endl;
 
151
 
 
152
                if(batchmode)
 
153
                {
 
154
                        try
 
155
                        {
 
156
                                cerr << "Running in batch mode" << endl;
 
157
                                if(argc>optind)
 
158
                                {
 
159
                                        for(int i=optind;i<argc;++i)
 
160
                                        {
 
161
                                                cerr << "Adding file: " << argv[i] << endl;
 
162
                                                state.layout->AddImage(argv[i]);
 
163
                                        }
 
164
                                        Progress p;
 
165
                                        state.layout->Print(&p);
 
166
                                }
 
167
                        }
 
168
                        catch(const char *err)
 
169
                        {
 
170
                                cerr << "Error: " << err << endl;
 
171
                        }
 
172
                }
 
173
                else
 
174
                {
 
175
                        try
 
176
                        {
 
177
                                GtkWidget *mainwindow;
 
178
                cerr << "Translation test: " << _("Initializing...") << endl;
 
179
                                mainwindow = pp_mainwindow_new(&state);
 
180
                                g_signal_connect (G_OBJECT (mainwindow), "destroy",
 
181
                                            G_CALLBACK (destroy), NULL);
 
182
                                gtk_widget_show (mainwindow);
 
183
 
 
184
                cerr << "Translation test: " << _("Initializing...") << endl;
 
185
                
 
186
                                if(argc>optind)
 
187
                                {
 
188
                                        ProgressBar p(_("Loading images..."),true,mainwindow);
 
189
                                        int lastpage=0;
 
190
                                        for(int i=optind;i<argc;++i)
 
191
                                        {
 
192
                                                if(!p.DoProgress(i-optind,argc-optind))
 
193
                                                        break;
 
194
                                                lastpage=state.layout->AddImage(argv[i]);
 
195
                                        }
 
196
                                        state.layout->SetCurrentPage(lastpage);
 
197
                                }
 
198
        
 
199
                cerr << "Translation test: " << _("Initializing...") << endl;
 
200
 
 
201
                                pp_mainwindow_refresh(PP_MAINWINDOW(mainwindow));
 
202
 
 
203
                cerr << "Translation test: " << _("Initializing...") << endl;
 
204
        
 
205
                                gtk_main ();
 
206
                        }
 
207
                        catch (const char *err)
 
208
                        {
 
209
                                ErrorMessage_Dialog(err);
 
210
                        }
 
211
                }
 
212
        }
 
213
        catch(const char *err)
 
214
        {
 
215
                cerr << "Error: " << err << endl;
 
216
        }
 
217
        catch(int retcode)
 
218
        {
 
219
                return(retcode);
 
220
        }
 
221
        return(0);
 
222
}