Logo Search packages:      
Sourcecode: cantor version File versions  Download package

backend.cpp

/*
    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., 51 Franklin Street, Fifth Floor,
    Boston, MA  02110-1301, USA.

    ---
    Copyright (C) 2009 Alexander Rieder <alexanderrieder@gmail.com>
 */

#include "backend.h"
using namespace Cantor;

#include <kservicetypetrader.h>
#include <kservice.h>
#include <kdebug.h>
#include <kxmlguifactory.h>
#include <kplugininfo.h>

#include "extension.h"

00032 class Cantor::BackendPrivate
{
  public:
    QString name;
    QString comment;
    QString icon;
    QString url;
    bool enabled;
};

00042 Backend::Backend(QObject* parent, const QList<QVariant> args) : QObject(parent),
                                                                d(new BackendPrivate)
{
    Q_UNUSED(args)
    d->enabled=true;
}

00049 Backend::~Backend()
{
    delete d;
}

00054 QString Backend::name() const
{
    return d->name;
}

00059 QString Backend::comment() const
{
    return d->comment;
}

00064 QString Backend::description() const
{
    return comment();
}

00069 QString Backend::icon() const
{
    return d->icon;
}

00074 QString Backend::url() const
{
    return d->url;
}

00079 KUrl Backend::helpUrl() const
{
    return KUrl();
}

00084 bool Backend::isEnabled() const
{
    return d->enabled&&requirementsFullfilled();
}

00089 void Backend::setEnabled(bool enabled)
{
    d->enabled=enabled;
}

static QList<Backend*> backendCache;

00096 QStringList Backend::listAvailableBackends()
{
    QList<Backend* > backends=availableBackends();
    QStringList l;
    foreach(Backend* b, backends)
    {
        if(b->isEnabled())
            l<<b->name();
    }

    return l;
}

00109 QList<Backend*> Backend::availableBackends()
{
    //if we already have all backends Cached, just return the cache.
    //otherwise create the available backends
    if(!backendCache.isEmpty())
    {
        return backendCache;
    }

    KService::List services;
    KServiceTypeTrader* trader = KServiceTypeTrader::self();
    QString error;

    services = trader->query("Cantor/Backend");

    foreach (const KService::Ptr &service,  services)
    {
        Backend* backend=service->createInstance<Backend>(0, QVariantList(),  &error);
        if(backend==0)
        {
            kDebug()<<"error: "<<error;
            continue;
        }

        KPluginInfo info(service);
        backend->d->name=info.name();
        backend->d->comment=info.comment();
        backend->d->icon=info.icon();
        backend->d->url=info.website();
        backendCache<<backend;
    }
    return backendCache;
}

00143 Backend* Backend::createBackend(const QString& name)
{
    QList<Backend*> backends=availableBackends();
    foreach(Backend* b, backends)
    {
        if(b->name().toLower()==name.toLower() || b->id().toLower()==name.toLower())
            return b;
    }

    return 0;
}

00155 QWidget* Backend::settingsWidget(QWidget* parent) const
{
    Q_UNUSED(parent)
        return 0;
}

00161 KConfigSkeleton* Backend::config() const
{
    return 0;
}


00167 QStringList Backend::extensions() const
{
    QList<Extension*> extensions=findChildren<Extension*>(QRegExp(".*Extension"));
    QStringList names;
    foreach(Extension* e, extensions)
        names<<e->objectName();
    return names;
}

00176 Extension* Backend::extension(const QString& name) const
{
    return findChild<Extension*>(name);
}

00181 bool Backend::requirementsFullfilled() const
{
    return true;
}

Generated by  Doxygen 1.6.0   Back to index