Changeset 19


Ignore:
Timestamp:
12/31/07 11:58:35 (4 years ago)
Author:
sander
Message:

Adding songs to playlist works

Files:
7 edited

Legend:

Unmodified
Added
Removed
  • gui/main_window.cpp

    r18 r19  
    4242    connect(playlistTableView, SIGNAL(activated(const QModelIndex &)), this, SLOT(playlistItemActivated(const QModelIndex &))); 
    4343    connect(removeFromPlaylistPushButton, SIGNAL(clicked(bool)), this, SLOT(removeFromPlaylist())); 
     44    connect(libraryTreeView, SIGNAL(activated(const QModelIndex &)), this, SLOT(libraryItemActivated(const QModelIndex &))); 
    4445 
    4546    // Timer 
     
    202203    mpd.removeSongs(toBeRemoved); 
    203204} 
     205 
     206void MainWindow::libraryItemActivated(const QModelIndex & index) 
     207{ 
     208    QStringList files; 
     209    MusicLibraryItem *item; 
     210    QModelIndex mappedIndex = libraryProxyModel.mapToSource(index); 
     211    item = static_cast<MusicLibraryItem *>(mappedIndex.internalPointer()); 
     212 
     213    switch(item->type()) { 
     214        case MusicLibraryItem::Type_Artist: 
     215            for(qint32 i = 0; i < item->childCount(); i++) { 
     216                for(qint32 j = 0; j < item->child(i)->childCount(); j++) 
     217                    files.append(item->child(i)->child(j)->file()); 
     218            } 
     219            break; 
     220        case MusicLibraryItem::Type_Album: 
     221            for(qint32 i = 0; i < item->childCount(); i++) 
     222                files.append(item->child(i)->file()); 
     223            break; 
     224        case MusicLibraryItem::Type_Song: 
     225            if(item->type() == MusicLibraryItem::Type_Song) 
     226                files.append(item->file()); 
     227            break; 
     228        default: 
     229            break; 
     230    } 
     231 
     232    if(!files.isEmpty()) { 
     233        mpd.add(files); 
     234        mpd.startPlayingSong(); 
     235    } 
     236} 
  • gui/main_window.h

    r18 r19  
    4141        void playlistItemActivated(const QModelIndex &); 
    4242        void removeFromPlaylist(); 
     43        void libraryItemActivated(const QModelIndex &); 
    4344}; 
    4445 
  • gui/musiclibraryitem.cpp

    r17 r19  
    6464} 
    6565 
     66QString & MusicLibraryItem::file() const 
     67{ 
     68    return *_file; 
     69} 
     70 
    6671void MusicLibraryItem::setFile(const QString &filename) 
    6772{ 
    68     file = new QString(filename); 
     73    _file = new QString(filename); 
    6974} 
    7075 
  • gui/musiclibraryitem.h

    r17 r19  
    2727        void setParent(MusicLibraryItem *parent); 
    2828        MusicLibraryItem::Type type() const; 
     29        QString & file() const; 
    2930        void setFile(const QString &filename); 
    3031        void clearChildren(); 
     
    3435        QList<MusicLibraryItem *> childItems; 
    3536        QString itemData; 
    36         QString *file; 
     37        QString *_file; 
    3738        MusicLibraryItem *parentItem; 
    3839}; 
  • lib/mpdconnection.cpp

    r17 r19  
    185185 */ 
    186186 
     187void MPDConnection::add(const QStringList &files) 
     188{ 
     189    QByteArray send = "command_list_begin\n"; 
     190 
     191    for(qint32 i = 0; i < files.size(); i++) { 
     192        send += "add \""; 
     193        send += files.at(i); 
     194        send += "\"\n"; 
     195    } 
     196 
     197    send += "command_list_end"; 
     198 
     199    sendCommand(send); 
     200 
     201    if(!commandOk()) 
     202        qDebug("Couldn't add song(s) to playlist"); 
     203} 
     204 
    187205void MPDConnection::removeSongs(const QList<qint32> &items) 
    188206{ 
     
    199217    sendCommand(send); 
    200218 
    201     if(!commandOk()) { 
     219    if(!commandOk()) 
    202220        qDebug("Couldn't remove songs from playlist"); 
    203     } 
    204221} 
    205222 
     
    243260    sendCommand("next"); 
    244261 
    245     if(!commandOk()) { 
     262    if(!commandOk()) 
    246263        qDebug("Couldn't go to next track"); 
    247     } 
    248264} 
    249265 
     
    258274    sendCommand(data); 
    259275 
    260     if(!commandOk()) { 
     276    if(!commandOk()) 
    261277        qDebug("Couldn't set pause"); 
    262     } 
    263278} 
    264279 
     
    269284    sendCommand(data); 
    270285 
    271     if(!commandOk()) { 
     286    if(!commandOk()) 
    272287        qDebug("Couldn't start playing song"); 
    273     } 
    274288} 
    275289 
     
    280294    sendCommand(data); 
    281295 
    282     if(!commandOk()) { 
     296    if(!commandOk()) 
    283297        qDebug("Couldn't start playing song id"); 
    284     } 
    285298} 
    286299 
     
    289302    sendCommand("previous"); 
    290303 
    291     if(!commandOk()) { 
     304    if(!commandOk()) 
    292305        qDebug("Couldn't go to previous track"); 
    293     } 
    294306} 
    295307 
     
    304316    sendCommand(data); 
    305317 
    306     if(!commandOk()) { 
     318    if(!commandOk()) 
    307319        qDebug("Couldn't toggle random"); 
    308     } 
    309320} 
    310321 
     
    319330    sendCommand(data); 
    320331 
    321     if(!commandOk()) { 
     332    if(!commandOk()) 
    322333        qDebug("Couldn't toggle repeat"); 
    323     } 
    324334} 
    325335 
     
    348358    sendCommand(data); 
    349359 
    350     if(!commandOk()) { 
     360    if(!commandOk()) 
    351361        qDebug("Couldn't set volume"); 
    352     } 
    353362} 
    354363 
     
    357366    sendCommand("stop"); 
    358367 
    359     if(!commandOk()) { 
     368    if(!commandOk()) 
    360369        qDebug("Couldn't stop playing"); 
    361     } 
    362370} 
    363371 
  • lib/mpdconnection.h

    r17 r19  
    3232 
    3333        // Playlist 
     34        void add(const QStringList &files); 
    3435        void currentSong(); 
    3536        void playListInfo(); 
  • lib/mpdparseutils.cpp

    r17 r19  
    7272        if(tokens.at(0) == "file") { 
    7373            song->file = tokens.at(1); 
     74            song->file = song->file.trimmed(); 
    7475        } else if(tokens.at(0) == "Time") { 
    7576            song->time = tokens.at(1).toUInt(); 
Note: See TracChangeset for help on using the changeset viewer.