SVN commit 1251552 by mfuchs: Adds support for retrieving the network status. If there is no network connection all jobs are stopped, avoiding that they are aborted. As soon as there is a network connection again the jobs will resume, depending on their policies in fact. M +1 -1 CMakeLists.txt M +35 -0 core/kget.cpp M +10 -0 core/kget.h M +37 -13 core/scheduler.cpp M +20 -0 core/scheduler.h --- trunk/KDE/kdenetwork/kget/CMakeLists.txt #1251551:1251552 @@ -146,7 +146,7 @@ kde4_add_library(kgetcore SHARED ${kgetcore_SRCS}) -target_link_libraries(kgetcore ${KDE4_KIO_LIBS}) +target_link_libraries(kgetcore ${KDE4_KIO_LIBS} ${KDE4_SOLID_LIBS}) if (KDE4WORKSPACE_FOUND) target_link_libraries(kgetcore ${KDE4WORKSPACE_KWORKSPACE_LIBS}) --- trunk/KDE/kdenetwork/kget/core/kget.cpp #1251551:1251552 @@ -814,6 +814,7 @@ MainWindow * KGet::m_mainWindow = 0; KUiServerJobs * KGet::m_jobManager = 0; TransferHistoryStore * KGet::m_store = 0; +bool KGet::m_hasConnection = true; #ifdef HAVE_NEPOMUK NepomukController *KGet::m_nepomukController = 0; #endif @@ -835,6 +836,10 @@ QObject::connect(m_transferTreeModel, SIGNAL(transfersChangedEvent(QMap)), m_jobManager, SLOT(slotTransfersChanged(QMap))); + //check if there is a connection + const Solid::Networking::Status status = Solid::Networking::status(); + KGet::setHasNetworkConnection((status == Solid::Networking::Connected) || (status == Solid::Networking::Unknown)); + //Load all the available plugins loadPlugins(); @@ -1214,6 +1219,28 @@ kDebug(5001) << "Number of factories = " << m_transferFactories.size(); } + +void KGet::setHasNetworkConnection(bool hasConnection) +{ + kDebug(5001) << "Existing internet connection:" << hasConnection << "old:" << m_hasConnection; + if (hasConnection == m_hasConnection) { + return; + } + m_hasConnection = hasConnection; + + if (hasConnection) { + KGet::showNotification(m_mainWindow, "notification", + i18n("Internet connection established, resuming transfers."), + "dialog-info"); + + } else { + KGet::showNotification(m_mainWindow, "notification", + i18n("No internet connection, stopping transfers."), + "dialog-info"); + } + m_scheduler->setHasNetworkConnection(hasConnection); +} + KGetPlugin * KGet::createPluginFromService( const KService::Ptr &service ) { //try to load the specified library @@ -1278,6 +1305,9 @@ SLOT(groupsChangedEvent(QMap))); connect(KGet::model(), SIGNAL(transferMovedEvent(TransferHandler*,TransferGroupHandler*)), SLOT(transferMovedEvent(TransferHandler*,TransferGroupHandler*))); + connect(Solid::Networking::notifier(), SIGNAL(statusChanged(Solid::Networking::Status)), + this, SLOT(slotNetworkStatusChanged(Solid::Networking::Status))); + } GenericObserver::~GenericObserver() @@ -1465,6 +1495,11 @@ m_notifications.remove(notification); } +void GenericObserver::slotNetworkStatusChanged(const Solid::Networking::Status &status) +{ + KGet::setHasNetworkConnection((status == Solid::Networking::Connected) || (status == Solid::Networking::Unknown)); +} + void GenericObserver::groupsChangedEvent(QMap groups) { bool recalculate = false; --- trunk/KDE/kdenetwork/kget/core/kget.h #1251551:1251552 @@ -24,6 +24,7 @@ #include #include +#include #include #include "kuiserverjobs.h" @@ -415,6 +416,12 @@ //Plugin-related functions static KGetPlugin * createPluginFromService( const KService::Ptr &service ); + /** + * Stops all downloads if there is no connection and also displays + * a message. + * If there is a connection, then the downloads will be started again + */ + static void setHasNetworkConnection(bool hasConnection); /** * Deletes the given file, if possible. @@ -446,6 +453,8 @@ //pointer to the used TransferHistoryStore static TransferHistoryStore *m_store; + static bool m_hasConnection; + #ifdef HAVE_NEPOMUK static NepomukController *m_nepomukController; #endif @@ -485,6 +494,7 @@ void slotAbortAfterFinishAction(); void slotResolveTransferError(); void slotNotificationClosed(); + void slotNetworkStatusChanged(const Solid::Networking::Status &status); private: bool allTransfersFinished(); --- trunk/KDE/kdenetwork/kget/core/scheduler.cpp #1251551:1251552 @@ -22,7 +22,8 @@ m_stallTime(5), m_stallTimeout(Settings::reconnectDelay()), m_abortTimeout(Settings::reconnectDelay()), - m_isSuspended(false) + m_isSuspended(false), + m_hasConnection(true) { } @@ -38,12 +39,35 @@ m_isSuspended = isSuspended; //update all the queues - if (changed && !m_isSuspended) { + if (changed && shouldUpdate()) { + updateAllQueues(); + } +} + +void Scheduler::setHasNetworkConnection(bool hasConnection) +{ + const bool changed = (hasConnection != m_hasConnection); + m_hasConnection = hasConnection; + + if (changed) { + if (hasConnection) { + if (!m_failureCheckTimer) { + m_failureCheckTimer = startTimer(1000); + } + updateAllQueues(); + } else { + if (m_failureCheckTimer) { + killTimer(m_failureCheckTimer); + m_failureCheckTimer = 0; + } foreach (JobQueue *queue, m_queues) { - updateQueue(queue); + for (JobQueue::iterator it = queue->begin(); it != queue->end(); ++it) { + (*it)->stop(); } } } + } +} void Scheduler::addQueue(JobQueue * queue) { @@ -80,11 +104,8 @@ m_stallTimeout = Settings::reconnectDelay(); m_abortTimeout = Settings::reconnectDelay(); - foreach(JobQueue * queue, m_queues) - { - updateQueue(queue); + updateAllQueues(); } -} void Scheduler::jobQueueChangedEvent(JobQueue * queue, JobQueue::Status status) { @@ -229,13 +250,9 @@ { static bool updatingQueue = false; - if(updatingQueue) + if (!shouldUpdate() || updatingQueue) return; - if (m_isSuspended) { - return; - } - updatingQueue = true; int runningJobs = 0; //Jobs that are running (and not in the stallTimeout) @@ -307,6 +324,13 @@ updatingQueue = false; } +void Scheduler::updateAllQueues() +{ + foreach (JobQueue *queue, m_queues) { + updateQueue(queue); + } +} + bool Scheduler::shouldBeRunning( Job * job ) { Job::Policy policy = job->policy(); @@ -331,7 +355,7 @@ Q_UNUSED(event) // kDebug(5001); - if (m_isSuspended) { + if (!shouldUpdate()) { return; } --- trunk/KDE/kdenetwork/kget/core/scheduler.h #1251551:1251552 @@ -90,6 +90,13 @@ void setIsSuspended(bool isSuspended); /** + * The JobQueues will be informed of changes in the network connection + * If there is no network connection then the Scheduler won't act on + * the timerEvent or updateQueue + */ + void setHasNetworkConnection(bool hasConnection); + + /** * Adds a queue to the scheduler. * * @param queue The queue that should be added @@ -150,6 +157,14 @@ //Virtual QObject method void timerEvent(QTimerEvent * event); + /** + * Calls updateQueue for all queues + * @see updateQueue + */ + void updateAllQueues(); + + bool shouldUpdate() const; + private: QList m_queues; QMap m_failedJobs; @@ -160,6 +175,11 @@ int m_stallTimeout; int m_abortTimeout; bool m_isSuspended; + bool m_hasConnection; }; +inline bool Scheduler::shouldUpdate() const +{ + return !m_isSuspended && m_hasConnection; +} #endif