File indexing completed on 2024-05-12 04:49:36

0001 /****************************************************************************************
0002 * Copyright (c) 2010 Nathan Sala <sala.nathan@gmail.com>                               *
0003 *                                                                                      *
0004 * This program is free software; you can redistribute it and/or modify it under        *
0005 * the terms of the GNU General Public License as published by the Free Software        *
0006 * Foundation; either version 2 of the License, or (at your option) any later           *
0007 * version.                                                                             *
0008 *                                                                                      *
0009 * This program is distributed in the hope that it will be useful, but WITHOUT ANY      *
0010 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A      *
0011 * PARTICULAR PURPOSE. See the GNU General Public License for more details.             *
0012 *                                                                                      *
0013 * You should have received a copy of the GNU General Public License along with         *
0014 * this program.  If not, see <http://www.gnu.org/licenses/>.                           *
0015 ****************************************************************************************/
0016 
0017 #include "TestDataEngineBlackBox.h"
0018 #include <KServiceTypeTrader>
0019 
0020 TestDataEngineBlackBox::TestDataEngineBlackBox(QString identifier)
0021 {
0022     Plasma::DataEngine* engine = 0;
0023     // load the engine, add it to the engines
0024     QString constraint = QString("[X-KDE-PluginInfo-Name] == '" + identifier + '\'').arg(identifier);
0025     KService::List offers = KServiceTypeTrader::self()->query("Plasma/DataEngine", constraint);
0026     QString error;
0027 
0028     if (!offers.isEmpty()) {
0029         QVariantList allArgs;
0030         allArgs << offers.first()->storageId();
0031         QString api = offers.first()->property("X-Plasma-API").toString();
0032         if (api.isEmpty()) {
0033             if (offers.first()) {
0034                 KPluginLoader plugin(*offers.first());
0035                 if (Plasma::isPluginVersionCompatible(plugin.pluginVersion())) {
0036                    engine = offers.first()->createInstance<Plasma::DataEngine>(0, allArgs, &error);
0037                }
0038             }
0039         } else {
0040             engine = new Plasma::DataEngine(0, offers.first());
0041         }
0042     }
0043     
0044     m_engine = engine;
0045 }
0046 
0047 
0048 TestDataEngineBlackBox::~TestDataEngineBlackBox()
0049 {
0050   delete m_engine;
0051 }