5
5
A MIDI and audio sequencer and musical notation editor.
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>
87
int selectedProbability = 0;
89
selectedProbability = cc->heuristicContentMatch
90
(m_text.c_str(), m_text.length());
87
93
while ((codec = QTextCodec::codecForIndex(i)) != 0) {
88
if (codec->heuristicContentMatch(m_text.c_str(), m_text.length()) <= 0) {
95
int probability = codec->heuristicContentMatch
96
(m_text.c_str(), m_text.length());
98
if (probability <= 0) {
92
std::cerr << "codec " << codec->name() << " probability " << codec->heuristicContentMatch(m_text.c_str(), m_text.length()) << std::endl;
93
103
std::string name = codec->name();
105
std::cerr << "codec " << name << " probability " << probability << std::endl;
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;
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));
101
122
if (description != "") {
102
123
description = i18n("%1 (%2)").arg(strtoqstr(name)).arg(description);
104
125
description = strtoqstr(name);
106
128
codecs->insertItem(description, 0);
107
m_codecs.push_back(name);
129
m_codecs.push_front(name);
130
if (current >= 0) ++current;
108
132
if (cc && (name == cc->name())) {
109
codecs->setCurrentItem(0);
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);
131
155
IdentifyTextCodecDialog::slotCodecSelected(int i)
133
if (i < 0 || i >= m_codecs.size())
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));
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 + "\"");