fixed #1644319
git-svn-id: https://svn.code.sf.net/p/keepassx/code/trunk@143 b624d157-de02-0410-bad0-e51aec6abb33
This commit is contained in:
parent
bbdf870dbe
commit
babeb3e057
95
src/main.cpp
95
src/main.cpp
|
@ -1,11 +1,12 @@
|
||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
|
* Copyright (C) 1992-2007 Trolltech ASA *
|
||||||
|
* *
|
||||||
* Copyright (C) 2005-2007 by Tarek Saidi *
|
* Copyright (C) 2005-2007 by Tarek Saidi *
|
||||||
* tarek.saidi@arcor.de *
|
* tarek.saidi@arcor.de *
|
||||||
* *
|
* *
|
||||||
* This program is free software; you can redistribute it and/or modify *
|
* 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 *
|
* it under the terms of the GNU General Public License as published by *
|
||||||
* the Free Software Foundation; either version 2 of the License, or *
|
* the Free Software Foundation; version 2 of the License. *
|
||||||
* (at your option) any later version. *
|
|
||||||
* *
|
* *
|
||||||
* This program is distributed in the hope that it will be useful, *
|
* This program is distributed in the hope that it will be useful, *
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||||
|
@ -70,6 +71,7 @@ QString DetailViewTemplate;
|
||||||
|
|
||||||
QPixmap* EntryIcons;
|
QPixmap* EntryIcons;
|
||||||
IIconTheme* IconLoader=NULL;
|
IIconTheme* IconLoader=NULL;
|
||||||
|
char ** argv;
|
||||||
|
|
||||||
inline void loadImages();
|
inline void loadImages();
|
||||||
inline void parseCmdLineArgs(int argc, char** argv,QString &ArgFile,QString& ArgCfg,QString& ArgLang);
|
inline void parseCmdLineArgs(int argc, char** argv,QString &ArgFile,QString& ArgCfg,QString& ArgLang);
|
||||||
|
@ -95,15 +97,14 @@ void test_getAllWindowTitles(){
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **_argv)
|
||||||
{
|
{
|
||||||
//test_getAllWindowTitles();
|
argv=_argv;
|
||||||
//exit(0);
|
|
||||||
QString ArgFile,ArgCfg,ArgLang,IniFilename;
|
QString ArgFile,ArgCfg,ArgLang,IniFilename;
|
||||||
QApplication* app=NULL;
|
QApplication* app=NULL;
|
||||||
AppDir=QString(argv[0]);
|
AppDir=applicationDirPath();
|
||||||
AppDir.truncate(AppDir.lastIndexOf("/"));
|
|
||||||
parseCmdLineArgs(argc,argv,ArgFile,ArgCfg,ArgLang);
|
parseCmdLineArgs(argc,argv,ArgFile,ArgCfg,ArgLang);
|
||||||
|
qDebug(CSTR(QDir::current().absolutePath()));
|
||||||
|
|
||||||
//Load Config
|
//Load Config
|
||||||
if(ArgCfg.isEmpty()){
|
if(ArgCfg.isEmpty()){
|
||||||
|
@ -478,3 +479,83 @@ QString makePathRelative(const QString& AbsDir,const QString& CurDir){
|
||||||
rel.append(abs[i]+"/");
|
rel.append(abs[i]+"/");
|
||||||
return rel;
|
return rel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QString applicationDirPath(){
|
||||||
|
QString filepath=applicationFilePath();
|
||||||
|
filepath.truncate(filepath.lastIndexOf("/"));
|
||||||
|
return filepath;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString applicationFilePath()
|
||||||
|
{
|
||||||
|
#if defined( Q_WS_WIN )
|
||||||
|
QFileInfo filePath;
|
||||||
|
QT_WA({
|
||||||
|
wchar_t module_name[256];
|
||||||
|
GetModuleFileNameW(0, module_name, sizeof(module_name) / sizeof(wchar_t));
|
||||||
|
filePath = QString::fromUtf16((ushort *)module_name);
|
||||||
|
}, {
|
||||||
|
char module_name[256];
|
||||||
|
GetModuleFileNameA(0, module_name, sizeof(module_name));
|
||||||
|
filePath = QString::fromLocal8Bit(module_name);
|
||||||
|
});
|
||||||
|
|
||||||
|
return filePath.filePath();
|
||||||
|
#elif defined(Q_WS_MAC)
|
||||||
|
QString qAppFileName_str = qAppFileName();
|
||||||
|
if(!qAppFileName_str.isEmpty()) {
|
||||||
|
QFileInfo fi(qAppFileName_str);
|
||||||
|
return fi.exists() ? fi.canonicalFilePath() : QString();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#if defined( Q_OS_UNIX )
|
||||||
|
#ifdef Q_OS_LINUX
|
||||||
|
// Try looking for a /proc/<pid>/exe symlink first which points to
|
||||||
|
// the absolute path of the executable
|
||||||
|
QFileInfo pfi(QString::fromLatin1("/proc/%1/exe").arg(getpid()));
|
||||||
|
if (pfi.exists() && pfi.isSymLink())
|
||||||
|
return pfi.canonicalFilePath();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
QString argv0 = QFile::decodeName(QByteArray(argv[0]));
|
||||||
|
QString absPath;
|
||||||
|
|
||||||
|
if (!argv0.isEmpty() && argv0.at(0) == QLatin1Char('/')) {
|
||||||
|
/*
|
||||||
|
If argv0 starts with a slash, it is already an absolute
|
||||||
|
file path.
|
||||||
|
*/
|
||||||
|
absPath = argv0;
|
||||||
|
} else if (argv0.contains(QLatin1Char('/'))) {
|
||||||
|
/*
|
||||||
|
If argv0 contains one or more slashes, it is a file path
|
||||||
|
relative to the current directory.
|
||||||
|
*/
|
||||||
|
absPath = QDir::current().absoluteFilePath(argv0);
|
||||||
|
} else {
|
||||||
|
/*
|
||||||
|
Otherwise, the file path has to be determined using the
|
||||||
|
PATH environment variable.
|
||||||
|
*/
|
||||||
|
QByteArray pEnv = qgetenv("PATH");
|
||||||
|
QDir currentDir = QDir::current();
|
||||||
|
QStringList paths = QString::fromLocal8Bit(pEnv.constData()).split(QLatin1String(":"));
|
||||||
|
for (QStringList::const_iterator p = paths.constBegin(); p != paths.constEnd(); ++p) {
|
||||||
|
if ((*p).isEmpty())
|
||||||
|
continue;
|
||||||
|
QString candidate = currentDir.absoluteFilePath(*p + QLatin1Char('/') + argv0);
|
||||||
|
QFileInfo candidate_fi(candidate);
|
||||||
|
if (candidate_fi.exists() && !candidate_fi.isDir()) {
|
||||||
|
absPath = candidate;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
absPath = QDir::cleanPath(absPath);
|
||||||
|
|
||||||
|
QFileInfo fi(absPath);
|
||||||
|
return fi.exists() ? fi.canonicalFilePath() : QString();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
|
@ -40,6 +40,8 @@ void createBanner(QPixmap* Pixmap, const QPixmap* IconAlpha,const QString& Text,
|
||||||
void createBanner(QPixmap* Pixmap, const QPixmap* IconAlpha,const QString& Text,int Width, QColor Color1, QColor Color2, QColor TextColor);
|
void createBanner(QPixmap* Pixmap, const QPixmap* IconAlpha,const QString& Text,int Width, QColor Color1, QColor Color2, QColor TextColor);
|
||||||
void openBrowser(QString url);
|
void openBrowser(QString url);
|
||||||
void showErrMsg(const QString& msg,QWidget* parent=NULL);
|
void showErrMsg(const QString& msg,QWidget* parent=NULL);
|
||||||
|
QString applicationFilePath();
|
||||||
|
QString applicationDirPath();
|
||||||
const QIcon& getIcon(const QString& name);
|
const QIcon& getIcon(const QString& name);
|
||||||
const QPixmap* getPixmap(const QString& name);
|
const QPixmap* getPixmap(const QString& name);
|
||||||
QString decodeFileError(QFile::FileError Code);
|
QString decodeFileError(QFile::FileError Code);
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
#include <QHash>
|
#include <QHash>
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
#include <kurl.h>
|
#include <kurl.h>
|
||||||
|
#include <QByteArray>
|
||||||
#include "keepassx-kde.h"
|
#include "keepassx-kde.h"
|
||||||
|
|
||||||
QHash<QString,QString>IconMap;
|
QHash<QString,QString>IconMap;
|
||||||
|
@ -100,7 +101,11 @@ QStringList KdePlugin::openExistingFilesDialog(QWidget* parent,QString title,QSt
|
||||||
QString KdePlugin::saveFileDialog(QWidget* parent,QString title,QString dir,QStringList Filters,int SelectedFilter,bool OverWriteWarn){return QString();}
|
QString KdePlugin::saveFileDialog(QWidget* parent,QString title,QString dir,QStringList Filters,int SelectedFilter,bool OverWriteWarn){return QString();}
|
||||||
|
|
||||||
QApplication* KdePlugin::getMainAppObject(int argc, char** argv){
|
QApplication* KdePlugin::getMainAppObject(int argc, char** argv){
|
||||||
KCmdLineArgs::init(argc,argv,"keepassx","KeePassX","Cross Platform Password Manager","0.2.3");
|
KCmdLineArgs::init(argc,argv,QByteArray("keepassx"),
|
||||||
|
QByteArray("none"),
|
||||||
|
ki18n("KeePassX"),
|
||||||
|
QByteArray("0.2.3"),
|
||||||
|
ki18n("Cross Platform Password Manager"));
|
||||||
createIconMap();
|
createIconMap();
|
||||||
return dynamic_cast<QApplication*>( new KApplication() );
|
return dynamic_cast<QApplication*>( new KApplication() );
|
||||||
}
|
}
|
||||||
|
@ -108,7 +113,7 @@ QApplication* KdePlugin::getMainAppObject(int argc, char** argv){
|
||||||
|
|
||||||
QIcon KdePlugin::getIcon(const QString& name){
|
QIcon KdePlugin::getIcon(const QString& name){
|
||||||
KIconLoader loader;
|
KIconLoader loader;
|
||||||
QPixmap pxm=loader.loadIcon(IconMap.value(name),K3Icon::Desktop,0,K3Icon::DefaultState,NULL, true);
|
QPixmap pxm=loader.loadIcon(IconMap.value(name),K3Icon::Desktop,0,K3Icon::DefaultState,QStringList(),NULL,true);
|
||||||
if(pxm.isNull())return QIcon();
|
if(pxm.isNull())return QIcon();
|
||||||
QIcon icon(pxm);
|
QIcon icon(pxm);
|
||||||
return icon;
|
return icon;
|
||||||
|
|
|
@ -1,4 +1,7 @@
|
||||||
INCLUDEPATH += /usr/lib/kde4/include
|
isEmpty(KDEDIR){
|
||||||
|
KDEDIR=/usr
|
||||||
|
}
|
||||||
|
INCLUDEPATH += $$(KDEDIR)/include
|
||||||
TEMPLATE = lib
|
TEMPLATE = lib
|
||||||
CONFIG += plugin release
|
CONFIG += plugin release
|
||||||
HEADERS += keepassx-kde.h
|
HEADERS += keepassx-kde.h
|
||||||
|
@ -6,4 +9,4 @@ SOURCES += keepassx-kde.cpp
|
||||||
MOC_DIR = ../../../build/moc
|
MOC_DIR = ../../../build/moc
|
||||||
OBJECTS_DIR = ../../../build
|
OBJECTS_DIR = ../../../build
|
||||||
TARGET = ../../../lib/keepassx-kde
|
TARGET = ../../../lib/keepassx-kde
|
||||||
LIBS+=-L/usr/lib/kde4/lib -lkio -lkdecore
|
LIBS+=-L$$KDEDIR/lib -lkio -lkdecore
|
Loading…
Reference in New Issue