1
/***************************************************************************
2
qgsproviderregistry.cpp - Singleton class for
3
registering data providers.
5
begin : Sat Jan 10 2004
6
copyright : (C) 2004 by Gary E.Sherman
7
email : sherman at mrcc.com
8
***************************************************************************/
10
/***************************************************************************
12
* This program is free software; you can redistribute it and/or modify *
13
* it under the terms of the GNU General Public License as published by *
14
* the Free Software Foundation; either version 2 of the License, or *
15
* (at your option) any later version. *
17
***************************************************************************/
18
/* $Id: qgsproviderregistry.cpp,v 1.8.10.1 2005/07/09 23:51:20 timlinux Exp $ */
21
#include <qmessagebox.h>
25
#include <qapplication.h>
26
#include "qgsprovidermetadata.h"
27
#include "qgsproviderregistry.h"
28
// typedefs for provider plugin functions of interest
29
typedef QString providerkey_t();
30
typedef QString description_t();
31
typedef bool isprovider_t();
33
QgsProviderRegistry *QgsProviderRegistry::_instance = 0;
34
QgsProviderRegistry *QgsProviderRegistry::instance(QString pluginPath)
38
_instance = new QgsProviderRegistry(pluginPath);
43
QgsProviderRegistry::QgsProviderRegistry(QString pluginPath)
45
// At startup, examine the libs in the qgis/lib dir and store those that
46
// are a provider shared lib
47
// check all libs in the current plugin directory and get name and descriptions
48
//TODO figure out how to register and identify data source plugin for a specific
50
/* char **argv = qApp->argv();
51
QString appDir = argv[0];
52
int bin = appDir.findRev("/bin", -1, false);
53
QString baseDir = appDir.left(bin);
54
QString libDir = baseDir + "/lib"; */
57
QDir pluginDir(libDir, "*.dll", QDir::Name | QDir::IgnoreCase, QDir::Files | QDir::NoSymLinks);
59
QDir pluginDir(libDir, "*.so*", QDir::Name | QDir::IgnoreCase, QDir::Files | QDir::NoSymLinks);
62
std::cerr << "Checking " << libDir.local8Bit() << " for provider plugins" << std::endl;
64
if (pluginDir.count() == 0)
66
QString msg = QObject::tr("No Data Provider Plugins", "No QGIS data provider plugins found in:");
67
msg += "\n" + libDir + "\n\n";
68
msg += QObject::tr("No vector layers can be loaded. Check your QGIS installation");
69
QMessageBox::critical(0, QObject::tr("No Data Providers"), msg);
73
for (unsigned i = 0; i < pluginDir.count(); i++)
75
QLibrary *myLib = new QLibrary(libDir + "/" + pluginDir[i]);
76
bool loaded = myLib->load();
80
std::cout << "Checking " << myLib->library().local8Bit() << std::endl;
82
// get the description and the key for the provider plugin
84
isprovider_t *isProvider = (isprovider_t *) myLib->resolve("isProvider");
88
// check to see if this is a provider plugin
91
// looks like a provider. get the key and description
92
description_t *pDesc = (description_t *) myLib->resolve("description");
93
providerkey_t *pKey = (providerkey_t *) myLib->resolve("providerKey");
96
const char *foo = pKey().local8Bit();
97
// add this provider to the provider map
98
provider[pKey()] = new QgsProviderMetadata(pKey(), pDesc(), myLib->library());
100
std::cout << "Loaded " << pDesc().local8Bit() << std::endl;
105
library().local8Bit() << " Unable to find one of the required provider functions:\n\tproviderKey() or description()" <<
115
QString QgsProviderRegistry::library(QString providerKey)
118
QgsProviderMetadata *md = provider[providerKey];
121
retval = md->library();
126
QString QgsProviderRegistry::pluginList(bool asHTML)
128
std::map < QString, QgsProviderMetadata * >::iterator it = provider.begin();
130
if (provider.size() == 0)
132
list = QObject::tr("No data provider plugins are available. No vector layers can be loaded");
139
while (it != provider.end())
141
QgsProviderMetadata *mp = (*it).second;
144
list += "<li>" + mp->description() + "<br>";
147
list += mp->description() + "\n";
159
void QgsProviderRegistry::setLibDirectory(QString path)
164
QString QgsProviderRegistry::libDirectory()