]>
vaikene.ee Git - evaf/blob - src/libs/Common/app.cpp
3 * @brief Application interface implementation
6 * Copyright (c) 2011 Enar Vaikene
8 * This file is part of the eVaf C++ cross-platform application development framework.
10 * This file can be used under the terms of the GNU General Public License
11 * version 3.0 as published by the Free Software Foundation and appearing in
12 * the file LICENSE included in the packaging of this file. Please review the
13 * the following information to ensure the GNU General Public License version
14 * 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
16 * Alternatively, this file may be used in accordance with the Commercial License
17 * Agreement provided with the Software.
29 //-------------------------------------------------------------------
31 using namespace eVaf::Common
;
33 iApp
* iApp::instance()
35 static Internal::App singleton
;
39 char const * const iApp::EV_QUIT
= "iApp::quit";
40 char const * const iApp::EV_RESTART
= "iApp::restart";
41 char const * const iApp::EV_READY
= "iApp::ready";
42 char const * const iApp::EV_TERMINATING
= "iApp::terminating";
45 //-------------------------------------------------------------------
47 using namespace eVaf::Common::Internal
;
52 , mName(VER_PRODUCT_NAME_STR
)
54 setObjectName(QString("%1.iApp").arg(VER_MODULE_NAME_STR
));
64 // Register our interface
65 iRegistry::instance()->registerInterface("iApp", this);
67 // Set the default application name and language
68 mName
= VER_PRODUCT_NAME_STR
;
69 mLanguage
= QLocale::system().name();
71 // Clear the XML file name
74 // Process environment variables
75 QStringList env
= QProcess::systemEnvironment();
76 for (int i
= 0; i
< env
.size(); ++i
) {
77 // Get the name/value pair
78 QString name
= env
.at(i
).section('=', 0, 0).trimmed();
79 QString value
= env
.at(i
).section('=', 1).trimmed();
81 if (name
== "EVAF_APP_NAME")
83 else if (name
== "EVAF_LANGUAGE")
87 // Then process command-line arguments
88 env
= QCoreApplication::arguments();
89 for (int i
= 0; i
< env
.size(); ++i
) {
90 // Get the name and optional value
91 QStringList arg
= env
.at(i
).simplified().split('=');
93 if (QRegExp("-[-]?app(lication)?").exactMatch(arg
.at(0)) && arg
.size() > 1)
95 else if (QRegExp("-[-]?lang(uage)?").exactMatch(arg
.at(0)) && arg
.size() > 1)
96 mLanguage
= arg
.at(1);
102 QString
const App::xmlFileName() const
104 if (mXmlFile
.isEmpty()) {
107 // Try the full application name + country + language combination
108 QString name
= mName
+ "_" + mLanguage
+ ".xml";
109 fi
.setFile(iEnv::instance()->etcDir() + name
);
113 // Try application name + country
114 name
= mName
+ "_" + mLanguage
.left(2) + ".xml";
115 fi
.setFile(iEnv::instance()->etcDir() + name
);
119 // Fall-back to the generic name
120 mXmlFile
= mName
+ ".xml";
128 QCoreApplication::exit(RC_Restart
);
131 void App::quit(bool err
)
133 QCoreApplication::exit(err
? RC_Error
: RC_Quit
);