Example #1
0
  void CDInfoDialog::slotChangeEncoding()
  {
      QDialog* dialog = new QDialog(this);
      dialog->setWindowTitle(i18n("Change Encoding"));
      dialog->setModal( true );


      QStringList songTitles;
        for (int t = 0; t < m_trackModel->rowCount(); ++t) {
              QString title = m_trackModel->index(t, Private::TRACK_ARTIST).data().toString().trimmed();
              if (!title.isEmpty())
              title.append(Private::SEPARATOR);
              title.append(m_trackModel->index(t, Private::TRACK_TITLE).data().toString().trimmed());
              songTitles << title;
          }

      KCDDB::CDInfoEncodingWidget* encWidget = new KCDDB::CDInfoEncodingWidget(
          dialog, d->ui->m_artist->text(),d->ui->m_title->text(), songTitles);

      QVBoxLayout* layout = new QVBoxLayout(dialog);
      layout->addWidget(encWidget);

      if (dialog->exec())
      {
        KCharsets* charsets = KCharsets::charsets();
        QTextCodec* codec = charsets->codecForName(charsets->encodingForName(encWidget->selectedEncoding()));

        d->ui->m_artist->setText(codec->toUnicode(d->ui->m_artist->text().toLatin1()));
        d->ui->m_title->setText(codec->toUnicode(d->ui->m_title->text().toLatin1()));
        d->ui->m_genre->setItemText(d->ui->m_genre->currentIndex(), codec->toUnicode(d->ui->m_genre->currentText().toLatin1()));
        d->ui->m_comment->setText(codec->toUnicode(d->ui->m_comment->text().toLatin1()));

        QModelIndex trackIndex = m_trackModel->index(0, 0, QModelIndex());
        int trackRows = m_trackModel->rowCount(trackIndex);
        for (int t = 0; t < trackRows; ++t) {
            QString artist = m_trackModel->index(t, Private::TRACK_ARTIST, trackIndex).data().toString();
            m_trackModel->setData(m_trackModel->index(t, Private::TRACK_ARTIST, trackIndex), codec->toUnicode(artist.toLatin1()));
            QString title = m_trackModel->index(t, Private::TRACK_TITLE, trackIndex).data().toString();
            m_trackModel->setData(m_trackModel->index(t, Private::TRACK_TITLE, trackIndex), codec->toUnicode(title.toLatin1()));
            QString comment = m_trackModel->index(t, Private::TRACK_COMMENT, trackIndex).data().toString();
            m_trackModel->setData(m_trackModel->index(t, Private::TRACK_COMMENT, trackIndex), codec->toUnicode(comment.toLatin1()));
        }
      }
  }
Example #2
0
const QStringList& TextCharCodec::codecNames()
{
    static QStringList textCodecNames;

    // first call?
    if( textCodecNames.isEmpty() )
    {
        KCharsets* charsets = KGlobal::charsets();
        for( unsigned int i = 0; i < encodingDataListSize; ++i )
        {
            bool isCodecFound = false;
            const QString codecName = QString::fromLatin1( encodingDataList[i].name );
            QTextCodec* codec = charsets->codecForName( codecName, isCodecFound );
            if( isCodecFound )
                textCodecNames.append( QString::fromLatin1(codec->name()) );
        }
    }

    return textCodecNames;
}