Isis 3 Programmer Reference
QIsisApplication.cpp
1 #include "QIsisApplication.h"
2 
3 #include <locale.h>
4 
5 #include <QDesktopServices>
6 #include <QFileInfo>
7 #include <QObject>
8 #include <QMessageBox>
9 #include <QUrl>
10 
11 #include "FileName.h"
12 #include "Preference.h"
13 #include "IException.h"
14 #include "IString.h"
15 
16 namespace Isis {
28  QIsisApplication::QIsisApplication(int &argc, char *argv[]) :
29  QApplication(argc, argv) {
30  // try to use US locale for numbers so we don't end up printing "," instead
31  // of "." where it might count.
32 
33  for (int i = 1; i < argc; i++) {
34  QString arg(argv[i]);
35  if (arg.startsWith("-pref")) {
36 
37  // So that we can grab the file located after the current '-pref' flag.
38  int nextIndex = i + 1;
39 
40  if (nextIndex < argc) {
41  FileName preferenceFile(argv[nextIndex]);
42  QString filePath = preferenceFile.expanded();
43  Preference::Preferences().clear();
44  Preference::Preferences().Load(filePath);
45  }
46  else {
47  QMessageBox::warning(NULL, "Warning", "Preference flag set but no preference file given.");
48  }
49  }
50  }
51  setlocale(LC_NUMERIC, "en_US");
52 
53  QDesktopServices::setUrlHandler("http", this, "openUrl");
54  }
55 
56 
74  bool QIsisApplication::notify(QObject *rec, QEvent *ev) {
75  try {
76  return QApplication::notify(rec, ev);
77  }
78  catch(IException &e) {
79  QMessageBox::critical(NULL, "Error", e.what());
80  }
81  return false;
82  }
83 
84 
88  void QIsisApplication::openUrl(QUrl url) {
89  QDesktopServices::openUrl(url);
90  }
91 }
const char * what() const
Returns a string representation of this exception in its current state.
Definition: IException.cpp:391
File name manipulation and expansion.
Definition: FileName.h:116
QString expanded() const
Returns a QString of the full file name including the file path, excluding the attributes.
Definition: FileName.cpp:212
virtual bool notify(QObject *rec, QEvent *ev)
notify - this function overrides the QApplication notify as QT event handlers do not handle exception...
QIsisApplication(int &argc, char *argv[])
Constructor.
Isis exception class.
Definition: IException.h:107
Namespace for ISIS/Bullet specific routines.
Definition: Apollo.h:31
void openUrl(QUrl url)
Open a URL in the browser specified by Isis.