From 05ec5eb40c2b419715bb72f6ac010015f81bf7c9 Mon Sep 17 00:00:00 2001 From: tarek_saidi Date: Tue, 24 Jul 2007 19:34:09 +0000 Subject: [PATCH] -KDE-Plugin: Updated API, plugin works fine again -KDE-Plugin: added KDE icon loader to load KDE's currunt icon theme (incomplete) -reverted change in the group combobox in the editentrydialog git-svn-id: https://svn.code.sf.net/p/keepassx/code/trunk@141 b624d157-de02-0410-bad0-e51aec6abb33 --- src/dialogs/EditEntryDlg.cpp | 2 +- src/main.cpp | 33 +++++++++++------ src/plugins/interfaces/IIconTheme.h | 33 +++++++++++++++++ src/plugins/kde/keepassx-kde.cpp | 55 ++++++++++++++++++++++++++--- src/plugins/kde/keepassx-kde.h | 13 ++++--- src/plugins/kde/keepassx-kde.pro | 10 +++--- src/src.pro | 1 + 7 files changed, 123 insertions(+), 24 deletions(-) create mode 100644 src/plugins/interfaces/IIconTheme.h diff --git a/src/dialogs/EditEntryDlg.cpp b/src/dialogs/EditEntryDlg.cpp index 721b482..c719e09 100755 --- a/src/dialogs/EditEntryDlg.cpp +++ b/src/dialogs/EditEntryDlg.cpp @@ -192,7 +192,7 @@ void CEditEntryDlg::InitGroupComboBox(){ QString Space; groups=db->sortedGroups(); for(int i=0;ilevel() - 1)); + Space.fill(' ', 2 * (groups[i]->level())); Combo_Group->insertItem(i,db->icon(groups[i]->image()),Space+groups[i]->title()); if(groups[i]==entry->group()){ Combo_Group->setCurrentIndex(i); diff --git a/src/main.cpp b/src/main.cpp index 0599bcd..d53247e 100755 --- a/src/main.cpp +++ b/src/main.cpp @@ -37,6 +37,7 @@ #include "plugins/interfaces/IFileDialog.h" #include "plugins/interfaces/IKdeInit.h" #include "plugins/interfaces/IGnomeInit.h" +#include "plugins/interfaces/IIconTheme.h" #include "lib/FileDialogs.h" #include "main.h" @@ -68,6 +69,7 @@ bool TrActive; QString DetailViewTemplate; QPixmap* EntryIcons; +IIconTheme* IconLoader=NULL; inline void loadImages(); inline void parseCmdLineArgs(int argc, char** argv,QString &ArgFile,QString& ArgCfg,QString& ArgLang); @@ -134,8 +136,13 @@ int main(int argc, char **argv) qWarning("Could not load desktop integration plugin:"); qWarning(CSTR(PluginLoadError)); } - else{ - IFileDialog* fdlg=qobject_cast(plugin.instance()); + else{ + QObject *plugininstance=plugin.instance(); + IFileDialog* fdlg=qobject_cast(plugininstance); + IconLoader=qobject_cast(plugininstance); + if(IconLoader==NULL){ + qWarning("Error: Integration Plugin: Could not initialize IconTheme interface."); + } KpxFileDialogs::setPlugin(fdlg); if(config->integrPlugin()==KpxConfig::KDE){ IKdeInit* kdeinit=qobject_cast(plugin.instance()); @@ -350,13 +357,19 @@ const QIcon& getIcon(const QString& name){ QIcon* CachedIcon=IconCache.value(name); if(CachedIcon) return *CachedIcon; - QFileInfo IconFile(AppDir+"/../share/keepass/icons/"+name+".png"); - if(!IconFile.isFile() || !IconFile.exists() || !IconFile.isReadable()){ - ///TODO 0.2.3 error handling - qWarning("%s",CSTR(name)); + QIcon* NewIcon=NULL; + if(IconLoader==NULL){ + QFileInfo IconFile(AppDir+"/../share/keepass/icons/"+name+".png"); + if(!IconFile.isFile() || !IconFile.exists() || !IconFile.isReadable()){ + ///TODO 0.2.3 error handling + qWarning("%s",CSTR(name)); + } + NewIcon=new QIcon(AppDir+"/../share/keepass/icons/"+name+".png"); + IconCache.insert(name,NewIcon); + } else { + NewIcon=new QIcon(IconLoader->getIcon(name)); + IconCache.insert(name,NewIcon); } - QIcon* NewIcon=new QIcon(AppDir+"/../share/keepass/icons/"+name+".png"); - IconCache.insert(name,NewIcon); return *NewIcon; } @@ -436,9 +449,9 @@ QMessageBox::critical(parent,QObject::tr("Error"),msg,QObject::tr("OK")); QString findPlugin(const QString& filename){ QFileInfo info; - info.setFile(AppDir+"/../lib/keepassx/"+filename); + info.setFile(AppDir+"/../lib/"+filename); if(info.exists() && info.isFile()) - return AppDir+"/../lib/keepassx/"+filename; + return AppDir+"/../lib/"+filename; return QString(); } diff --git a/src/plugins/interfaces/IIconTheme.h b/src/plugins/interfaces/IIconTheme.h new file mode 100644 index 0000000..08df4fc --- /dev/null +++ b/src/plugins/interfaces/IIconTheme.h @@ -0,0 +1,33 @@ +/*************************************************************************** + * Copyright (C) 2007 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; Version 2 of the license only. * + * * + * 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 +#include +#include + +#ifndef _I_ICON_THEME_H_ +#define _I_ICON_THEME_H_ + +class IIconTheme{ + public: + virtual ~IIconTheme(){} + virtual QIcon getIcon(const QString& name)=0; +}; +Q_DECLARE_INTERFACE(IIconTheme,"org.KeePassX.IconThemeInterface/0.2.3") + +#endif diff --git a/src/plugins/kde/keepassx-kde.cpp b/src/plugins/kde/keepassx-kde.cpp index 70ec001..532e029 100644 --- a/src/plugins/kde/keepassx-kde.cpp +++ b/src/plugins/kde/keepassx-kde.cpp @@ -17,27 +17,74 @@ * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ + #include #include #include +#include +#include +#include #include "keepassx-kde.h" +QHashIconMap; Q_EXPORT_PLUGIN2(keepassx_kde, KdePlugin) -QString KdePlugin::openExistingFileDialog(QWidget* parent,QString title,QString dir,QStringList Filters){ - return KFileDialog::getOpenFileName(); +void createIconMap(){ + IconMap["alarmclock"]="alarmclock"; + IconMap["appsettings"]="configure"; + IconMap["autotype"]="input-keyboard"; + IconMap["clock"]="chronometer"; + IconMap["clonenetry"]="edit-copy"; + IconMap["copypwd"]="kgpg-export-kgpg"; + IconMap["copyusername"]="user"; + IconMap["dbsearch"]="edit-find"; + IconMap["dbsettings"]="configure"; + IconMap["delete"]="edit-delete"; + IconMap["delete-entry"]="edit-delete"; + IconMap["delete-group"]="edit-delete"; + IconMap["editentry"]="edit"; + IconMap["editgroup"]="edit"; + IconMap["exit"]="application-exit"; + IconMap["expired"]="flag-red"; + IconMap["fileclose"]="dialog-close"; + IconMap["filedelete"]="edit-delete"; + IconMap["filenew"]="document-new"; + IconMap["fileopen"]="document-open"; + IconMap["filesave"]="document-save"; + IconMap["filesaveas"]="document-save-as"; + IconMap["filesaveasdisabled"]="document-save-as"; ///FIXME + IconMap["generator"]="roll"; + IconMap["groupsearch"]="file-find"; + IconMap["help"]="help-contents"; + IconMap["key"]="password"; + IconMap["manual"]="help-contents"; } +QString KdePlugin::openExistingFileDialog(QWidget* parent,QString title,QString dir,QStringList Filters,int SelectedFilter){ + return KFileDialog::getOpenFileName(); + +} -QStringList KdePlugin::openExistingFilesDialog(QWidget* parent,QString title,QString dir,QStringList Filters){ +QStringList KdePlugin::openExistingFilesDialog(QWidget* parent,QString title,QString dir,QStringList Filters,int SelectedFilter){ return QStringList(); } -QString KdePlugin::saveFileDialog(QWidget* parent,QString title,QString dir,QStringList Filters,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){ KCmdLineArgs::init(argc,argv,"keepassx","KeePassX","Cross Platform Password Manager","0.2.3"); + createIconMap(); return dynamic_cast( new KApplication() ); } + + +QIcon KdePlugin::getIcon(const QString& name){ + KIconLoader loader; + QPixmap pxm=loader.loadIcon(IconMap.value(name),K3Icon::Desktop); + QIcon icon(pxm); + return icon; +} + + diff --git a/src/plugins/kde/keepassx-kde.h b/src/plugins/kde/keepassx-kde.h index 830c757..d00303a 100644 --- a/src/plugins/kde/keepassx-kde.h +++ b/src/plugins/kde/keepassx-kde.h @@ -20,21 +20,26 @@ #include #include +#include #include "../interfaces/IFileDialog.h" #include "../interfaces/IKdeInit.h" +#include "../interfaces/IIconTheme.h" -class KdePlugin:public QObject,public IFileDialog,public IKdeInit{ +class KdePlugin:public QObject,public IFileDialog,public IKdeInit,public IIconTheme{ Q_OBJECT Q_INTERFACES(IFileDialog) Q_INTERFACES(IKdeInit) + Q_INTERFACES(IIconTheme) public: virtual QString openExistingFileDialog(QWidget* parent,QString title,QString dir, - QStringList Filters); + QStringList Filters, int SelectedFilter); virtual QStringList openExistingFilesDialog(QWidget* parent,QString title,QString dir, - QStringList Filters); + QStringList Filters, int SelectedFilter); virtual QString saveFileDialog(QWidget* parent,QString title,QString dir, - QStringList Filters,bool ShowOverwriteWarning=true); + QStringList Filters, int SelectedFilter, bool ShowOverwriteWarning=true); + virtual int getLastFilter(){return 0;} virtual QApplication* getMainAppObject(int argc, char** argv); + virtual QIcon getIcon(const QString& name); }; diff --git a/src/plugins/kde/keepassx-kde.pro b/src/plugins/kde/keepassx-kde.pro index 14a6861..9ddab92 100644 --- a/src/plugins/kde/keepassx-kde.pro +++ b/src/plugins/kde/keepassx-kde.pro @@ -1,9 +1,9 @@ - -INCLUDEPATH += /opt/kde4/include +INCLUDEPATH += /usr/lib/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 -lkio -lkdecore +MOC_DIR = ../../../build/moc +OBJECTS_DIR = ../../../build +TARGET = ../../../lib/keepassx-kde +LIBS+=-L/usr/lib/kde4/lib -lkio -lkdecore diff --git a/src/src.pro b/src/src.pro index e46c073..977fa5d 100755 --- a/src/src.pro +++ b/src/src.pro @@ -114,6 +114,7 @@ HEADERS += lib/IniReader.h \ plugins/interfaces/IFileDialog.h \ plugins/interfaces/IKdeInit.h \ plugins/interfaces/IGnomeInit.h \ + plugins/interfaces/IIconTheme.h \ KpxConfig.h \ KpxFirefox.h SOURCES += lib/UrlLabel.cpp \