Added KDE4 Plugin

git-svn-id: https://svn.code.sf.net/p/keepassx/code/trunk@113 b624d157-de02-0410-bad0-e51aec6abb33
master
tarek_saidi 18 years ago
parent db8ba66067
commit b39ca12cd5
  1. 23
      src/PwmConfig.cpp
  2. 4
      src/PwmConfig.h
  3. 176
      src/main.cpp
  4. 37
      src/plugins/kde/keepassx-kde.cpp
  5. 37
      src/plugins/kde/keepassx-kde.h
  6. 9
      src/plugins/kde/keepassx-kde.pro

@ -34,6 +34,8 @@ using namespace std;
#define DEFAULT_MOUNT_DIR "/" #define DEFAULT_MOUNT_DIR "/"
#endif #endif
#define CSTR(x)((const char*)x.toUtf8())
bool CConfig::loadFromIni(QString filename){ bool CConfig::loadFromIni(QString filename){
QString defaultSearchOptions = "001101111"; QString defaultSearchOptions = "001101111";
@ -59,7 +61,6 @@ ParseBoolString(ini.GetValue("Options","PwGenOptions",(const char*)defaultPwGenO
PwGenLength=ini.GetValueI("Options","PwGenLength",25); PwGenLength=ini.GetValueI("Options","PwGenLength",25);
PwGenCharList=ini.GetValue("Options","PwGenCharList","").c_str(); PwGenCharList=ini.GetValue("Options","PwGenCharList","").c_str();
ExpandGroupTree=ini.GetValueB("Options","ExpandGroupTree",true); ExpandGroupTree=ini.GetValueB("Options","ExpandGroupTree",true);
EnableKdePlugin=ini.GetValueB("KDE Plugin","Enabled",false);
MainWinHeight=ini.GetValueI("UI","MainWinHeight",550); MainWinHeight=ini.GetValueI("UI","MainWinHeight",550);
MainWinWidth=ini.GetValueI("UI","MainWinWidth",900); MainWinWidth=ini.GetValueI("UI","MainWinWidth",900);
MainWinSplit1=ini.GetValueI("UI","MainWinSplit1",100); MainWinSplit1=ini.GetValueI("UI","MainWinSplit1",100);
@ -73,6 +74,17 @@ LastKeyLocation=ini.GetValue("Options","LastKeyLocation","").c_str();
LastKeyType=(tKeyType)ini.GetValueI("Options","LastKeyType",(int)PASSWORD); LastKeyType=(tKeyType)ini.GetValueI("Options","LastKeyType",(int)PASSWORD);
if(!OpenLast)RememberLastKey=false; if(!OpenLast)RememberLastKey=false;
ToolbarIconSize=ini.GetValueI("UI","ToolbarIconSize",16); ToolbarIconSize=ini.GetValueI("UI","ToolbarIconSize",16);
QString IntegrPluginVal=ini.GetValue("Options","IntegrPlugin","None").c_str();
if(IntegrPluginVal=="None")
IntegrPlugin=NONE;
else if(IntegrPluginVal=="Gnome")
IntegrPlugin=GNOME;
else if(IntegrPluginVal=="KDE")
IntegrPlugin=KDE;
else
IntegrPlugin=NONE;
return true; return true;
} }
@ -97,7 +109,6 @@ ini.SetValue("Options","PwGenOptions",(const char*)CreateBoolString(PwGenOptions
ini.SetValueI("Options","PwGenLength",PwGenLength,true); ini.SetValueI("Options","PwGenLength",PwGenLength,true);
ini.SetValue("Options","PwGenCharList",(const char*)PwGenCharList.toUtf8(),true); ini.SetValue("Options","PwGenCharList",(const char*)PwGenCharList.toUtf8(),true);
ini.SetValueB("Options","ExpandGroupTree",ExpandGroupTree,true); ini.SetValueB("Options","ExpandGroupTree",ExpandGroupTree,true);
ini.SetValueB("KDE Plugin","Enabled",EnableKdePlugin,true);
ini.SetValueI("UI","MainWinHeight",MainWinHeight); ini.SetValueI("UI","MainWinHeight",MainWinHeight);
ini.SetValueI("UI","MainWinWidth",MainWinWidth); ini.SetValueI("UI","MainWinWidth",MainWinWidth);
ini.SetValueI("UI","MainWinSplit1",MainWinSplit1); ini.SetValueI("UI","MainWinSplit1",MainWinSplit1);
@ -114,6 +125,14 @@ else{
ini.SetValue("Options","LastKeyLocation",""); ini.SetValue("Options","LastKeyLocation","");
ini.SetValueI("Options","LastKeyType",0);} ini.SetValueI("Options","LastKeyType",0);}
ini.SetValueI("UI","ToolbarIconSize",ToolbarIconSize,true); ini.SetValueI("UI","ToolbarIconSize",ToolbarIconSize,true);
if(IntegrPlugin==NONE)
ini.SetValue("Options","IntegrPlugin","None");
if(IntegrPlugin==GNOME)
ini.SetValue("Options","IntegrPlugin","Gnome");
if(IntegrPlugin==KDE)
ini.SetValue("Options","IntegrPlugin","KDE");
if(!ini.WriteFile())return false; if(!ini.WriteFile())return false;
else return true; else return true;
} }

@ -24,8 +24,10 @@
#include "lib/IniReader.h" #include "lib/IniReader.h"
#include <qcolor.h> #include <qcolor.h>
class CConfig{ class CConfig{
public: public:
enum IntegrPluginType{NONE,KDE,GNOME};
int TimeFormat; int TimeFormat;
int ClipboardTimeOut; int ClipboardTimeOut;
bool Toolbar; bool Toolbar;
@ -59,7 +61,7 @@ public:
tKeyType LastKeyType; tKeyType LastKeyType;
QString LastKeyLocation; QString LastKeyLocation;
int ToolbarIconSize; int ToolbarIconSize;
IntegrPluginType IntegrPlugin;
bool loadFromIni(QString filename); bool loadFromIni(QString filename);
bool saveToIni(QString filename); bool saveToIni(QString filename);

@ -87,87 +87,103 @@ bool loadTranslation(QTranslator* tr,const QString& prefix,const QString& Locale
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
QApplication* app=new QApplication(argc,argv); QApplication* app=new QApplication(argc,argv);
QString ArgFile,ArgCfg,ArgLang,IniFilename; QString ArgFile,ArgCfg,ArgLang,IniFilename;
parseCmdLineArgs(argc,argv,ArgFile,ArgCfg,ArgLang); parseCmdLineArgs(argc,argv,ArgFile,ArgCfg,ArgLang);
AppDir=app->applicationDirPath(); AppDir=app->applicationDirPath();
//Load Config
QPluginLoader gtkplugin("/home/tarek/Documents/KeePassX/src/plugins/gnome/libkeepassx-gnome.so"); if(ArgCfg==QString()){
KpxFileDialogs::setPlugin(qobject_cast<IFileDialog*>(gtkplugin.instance())); if(!QDir(QDir::homePath()+"/.keepass").exists()){
QDir conf(QDir::homePath());
if(!conf.mkdir(".keepass")){
//Load Config cout << "Warning: Could not create directory '~/.keepass'." << endl;}
if(ArgCfg==QString()){ }
if(!QDir(QDir::homePath()+"/.keepass").exists()){ IniFilename=QDir::homePath()+"/.keepass/config";
QDir conf(QDir::homePath()); config.loadFromIni(IniFilename);
if(!conf.mkdir(".keepass")){ }
cout << "Warning: Could not create directory '~/.keepass'." << endl;} else{
} IniFilename=ArgCfg;
IniFilename=QDir::homePath()+"/.keepass/config"; config.loadFromIni(IniFilename);}
config.loadFromIni(IniFilename);
}
else{ //Plugins
IniFilename=ArgCfg; if(config.IntegrPlugin!=CConfig::NONE){
config.loadFromIni(IniFilename);} QString LibName="libkeepassx-";
if(config.IntegrPlugin==CConfig::KDE)
//Internationalization LibName+="kde.so";
QLocale loc; else if(config.IntegrPlugin==CConfig::GNOME)
if(!ArgLang.size()) LibName+="gnome.so";
loc=QLocale::system(); QPluginLoader plugin("/home/tarek/Documents/KeePassX/src/plugins/gnome/"+LibName);
else if(!plugin.load()){
loc=QLocale(ArgLang); qDebug(plugin.errorString().toUtf8().data());
exit(1);
QTranslator* translator = NULL; }
QTranslator* qtTranslator=NULL; else{
translator=new QTranslator; IFileDialog* fdlg=qobject_cast<IFileDialog*>(plugin.instance());
qtTranslator=new QTranslator; KpxFileDialogs::setPlugin(fdlg);
}
if(loadTranslation(translator,"keepass-",loc.name(),QStringList() }
<< app->applicationDirPath()+"/../share/keepass/i18n/"
<< QDir::homePath()+"/.keepass/" ))
{app->installTranslator(translator);
TrActive=true;}
else{
if(loc.name()!="en_US")
qWarning(QString("Kpx: No Translation found for '%1 (%2)'using 'English (UnitedStates)'")
.arg(QLocale::languageToString(loc.language()))
.arg(QLocale::countryToString(loc.country())).toAscii());
delete translator;
TrActive=false;
}
if(loadTranslation(qtTranslator,"qt_",loc.name(),QStringList()
<< QLibraryInfo::location(QLibraryInfo::TranslationsPath)
<< app->applicationDirPath()+"/../share/keepass/i18n/"
<< QDir::homePath()+"/.keepass/" ))
app->installTranslator(qtTranslator);
else{
if(loc.name()!="en_US")
qWarning(QString("Qt: No Translation found for '%1 (%2)'using 'English (UnitedStates)'")
.arg(QLocale::languageToString(loc.language()))
.arg(QLocale::countryToString(loc.country())).toAscii());
delete qtTranslator;
}
loadImages();
initYarrow(); //init random number generator
SecString::generateSessionKey();
int r=0;
KeepassMainWindow *mainWin = new KeepassMainWindow(ArgFile); //Internationalization
if(mainWin->Start){ QLocale loc;
mainWin->show(); if(!ArgLang.size())
r=app->exec(); loc=QLocale::system();
} else
delete mainWin; loc=QLocale(ArgLang);
if(!config.saveToIni(IniFilename))
QMessageBox::warning(NULL,QObject::tr("Warning"), QTranslator* translator = NULL;
QObject::tr("Could not save configuration file.\nMake sure you have write access to '~/.keepass'."), QTranslator* qtTranslator=NULL;
QObject::tr("OK"),"","",0.0); translator=new QTranslator;
delete app; qtTranslator=new QTranslator;
return r;
if(loadTranslation(translator,"keepass-",loc.name(),QStringList()
<< app->applicationDirPath()+"/../share/keepass/i18n/"
<< QDir::homePath()+"/.keepass/" ))
{app->installTranslator(translator);
TrActive=true;}
else{
if(loc.name()!="en_US")
qWarning(QString("Kpx: No Translation found for '%1 (%2)'using 'English (UnitedStates)'")
.arg(QLocale::languageToString(loc.language()))
.arg(QLocale::countryToString(loc.country())).toAscii());
delete translator;
TrActive=false;
}
if(loadTranslation(qtTranslator,"qt_",loc.name(),QStringList()
<< QLibraryInfo::location(QLibraryInfo::TranslationsPath)
<< app->applicationDirPath()+"/../share/keepass/i18n/"
<< QDir::homePath()+"/.keepass/" ))
app->installTranslator(qtTranslator);
else{
if(loc.name()!="en_US")
qWarning(QString("Qt: No Translation found for '%1 (%2)'using 'English (UnitedStates)'")
.arg(QLocale::languageToString(loc.language()))
.arg(QLocale::countryToString(loc.country())).toAscii());
delete qtTranslator;
}
loadImages();
initYarrow(); //init random number generator
SecString::generateSessionKey();
int r=0;
KeepassMainWindow *mainWin = new KeepassMainWindow(ArgFile);
if(mainWin->Start){
mainWin->show();
r=app->exec();
}
delete mainWin;
if(!config.saveToIni(IniFilename))
QMessageBox::warning(NULL,QObject::tr("Warning"),
QObject::tr("Could not save configuration file.\nMake sure you have write access to '~/.keepass'."),
QObject::tr("OK"),"","",0.0);
delete app;
return r;
} }

@ -0,0 +1,37 @@
/***************************************************************************
* Copyright (C) 2005-2006 by Tarek Saidi *
* tarek.saidi@arcor.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 of the License, or *
* (at your option) any later version. *
* *
* 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, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include <kfiledialog.h>
#include "keepassx-kde.h"
Q_EXPORT_PLUGIN2(keepassx_kde, KdePlugin)
QString KdePlugin::openExistingFileDialog(QWidget* parent,QString title,QString dir,QStringList Filters){
return KFileDialog::getOpenFileName();
}
QStringList KdePlugin::openExistingFilesDialog(QWidget* parent,QString title,QString dir,QStringList Filters){
return QStringList();
}
QString KdePlugin::saveFileDialog(QWidget* parent,QString title,QString dir,QStringList Filters,bool OverWriteWarn){return QString();}

@ -0,0 +1,37 @@
/***************************************************************************
* Copyright (C) 2005-2006 by Tarek Saidi *
* tarek.saidi@arcor.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 of the License, or *
* (at your option) any later version. *
* *
* 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, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include <QtPlugin>
#include <QObject>
#include "../interfaces/IFileDialog.h"
class KdePlugin:public QObject,public IFileDialog{
Q_OBJECT
Q_INTERFACES(IFileDialog)
public:
virtual QString openExistingFileDialog(QWidget* parent,QString title,QString dir,
QStringList Filters);
virtual QStringList openExistingFilesDialog(QWidget* parent,QString title,QString dir,
QStringList Filters);
virtual QString saveFileDialog(QWidget* parent,QString title,QString dir,
QStringList Filters,bool ShowOverwriteWarning=true);
};

@ -0,0 +1,9 @@
INCLUDEPATH += /opt/kde4/include
TEMPLATE = lib
CONFIG += plugin release
HEADERS += keepassx-kde.h
SOURCES += keepassx-kde.cpp
MOC_DIR = build/moc
OBJECTS_DIR = build/
LIBS+=-L/opt/kde4/lib/ -lkdeui