#include "playlistmodel.h"
#include "mediaview.h"
+#include "playlistitemdelegate.h"
#include "searchparams.h"
#include "video.h"
#include "videomimedata.h"
#include "videosource.h"
-#include "ytsearch.h"
+
+#include "searchvideosource.h"
namespace {
-const int maxItems = 50;
const QString recentKeywordsKey = "recentKeywords";
const QString recentChannelsKey = "recentChannels";
} // namespace
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
},
Qt::UniqueConnection);
+ canSearchMore = true;
searchMore();
}
-void PlaylistModel::searchMore(int max) {
- if (videoSource == nullptr || searching) return;
+void PlaylistModel::searchMore() {
+ if (!canSearchMore || videoSource == nullptr || searching) return;
searching = true;
firstSearch = startIndex == 1;
- this->max = max;
+ max = videoSource->maxResults();
+ if (max == 0) max = 20;
errorMessage.clear();
videoSource->loadVideos(max, startIndex);
startIndex += max;
}
-void PlaylistModel::searchMore() {
- searchMore(maxItems);
-}
-
void PlaylistModel::searchNeeded() {
const int desiredRowsAhead = 10;
int remainingRows = videos.size() - m_activeRow;
- if (remainingRows < desiredRowsAhead) searchMore(maxItems);
+ if (remainingRows < desiredRowsAhead) searchMore();
}
void PlaylistModel::abortSearch() {
canSearchMore = videoSource->hasMoreVideos();
// update the message item
- emit dataChanged(createIndex(maxItems, 0), createIndex(maxItems, columnCount() - 1));
+ emit dataChanged(createIndex(videos.size(), 0), createIndex(videos.size(), columnCount() - 1));
if (firstSearch && !videos.isEmpty()) handleFirstVideo(videos.at(0));
}
void PlaylistModel::searchError(const QString &message) {
errorMessage = message;
// update the message item
- emit dataChanged(createIndex(maxItems, 0), createIndex(maxItems, columnCount() - 1));
+ emit dataChanged(createIndex(videos.size(), 0), createIndex(videos.size(), columnCount() - 1));
}
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));
+ });
}
}
if (!settings.value("manualplay", false).toBool()) setActiveRow(0);
}
- if (videoSource->metaObject()->className() == QLatin1String("YTSearch")) {
- static const int maxRecentElements = 10;
-
- YTSearch *search = qobject_cast<YTSearch *>(videoSource);
+ auto clazz = videoSource->metaObject()->className();
+ 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://")) {
}
}
-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);
// 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();
}