X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=src%2Fplaylistmodel.cpp;h=f2e0e5f32d0f5c9a10c4c6e84e3dfa85e7c311e8;hb=2e524d4ed49280113efb6318b32d7f8931c5ccbd;hp=a3cad088bcee9646d686264c1ab6bdd25e1cd457;hpb=5ecc9c04fb173c5693bcded5191d29816304d12c;p=minitube
diff --git a/src/playlistmodel.cpp b/src/playlistmodel.cpp
index a3cad08..f2e0e5f 100644
--- a/src/playlistmodel.cpp
+++ b/src/playlistmodel.cpp
@@ -19,83 +19,78 @@ 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 = 10;
-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;
- skip = 1;
+ startIndex = 1;
max = 0;
hoveredRow = -1;
authorHovered = false;
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 (canSearchMore) return tr("Show %1 More").arg(maxItems);
- if (videos.isEmpty()) return tr("No videos");
- else return tr("No more videos");
+ 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");
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,180 +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();
- m_activeVideo = 0;
+
+ qDeleteAll(videos);
+ videos.clear();
+
+ qDeleteAll(deletedVideos);
+ deletedVideos.clear();
+
+ m_activeVideo = nullptr;
m_activeRow = -1;
- skip = 1;
+ startIndex = 1;
endResetModel();
this->videoSource = videoSource;
- connect(videoSource, SIGNAL(gotVideos(QList