• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdesdk API Reference
  • KDE Home
  • Contact Us
 

lokalize

  • sources
  • kde-4.14
  • kdesdk
  • lokalize
  • src
msgctxtview.cpp
Go to the documentation of this file.
1 /* ****************************************************************************
2  This file is part of Lokalize
3 
4  Copyright (C) 2007-2009 by Nick Shaforostoff <shafff@ukr.net>
5 
6  This program is free software; you can redistribute it and/or
7  modify it under the terms of the GNU General Public License as
8  published by the Free Software Foundation; either version 2 of
9  the License or (at your option) version 3 or any later version
10  accepted by the membership of KDE e.V. (or its successor approved
11  by the membership of KDE e.V.), which shall act as a proxy
12  defined in Section 14 of version 3 of the license.
13 
14  This program is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU General Public License for more details.
18 
19  You should have received a copy of the GNU General Public License
20  along with this program. If not, see <http://www.gnu.org/licenses/>.
21 
22 **************************************************************************** */
23 
24 #define KDE_NO_DEBUG_OUTPUT
25 
26 #include "msgctxtview.h"
27 
28 #include "noteeditor.h"
29 #include "catalog.h"
30 #include "cmd.h"
31 #include "prefs_lokalize.h"
32 
33 
34 #include <klocale.h>
35 #include <kdebug.h>
36 #include <ktextbrowser.h>
37 #include <ktextedit.h>
38 #include <kcombobox.h>
39 #include <kpushbutton.h>
40 
41 #include <QTime>
42 #include <QTimer>
43 #include <QBoxLayout>
44 #include <QStackedLayout>
45 #include <QLabel>
46 #include <QStringListModel>
47 #include <QLineEdit>
48 
49 MsgCtxtView::MsgCtxtView(QWidget* parent, Catalog* catalog)
50  : QDockWidget (i18nc("@title toolview name","Unit metadata"), parent)
51  , m_browser(new KTextBrowser(this))
52  , m_editor(0)
53  , m_catalog(catalog)
54  , m_hasInfo(false)
55  , m_hasErrorNotes(false)
56 {
57  setObjectName("msgCtxtView");
58  QWidget* main=new QWidget(this);
59  setWidget(main);
60  m_stackedLayout = new QStackedLayout(main);
61  m_stackedLayout->addWidget(m_browser);
62 
63  m_browser->viewport()->setBackgroundRole(QPalette::Background);
64  m_browser->setOpenLinks(false);
65  connect(m_browser,SIGNAL(anchorClicked(QUrl)),this,SLOT(anchorClicked(QUrl)));
66 }
67 
68 MsgCtxtView::~MsgCtxtView()
69 {
70 }
71 
72 void MsgCtxtView::cleanup()
73 {
74  m_unfinishedNotes.clear();
75  m_tempNotes.clear();
76 }
77 
78 void MsgCtxtView::gotoEntry(const DocPosition& pos, int selection)
79 {
80  m_entry=DocPos(pos);
81  m_selection=selection;
82  m_offset=pos.offset;
83  QTimer::singleShot(0,this,SLOT(process()));
84 }
85 
86 void MsgCtxtView::process()
87 {
88  if (m_catalog->numberOfEntries()<=m_entry.entry)
89  return;//because of Qt::QueuedConnection
90 
91  if (m_stackedLayout->currentIndex())
92  m_unfinishedNotes[m_prevEntry]=qMakePair(m_editor->note(),m_editor->noteIndex());
93 
94 
95  if (m_unfinishedNotes.contains(m_entry))
96  {
97  addNoteUI();
98  m_editor->setNote(m_unfinishedNotes.value(m_entry).first,m_unfinishedNotes.value(m_entry).second);
99  }
100  else
101  m_stackedLayout->setCurrentIndex(0);
102 
103 
104  m_prevEntry=m_entry;
105  m_browser->clear();
106 
107  if (m_tempNotes.contains(m_entry.entry))
108  {
109  QString html=i18nc("@info notes to translation unit which expire when the catalog is closed", "<b>Temporary notes:</b>");
110  html+="<br>";
111  foreach(const QString& note, m_tempNotes.values(m_entry.entry))
112  html+=Qt::escape(note)+"<br>";
113  html+="<br>";
114  m_browser->insertHtml(html.replace('\n',"<br>"));
115  }
116 
117  QString phaseName=m_catalog->phase(m_entry.toDocPosition());
118  if (!phaseName.isEmpty())
119  {
120  Phase phase=m_catalog->phase(phaseName);
121  QString html=i18nc("@info translation unit metadata","<b>Phase:</b><br>");
122  if (phase.date.isValid())
123  html+=QString("%1: ").arg(phase.date.toString(Qt::ISODate));
124  html+=Qt::escape(phase.process);
125  if (!phase.contact.isEmpty())
126  html+=QString(" (%1)").arg(Qt::escape(phase.contact));
127  m_browser->insertHtml(html+"<br>");
128  }
129 
130  const QVector<Note> notes=m_catalog->notes(m_entry.toDocPosition());
131  m_hasErrorNotes=false;
132  foreach (const Note& note, notes)
133  m_hasErrorNotes=m_hasErrorNotes||note.content.contains("[ERROR]");
134 
135  int realOffset=displayNotes(m_browser, m_catalog->notes(m_entry.toDocPosition()), m_entry.form, m_catalog->capabilities()&MultipleNotes);
136 
137  QString html;
138  foreach(const Note& note, m_catalog->developerNotes(m_entry.toDocPosition()))
139  html+="<br>"+Qt::escape(note.content);
140 
141  QStringList sourceFiles=m_catalog->sourceFiles(m_entry.toDocPosition());
142  if (!sourceFiles.isEmpty())
143  {
144  html+=i18nc("@info PO comment parsing","<br><b>Files:</b><br>");
145  foreach(const QString &sourceFile, sourceFiles)
146  html+=QString("<a href=\"src:/%1\">%2</a><br />").arg(sourceFile).arg(sourceFile);
147  html.chop(6);
148  }
149 
150  QString msgctxt=m_catalog->context(m_entry.entry).first();
151  if (!msgctxt.isEmpty())
152  html+=i18nc("@info PO comment parsing","<br><b>Context:</b><br>")+Qt::escape(msgctxt);
153 
154  QTextCursor t=m_browser->textCursor();
155  t.movePosition(QTextCursor::End);
156  m_browser->setTextCursor(t);
157  m_browser->insertHtml(html);
158 
159  t.movePosition(QTextCursor::Start);
160  t.movePosition(QTextCursor::NextCharacter,QTextCursor::MoveAnchor,realOffset+m_offset);
161  t.movePosition(QTextCursor::NextCharacter,QTextCursor::KeepAnchor,m_selection);
162  m_browser->setTextCursor(t);
163 }
164 
165 
166 void MsgCtxtView::addNoteUI()
167 {
168  anchorClicked(QUrl("note:/add"));
169 }
170 
171 void MsgCtxtView::anchorClicked(const QUrl& link)
172 {
173  QString path=link.path().mid(1);// minus '/'
174 
175  if (link.scheme()=="note")
176  {
177  int capabilities=m_catalog->capabilities();
178  if (!m_editor)
179  {
180  m_editor=new NoteEditor(this);
181  m_stackedLayout->addWidget(m_editor);
182  connect(m_editor,SIGNAL(accepted()),this,SLOT(noteEditAccepted()));
183  connect(m_editor,SIGNAL(rejected()),this,SLOT(noteEditRejected()));
184  }
185  m_editor->setNoteAuthors(m_catalog->noteAuthors());
186  QVector<Note> notes=m_catalog->notes(m_entry.toDocPosition());
187  int noteIndex=-1;//means add new note
188  Note note;
189  if (!path.endsWith("add"))
190  {
191  noteIndex=path.toInt();
192  note=notes.at(noteIndex);
193  }
194  else if (!(capabilities&MultipleNotes) && notes.size())
195  {
196  noteIndex=0; //so we don't overwrite the only possible note
197  note=notes.first();
198  }
199  m_editor->setNote(note,noteIndex);
200  m_editor->setFromFieldVisible(capabilities&KeepsNoteAuthors);
201  m_stackedLayout->setCurrentIndex(1);
202  }
203  else if (link.scheme()=="src")
204  {
205  int pos=path.lastIndexOf(':');
206  emit srcFileOpenRequested(path.left(pos),path.mid(pos+1).toInt());
207  }
208 }
209 
210 void MsgCtxtView::noteEditAccepted()
211 {
212  DocPosition pos=m_entry.toDocPosition();
213  pos.form=m_editor->noteIndex();
214  m_catalog->push(new SetNoteCmd(m_catalog,pos,m_editor->note()));
215 
216  m_prevEntry.entry=-1; process();
217  //m_stackedLayout->setCurrentIndex(0);
218  //m_unfinishedNotes.remove(m_entry);
219  noteEditRejected();
220 }
221 void MsgCtxtView::noteEditRejected()
222 {
223  m_stackedLayout->setCurrentIndex(0);
224  m_unfinishedNotes.remove(m_entry);
225  emit escaped();
226 }
227 
228 void MsgCtxtView::addNote(DocPosition p, const QString& text)
229 {
230  p.form=-1;
231  m_catalog->push(new SetNoteCmd(m_catalog,p,Note(text)));
232  if (m_entry.entry==p.entry) {m_prevEntry.entry=-1; process();}
233 }
234 
235 void MsgCtxtView::addTemporaryEntryNote(int entry, const QString& text)
236 {
237  m_tempNotes.insertMulti(entry,text);
238  m_prevEntry.entry=-1; process();
239 }
240 
241 void MsgCtxtView::removeErrorNotes()
242 {
243  if (!m_hasErrorNotes) return;
244 
245  DocPosition p=m_entry.toDocPosition();
246  const QVector<Note> notes=m_catalog->notes(p);
247  p.form=notes.size();
248  while(--(p.form)>=0)
249  {
250  if (notes.at(p.form).content.contains("[ERROR]"))
251  m_catalog->push(new SetNoteCmd(m_catalog,p,Note()));
252  }
253 
254  m_prevEntry.entry=-1; process();
255 }
256 
257 
258 #include "msgctxtview.moc"
Catalog::context
QStringList context(const DocPosition &pos) const
Definition: catalog.cpp:322
MsgCtxtView::gotoEntry
void gotoEntry(const DocPosition &, int selection=0)
Definition: msgctxtview.cpp:78
QWidget
MsgCtxtView::addNote
void addNote(DocPosition, const QString &text)
Definition: msgctxtview.cpp:228
QTextCursor
QMap::contains
bool contains(const Key &key) const
QMap::values
QList< T > values() const
QDate::toString
QString toString(Qt::DateFormat format) const
QDockWidget
MsgCtxtView::cleanup
void cleanup()
Definition: msgctxtview.cpp:72
Phase::contact
QString contact
Definition: phase.h:40
MultipleNotes
Definition: catalogcapabilities.h:30
main
int main(int argc, char **argv)
Definition: main.cpp:58
Note
Definition: note.h:29
msgctxtview.h
DocPos::form
uchar form
Definition: pos.h:85
Catalog::push
void push(QUndoCommand *cmd)
Definition: catalog.cpp:155
QVector::first
T & first()
cmd.h
QMap::clear
void clear()
QString::chop
void chop(int n)
QTextCursor::movePosition
bool movePosition(MoveOperation operation, MoveMode mode, int n)
MsgCtxtView::removeErrorNotes
void removeErrorNotes()
Definition: msgctxtview.cpp:241
QString::lastIndexOf
int lastIndexOf(QChar ch, int from, Qt::CaseSensitivity cs) const
DocPosition::offset
uint offset
Definition: pos.h:51
DocPosition::entry
int entry
Definition: pos.h:48
Catalog::developerNotes
QVector< Note > developerNotes(const DocPosition &pos) const
Definition: catalog.cpp:236
DocPosition
This struct represents a position in a catalog.
Definition: pos.h:38
MsgCtxtView::srcFileOpenRequested
void srcFileOpenRequested(const QString &srcPath, int line)
QMap::insertMulti
iterator insertMulti(const Key &key, const T &value)
Phase::date
QDate date
Definition: phase.h:39
MsgCtxtView::~MsgCtxtView
~MsgCtxtView()
Definition: msgctxtview.cpp:68
catalog.h
QString::toInt
int toInt(bool *ok, int base) const
Catalog::noteAuthors
QStringList noteAuthors() const
Definition: catalog.cpp:252
QList::isEmpty
bool isEmpty() const
QObject::setObjectName
void setObjectName(const QString &name)
QString::isEmpty
bool isEmpty() const
DocPosition::form
char form
Definition: pos.h:50
QDate::isValid
bool isValid() const
QUrl::path
QString path() const
QWidget::pos
QPoint pos() const
MsgCtxtView::addTemporaryEntryNote
void addTemporaryEntryNote(int entry, const QString &text)
Definition: msgctxtview.cpp:235
QString::endsWith
bool endsWith(const QString &s, Qt::CaseSensitivity cs) const
NoteEditor
Definition: noteeditor.h:39
QList::first
T & first()
QString
Phase
Definition: phase.h:34
QStackedLayout::currentIndex
currentIndex
QUrl::scheme
QString scheme() const
QStringList
Catalog::capabilities
int capabilities() const
Definition: catalog.cpp:164
QString::contains
bool contains(QChar ch, Qt::CaseSensitivity cs) const
QUrl
Catalog::phase
QString phase(const DocPosition &pos) const
Definition: catalog.cpp:372
KTextBrowser
displayNotes
int displayNotes(KTextBrowser *browser, const QVector< Note > &notes, int active, bool multiple)
Definition: noteeditor.cpp:124
QDockWidget::setWidget
void setWidget(QWidget *widget)
Note::content
QString content
Definition: note.h:33
QString::replace
QString & replace(int position, int n, QChar after)
QVector::at
const T & at(int i) const
QString::mid
QString mid(int position, int n) const
QVector
prefs_lokalize.h
MsgCtxtView::addNoteUI
void addNoteUI()
Definition: msgctxtview.cpp:166
Qt::escape
QString escape(const QString &plain)
QStackedLayout
MsgCtxtView::escaped
void escaped()
NoteEditor::setNoteAuthors
void setNoteAuthors(const QStringList &)
Definition: noteeditor.cpp:117
QWidget::QWidget
QWidget(QWidget *parent, QFlags< Qt::WindowType > f)
Catalog::numberOfEntries
int numberOfEntries() const
Definition: catalog.cpp:171
DocPos
simpler version of DocPosition for use in QMap
Definition: pos.h:82
Phase::process
QString process
Definition: phase.h:37
NoteEditor::setFromFieldVisible
void setFromFieldVisible(bool)
Definition: noteeditor.cpp:93
DocPos::entry
int entry
Definition: pos.h:84
QString::left
QString left(int n) const
NoteEditor::note
Note note()
Definition: noteeditor.cpp:99
Catalog
This class represents a catalog It uses CatalogStorage interface to work with catalogs in different f...
Definition: catalog.h:74
NoteEditor::noteIndex
int noteIndex()
Definition: noteeditor.h:48
KeepsNoteAuthors
Definition: catalogcapabilities.h:29
Catalog::notes
QVector< Note > notes(const DocPosition &pos) const
Definition: catalog.cpp:228
Catalog::sourceFiles
QStringList sourceFiles(const DocPosition &pos) const
Definition: catalog.cpp:306
QStackedLayout::addWidget
int addWidget(QWidget *widget)
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
NoteEditor::setNote
void setNote(const Note &, int idx)
Definition: noteeditor.cpp:106
noteeditor.h
QVector::size
int size() const
QString::arg
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
SetNoteCmd
Insert or remove (if content is empty) a note.
Definition: cmd.h:163
DocPos::toDocPosition
DocPosition toDocPosition()
Definition: pos.h:107
MsgCtxtView::MsgCtxtView
MsgCtxtView(QWidget *, Catalog *)
Definition: msgctxtview.cpp:49
QMap::value
const T value(const Key &key) const
QMap::remove
int remove(const Key &key)
QTimer::singleShot
singleShot
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:40:07 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

lokalize

Skip menu "lokalize"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdesdk API Reference

Skip menu "kdesdk API Reference"
  • kapptemplate
  • kcachegrind
  • kompare
  • lokalize
  • umbrello
  •   umbrello

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal