// // This file is part of the Marble Desktop Globe. // // This program is free software licensed under the GNU LGPL. You can // find a copy of this license in LICENSE.txt in the top directory of // the source code. // // Copyright 2009 Bastian Holst // // Self #include "BBCItemGetter.h" #include "BBCStation.h" #include "BBCWeatherItem.h" #include "MarbleDebug.h" // Qt #include #include using namespace Marble; BBCItemGetter::BBCItemGetter( QObject *parent ) : AbstractWorkerThread( parent ), m_scheduleMutex(), m_scheduledNumber( 0 ) { } BBCItemGetter::~BBCItemGetter() { } void BBCItemGetter::setSchedule( const GeoDataLatLonAltBox& box, MarbleDataFacade *facade, qint32 number ) { Q_UNUSED( facade ) m_scheduleMutex.lock(); m_scheduledBox = box; m_scheduledNumber = number; m_scheduleMutex.unlock(); ensureRunning(); } void BBCItemGetter::setStationList( const QList& items ) { m_items = items; ensureRunning(); } bool BBCItemGetter::workAvailable() { return !m_scheduledBox.isNull() && m_scheduledNumber; } void BBCItemGetter::work() { if ( m_items.isEmpty() ) { sleep( 1 ); return; } m_scheduleMutex.lock(); GeoDataLatLonAltBox box = m_scheduledBox; qint32 number = m_scheduledNumber; m_scheduledBox = GeoDataLatLonAltBox(); m_scheduledNumber = 0; m_scheduleMutex.unlock(); qint32 fetched = 0; QList::ConstIterator it = m_items.constBegin(); QList::ConstIterator end = m_items.constEnd(); while ( fetched < number && it != end ) { if ( box.contains( it->coordinate() ) ) { emit foundStation( (*it) ); fetched++; } ++it; } } #include "BBCItemGetter.moc"