Fix very obscure bug that corrupted the input of non-ascii characters.

This is caused by calling QFileInfo::canonicalFilePath() before creating the QApplication object.
So now the first thing we do is creating the QApplication object. This breaks the kde plugin, which we are not using anyway.

git-svn-id: https://svn.code.sf.net/p/keepassx/code/trunk@275 b624d157-de02-0410-bad0-e51aec6abb33
master
sniperbeamer 16 years ago
parent d569b51e6c
commit e531a8a7ff
  1. 14
      src/CMakeLists.txt
  2. 81
      src/main.cpp
  3. 6
      src/src.pro

@ -131,13 +131,13 @@ set(keepassx_TRANSLATIONS
translations/keepassx-tr_TR.ts
)
IF( MINGW )
SET(keepassx_SOURCES ${keepassx_SOURCES} main_win32.cpp)
ELSEIF( APPLE )
SET(keepassx_SOURCES ${keepassx_SOURCES} main_macx.cpp)
ELSE( MINGW )
SET(keepassx_SOURCES ${keepassx_SOURCES} main_unix.cpp)
ENDIF( MINGW )
#IF( MINGW )
# SET(keepassx_SOURCES ${keepassx_SOURCES} main_win32.cpp)
#ELSEIF( APPLE )
# SET(keepassx_SOURCES ${keepassx_SOURCES} main_macx.cpp)
#ELSE( MINGW )
# SET(keepassx_SOURCES ${keepassx_SOURCES} main_unix.cpp)
#ENDIF( MINGW )
IF( AUTOTYPE )
SET(keepassx_HEADERS ${keepassx_HEADERS}

@ -48,14 +48,42 @@ IIconTheme* IconLoader=NULL;
int main(int argc, char **argv)
{
QApplication* app=NULL;
initAppPaths(argc,argv);
#if defined(Q_WS_X11) && defined(GLOBAL_AUTOTYPE)
QApplication* app = new KeepassApplication(argc,argv);
#else
QApplication* app = new QApplication(argc,argv);
#endif
AppDir = QApplication::applicationFilePath();
AppDir.truncate(AppDir.lastIndexOf("/"));
#if defined(Q_WS_X11)
DataDir=AppDir+"/../share/keepassx";
if (!QFile::exists(DataDir) && QFile::exists(AppDir+"/share"))
DataDir=AppDir+"/share";
HomeDir = QDir::homePath()+"/.keepassx";
#elif defined(Q_WS_MAC)
HomeDir = QDir::homePath()+"/.keepassx";
DataDir=AppDir+"/../Resources/keepassx";
#else //Q_WS_WIN
HomeDir = QString::fromLocal8Bit(qgetenv("APPDATA").constData());
if(!HomeDir.isEmpty() && QFile::exists(HomeDir))
HomeDir = QDir::fromNativeSeparators(HomeDir)+"/KeePassX";
else
HomeDir = QDir::homePath()+"/KeePassX";
DataDir=AppDir+"/share";
#endif
CmdLineArgs args;
if(!args.preparse(argc,argv)){ // searches only for the -cfg parameter
if ( !args.parse(QApplication::arguments()) ){
qCritical("%s\n", CSTR( args.error() ));
args.printHelp();
return 1;
}
if (args.help()){
args.printHelp();
return 1;
}
//Load Config
QString IniFilename;
@ -120,22 +148,6 @@ int main(int argc, char **argv)
}
#endif
*/
if(!app){
#if defined(Q_WS_X11) && defined(GLOBAL_AUTOTYPE)
app = new KeepassApplication(argc,argv);
#else
app = new QApplication(argc,argv);
#endif
}
if ( !args.parse(QApplication::arguments()) ){
qCritical("%s\n", CSTR( args.error() ));
args.printHelp();
return 1;
}
if (args.help()){
args.printHelp();
return 1;
}
DetailViewTemplate=config->detailViewTemplate();
@ -190,7 +202,16 @@ bool CmdLineArgs::parse(const QStringList& argv){
break; // break, because other arguments will be ignored anyway
}
if(argv[i]=="-cfg"){
//already done in preparse() -> skip
if(argv.size() == i+1){
Error="Missing argument for '-cfg'.";
return false;
}
if(argv[i+1].left(1)=="-"){
Error=QString("Expected a path as argument for '-cfg' but got '%1.'").arg(argv[i+1]);
return false;
}
QFileInfo file(argv[i+1]);
ConfigLocation=file.absoluteFilePath();
i++;
continue;
}
@ -212,26 +233,6 @@ bool CmdLineArgs::parse(const QStringList& argv){
return true;
}
bool CmdLineArgs::preparse(int argc,char** argv){
for(int i=1;i<argc;i++){
if(QString(argv[i])=="-cfg"){
if(argc==i+1){
Error="Missing argument for '-cfg'.";
return false;
}
if(QString(argv[i+1]).left(1)=="-"){
Error=QString("Expected a path as argument for '-cfg' but got '%1.'").arg(argv[i+1]);
return false;
}
QFileInfo file(argv[i+1]);
ConfigLocation=file.absoluteFilePath();
i++;
return true;
}
}
return true;
}
void CmdLineArgs::printHelp(){
cerr << "KeePassX " << APP_VERSION << endl;
cerr << "Usage: keepassx [filename] [options]" << endl;

@ -56,7 +56,7 @@ unix : !macx : !isEqual(QMAKE_WIN32,1){
SOURCES += Application_X11.cpp lib/AutoTypeGlobalX11.cpp
HEADERS += Application_X11.h lib/AutoTypeGlobalX11.h
}
SOURCES += main_unix.cpp
# SOURCES += main_unix.cpp
}
@ -90,7 +90,7 @@ macx {
}
isEqual(ARCH,INTEL): CONFIG += x86
isEqual(ARCH,PPC): CONFIG += ppc
SOURCES += main_macx.cpp
# SOURCES += main_macx.cpp
}
#-------------------------------------------------------------------------------
@ -110,7 +110,7 @@ isEqual(QMAKE_WIN32,1){
}
RC_FILE = ../share/win_ico/keepassx.rc
QMAKE_LINK_OBJECT_SCRIPT = $${OBJECTS_DIR}/$${QMAKE_LINK_OBJECT_SCRIPT}
SOURCES += main_win32.cpp
# SOURCES += main_win32.cpp
}