diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -131,6 +131,7 @@ prefs/prefs_tm.ui project/prefs_project_advanced.ui project/prefs_project_local.ui + project/prefs_project_pology.ui project/prefs_projectmain.ui glossary/termedit.ui filesearch/filesearchoptions.ui diff --git a/src/msgctxtview.h b/src/msgctxtview.h --- a/src/msgctxtview.h +++ b/src/msgctxtview.h @@ -29,6 +29,7 @@ #include #include +#include class Catalog; class NoteEditor; @@ -56,6 +57,10 @@ void noteEditAccepted(); void noteEditRejected(); void process(); + void pology(); + void pologyReceivedStandardOutput(); + void pologyReceivedStandardError(); + void pologyHasFinished(); signals: void srcFileOpenRequested(const QString& srcPath, int line); @@ -66,6 +71,10 @@ NoteEditor* m_editor; QStackedLayout* m_stackedLayout; + KProcess* m_pologyProcess; + bool m_pologyStartedReceivingOutput; + QString m_pologyData; + Catalog* m_catalog; QMap< DocPos, QPair > m_unfinishedNotes; //note and its index QMap< int, QString > m_tempNotes; diff --git a/src/msgctxtview.cpp b/src/msgctxtview.cpp --- a/src/msgctxtview.cpp +++ b/src/msgctxtview.cpp @@ -27,6 +27,9 @@ #include "catalog.h" #include "cmd.h" #include "prefs_lokalize.h" +#include "project.h" + +#include "lokalize_debug.h" #include #include @@ -42,6 +45,7 @@ #include #include #include +#include MsgCtxtView::MsgCtxtView(QWidget* parent, Catalog* catalog) : QDockWidget(i18nc("@title toolview name", "Unit metadata"), parent) @@ -80,6 +84,7 @@ m_selection = selection; m_offset = pos.offset; QTimer::singleShot(0, this, &MsgCtxtView::process); + QTimer::singleShot(0, this, &MsgCtxtView::pology); } void MsgCtxtView::process() @@ -157,7 +162,63 @@ t.movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor, m_selection); m_browser->setTextCursor(t); } +void MsgCtxtView::pology() +{ + if (Project::instance()->local()->pologyEnabled()) { + QString command = Project::instance()->local()->pologyCommandEntry(); + command = command.replace(QStringLiteral("%u"), QString::number(m_entry.entry + 1)).replace(QStringLiteral("%f"), m_catalog->url()).replace(QStringLiteral("\n"), QStringLiteral(" ")); + m_pologyProcess = new KProcess; + m_pologyProcess->setShellCommand(command); + m_pologyProcess->setOutputChannelMode(KProcess::SeparateChannels); + m_pologyStartedReceivingOutput = false; + connect(m_pologyProcess, &KProcess::readyReadStandardOutput, + this, &MsgCtxtView::pologyReceivedStandardOutput); + connect(m_pologyProcess, &KProcess::readyReadStandardError, + this, &MsgCtxtView::pologyReceivedStandardError); + connect(m_pologyProcess, QOverload::of(&KProcess::finished), + this, &MsgCtxtView::pologyHasFinished); + m_pologyData = QStringLiteral("[pology] "); + m_pologyProcess->start(); + m_pologyProcess->waitForFinished(); + } +} +void MsgCtxtView::pologyReceivedStandardOutput() +{ + if (!m_pologyStartedReceivingOutput) { + m_pologyStartedReceivingOutput = true; + } + static const QString grossPologyOutput = m_pologyProcess->readAllStandardOutput(); + static const QStringList pologyTmpLines = grossPologyOutput.split('\n', QString::SkipEmptyParts); + foreach (const QString pologyTmp, pologyTmpLines) { + if (pologyTmp.startsWith(QStringLiteral("[note]"))) + m_pologyData += pologyTmp; + } +} +void MsgCtxtView::pologyReceivedStandardError() +{ + if (!m_pologyStartedReceivingOutput) { + m_pologyStartedReceivingOutput = true; + } + static const QString BR = QStringLiteral("
"); + m_pologyData += m_pologyProcess->readAllStandardError().replace('\n', BR); +} +void MsgCtxtView::pologyHasFinished() +{ + if (!m_pologyStartedReceivingOutput) { + m_pologyStartedReceivingOutput = true; + m_pologyData += i18nc("@info The pology command didn't return anything", "(empty)"); + } + if (!m_tempNotes.value(m_entry.entry).startsWith(QStringLiteral("Failed rules:"))) { + //This was not opened by pology + //Delete the previous pology notes + if (m_tempNotes.value(m_entry.entry).startsWith(QStringLiteral("[pology] "))) { + m_tempNotes.remove(m_entry.entry); + } + addTemporaryEntryNote(m_entry.entry, m_pologyData); + } + m_pologyProcess->deleteLater(); +} void MsgCtxtView::addNoteUI() { diff --git a/src/prefs/prefs.cpp b/src/prefs/prefs.cpp --- a/src/prefs/prefs.cpp +++ b/src/prefs/prefs.cpp @@ -39,6 +39,7 @@ #include "ui_prefs_projectmain.h" #include "ui_prefs_project_advanced.h" #include "ui_prefs_project_local.h" +#include "ui_prefs_project_pology.h" #include @@ -327,6 +328,11 @@ ui_prefs_project_local.setupUi(w); dialog->addPage(w, Project::local(), i18nc("@title:tab", "Personal"), "preferences-desktop-user"); + w = new QWidget(dialog); + Ui_prefs_project_pology ui_prefs_project_pology; + ui_prefs_project_pology.setupUi(w); + dialog->addPage(w, Project::local(), i18nc("@title:tab", "Pology"), "preferences-desktop-filetype-association"); + connect(dialog, &KConfigDialog::settingsChanged, Project::instance(), &Project::reinit); connect(dialog, &KConfigDialog::settingsChanged, Project::instance(), &Project::save, Qt::QueuedConnection); connect(dialog, &KConfigDialog::settingsChanged, TM::DBFilesModel::instance(), &TM::DBFilesModel::updateProjectTmIndex); diff --git a/src/project/prefs_project_pology.ui b/src/project/prefs_project_pology.ui new file mode 100644 --- /dev/null +++ b/src/project/prefs_project_pology.ui @@ -0,0 +1,64 @@ + + prefs_project_pology + + + + 0 + 0 + 611 + 439 + + + + + + + QFormLayout::ExpandingFieldsGrow + + + + + Enable Pology verification + + + + + + + Pology command at entry level: + + + false + + + kcfg_PologyCommandEntry + + + + + + + The Pology command to run in order to check a single entry + + + Please enter here the Pology command to be run in order to check a single entry + + + + + + + Use the following placeholders in order to set-up the commands: %u is the entry number, %f is the file name. + + + true + + + + + + + + + + diff --git a/src/project/projectlocal.kcfg b/src/project/projectlocal.kcfg --- a/src/project/projectlocal.kcfg +++ b/src/project/projectlocal.kcfg @@ -21,4 +21,8 @@ true + + + +