예제 #1
0
QVariant MusicModel::data(const QModelIndex &index, int role) const
{
    if (!index.isValid()) {
        return QVariant();
    }

    MusicLibraryItem *item = static_cast<MusicLibraryItem *>(index.internalPointer());

    switch (role) {
    #ifndef ENABLE_UBUNTU
    case Qt::DecorationRole:
        switch (item->itemType()) {
        case MusicLibraryItem::Type_Root:
            return static_cast<MusicLibraryItemRoot *>(item)->icon();
        case MusicLibraryItem::Type_Artist:
            return static_cast<MusicLibraryItemArtist *>(item)->isComposer()
                        ? Icons::self()->composerIcon
                        : Icons::self()->artistIcon;
        #ifdef ENABLE_ONLINE_SERVICES
        case MusicLibraryItem::Type_Podcast:
            return Icons::self()->podcastIcon;
        #endif
        case MusicLibraryItem::Type_Album:
            return Icons::self()->albumIcon;
        case MusicLibraryItem::Type_Song:
            return Song::Playlist==static_cast<MusicLibraryItemSong *>(item)->song().type ? Icons::self()->playlistIcon : Icons::self()->audioFileIcon;
        default:
            return QVariant();
        }
    #endif
    case Cantata::Role_BriefMainText:
        if (MusicLibraryItem::Type_Album==item->itemType()) {
            return item->data();
        }
    case Cantata::Role_MainText:
    case Qt::DisplayRole:
        if (MusicLibraryItem::Type_Song==item->itemType()) {
            MusicLibraryItemSong *song = static_cast<MusicLibraryItemSong *>(item);
            if (Song::Playlist==song->song().type) {
                return song->song().isCueFile() ? i18n("Cue Sheet") : i18n("Playlist");
            }
            if (MusicLibraryItem::Type_Root==song->parentItem()->itemType()) {
                return song->song().artistSong();
            }
            if (static_cast<MusicLibraryItemAlbum *>(song->parentItem())->isSingleTracks()) {
                return song->song().artistSong();
            }
            #ifdef ENABLE_ONLINE_SERVICES
            if (MusicLibraryItem::Type_Podcast==song->parentItem()->itemType()) {
                return item->data();
            }
            #endif
            return song->song().trackAndTitleStr();
        }
        return item->displayData();
    case Qt::ToolTipRole:
        if (!Settings::self()->infoTooltips()) {
            return QVariant();
        }
        if (MusicLibraryItem::Type_Song==item->itemType()) {
            #ifdef ENABLE_ONLINE_SERVICES
            if (MusicLibraryItem::Type_Podcast==item->parentItem()->itemType()) {
                return parentData(item)+data(index, Qt::DisplayRole).toString()+QLatin1String("<br/>")+
                       Utils::formatTime(static_cast<MusicLibraryItemSong *>(item)->time(), true)+
                       QLatin1String("<br/><small><i>")+static_cast<MusicLibraryItemPodcastEpisode *>(item)->published()+QLatin1String("</i></small>");
            }
            #endif
            return static_cast<MusicLibraryItemSong *>(item)->song().toolTip();
        }

        return parentData(item)+
                (0==item->childCount()
                    ? item->displayData(true)
                    : (item->displayData(true)+"<br/>"+data(index, Cantata::Role_SubText).toString()));
    case Cantata::Role_SubText:
        switch (item->itemType()) {
        case MusicLibraryItem::Type_Root: {
            MusicLibraryItemRoot *collection=static_cast<MusicLibraryItemRoot *>(item);

            if (collection->flat()) {
                return Plurals::tracks(item->childCount());
            }
            return Plurals::artists(item->childCount());
        }
        case MusicLibraryItem::Type_Artist:
            return Plurals::albums(item->childCount());
        case MusicLibraryItem::Type_Podcast:
            return Plurals::episodes(item->childCount());
        case MusicLibraryItem::Type_Song:
            return Utils::formatTime(static_cast<MusicLibraryItemSong *>(item)->time(), true);
        case MusicLibraryItem::Type_Album:
            return Plurals::tracksWithDuration(static_cast<MusicLibraryItemAlbum *>(item)->trackCount(),
                                               Utils::formatTime(static_cast<MusicLibraryItemAlbum *>(item)->totalTime()));
        default: return QVariant();
        }
    case Cantata::Role_ListImage:
        switch (item->itemType()) {
        case MusicLibraryItem::Type_Album:
            return true;
        #ifdef ENABLE_ONLINE_SERVICES
        case MusicLibraryItem::Type_Podcast:
            return true;
        #endif
        default:
            return false;
        }
    #ifdef ENABLE_UBUNTU
    case Cantata::Role_Image:
        switch (item->itemType()) {
        case MusicLibraryItem::Type_Album:
            return static_cast<MusicLibraryItemAlbum *>(item)->cover();
        case MusicLibraryItem::Type_Artist:
            return static_cast<MusicLibraryItemArtist *>(item)->cover();
        default:
            return QString();
        }
    #endif
    case Cantata::Role_CoverSong: {
        QVariant v;
        switch (item->itemType()) {
        case MusicLibraryItem::Type_Album:
            v.setValue<Song>(static_cast<MusicLibraryItemAlbum *>(item)->coverSong());
            break;
        case MusicLibraryItem::Type_Artist:
            v.setValue<Song>(static_cast<MusicLibraryItemArtist *>(item)->coverSong());
            break;
        #ifdef ENABLE_ONLINE_SERVICES
        case MusicLibraryItem::Type_Podcast:
            v.setValue<Song>(static_cast<MusicLibraryItemPodcast *>(item)->coverSong());
            break;
        #endif
        default:
            break;
        }
        return v;
    }
    case Cantata::Role_TitleText:
        if (MusicLibraryItem::Type_Album==item->itemType()) {
            return i18nc("Album by Artist", "%1 by %2", item->data(), item->parentItem()->data());
        }
        return item->data();
    default:
        break;
    }
    return ActionModel::data(index, role);
}
예제 #2
0
QVariant MusicLibraryModel::data(const QModelIndex &index, int role) const
{
    if (!index.isValid()) {
        return QVariant();
    }

    if (Qt::CheckStateRole==role) {
        return static_cast<MusicLibraryItem *>(index.internalPointer())->checkState();
    }

    MusicLibraryItem *item = static_cast<MusicLibraryItem *>(index.internalPointer());

    switch (role) {
    case Qt::DecorationRole:
        switch (item->itemType()) {
        case MusicLibraryItem::Type_Root:
            return static_cast<MusicLibraryItemRoot *>(item)->icon();
        case MusicLibraryItem::Type_Artist:
            return Icons::self()->artistIcon;
        case MusicLibraryItem::Type_Album:
            return Icons::self()->albumIcon(32, true);
        case MusicLibraryItem::Type_Song:
            return Song::Playlist==static_cast<MusicLibraryItemSong *>(item)->song().type ? Icons::self()->playlistListIcon : Icons::self()->audioListIcon;
        default:
            return QVariant();
        }
    case Cantata::Role_BriefMainText:
        if (MusicLibraryItem::Type_Album==item->itemType()) {
            return item->data();
        }
    case Cantata::Role_MainText:
    case Qt::DisplayRole:
        if (MusicLibraryItem::Type_Song==item->itemType()) {
            MusicLibraryItemSong *song = static_cast<MusicLibraryItemSong *>(item);
            if (Song::Playlist==song->song().type) {
                return song->song().isCueFile() ? tr("Cue Sheet") : tr("Playlist");
            }
            if (MusicLibraryItem::Type_Root==song->parentItem()->itemType()) {
                return song->song().trackAndTitleStr();
            }
            return song->song().trackAndTitleStr();
        }
        return item->displayData();
    case Qt::ToolTipRole:
        if (!Settings::self()->infoTooltips()) {
            return QVariant();
        }
        if (MusicLibraryItem::Type_Song==item->itemType()) {
            return static_cast<MusicLibraryItemSong *>(item)->song().toolTip();
        }

        return parentData(item)+
                (0==item->childCount()
                    ? item->displayData(true)
                    : (item->displayData(true)+"<br/>"+data(index, Cantata::Role_SubText).toString()));
    case Cantata::Role_SubText:
        switch (item->itemType()) {
        case MusicLibraryItem::Type_Root: {
            MusicLibraryItemRoot *collection=static_cast<MusicLibraryItemRoot *>(item);

            if (collection->flat()) {
                return tr("%n Track(s)", "", item->childCount());
            }
            return tr("%n Artist(s)", "", item->childCount());
        }
        case MusicLibraryItem::Type_Artist:
            return tr("%n Album(s)", "", item->childCount());
        case MusicLibraryItem::Type_Song:
            return Utils::formatTime(static_cast<MusicLibraryItemSong *>(item)->time(), true);
        case MusicLibraryItem::Type_Album:
            return tr("%n Tracks (%1)", "", static_cast<MusicLibraryItemAlbum *>(item)->trackCount())
                   .arg(Utils::formatTime(static_cast<MusicLibraryItemAlbum *>(item)->totalTime()));
        default: return QVariant();
        }
    case Cantata::Role_ListImage:
        switch (item->itemType()) {
        case MusicLibraryItem::Type_Album:
            return true;
        default:
            return false;
        }
    case Cantata::Role_CoverSong: {
        QVariant v;
        switch (item->itemType()) {
        case MusicLibraryItem::Type_Album:
            v.setValue<Song>(static_cast<MusicLibraryItemAlbum *>(item)->coverSong());
            break;
        case MusicLibraryItem::Type_Artist:
            v.setValue<Song>(static_cast<MusicLibraryItemArtist *>(item)->coverSong());
            break;
        default:
            break;
        }
        return v;
    }
    case Cantata::Role_TitleText:
        if (MusicLibraryItem::Type_Album==item->itemType()) {
            return tr("%1 by %2", "Album by Artist").arg(item->data()).arg(item->parentItem()->data());
        }
        return item->data();
    default:
        break;
    }
    return ActionModel::data(index, role);
}
예제 #3
0
QVariant DevicesModel::data(const QModelIndex &index, int role) const
{
    if (!index.isValid()) {
        return QVariant();
    }

    MusicLibraryItem *item = static_cast<MusicLibraryItem *>(index.internalPointer());

    switch (role) {
    case Qt::DisplayRole:
        if (MusicLibraryItem::Type_Song==item->itemType()) {
            MusicLibraryItemSong *song = static_cast<MusicLibraryItemSong *>(item);
            if (MusicLibraryItem::Type_Root==song->parentItem()->itemType()) {
                return song->song().trackAndTitleStr();
            }
        }
        break;
    #if defined CDDB_FOUND || defined MUSICBRAINZ5_FOUND
    case Cantata::Role_Image:
        if (MusicLibraryItem::Type_Root==item->itemType()) {
            Device *dev=static_cast<Device *>(item);
            if (Device::AudioCd==dev->devType()) {
                return static_cast<AudioCdDevice *>(dev)->coverPix();
            }
        }
        break;
    #endif
    case Cantata::Role_SubText:
        if (MusicLibraryItem::Type_Root==item->itemType()) {
            Device *dev=static_cast<Device *>(item);
            if (!dev->statusMessage().isEmpty()) {
                return dev->statusMessage();
            }
            if (!dev->isConnected()) {
                QString sub=dev->subText();
                return i18n("Not Connected")+(sub.isEmpty() ? QString() : (QString(" - ")+sub));
            }
            if (Device::AudioCd==dev->devType()) {
                return dev->subText();
            }
        }
        break;
    case Cantata::Role_Capacity:
        if (MusicLibraryItem::Type_Root==item->itemType()) {
            return static_cast<Device *>(item)->usedCapacity();
        }
        return QVariant();
    case Cantata::Role_CapacityText:
        if (MusicLibraryItem::Type_Root==item->itemType()) {
            return static_cast<Device *>(item)->capacityString();
        }
        return QVariant();
    case Cantata::Role_Actions: {
        QVariant v;
        if (MusicLibraryItem::Type_Root==item->itemType()) {
            QList<Action *> actions;
            if (Device::AudioCd!=static_cast<Device *>(item)->devType()) {
                actions << configureAction;
            } else if (HttpServer::self()->isAlive()) {
                actions << StdActions::self()->replacePlayQueueAction;
            }
            actions << refreshAction;
            if (static_cast<Device *>(item)->supportsDisconnect()) {
                actions << (static_cast<Device *>(item)->isConnected() ? disconnectAction : connectAction);
            }
            #if defined CDDB_FOUND || defined MUSICBRAINZ5_FOUND
            if (Device::AudioCd==static_cast<Device *>(item)->devType()) {
                actions << editAction;
            }
            #endif
            v.setValue<QList<Action *> >(actions);
        } else if (root(item)->canPlaySongs() && HttpServer::self()->isAlive()) {
            v.setValue<QList<Action *> >(QList<Action *>() << StdActions::self()->replacePlayQueueAction << StdActions::self()->appendToPlayQueueAction);
        }
        return v;
    }
    case Cantata::Role_ListImage:
        return MusicLibraryItem::Type_Album==item->itemType();
    default:
        break;
    }
    return MultiMusicModel::data(index, role);
}