diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -130,9 +130,9 @@ prefs/prefs_editor.ui prefs/prefs_appearance.ui prefs/prefs_tm.ui + prefs/prefs_pology.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/editortab.h b/src/editortab.h --- a/src/editortab.h +++ b/src/editortab.h @@ -32,6 +32,7 @@ #include "lokalizesubwindowbase.h" #include +#include #ifndef NOKDE namespace Sonnet @@ -292,6 +293,7 @@ void displayWordCount(); void clearTranslatedEntries(); + void launchPology(); void openPhasesWindow(); @@ -305,6 +307,8 @@ void fileAutoSaveFailedWarning(const QString&); + void pologyHasFinished(int exitCode, QProcess::ExitStatus exitStatus); + protected: void paintEvent(QPaintEvent* event); @@ -325,6 +329,9 @@ QAction* m_approveAction; QAction* m_stateAction; //is = m_approveAction ifndef NOKDE + KProcess* m_pologyProcess; + bool m_pologyProcessInProgress; + DocPosition m_currentPos; DocPosition _searchingPos; //for find/replace DocPosition _replacingPos; diff --git a/src/editortab.cpp b/src/editortab.cpp --- a/src/editortab.cpp +++ b/src/editortab.cpp @@ -57,19 +57,20 @@ #include "project.h" #include "prefs.h" +#include "prefs_lokalize.h" #include "languagelistmodel.h" #ifndef NOKDE -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include #endif -#include -#include +#include +#include #include #include @@ -92,6 +93,7 @@ , m_project(Project::instance()) , m_catalog(new Catalog(this)) , m_view(new EditorView(this, m_catalog/*,new keyEventHandler(this,m_catalog)*/)) + , m_pologyProcessInProgress(false) #ifndef NOKDE , m_sonnetDialog(0) , m_spellcheckStartUndoIndex(0) @@ -462,6 +464,10 @@ ADD_ACTION_SHORTCUT("file_cleartarget", i18nc("@action:inmenu", "Clear all translated entries"), Qt::CTRL + Qt::ALT + Qt::Key_D) connect(action, &QAction::triggered, this, &EditorTab::clearTranslatedEntries); + ADD_ACTION_SHORTCUT("file_pology", i18nc("@action:inmenu", "Launch the Pology command on this file"), Qt::CTRL + Qt::ALT + Qt::Key_P) + action->setEnabled(Settings::self()->pologyEnabled()); + connect(action, &QAction::triggered, this, &EditorTab::launchPology); + ADD_ACTION_SHORTCUT("file_xliff2odf", i18nc("@action:inmenu", "Merge translation into OpenDocument"), Qt::CTRL + Qt::Key_Backslash) connect(action, &QAction::triggered, this, &EditorTab::mergeIntoOpenDocument); connect(this, &EditorTab::xliffFileOpened, action, &QAction::setVisible); @@ -1395,6 +1401,37 @@ CompletionStorage::instance()->scanCatalog(m_catalog); } +void EditorTab::launchPology() +{ + if (!m_pologyProcessInProgress) { + QString command = Settings::self()->pologyCommandFile().replace(QStringLiteral("%f"), QStringLiteral("\"") + currentFilePath() + QStringLiteral("\"")); + m_pologyProcess = new KProcess; + m_pologyProcess->setOutputChannelMode(KProcess::SeparateChannels); + qCWarning(LOKALIZE_LOG) << "Launching pology command: " << command; + connect(m_pologyProcess, QOverload::of(&KProcess::finished), + this, &EditorTab::pologyHasFinished); + m_pologyProcess->setShellCommand(command); + m_pologyProcessInProgress = true; + m_pologyProcess->start(); + } else { + KMessageBox::error(this, i18n("A Pology check is already in progress."), i18n("Pology error")); + } +} + +void EditorTab::pologyHasFinished(int exitCode, QProcess::ExitStatus exitStatus) +{ + const QString pologyError = m_pologyProcess->readAllStandardError(); + if (exitStatus == QProcess::CrashExit) { + KMessageBox::error(this, i18n("The Pology check has crashed unexpectedly:\n%1", pologyError), i18n("Pology error")); + } else if (exitCode == 0) { + KMessageBox::information(this, i18n("The Pology check has succeeded."), i18n("Pology success")); + } else { + KMessageBox::error(this, i18n("The Pology check has returned an error:\n%1", pologyError), i18n("Pology error")); + } + m_pologyProcess->deleteLater(); + m_pologyProcessInProgress = false; +} + void EditorTab::clearTranslatedEntries() { switch (KMessageBox::warningYesNoCancel(this, diff --git a/src/editorui.rc b/src/editorui.rc --- a/src/editorui.rc +++ b/src/editorui.rc @@ -1,5 +1,5 @@ - + &File @@ -22,6 +22,7 @@ + diff --git a/src/filesearch/filesearchtab.cpp b/src/filesearch/filesearchtab.cpp --- a/src/filesearch/filesearchtab.cpp +++ b/src/filesearch/filesearchtab.cpp @@ -54,12 +54,12 @@ #include #include -#include +#include #ifndef NOKDE -#include -#include -#include +#include +#include +#include #endif static QStringList doScanRecursive(const QDir& dir); diff --git a/src/lokalizemainwindow.cpp b/src/lokalizemainwindow.cpp --- a/src/lokalizemainwindow.cpp +++ b/src/lokalizemainwindow.cpp @@ -44,15 +44,15 @@ #include "multieditoradaptor.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include diff --git a/src/msgctxtview.cpp b/src/msgctxtview.cpp --- a/src/msgctxtview.cpp +++ b/src/msgctxtview.cpp @@ -167,9 +167,9 @@ } void MsgCtxtView::pology() { - if (Project::instance()->local()->pologyEnabled() && m_pologyProcessInProgress == 0) { - 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(" ")); + if (Settings::self()->pologyEnabled() && m_pologyProcessInProgress == 0) { + QString command = Settings::self()->pologyCommandEntry(); + command = command.replace(QStringLiteral("%u"), QString::number(m_entry.entry + 1)).replace(QStringLiteral("%f"), QStringLiteral("\"") + m_catalog->url() + QStringLiteral("\"")).replace(QStringLiteral("\n"), QStringLiteral(" ")); m_pologyProcess = new KProcess; m_pologyProcess->setShellCommand(command); m_pologyProcess->setOutputChannelMode(KProcess::SeparateChannels); @@ -183,7 +183,7 @@ m_pologyData = QStringLiteral("[pology] "); m_pologyProcessInProgress = m_entry.entry + 1; m_pologyProcess->start(); - } else if (Project::instance()->local()->pologyEnabled() && m_pologyProcessInProgress > 0) { + } else if (Settings::self()->pologyEnabled() && m_pologyProcessInProgress > 0) { QTimer::singleShot(1000, this, &MsgCtxtView::pology); } } diff --git a/src/prefs/lokalize.kcfg b/src/prefs/lokalize.kcfg --- a/src/prefs/lokalize.kcfg +++ b/src/prefs/lokalize.kcfg @@ -132,4 +132,15 @@ false + + + false + + + posieve -u %u check-rules %f + + + posieve -s lokalize check-rules %f + + diff --git a/src/prefs/prefs.cpp b/src/prefs/prefs.cpp --- a/src/prefs/prefs.cpp +++ b/src/prefs/prefs.cpp @@ -36,11 +36,11 @@ #include "ui_prefs_editor.h" #include "ui_prefs_general.h" #include "ui_prefs_appearance.h" +#include "ui_prefs_pology.h" #include "ui_prefs_tm.h" #include "ui_prefs_projectmain.h" #include "ui_prefs_project_advanced.h" #include "ui_prefs_project_local.h" -#include "ui_prefs_project_pology.h" #include @@ -138,6 +138,12 @@ ui_prefs_tm.setupUi(w); dialog->addPage(w, i18nc("@title:tab", "Translation Memory"), "configure"); +//Pology + w = new QWidget(dialog); + Ui_prefs_pology ui_prefs_pology; + ui_prefs_pology.setupUi(w); + dialog->addPage(w, i18nc("@title:tab", "Pology"), "preferences-desktop-filetype-association"); + connect(dialog, &KConfigDialog::settingsChanged, this, &SettingsController::generalSettingsChanged); @@ -335,11 +341,6 @@ 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/prefs/prefs_pology.ui b/src/prefs/prefs_pology.ui new file mode 100644 --- /dev/null +++ b/src/prefs/prefs_pology.ui @@ -0,0 +1,83 @@ + + prefs_pology + + + + 0 + 0 + 611 + 439 + + + + + + + QFormLayout::ExpandingFieldsGrow + + + + + Enable Pology verification + + + + + + + The Pology command to 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. For instance: posieve -u %u check-rules %f + + + true + + + + + + + + 611 + 100 + + + + 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 + + + + + + + The Pology command to run in order to check a whole file. This command should include "-s lokalize", placeholder %f is the file name. For instance: posieve -s lokalize check-rules %f + + + true + + + + + + + + 611 + 100 + + + + The Pology command to run in order to check a whole file. + + + Please enter here the Pology command to be run in order to check a whole file + + + + + + + + + + diff --git a/src/project/prefs_project_pology.ui b/src/project/prefs_project_pology.ui deleted file mode 100644 --- a/src/project/prefs_project_pology.ui +++ /dev/null @@ -1,64 +0,0 @@ - - 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. For instance: python /home/translator/i18n/pology/scripts/posieve.py -u %u check_rules %f - - - true - - - - - - - - - - diff --git a/src/project/projectlocal.kcfg b/src/project/projectlocal.kcfg --- a/src/project/projectlocal.kcfg +++ b/src/project/projectlocal.kcfg @@ -21,10 +21,4 @@ true - - - false - - - diff --git a/src/project/projecttab.h b/src/project/projecttab.h --- a/src/project/projecttab.h +++ b/src/project/projecttab.h @@ -27,6 +27,7 @@ #include "lokalizesubwindowbase.h" #include +#include #include @@ -89,6 +90,7 @@ void setFilterRegExp(); void setFocus(); void scanFilesToTM(); + void pologyOnFiles(); void searchInFiles(bool templ = false); void searchInFilesInclTempl(); void openFile(); @@ -111,13 +113,18 @@ void updateStatusBar(int fuzzy = 0, int translated = 0, int untranslated = 0, bool done = false); void initStatusBarProgress(); + void pologyHasFinished(int exitCode, QProcess::ExitStatus exitStatus); + private: ProjectWidget* m_browser; QLineEdit* m_filterEdit; QProgressBar* m_progressBar; QStackedLayout *m_stackedLayout; + KProcess* m_pologyProcess; + bool m_pologyProcessInProgress; + int m_legacyUnitsCount, m_currentUnitsCount; }; diff --git a/src/project/projecttab.cpp b/src/project/projecttab.cpp --- a/src/project/projecttab.cpp +++ b/src/project/projecttab.cpp @@ -26,13 +26,17 @@ #include "projectwidget.h" #include "tmscanapi.h" #include "prefs.h" +#include "prefs_lokalize.h" #include "catalog.h" +#include "lokalize_debug.h" -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include #include #include @@ -51,6 +55,7 @@ : LokalizeSubwindowBase2(parent) , m_browser(new ProjectWidget(this)) , m_filterEdit(new QLineEdit(this)) + , m_pologyProcessInProgress(false) , m_legacyUnitsCount(-1) , m_currentUnitsCount(0) @@ -261,6 +266,9 @@ menu->addAction(i18nc("@action:inmenu", "Add to translation memory"), this, SLOT(scanFilesToTM())); menu->addAction(i18nc("@action:inmenu", "Search in files"), this, SLOT(searchInFiles())); + if (Settings::self()->pologyEnabled()) { + menu->addAction(i18nc("@action:inmenu", "Launch Pology on files"), this, &ProjectTab::pologyOnFiles); + } if (QDir(Project::instance()->templatesRoot()).exists()) menu->addAction(i18nc("@action:inmenu", "Search in files (including templates)"), this, SLOT(searchInFilesInclTempl())); @@ -296,6 +304,46 @@ emit searchRequested(files); } +void ProjectTab::pologyOnFiles() +{ + if (!m_pologyProcessInProgress) { + QStringList files = m_browser->selectedItems(); + QString templatesRoot = Project::instance()->templatesRoot(); + QString filesAsString; + int i = files.size(); + while (--i >= 0) { + if (files.at(i).endsWith(QStringLiteral(".po"))) + filesAsString += QStringLiteral("\"") + files.at(i) + QStringLiteral("\" "); + } + + QString command = Settings::self()->pologyCommandFile().replace(QStringLiteral("%f"), filesAsString); + m_pologyProcess = new KProcess; + m_pologyProcess->setOutputChannelMode(KProcess::SeparateChannels); + qCWarning(LOKALIZE_LOG) << "Launching pology command: " << command; + connect(m_pologyProcess, QOverload::of(&KProcess::finished), + this, &ProjectTab::pologyHasFinished); + m_pologyProcess->setShellCommand(command); + m_pologyProcessInProgress = true; + m_pologyProcess->start(); + } else { + KMessageBox::error(this, i18n("A Pology check is already in progress."), i18n("Pology error")); + } +} + +void ProjectTab::pologyHasFinished(int exitCode, QProcess::ExitStatus exitStatus) +{ + const QString pologyError = m_pologyProcess->readAllStandardError(); + if (exitStatus == QProcess::CrashExit) { + KMessageBox::error(this, i18n("The Pology check has crashed unexpectedly:\n%1", pologyError), i18n("Pology error")); + } else if (exitCode == 0) { + KMessageBox::information(this, i18n("The Pology check has succeeded"), i18n("Pology success")); + } else { + KMessageBox::error(this, i18n("The Pology check has returned an error:\n%1", pologyError), i18n("Pology error")); + } + m_pologyProcess->deleteLater(); + m_pologyProcessInProgress = false; +} + void ProjectTab::searchInFilesInclTempl() { searchInFiles(true); diff --git a/src/tm/tmtab.cpp b/src/tm/tmtab.cpp --- a/src/tm/tmtab.cpp +++ b/src/tm/tmtab.cpp @@ -54,11 +54,11 @@ #include #ifndef NOKDE -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include #endif #if defined(Q_OS_WIN) && defined(QStringLiteral)