diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -50,6 +50,7 @@ msgctxtview.cpp binunitsview.cpp + pologyview.cpp cataloglistview/cataloglistview.cpp cataloglistview/catalogmodel.cpp @@ -131,6 +132,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/editortab.h b/src/editortab.h --- a/src/editortab.h +++ b/src/editortab.h @@ -56,6 +56,7 @@ class MergeView; class CatalogView; class MsgCtxtView; +class PologyView; class AltTransView; namespace GlossaryNS { @@ -355,6 +356,7 @@ CatalogView* m_transUnitsView; MsgCtxtView* m_notesView; AltTransView* m_altTransView; + PologyView* m_pologyView; //END views diff --git a/src/editortab.cpp b/src/editortab.cpp --- a/src/editortab.cpp +++ b/src/editortab.cpp @@ -29,6 +29,7 @@ #include "actionproxy.h" #include "editorview.h" +#include "pologyview.h" #include "catalog.h" #include "pos.h" #include "cmd.h" @@ -290,6 +291,13 @@ connect(m_view, &EditorView::signalChanged, m_notesView, &MsgCtxtView::removeErrorNotes); connect(m_notesView, &MsgCtxtView::escaped, this, &EditorTab::setProperFocus); + m_pologyView = new PologyView(this, m_catalog); + if (Project::instance()->local()->pologyEnabled()) { + addDockWidget(Qt::BottomDockWidgetArea, m_pologyView); + } + actionCollection()->addAction(QStringLiteral("showpologyview_action"), m_pologyView->toggleViewAction()); + connect(this, QOverload::of(&EditorTab::signalNewEntryDisplayed), m_pologyView, QOverload::of(&PologyView::slotNewEntryDisplayed)); + action = edit->addAction(QStringLiteral("edit_addnote"), m_notesView, SLOT(addNoteUI())); //action->setShortcut(Qt::CTRL+glist[i]); action->setText(i18nc("@action:inmenu", "Add a note")); diff --git a/src/editorui.rc b/src/editorui.rc --- a/src/editorui.rc +++ b/src/editorui.rc @@ -1,5 +1,5 @@ - + &File @@ -233,6 +233,7 @@ + diff --git a/src/pologyview.h b/src/pologyview.h new file mode 100644 --- /dev/null +++ b/src/pologyview.h @@ -0,0 +1,68 @@ +/* **************************************************************************** + This file is part of Lokalize + + Copyright (C) 2007-2014 by Nick Shaforostoff + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of + the License or (at your option) version 3 or any later version + accepted by the membership of KDE e.V. (or its successor approved + by the membership of KDE e.V.), which shall act as a proxy + defined in Section 14 of version 3 of the license. + + 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, see . + +**************************************************************************** */ + +#ifndef POLOGYVIEW_H +#define POLOGYVIEW_H + +#include "pos.h" +#include "note.h" + +#include +#include +#include + +class Catalog; +class NoteEditor; +class QTextBrowser; +class QStackedLayout; + +class PologyView: public QDockWidget +{ + Q_OBJECT + +public: + PologyView(QWidget*, Catalog*); + ~PologyView(); + +public slots: + void slotNewEntryDisplayed(const DocPosition&); + +private slots: + void process(); + void receivedStandardOutput(); + void receivedStandardError(); + void hasFinished(); + +private: + QTextBrowser* m_browser; + KProcess* m_process; + QStackedLayout* m_stackedLayout; + bool m_startedReceivingOutput; + + Catalog* m_catalog; + DocPos m_entry; +}; + + + +#endif diff --git a/src/pologyview.cpp b/src/pologyview.cpp new file mode 100644 --- /dev/null +++ b/src/pologyview.cpp @@ -0,0 +1,128 @@ +/* **************************************************************************** + This file is part of Lokalize + + Copyright (C) 2007-2014 by Nick Shaforostoff + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of + the License or (at your option) version 3 or any later version + accepted by the membership of KDE e.V. (or its successor approved + by the membership of KDE e.V.), which shall act as a proxy + defined in Section 14 of version 3 of the license. + + 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, see . + +**************************************************************************** */ + +#include "pologyview.h" + +#include "lokalize_debug.h" + +#include "catalog.h" +#include "cmd.h" +#include "prefs_lokalize.h" +#include "project.h" + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +PologyView::PologyView(QWidget* parent, Catalog* catalog) + : QDockWidget(i18nc("@title toolview name", "Pology"), parent) + , m_browser(new QTextBrowser(this)) + , m_catalog(catalog) +{ + setObjectName(QStringLiteral("pologyView")); + QWidget* main = new QWidget(this); + setWidget(main); + m_stackedLayout = new QStackedLayout(main); + m_stackedLayout->addWidget(m_browser); + + m_browser->viewport()->setBackgroundRole(QPalette::Background); + m_browser->setOpenLinks(false); +} + +PologyView::~PologyView() +{ +} + +void PologyView::slotNewEntryDisplayed(const DocPosition& pos) +{ + m_entry = DocPos(pos); + QTimer::singleShot(0, this, &PologyView::process); +} + +void PologyView::process() +{ + m_browser->clear(); + + 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(" ")); + QString result = QString(); + m_process = new KProcess; + m_process->setShellCommand(command); + m_process->setOutputChannelMode(KProcess::SeparateChannels); + m_startedReceivingOutput = false; + m_browser->insertHtml(i18nc("@info The pology command is in progress", "(waiting)")); + connect(m_process, &KProcess::readyReadStandardOutput, + this, &PologyView::receivedStandardOutput); + connect(m_process, &KProcess::readyReadStandardError, + this, &PologyView::receivedStandardError); + connect(m_process, QOverload::of(&KProcess::finished), + this, &PologyView::hasFinished); + m_process->start(); + } else { + QString html = i18nc("@info Pology is not enabled in the configuration of this project", "Pology is disabled for this project."); + } +} +void PologyView::receivedStandardOutput() +{ + if (!m_startedReceivingOutput) { + m_browser->clear(); + m_startedReceivingOutput = true; + } + + static const QString BR = QStringLiteral("
"); + QString data = m_process->readAllStandardOutput().replace('\n', BR); + m_browser->insertHtml(data); +} + +void PologyView::receivedStandardError() +{ + if (!m_startedReceivingOutput) { + m_browser->clear(); + m_startedReceivingOutput = true; + } + + static const QString BR = QStringLiteral("
"); + QString data = m_process->readAllStandardError().replace('\n', BR); + m_browser->insertHtml(data); +} +void PologyView::hasFinished() +{ + if (!m_startedReceivingOutput) { + m_browser->clear(); + m_startedReceivingOutput = true; + m_browser->insertHtml(i18nc("@info The pology command didn't return anything", "(empty)")); + } +} + 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/projectlocal.kcfg b/src/project/projectlocal.kcfg --- a/src/project/projectlocal.kcfg +++ b/src/project/projectlocal.kcfg @@ -21,4 +21,8 @@ true + + + +