]> git.sur5r.net Git - minitube/blobdiff - src/playlistmodel.cpp
New upstream version 3.8
[minitube] / src / playlistmodel.cpp
index 99083489b18356919e86058779abcb804ebb66b2..be0819479e1a5096b6bfe58d7c05bc218d0fc903 100644 (file)
@@ -25,9 +25,7 @@ $END_LICENSE */
 #include "videomimedata.h"
 #include "videosource.h"
 
-#include "ivchannelsource.h"
-#include "ivsearch.h"
-#include "ytsearch.h"
+#include "searchvideosource.h"
 
 namespace {
 const QString recentKeywordsKey = "recentKeywords";
@@ -77,11 +75,8 @@ QVariant PlaylistModel::data(const QModelIndex &index, int role) const {
         case Qt::TextAlignmentRole:
             return QVariant(int(Qt::AlignHCenter | Qt::AlignVCenter));
         case Qt::ForegroundRole:
-            if (!errorMessage.isEmpty())
-                return palette.color(QPalette::ToolTipText);
-            else
-                return palette.color(QPalette::Dark);
-        case Qt::BackgroundColorRole:
+            return palette.color(QPalette::Dark);
+        case Qt::BackgroundRole:
             if (!errorMessage.isEmpty())
                 return palette.color(QPalette::ToolTipBase);
             else
@@ -262,23 +257,12 @@ void PlaylistModel::handleFirstVideo(Video *video) {
     }
 
     auto clazz = videoSource->metaObject()->className();
-    if (clazz == QLatin1String("YTSearch") || clazz == QLatin1String("IVSearch") ||
-        clazz == QLatin1String("IVChannelSource")) {
-        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();
-        }
+    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://")) {
@@ -427,7 +411,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();
     }