Description: Do proper temporary file creation
 Upstream is using predictable temporary file names. Fix this in Debian
 for now by using QTemporaryFile. This additionally ensures removal of
 temporary files upon exit.
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()));
 #endif
 
+    tempFile = new QTemporaryFile(this);
 }
 
 void MediaView::initialize() {
@@ -346,21 +347,15 @@ void MediaView::gotStreamUrl(QUrl stream
 
 
     QString tempDir = QDesktopServices::storageLocation(QDesktopServices::TempLocation);
-#ifdef Q_WS_X11
-    QString tempFile = tempDir + "/minitube-" + getenv("USERNAME") + ".mp4";
-#else
-    QString tempFile = tempDir + "/minitube.mp4";
-#endif
-    if (QFile::exists(tempFile) && !QFile::remove(tempFile)) {
-        qDebug() << "Cannot remove temp file";
-    }
+    if(tempFile->fileName().isNull())
+        tempFile->open();
 
     Video *videoCopy = video->clone();
     if (downloadItem) {
         downloadItem->stop();
         delete downloadItem;
     }
-    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
@@ -3,6 +3,7 @@
 
 #include <QtGui>
 #include <QtNetwork>
+#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__
