X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=src%2Fplaylistmodel.cpp;h=f2e0e5f32d0f5c9a10c4c6e84e3dfa85e7c311e8;hb=9ff1806f2db97d617aa96185b7bf17f77bbacbcb;hp=eb8a2ddb06ffc808244ee45887bb8452894ebdcc;hpb=fd2de342562fc7565ee7437636eb10c4456e0368;p=minitube
diff --git a/src/playlistmodel.cpp b/src/playlistmodel.cpp
index eb8a2dd..f2e0e5f 100644
--- a/src/playlistmodel.cpp
+++ b/src/playlistmodel.cpp
@@ -19,23 +19,26 @@ along with Minitube. If not, see .
$END_LICENSE */
#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 "video.h"
-#include "searchparams.h"
-#include "mediaview.h"
-static const int maxItems = 50;
-static const QString recentKeywordsKey = "recentKeywords";
-static const QString recentChannelsKey = "recentChannels";
+#include "searchvideosource.h"
+
+namespace {
+const QString recentKeywordsKey = "recentKeywords";
+const QString recentChannelsKey = "recentChannels";
+} // namespace
PlaylistModel::PlaylistModel(QWidget *parent) : QAbstractListModel(parent) {
- videoSource = 0;
+ videoSource = nullptr;
searching = false;
canSearchMore = true;
firstSearch = false;
- m_activeVideo = 0;
+ m_activeVideo = nullptr;
m_activeRow = -1;
startIndex = 1;
max = 0;
@@ -44,58 +47,50 @@ PlaylistModel::PlaylistModel(QWidget *parent) : QAbstractListModel(parent) {
authorPressed = false;
}
-int PlaylistModel::rowCount(const QModelIndex &/*parent*/) const {
+int PlaylistModel::rowCount(const QModelIndex & /*parent*/) const {
int count = videos.size();
-
+
// add the message item
- if (videos.isEmpty() || !searching)
- count++;
-
+ if (videos.isEmpty() || !searching) count++;
+
return count;
}
QVariant PlaylistModel::data(const QModelIndex &index, int role) const {
-
int row = index.row();
-
+
if (row == videos.size()) {
-
QPalette palette;
- QFont boldFont;
- boldFont.setBold(true);
-
+
switch (role) {
case ItemTypeRole:
return ItemTypeShowMore;
case Qt::DisplayRole:
if (!errorMessage.isEmpty()) return errorMessage;
- if (searching) return tr("Searching...");
+ if (searching) return QString(); // tr("Searching...");
if (canSearchMore) return tr("Show %1 More").arg("").simplified();
- if (videos.isEmpty()) return tr("No videos");
- else return tr("No more videos");
+ if (videos.isEmpty())
+ return tr("No videos");
+ else
+ return tr("No more videos");
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
return QVariant();
- case Qt::FontRole:
- return boldFont;
default:
return QVariant();
}
-
+
} else if (row < 0 || row >= videos.size())
return QVariant();
-
+
Video *video = videos.at(row);
-
+
switch (role) {
case ItemTypeRole:
return ItemTypeVideo;
@@ -104,183 +99,178 @@ QVariant PlaylistModel::data(const QModelIndex &index, int role) const {
case ActiveTrackRole:
return video == m_activeVideo;
case Qt::DisplayRole:
- return video->title();
+ return video->getTitle();
case HoveredItemRole:
return hoveredRow == index.row();
case AuthorHoveredRole:
return authorHovered;
case AuthorPressedRole:
return authorPressed;
+ /*
case Qt::StatusTipRole:
return video->description();
+ */
}
-
+
return QVariant();
}
void PlaylistModel::setActiveRow(int row, bool notify) {
- if ( rowExists( row ) ) {
-
+ if (rowExists(row)) {
m_activeRow = row;
+ Video *previousVideo = m_activeVideo;
m_activeVideo = videoAt(row);
-
+
int oldactiverow = m_activeRow;
-
- if ( rowExists( oldactiverow ) )
- emit dataChanged( createIndex( oldactiverow, 0 ), createIndex( oldactiverow, columnCount() - 1 ) );
-
- emit dataChanged( createIndex( m_activeRow, 0 ), createIndex( m_activeRow, columnCount() - 1 ) );
- if (notify) emit activeRowChanged(row);
-
+
+ if (rowExists(oldactiverow))
+ emit dataChanged(createIndex(oldactiverow, 0),
+ createIndex(oldactiverow, columnCount() - 1));
+
+ emit dataChanged(createIndex(m_activeRow, 0), createIndex(m_activeRow, columnCount() - 1));
+ if (notify) emit activeVideoChanged(m_activeVideo, previousVideo);
+
} else {
m_activeRow = -1;
- m_activeVideo = 0;
+ m_activeVideo = nullptr;
}
-
}
int PlaylistModel::nextRow() const {
int nextRow = m_activeRow + 1;
- if (rowExists(nextRow))
- return nextRow;
+ if (rowExists(nextRow)) return nextRow;
return -1;
}
int PlaylistModel::previousRow() const {
int prevRow = m_activeRow - 1;
- if (rowExists(prevRow))
- return prevRow;
+ if (rowExists(prevRow)) return prevRow;
return -1;
}
-Video* PlaylistModel::videoAt( int row ) const {
- if ( rowExists( row ) )
- return videos.at( row );
- return 0;
+Video *PlaylistModel::videoAt(int row) const {
+ if (rowExists(row)) return videos.at(row);
+ return nullptr;
}
-Video* PlaylistModel::activeVideo() const {
+Video *PlaylistModel::activeVideo() const {
return m_activeVideo;
}
void PlaylistModel::setVideoSource(VideoSource *videoSource) {
beginResetModel();
- while (!videos.isEmpty()) delete videos.takeFirst();
+
+ qDeleteAll(videos);
videos.clear();
- m_activeVideo = 0;
+
+ qDeleteAll(deletedVideos);
+ deletedVideos.clear();
+
+ m_activeVideo = nullptr;
m_activeRow = -1;
startIndex = 1;
endResetModel();
this->videoSource = videoSource;
- connect(videoSource, SIGNAL(gotVideos(QList