diff --git a/src/plugins/phabricator/phabricatorplugin.cpp b/src/plugins/phabricator/phabricatorplugin.cpp index 1596664..bcfc3db 100644 --- a/src/plugins/phabricator/phabricatorplugin.cpp +++ b/src/plugins/phabricator/phabricatorplugin.cpp @@ -1,153 +1,148 @@ /* * This file is part of KDevelop * Copyright 2017 René J.V. Bertin * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public * License along with this program; if not, write to the * Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include #include #include #include #include #include #include #include #include #include #include "phabricatorjobs.h" #include "debug.h" #include "purpose/job.h" #include "purpose/pluginbase.h" // FIXME: For some reason PLUGIN_PHABRICATOR isn't exported from the PhabricatorHelpers lib #undef qCDebug #define qCDebug(dum) qDebug() #undef qCWarning #define qCWarning(dum) qWarning() #undef qCCritical #define qCCritical(dum) qCritical() class PhabricatorJob : public Purpose::Job { Q_OBJECT public: PhabricatorJob(QObject* object = nullptr) : Purpose::Job(object) {} void start() override { const QString localBaseDir(data().value(QStringLiteral("localBaseDir")).toString()); const QUrl sourceFile(data().value(QStringLiteral("urls")).toArray().first().toString()); const QString updateDR = data().value(QStringLiteral("updateDR")).toString(); const bool doBrowse = data().value(QStringLiteral("doBrowse")).toBool(); const QString baseDir = QUrl(localBaseDir).toLocalFile(); if (QFileInfo(sourceFile.toLocalFile()).size() <= 0) { setError(KJob::UserDefinedError+1); setErrorText(i18n("Phabricator refuses empty patchfiles")); emit PhabricatorJob::warning(this, errorString(), QString()); qCCritical(PLUGIN_PHABRICATOR) << errorString(); emitResult(); return; } else if (updateDR.localeAwareCompare(i18n("unknown")) == 0) { setError(KJob::UserDefinedError+1); setErrorText(i18n("Please choose between creating a new revision or updating an existing one")); emit PhabricatorJob::warning(this, errorString(), QString()); qCCritical(PLUGIN_PHABRICATOR) << errorString(); emitResult(); return; } m_drTitle = data().value(QStringLiteral("drTitle")).toString(); KJob* job; if (!updateDR.isEmpty()) { const QString updateComment = data().value(QStringLiteral("updateComment")).toString(); job=new Phabricator::UpdateDiffRev(sourceFile, baseDir, updateDR, updateComment, doBrowse, this); connect(job, &KJob::finished, this, &PhabricatorJob::diffUpdated); } else { - job=new Phabricator::NewDiffRev(sourceFile, baseDir, doBrowse, this); + job=new Phabricator::NewDiffRev(sourceFile, baseDir, true, this); connect(job, &KJob::finished, this, &PhabricatorJob::diffCreated); - if (!doBrowse) { - QMessageBox::warning(nullptr, - i18n("Please note"), - i18n("Remember to complete the differential revision online!")); - } } job->start(); emit PhabricatorJob::infoMessage(this, QStringLiteral("upload job started"), QString()); } void diffCreatedOrUpdated(KJob* j, bool created) { if(j->error()!=0) { setError(j->error()); setErrorText(j->errorString()); emit PhabricatorJob::warning(this, j->errorString(), QString()); qCCritical(PLUGIN_PHABRICATOR) << "Could not upload the patch" << j->errorString(); emitResult(); return; } if (created) { Phabricator::NewDiffRev const * job = qobject_cast(j); qCWarning(PLUGIN_PHABRICATOR) <<"new diff:" << job->diffURI(); setOutput({{ QStringLiteral("url"), job->diffURI() }}); } else { Phabricator::UpdateDiffRev const * job = qobject_cast(j); qCWarning(PLUGIN_PHABRICATOR) << "updated diff" << job->requestId() << ":" << job->diffURI(); setOutput({{ QStringLiteral("url"), job->diffURI() }}); emit PhabricatorJob::infoMessage(this, QStringLiteral("updated diff %1: %2").arg(job->requestId()).arg(job->diffURI()), QString()); } emitResult(); } void diffCreated(KJob* j) { diffCreatedOrUpdated(j, true); } void diffUpdated(KJob* j) { diffCreatedOrUpdated(j, false); } QString m_drTitle; }; class Q_DECL_EXPORT PhabricatorPlugin : public Purpose::PluginBase { Q_OBJECT public: PhabricatorPlugin(QObject* parent, const QList& /*args*/) : PluginBase(parent) {} ~PhabricatorPlugin() override {} Purpose::Job* createJob() const override { return new PhabricatorJob; } }; K_PLUGIN_CLASS_WITH_JSON(PhabricatorPlugin, "phabricatorplugin.json") #include "phabricatorplugin.moc" diff --git a/src/plugins/phabricator/phabricatorplugin_config.qml b/src/plugins/phabricator/phabricatorplugin_config.qml index ff34b95..1f1bed7 100644 --- a/src/plugins/phabricator/phabricatorplugin_config.qml +++ b/src/plugins/phabricator/phabricatorplugin_config.qml @@ -1,142 +1,142 @@ /* Copyright 2017 René J.V. Bertin This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ import QtQuick 2.2 import QtQuick.Controls 1.2 import QtQuick.Layouts 1.1 import org.kde.purpose.phabricator 1.0 ColumnLayout { id: root enabled: true property string updateDR: "" property string drTitle: "" property string localBaseDir property alias updateComment: updateCommentField.text // This is a workaround for installs where the result dialog doesn't always appear // or doesn't always show the revision URL. property alias doBrowse: doBrowseCheck.checked property variant urls property variant mimeType function labelText() { if (updateDRCombo.currentIndex>=0 && updateOld.checked) { return updateDR.length > 0 ? i18n("Update differential revision %1", updateDR) : i18n("Update differential revision") } else if (createNew.checked) { return i18n("Create new \"differential diff\"") } else { return i18n("Create or update?") } } Label { id: label text: root.labelText() } PhabricatorRC { id: json path: root.localBaseDir + "/.arcconfig" } function refreshUpdateDR() { if (updateDRCombo.currentIndex>=0 && updateOld.checked) { root.updateDR = diffList.get(updateDRCombo.currentIndex, "toolTip") root.drTitle = diffList.get(updateDRCombo.currentIndex, "display") } else { if (createNew.checked) { root.updateDR = "" root.drTitle = "" } else { root.updateDR = i18n("unknown") root.drTitle = "" } } } RowLayout { Layout.alignment: Qt.AlignHCenter ExclusiveGroup { id: updateGroup } RadioButton { id: createNew exclusiveGroup: updateGroup text: i18n("New Diff") tooltip: i18n("tick this to create a new \"differential diff\" which can\nbe converted online to a new differential revision") onCheckedChanged: { root.refreshUpdateDR(); } } RadioButton { id: updateOld exclusiveGroup: updateGroup text: i18n("Update Diff") tooltip: i18n("tick this to update an existing revision,\nselect one from the list below.") onCheckedChanged: { root.refreshUpdateDR(); } } } ComboBox { id: updateDRCombo Layout.fillWidth: true enabled: updateOld.checked textRole: "display" model: DiffListModel { id: diffList status: "pending" } onCurrentIndexChanged: { root.refreshUpdateDR(); } } Item { Layout.fillWidth: true height: doBrowseCheck.height CheckBox { id: doBrowseCheck anchors.centerIn: parent text: i18n("Open Diff in browser") - enabled: true + enabled: updateOld.checked } } Label { // use i18n().arg() to avoid showing the "%1" when inactive text: updateDR != "unknown" && updateDR.length > 0 ? i18n("Summary of the update to %1:", updateDR) : i18n("Summary of the update") enabled: updateOld.checked } TextArea { id: updateCommentField Layout.fillWidth: true Layout.fillHeight: true text: i18n("patch updated through %1 and the Purpose/Phabricator plugin", Qt.application.name) enabled: updateOld.checked tabChangesFocus: false } Item { Layout.fillHeight: true Layout.fillWidth: true } }