2010-08-07 13:10:44 +00: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/>.
*/
2015-07-22 15:02:50 +00:00
# include <QCommandLineParser>
2013-10-03 13:18:16 +00:00
# include <QFile>
2016-10-24 18:22:02 +00:00
# include <QTextStream>
2010-08-15 10:31:48 +00:00
2014-01-18 14:31:24 +00:00
# include "config-keepassx.h"
2013-03-29 19:35:54 +00:00
# include "core/Config.h"
2012-10-13 09:05:50 +00:00
# include "core/Tools.h"
2014-05-17 23:33:22 +00:00
# include "core/Translator.h"
2010-09-13 21:25:48 +00:00
# include "crypto/Crypto.h"
2012-05-17 22:35:24 +00:00
# include "gui/Application.h"
2010-09-19 14:59:32 +00:00
# include "gui/MainWindow.h"
2014-06-15 09:17:40 +00:00
# include "gui/MessageBox.h"
2010-08-15 10:31:48 +00:00
2012-05-02 15:04:03 +00:00
int main ( int argc , char * * argv )
2010-08-07 13:10:44 +00:00
{
2012-10-13 09:05:50 +00:00
# ifdef QT_NO_DEBUG
Tools : : disableCoreDumps ( ) ;
# endif
2015-12-06 13:32:06 +00:00
Tools : : setupSearchPaths ( ) ;
2012-10-13 09:05:50 +00:00
2012-05-17 22:35:24 +00:00
Application app ( argc , argv ) ;
2016-11-03 04:05:30 +00:00
Application : : setApplicationName ( " keepassxc " ) ;
2014-01-18 14:31:24 +00:00
Application : : setApplicationVersion ( KEEPASSX_VERSION ) ;
// don't set organizationName as that changes the return value of
2015-09-12 16:41:48 +00:00
// QStandardPaths::writableLocation(QDesktopServices::DataLocation)
2010-08-15 10:31:48 +00:00
2014-11-02 09:15:44 +00:00
QApplication : : setQuitOnLastWindowClosed ( false ) ;
2014-06-15 09:17:40 +00:00
if ( ! Crypto : : init ( ) ) {
QString error = QCoreApplication : : translate ( " Main " ,
" Fatal error while testing the cryptographic functions. " ) ;
error . append ( " \n " ) ;
error . append ( Crypto : : errorString ( ) ) ;
2016-11-03 04:05:30 +00:00
MessageBox : : critical ( nullptr , QCoreApplication : : translate ( " Main " , " KeePassXC - Error " ) , error ) ;
2014-06-15 09:17:40 +00:00
return 1 ;
}
2010-09-13 21:25:48 +00:00
2014-01-18 14:23:55 +00:00
QCommandLineParser parser ;
2016-11-03 04:05:30 +00:00
parser . setApplicationDescription ( QCoreApplication : : translate ( " main " , " KeePassXC - cross-platform password manager " ) ) ;
2015-06-23 09:40:54 +00:00
parser . addPositionalArgument ( " filename " , QCoreApplication : : translate ( " main " , " filename(s) of the password database(s) to open (*.kdbx) " ) , " [filename(s)] " ) ;
2013-03-29 19:35:54 +00:00
2014-01-18 14:23:55 +00: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 " ) ;
2016-10-24 18:22:02 +00:00
QCommandLineOption pwstdinOption ( " pw-stdin " ,
QCoreApplication : : translate ( " main " , " read password of the database from stdin " ) ) ;
2014-01-18 14:23:55 +00:00
parser . addHelpOption ( ) ;
2014-01-18 14:31:24 +00:00
parser . addVersionOption ( ) ;
2014-01-18 14:23:55 +00:00
parser . addOption ( configOption ) ;
parser . addOption ( keyfileOption ) ;
2016-10-24 18:22:02 +00:00
parser . addOption ( pwstdinOption ) ;
2014-01-18 14:23:55 +00:00
parser . process ( app ) ;
const QStringList args = parser . positionalArguments ( ) ;
if ( parser . isSet ( configOption ) ) {
Config : : createConfigFromFile ( parser . value ( configOption ) ) ;
2012-04-24 09:47:16 +00:00
}
2014-05-17 23:33:22 +00:00
Translator : : installTranslator ( ) ;
2013-03-30 10:16:24 +00:00
# ifdef Q_OS_MAC
// Don't show menu icons on OSX
QApplication : : setAttribute ( Qt : : AA_DontShowIconsInMenus ) ;
# endif
2010-09-19 14:59:32 +00:00
MainWindow mainWindow ;
2015-10-10 15:00:50 +00:00
app . setMainWindow ( & mainWindow ) ;
2016-11-23 23:15:51 +00:00
mainWindow . show ( ) ;
2012-05-21 20:11:26 +00:00
QObject : : connect ( & app , SIGNAL ( openFile ( QString ) ) , & mainWindow , SLOT ( openDatabase ( QString ) ) ) ;
2016-11-23 23:15:51 +00:00
2016-11-26 14:37:25 +00:00
// start minimized if configured
if ( config ( ) - > get ( " GUI/MinimizeOnStartup " ) . toBool ( ) ) {
mainWindow . setWindowState ( Qt : : WindowMinimized ) ;
}
2015-06-23 09:40:54 +00:00
for ( int ii = 0 ; ii < args . length ( ) ; ii + + ) {
QString filename = args [ ii ] ;
2014-01-18 14:23:55 +00:00
if ( ! filename . isEmpty ( ) & & QFile : : exists ( filename ) ) {
2016-10-24 18:22:02 +00:00
QString password ;
if ( parser . isSet ( pwstdinOption ) ) {
static QTextStream in ( stdin , QIODevice : : ReadOnly ) ;
password = in . readLine ( ) ;
}
mainWindow . openDatabase ( filename , password , parser . value ( keyfileOption ) ) ;
2014-01-18 14:23:55 +00:00
}
2012-04-24 09:47:16 +00:00
}
2013-04-18 20:15:01 +00:00
if ( config ( ) - > get ( " OpenPreviousDatabasesOnStartup " ) . toBool ( ) ) {
2016-09-02 17:51:51 +00:00
const QStringList filenames = config ( ) - > get ( " LastOpenedDatabases " ) . toStringList ( ) ;
for ( const QString & filename : filenames ) {
2013-04-18 20:15:01 +00:00
if ( ! filename . isEmpty ( ) & & QFile : : exists ( filename ) ) {
2013-04-18 20:15:01 +00:00
mainWindow . openDatabase ( filename , QString ( ) , QString ( ) ) ;
2013-04-18 20:15:01 +00:00
}
}
}
2016-11-23 23:15:51 +00:00
2010-08-15 10:31:48 +00:00
return app . exec ( ) ;
2010-08-07 13:10:44 +00:00
}