Import of widgets from wxKanjiPad, plus the files needed to compile kpengine. Also...
[jben.git] / jben.cpp
blob7a52be2085de7ed8937732cdd29ce3a9b86508db
1 /*
2 Project: J-Ben
3 Author: Paul Goins
4 License: GNU General Public License (GPL) version 2
5 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt)
7 File: jben.cpp
9 This file is part of J-Ben.
11 J-Ben is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License version 2
13 as published by the Free Software Foundation.
15 J-Ben 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.
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>
24 #include "global.h"
25 #include "dictload.h"
26 #include "jben.h"
28 #include <stdlib.h>
30 JBen *jben;
31 Preferences *prefs;
33 /* The application entry point */
34 IMPLEMENT_APP(JBen)
36 bool JBen::OnInit() {
37 int result;
39 jben = this;
40 edict = (Edict *)NULL;
41 kdict = (KanjiDic *)NULL;
42 kanjiList = (KanjiList *)NULL;
43 vocabList = (VocabList *)NULL;
44 gui = (MainGUI *)NULL;
46 /* Start our random number generator */
47 srand(time(NULL));
48 for(int i=0;i<50;i++) rand(); /* On some platforms I've seen rand() behave
49 fairly predictably for the first iteration or so.
50 That's why I spin off a few iterations of rand()
51 before really using it. */
53 /* DictionaryLoader was intended to be a splash screen for loading the dictionaries. However,
54 currently this is a fast enough operation that I decided it was unnecessary. */
55 #if 0
56 /* Display splash screen which shows progress bars while loading
57 dictionaries. (Yes, this is fluff.) */
58 DictionaryLoader *d = new DictionaryLoader();
59 d->Show(true);
60 SetTopWindow(d);
61 result = d->LoadDictionaries();
62 d->Destroy();
63 #endif
64 /* For now, DictionaryLoader is a non-GUI class. Just make the object, run the function, and be done with it. */
65 DictionaryLoader *d = new DictionaryLoader();
66 result = d->LoadDictionaries();
67 delete d;
69 if(result==DL_SUCCESS) {
70 kanjiList = new KanjiList(kdict->GetHashTable());
71 vocabList = new VocabList();
72 prefs = new Preferences(_T("jben.cfg"));
73 /* Show the main GUI. */
74 gui = new MainGUI();
75 /* On Linux, for some reason there's a placeholder "loading" mini-window which pops up during creation of this object. Why??*/
76 gui->Show(true);
77 SetTopWindow(gui);
78 return true;
79 } else {
80 wxMessageBox(wxString::Format(_T("Error during startup, DictionaryLoader result = 0x%X\n"), result),
81 _T("DictionaryLoader error"), wxOK | wxICON_ERROR);
82 return false;
86 int JBen::OnExit() {
87 #ifdef DEBUG
88 printf("JBen::OnExit being processed...\n");
89 #endif
90 if(prefs) delete prefs;
91 if(edict) delete edict;
92 if(kanjiList) delete kanjiList;
93 if(kdict) delete kdict;
94 #ifdef DEBUG
95 printf("Terminating program.\n");
96 #endif
97 return 0;