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
master
sniperbeamer 16 years ago
parent c614192a48
commit c6fbc412be
  1. 1
      src/Kdb3Database.cpp
  2. 4
      src/keepassx.h
  3. 3
      src/lib/WaitAnimationWidget.cpp
  4. 29
      src/lib/tools.cpp
  5. 15
      src/lib/tools.h
  6. 43
      src/main.cpp

@ -21,7 +21,6 @@
#include "crypto/twoclass.h" #include "crypto/twoclass.h"
#include <QBuffer> #include <QBuffer>
#include <QTextCodec>
#define UNEXP_ERROR error=QString("Unexpected error in: %1, Line:%2").arg(__FILE__).arg(__LINE__); #define UNEXP_ERROR error=QString("Unexpected error in: %1, Line:%2").arg(__FILE__).arg(__LINE__);

@ -35,11 +35,8 @@
#ifdef __cplusplus #ifdef __cplusplus
#include <cstdlib> #include <cstdlib>
#include <iostream>
#include <cassert>
#include <cmath> #include <cmath>
#include <ctime>
#include <QApplication> #include <QApplication>
#include <QBitArray> #include <QBitArray>
@ -67,6 +64,7 @@
#include <QSettings> #include <QSettings>
#include <QString> #include <QString>
#include <QStringList> #include <QStringList>
#include <QTextCodec>
#include <QTimer> #include <QTimer>
#include <QTreeWidget> #include <QTreeWidget>
#include <QUrl> #include <QUrl>

@ -18,10 +18,8 @@
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/ ***************************************************************************/
#include "WaitAnimationWidget.h" #include "WaitAnimationWidget.h"
WaitAnimationWidget::WaitAnimationWidget(QWidget* parent):QWidget(parent){ WaitAnimationWidget::WaitAnimationWidget(QWidget* parent):QWidget(parent){
speed=60; speed=60;
setRefreshRate(25); 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); 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()); qSort(translations.begin(), translations.end());
return translations; 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 #ifndef TOOLS_H
#define TOOLS_H #define TOOLS_H
#define CSTR(x)(x.toLocal8Bit().constData())
class IEntryHandle; class IEntryHandle;
enum tKeyType {PASSWORD=0,KEYFILE=1,BOTH=2}; enum tKeyType {PASSWORD=0,KEYFILE=1,BOTH=2};
@ -32,10 +30,15 @@ struct Translation {
}; };
bool operator<(const Translation& t1, const Translation& t2); 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 QIcon& getIcon(const QString& name);
const QPixmap* getPixmap(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);
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(const QString& UrlString);
void openBrowser(IEntryHandle* entry); void openBrowser(IEntryHandle* entry);
void showErrMsg(const QString& msg,QWidget* parent=NULL); void showErrMsg(const QString& msg,QWidget* parent=NULL);
@ -48,5 +51,11 @@ bool unlockPage(void* addr, int len);
void installTranslator(); void installTranslator();
bool isTranslationActive(); bool isTranslationActive();
QList<Translation> getAllTranslations(); 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 #endif //TOOLS_H

@ -19,17 +19,18 @@
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * 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/IFileDialog.h"
#include "plugins/interfaces/IKdeInit.h" #include "plugins/interfaces/IKdeInit.h"
#include "plugins/interfaces/IGnomeInit.h" #include "plugins/interfaces/IGnomeInit.h"
//#include <QPluginLoader> //#include <QPluginLoader>
#include "mainwindow.h" #include <iostream>
#include "main.h"
#if defined(Q_WS_X11) && defined(GLOBAL_AUTOTYPE)
#include "Application_X11.h"
#endif
using namespace std; using namespace std;
@ -48,6 +49,8 @@ IIconTheme* IconLoader=NULL;
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
setlocale(LC_CTYPE, "");
QT_REQUIRE_VERSION(argc, argv, "4.3.0"); QT_REQUIRE_VERSION(argc, argv, "4.3.0");
#if defined(Q_WS_X11) && defined(GLOBAL_AUTOTYPE) #if defined(Q_WS_X11) && defined(GLOBAL_AUTOTYPE)
@ -62,12 +65,23 @@ int main(int argc, char **argv)
DataDir = AppDir+"/../share/keepassx"; DataDir = AppDir+"/../share/keepassx";
if (!QFile::exists(DataDir) && QFile::exists(AppDir+"/share")) if (!QFile::exists(DataDir) && QFile::exists(AppDir+"/share"))
DataDir = AppDir+"/share"; DataDir = AppDir+"/share";
HomeDir = QDir::homePath()+"/.keepassx"; 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) #elif defined(Q_WS_MAC)
HomeDir = QDir::homePath()+"/.keepassx"; HomeDir = QDir::homePath()+"/.keepassx";
DataDir = AppDir+"/../Resources/keepassx"; DataDir = AppDir+"/../Resources/keepassx";
#else //Q_WS_WIN #else //Q_WS_WIN
HomeDir = QString::fromLocal8Bit(qgetenv("APPDATA").constData()); HomeDir = qtWindowsConfigPath(CSIDL_APPDATA);
if(!HomeDir.isEmpty() && QFile::exists(HomeDir)) if(!HomeDir.isEmpty() && QFile::exists(HomeDir))
HomeDir = QDir::fromNativeSeparators(HomeDir)+"/KeePassX"; HomeDir = QDir::fromNativeSeparators(HomeDir)+"/KeePassX";
else else
@ -75,6 +89,7 @@ int main(int argc, char **argv)
DataDir = AppDir+"/share"; DataDir = AppDir+"/share";
#endif #endif
DataDir = QDir::cleanPath(DataDir);
CmdLineArgs args; CmdLineArgs args;
if ( !args.parse(QApplication::arguments()) ){ if ( !args.parse(QApplication::arguments()) ){
@ -95,11 +110,21 @@ int main(int argc, char **argv)
if(!QDir().mkpath(HomeDir)) if(!QDir().mkpath(HomeDir))
qWarning("Warning: Could not create directory '%s'", CSTR(HomeDir)); qWarning("Warning: Could not create directory '%s'", CSTR(HomeDir));
} }
IniFilename=HomeDir+"/config"; IniFilename=HomeDir+"/config.ini";
} }
else else
IniFilename=args.configLocation(); 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); config = new KpxConfig(IniFilename);
fileDlgHistory.load(); fileDlgHistory.load();