Пример #1
0
void PlaylistView::selectSongsByRegExp()
{
    // We can't use selectItemsByRegExp here, because it matches ListModelItemData::text,
    // but for PlaylistModel its value doesn't correspond to what actually displyed, as
    // it uses SongDisplayFormatParser for this job.
    auto resultCallback = [this](const std::string& pattern, LineEdit::Result result)
    {
        if (result == LineEdit::Result::Accepted) {
            GRegex *regex = g_regex_new(pattern.c_str(), G_REGEX_OPTIMIZE,
                                        (GRegexMatchFlags)0, nullptr);
            if (!regex)
                return;

            PlaylistModel *plsModel = static_cast<PlaylistModel*>(model());
            PlaylistItemDelegate *delegate = static_cast<PlaylistItemDelegate*>(itemDelegate());

            selectItems([plsModel, delegate, regex](int item){
                return delegate->matchFormattedString(plsModel->song(item), regex);
            });
            g_regex_unref(regex);
            StatusArea::showMessage("%d items selected", selectedItems().size());
        }
    };
    StatusArea::askQuestion("Select items: ", resultCallback, ".*");
}
Пример #2
0
void PlaylistView::unselectSongsByRegExp()
{
    // The same story here...
    auto resultCallback = [this](const std::string& pattern, LineEdit::Result result)
    {
        if (result == LineEdit::Result::Accepted) {
            GRegex *regex = g_regex_new(pattern.c_str(), G_REGEX_OPTIMIZE,
                                        (GRegexMatchFlags)0, nullptr);
            if (!regex)
                return;

            PlaylistModel *plsModel = static_cast<PlaylistModel*>(model());
            PlaylistItemDelegate *delegate = static_cast<PlaylistItemDelegate*>(itemDelegate());

            unselectItems([plsModel, delegate, regex](int item){
                return delegate->matchFormattedString(plsModel->song(item), regex);
            });
            g_regex_unref(regex);
            StatusArea::showMessage("%d items selected", selectedItems().size());
        }
    };
    StatusArea::askQuestion("Unselect items: ", resultCallback, ".*");
}
Пример #3
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);
    }
}