Support proper plugin finding.

So we don't have to hardcode the location anymore.
This commit is contained in:
Felix Geyer 2012-07-18 20:54:26 +02:00
parent 7fef3bd701
commit 2a45f57386
7 changed files with 62 additions and 10 deletions

View File

@ -23,6 +23,7 @@
#include "autotype/AutoTypePlatformPlugin.h"
#include "core/Database.h"
#include "core/Entry.h"
#include "core/FilePath.h"
#include "core/Group.h"
#include "core/ListDeleter.h"
#include "core/Tools.h"
@ -39,10 +40,21 @@ AutoType::AutoType(QObject* parent)
// prevent crash when the plugin has unresolved symbols
m_pluginLoader->setLoadHints(QLibrary::ResolveAllSymbolsHint);
// TODO: scan in proper paths
#if defined(Q_OS_UNIX) && !defined(Q_OS_MAC)
m_pluginLoader->setFileName(QCoreApplication::applicationDirPath() + "/autotype/x11/libkeepassx-autotype-x11.so");
#endif
QString pluginPath = filePath()->pluginPath("keepassx-autotype-" + Tools::platform());
if (!pluginPath.isEmpty()) {
loadPlugin(pluginPath);
}
}
AutoType::~AutoType()
{
delete m_executor;
}
void AutoType::loadPlugin(const QString& pluginPath)
{
m_pluginLoader->setFileName(pluginPath);
QObject* pluginInstance = m_pluginLoader->instance();
if (pluginInstance) {
@ -58,11 +70,6 @@ AutoType::AutoType(QObject* parent)
}
}
AutoType::~AutoType()
{
delete m_executor;
}
AutoType* AutoType::instance()
{
if (!m_instance) {

View File

@ -57,6 +57,7 @@ Q_SIGNALS:
private:
explicit AutoType(QObject* parent = Q_NULLPTR);
~AutoType();
void loadPlugin(const QString& pluginPath);
bool parseActions(const QString& sequence, const Entry* entry, QList<AutoTypeAction*>& actions);
QList<AutoTypeAction*> createActionFromTemplate(const QString& tmpl, const Entry* entry);

View File

@ -106,7 +106,7 @@ QImage DatabaseIcons::icon(int index)
}
else {
QString iconPath = QString("icons/database/").append(m_indexToName[index]);
QImage icon(filePath()->path(iconPath));
QImage icon(filePath()->dataPath(iconPath));
m_iconCache[index] = icon;
return icon;

View File

@ -19,6 +19,7 @@
#include <QtCore/QCoreApplication>
#include <QtCore/QDir>
#include <QtCore/QLibrary>
#include "config-keepassx.h"
@ -29,6 +30,34 @@ QString FilePath::dataPath(const QString& name)
return m_basePath + name;
}
QString FilePath::pluginPath(const QString& name)
{
QStringList pluginPaths;
QDir buildDir(QCoreApplication::applicationDirPath() + "/autotype");
Q_FOREACH (const QString& dir, buildDir.entryList(QDir::Dirs | QDir::NoDotAndDotDot)) {
pluginPaths << QCoreApplication::applicationDirPath() + "/autotype/" + dir;
}
pluginPaths << QCoreApplication::applicationDirPath();
pluginPaths << QCoreApplication::applicationDirPath() + "/../lib/keepassx";
QStringList dirFilter;
dirFilter << QString("*%1*").arg(name);
Q_FOREACH (const QString& path, pluginPaths) {
QStringList fileCandidates = QDir(path).entryList(dirFilter, QDir::Files);
Q_FOREACH (const QString& file, fileCandidates) {
QString filePath = path + "/" + file;
if (QLibrary::isLibrary(filePath)) {
return filePath;
}
}
}
return QString();
}
QIcon FilePath::applicationIcon()
{
return icon("apps", "keepassx");

View File

@ -27,6 +27,7 @@ class FilePath
{
public:
QString dataPath(const QString& name);
QString pluginPath(const QString& name);
QIcon applicationIcon();
QIcon icon(const QString& category, const QString& name, bool fromTheme = true);

View File

@ -181,4 +181,17 @@ void wait(int ms)
}
}
QString platform()
{
#if defined(Q_WS_X11)
return "x11";
#elif defined(Q_WS_MAC)
return "mac";
#elif defined(Q_WS_WIN)
return "win";
#else
return QString();
#endif
}
} // namespace Tools

View File

@ -37,6 +37,7 @@ QString imageReaderFilter();
bool isHex(const QByteArray& ba);
void sleep(int ms);
void wait(int ms);
QString platform();
} // namespace Tools