Make the fallback component more generic
This commit is contained in:
parent
dde5cc7d6c
commit
d14494d096
@ -19,10 +19,9 @@
|
|||||||
|
|
||||||
#include "fallbackcomponent.h"
|
#include "fallbackcomponent.h"
|
||||||
|
|
||||||
|
#include <QDir>
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
|
|
||||||
|
|
||||||
#include <KStandardDirs>
|
#include <KStandardDirs>
|
||||||
#include <KDebug>
|
#include <KDebug>
|
||||||
|
|
||||||
@ -32,14 +31,38 @@ FallbackComponent::FallbackComponent(QObject *parent)
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
QString FallbackComponent::resolvePath(const QString &component, const QStringList &paths)
|
QString FallbackComponent::basePath() const
|
||||||
|
{
|
||||||
|
return m_basePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
void FallbackComponent::setBasePath(const QString &basePath)
|
||||||
|
{
|
||||||
|
if (basePath != m_basePath) {
|
||||||
|
m_basePath = basePath;
|
||||||
|
emit onBasePathChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QStringList FallbackComponent::candidates() const
|
||||||
|
{
|
||||||
|
return m_candidates;
|
||||||
|
}
|
||||||
|
|
||||||
|
void FallbackComponent::setCandidates(const QStringList &candidates)
|
||||||
|
{
|
||||||
|
m_candidates = candidates;
|
||||||
|
emit onCandidatesChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
QString FallbackComponent::filePath(const QString &key)
|
||||||
{
|
{
|
||||||
QString resolved;
|
QString resolved;
|
||||||
foreach (const QString &path, paths) {
|
|
||||||
//kDebug() << "Searching for" << path;
|
foreach (const QString &path, m_candidates) {
|
||||||
const QString key = component + '/' + path;
|
kDebug() << "Searching for!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << path;
|
||||||
if (m_paths.contains(key)) {
|
if (m_possiblePaths.contains(key)) {
|
||||||
resolved = *m_paths.object(key);
|
resolved = *m_possiblePaths.object(key);
|
||||||
if (!resolved.isEmpty()) {
|
if (!resolved.isEmpty()) {
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
@ -47,8 +70,14 @@ QString FallbackComponent::resolvePath(const QString &component, const QStringLi
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
resolved = KStandardDirs::locate("data", "plasma/" + key);
|
QDir tmpPath(m_basePath);
|
||||||
m_paths.insert(key, new QString(resolved));
|
if (tmpPath.isAbsolute()) {
|
||||||
|
resolved = m_basePath + path;
|
||||||
|
} else {
|
||||||
|
resolved = KStandardDirs::locate("data", m_basePath + '/' + path);
|
||||||
|
}
|
||||||
|
|
||||||
|
m_possiblePaths.insert(key, new QString(resolved));
|
||||||
if (!resolved.isEmpty()) {
|
if (!resolved.isEmpty()) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -23,19 +23,36 @@
|
|||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QCache>
|
#include <QCache>
|
||||||
|
#include <QStringList>
|
||||||
|
|
||||||
class FallbackComponent : public QObject
|
class FallbackComponent : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
|
Q_PROPERTY(QString basePath READ basePath WRITE setBasePath NOTIFY onBasePathChanged)
|
||||||
|
Q_PROPERTY(QStringList candidates READ candidates WRITE setCandidates NOTIFY onCandidatesChanged)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
FallbackComponent(QObject *parent = 0);
|
FallbackComponent(QObject *parent = 0);
|
||||||
|
|
||||||
Q_INVOKABLE QString resolvePath(const QString &component, const QStringList &paths);
|
Q_INVOKABLE QString filePath(const QString& key);
|
||||||
|
|
||||||
|
QString basePath() const;
|
||||||
|
void setBasePath(const QString &basePath);
|
||||||
|
|
||||||
|
|
||||||
|
QStringList candidates() const;
|
||||||
|
void setCandidates(const QStringList &candidates);
|
||||||
|
|
||||||
|
|
||||||
|
Q_SIGNALS:
|
||||||
|
void onBasePathChanged();
|
||||||
|
void onCandidatesChanged();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QCache<QString, QString> m_paths;
|
QCache<QString, QString> m_possiblePaths;
|
||||||
|
QString m_basePath;
|
||||||
|
QStringList m_candidates;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user