~ubuntu-branches/ubuntu/saucy/clementine/saucy

« back to all changes in this revision

Viewing changes to src/core/encoding.cpp

  • Committer: Package Import Robot
  • Author(s): Thomas PIERSON
  • Date: 2012-01-01 20:43:39 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20120101204339-lsb6nndwhfy05sde
Tags: 1.0.1+dfsg-1
New upstream release. (Closes: #653926, #651611, #657391)

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
*/
17
17
 
18
18
#include "encoding.h"
 
19
#include "core/logging.h"
19
20
 
20
21
#include <QTextCodec>
21
22
#include <QtDebug>
27
28
#include <vorbisfile.h>
28
29
#include <flacfile.h>
29
30
 
 
31
#include "core/logging.h"
30
32
#include "engines/enginebase.h"
31
33
 
32
34
UniversalEncodingHandler::UniversalEncodingHandler()
91
93
        repeats = 0;
92
94
      }
93
95
      if (repeats > 3) {
94
 
        qWarning() << "Heuristic guessed windows-1251";
 
96
        qLog(Warning) << "Heuristic guessed windows-1251";
95
97
        current_codec_ = QTextCodec::codecForName("windows-1251");
96
98
      }
97
99
    }
132
134
    return NULL;
133
135
  }
134
136
 
135
 
  QHash<QTextCodec*, int>::const_iterator max = std::max_element(usages.begin(), usages.end());
 
137
  QHash<QTextCodec*, int>::const_iterator max =
 
138
      std::max_element(usages.constBegin(), usages.constEnd());
136
139
  return max.key();
137
140
}
138
141
 
154
157
    return NULL;
155
158
  }
156
159
  if (input.isLatin1()) {
157
 
    qWarning() << "Extended ASCII... possibly should be CP866 or windows-1251 instead";
 
160
    qLog(Warning) << "Extended ASCII... possibly should be CP866 or windows-1251 instead";
158
161
    std::string broken = input.toCString(true);
159
162
    std::string fixed = QString::fromUtf8(broken.c_str()).toStdString();
160
163
    QTextCodec* codec = Guess(fixed.c_str());
172
175
  ++usages[Guess(bundle, &Engine::SimpleMetaBundle::genre)];
173
176
 
174
177
  usages.remove(NULL);  // Remove votes for ASCII.
175
 
  QHash<QTextCodec*, int>::const_iterator max = std::max_element(usages.begin(), usages.end());
176
 
  if (max != usages.end()) {
 
178
  QHash<QTextCodec*, int>::const_iterator max =
 
179
      std::max_element(usages.constBegin(), usages.constEnd());
 
180
  if (max != usages.constEnd()) {
177
181
    return max.key();
178
182
  }
179
183
  return NULL;
181
185
 
182
186
QString UniversalEncodingHandler::FixEncoding(const TagLib::String& input) {
183
187
  if (input.isLatin1() && !input.isAscii()) {
184
 
    qWarning() << "Extended ASCII... possibly should be CP866 or windows-1251 instead";
 
188
    qLog(Warning) << "Extended ASCII... possibly should be CP866 or windows-1251 instead";
185
189
    std::string broken = input.toCString(true);
186
190
    std::string fixed;
187
191
    if (broken.size() > input.size()) {
188
192
      fixed = QString::fromUtf8(broken.c_str()).toStdString();
189
193
      QTextCodec* codec = Guess(fixed.c_str());
190
194
      if (!codec) {
191
 
        qDebug() << "Could not guess encoding. Using extended ASCII.";
 
195
        qLog(Debug) << "Could not guess encoding. Using extended ASCII.";
192
196
      } else {
193
 
        qDebug() << "Guessed:" << codec->name();
 
197
        qLog(Debug) << "Guessed:" << codec->name();
194
198
        QString foo = codec->toUnicode(fixed.c_str());
195
199
        return foo.trimmed();
196
200
      }