Example #1
0
void PlaylistView::addFile(const std::string& path)
{
    PlaylistModel *plsModel = static_cast<PlaylistModel*>(model());

    const std::string::size_type slashPos = path.rfind('/');
    const std::string fileName = slashPos != std::string::npos
                                 ? path.substr(slashPos + 1)
                                 : path;

    const Utils::FileType fileType = Utils::getFileType(path);
    switch (fileType) {
        case Utils::FileType::Media:
            m_xmmsClient->playlistAddUrl(plsModel->playlist(),
                                         std::string("file://").append(path));
            StatusArea::showMessage("Adding \"%s\" file to \"%s\" playlist",
                                    fileName, plsModel->playlist());
            break;

        case Utils::FileType::Playlist:
            m_xmmsClient->playlistAddPlaylistFile(plsModel->playlist(),
                                                  std::string("file://").append(path));
            StatusArea::showMessage("Adding \"%s\" playlist to \"%s\" playlist",
                                    fileName, plsModel->playlist());
            break;

        case Utils::FileType::Unknown:
            StatusArea::showMessage("Unknown file type!");
            break;
    }
}
Example #2
0
void PlaylistView::addUrl(const std::string& url)
{
    PlaylistModel *plsModel = static_cast<PlaylistModel*>(model());
    m_xmmsClient->playlistAddUrl(plsModel->playlist(), url);

    // FIXME: Url may be too long to display
    StatusArea::showMessage("Adding \"%s\" to \"%s\" playlist", url, plsModel->playlist());
}
Example #3
0
playlist_ptr
ViewManager::playlistForPage( ViewPage* page ) const
{
    playlist_ptr p;

    PlaylistViewPage* fv = dynamic_cast< PlaylistViewPage* >( page );
    if ( fv && fv->view()->trackView()->model() )
    {
        PlaylistModel* m = dynamic_cast< PlaylistModel* >( fv->view()->trackView()->model() );
        if ( m && m->playlist() )
        {
            p = m->playlist();
        }
    }
    else if ( dynamic_cast< DynamicWidget* >( page ) )
        p = dynamic_cast< DynamicWidget* >( page )->playlist();

    return p;
}
Example #4
0
void PlaylistView::removeSelectedSongs()
{
    PlaylistModel *plsModel = static_cast<PlaylistModel*>(model());
    if (plsModel->itemsCount() && !isCurrentItemHidden()) {
        //   Actually we don't have to make copy of selectedItems, since removeEntry
        // doesn't modify it immediately, but this is not obvious and may lead to
        // problems in the future.
        const std::vector<int> selectedSongs = selectedItems();
        if (!selectedSongs.empty()) {
            assert(std::is_sorted(selectedSongs.begin(), selectedSongs.end()));
            std::for_each(selectedSongs.rbegin(), selectedSongs.rend(), [&](int item){
                m_xmmsClient->playlistRemoveEntry(plsModel->playlist(), item);
            });
        } else {
            m_xmmsClient->playlistRemoveEntry(plsModel->playlist(), currentItem());
        }
        showCurrentItem();
    }
}
Example #5
0
void PlaylistView::moveSelectedSongs()
{
    PlaylistModel *plsModel = static_cast<PlaylistModel*>(model());
    const std::vector<int> selectedSongs  = selectedItems();
    assert(std::is_sorted(selectedSongs.begin(), selectedSongs.end()));
    
    if (isCurrentItemHidden() || selectedSongs.empty())
        return;
    
    const int moveTo = currentItem();
    auto it = std::lower_bound(selectedSongs.begin(), selectedSongs.end(), moveTo);
    
    int to = moveTo;
    for (size_t i = it - selectedSongs.begin(); i < selectedSongs.size(); ++i, ++to) {
        m_xmmsClient->playlistMoveEntry(plsModel->playlist(), selectedSongs[i], to);
    }
    
    to = it == selectedSongs.end() ? moveTo : moveTo - 1;
    for (ptrdiff_t i = it - selectedSongs.begin() - 1; i >= 0; --i, --to) {
        m_xmmsClient->playlistMoveEntry(plsModel->playlist(), selectedSongs[i], to);
    }
}
Example #6
0
void PlaylistView::addPath(const std::string& path)
{
    // TODO: Introduce FileInfo class instead of using glib functions,
    // maybe simple stat call wrapper
    if (!g_file_test(path.c_str(), G_FILE_TEST_EXISTS)) {
        StatusArea::showMessage("File doesn't exist!");
        return;
    }

    if (g_file_test(path.c_str(), G_FILE_TEST_IS_REGULAR)) {
        addFile(path);
    } else if (g_file_test(path.c_str(), G_FILE_TEST_IS_DIR)) {
        PlaylistModel *plsModel = static_cast<PlaylistModel*>(model());
        m_xmmsClient->playlistAddRecursive(plsModel->playlist(),
                                           std::string("file://").append(path));
        // FIXME: Path may be too long to display
        StatusArea::showMessage("Adding \"%s\" directory to \"%s\" playlist",
                                path, plsModel->playlist());
    } else {
        StatusArea::showMessage("File is neither a directory nor regular file!");
    }
}
Example #7
0
void PlaylistView::keyPressedEvent(const KeyEvent& keyEvent)
{
    PlaylistModel *plsModel = static_cast<PlaylistModel*>(model());

    switch (keyEvent.key()) {
        case Hotkeys::PlaylistView::RemoveEntry:
            removeSelectedSongs();
            break;

        case Hotkeys::PlaylistView::ClearPlaylist:
            m_xmmsClient->playlistClear(plsModel->playlist());
            break;

        case Hotkeys::PlaylistView::ShufflePlaylist:
            m_xmmsClient->playlistShuffle(plsModel->playlist());
            break;

        case Hotkeys::PlaylistView::GoToCurrentlyPlayingSong:
            setCurrentItem(plsModel->currentSongItem());
            break;

        case Hotkeys::PlaylistView::MoveSelectedSongs:
            moveSelectedSongs();
            break;
            
        case Hotkeys::PlaylistView::AddFileOrDirectory:
        {
            auto resultCallback = [this](const std::string& path, LineEdit::Result result)
            {
                if (result == LineEdit::Result::Accepted)
                    addPath(path);
            };
            StatusArea::askQuestion("Add path: ", resultCallback);
            break;
        }

        case Hotkeys::PlaylistView::AddUrl:
        {
            auto resultCallback = [this](const std::string& url, LineEdit::Result result)
            {
                if (result == LineEdit::Result::Accepted)
                    addUrl(url);
            };
            StatusArea::askQuestion("Add url: ", resultCallback);
            break;
        }
        
        case Hotkeys::PlaylistView::ShowSongInfo:
            if (plsModel->itemsCount() && !isCurrentItemHidden()) {
                int id = plsModel->song(currentItem()).id();
                if (id > 0)
                    showSongInfo(id);
            }
            break;
            
        case '+': // Select be regexp
            selectSongsByRegExp();
            break;

        case '\\': // Unselect be regexp
            unselectSongsByRegExp();
            break;

        default: ListViewAppIntegrated::keyPressedEvent(keyEvent);
    }
}
Example #8
0
void PlaylistView::onItemEntered(int item)
{
    PlaylistModel *plsModel = static_cast<PlaylistModel*>(model());
    m_xmmsClient->playlistPlayItem(plsModel->playlist(), item);
}