File indexing completed on 2025-01-05 04:26:38
0001 /**************************************************************************************** 0002 * Copyright (c) 2009 Nikolaj Hald Nielsen <nhn@kde.org> * 0003 * * 0004 * This program is free software; you can redistribute it and/or modify it under * 0005 * the terms of the GNU General Public License as published by the Free Software * 0006 * Foundation; either version 2 of the License, or (at your option) any later * 0007 * version. * 0008 * * 0009 * This program is distributed in the hope that it will be useful, but WITHOUT ANY * 0010 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * 0011 * PARTICULAR PURPOSE. See the GNU General Public License for more details. * 0012 * * 0013 * You should have received a copy of the GNU General Public License along with * 0014 * this program. If not, see <http://www.gnu.org/licenses/>. * 0015 ****************************************************************************************/ 0016 0017 #include "SourceSelectionPopup.h" 0018 0019 #include <QIcon> 0020 #include <KLocalizedString> 0021 0022 #include <QPushButton> 0023 #include <QLabel> 0024 #include <QListWidget> 0025 #include <QListWidgetItem> 0026 #include <QVBoxLayout> 0027 0028 namespace Playlist { 0029 0030 SourceSelectionPopup::SourceSelectionPopup( QWidget * parent, Capabilities::MultiSourceCapability * msc ) 0031 : QDialog( parent ) 0032 , m_msc( msc ) 0033 { 0034 QLabel * label = new QLabel( i18n( "The following sources are available for this track:" ) ); 0035 label->setWordWrap( true ); 0036 0037 m_listWidget = new QListWidget(); 0038 0039 QPushButton * okButton = new QPushButton( i18n( "OK" ) ); 0040 connect( okButton, &QPushButton::clicked, this, &SourceSelectionPopup::accept ); 0041 0042 connect( m_listWidget, &QListWidget::itemDoubleClicked, this, &SourceSelectionPopup::sourceSelected ); 0043 0044 QVBoxLayout *layout = new QVBoxLayout; 0045 layout->addWidget( label ); 0046 layout->addWidget( m_listWidget ); 0047 layout->addWidget( okButton ); 0048 setLayout( layout ); 0049 0050 int i = 0; 0051 foreach( const QString &source, m_msc->sources() ) 0052 { 0053 if ( i == m_msc->current() ) 0054 new QListWidgetItem( QIcon::fromTheme( QStringLiteral("arrow-right") ), source, m_listWidget ) ; 0055 else 0056 new QListWidgetItem( source, m_listWidget ); 0057 0058 i++; 0059 } 0060 } 0061 0062 SourceSelectionPopup::~SourceSelectionPopup() 0063 { 0064 delete m_msc; 0065 } 0066 0067 void SourceSelectionPopup::sourceSelected( QListWidgetItem * item ) 0068 { 0069 0070 //get row of item: 0071 0072 int currentSource = m_listWidget->row( item ); 0073 0074 m_msc->setSource( currentSource ); 0075 0076 m_listWidget->clear(); 0077 0078 int i = 0; 0079 foreach( const QString &source, m_msc->sources() ) 0080 { 0081 if ( i == m_msc->current() ) 0082 new QListWidgetItem( QIcon::fromTheme( QStringLiteral("arrow-right") ), source, m_listWidget ) ; 0083 else 0084 new QListWidgetItem( source, m_listWidget ); 0085 0086 i++; 0087 } 0088 0089 } 0090 0091 0092 } 0093 0094 0095