Author: Jakob Haufe <sur5r@sur5r.net>
Bug-Debian: http://bugs.debian.org/644935
---- minitube-1.5.orig/src/MediaView.cpp
-+++ minitube-1.5/src/MediaView.cpp
-@@ -127,6 +127,7 @@ MediaView::MediaView(QWidget *parent) :
- connect(demoTimer, SIGNAL(timeout()), SLOT(demoMessage()));
+diff --git a/src/temporary.cpp b/src/temporary.cpp
+index a979cbd..bebcd1f 100644
+--- a/src/temporary.cpp
++++ b/src/temporary.cpp
+@@ -1,7 +1,7 @@
+ #include "temporary.h"
+ #include "constants.h"
+
+-static QList<QString> paths;
++static QList<QTemporaryFile*> tempfiles;
+ #ifdef Q_WS_X11
+ static QString userName;
#endif
+@@ -10,41 +10,21 @@ Temporary::Temporary() { }
-+ tempFile = new QTemporaryFile(this);
- }
+ QString Temporary::filename() {
- void MediaView::initialize() {
-@@ -346,21 +347,15 @@ void MediaView::gotStreamUrl(QUrl stream
+- static const QString tempDir = QDesktopServices::storageLocation(QDesktopServices::TempLocation);
++ QTemporaryFile *tempfile = new QTemporaryFile(QDir::tempPath() + "/" + Constants::UNIX_NAME + "-XXXXXX");
+- QString tempFile = tempDir + "/" + Constants::UNIX_NAME + "-" + QString::number(qrand());
++ tempfiles << tempfile;
- QString tempDir = QDesktopServices::storageLocation(QDesktopServices::TempLocation);
-#ifdef Q_WS_X11
-- QString tempFile = tempDir + "/minitube-" + getenv("USERNAME") + ".mp4";
--#else
-- QString tempFile = tempDir + "/minitube.mp4";
+- if (userName.isNull()) {
+- userName = QString(getenv("USERNAME"));
+- if (userName.isEmpty())
+- userName = QString(getenv("USER"));
+- }
+- if (!userName.isEmpty())
+- tempFile += "-" + userName;
-#endif
+-
- if (QFile::exists(tempFile) && !QFile::remove(tempFile)) {
-- qDebug() << "Cannot remove temp file";
+- qDebug() << "Cannot remove temp file" << tempFile;
++ if (tempfiles.size() > 1) {
++ QTemporaryFile *removedFile = tempfiles.takeFirst();
++ delete removedFile;
+ }
+
+- paths << tempFile;
+-
+- if (paths.size() > 1) {
+- QString removedFile = paths.takeFirst();
+- if (QFile::exists(removedFile) && !QFile::remove(removedFile)) {
+- qDebug() << "Cannot remove temp file" << removedFile;
+- }
- }
-+ if(tempFile->fileName().isNull())
-+ tempFile->open();
+-
+- return tempFile;
+-
++ tempfile->open();
++ return tempfile->fileName();
+ }
- Video *videoCopy = video->clone();
- if (downloadItem) {
- downloadItem->stop();
- delete downloadItem;
+ void Temporary::deleteAll() {
+- foreach(QString path, paths) {
+- if (QFile::exists(path) && !QFile::remove(path)) {
+- qDebug() << "Cannot remove temp file" << path;
+- }
++ foreach(QTemporaryFile *tempfile, tempfiles) {
++ delete tempfile;
}
-- downloadItem = new DownloadItem(videoCopy, streamUrl, tempFile, this);
-+ downloadItem = new DownloadItem(videoCopy, streamUrl, tempFile->fileName(), this);
- connect(downloadItem, SIGNAL(statusChanged()), SLOT(downloadStatusChanged()));
- // connect(downloadItem, SIGNAL(progress(int)), SLOT(downloadProgress(int)));
- connect(downloadItem, SIGNAL(bufferProgress(int)), loadingWidget, SLOT(bufferStatus(int)));
---- minitube-1.5.orig/src/MediaView.h
-+++ minitube-1.5/src/MediaView.h
+ }
+diff --git a/src/temporary.h b/src/temporary.h
+index 50b9633..0453572 100644
+--- a/src/temporary.h
++++ b/src/temporary.h
@@ -3,6 +3,7 @@
- #include <QtGui>
- #include <QtNetwork>
+ #include <QtCore>
+ #include <QDesktopServices>
+#include <QTemporaryFile>
- #include <phonon/mediaobject.h>
- #include <phonon/videowidget.h>
- #include "View.h"
-@@ -130,6 +131,8 @@ private:
- DownloadItem *downloadItem;
- // QSlider *slider;
-
-+ QTemporaryFile *tempFile;
-+
- };
-
- #endif // __MEDIAVIEW_H__
+
+ class Temporary {
+