2012-09-24 20:51:39 +02:00
|
|
|
/*
|
|
|
|
* Copyright 2011 Marco Martin <mart@kde.org>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Library General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2, 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 Library General Public License for more details
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this program; if not, write to the
|
|
|
|
* Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef FALLBACKCOMPONENT_H
|
|
|
|
#define FALLBACKCOMPONENT_H
|
|
|
|
|
|
|
|
|
|
|
|
#include <QObject>
|
|
|
|
#include <QCache>
|
2012-09-24 23:21:57 +02:00
|
|
|
#include <QStringList>
|
2012-09-24 20:51:39 +02:00
|
|
|
|
|
|
|
class FallbackComponent : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
2012-10-11 10:21:17 +02:00
|
|
|
/**
|
|
|
|
* Prefix of the path
|
|
|
|
* This should be something like "plasma","kwin","plasmate",etc
|
|
|
|
* If the basePath is "plasma", it will be set for the data of plasma like,
|
|
|
|
* or it can be an absolute path
|
|
|
|
**/
|
2012-10-03 12:47:43 +02:00
|
|
|
Q_PROPERTY(QString basePath READ basePath WRITE setBasePath NOTIFY basePathChanged)
|
2012-10-11 10:21:17 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The possible candidates in order to have a complete path.
|
|
|
|
* basepath/candidate, where candidate is the first one in the list of candidates
|
|
|
|
* in order of importance that matches an existing file
|
|
|
|
**/
|
2012-10-03 12:47:43 +02:00
|
|
|
Q_PROPERTY(QStringList candidates READ candidates WRITE setCandidates NOTIFY candidatesChanged)
|
2012-09-24 23:21:57 +02:00
|
|
|
|
2012-09-24 20:51:39 +02:00
|
|
|
public:
|
|
|
|
FallbackComponent(QObject *parent = 0);
|
|
|
|
|
2012-10-11 10:21:17 +02:00
|
|
|
/**
|
|
|
|
* This method must be called after the the basePath and the candidates property
|
|
|
|
* This method resolves a file path based on the base path and the candidates.
|
|
|
|
* it searches for a file named key under basepath/candidate/key, and returns
|
|
|
|
* the path constructed with the first candidate that matches, if any.
|
|
|
|
*
|
|
|
|
* @param key the name of the file to search for
|
|
|
|
**/
|
2012-10-15 20:41:27 +02:00
|
|
|
Q_INVOKABLE QString filePath(const QString& key = QString());
|
2012-09-24 23:21:57 +02:00
|
|
|
|
|
|
|
QString basePath() const;
|
|
|
|
void setBasePath(const QString &basePath);
|
|
|
|
|
|
|
|
|
|
|
|
QStringList candidates() const;
|
|
|
|
void setCandidates(const QStringList &candidates);
|
|
|
|
|
|
|
|
|
|
|
|
Q_SIGNALS:
|
2012-10-03 12:47:43 +02:00
|
|
|
void basePathChanged();
|
|
|
|
void candidatesChanged();
|
2012-09-24 20:51:39 +02:00
|
|
|
|
|
|
|
private:
|
2012-09-24 23:21:57 +02:00
|
|
|
QCache<QString, QString> m_possiblePaths;
|
|
|
|
QString m_basePath;
|
|
|
|
QStringList m_candidates;
|
2012-09-24 20:51:39 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|