XDG compliant config location on Linux
Better way to detect APPDATA path on Windows Optimize global include file git-svn-id: https://svn.code.sf.net/p/keepassx/code/trunk@282 b624d157-de02-0410-bad0-e51aec6abb33
This commit is contained in:
parent
c614192a48
commit
c6fbc412be
|
@ -21,7 +21,6 @@
|
|||
|
||||
#include "crypto/twoclass.h"
|
||||
#include <QBuffer>
|
||||
#include <QTextCodec>
|
||||
|
||||
#define UNEXP_ERROR error=QString("Unexpected error in: %1, Line:%2").arg(__FILE__).arg(__LINE__);
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
#ifndef KEEPASSX_H_
|
||||
#define KEEPASSX_H_
|
||||
|
||||
// global defines
|
||||
// global defines
|
||||
|
||||
#define APP_DISPLAY_NAME "KeePassX"
|
||||
#define APP_CODE_NAME "keepassx"
|
||||
|
@ -35,11 +35,8 @@
|
|||
#ifdef __cplusplus
|
||||
|
||||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
|
||||
#include <cassert>
|
||||
#include <cmath>
|
||||
#include <ctime>
|
||||
|
||||
#include <QApplication>
|
||||
#include <QBitArray>
|
||||
|
@ -67,6 +64,7 @@
|
|||
#include <QSettings>
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
#include <QTextCodec>
|
||||
#include <QTimer>
|
||||
#include <QTreeWidget>
|
||||
#include <QUrl>
|
||||
|
|
|
@ -18,10 +18,8 @@
|
|||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#include "WaitAnimationWidget.h"
|
||||
|
||||
|
||||
WaitAnimationWidget::WaitAnimationWidget(QWidget* parent):QWidget(parent){
|
||||
speed=60;
|
||||
setRefreshRate(25);
|
||||
|
@ -94,4 +92,3 @@ void WaitAnimationWidget::resizeEvent(QResizeEvent* event){
|
|||
CircPositions[i].setY((r-10)*sin(-2.0*3.14159265*(0.16666667*i))+r);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -363,3 +363,32 @@ QList<Translation> getAllTranslations(){
|
|||
qSort(translations.begin(), translations.end());
|
||||
return translations;
|
||||
}
|
||||
|
||||
// from src/corelib/qsettings.cpp:
|
||||
#ifdef Q_OS_WIN
|
||||
QString qtWindowsConfigPath(int type)
|
||||
{
|
||||
QString result;
|
||||
|
||||
QLibrary library(QLatin1String("shell32"));
|
||||
QT_WA( {
|
||||
typedef BOOL (WINAPI*GetSpecialFolderPath)(HWND, LPTSTR, int, BOOL);
|
||||
GetSpecialFolderPath SHGetSpecialFolderPath = (GetSpecialFolderPath)library.resolve("SHGetSpecialFolderPathW");
|
||||
if (SHGetSpecialFolderPath) {
|
||||
TCHAR path[MAX_PATH];
|
||||
SHGetSpecialFolderPath(0, path, type, FALSE);
|
||||
result = QString::fromUtf16((ushort*)path);
|
||||
}
|
||||
} , {
|
||||
typedef BOOL (WINAPI*GetSpecialFolderPath)(HWND, char*, int, BOOL);
|
||||
GetSpecialFolderPath SHGetSpecialFolderPath = (GetSpecialFolderPath)library.resolve("SHGetSpecialFolderPathA");
|
||||
if (SHGetSpecialFolderPath) {
|
||||
char path[MAX_PATH];
|
||||
SHGetSpecialFolderPath(0, path, type, FALSE);
|
||||
result = QString::fromLocal8Bit(path);
|
||||
}
|
||||
} );
|
||||
|
||||
return result;
|
||||
}
|
||||
#endif // Q_OS_WIN
|
||||
|
|
|
@ -19,8 +19,6 @@
|
|||
#ifndef TOOLS_H
|
||||
#define TOOLS_H
|
||||
|
||||
#define CSTR(x)(x.toLocal8Bit().constData())
|
||||
|
||||
class IEntryHandle;
|
||||
|
||||
enum tKeyType {PASSWORD=0,KEYFILE=1,BOTH=2};
|
||||
|
@ -32,10 +30,15 @@ struct Translation {
|
|||
};
|
||||
bool operator<(const Translation& t1, const Translation& t2);
|
||||
|
||||
inline const char* CSTR(const QString& str) {
|
||||
return QTextCodec::codecForLocale()->fromUnicode(str).constData();
|
||||
}
|
||||
|
||||
const QIcon& getIcon(const QString& name);
|
||||
const QPixmap* getPixmap(const QString& name);
|
||||
void createBanner(QPixmap* Pixmap, const QPixmap* IconAlpha,const QString& Text,int Width);
|
||||
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(const QString& UrlString);
|
||||
void openBrowser(IEntryHandle* entry);
|
||||
void showErrMsg(const QString& msg,QWidget* parent=NULL);
|
||||
|
@ -48,5 +51,11 @@ bool unlockPage(void* addr, int len);
|
|||
void installTranslator();
|
||||
bool isTranslationActive();
|
||||
QList<Translation> getAllTranslations();
|
||||
#ifdef Q_OS_WIN
|
||||
#ifndef CSIDL_APPDATA
|
||||
#define CSIDL_APPDATA 0x001a // <username>\Application Data
|
||||
#endif
|
||||
QString qtWindowsConfigPath(int type);
|
||||
#endif
|
||||
|
||||
#endif //TOOLS_H
|
||||
|
|
51
src/main.cpp
51
src/main.cpp
|
@ -19,17 +19,18 @@
|
|||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
|
||||
#include "main.h"
|
||||
#include "mainwindow.h"
|
||||
#if defined(Q_WS_X11) && defined(GLOBAL_AUTOTYPE)
|
||||
#include "Application_X11.h"
|
||||
#endif
|
||||
|
||||
#include "plugins/interfaces/IFileDialog.h"
|
||||
#include "plugins/interfaces/IKdeInit.h"
|
||||
#include "plugins/interfaces/IGnomeInit.h"
|
||||
|
||||
|
||||
//#include <QPluginLoader>
|
||||
#include "mainwindow.h"
|
||||
#include "main.h"
|
||||
#if defined(Q_WS_X11) && defined(GLOBAL_AUTOTYPE)
|
||||
#include "Application_X11.h"
|
||||
#endif
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
@ -48,6 +49,8 @@ IIconTheme* IconLoader=NULL;
|
|||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
setlocale(LC_CTYPE, "");
|
||||
|
||||
QT_REQUIRE_VERSION(argc, argv, "4.3.0");
|
||||
|
||||
#if defined(Q_WS_X11) && defined(GLOBAL_AUTOTYPE)
|
||||
|
@ -59,22 +62,34 @@ int main(int argc, char **argv)
|
|||
AppDir = QApplication::applicationFilePath();
|
||||
AppDir.truncate(AppDir.lastIndexOf("/"));
|
||||
#if defined(Q_WS_X11)
|
||||
DataDir=AppDir+"/../share/keepassx";
|
||||
DataDir = AppDir+"/../share/keepassx";
|
||||
if (!QFile::exists(DataDir) && QFile::exists(AppDir+"/share"))
|
||||
DataDir=AppDir+"/share";
|
||||
HomeDir = QDir::homePath()+"/.keepassx";
|
||||
DataDir = AppDir+"/share";
|
||||
const char* env = getenv("XDG_CONFIG_HOME");
|
||||
if (!env) {
|
||||
HomeDir = QDir::homePath() + "/.config";
|
||||
}
|
||||
else {
|
||||
QString qenv = QTextCodec::codecForLocale()->toUnicode(env);
|
||||
if (qenv[0] == '/')
|
||||
HomeDir = qenv;
|
||||
else
|
||||
HomeDir = QDir::homePath() + '/' + qenv;
|
||||
}
|
||||
HomeDir += "/keepassx";
|
||||
#elif defined(Q_WS_MAC)
|
||||
HomeDir = QDir::homePath()+"/.keepassx";
|
||||
DataDir=AppDir+"/../Resources/keepassx";
|
||||
DataDir = AppDir+"/../Resources/keepassx";
|
||||
#else //Q_WS_WIN
|
||||
HomeDir = QString::fromLocal8Bit(qgetenv("APPDATA").constData());
|
||||
HomeDir = qtWindowsConfigPath(CSIDL_APPDATA);
|
||||
if(!HomeDir.isEmpty() && QFile::exists(HomeDir))
|
||||
HomeDir = QDir::fromNativeSeparators(HomeDir)+"/KeePassX";
|
||||
else
|
||||
HomeDir = QDir::homePath()+"/KeePassX";
|
||||
|
||||
DataDir=AppDir+"/share";
|
||||
DataDir = AppDir+"/share";
|
||||
#endif
|
||||
DataDir = QDir::cleanPath(DataDir);
|
||||
|
||||
CmdLineArgs args;
|
||||
if ( !args.parse(QApplication::arguments()) ){
|
||||
|
@ -95,11 +110,21 @@ int main(int argc, char **argv)
|
|||
if(!QDir().mkpath(HomeDir))
|
||||
qWarning("Warning: Could not create directory '%s'", CSTR(HomeDir));
|
||||
}
|
||||
IniFilename=HomeDir+"/config";
|
||||
IniFilename=HomeDir+"/config.ini";
|
||||
}
|
||||
else
|
||||
IniFilename=args.configLocation();
|
||||
|
||||
#ifdef Q_WS_X11
|
||||
{
|
||||
QString OldHomeDir = QDir::homePath()+"/.keepassx";
|
||||
if (args.configLocation().isEmpty() && QFile::exists(OldHomeDir+"/config") && !QFile::exists(HomeDir+"/config"))
|
||||
QFile::rename(OldHomeDir+"/config", HomeDir+"/config.ini");
|
||||
}
|
||||
#else
|
||||
if (args.configLocation().isEmpty() && QFile::exists(HomeDir+"/config") && !QFile::exists(HomeDir+"/config.ini"))
|
||||
QFile::rename(HomeDir+"/config", HomeDir+"/config.ini");
|
||||
#endif
|
||||
config = new KpxConfig(IniFilename);
|
||||
fileDlgHistory.load();
|
||||
|
||||
|
|
Loading…
Reference in New Issue