~ubuntu-branches/ubuntu/karmic/rosegarden/karmic

« back to all changes in this revision

Viewing changes to src/gui/dialogs/IdentifyTextCodecDialog.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Stefan Ebner
  • Date: 2008-05-02 00:33:44 UTC
  • mfrom: (1.1.7 upstream) (6.1.1 lenny)
  • Revision ID: james.westby@ubuntu.com-20080502003344-67vbfhgqx2yl0ksi
Tags: 1:1.7.0-1ubuntu1
* Merge from Debian unstable. (LP: #225849) Remaining Ubuntu changes:
  - Add usr/share/doc/kde/HTML to rosegarden-data, to provide online
    help documentation.
  - Change fftw3-dev to libfftw3-dev.
  - Update maintainer field as per spec.

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
    Rosegarden
5
5
    A MIDI and audio sequencer and musical notation editor.
6
6
 
7
 
    This program is Copyright 2000-2007
 
7
    This program is Copyright 2000-2008
8
8
        Guillaume Laurent   <glaurent@telegraph-road.org>,
9
9
        Chris Cannam        <cannam@all-day-breakfast.com>,
10
10
        Richard Bown        <richard.bown@ferventsoftware.com>
84
84
    int i = 0;
85
85
    int current = -1;
86
86
 
 
87
    int selectedProbability = 0;
 
88
    if (cc) {
 
89
        selectedProbability = cc->heuristicContentMatch
 
90
            (m_text.c_str(), m_text.length());
 
91
    }
 
92
 
87
93
    while ((codec = QTextCodec::codecForIndex(i)) != 0) {
88
 
        if (codec->heuristicContentMatch(m_text.c_str(), m_text.length()) <= 0) {
 
94
 
 
95
        int probability = codec->heuristicContentMatch
 
96
            (m_text.c_str(), m_text.length());
 
97
 
 
98
        if (probability <= 0) {
89
99
            ++i;
90
100
            continue;
91
101
        }
92
 
        std::cerr << "codec " << codec->name() << " probability " << codec->heuristicContentMatch(m_text.c_str(), m_text.length()) << std::endl;
 
102
 
93
103
        std::string name = codec->name();
 
104
 
 
105
        std::cerr << "codec " << name << " probability " << probability << std::endl;
 
106
 
 
107
        if (name == "UTF-8" && 
 
108
            (!cc || (cc->name() != name)) &&
 
109
            probability > selectedProbability/2) {
 
110
            std::cerr << "UTF-8 has a decent probability, selecting it instead to promote global harmony" << std::endl;
 
111
            cc = codec;
 
112
        }
 
113
 
94
114
        QString description = codecDescriptions[name];
95
115
        if (description == "") {
96
116
            if (strtoqstr(name).left(3) == "CP ") {
98
118
                              arg(strtoqstr(name).right(name.length() - 3));
99
119
            }
100
120
        }
 
121
 
101
122
        if (description != "") {
102
123
            description = i18n("%1 (%2)").arg(strtoqstr(name)).arg(description);
103
124
        } else {
104
125
            description = strtoqstr(name);
105
126
        }
 
127
 
106
128
        codecs->insertItem(description, 0);
107
 
        m_codecs.push_back(name);
 
129
        m_codecs.push_front(name);
 
130
        if (current >= 0) ++current;
 
131
 
108
132
        if (cc && (name == cc->name())) {
109
 
            codecs->setCurrentItem(0);
110
133
            current = 0;
111
 
        } else {
112
 
            if (current >= 0)
113
 
                ++current;
114
134
        }
 
135
 
115
136
        ++i;
116
137
    }
117
138
 
124
145
    font.setStyleHint(QFont::TypeWriter);
125
146
    m_example->setFont(font);
126
147
    m_example->setPaletteForegroundColor(Qt::blue);
127
 
    slotCodecSelected(current >= 0 ? current : 0);
 
148
    std::cerr << "calling slotCodecSelected(" << current << ")" << std::endl;
 
149
    if (current < 0) current = 0;
 
150
    codecs->setCurrentItem(current);
 
151
    slotCodecSelected(current);
128
152
}
129
153
 
130
154
void
131
155
IdentifyTextCodecDialog::slotCodecSelected(int i)
132
156
{
133
 
    if (i < 0 || i >= m_codecs.size())
134
 
        return ;
135
 
    std::string name = m_codecs[m_codecs.size() - i - 1];
 
157
//    std::cerr << "codec index = " << i << std::endl;
 
158
    if (i < 0 || i >= m_codecs.size()) return;
 
159
    std::string name = m_codecs[i];
 
160
//    std::cerr << "codecs: ";
 
161
//    for (int j = 0; j < m_codecs.size(); ++j) std::cerr << m_codecs[j] << " ";
 
162
//    std::cerr << std::endl;
136
163
    QTextCodec *codec = QTextCodec::codecForName(strtoqstr(name));
137
 
    if (!codec)
138
 
        return ;
 
164
    if (!codec) return;
139
165
    m_codec = qstrtostr(codec->name());
140
166
    std::cerr << "Applying codec " << m_codec << std::endl;
141
167
    QString outText = codec->toUnicode(m_text.c_str(), m_text.length());
142
 
    if (outText.length() > 80)
143
 
        outText = outText.left(80);
 
168
    if (outText.length() > 80) outText = outText.left(80);
144
169
    m_example->setText("\"" + outText + "\"");
145
170
}
146
171