From 2d98d307f2735ba102e5c87d8c77570889b21ace Mon Sep 17 00:00:00 2001 From: Brian David Pritchett Date: Tue, 13 Jul 2010 01:07:30 +0000 Subject: [PATCH] I accidently deleted a file that was needed! Readding. svn path=/trunk/KDE/kdelibs/; revision=1149245 --- private/storage.cpp | 88 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 private/storage.cpp diff --git a/private/storage.cpp b/private/storage.cpp new file mode 100644 index 000000000..b654f1b4f --- /dev/null +++ b/private/storage.cpp @@ -0,0 +1,88 @@ +///////////////////////////////////////////////////////////////////////// +// storage.cpp // +// // +// Copyright (C) 2010 Brian Pritchett // +// // +// This library is free software; you can redistribute it and/or // +// modify it under the terms of the GNU Lesser General Public // +// License as published by the Free Software Foundation; either // +// version 2.1 of the License, or (at your option) any later version. // +// // +// This library 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 // +// Lesser General Public License for more details. // +// // +// You should have received a copy of the GNU Lesser General Public // +// License along with this library; if not, write to the Free Software // +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA // +// 02110-1301 USA // +///////////////////////////////////////////////////////////////////////// + +#include "private/storage_p.h" +#include + +//Storage Job implentation +StorageJob::StorageJob(const QString& destination, + const QString& operation, + const QMap& parameters, + QObject *parent) + : ServiceJob(destination, operation, parameters, parent) +{ +} + +void StorageJob::start() +{ + static QStringList* keyList = NULL; + QMap params = parameters(); + QString source = params["source"].toString(); + KConfig config("plasma-storagerc"); + KConfigGroup destinationGroup(&config, destination()); + KConfigGroup sourceGroup(&destinationGroup, source); + KConfigGroup data(&sourceGroup, "Data"); + + if (operationName() == "save") { + // KConfigGroup metaData(&sourceGroup, "MetaData"); + // metaData.writeEntry("TimeStamp", QDateTime::currentDateTime()); + data.writeEntry(params["key"].toString(), params["data"]); + setResult(true); + } else if (operationName() == "retrieve") { + if (keyList == NULL) { + kDebug() << "NULL"; + keyList = new QStringList; + *keyList = data.keyList(); + } + if (keyList->isEmpty()) { + setError(1); + delete keyList; + keyList = NULL; + } else { + QString key = keyList->first(); + QHash h; + QVariant v(data.readEntry(key)); + h["key"] = key; + h["data"] = v; + keyList->pop_front(); + setResult(h); + } + } + setError(1); +} + +Plasma::ServiceJob* Storage::createJob(const QString &operation, QMap ¶meters) +{ + return new StorageJob(m_serviceName, operation, parameters); +} + +//Storage implementation +Storage::Storage(const QString& destination, QObject* parent) : Plasma::Service(parent) +{ + m_serviceName = destination; + setName("storage"); +} + +Storage::~Storage() +{ +} + +#include "storage_p.moc"