Logo Search packages:      
Sourcecode: bangarang version File versions  Download package

bool MediaItemModel::dropMimeData ( const QMimeData *  data,
Qt::DropAction  action,
int  row,
int  column,
const QModelIndex &  parent 
)

Handler for data that is dropped onto a view associated with the mdel.

Definition at line 671 of file mediaitemmodel.cpp.

References mediaItemAt(), mediaListChanged(), and MediaItem::url.

{
    if (action == Qt::IgnoreAction)
     return true;

    if (!data->hasFormat("text/uri-list"))
    return false;

    if (column > 0)
     return false;
    
    int beginRow;
    
    if (row != -1) {
        beginRow = row;
    } else if (parent.isValid()) {
        beginRow = parent.row();
    } else {
        beginRow = rowCount(QModelIndex());
    }
    
    QList<QUrl> urls = data->urls();
    
    bool internalMove = false;
    QStringList rowsToMove;
    if (data->text().startsWith("BangarangRow:")) {
        rowsToMove = data->text().split(",", QString::SkipEmptyParts);
        internalMove = true;
    }

    //insert rows into model
    QList<MediaItem> mediaItemsInserted;
    int insertionRow = beginRow;
    for (int i = 0; i < urls.count(); i++) {
        if (internalMove) {
            QString rowEntry = rowsToMove.at(i);
            int rowToMove = rowEntry.remove("BangarangRow:").toInt();
            MediaItem mediaItem = mediaItemAt(rowToMove);
            mediaItemsInserted << mediaItem;
            QList<QStandardItem *> rowItems = rowDataFromMediaItem(mediaItem);
            insertRow(insertionRow, rowItems);
            insertionRow = insertionRow + 1;
        } else {
            QString url = QUrl::fromPercentEncoding(urls.at(i).toString().toUtf8());
            if (Utilities::isAudio(url) || Utilities::isVideo(url)) {
                MediaItem mediaItem = Utilities::mediaItemFromUrl(KUrl(url));
                mediaItemsInserted << mediaItem;
                QList<QStandardItem *> rowItems = rowDataFromMediaItem(mediaItem);
                insertRow(insertionRow, rowItems);
                insertionRow = insertionRow + 1;
            }
        }
    }
    
    //Update cached data to reflect inserted rows
    insertionRow = beginRow;
    for (int i = 0; i < mediaItemsInserted.count(); i++) {
        MediaItem mediaItem = mediaItemsInserted.at(i);
        m_mediaList.insert(insertionRow, mediaItem);
        m_urlList.insert(insertionRow, mediaItem.url);
        insertionRow = insertionRow + 1;
    }
    
    if (internalMove) {
        m_emitChangedAfterDrop = true;
    } else {
        emit mediaListChanged();
    }
    
    return true;
}


Generated by  Doxygen 1.6.0   Back to index