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