]> git.sur5r.net Git - minitube/blobdiff - src/playlistmodel.cpp
Upload 3.9.3-2 to unstable
[minitube] / src / playlistmodel.cpp
index 1ddc1dea263b8f9b9f823b4c8160471056fde009..f2e0e5f32d0f5c9a10c4c6e84e3dfa85e7c311e8 100644 (file)
@@ -20,17 +20,13 @@ $END_LICENSE */
 
 #include "playlistmodel.h"
 #include "mediaview.h"
+#include "playlistitemdelegate.h"
 #include "searchparams.h"
 #include "video.h"
 #include "videomimedata.h"
 #include "videosource.h"
 
-#include "ivchannelsource.h"
-#include "ivsearch.h"
-#include "ytsearch.h"
-
-#include "ytjschannelsource.h"
-#include "ytjssearch.h"
+#include "searchvideosource.h"
 
 namespace {
 const QString recentKeywordsKey = "recentKeywords";
@@ -247,8 +243,10 @@ void PlaylistModel::addVideos(const QVector<Video *> &newVideos) {
     videos.append(newVideos);
     endInsertRows();
     for (Video *video : newVideos) {
-        connect(video, SIGNAL(gotThumbnail()), SLOT(updateVideoSender()), Qt::UniqueConnection);
-        video->loadThumbnail();
+        connect(video, &Video::changed, this, [video, this] {
+            int row = rowForVideo(video);
+            emit dataChanged(createIndex(row, 0), createIndex(row, columnCount() - 1));
+        });
     }
 }
 
@@ -262,30 +260,12 @@ void PlaylistModel::handleFirstVideo(Video *video) {
     }
 
     auto clazz = videoSource->metaObject()->className();
-    if (clazz == QLatin1String("YTSearch") || clazz == QLatin1String("IVSearch") ||
-        clazz == QLatin1String("IVChannelSource") || clazz == QLatin1String("YTJSSearch") ||
-        clazz == QLatin1String("YTJSChannelSource")) {
-        static const int maxRecentElements = 10;
-
-        SearchParams *searchParams;
-        if (clazz == QLatin1String("YTSearch")) {
-            auto search = qobject_cast<YTSearch *>(videoSource);
-            searchParams = search->getSearchParams();
-        } else if (clazz == QLatin1String("IVSearch")) {
-            auto search = qobject_cast<IVSearch *>(videoSource);
-            searchParams = search->getSearchParams();
-        } else if (clazz == QLatin1String("IVChannelSource")) {
-            auto search = qobject_cast<IVChannelSource *>(videoSource);
-            searchParams = search->getSearchParams();
-        } else if (clazz == QLatin1String("YTJSSearch")) {
-            auto search = qobject_cast<YTJSSearch *>(videoSource);
-            searchParams = search->getSearchParams();
-        } else if (clazz == QLatin1String("YTJSChannelSource")) {
-            auto search = qobject_cast<YTJSChannelSource *>(videoSource);
-            searchParams = search->getSearchParams();
-        }
+    if (clazz == QLatin1String("SearchVideoSource")) {
+        auto search = qobject_cast<SearchVideoSource *>(videoSource);
+        SearchParams *searchParams = search->getSearchParams();
 
         // save keyword
+        static const int maxRecentElements = 10;
         QString query = searchParams->keywords();
         if (!query.isEmpty() && !searchParams->isTransient()) {
             if (query.startsWith("http://")) {
@@ -320,16 +300,6 @@ void PlaylistModel::handleFirstVideo(Video *video) {
     }
 }
 
-void PlaylistModel::updateVideoSender() {
-    Video *video = static_cast<Video *>(sender());
-    if (!video) {
-        qDebug() << "Cannot get sender";
-        return;
-    }
-    int row = rowForVideo(video);
-    emit dataChanged(createIndex(row, 0), createIndex(row, columnCount() - 1));
-}
-
 void PlaylistModel::emitDataChanged() {
     QModelIndex index = createIndex(rowCount() - 1, 0);
     emit dataChanged(index, index);
@@ -434,7 +404,11 @@ bool PlaylistModel::dropMimeData(const QMimeData *data,
 
         // and then add them again at the new position
         beginInsertRows(QModelIndex(), beginRow, beginRow);
-        videos.insert(beginRow, video);
+        if (beginRow >= videos.size()) {
+            videos.push_back(video);
+        } else {
+            videos.insert(beginRow, video);
+        }
         endInsertRows();
     }