~ubuntu-branches/ubuntu/precise/ipe/precise

« back to all changes in this revision

Viewing changes to src/ipe/main.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Steve M. Robbins
  • Date: 2005-02-24 22:09:16 UTC
  • mfrom: (2.1.1 hoary)
  • Revision ID: james.westby@ubuntu.com-20050224220916-9vxiiqjz066r5489
Tags: 6.0pre23-2
debian/control: Ipe should depend on exact version of libipe.
Closes: #296771.

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
 
29
29
*/
30
30
 
31
 
#include "ipepdfdoc.h"
32
31
#include "appui.h"
33
32
#include "ipeq.h"
34
 
#include "debugwin.h"
 
33
#include "ipeversion.h"
35
34
 
36
35
#include <qapplication.h>
37
36
#include <qdir.h>
39
38
#include <qtextstream.h>
40
39
#include <qtextcodec.h>
41
40
 
 
41
#ifdef IPE_KDE
 
42
#include <kcmdlineargs.h>
 
43
#include <kapplication.h>
 
44
#endif
 
45
 
42
46
#include <cstdio>
43
47
#include <cstdlib>
44
48
 
48
52
#include <windows.h>
49
53
#endif
50
54
 
 
55
static bool showDebug = false;
 
56
 
51
57
#ifdef WIN32
52
58
static void ipeDebugImpl(const char *msg)
53
59
{
54
60
  OutputDebugStringA(msg);
55
61
}
56
62
#else
57
 
static void ipeDebugImpl(const char *)
 
63
static void ipeDebugImpl(const char *msg)
58
64
{
59
 
  // nothing
 
65
  if (showDebug)
 
66
    fprintf(stderr, "%s\n", msg);
60
67
}
61
68
#endif
62
69
 
63
70
// used from appui.cpp
64
71
void StartManual(QString url)
65
72
{
66
 
  //HelpWindow *manual = HelpWindow::Static(url);
67
 
  //manual->raise();
68
 
#ifdef WIN32
 
73
#if defined(WIN32)
69
74
  ShellExecute(0, "open", url.local8Bit(), 0, 0, 0);
 
75
#elif defined(IPE_KDE)
 
76
  KApplication::kApplication()->invokeBrowser(url);
70
77
#else
71
78
  QString browser = IpePreferences::Static()->iBrowser;
72
79
  QString s = browser + " " + url;
74
81
#endif
75
82
}
76
83
 
 
84
int saveKeys(int argc, char **argv, const char *fname)
 
85
{
 
86
  QApplication a(argc, argv);
 
87
  AppUi *appui = new AppUi;
 
88
  appui->SaveKeys(QString::fromLocal8Bit(fname));
 
89
  return 0;
 
90
}
 
91
 
 
92
#ifdef IPE_KDE
 
93
 
 
94
static const KCmdLineOptions options[] = {
 
95
  { "debug", "Display debug information on stderr.", 0 },
 
96
  { "sheet <stylesheet>", "Add style sheet to all newly created documents.",
 
97
    0 },
 
98
  { "!geom <WxH+X+Y>", "Set geometry of main window.", 0 },
 
99
  { "+[file]", "Load document from file.", 0 },
 
100
  KCmdLineLastOption // End of options.
 
101
};
 
102
 
 
103
#else
 
104
 
77
105
static void usage()
78
106
{
79
 
  fprintf(stderr, "Usage:\n ipe [ Qt options ] [-geom wxh+x+y] [-sheet stylesheet][ filename ]\n");
 
107
  fprintf(stderr,
 
108
          "Usage:\n ipe [ Qt options ] [-debug] [-geom wxh+x+y] "
 
109
          "[-sheet stylesheet][ filename ]\n");
80
110
  exit(1);
81
111
}
82
112
 
 
113
#endif
 
114
 
83
115
// The main function just starts the QApplication
84
116
int main(int argc, char *argv[])
85
117
{
97
129
  // set ipeDebug handler
98
130
  ipeDebugHandler = ipeDebugImpl;
99
131
 
 
132
  if (argc == 3 && !qstrcmp(argv[1], "-savekeys"))
 
133
    return saveKeys(argc, argv, argv[2]);
 
134
 
 
135
#ifdef IPE_KDE
 
136
 
 
137
  KCmdLineArgs::init(argc, argv, "ipe", "Ipe",
 
138
                     "Ipe drawing editor", IPE_VERSION);
 
139
  KCmdLineArgs::addCmdLineOptions(options);
 
140
  KApplication::addCmdLineOptions();
 
141
  KApplication a;
 
142
 
 
143
#else
 
144
 
100
145
  if (argc >= 2 && (!qstrcmp(argv[1], "-help") ||
101
146
                    !qstrcmp(argv[1], "--help")))
102
147
    usage();
103
148
 
104
149
  QApplication a( argc, argv );
105
150
 
 
151
#endif
 
152
 
106
153
  // must create QApplication before first call to IpePreferences::Static.
107
154
  IpePreferences *prefs = IpePreferences::Static();
108
155
 
109
156
  QApplication::setFont(prefs->iFont, true);
110
157
 
111
158
  QString lang = IpePreferences::Static()->iLanguage;
112
 
  IPEDBG << "Current locale is " << QTextCodec::locale() << "\n";
113
 
  IPEDBG << "Current directory is " << QDir::current().path() << "\n";
 
159
  ipeDebug("Current locale is '%s'", QTextCodec::locale());
 
160
  ipeDebug("Current directory is '%s'", QDir::current().path().latin1());
114
161
 
115
162
  QTranslator qt(0);
116
163
  QTranslator qt1(0);
117
 
  if (lang != QString::null) {
 
164
  if (!lang.isNull()) {
118
165
    if (qt.load("ipe-" + lang, prefs->iLangDir))
119
166
      a.installTranslator(&qt);
120
167
    if (qt1.load("keys-" + lang, prefs->iLangDir))
123
170
 
124
171
  QTranslator qt2(0);
125
172
  if (qt2.load(prefs->iKeysFileName)) {
126
 
    IPEDBG << "Loaded personal key definitions\n";
 
173
    qDebug("Loaded personal key definitions from '%s'",
 
174
           prefs->iKeysFileName.latin1());
127
175
    a.installTranslator(&qt2);
128
176
  }
129
177
 
130
 
  int i = 1;
131
178
  bool geom = false;
132
179
  int w, h, x, y;
 
180
  QCString load;
 
181
 
 
182
#ifdef IPE_KDE
 
183
 
 
184
  KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
 
185
 
 
186
  QCString sheet = args->getOption("sheet");
 
187
  if (!sheet.isEmpty())
 
188
    prefs->iStyleSheet2 = sheet.data();
 
189
 
 
190
  QCString geoms = args->getOption("geom");
 
191
  if (!geoms.isEmpty() &&
 
192
      sscanf(geoms.data(), "%dx%d+%d+%d", &w, &h, &x, &y) == 4) {
 
193
    geom = true;
 
194
    ipeDebug("Geometry: %dx%d at (%d,%d)", w, h, x, y);
 
195
  }
 
196
 
 
197
  // File to open
 
198
  if (args->count() > 0)
 
199
    load = args->arg(0);
 
200
 
 
201
  args->clear(); // Free up some memory.
 
202
 
 
203
#else
 
204
 
 
205
  int i = 1;
133
206
  if (a.argc() >= i+2 && !qstrcmp(a.argv()[i], "-geom")) {
134
207
    if (sscanf(a.argv()[i+1], "%dx%d+%d+%d", &w, &h, &x, &y) == 4)
135
208
      geom = true;
136
 
    IPEDBG << "Geometry: " << w << " x " << h
137
 
           << " at (" << x << "," << y << ")\n";
 
209
    ipeDebug("Geometry: %dx%d at (%d,%d)", w, h, x, y);
138
210
    i += 2;
139
211
  }
140
212
  if (a.argc() >= i+2 && !qstrcmp(a.argv()[i], "-sheet")) {
141
213
    prefs->iStyleSheet2 = a.argv()[i+1];
142
214
    i += 2;
143
215
  }
144
 
 
145
 
  if (a.argc() > i + 1)
 
216
  if (a.argc() >= i+1 && !qstrcmp(a.argv()[i], "-debug")) {
 
217
    showDebug = true;
 
218
    ++i;
 
219
  }
 
220
  if (a.argc() == i + 1) {
 
221
    load = a.argv()[i];
 
222
  } else if (a.argc() > i + 1)
146
223
    usage();
147
224
 
 
225
#endif
 
226
 
148
227
  AppUi *appui = new AppUi;
149
228
 
150
 
  if (a.argc() != i+1 || !appui->Load(a.argv()[i]))
 
229
  if (load.isEmpty() || !appui->Load(load))
151
230
    appui->NewDoc();
152
231
 
153
232
  if (prefs->iMaximize) {