Commit 6409161f authored by Morten Volden's avatar Morten Volden
Browse files

Move the implementation of hasError and setHasError to iplugin. They are...

Move the implementation of hasError and setHasError to iplugin. They are basically just getter/setters and actual implementation belong there - not in the individual plug-ins.
Unified the way plug-ins report errors when failing.

Differential Revision: https://phabricator.kde.org/D2192
parent aa8b3ddb
......@@ -78,6 +78,7 @@ public:
IPlugin *q;
ICore *core;
QVector<QByteArray> m_extensions;
QString m_errorDescription;
};
IPlugin::IPlugin( const QString &componentName, QObject *parent )
......@@ -184,12 +185,18 @@ void KDevelop::IPlugin::createActionsForMainWindow( Sublime::MainWindow* /*windo
bool KDevelop::IPlugin::hasError() const
{
return false;
return !d->m_errorDescription.isEmpty();
}
void KDevelop::IPlugin::setErrorDescription(const QString& description)
{
d->m_errorDescription = description;
}
QString KDevelop::IPlugin::errorDescription() const
{
return QString();
return d->m_errorDescription;
}
int KDevelop::IPlugin::configPages() const
......
......@@ -210,14 +210,21 @@ public:
/**
* 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.
* @returns True if the plugin has encountered an error (and therefore has an error description),
* false otherwise.
*/
virtual bool hasError() const;
bool hasError() const;
/**
* Description of the last encountered error, of an empty string if none.
*/
virtual QString errorDescription() const;
QString errorDescription() const;
/**
* Set a @p description of the errror encountered. An empty error
* description implies no error in the plugin.
*/
void setErrorDescription(QString const& description);
/**
* Get the global config page with the \p number, config pages from 0 to
......
......@@ -45,13 +45,11 @@ using namespace KDevelop;
BazaarPlugin::BazaarPlugin(QObject* parent, const QVariantList& args) :
IPlugin(QStringLiteral("kdevbazaar"), parent),
m_vcsPluginHelper(new KDevelop::VcsPluginHelper(this, this)), m_hasError(false)
m_vcsPluginHelper(new KDevelop::VcsPluginHelper(this, this))
{
Q_UNUSED(args); // What is this?
if (QStandardPaths::findExecutable(QStringLiteral("bzr")).isEmpty()) {
m_hasError = true;
m_errorDescription = i18n("Bazaar is not installed (bzr executable not"
" found)");
setErrorDescription(i18n("Unable to find Bazaar (bzr) executable Is it installed on the system?"));
return;
}
......@@ -339,12 +337,3 @@ ContextMenuExtension BazaarPlugin::contextMenuExtension(Context* context)
return menuExt;
}
bool BazaarPlugin::hasError() const
{
return m_hasError;
}
QString BazaarPlugin::errorDescription() const
{
return m_errorDescription;
}
......@@ -40,9 +40,6 @@ public:
explicit BazaarPlugin(QObject* parent, const QVariantList& args = QVariantList());
~BazaarPlugin() override;
bool hasError() const override;
QString errorDescription() const override;
QString name() const override;
KDevelop::VcsJob* add(const QList<QUrl>& localLocations, RecursionMode recursion=Recursive) override;
......@@ -75,9 +72,6 @@ private slots:
private:
KDevelop::VcsPluginHelper* m_vcsPluginHelper;
bool m_hasError;
QString m_errorDescription;
};
#endif // BAZAAR_BAZAARPLUGIN_H
......@@ -181,8 +181,7 @@ GitPlugin::GitPlugin( QObject *parent, const QVariantList & )
: DistributedVersionControlPlugin(parent, QStringLiteral("kdevgit")), m_oldVersion(false), m_usePrefix(true)
{
if (QStandardPaths::findExecutable(QStringLiteral("git")).isEmpty()) {
m_hasError = true;
m_errorDescription = i18n("git is not installed");
setErrorDescription(i18n("Unable to find git executable. Is it installed on the system?"));
return;
}
......@@ -190,7 +189,6 @@ GitPlugin::GitPlugin( QObject *parent, const QVariantList & )
KDEV_USE_EXTENSION_INTERFACE( KDevelop::IDistributedVersionControl )
KDEV_USE_EXTENSION_INTERFACE( KDevelop::IBranchingVersionControl )
m_hasError = false;
setObjectName(QStringLiteral("Git"));
DVcsJob* versionJob = new DVcsJob(QDir::tempPath(), this, KDevelop::OutputJob::Silent);
......@@ -1458,16 +1456,6 @@ 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;
}
void GitPlugin::registerRepositoryForCurrentBranchChanges(const QUrl& repository)
{
QDir dir = dotGitDirectory(repository);
......
......@@ -140,8 +140,6 @@ public:
bool hasModifications(const QDir& repository);
bool hasModifications(const QDir& repo, const QUrl& file);
bool hasError() const override;
QString errorDescription() const override;
void registerRepositoryForCurrentBranchChanges(const QUrl& repository) override;
KDevelop::CheckInRepositoryJob* isInRepository(KTextEditor::Document* document) override;
......@@ -216,8 +214,6 @@ private:
/** Tells if it's older than 1.7.0 or not */
bool m_oldVersion;
bool m_hasError;
QString m_errorDescription;
KDirWatch* m_watcher;
QList<QUrl> m_branchesChange;
bool m_usePrefix;
......
......@@ -62,7 +62,9 @@ KDevKonsoleViewPlugin::KDevKonsoleViewPlugin( KPluginFactory* konsoleFactory, QO
, m_konsoleFactory(konsoleFactory)
, m_viewFactory(konsoleFactory ? new KDevKonsoleViewFactory(this) : nullptr)
{
if (m_viewFactory) {
if(!m_viewFactory) {
setErrorDescription(i18n("Failed to load 'konsolepart' plugin"));
} else {
core()->uiController()->addToolView(QStringLiteral("Konsole"), m_viewFactory);
}
}
......@@ -74,16 +76,6 @@ void KDevKonsoleViewPlugin::unload()
}
}
bool KDevKonsoleViewPlugin::hasError() const
{
return !m_viewFactory;
}
QString KDevKonsoleViewPlugin::errorDescription() const
{
return !m_viewFactory ? i18n("Failed to load 'konsolepart' plugin") : QString();
}
KPluginFactory* KDevKonsoleViewPlugin::konsoleFactory() const
{
return m_konsoleFactory;
......
......@@ -28,8 +28,6 @@ public:
~KDevKonsoleViewPlugin() override;
void unload() override;
bool hasError() const override;
QString errorDescription() const override;
KPluginFactory* konsoleFactory() const;
......
......@@ -118,19 +118,16 @@ PerforcePlugin::PerforcePlugin(QObject* parent, const QVariantList&):
, m_perforceConfigName("p4config.txt")
, m_perforceExecutable("p4")
, m_edit_action(nullptr)
, m_hasError(true)
{
QProcessEnvironment currentEviron(QProcessEnvironment::systemEnvironment());
QString tmp(currentEviron.value("P4CONFIG"));
if (tmp.isEmpty()) {
// We require the P4CONFIG variable to be set because the perforce command line client will need it
m_hasError = true;
m_errorDescription = i18n("The variable P4CONFIG is not set.");
setErrorDescription(i18n("The variable P4CONFIG is not set. Is perforce installed on the system?"));
return;
} else {
m_perforceConfigName = tmp;
}
m_hasError = false;
qCDebug(PLUGIN_PERFORCE) << "The value of P4CONFIG is : " << tmp;
KDEV_USE_EXTENSION_INTERFACE(KDevelop::IBasicVersionControl)
......@@ -696,14 +693,4 @@ KDevelop::VcsJob* PerforcePlugin::errorsFound(const QString& error, KDevelop::Ou
return j;
}
bool PerforcePlugin::hasError() const
{
return m_hasError;
}
QString PerforcePlugin::errorDescription() const
{
return m_errorDescription;
}
......@@ -130,9 +130,6 @@ public:
KDevelop::VcsJob* edit(const QList<QUrl>& localLocations);
bool hasError() const override;
QString errorDescription() const override;
KDevelop::ContextMenuExtension contextMenuExtension(KDevelop::Context* context) override;
......@@ -174,10 +171,6 @@ private:
QString m_perforceConfigName;
QString m_perforceExecutable;
QAction* m_edit_action;
bool m_hasError;
QString m_errorDescription;
};
#endif // PERFORCEPLUGIN_H
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment