[KDevPlatform/1.2] 5774a52: Check that git is installed when loading Git Suppo

Aleix Pol aleixpol at kde.org
Sat Dec 18 12:51:45 UTC 2010


On Fri, Dec 17, 2010 at 10:47 PM, Dmitry Risenberg <
dmitry.risenberg at gmail.com> wrote:

> commit 5774a52c3a31a5deac524e36df7af1a20b0671c3
> branch 1.2
> Author: Dmitry Risenberg <dmitry.risenberg at gmail.com>
> Date:   Sat Dec 18 00:03:12 2010 +0300
>
>    Check that git is installed when loading Git Support plugin.
>    CCBUG: 257650.
>
> diff --git a/interfaces/iplugin.cpp b/interfaces/iplugin.cpp
> index 5d14247..0a87089 100644
> --- a/interfaces/iplugin.cpp
> +++ b/interfaces/iplugin.cpp
> @@ -199,6 +199,16 @@ void KDevelop::IPlugin::createActionsForMainWindow(
> Sublime::MainWindow* /*windo
>  {
>  }
>
> +bool KDevelop::IPlugin::hasError() const
> +{
> +    return false;
> +}
> +
> +QString KDevelop::IPlugin::errorDescription() const
> +{
> +    return QString();
> +}
> +
>  #include "iplugin.moc"
>
>
> diff --git a/interfaces/iplugin.h b/interfaces/iplugin.h
> index 508a92f..8ac4f8a 100644
> --- a/interfaces/iplugin.h
> +++ b/interfaces/iplugin.h
> @@ -213,6 +213,17 @@ public:
>      * @param actions Add your actions here. A new set of actions has to be
> created for each mainwindow.
>      */
>     virtual void createActionsForMainWindow( Sublime::MainWindow* window,
> QString& xmlFile, KActionCollection& actions );
> +
> +    /**
> +     * This function is necessary because there is no proper way to signal
> errors from plugin constructor.
> +     * @returns True if the plugin has encountered an error, false
> otherwise.
> +     */
> +    virtual bool hasError() const;
> +
> +    /**
> +     * Description of the last encountered error, of an empty string if
> none.
> +     */
> +    virtual QString errorDescription() const;
>  public Q_SLOTS:
>     /**
>      * Re-initialize the global icon loader
> diff --git a/plugins/git/gitplugin.cpp b/plugins/git/gitplugin.cpp
> index c149a50..cc25650 100644
> --- a/plugins/git/gitplugin.cpp
> +++ b/plugins/git/gitplugin.cpp
> @@ -48,6 +48,7 @@
>  #include <interfaces/iruncontroller.h>
>  #include "stashmanagerdialog.h"
>  #include <KMessageBox>
> +#include <KStandardDirs>
>  #include "gitjob.h"
>
>  K_PLUGIN_FACTORY(KDevGitFactory, registerPlugin<GitPlugin>(); )
> @@ -161,9 +162,16 @@ QDir urlDir(const KUrl::List& urls) { return
> urlDir(urls.first()); } //TODO: cou
>  GitPlugin::GitPlugin( QObject *parent, const QVariantList & )
>     : DistributedVersionControlPlugin(parent,
> KDevGitFactory::componentData()), m_oldVersion(false)
>  {
> +    if (KStandardDirs::findExe("git").isEmpty()) {
> +        m_hasError = true;
> +        m_errorDescription = "git is not installed";
> +        return;
> +    }
> +
>     KDEV_USE_EXTENSION_INTERFACE( KDevelop::IBasicVersionControl )
>     KDEV_USE_EXTENSION_INTERFACE( KDevelop::IDistributedVersionControl )
>
> +    m_hasError = false;
>     core()->uiController()->addToolView(i18n("Git"), dvcsViewFactory());
>     setObjectName("Git");
>
> @@ -1175,3 +1183,13 @@ KDevelop::VcsLocationWidget*
> GitPlugin::vcsLocation(QWidget* parent) const
>  {
>     return new GitVcsLocationWidget(parent);
>  }
> +
> +bool GitPlugin::hasError() const
> +{
> +    return m_hasError;
> +}
> +
> +QString GitPlugin::errorDescription() const
> +{
> +    return m_errorDescription;
> +}
> diff --git a/plugins/git/gitplugin.h b/plugins/git/gitplugin.h
> index de40d50..1a7c532 100644
> --- a/plugins/git/gitplugin.h
> +++ b/plugins/git/gitplugin.h
> @@ -138,6 +138,9 @@ public:
>
>     bool hasStashes(const QDir& repository);
>     bool hasModifications(const QDir& repository);
> +
> +    virtual bool hasError() const;
> +    virtual QString errorDescription() const;
>  protected:
>
>     KUrl repositoryRoot(const KUrl& path);
> @@ -183,6 +186,9 @@ private:
>
>     /** Tells if it's older than 1.7.0 or not */
>     bool m_oldVersion;
> +
> +    bool m_hasError;
> +    QString m_errorDescription;
>  };
>
>  #endif
> diff --git a/shell/plugincontroller.cpp b/shell/plugincontroller.cpp
> index 15f5c55..23408a6 100644
> --- a/shell/plugincontroller.cpp
> +++ b/shell/plugincontroller.cpp
> @@ -439,6 +439,13 @@ IPlugin *PluginController::loadPluginInternal( const
> QString &pluginId )
>
>     if ( plugin )
>     {
> +        if ( plugin->hasError() ) {
> +            KMessageBox::error(0, i18n("Plugin '%1' could not be loaded
> correctly and was disabled.\nReason: %2.", info.name(),
> plugin->errorDescription()));
> +            info.setPluginEnabled(false);
> +
>  info.save(Core::self()->activeSession()->config()->group(pluginControllerGrp));
> +            unloadPlugin(pluginId);
> +            return 0;
> +        }
>         d->loadedPlugins.insert( info, plugin );
>         info.setPluginEnabled( true );
>
> diff --git a/shell/settings/pluginpreferences.cpp
> b/shell/settings/pluginpreferences.cpp
> index edb4290..a7da484 100644
> --- a/shell/settings/pluginpreferences.cpp
> +++ b/shell/settings/pluginpreferences.cpp
> @@ -79,6 +79,7 @@ void PluginPreferences::save()
>     selector->save();
>     KCModule::save();
>     Core::self()->pluginControllerInternal()->updateLoadedPlugins();
> +    selector->load();   // Some plugins may have failed to load, they must
> be unchecked.
>  }
>
>  void PluginPreferences::load()
>

This patch looks really ugly.

Wouldn't it be easier that if it's not found Git support unloaded himself
automatically from the PluginController when constructed?

Aleix
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kde.org/pipermail/kdevelop-devel/attachments/20101218/ff8e2892/attachment.html>


More information about the KDevelop-devel mailing list