X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=src%2FListModel.cpp;h=761e5a4bff6c200c8ed49dba0bfdff35751b4408;hb=99d6f2c2311595b46876fdaafb190bfff9e9cd55;hp=e794d3de3ddf68ef35419f45e27221669ac7fbf0;hpb=9d21bba470b09c5bf9c35bfe0e8163e7dd13a4b2;p=minitube
diff --git a/src/ListModel.cpp b/src/ListModel.cpp
index e794d3d..761e5a4 100755
--- a/src/ListModel.cpp
+++ b/src/ListModel.cpp
@@ -2,6 +2,7 @@
#include "videomimedata.h"
#define MAX_ITEMS 10
+static const QString recentKeywordsKey = "recentKeywords";
ListModel::ListModel(QWidget *parent) : QAbstractListModel(parent) {
youtubeSearch = 0;
@@ -41,6 +42,7 @@ QVariant ListModel::data(const QModelIndex &index, int role) const {
return ItemTypeShowMore;
case Qt::DisplayRole:
case Qt::StatusTipRole:
+ if (!errorMessage.isEmpty()) return errorMessage;
if (searching) return tr("Searching...");
if (canSearchMore) return tr("Show %1 More").arg(MAX_ITEMS);
if (videos.isEmpty()) return tr("No videos");
@@ -48,7 +50,15 @@ QVariant ListModel::data(const QModelIndex &index, int role) const {
case Qt::TextAlignmentRole:
return QVariant(int(Qt::AlignHCenter | Qt::AlignVCenter));
case Qt::ForegroundRole:
- return palette.color(QPalette::Dark);
+ if (!errorMessage.isEmpty())
+ return palette.color(QPalette::ToolTipText);
+ else
+ return palette.color(QPalette::Dark);
+ case Qt::BackgroundColorRole:
+ if (!errorMessage.isEmpty())
+ return palette.color(QPalette::ToolTipBase);
+ else
+ return QVariant();
case Qt::FontRole:
return boldFont;
default:
@@ -68,29 +78,7 @@ QVariant ListModel::data(const QModelIndex &index, int role) const {
case ActiveTrackRole:
return video == m_activeVideo;
case Qt::DisplayRole:
- case Qt::StatusTipRole:
return video->title();
- /*
- case Qt::ToolTipRole:
-
- QString tooltip;
- if (!element.firstChildElement().text().isEmpty()) {
- tooltip.append(QString("").append(element.firstChildElement().text()).append("
"));
- }
- if (!fromDate.isEmpty()) {
- tooltip.append("Pubblicato il ").append(fromDate);
- }
- if (!toDate.isEmpty()) {
- tooltip.append("
Scadenza: ").append(toDate);
- }
- tooltip.append("
Tipo: ").append(typeName)
- .append("
Id: ").appen QFont boldFont;
- boldFont.setBold(true);d(id);
- return tooltip;
- */
-
- // case StreamUrlRole:
- // return video->streamUrl();
}
return QVariant();
@@ -102,8 +90,6 @@ void ListModel::setActiveRow( int row) {
m_activeRow = row;
m_activeVideo = videoAt(row);
- // setStateOfRow( row, Item::Played );
-
int oldactiverow = m_activeRow;
if ( rowExists( oldactiverow ) )
@@ -144,6 +130,7 @@ void ListModel::search(SearchParams *searchParams) {
m_activeVideo = 0;
m_activeRow = -1;
skip = 1;
+ errorMessage.clear();
reset();
// (re)initialize the YouTubeSearch
@@ -151,6 +138,7 @@ void ListModel::search(SearchParams *searchParams) {
youtubeSearch = new YouTubeSearch();
connect(youtubeSearch, SIGNAL(gotVideo(Video*)), this, SLOT(addVideo(Video*)));
connect(youtubeSearch, SIGNAL(finished(int)), this, SLOT(searchFinished(int)));
+ connect(youtubeSearch, SIGNAL(error(QString)), this, SLOT(searchError(QString)));
this->searchParams = searchParams;
searching = true;
@@ -161,6 +149,7 @@ void ListModel::search(SearchParams *searchParams) {
void ListModel::searchMore(int max) {
if (searching) return;
searching = true;
+ errorMessage.clear();
youtubeSearch->search(searchParams, max, skip);
skip += max;
}
@@ -187,6 +176,15 @@ void ListModel::abortSearch() {
void ListModel::searchFinished(int total) {
searching = false;
canSearchMore = total > 0;
+
+ // update the message item
+ emit dataChanged( createIndex( MAX_ITEMS, 0 ), createIndex( MAX_ITEMS, columnCount() - 1 ) );
+}
+
+void ListModel::searchError(QString message) {
+ errorMessage = message;
+ // update the message item
+ emit dataChanged( createIndex( MAX_ITEMS, 0 ), createIndex( MAX_ITEMS, columnCount() - 1 ) );
}
void ListModel::addVideo(Video* video) {
@@ -197,9 +195,20 @@ void ListModel::addVideo(Video* video) {
videos << video;
endInsertRows();
- // autoplay
+ // first result!
if (videos.size() == 1) {
+ // autoplay
setActiveRow(0);
+
+ // save keyword
+ QString query = searchParams->keywords();
+ QSettings settings;
+ QStringList keywords = settings.value(recentKeywordsKey).toStringList();
+ keywords.removeAll(query);
+ keywords.prepend(query);
+ while (keywords.size() > 10)
+ keywords.removeLast();
+ settings.setValue(recentKeywordsKey, keywords);
}
}
@@ -235,6 +244,7 @@ void ListModel::removeIndexes(QModelIndexList &indexes) {
QList