~ubuntu-branches/ubuntu/intrepid/kdesdk/intrepid-updates

« back to all changes in this revision

Viewing changes to lokalize/src/msgiddiffview.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2008-05-28 10:11:43 UTC
  • mto: This revision was merged to the branch mainline in revision 37.
  • Revision ID: james.westby@ubuntu.com-20080528101143-gzc3styjz1b70zxu
Tags: upstream-4.0.80
ImportĀ upstreamĀ versionĀ 4.0.80

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* ****************************************************************************
 
2
  This file is part of KAider
 
3
 
 
4
  Copyright (C) 2007 by Nick Shaforostoff <shafff@ukr.net>
 
5
 
 
6
  This program is free software; you can redistribute it and/or modify
 
7
  it under the terms of the GNU General Public License as published by
 
8
  the Free Software Foundation; either version 2 of the License, or
 
9
  (at your option) any later version.
 
10
 
 
11
  This program is distributed in the hope that it will be useful,
 
12
  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
  GNU General Public License for more details.
 
15
 
 
16
  You should have received a copy of the GNU General Public License
 
17
  along with this program; if not, write to the Free Software
 
18
  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
19
 
 
20
  In addition, as a special exception, the copyright holders give
 
21
  permission to link the code of this program with any edition of
 
22
  the Qt library by Trolltech AS, Norway (or with modified versions
 
23
  of Qt that use the same license as Qt), and distribute linked
 
24
  combinations including the two.  You must obey the GNU General
 
25
  Public License in all respects for all of the code used other than
 
26
  Qt. If you modify this file, you may extend this exception to
 
27
  your version of the file, but you are not obligated to do so.  If
 
28
  you do not wish to do so, delete this exception statement from
 
29
  your version.
 
30
 
 
31
**************************************************************************** */
 
32
#define KDE_NO_DEBUG_OUTPUT
 
33
 
 
34
#include "msgiddiffview.h"
 
35
 
 
36
#include "diff.h"
 
37
#include "catalog.h"
 
38
#include "project.h"
 
39
 
 
40
#include <klocale.h>
 
41
#include <kdebug.h>
 
42
#include <ktextedit.h>
 
43
 
 
44
//#include <QTime>
 
45
 
 
46
MsgIdDiff::MsgIdDiff(QWidget* parent, Catalog* catalog)
 
47
    : QDockWidget ( i18nc("@title:window","Original Diff"), parent)
 
48
    , m_browser(new KTextEdit(this))
 
49
    , m_catalog(catalog)
 
50
    , m_normTitle(i18nc("@title:window","Original Diff"))
 
51
    , m_hasInfoTitle(m_normTitle+" [*]")
 
52
    , m_hasInfo(false)
 
53
    , m_entry(-1)
 
54
    , m_prevEntry(-1)
 
55
{
 
56
    setObjectName("msgIdDiff");
 
57
    setWidget(m_browser);
 
58
    setToolTip(i18nc("@info:tooltip","Sometimes, if original is changed, its translation becomes <emphasis>fuzzy</emphasis>. This window shows the difference between new original string and the old one, so that you can see what changes should be applied to translation."));
 
59
 
 
60
    m_browser->setReadOnly(true);
 
61
}
 
62
 
 
63
MsgIdDiff::~MsgIdDiff()
 
64
{
 
65
    delete m_browser;
 
66
}
 
67
 
 
68
void MsgIdDiff::slotNewEntryDisplayed(uint index)
 
69
{
 
70
    m_entry=index;
 
71
    QTimer::singleShot(0,this,SLOT(process()));
 
72
}
 
73
 
 
74
void MsgIdDiff::process()
 
75
{
 
76
    if (m_entry==m_prevEntry)
 
77
        return;
 
78
    if (m_catalog->numberOfEntries()<=m_entry)
 
79
        return;//because of Qt::QueuedConnection
 
80
 
 
81
    m_prevEntry=m_entry;
 
82
    QString oldStr(m_catalog->comment(m_entry));
 
83
    if (!oldStr.contains("#|"))
 
84
    {
 
85
        if (m_hasInfo)
 
86
        {
 
87
            m_hasInfo=false;
 
88
            setWindowTitle(m_normTitle);
 
89
            m_browser->clear();
 
90
        }
 
91
        return;
 
92
    }
 
93
 
 
94
    if (!m_hasInfo)
 
95
    {
 
96
        m_hasInfo=true;
 
97
        setWindowTitle(m_hasInfoTitle);
 
98
    }
 
99
    QString newStr(m_catalog->msgid(m_entry));
 
100
 
 
101
    oldStr.replace("#| msgid_plural \"","#| \"");
 
102
    newStr.replace("#| msgid_plural \"","#| \"");
 
103
 
 
104
 
 
105
//     QTime time;
 
106
//     time.start();
 
107
 
 
108
    //get rid of other info (eg fuzzy marks)
 
109
    oldStr.remove(QRegExp("\\#[^\\|][^\n]*\n"));
 
110
    oldStr.remove(QRegExp("\\#[^\\|].*$"));
 
111
 
 
112
    if (oldStr.contains("#| msgid \"\""))
 
113
    {
 
114
        oldStr.remove("#| \"");
 
115
        oldStr.remove(QRegExp("\"\n"));
 
116
        oldStr.remove(QRegExp("\"$"));
 
117
 
 
118
        newStr.remove("\n");
 
119
        oldStr.replace("\\n"," \\n ");
 
120
        newStr.replace("\\n"," \\n ");
 
121
        oldStr.remove("#| msgid \"");
 
122
    }
 
123
    else
 
124
    {
 
125
        oldStr.remove("#| msgid \"");
 
126
        oldStr.remove(QRegExp("\"$"));
 
127
        oldStr.remove("\"\n");
 
128
    }
 
129
 
 
130
    QString result(wordDiff(oldStr,
 
131
                            newStr,
 
132
                            Project::instance()->accel(),
 
133
                            Project::instance()->markup()
 
134
                           ));
 
135
    result.replace("\\n","\\n<br>");
 
136
 
 
137
    m_browser->setHtml(result);
 
138
//     m_browser->setPlainText(result);
 
139
 
 
140
//     oldStr.replace("\\n","\\n\n");
 
141
//     newStr.replace("\\n","\\n\n");
 
142
 
 
143
//     kDebug()<<"ELA "<<time.elapsed();
 
144
}
 
145
 
 
146
#include "msgiddiffview.moc"