Changeset 26


Ignore:
Timestamp:
12/31/07 17:23:22 (4 years ago)
Author:
sander
Message:

Adding songs using multiple selection now works using the "Add" button.

Location:
gui
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • gui/main_window.cpp

    r25 r26  
    5353    connect(removeFromPlaylistPushButton, SIGNAL(clicked(bool)), this, SLOT(removeFromPlaylist())); 
    5454    connect(libraryTreeView, SIGNAL(activated(const QModelIndex &)), this, SLOT(libraryItemActivated(const QModelIndex &))); 
     55    connect(addToPlaylistPushButton, SIGNAL(clicked(bool)), this, SLOT(addToPlaylistButtonActivated())); 
    5556 
    5657    // Timer 
     
    253254    } 
    254255} 
     256 
     257void MainWindow::addToPlaylistButtonActivated() 
     258{ 
     259    QStringList files; 
     260    QModelIndex mappedIndex; 
     261    MPDStatus::State curState = mpd_status.state; 
     262    MusicLibraryItem *item; 
     263 
     264    // Get selected view indexes 
     265    QModelIndexList selected = libraryTreeView->selectionModel()->selectedIndexes(); 
     266 
     267    if(selected.size() == 0) 
     268        return; 
     269 
     270    for(qint32 i = 0; i < selected.size(); i++) { 
     271        mappedIndex = libraryProxyModel.mapToSource(selected.at(i)); 
     272        item = static_cast<MusicLibraryItem *>(mappedIndex.internalPointer()); 
     273 
     274        switch(item->type()) { 
     275            case MusicLibraryItem::Type_Artist: 
     276                for(qint32 i = 0; i < item->childCount(); i++) { 
     277                    for(qint32 j = 0; j < item->child(i)->childCount(); j++) 
     278                        files.append(item->child(i)->child(j)->file()); 
     279                } 
     280                break; 
     281            case MusicLibraryItem::Type_Album: 
     282                for(qint32 i = 0; i < item->childCount(); i++) 
     283                    files.append(item->child(i)->file()); 
     284                break; 
     285            case MusicLibraryItem::Type_Song: 
     286                if(item->type() == MusicLibraryItem::Type_Song) 
     287                    files.append(item->file()); 
     288                break; 
     289            default: 
     290                break; 
     291        } 
     292    } 
     293 
     294    if(!files.isEmpty()) { 
     295        mpd.add(files); 
     296        if(curState != MPDStatus::State_Playing) 
     297            mpd.startPlayingSong(); 
     298 
     299        libraryTreeView->selectionModel()->clearSelection(); 
     300    } 
     301} 
  • gui/main_window.h

    r25 r26  
    4343        void removeFromPlaylist(); 
    4444        void libraryItemActivated(const QModelIndex &); 
     45        void addToPlaylistButtonActivated(); 
    4546}; 
    4647 
  • gui/main_window.ui

    r21 r26  
    275275            <property name="alternatingRowColors" > 
    276276             <bool>true</bool> 
     277            </property> 
     278            <property name="selectionMode" > 
     279             <enum>QAbstractItemView::ExtendedSelection</enum> 
    277280            </property> 
    278281            <property name="sortingEnabled" > 
Note: See TracChangeset for help on using the changeset viewer.