Ignore:
Timestamp:
Feb 21, 2014, 5:26:03 PM (11 years ago)
Author:
Silvan Scherrer
Message:

SMPlayer: update trunk to 0.8.6

Location:
smplayer/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • smplayer/trunk

  • smplayer/trunk/src/findsubtitles/findsubtitleswindow.cpp

    r142 r156  
    3636
    3737#ifdef DOWNLOAD_SUBS
     38#include <QBuffer>
    3839#include "filedownloader.h"
    3940#include "subchooserdialog.h"
     41#include "fixsubs.h"
     42
     43#ifdef USE_QUAZIP
    4044#include "quazip.h"
    4145#include "quazipfile.h"
    42 #include "fixsubs.h"
    4346#include <QTemporaryFile>
    44 #include <QBuffer>
     47#else
     48#include <zlib.h>
     49#endif
     50
    4551#endif
    4652
     
    134140        connect( osclient, SIGNAL(loginFailed()), this, SLOT(showLoginFailed()) );
    135141        connect( osclient, SIGNAL(searchFailed()), this, SLOT(showSearchFailed()) );
     142        connect( osclient, SIGNAL(errorFound(int, const QString &)), this, SLOT(showErrorOS(int, const QString &)) );
    136143
    137144#ifdef DOWNLOAD_SUBS
     
    346353}
    347354
     355void FindSubtitlesWindow::showErrorOS(int, const QString & error) {
     356        status->setText(error);
     357}
     358
    348359void FindSubtitlesWindow::updateDataReadProgress(int done, int total) {
    349360        qDebug("FindSubtitlesWindow::updateDataReadProgress: %d, %d", done, total);
     
    466477
    467478#ifdef DOWNLOAD_SUBS
     479
     480#ifndef USE_QUAZIP
     481void FindSubtitlesWindow::archiveDownloaded(const QByteArray & buffer) {
     482        qDebug("FindSubtitlesWindow::archiveDownloaded");
     483        QByteArray uncompress_data = gUncompress(buffer);
     484        //qDebug("uncompress_data: %s", uncompress_data.constData());
     485
     486        if (uncompress_data.isEmpty()) {
     487                status->setText(tr("Download failed"));
     488                return;
     489        }
     490
     491        QString lang = "unknown";
     492        QString extension = "unknown";
     493        if (view->currentIndex().isValid()) {
     494                const QModelIndex & index = view->currentIndex();
     495                lang = table->item(proxy_model->mapToSource(index).row(), COL_LANG)->data(Qt::UserRole).toString();
     496                extension = table->item(proxy_model->mapToSource(index).row(), COL_FORMAT)->text();
     497        }
     498
     499        QFileInfo fi(file_chooser->text());
     500        QString output_name = fi.completeBaseName();
     501        if (include_lang_on_filename) output_name += "_"+ lang;
     502        output_name += "." + extension;
     503
     504        QString output_file = fi.absolutePath() + "/" + output_name;
     505        qDebug("FindSubtitlesWindow::archiveDownloaded: save subtitle as '%s'", output_file.toUtf8().constData());
     506
     507        QFile file(output_file);
     508        file.open(QIODevice::WriteOnly);
     509        bool error = (file.write(uncompress_data) == -1);
     510        file.close();
     511
     512        if (error) {
     513                qWarning("FindSubtitlesWindow::archiveDownloaded: can't write subtitle file");
     514                QMessageBox::warning(this, tr("Error saving file"),
     515                             tr("It wasn't possible to save the downloaded\n"
     516                                "file in folder %1\n"
     517                                "Please check the permissions of that folder.").arg(fi.absolutePath()));
     518        } else {
     519                emit subtitleDownloaded( output_file );
     520        }
     521}
     522
     523QByteArray FindSubtitlesWindow::gUncompress(const QByteArray &data)
     524{
     525    if (data.size() <= 4) {
     526        qWarning("gUncompress: Input data is truncated");
     527        return QByteArray();
     528    }
     529
     530    QByteArray result;
     531
     532    int ret;
     533    z_stream strm;
     534    static const int CHUNK_SIZE = 1024;
     535    char out[CHUNK_SIZE];
     536
     537    /* allocate inflate state */
     538    strm.zalloc = Z_NULL;
     539    strm.zfree = Z_NULL;
     540    strm.opaque = Z_NULL;
     541    strm.avail_in = data.size();
     542    strm.next_in = (Bytef*)(data.data());
     543
     544    ret = inflateInit2(&strm, 15 +  32); // gzip decoding
     545    if (ret != Z_OK)
     546        return QByteArray();
     547
     548    // run inflate()
     549    do {
     550        strm.avail_out = CHUNK_SIZE;
     551        strm.next_out = (Bytef*)(out);
     552
     553        ret = inflate(&strm, Z_NO_FLUSH);
     554        Q_ASSERT(ret != Z_STREAM_ERROR);  // state not clobbered
     555
     556        switch (ret) {
     557        case Z_NEED_DICT:
     558            ret = Z_DATA_ERROR;     // and fall through
     559        case Z_DATA_ERROR:
     560        case Z_MEM_ERROR:
     561            (void)inflateEnd(&strm);
     562            return QByteArray();
     563        }
     564
     565        result.append(out, CHUNK_SIZE - strm.avail_out);
     566    } while (strm.avail_out == 0);
     567
     568    // clean up and return
     569    inflateEnd(&strm);
     570    return result;
     571}
     572
     573#else
     574
    468575void FindSubtitlesWindow::archiveDownloaded(const QByteArray & buffer) {
    469576        qDebug("FindSubtitlesWindow::archiveDownloaded");
     
    630737        return true;
    631738}
     739#endif // USE_QUAZIP
    632740
    633741void FindSubtitlesWindow::fixSubtitles(const QString & filename) {
     
    644752}
    645753
    646 #endif
     754#endif // DOWNLOAD_SUBS
    647755
    648756void FindSubtitlesWindow::on_configure_button_clicked() {
Note: See TracChangeset for help on using the changeset viewer.