~vcs-imports/bibletime/trunk

« back to all changes in this revision

Viewing changes to bibletime/main.cpp

  • Committer: mgruner
  • Date: 2007-05-08 15:51:07 UTC
  • Revision ID: vcs-imports@canonical.com-20070508155107-0rj7jdmm5ivf8685
-imported source and data files to new svn module
-this is where KDE4-based development will take place

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*********
 
2
*
 
3
* This file is part of BibleTime's source code, http://www.bibletime.info/.
 
4
*
 
5
* Copyright 1999-2006 by the BibleTime developers.
 
6
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
 
7
*
 
8
**********/
 
9
 
 
10
 
 
11
 
 
12
/* $Header: /cvsroot/bibletime/bibletime/bibletime/main.cpp,v 1.143 2007/04/02 21:53:48 joachim Exp $ */
 
13
/* $Revision: 1.143 $ */
 
14
 
 
15
//standard includes
 
16
#include <stdlib.h>
 
17
#include <stdio.h>
 
18
#include <signal.h>
 
19
 
 
20
//own includes
 
21
#include "bibletimeapp.h"
 
22
#include "bibletime.h"
 
23
#include "config.h"
 
24
 
 
25
//util includes
 
26
#include "util/scoped_resource.h"
 
27
#include "util/cresmgr.h"
 
28
 
 
29
//frontend includes
 
30
#include "frontend/kstartuplogo.h"
 
31
#include "frontend/cbtconfig.h"
 
32
 
 
33
//Qt includes
 
34
#include <qdir.h>
 
35
 
 
36
//KDE includes
 
37
#include <kcmdlineargs.h>
 
38
#include <kcrash.h>
 
39
#include <kglobal.h>
 
40
#include <kapplication.h>
 
41
#include <kstandarddirs.h>
 
42
#include <kinstance.h>
 
43
#include <kaboutdata.h>
 
44
#include <klocale.h>
 
45
 
 
46
bool showDebugMessages = false;
 
47
BibleTime* bibletime_ptr = 0;
 
48
 
 
49
void myMessageOutput( QtMsgType type, const char *msg ) {
 
50
        //we use this messagehandler to switch debugging off in final releases
 
51
        switch ( type ) {
 
52
                case QtDebugMsg:
 
53
                        if (showDebugMessages) { //only show messages if they are enabled!
 
54
                                fprintf( stderr,"(BibleTime %s) Debug: %s\n",VERSION, msg );
 
55
                        }
 
56
                        break;
 
57
                case QtWarningMsg:
 
58
                        //if (showDebugMessages) //comment out for releases so users don't get our debug warnings
 
59
                        fprintf( stderr,"(BibleTime %s) WARNING: %s\n",VERSION, msg );
 
60
                        break;
 
61
                case QtFatalMsg:
 
62
                        fprintf( stderr,"(BibleTime %s) _FATAL_: %s\nPlease contact info@bibletime.de and report this bug!",VERSION, msg );
 
63
                        abort(); // dump core on purpose
 
64
        }
 
65
}
 
66
 
 
67
extern "C" {
 
68
        static void setSignalHandler(void (*handler)(int));
 
69
 
 
70
        // Crash recovery signal handler
 
71
        static void signalHandler(int sigId) {
 
72
                setSignalHandler(SIG_DFL);
 
73
                fprintf(stderr, "*** BibleTime got signal %d (Exiting)\n", sigId);
 
74
                // try to cleanup all windows
 
75
                if (CBTConfig::get(CBTConfig::crashedLastTime)) {
 
76
                        //crashed this time and the execution before this one, probably a bug which occurs every time
 
77
                        CBTConfig::set(CBTConfig::crashedTwoTimes, true);
 
78
                }
 
79
                else {
 
80
                        //try to restore next time.
 
81
                        CBTConfig::set(CBTConfig::crashedLastTime, true);
 
82
                }
 
83
                if (bibletime_ptr) {
 
84
                        bibletime_ptr->saveSettings();
 
85
                        fprintf(stderr, "*** Saving seemed to be successful. If restoring does not work on next startup please use the option --ignore-session\n");
 
86
                }
 
87
                ::exit(-1); //exit BibleTime
 
88
        }
 
89
 
 
90
        // Crash recovery signal handler
 
91
        static void crashHandler(int sigId) {
 
92
                setSignalHandler(SIG_DFL);
 
93
                fprintf(stderr, "*** BibleTime got signal %d (Crashing). Trying to save settings.\n", sigId);
 
94
                if (CBTConfig::get(CBTConfig::crashedLastTime)) {
 
95
                        // crashed this time and the execution before this one,
 
96
                        // probably a bug which occurs every time
 
97
                        CBTConfig::set(CBTConfig::crashedTwoTimes, true);
 
98
                }
 
99
                else {
 
100
                        //try to restore next time.
 
101
                        CBTConfig::set(CBTConfig::crashedLastTime, true);
 
102
                }
 
103
                if (bibletime_ptr) {
 
104
                        bibletime_ptr->saveSettings();
 
105
                        fprintf(stderr, "*** Saving seemed to be successful. If restoring does not work on next startup please use the option --ignore-session\n");
 
106
                }
 
107
                // Return to DrKonqi.
 
108
        }
 
109
 
 
110
        static void setSignalHandler(void (*handler)(int)) {
 
111
                signal(SIGKILL, handler);
 
112
                signal(SIGTERM, handler);
 
113
                signal(SIGHUP,  handler);
 
114
                KCrash::setEmergencySaveFunction(crashHandler);
 
115
        }
 
116
}
 
117
 
 
118
int main(int argc, char* argv[]) {
 
119
        qInstallMsgHandler( myMessageOutput );
 
120
 
 
121
        //create about data for this application
 
122
        static KCmdLineOptions options[] =
 
123
                {
 
124
                        {"debug", I18N_NOOP("Enable debug messages"),0},
 
125
                        {"ignore-session", I18N_NOOP("Ignore the startup session that was saved when BibleTime was closed the last time."),0},
 
126
                        {"open-default-bible <key>", I18N_NOOP("Open the standard Bible with the given key. Use <random> to open at a random position."),0},
 
127
                        //{"install-local <path>", I18N_NOOP("Open the SwordSetup dialog to install works from <path>"),0},
 
128
                        {0,0,0}
 
129
                };
 
130
 
 
131
        KAboutData aboutData(
 
132
                PACKAGE,
 
133
                "BibleTime",
 
134
                VERSION,
 
135
                I18N_NOOP("Bible study tool for KDE"),
 
136
                KAboutData::License_GPL_V2,
 
137
                I18N_NOOP("(c)1999-2007, The BibleTime Team"),
 
138
                I18N_NOOP("BibleTime is an easy to use but powerful Bible study tool for KDE.\n\nWe are looking for developers and translators.\nIf you'd like to join our team, please send an email to info@bibletime.info."),
 
139
                "http://www.bibletime.info/",
 
140
                "info@bibletime.info"
 
141
        );
 
142
 
 
143
        /***********************************************
 
144
        *    Active developers (sorted by last name)   *
 
145
        ************************************************/
 
146
        // Project coordination
 
147
        aboutData.addAuthor("Joachim Ansorg", I18N_NOOP("Project coordinator"), "nospam@joachim-ansorg.de", "http://www.joachim-ansorg.de/");
 
148
        // Second main developer
 
149
        aboutData.addAuthor("Martin Gruner", I18N_NOOP("Frontend, backend"), "mg.pub@gmx.net", "");
 
150
        // artwork
 
151
        aboutData.addAuthor("James Ots", I18N_NOOP("Crystal icons, crystal startlogo, webpage"), "me@jamesots.com", "http://www.jamesots.com");
 
152
 
 
153
        //inactiv
 
154
 
 
155
        /***********************************************
 
156
        *        Credits (sorted by last name)         *
 
157
        ************************************************/
 
158
        // Update to the Romanian GUI translation
 
159
        aboutData.addCredit("Horatiu Alexe", I18N_NOOP("Romanian translation"), "");
 
160
        //highcolor icons, startlogo for BT <= 1.4
 
161
        aboutData.addCredit("David Blue", I18N_NOOP("High contrast template"), "davidslists@gmx.net");
 
162
        //helped out with the installation manager
 
163
        aboutData.addCredit("Tim Brodie",    I18N_NOOP("Installation manager"),"tbrodie@displayworksinc.com", "");
 
164
        //first set of icons and the first startup logos
 
165
        aboutData.addCredit("Timothy R. Butler", I18N_NOOP("Icons, startlogo"), "tbutler@uninetsolutions.com", "http://www.uninetsolutions.com");
 
166
        //GUI improvements
 
167
        aboutData.addCredit("Jim Campbell",   I18N_NOOP("GUI"), "jdc.email@gmail.com", ""); 
 
168
        //Indexed search, gui improvements
 
169
        aboutData.addCredit("Lee Carpenter",  I18N_NOOP("GUI, instant search"),"Lee Carpenter <elc@carpie.net>", "http://www.carpie.net");
 
170
        //Translations into Traditional and Simplified Chinese
 
171
        aboutData.addCredit("Chun-shek Chan",   I18N_NOOP("GUI translations into Traditional and Simplified Chinese"), "chunshek@gmail.com", "");
 
172
        //Binary packages of CLucene, BibleTime and Sword for Fedore, SUSE, Mandriva
 
173
        aboutData.addCredit("Jeremy Erickson",   I18N_NOOP("Binary packages"), "", "");
 
174
        //Started the Crosswire porject, also contributed some code
 
175
        aboutData.addCredit("Troy A. Griffits",   I18N_NOOP("Founder of the Sword project"), "scribe@crosswire.org", "http://www.crosswire.org/");  
 
176
        //Sponsored many years the www.bibletime.de domain!
 
177
        aboutData.addCredit("Thomas Hagedorn",   I18N_NOOP("Sponsored our internet domain for many years"), "tom@theta-consulting.de", "");
 
178
        //He provided us with the Bible Study HowTo
 
179
        aboutData.addCredit("Bob Harman",        I18N_NOOP("Bible Study HowTo"), "ncc@ncchampton.org", "");
 
180
        // and / or search for multiple words, other fixes and improvements
 
181
        aboutData.addCredit("Nikolay Igotti", I18N_NOOP("Search dialog enhancements"), "olonho@hotmail.com", "");
 
182
        // Language codes iso639-1, iso639-2 and SIL language codes
 
183
        aboutData.addCredit("SIL International", I18N_NOOP("Language codes and names"), "", "http://www.ethnologue.com/iso639");
 
184
        //Patch for the mag delay (2007-03-22)
 
185
        aboutData.addCredit("Eeli Kaikkonen",  I18N_NOOP("GUI improvements"),"eekaikko@mail.student.oulu.fi", "");
 
186
        //Update the the Finnish GUI translation
 
187
        aboutData.addCredit("Ilpo Kantonen",  I18N_NOOP("Finnish translation"),"", "");
 
188
        //Smaller frontend enhancements
 
189
        aboutData.addCredit("Chris Kujawa",  I18N_NOOP("Frontend"),"christopher.kujawa@verizon.net", "");
 
190
        //Update to the Czech GUI translation
 
191
        aboutData.addCredit("Pavel Lauko",  I18N_NOOP("Czech translation"),"", "");
 
192
        //Smaller searchdialog enhancements
 
193
        aboutData.addCredit("Mark Lybarger",  I18N_NOOP("Searchdialog"), "mlybarge@insight.rr.com","");
 
194
        //Polish GUI translation update
 
195
        aboutData.addCredit("Piotr Markiewicz",  I18N_NOOP("Polish translation"), "pmarki@o2.pl", "");
 
196
        //Smaller frontend enhancements
 
197
        aboutData.addCredit("Luke Mauldin",  I18N_NOOP("Frontend"), "lukeskyfly@txk.net", "");
 
198
        //translated parts of the russian website files
 
199
        aboutData.addCredit("Igor Rykhlin",   I18N_NOOP("Russian website translation"), "", "");
 
200
        // update to the Spanish website translation
 
201
        aboutData.addCredit("Gabriel Pérez",   I18N_NOOP("Spanish website translation updates"), "", "");
 
202
        //Update to the russian website translation
 
203
        aboutData.addCredit("Igor Plisco", I18N_NOOP("Update to the russian website translation"), "", "");
 
204
        // handbook documentation
 
205
        aboutData.addCredit("Fred Saalbach", I18N_NOOP("Documentation"), "saalbach@sybercom.net", "");
 
206
        // Original Russian website translator
 
207
        aboutData.addCredit("Vlad Savitsky", I18N_NOOP("Russian website translation"), "", "");
 
208
        // comitted search in default bible, opened modules, other smaller things
 
209
        aboutData.addCredit("Gary Sims", I18N_NOOP("Search dialog enhancements"), "gary@garysims.co.uk", "");
 
210
        // Very helpful testing
 
211
        aboutData.addCredit("Wolfgang Stradner", I18N_NOOP("Very helpful and detailed testing"), "wolfgang_stradner@wycliffe.org", "");
 
212
        //The first lead developer
 
213
        aboutData.addCredit("Torsten Uhlmann",   I18N_NOOP("The first lead developer"), "", "");
 
214
        //Update of the dutch website translation
 
215
        aboutData.addCredit("Johan van der Lingen",   I18N_NOOP("Translation updates for the Dutch GUI, the website and the handbook"), "", "");
 
216
        //French handbook translation
 
217
        aboutData.addCredit("Jean Van Schaftingen", I18N_NOOP("French handbook translation"), "", "");
 
218
        //scoped_ptr and related classes
 
219
        aboutData.addCredit("David White",   I18N_NOOP("Helpful source code additions"), "", "http://www.wesnoth.org/");
 
220
        //Translated the GUI into Russian
 
221
        aboutData.addCredit("Dmitry Yurevich",   I18N_NOOP("Translated the GUI into Russian"), "", "");
 
222
        //The new keychooser for Bible modules
 
223
        aboutData.addCredit("Mark Zealey",   I18N_NOOP("New Bible key choosers"), "mspam@zealey.org", "");
 
224
        //Update to the Spanish GUI translation
 
225
        aboutData.addCredit("Esteban Zeller",   I18N_NOOP("Spanish translation"), "", "");
 
226
 
 
227
        
 
228
        //special message so the translator get his credits in the about box, don't remove this!
 
229
        QString dummy = I18N_NOOP("_: NAME OF TRANSLATORS\nYour names"); //translator's name
 
230
        dummy = I18N_NOOP("_: EMAIL OF TRANSLATORS\nYour emails"); //translators eMail
 
231
 
 
232
        KCmdLineArgs::init(argc, argv, &aboutData);
 
233
        KCmdLineArgs::addCmdLineOptions( options );
 
234
 
 
235
        BibleTimeApp app;
 
236
        KGlobal::dirs()->addResourceType("BT_pic", "share/apps/bibletime/pics");
 
237
        KGlobal::dirs()->addResourceType("BT_DisplayTemplates", "share/apps/bibletime/display-templates");
 
238
 
 
239
        KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
 
240
 
 
241
        // A binary option (on / off)
 
242
        if (args->isSet("debug")) {
 
243
                showDebugMessages = true;
 
244
        }
 
245
 
 
246
        if (kapp->isRestored()) {
 
247
                //    qWarning("Restoring BibleTime");
 
248
                RESTORE( BibleTime );
 
249
        }
 
250
        else {
 
251
                const bool showIt = CBTConfig::get(CBTConfig::logo);
 
252
 
 
253
                if(showIt) {
 
254
                        KStartupLogo::createSplash();
 
255
                        KStartupLogo::showSplash();
 
256
                        KStartupLogo::setStatusMessage( i18n("Starting BibleTime") + QString("...") );
 
257
                }
 
258
 
 
259
                setSignalHandler(signalHandler);
 
260
 
 
261
                // compatibility stuff for 1.3, needs to be moved to better place later
 
262
                if (CBTConfig::get(CBTConfig::bibletimeVersion) != VERSION) {
 
263
                        KStandardDirs stdDirs;
 
264
                        QDir dir(stdDirs.saveLocation("data", "bibletime/"));
 
265
                        if (!dir.exists("sessions/") && dir.exists("profiles/")) { //only old dir exists
 
266
                                dir.rename("profiles", "sessions");
 
267
                        }
 
268
                }
 
269
 
 
270
                bibletime_ptr = new BibleTime();
 
271
 
 
272
                // a new BibleTime version was installed (maybe a completely new installation)
 
273
                if (CBTConfig::get(CBTConfig::bibletimeVersion) != VERSION) {
 
274
                        KStartupLogo::hideSplash();
 
275
 
 
276
                        CBTConfig::set(CBTConfig::bibletimeVersion, VERSION);
 
277
                        bibletime_ptr->slotSettingsOptions();
 
278
                }
 
279
 
 
280
                //The tip of the day
 
281
                if (CBTConfig::get(CBTConfig::tips)) {
 
282
                        KStartupLogo::hideSplash();
 
283
                        bibletime_ptr->slotHelpTipOfDay();
 
284
                }
 
285
 
 
286
                // restore the workspace and process command line options
 
287
                app.setMainWidget(bibletime_ptr);
 
288
                bibletime_ptr->show();
 
289
                bibletime_ptr->processCommandline(); //must be done after the bibletime window is visible
 
290
 
 
291
                if (showIt) {
 
292
                        KStartupLogo::hideSplash();
 
293
                        KStartupLogo::deleteSplash();
 
294
                }
 
295
        }
 
296
 
 
297
        const int ret = app.exec();
 
298
 
 
299
        delete bibletime_ptr;
 
300
        return ret;
 
301
}
 
302