File indexing completed on 2024-05-05 04:47:20
0001 /**************************************************************************************** 0002 * Copyright (c) 2009 Téo Mrnjavac <teo@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 "OcsPersonListWidget.h" 0018 0019 #include "core/support/Debug.h" 0020 0021 #include <QScrollArea> 0022 0023 0024 OcsPersonListWidget::OcsPersonListWidget( const QList< KAboutPerson > &persons, 0025 const OcsData::OcsPersonList *ocsPersons, 0026 OcsPersonItem::PersonStatus status, 0027 QWidget *parent ) 0028 : QWidget( parent ) 0029 , m_status( status ) 0030 , m_fetchCount( 0 ) 0031 { 0032 //Set up the layouts... 0033 QHBoxLayout *scrollLayout = new QHBoxLayout( this ); 0034 scrollLayout->setMargin( 1 ); 0035 setLayout( scrollLayout ); 0036 QScrollArea *personsScrollArea = new QScrollArea( this ); 0037 scrollLayout->addWidget( personsScrollArea ); 0038 personsScrollArea->setFrameStyle( QFrame::NoFrame ); 0039 m_personsArea = new QWidget( personsScrollArea ); 0040 m_areaLayout = new QVBoxLayout( m_personsArea ); 0041 m_areaLayout->setMargin( 0 ); 0042 m_personsArea->setLayout( m_areaLayout ); 0043 m_personsArea->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum ); 0044 0045 0046 personsScrollArea->setWidgetResizable( true ); 0047 personsScrollArea->setWidget( m_personsArea ); 0048 m_personsArea->show(); 0049 0050 //Populate the scroll area... 0051 for( int i = 0; i < persons.count(); ++i ) //TODO: really ugly and inefficient, fix this 0052 { 0053 OcsPersonItem *item = new OcsPersonItem( persons.at( i ), ocsPersons->at( i ).first, status, m_personsArea ); 0054 m_areaLayout->addWidget( item ); 0055 connect( item, &OcsPersonItem::ocsFetchStarted, this, &OcsPersonListWidget::onOcsFetchStarted ); 0056 connect( item, &OcsPersonItem::ocsFetchResult, this, &OcsPersonListWidget::onOcsDataFetched ); 0057 } 0058 } 0059 0060 void 0061 OcsPersonListWidget::switchToOcs( Attica::Provider &provider ) 0062 { 0063 for( int i = 0; i < m_areaLayout->count(); ++i ) 0064 { 0065 OcsPersonItem *item = qobject_cast< OcsPersonItem * >( m_areaLayout->itemAt( i )->widget() ); 0066 item->switchToOcs( provider ); 0067 } 0068 } 0069 0070 void 0071 OcsPersonListWidget::onOcsFetchStarted() //SLOT 0072 { 0073 m_fetchCount++; 0074 } 0075 0076 void 0077 OcsPersonListWidget::onOcsDataFetched( int err ) //SLOT 0078 { 0079 m_fetchCount--; 0080 debug()<<m_status<<"Fetch count is"<< m_fetchCount; 0081 if( err != 0 ) 0082 warning() << "OCS data download failed with error"<<err; 0083 if( m_fetchCount == 0 ) 0084 { 0085 debug()<<m_status<<"FETCH COMPLETE"; 0086 Q_EMIT switchedToOcs(); 0087 } 0088 }