File indexing completed on 2024-05-19 04:50:18
0001 /**************************************************************************************** 0002 * Copyright (c) 2006,2007 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 "MagnatuneRedownloadDialog.h" 0018 0019 #include "core/support/Debug.h" 0020 0021 #include <QHeaderView> 0022 0023 MagnatuneRedownloadDialog::MagnatuneRedownloadDialog(QWidget* parent, const char* name, bool modal, Qt::WindowFlags fl) 0024 : QDialog(parent, fl) 0025 { 0026 setObjectName( name ); 0027 setModal( modal ); 0028 setupUi(this); 0029 redownloadButton->setEnabled ( false ); 0030 0031 redownloadListView->header()->setStretchLastSection( true ); 0032 redownloadListView->setRootIsDecorated( false ); 0033 connect( redownloadListView, &QTreeWidget::itemSelectionChanged, this, &MagnatuneRedownloadDialog::selectionChanged ); 0034 } 0035 0036 MagnatuneRedownloadDialog::~MagnatuneRedownloadDialog() 0037 { 0038 } 0039 0040 void MagnatuneRedownloadDialog::setRedownloadItems( const QStringList &items ) 0041 { 0042 0043 QStringListIterator it(items); 0044 while ( it.hasNext() ) { 0045 0046 const QString currentItem = it.next(); 0047 debug() << "Adding item to redownload dialog: " << currentItem; 0048 redownloadListView->addTopLevelItem( new QTreeWidgetItem( QStringList(currentItem) ) ); 0049 } 0050 0051 debug() << "Nothing more to add..."; 0052 0053 } 0054 0055 void MagnatuneRedownloadDialog::setRedownloadItems( const QList<MagnatuneDownloadInfo> &previousPurchases ) 0056 { 0057 m_infoMap.clear(); 0058 0059 foreach( const MagnatuneDownloadInfo &prevPurchase, previousPurchases ) 0060 { 0061 const QString albumText = prevPurchase.artistName() + " - " + prevPurchase.albumName(); 0062 QTreeWidgetItem *item = new QTreeWidgetItem( QStringList( albumText ) ); 0063 m_infoMap.insert( item, prevPurchase ); 0064 redownloadListView->addTopLevelItem( item ); 0065 } 0066 0067 0068 } 0069 0070 void MagnatuneRedownloadDialog::slotRedownload( ) 0071 { 0072 QTreeWidgetItem * current = redownloadListView->currentItem(); 0073 if ( m_infoMap.keys().contains( current ) ) 0074 { 0075 Q_EMIT( redownload( m_infoMap.value( current ) ) ); 0076 } 0077 0078 //Q_EMIT ( redownload( redownloadListView->currentItem()->text( 0 ) ) ); 0079 0080 hide(); 0081 } 0082 0083 void MagnatuneRedownloadDialog::reject( ) 0084 { 0085 hide(); 0086 Q_EMIT(cancelled()); 0087 } 0088 0089 void MagnatuneRedownloadDialog::selectionChanged( ) 0090 { 0091 if (redownloadListView->currentItem()) { 0092 redownloadButton->setEnabled ( true ); 0093 } else { 0094 redownloadButton->setEnabled ( false ); 0095 } 0096 } 0097 0098 /*$SPECIALIZATION$*/ 0099 0100 0101