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