All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
main.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2008 National Institute For Space Research (INPE) - Brazil.
2 
3  This file is part of TerraView - A Free and Open Source GIS Application.
4 
5  TerraView is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  TerraView is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with TerraView. See COPYING. If not, write to
17  TerraLib Team at <terralib-team@dpi.inpe.br>.
18  */
19 
20 /*!
21  \file terraview/main.cpp
22 
23  \brief It contains the main routine of TerraView.
24 */
25 
26 // TerraView
27 #include "Config.h"
28 #include "../terralib/Defines.h"
29 #include "TerraView.h"
30 
31 // TerraLib
33 #include <terralib/qt/af/Utils.h>
35 
36 // STL
37 #include <cstdlib>
38 #include <exception>
39 #include <locale>
40 
41 // Qt
42 #include <QApplication>
43 #include <QDir>
44 #include <QFileInfo>
45 #include <QLibraryInfo>
46 #include <QLocale>
47 #include <QMessageBox>
48 #include <QSplashScreen>
49 #include <QTextCodec>
50 #include <QTranslator>
51 
52 
53 #if TE_PLATFORM == TE_PLATFORMCODE_APPLE
54 #include <CoreFoundation/CoreFoundation.h>
55 #endif
56 
57 
58 int main(int argc, char** argv)
59 {
60  QApplication app(argc, argv);
61 
62  QDir dir(QLibraryInfo::location(QLibraryInfo::TranslationsPath));
63 
64  QStringList filters;
65  filters <<"*" + QLocale::system().name().toLower() + ".qm";
66 
67  QFileInfoList lst = dir.entryInfoList(filters, QDir::Files);
68 
69  for(int i=0; i<lst.size(); ++i)
70  {
71  QTranslator* trans = new QTranslator;
72  bool ls = trans->load(lst.at(i).baseName(), QLibraryInfo::location(QLibraryInfo::TranslationsPath));
73  app.installTranslator(trans);
74  }
75 
76  setlocale(LC_ALL,"C"); // This force to use "." as decimal separator.
77 
78 #if QT_VERSION >= 0x050000
79  QTextCodec::setCodecForLocale(QTextCodec::codecForLocale());
80 #else
81  QTextCodec::setCodecForCStrings(QTextCodec::codecForLocale());
82 #endif
83 
84  int waitVal = EXIT_FAILURE;
85 
86  const int RESTART_CODE = 1000;
87 
88  try
89  {
90  do
91  {
92  std::string splash_pix = te::common::FindInTerraLibPath(TVIEW_SPLASH_SCREEN_PIXMAP);
93 
94  QPixmap pixmap(splash_pix.c_str());
95 
96  QSplashScreen* splash(new QSplashScreen(pixmap/*, Qt::WindowStaysOnTopHint*/));
97 
98  splash->setAttribute(Qt::WA_DeleteOnClose, true);
99 
100  splash->setStyleSheet("QWidget { font-size: 12px; font-weight: bold }");
101 
102  te::qt::af::SplashScreenManager::getInstance().set(splash, Qt::AlignBottom | Qt::AlignHCenter, Qt::white);
103 
104  splash->show();
105 
106  TerraView tview;
107 
108  tview.resetTerraLib(waitVal != RESTART_CODE);
109 
110 #if TE_PLATFORM == TE_PLATFORMCODE_APPLE
111  CFBundleRef mainBundle = CFBundleGetMainBundle();
112  CFURLRef execPath = CFBundleCopyBundleURL(mainBundle);
113 
114  char path[PATH_MAX];
115 
116  if (!CFURLGetFileSystemRepresentation(execPath, TRUE, (UInt8 *)path, PATH_MAX))
117  throw; // error!
118 
119  CFRelease(execPath);
120 
121  QDir dPath(path);
122 
123  dPath.cd("Contents");
124 
125  chdir(dPath.path().toStdString().c_str());
126 #endif
127 
128  tview.init();
129 
130  splash->finish(&tview);
131 
132  tview.showMaximized();
133 
134  tview.resetState();
135 
136  // Start TerraView from project file(.tview)
137  if(argc > 1)
138  {
139  std::string projPath = argv[1];
140 
141  if(!projPath.empty())
142  tview.startProject(projPath.c_str());
143  }
144 
145  waitVal = app.exec();
146 
147  tview.resetTerraLib(waitVal != RESTART_CODE);
148 
149  } while(waitVal == RESTART_CODE);
150  }
151  catch(const std::exception& /*e*/)
152  {
153  return EXIT_FAILURE;
154  }
155  catch(...)
156  {
157  return EXIT_FAILURE;
158  }
159 
160  return waitVal;
161 }
void resetTerraLib(const bool &status)
The main class of TerraView.
Definition: TerraView.h:54
This file is a wrapper around platform specific include files.
TECOMMONEXPORT std::string FindInTerraLibPath(const std::string &p)
Returns the path relative to a directory or file in the context of TerraLib.
A singleton for holding he application splash screen.
static SplashScreenManager & getInstance()
It returns a reference to the singleton instance.
int main(int argc, char *argv[])
Definition: main.cpp:24
void startProject(const QString &projectFileName)
Definition: TerraView.cpp:97
Proxy configuration file for TerraView (see terraview_config.h).
The main class of TerraView.
Utility routines for the TerraLib Application Framework module.
void init()
Definition: TerraView.cpp:53