-
Notifications
You must be signed in to change notification settings - Fork 17
/
IDEApplication.cpp
145 lines (116 loc) · 3.95 KB
/
IDEApplication.cpp
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/*
IDEApplication.cpp
This file is part of arduide, The Qt-based IDE for the open-source Arduino electronics prototyping platform.
Copyright (C) 2010-2016
Authors : Denis Martinez
Martin Peres
Copyright (C) 2011
Laurent Navet (translation support)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* \file IDEApplication.cpp
* \author Denis Martinez
* \date 2010-02-28
*/
#include "IDEApplication.h"
#include <QDir>
#include <QPluginLoader>
#include <QDebug>
#include "plugins/IDEPluginInterface.h"
#include <QTextCursor>
#include <QTextCharFormat>
void IDEApplication::registerMetaTypes()
{
qRegisterMetaType<QTextCursor>("QTextCursor");
qRegisterMetaType<QTextCharFormat>("QTextCharFormat");
}
IDEApplication::IDEApplication(int& argc, char **argv)
: QApplication(argc, argv),
mSettings(NULL)
{
setOrganizationName(PROJECT_ORGANIZATION);
setApplicationName(PROJECT_NAME);
setApplicationVersion(PROJECT_VERSION);
setWindowIcon(QIcon(":/images/arduide.png"));
// translation support
initializeTranslator();
// fix the data path
mDataPath = QDir(DATA_PATH).absolutePath();
registerMetaTypes();
// initialize Grantlee
initializeTemplates();
// start the GUI
initializeGui();
// check the settings are correct, or start the wizard
initializeSettings();
// further gui initialization
mMainWindow->initialize();
// initialize the plugins
initializePlugins();
}
void IDEApplication::initializeTemplates()
{
mEngine = new Grantlee::Engine(this);
mEngine->setPluginPaths(QStringList() << QDir(GRANTLEE_PLUGIN_DIR).absolutePath());
Grantlee::FileSystemTemplateLoader::Ptr loader = Grantlee::FileSystemTemplateLoader::Ptr(new Grantlee::FileSystemTemplateLoader);
loader->setTemplateDirs(QStringList() << ":/templates");
mEngine->addTemplateLoader(loader);
}
void IDEApplication::initializeGui()
{
mMainWindow = new MainWindow;
mMainWindow->show();
}
void IDEApplication::initializeSettings()
{
mSettings = new Settings;
if (! mSettings->isCorrect())
{
FirstTimeWizard w;
if (w.exec() == QWizard::Rejected)
::exit(1);
}
mProjectHistory = new ProjectHistory(this);
}
void IDEApplication::initializePlugins()
{
qDebug() << "initializePlugins: loading the plugins in " PLUGIN_PATH;
mPluginLoader = new QPluginLoader(this);
mPluginLoader->setLoadHints(QLibrary::ResolveAllSymbolsHint | QLibrary::ExportExternalSymbolsHint);
QDir pluginDir(PLUGIN_PATH);
QString fileName;
bool ok;
foreach(const QString &entry, pluginDir.entryList(QDir::Files, QDir::Name))
{
fileName = pluginDir.filePath(entry);
mPluginLoader->setFileName(fileName);
ok = mPluginLoader->load();
qDebug() << "Loading" << entry << "result:" << ok;
if (ok)
{
IDEPluginInterface *plugin = dynamic_cast<IDEPluginInterface *>(mPluginLoader->instance());
ok = plugin != NULL && plugin->setup(this);
qDebug() << "Initializing" << entry << "result:" << ok;
}
else
qDebug() << mPluginLoader->errorString();
}
}
void IDEApplication::initializeTranslator()
{
if(! mTranslator.load("arduide_" + QLocale::system().name(), TRANSLATION_PATH))
{
qDebug() << "loading translator failed.";
}
installTranslator(&mTranslator);
}