Welcome to mirror list, hosted at ThFree Co, Russian Federation.

main.cpp « qt - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: ea687e25c0c531a86c5a8781f4f916a9cc2ad254 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#include "mainwindow.hpp"
#include "info_dialog.hpp"

#include "../platform/settings.hpp"
#include "../platform/platform.hpp"

#include "../base/logging.hpp"
#include "../base/macros.hpp"

#include "../coding/file_reader.hpp"

#include "../version/version.hpp"

#include "../std/cstdio.hpp"

#include <QtGui/QApplication>

//#ifdef OMIM_OS_WINDOWS
//  #include <../src/gui/image/qimageiohandler.h>
//  #include <../src/network/bearer/qbearerplugin_p.h>
//  #include <../src/corelib/plugin/qfactoryloader_p.h>
//#endif

//#include <google/protobuf/stubs/common.h>

#include "../base/start_mem_debug.hpp"

//#ifdef OMIM_OS_WINDOWS
//Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, imageLoader,
//                          (QImageIOHandlerFactoryInterface_iid, QLatin1String("/imageformats")))
//Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, bearerLoader,
//                          (QBearerEngineFactoryInterface_iid, QLatin1String("/bearer")))
//#endif


#define SETTING_EULA_ACCEPTED "EulaAccepted"

namespace
{
  class FinalizeBase
  {
  public:
    ~FinalizeBase()
    {
      // optional - clean allocated data in protobuf library
      // useful when using memory and resource leak utilites
      //google::protobuf::ShutdownProtobufLibrary();
    }
  };

#if defined(OMIM_OS_WINDOWS) //&& defined(PROFILER_COMMON)
  class InitializeFinalize : public FinalizeBase
  {
    FILE * m_errFile;
  public:
    InitializeFinalize()
    {
      // App runs without error console under win32.
      m_errFile = ::freopen(".\\mapswithme.log", "w", stderr);
      my::g_LogLevel = my::LDEBUG;

      //_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_DELAY_FREE_MEM_DF);
      //_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
    }
    ~InitializeFinalize()
    {
      ::fclose(m_errFile);
    }
  };
#else
  typedef FinalizeBase InitializeFinalize;
#endif
}

int main(int argc, char *argv[])
{
  InitializeFinalize mainGuard;
  UNUSED_VALUE(mainGuard);

  LOG(LINFO, ("MapsWithMe started"));
  LOG(LINFO, ("Version : ", VERSION_STRING));
  LOG(LINFO, ("Built on : ", VERSION_DATE_STRING));

  QApplication a(argc, argv);

  (void)GetPlatform();

  // display EULA if needed
  bool eulaAccepted = false;
  if (!Settings::Get(SETTING_EULA_ACCEPTED, eulaAccepted) || !eulaAccepted)
  {
    QStringList buttons;
    buttons << "Accept" << "Decline";

    string buffer;
    FileReader(GetPlatform().ReadPathForFile("eula.html")).ReadAsString(buffer);
    qt::InfoDialog eulaDialog("MapsWithMe End User Licensing Agreement", buffer.c_str(), NULL, buttons);
    eulaAccepted = (eulaDialog.exec() == 1);
    Settings::Set(SETTING_EULA_ACCEPTED, eulaAccepted);
  }

  int returnCode = -1;
  if (eulaAccepted)   // User has accepted EULA
  {
    qt::MainWindow w;
    w.show();
    returnCode = a.exec();
  }

  // QTBUG: Fix memory leaks. Nobody delete created plugins.
//#ifdef OMIM_OS_WINDOWS
//  QFactoryLoader * arr[] = { imageLoader(), bearerLoader() };
//  for (int i = 0; i < 2; ++i)
//  {
//    QStringList const & keys = arr[i]->keys();

//    for (int j = 0; j < keys.count(); ++j)
//      delete arr[i]->instance(keys.at(j));
//  }
//#endif

  LOG(LINFO, ("MapsWithMe finished with code : ", returnCode));
  return returnCode;
}