]> git.sur5r.net Git - minitube/blobdiff - src/ListModel.cpp
Imported Upstream version 1.3
[minitube] / src / ListModel.cpp
index e7592ecbf096e3e17369554b3a5af7ba7bdfa7dc..1c146eec728e1fbf0eedf47397f0c167c3586b78 100755 (executable)
@@ -78,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("<b>").append(element.firstChildElement().text()).append("</b><br/>"));
-            }
-            if (!fromDate.isEmpty()) {
-                tooltip.append("<i>Pubblicato il</i> ").append(fromDate);
-            }
-            if (!toDate.isEmpty()) {
-                tooltip.append("<br/><i>Scadenza</i>: ").append(toDate);
-            }
-            tooltip.append("<br/><i>Tipo</i>: ").append(typeName)
-                .append("<br/><i>Id</i>: ").appen    QFont boldFont;
-    boldFont.setBold(true);d(id);
-            return tooltip;
-            */
-        
-        // case StreamUrlRole:
-        // return video->streamUrl();
     }
     
     return QVariant();
@@ -112,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 ) )
@@ -226,6 +202,10 @@ void ListModel::addVideo(Video* video) {
 
         // save keyword
         QString query = searchParams->keywords();
+        if (query.startsWith("http://")) {
+            // Save the video title
+            query += "|" + videos.first()->title();
+        }
         QSettings settings;
         QStringList keywords = settings.value(recentKeywordsKey).toStringList();
         keywords.removeAll(query);
@@ -268,6 +248,7 @@ void ListModel::removeIndexes(QModelIndexList &indexes) {
     QList<Video*> originalList(videos);
     QList<Video*> delitems;
     foreach (QModelIndex index, indexes) {
+        if (index.row() >= originalList.size()) continue;
         Video* video = originalList.at(index.row());
         int idx = videos.indexOf(video);
         if (idx != -1) {
@@ -377,20 +358,21 @@ QModelIndex ListModel::indexForVideo(Video* video) {
 }
 
 void ListModel::move(QModelIndexList &indexes, bool up) {
-
     QList<Video*> movedVideos;
 
     foreach (QModelIndex index, indexes) {
         int row = index.row();
+        if (row >= videos.size()) continue;
         // qDebug() << "index row" << row;
         Video *video = videoAt(row);
         movedVideos << video;
     }
 
-    int counter = 1;
+    int end=up ? -1 : rowCount()-1, mod=up ? -1 : 1;
     foreach (Video *video, movedVideos) {
 
         int row = rowForVideo(video);
+        if (row+mod==end) { end=row; continue; }
         // qDebug() << "video row" << row;
         removeRows(row, 1, QModelIndex());
 
@@ -401,7 +383,6 @@ void ListModel::move(QModelIndexList &indexes, bool up) {
         videos.insert(row, video);
         endInsertRows();
 
-        counter++;
     }
 
     emit needSelectionFor(movedVideos);