~ubuntu-branches/ubuntu/natty/plasma-mobile/natty

« back to all changes in this revision

Viewing changes to bindings/private/dataengineconsumer.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Rodrigo Belem
  • Date: 2011-01-01 16:58:27 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20110101165827-vij700zj247uxcdr
Tags: 0.0~svn20110101-0ubuntu1
* New svn snapshot
* Remove kubuntu_01_library_version.diff and
  debian-changes-0.0~svn20100830-0ubuntu4, they don't apply and aren't
  needed in the current snapshot.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 *   Copyright 2005 by Aaron Seigo <aseigo@kde.org>
3
 
 *   Copyright 2007 by Riccardo Iaconelli <riccardo@kde.org>
4
 
 *   Copyright 2008 by Ménard Alexis <darktears31@gmail.com>
5
 
 *
6
 
 *   This program is free software; you can redistribute it and/or modify
7
 
 *   it under the terms of the GNU Library General Public License as
8
 
 *   published by the Free Software Foundation; either version 2, or
9
 
 *   (at your option) any later version.
10
 
 *
11
 
 *   This program is distributed in the hope that it will be useful,
12
 
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 
 *   GNU General Public License for more details
15
 
 *
16
 
 *   You should have received a copy of the GNU Library General Public
17
 
 *   License along with this program; if not, write to the
18
 
 *   Free Software Foundation, Inc.,
19
 
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20
 
 */
21
 
 
22
 
#include "dataengineconsumer_p.h"
23
 
 
24
 
#include <QtCore/QSet>
25
 
 
26
 
#include <kdebug.h>
27
 
 
28
 
#include <plasma/dataenginemanager.h>
29
 
#include <plasma/servicejob.h>
30
 
 
31
 
namespace Plasma
32
 
{
33
 
 
34
 
ServiceMonitor::ServiceMonitor(DataEngineConsumer *consumer)
35
 
    : m_consumer(consumer)
36
 
{
37
 
}
38
 
 
39
 
ServiceMonitor::~ServiceMonitor()
40
 
{
41
 
}
42
 
 
43
 
void ServiceMonitor::slotJobFinished(Plasma::ServiceJob *job)
44
 
{
45
 
    kDebug() << "engine ready!";
46
 
    QString engineName = job->parameters()["EngineName"].toString();
47
 
    QString location = job->destination();
48
 
    QPair<QString, QString> pair(location, engineName);
49
 
    kDebug() << "pair = " << pair;
50
 
    if (!m_consumer->m_remoteEngines.contains(pair)) {
51
 
        kDebug() << "engine does not exist yet!";
52
 
    } else {
53
 
        KUrl engineLocation(location);
54
 
        engineLocation.setFileName(job->result().toString());
55
 
        kDebug() << "setting location : "
56
 
                 << engineLocation.prettyUrl();
57
 
      //  m_consumer->m_remoteEngines[pair]->setLocation(engineLocation);
58
 
    }
59
 
}
60
 
 
61
 
void ServiceMonitor::slotServiceReady(Plasma::Service *plasmoidService)
62
 
{
63
 
    kDebug() << "service ready!";
64
 
    if (!m_consumer->m_engineNameForService.contains(plasmoidService)) {
65
 
        kDebug() << "no engine name for service!";
66
 
        kDebug() << "amount of services in map: " << m_consumer->m_engineNameForService.count();
67
 
    } else {
68
 
        kDebug() << "value = " << m_consumer->m_engineNameForService.value(plasmoidService);
69
 
    }
70
 
 
71
 
    kDebug() << "requesting dataengine!";
72
 
    KConfigGroup op = plasmoidService->operationDescription("DataEngine");
73
 
    op.writeEntry("EngineName", m_consumer->m_engineNameForService.value(plasmoidService));
74
 
    plasmoidService->startOperationCall(op);
75
 
    connect(plasmoidService, SIGNAL(finished(Plasma::ServiceJob*)),
76
 
            this, SLOT(slotJobFinished(Plasma::ServiceJob*)));
77
 
}
78
 
 
79
 
DataEngineConsumer::DataEngineConsumer()
80
 
    : m_monitor(new ServiceMonitor(this))
81
 
{
82
 
}
83
 
 
84
 
DataEngineConsumer::~DataEngineConsumer()
85
 
{
86
 
    foreach (const QString &engine, m_loadedEngines) {
87
 
        DataEngineManager::self()->unloadEngine(engine);
88
 
    }
89
 
 
90
 
    delete m_monitor;
91
 
}
92
 
 
93
 
DataEngine *DataEngineConsumer::dataEngine(const QString &name)
94
 
{
95
 
    if (m_loadedEngines.contains(name)) {
96
 
        return DataEngineManager::self()->engine(name);
97
 
    }
98
 
 
99
 
    DataEngine *engine = DataEngineManager::self()->loadEngine(name);
100
 
    if (engine->isValid()) {
101
 
        m_loadedEngines.insert(name);
102
 
    }
103
 
 
104
 
    return engine;
105
 
}
106
 
 
107
 
DataEngine *DataEngineConsumer::remoteDataEngine(const KUrl &location, const QString &name)
108
 
{
109
 
    return 0;
110
 
}
111
 
 
112
 
 
113
 
} // namespace Plasma
114
 
 
115
 
#include "dataengineconsumer_p.moc"
116
 
 
117