1 /****************************************************************************************
2 * Copyright (c) 2009 Nikolaj Hald Nielsen <nhn@kde.org> *
3 * *
4 * This program is free software; you can redistribute it and/or modify it under *
5 * the terms of the GNU General Public License as published by the Free Software *
6 * Foundation; either version 2 of the License, or (at your option) any later *
7 * version. *
8 * *
9 * This program is distributed in the hope that it will be useful, but WITHOUT ANY *
10 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A *
11 * PARTICULAR PURPOSE. See the GNU General Public License for more details. *
12 * *
13 * You should have received a copy of the GNU General Public License along with *
14 * this program. If not, see <http://www.gnu.org/licenses/>. *
15 ****************************************************************************************/
16
17 #include "SourceSelectionPopup.h"
18
19 #include <QIcon>
20 #include <KLocalizedString>
21
22 #include <QPushButton>
23 #include <QLabel>
24 #include <QListWidget>
25 #include <QListWidgetItem>
26 #include <QVBoxLayout>
27
28 namespace Playlist {
29
SourceSelectionPopup(QWidget * parent,Capabilities::MultiSourceCapability * msc)30 SourceSelectionPopup::SourceSelectionPopup( QWidget * parent, Capabilities::MultiSourceCapability * msc )
31 : QDialog( parent )
32 , m_msc( msc )
33 {
34 QLabel * label = new QLabel( i18n( "The following sources are available for this track:" ) );
35 label->setWordWrap( true );
36
37 m_listWidget = new QListWidget();
38
39 QPushButton * okButton = new QPushButton( i18n( "OK" ) );
40 connect( okButton, &QPushButton::clicked, this, &SourceSelectionPopup::accept );
41
42 connect( m_listWidget, &QListWidget::itemDoubleClicked, this, &SourceSelectionPopup::sourceSelected );
43
44 QVBoxLayout *layout = new QVBoxLayout;
45 layout->addWidget( label );
46 layout->addWidget( m_listWidget );
47 layout->addWidget( okButton );
48 setLayout( layout );
49
50 int i = 0;
51 foreach( const QString &source, m_msc->sources() )
52 {
53 if ( i == m_msc->current() )
54 new QListWidgetItem( QIcon::fromTheme( QStringLiteral("arrow-right") ), source, m_listWidget ) ;
55 else
56 new QListWidgetItem( source, m_listWidget );
57
58 i++;
59 }
60 }
61
~SourceSelectionPopup()62 SourceSelectionPopup::~SourceSelectionPopup()
63 {
64 delete m_msc;
65 }
66
sourceSelected(QListWidgetItem * item)67 void SourceSelectionPopup::sourceSelected( QListWidgetItem * item )
68 {
69
70 //get row of item:
71
72 int currentSource = m_listWidget->row( item );
73
74 m_msc->setSource( currentSource );
75
76 m_listWidget->clear();
77
78 int i = 0;
79 foreach( const QString &source, m_msc->sources() )
80 {
81 if ( i == m_msc->current() )
82 new QListWidgetItem( QIcon::fromTheme( QStringLiteral("arrow-right") ), source, m_listWidget ) ;
83 else
84 new QListWidgetItem( source, m_listWidget );
85
86 i++;
87 }
88
89 }
90
91
92 }
93
94
95
96