Skip to content

Commit

Permalink
Fix building with -DWITH_BINDINGS=OFF
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed Feb 14, 2017
1 parent 620ad41 commit dccf010
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 6 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Expand Up @@ -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
Expand Down
19 changes: 15 additions & 4 deletions src/app/pluginmanager/qgspluginmanager.cpp
Expand Up @@ -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
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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
Expand All @@ -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 );
}

Expand Down
2 changes: 1 addition & 1 deletion src/app/pluginmanager/qgspluginmanager.h
Expand Up @@ -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;
Expand Down
22 changes: 21 additions & 1 deletion src/app/qgisapp.cpp
Expand Up @@ -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>
Expand Down Expand Up @@ -965,6 +967,7 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, bool skipVersionCh
}
}

#ifdef WITH_BINDINGS
if ( mPythonUtils && mPythonUtils->isEnabled() )
{
startProfile( QStringLiteral( "initPluginInstaller" ) );
Expand All @@ -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
Expand Down Expand Up @@ -1846,6 +1850,7 @@ void QgisApp::showStyleManager()

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

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

void QgisApp::createActionGroups()
Expand Down Expand Up @@ -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() )
{
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}


Expand Down Expand Up @@ -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();
Expand All @@ -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
}


Expand All @@ -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;
}

Expand Down Expand Up @@ -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" ) ) );
Expand All @@ -9019,6 +9038,7 @@ void QgisApp::loadPythonSupport()

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

void QgisApp::checkQgisVersion()
Expand Down
26 changes: 26 additions & 0 deletions src/app/qgspluginregistry.cpp
Expand Up @@ -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"
Expand Down Expand Up @@ -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;
}
Expand All @@ -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();
}
Expand All @@ -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;
}

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

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


Expand Down Expand Up @@ -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
}


Expand Down Expand Up @@ -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" ) );
Expand Down Expand Up @@ -296,6 +309,7 @@ void QgsPluginRegistry::loadPythonPlugin( const QString& packageName )

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


Expand Down Expand Up @@ -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" ) );
Expand All @@ -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
}


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

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

QgsDebugMsg( "Plugin loading completed" );
}
Expand Down Expand Up @@ -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
Expand All @@ -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()
Expand Down

0 comments on commit dccf010

Please sign in to comment.