src/terraview/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 
27 // TerraView
28 #include "Config.h"
29 #include "../terralib/Defines.h"
30 #include "TerraView.h"
31 #include "TerraViewApp.h"
32 
33 // TerraLib
34 #include <terralib/Exception.h>
37 #include <terralib/qt/af/Utils.h>
39 
40 // STL
41 #include <cstdlib>
42 #include <exception>
43 #include <locale>
44 
45 // Qt
46 #include <QApplication>
47 #include <QDir>
48 #include <QFileInfo>
49 #include <QLibraryInfo>
50 #include <QLocale>
51 #include <QMessageBox>
52 #include <QSplashScreen>
53 #include <QTextCodec>
54 #include <QTranslator>
55 
56 
57 #if TE_PLATFORM == TE_PLATFORMCODE_APPLE
58 #include <CoreFoundation/CoreFoundation.h>
59 #endif
60 
61 
62 int main(int argc, char** argv)
63 {
64  TerraViewApp app(argc, argv);
65  app.setApplicationVersion(QString::fromUtf8(te::common::Version::asString().c_str()));
66 
67  QDir dir(QLibraryInfo::location(QLibraryInfo::TranslationsPath));
68 
69  QStringList filters;
70  filters <<"*" + QLocale::system().name().toLower() + ".qm";
71 
72  QFileInfoList lst = dir.entryInfoList(filters, QDir::Files);
73 
74  for(int i=0; i<lst.size(); ++i)
75  {
76  QTranslator* trans = new QTranslator;
77  trans->load(lst.at(i).baseName(), QLibraryInfo::location(QLibraryInfo::TranslationsPath));
78  app.installTranslator(trans);
79  }
80 
81  setlocale(LC_ALL,"C"); // This force to use "." as decimal separator.
82 
83 #if QT_VERSION >= 0x050000
84  QTextCodec::setCodecForLocale(QTextCodec::codecForLocale());
85 #else
86  QTextCodec::setCodecForCStrings(QTextCodec::codecForLocale());
87 #endif
88 
89  int waitVal = EXIT_FAILURE;
90 
91  const int RESTART_CODE = 1000;
92  try
93  {
94  do
95  {
96  std::string splash_pix = te::core::FindInTerraLibPath(TVIEW_SPLASH_SCREEN_PIXMAP);
97 
98  QPixmap pixmap(splash_pix.c_str());
99 
100  QSplashScreen* splash = new QSplashScreen(pixmap/*, Qt::WindowStaysOnTopHint*/);
101 
102 // splash.setAttribute(Qt::WA_DeleteOnClose, true);
103 
104  splash->setStyleSheet("QWidget { font-size: 12px; font-weight: bold }");
105 
106  te::qt::af::SplashScreenManager::getInstance().set(splash, Qt::AlignBottom | Qt::AlignHCenter, Qt::white);
107 
108  splash->show();
109 
110  TerraView tview;
111 
112  //tview.resetTerraLib(waitVal != RESTART_CODE);
113 
114 #if TE_PLATFORM == TE_PLATFORMCODE_APPLE
115  CFBundleRef mainBundle = CFBundleGetMainBundle();
116  CFURLRef execPath = CFBundleCopyBundleURL(mainBundle);
117 
118  char path[PATH_MAX];
119 
120  if (!CFURLGetFileSystemRepresentation(execPath, TRUE, (UInt8 *)path, PATH_MAX))
121  throw; // error!
122 
123  CFRelease(execPath);
124 
125  QDir dPath(path);
126 
127  dPath.cd("Contents");
128 
129  chdir(dPath.path().toUtf8().data());
130 #endif
131 
133 
134  splash->setParent(&tview);
135 
136  splash->finish(&tview);
137 
138  tview.showMaximized();
139 
140  //tview.resetState();
141 
142  // Start TerraView from project file(.tview)
143  if(argc > 1)
144  {
145  std::string projPath = argv[1];
146 
147  if(!projPath.empty())
148  tview.startProject(projPath.c_str());
149  }
150 
151  waitVal = app.exec();
152 
153  } while(waitVal == RESTART_CODE);
154  }
155  catch(const boost::exception& e)
156  {
157  if(const std::string* d =
158  boost::get_error_info<te::ErrorDescription>(e))
159  QMessageBox::warning(nullptr, "TerraView", d->c_str());
160  else
161  QMessageBox::warning(nullptr,"TerraView", "An unknown error has occurred");
162  return EXIT_FAILURE;
163  }
164  catch(const std::exception& e)
165  {
166  QMessageBox::warning(nullptr, "TerraView", e.what());
167  return EXIT_FAILURE;
168  }
169  catch(...)
170  {
171  return EXIT_FAILURE;
172  }
173 
174  return waitVal;
175 }
The main class of TerraView.
Definition: TerraView.h:67
This file is a wrapper around platform specific include files.
static std::string asString()
Definition: Version.cpp:60
#define TERRAVIEW_APPLICATION_CONFIG_FILE
A singleton for holding he application splash screen.
Utility class for system versioning.
static SplashScreenManager & getInstance()
It returns a reference to the singleton instance.
void startProject(const QString &projectFileName)
Definition: TerraView.cpp:304
static te::dt::DateTime d(2010, 8, 9, 15, 58, 39)
void init(const QString &cfgFile)
Definition: TerraView.cpp:281
Utility routines for the TerraLib Application Framework module.
TECOREEXPORT std::string FindInTerraLibPath(const std::string &path)
Returns the path relative to a directory or file in the context of TerraLib.
The main class of TerraView.
Proxy configuration file for TerraView (see terraview_config.h).
int main(int argc, char **argv)