2010-08-07 09:10:44 -04:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2010 Felix Geyer <debfx@fobos.de>
|
|
|
|
*
|
|
|
|
* 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 or (at your option)
|
|
|
|
* version 3 of the License.
|
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2013-10-03 09:18:16 -04:00
|
|
|
#include <QFile>
|
2010-08-15 06:31:48 -04:00
|
|
|
|
2014-01-18 09:31:24 -05:00
|
|
|
#include "config-keepassx.h"
|
2013-03-29 15:35:54 -04:00
|
|
|
#include "core/Config.h"
|
2014-01-18 09:23:55 -05:00
|
|
|
#include "core/qcommandlineparser.h"
|
2012-10-13 05:05:50 -04:00
|
|
|
#include "core/Tools.h"
|
2014-05-17 19:33:22 -04:00
|
|
|
#include "core/Translator.h"
|
2010-09-13 17:25:48 -04:00
|
|
|
#include "crypto/Crypto.h"
|
2012-05-17 18:35:24 -04:00
|
|
|
#include "gui/Application.h"
|
2010-09-19 10:59:32 -04:00
|
|
|
#include "gui/MainWindow.h"
|
2014-06-15 05:17:40 -04:00
|
|
|
#include "gui/MessageBox.h"
|
2010-08-15 06:31:48 -04:00
|
|
|
|
2012-05-02 11:04:03 -04:00
|
|
|
int main(int argc, char** argv)
|
2010-08-07 09:10:44 -04:00
|
|
|
{
|
2012-10-13 05:05:50 -04:00
|
|
|
#ifdef QT_NO_DEBUG
|
|
|
|
Tools::disableCoreDumps();
|
|
|
|
#endif
|
2015-12-06 08:32:06 -05:00
|
|
|
Tools::setupSearchPaths();
|
2012-10-13 05:05:50 -04:00
|
|
|
|
2012-05-17 18:35:24 -04:00
|
|
|
Application app(argc, argv);
|
2014-01-18 09:31:24 -05:00
|
|
|
Application::setApplicationName("keepassx");
|
|
|
|
Application::setApplicationVersion(KEEPASSX_VERSION);
|
|
|
|
// don't set organizationName as that changes the return value of
|
|
|
|
// QDesktopServices::storageLocation(QDesktopServices::DataLocation)
|
2010-08-15 06:31:48 -04:00
|
|
|
|
2014-11-02 04:15:44 -05:00
|
|
|
QApplication::setQuitOnLastWindowClosed(false);
|
|
|
|
|
2014-06-15 05:17:40 -04:00
|
|
|
if (!Crypto::init()) {
|
|
|
|
QString error = QCoreApplication::translate("Main",
|
|
|
|
"Fatal error while testing the cryptographic functions.");
|
|
|
|
error.append("\n");
|
|
|
|
error.append(Crypto::errorString());
|
|
|
|
MessageBox::critical(Q_NULLPTR, QCoreApplication::translate("Main", "KeePassX - Error"), error);
|
|
|
|
return 1;
|
|
|
|
}
|
2010-09-13 17:25:48 -04:00
|
|
|
|
2014-01-18 09:23:55 -05:00
|
|
|
QCommandLineParser parser;
|
|
|
|
parser.setApplicationDescription(QCoreApplication::translate("main", "KeePassX - cross-platform password manager"));
|
|
|
|
parser.addPositionalArgument("filename", QCoreApplication::translate("main", "filename of the password database to open (*.kdbx)"));
|
2013-03-29 15:35:54 -04:00
|
|
|
|
2014-01-18 09:23:55 -05:00
|
|
|
QCommandLineOption configOption("config",
|
|
|
|
QCoreApplication::translate("main", "path to a custom config file"),
|
|
|
|
"config");
|
|
|
|
QCommandLineOption keyfileOption("keyfile",
|
|
|
|
QCoreApplication::translate("main", "key file of the database"),
|
|
|
|
"keyfile");
|
|
|
|
|
|
|
|
parser.addHelpOption();
|
2014-01-18 09:31:24 -05:00
|
|
|
parser.addVersionOption();
|
2014-01-18 09:23:55 -05:00
|
|
|
parser.addOption(configOption);
|
|
|
|
parser.addOption(keyfileOption);
|
|
|
|
|
|
|
|
parser.process(app);
|
|
|
|
const QStringList args = parser.positionalArguments();
|
|
|
|
|
|
|
|
if (parser.isSet(configOption)) {
|
|
|
|
Config::createConfigFromFile(parser.value(configOption));
|
2012-04-24 05:47:16 -04:00
|
|
|
}
|
|
|
|
|
2014-05-17 19:33:22 -04:00
|
|
|
Translator::installTranslator();
|
|
|
|
|
2013-03-30 06:16:24 -04:00
|
|
|
#ifdef Q_OS_MAC
|
|
|
|
// Don't show menu icons on OSX
|
|
|
|
QApplication::setAttribute(Qt::AA_DontShowIconsInMenus);
|
|
|
|
#endif
|
|
|
|
|
2010-09-19 10:59:32 -04:00
|
|
|
MainWindow mainWindow;
|
|
|
|
mainWindow.show();
|
2015-10-10 11:00:50 -04:00
|
|
|
app.setMainWindow(&mainWindow);
|
2010-08-07 09:10:44 -04:00
|
|
|
|
2012-05-21 16:11:26 -04:00
|
|
|
QObject::connect(&app, SIGNAL(openFile(QString)), &mainWindow, SLOT(openDatabase(QString)));
|
2012-05-17 17:59:31 -04:00
|
|
|
|
2014-01-18 09:23:55 -05:00
|
|
|
if (!args.isEmpty()) {
|
|
|
|
QString filename = args[0];
|
|
|
|
if (!filename.isEmpty() && QFile::exists(filename)) {
|
2015-07-17 15:31:36 -04:00
|
|
|
mainWindow.openDatabase(filename, QString(), parser.value(keyfileOption));
|
2014-01-18 09:23:55 -05:00
|
|
|
}
|
2012-04-24 05:47:16 -04:00
|
|
|
}
|
|
|
|
|
2013-04-18 16:15:01 -04:00
|
|
|
if (config()->get("OpenPreviousDatabasesOnStartup").toBool()) {
|
2013-04-27 05:19:40 -04:00
|
|
|
QStringList filenames = config()->get("LastOpenedDatabases").toStringList();
|
2013-04-18 16:15:01 -04:00
|
|
|
Q_FOREACH (const QString& filename, filenames) {
|
|
|
|
if (!filename.isEmpty() && QFile::exists(filename)) {
|
2013-04-18 16:15:01 -04:00
|
|
|
mainWindow.openDatabase(filename, QString(), QString());
|
2013-04-18 16:15:01 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-15 06:31:48 -04:00
|
|
|
return app.exec();
|
2010-08-07 09:10:44 -04:00
|
|
|
}
|