Changeset 156 for smplayer/trunk/src/findsubtitles/findsubtitleswindow.cpp
- Timestamp:
- Feb 21, 2014, 5:26:03 PM (11 years ago)
- Location:
- smplayer/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
smplayer/trunk
- Property svn:mergeinfo changed
/smplayer/vendor/current merged: 154
- Property svn:mergeinfo changed
-
smplayer/trunk/src/findsubtitles/findsubtitleswindow.cpp
r142 r156 36 36 37 37 #ifdef DOWNLOAD_SUBS 38 #include <QBuffer> 38 39 #include "filedownloader.h" 39 40 #include "subchooserdialog.h" 41 #include "fixsubs.h" 42 43 #ifdef USE_QUAZIP 40 44 #include "quazip.h" 41 45 #include "quazipfile.h" 42 #include "fixsubs.h"43 46 #include <QTemporaryFile> 44 #include <QBuffer> 47 #else 48 #include <zlib.h> 49 #endif 50 45 51 #endif 46 52 … … 134 140 connect( osclient, SIGNAL(loginFailed()), this, SLOT(showLoginFailed()) ); 135 141 connect( osclient, SIGNAL(searchFailed()), this, SLOT(showSearchFailed()) ); 142 connect( osclient, SIGNAL(errorFound(int, const QString &)), this, SLOT(showErrorOS(int, const QString &)) ); 136 143 137 144 #ifdef DOWNLOAD_SUBS … … 346 353 } 347 354 355 void FindSubtitlesWindow::showErrorOS(int, const QString & error) { 356 status->setText(error); 357 } 358 348 359 void FindSubtitlesWindow::updateDataReadProgress(int done, int total) { 349 360 qDebug("FindSubtitlesWindow::updateDataReadProgress: %d, %d", done, total); … … 466 477 467 478 #ifdef DOWNLOAD_SUBS 479 480 #ifndef USE_QUAZIP 481 void 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 523 QByteArray 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 468 575 void FindSubtitlesWindow::archiveDownloaded(const QByteArray & buffer) { 469 576 qDebug("FindSubtitlesWindow::archiveDownloaded"); … … 630 737 return true; 631 738 } 739 #endif // USE_QUAZIP 632 740 633 741 void FindSubtitlesWindow::fixSubtitles(const QString & filename) { … … 644 752 } 645 753 646 #endif 754 #endif // DOWNLOAD_SUBS 647 755 648 756 void FindSubtitlesWindow::on_configure_button_clicked() {
Note:
See TracChangeset
for help on using the changeset viewer.