Skip to content
Permalink
Browse files

Fix building with -DWITH_BINDINGS=OFF

  • Loading branch information
m-kuhn committed Feb 14, 2017
1 parent 620ad41 commit dccf010a135b3045108565e476a93a1ada8dc356
@@ -105,6 +105,7 @@ IF (WITH_BINDINGS)
SET (WITH_QSCIAPI TRUE CACHE BOOL "Whether to generate PyQGIS QScintilla2 API file. (For devs) run 'make qsci-pap-src' in between QGIS build and install to regenerate .pap file in source tree for console auto-completion.")
# keep casual users from updating their source tree via WITH_QSCIAPI
MARK_AS_ADVANCED (WITH_QSCIAPI)
ADD_DEFINITIONS(-DWITH_BINDINGS)
ENDIF (WITH_BINDINGS)

#BUILD WITH QtMobility by default on android only. Other platform can force it
@@ -44,6 +44,9 @@
#include "qgisplugin.h"
#include "qgslogger.h"
#include "qgspluginitemdelegate.h"
#ifdef WITH_BINDINGS
#include "qgspythonutils.h"
#endif

// Do we need this?
// #define TESTLIB
@@ -552,16 +555,22 @@ void QgsPluginManager::reloadModelData()
}
}

#ifdef WITH_BINDINGS
// Add spacers for sort by status
if ( mPythonUtils && mPythonUtils->isEnabled() )
{
// TODO: implement better sort method instead of these dummy -Z statuses
mModelPlugins->appendRow( createSpacerItem( tr( "Only locally available", "category: plugins that are only locally available" ), QStringLiteral( "orphanZ" ) ) );
if ( hasReinstallablePlugins() ) mModelPlugins->appendRow( createSpacerItem( tr( "Reinstallable", "category: plugins that are installed and available" ), QStringLiteral( "installedZ" ) ) );
if ( hasUpgradeablePlugins() ) mModelPlugins->appendRow( createSpacerItem( tr( "Upgradeable", "category: plugins that are installed and there is a newer version available" ), QStringLiteral( "upgradeableZ" ) ) );
if ( hasNewerPlugins() ) mModelPlugins->appendRow( createSpacerItem( tr( "Downgradeable", "category: plugins that are installed and there is an OLDER version available" ), QStringLiteral( "newerZ" ) ) );
if ( hasAvailablePlugins() ) mModelPlugins->appendRow( createSpacerItem( tr( "Installable", "category: plugins that are available for installation" ), QStringLiteral( "not installedZ" ) ) );
if ( hasReinstallablePlugins() )
mModelPlugins->appendRow( createSpacerItem( tr( "Reinstallable", "category: plugins that are installed and available" ), QStringLiteral( "installedZ" ) ) );
if ( hasUpgradeablePlugins() )
mModelPlugins->appendRow( createSpacerItem( tr( "Upgradeable", "category: plugins that are installed and there is a newer version available" ), QStringLiteral( "upgradeableZ" ) ) );
if ( hasNewerPlugins() )
mModelPlugins->appendRow( createSpacerItem( tr( "Downgradeable", "category: plugins that are installed and there is an OLDER version available" ), QStringLiteral( "newerZ" ) ) );
if ( hasAvailablePlugins() )
mModelPlugins->appendRow( createSpacerItem( tr( "Installable", "category: plugins that are available for installation" ), QStringLiteral( "not installedZ" ) ) );
}
#endif

updateWindowTitle();

@@ -1064,6 +1073,7 @@ void QgsPluginManager::addToRepositoryList( const QMap<QString, QString>& reposi
// "Close" button clicked
void QgsPluginManager::reject()
{
#ifdef WITH_BINDINGS
if ( mPythonUtils && mPythonUtils->isEnabled() )
{
// get the QSettings group from the installer
@@ -1074,6 +1084,7 @@ void QgsPluginManager::reject()
settings.setValue( settingsGroup + "/checkOnStartInterval", QVariant( mCheckingOnStartIntervals.value( comboInterval->currentIndex() ) ) );
QgsPythonRunner::run( QStringLiteral( "pyplugin_installer.instance().onManagerClose()" ) );
}
#endif
done( 1 );
}

@@ -28,9 +28,9 @@
#include "qgisgui.h"
#include "qgshelp.h"
#include "qgsmessagebar.h"
#include "qgspythonutils.h"

class QgsPluginSortFilterProxyModel;
class QgsPythonUtils;

const int PLUGMAN_TAB_ALL = 0;
const int PLUGMAN_TAB_INSTALLED = 1;
@@ -352,7 +352,9 @@ extern "C"
#include "qgsnewspatialitelayerdialog.h"
#include "qgsnewgeopackagelayerdialog.h"

#ifdef WITH_BINDINGS
#include "qgspythonutils.h"
#endif

#ifndef Q_OS_WIN
#include <dlfcn.h>
@@ -965,6 +967,7 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, bool skipVersionCh
}
}

#ifdef WITH_BINDINGS
if ( mPythonUtils && mPythonUtils->isEnabled() )
{
startProfile( QStringLiteral( "initPluginInstaller" ) );
@@ -976,6 +979,7 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, bool skipVersionCh
endProfile();
}
else if ( mActionShowPythonDialog || mActionInstallFromZip )
#endif
{
// python is disabled so get rid of the action for python console
// and installing plugin from ZUIP
@@ -1846,6 +1850,7 @@ void QgisApp::showStyleManager()

void QgisApp::showPythonDialog()
{
#ifdef WITH_BINDINGS
if ( !mPythonUtils || !mPythonUtils->isEnabled() )
return;

@@ -1865,6 +1870,7 @@ void QgisApp::showPythonDialog()
addWindow( mActionShowPythonDialog );
}
#endif
#endif
}

void QgisApp::createActionGroups()
@@ -5019,6 +5025,7 @@ bool QgisApp::addProject( const QString& projectFile )

QSettings settings;

#ifdef WITH_BINDINGS
// does the project have any macros?
if ( mPythonUtils && mPythonUtils->isEnabled() )
{
@@ -5061,6 +5068,7 @@ bool QgisApp::addProject( const QString& projectFile )
}
}
}
#endif

emit projectRead(); // let plug-ins know that we've read in a new
// project so that they can check any project
@@ -5330,13 +5338,15 @@ void QgisApp::openProject( QAction *action )

void QgisApp::runScript( const QString &filePath )
{
#ifdef WITH_BINDINGS
if ( !mPythonUtils || !mPythonUtils->isEnabled() )
return;

mPythonUtils->runString(
QString( "import sys\n"
"exec(open(\"%1\".replace(\"\\\\\", \"/\").encode(sys.getfilesystemencoding())).read())\n" ).arg( filePath )
, tr( "Failed to run Python script:" ), false );
#endif
}


@@ -8918,13 +8928,14 @@ void QgisApp::zoomToLayerExtent()

void QgisApp::showPluginManager()
{

#ifdef WITH_BINDINGS
if ( mPythonUtils && mPythonUtils->isEnabled() )
{
// Call pluginManagerInterface()->showPluginManager() as soon as the plugin installer says the remote data is fetched.
QgsPythonRunner::run( QStringLiteral( "pyplugin_installer.instance().showPluginManagerWhenReady()" ) );
}
else
#endif
{
// Call the pluginManagerInterface directly
mQgisInterface->pluginManagerInterface()->showPluginManager();
@@ -8933,10 +8944,12 @@ void QgisApp::showPluginManager()

void QgisApp::installPluginFromZip()
{
#ifdef WITH_BINDINGS
if ( mPythonUtils && mPythonUtils->isEnabled() )
{
QgsPythonRunner::run( QStringLiteral( "pyplugin_installer.instance().installFromZipFile()" ) );
}
#endif
}


@@ -8948,19 +8961,23 @@ class QgsPythonRunnerImpl : public QgsPythonRunner

virtual bool runCommand( QString command, QString messageOnError = QString() ) override
{
#ifdef WITH_BINDINGS
if ( mPythonUtils && mPythonUtils->isEnabled() )
{
return mPythonUtils->runString( command, messageOnError, false );
}
#endif
return false;
}

virtual bool evalCommand( QString command, QString &result ) override
{
#ifdef WITH_BINDINGS
if ( mPythonUtils && mPythonUtils->isEnabled() )
{
return mPythonUtils->evalString( command, result );
}
#endif
return false;
}

@@ -8993,6 +9010,8 @@ void QgisApp::loadPythonSupport()
}
}

#ifdef WITH_BINDINGS

//QgsDebugMsg("Python support library loaded successfully.");
typedef QgsPythonUtils*( *inst )();
inst pythonlib_inst = reinterpret_cast< inst >( cast_to_fptr( pythonlib.resolve( "instance" ) ) );
@@ -9019,6 +9038,7 @@ void QgisApp::loadPythonSupport()

QgsMessageLog::logMessage( tr( "Python support ENABLED :-) " ), QString::null, QgsMessageLog::INFO );
}
#endif
}

void QgisApp::checkQgisVersion()
@@ -28,7 +28,9 @@
#include "qgspluginregistry.h"
#include "qgspluginmetadata.h"
#include "qgisplugin.h"
#ifdef WITH_BINDINGS
#include "qgspythonutils.h"
#endif
#include "qgisapp.h"
#include "qgslogger.h"
#include "qgsmessagelog.h"
@@ -74,10 +76,12 @@ bool QgsPluginRegistry::isLoaded( const QString& key ) const
if ( it != mPlugins.end() ) // found a c++ plugin?
return true;

#ifdef WITH_BINDINGS
if ( mPythonUtils && mPythonUtils->isEnabled() )
{
return mPythonUtils->isPluginLoaded( key );
}
#endif

return false;
}
@@ -88,11 +92,13 @@ QString QgsPluginRegistry::library( const QString& key )
if ( it != mPlugins.constEnd() )
return it->library();

#ifdef WITH_BINDINGS
if ( mPythonUtils && mPythonUtils->isEnabled() )
{
if ( mPythonUtils->isPluginLoaded( key ) )
return key;
}
#endif

return QString();
}
@@ -110,11 +116,13 @@ QgisPlugin *QgsPluginRegistry::plugin( const QString& key )

bool QgsPluginRegistry::isPythonPlugin( const QString& key ) const
{
#ifdef WITH_BINDINGS
if ( mPythonUtils && mPythonUtils->isEnabled() )
{
if ( mPythonUtils->isPluginLoaded( key ) )
return true;
}
#endif
return false;
}

@@ -136,6 +144,7 @@ void QgsPluginRegistry::dump()
it->library() ) );
}

#ifdef WITH_BINDINGS
if ( mPythonUtils && mPythonUtils->isEnabled() )
{
QgsDebugMsg( "PYTHON PLUGINS IN REGISTRY:" );
@@ -145,6 +154,7 @@ void QgsPluginRegistry::dump()
QgsDebugMsg( pluginName );
}
}
#endif
}


@@ -176,13 +186,15 @@ void QgsPluginRegistry::unloadAll()
}
}

#ifdef WITH_BINDINGS
if ( mPythonUtils && mPythonUtils->isEnabled() )
{
Q_FOREACH ( const QString& pluginName, mPythonUtils->listActivePlugins() )
{
mPythonUtils->unloadPlugin( pluginName );
}
}
#endif
}


@@ -263,6 +275,7 @@ bool QgsPluginRegistry::checkQgisVersion( const QString& minVersion, const QStri

void QgsPluginRegistry::loadPythonPlugin( const QString& packageName )
{
#ifdef WITH_BINDINGS
if ( !mPythonUtils || !mPythonUtils->isEnabled() )
{
QgsMessageLog::logMessage( QObject::tr( "Python is not enabled in QGIS." ), QObject::tr( "Plugins" ) );
@@ -296,6 +309,7 @@ void QgsPluginRegistry::loadPythonPlugin( const QString& packageName )

settings.remove( "/PythonPlugins/watchDog/" + packageName );
}
#endif
}


@@ -404,6 +418,7 @@ void QgsPluginRegistry::loadCppPlugin( const QString& theFullPathName )

void QgsPluginRegistry::unloadPythonPlugin( const QString& packageName )
{
#ifdef WITH_BINDINGS
if ( !mPythonUtils || !mPythonUtils->isEnabled() )
{
QgsMessageLog::logMessage( QObject::tr( "Python is not enabled in QGIS." ), QObject::tr( "Plugins" ) );
@@ -419,6 +434,7 @@ void QgsPluginRegistry::unloadPythonPlugin( const QString& packageName )
// disable the plugin no matter if successfully loaded or not
QSettings settings;
settings.setValue( "/PythonPlugins/" + packageName, false );
#endif
}


@@ -488,6 +504,7 @@ void QgsPluginRegistry::restoreSessionPlugins( const QString& thePluginDirString
}
}

#ifdef WITH_BINDINGS
if ( mPythonUtils && mPythonUtils->isEnabled() )
{
// check for python plugins system-wide
@@ -551,6 +568,7 @@ void QgsPluginRegistry::restoreSessionPlugins( const QString& thePluginDirString
}
// end - temporary fix for issue #5879
}
#endif

QgsDebugMsg( "Plugin loading completed" );
}
@@ -581,6 +599,7 @@ bool QgsPluginRegistry::checkCppPlugin( const QString& pluginFullPath )

bool QgsPluginRegistry::checkPythonPlugin( const QString& packageName )
{
#ifdef WITH_BINDINGS
QString pluginName, description, /*category,*/ version;

// get information from the plugin
@@ -599,14 +618,21 @@ bool QgsPluginRegistry::checkPythonPlugin( const QString& packageName )
}

return true;
#else
return false;
#endif
}

bool QgsPluginRegistry::isPythonPluginCompatible( const QString& packageName ) const
{
#ifdef WITH_BINDINGS
QString minVersion = mPythonUtils->getPluginMetadata( packageName, QStringLiteral( "qgisMinimumVersion" ) );
// try to read qgisMaximumVersion. Note checkQgisVersion can cope with "__error__" value.
QString maxVersion = mPythonUtils->getPluginMetadata( packageName, QStringLiteral( "qgisMaximumVersion" ) );
return minVersion != QLatin1String( "__error__" ) && checkQgisVersion( minVersion, maxVersion );
#else
return false;
#endif
}

QList<QgsPluginMetadata*> QgsPluginRegistry::pluginData()

0 comments on commit dccf010

Please sign in to comment.
You can’t perform that action at this time.