[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [publictransport] engine/gtfs: Improve GTFS service notifications
From:       Friedrich_Karl_Tilman_Pülz <fpuelz () gmx ! de>
Date:       2012-11-30 20:36:58
Message-ID: 20121130203658.0F58FA60E5 () git ! kde ! org
[Download RAW message or body]

Git commit f5fa2bc3b523a1f04d12a5d25a9c0e00c2010557 by Friedrich Karl Tilman Pülz.
Committed on 29/11/2012 at 17:45.
Pushed by fkpulz into branch 'master'.

Improve GTFS service notifications

Do not register GTFS database update jobs at the job tracker,
that only check if there is any update. Register the update job
once the update really starts. Otherwise many GTFS feed update
notifications may be shown at the same time, ie. when installing
new providers.
After registering, the job description needs be emitted again.

M  +36   -17   engine/gtfs/gtfsservice.cpp
M  +5    -0    engine/gtfs/gtfsservice.h

http://commits.kde.org/publictransport/f5fa2bc3b523a1f04d12a5d25a9c0e00c2010557

diff --git a/engine/gtfs/gtfsservice.cpp b/engine/gtfs/gtfsservice.cpp
index 9d0746a..e0e56bc 100644
--- a/engine/gtfs/gtfsservice.cpp
+++ b/engine/gtfs/gtfsservice.cpp
@@ -144,10 +144,14 @@ void AbstractGtfsDatabaseJob::tryToWork()
     work();
 }
 
-void ImportGtfsToDatabaseJob::work()
+void ImportGtfsToDatabaseJob::registerAtJobTracker()
 {
-    Q_ASSERT( m_data );
+    KIO::getJobTracker()->registerJob( this );
+    emitDescription();
+}
 
+void ImportGtfsToDatabaseJob::emitDescription()
+{
     // Emit a description about what's done in this job
     const QPair< QString, QString > field1 =
             qMakePair( i18nc("@info/plain Label for GTFS service provider", "Service Provider"),
@@ -159,8 +163,23 @@ void ImportGtfsToDatabaseJob::work()
         emit description( this, i18nc("@info", "Update GTFS feed info"), field1, field2 );
     } else {
         emit description( this, i18nc("@info", "Import GTFS feed"), field1, field2 );
-        kDebug() << "Start GTFS feed import for" << m_data->id();
     }
+}
+
+void UpdateGtfsToDatabaseJob::emitDescription()
+{
+    emit description( this, i18nc("@info", "Updating GTFS feed"),
+                      qMakePair(i18nc("@info/plain Label for GTFS service provider",
+                                      "Service Provider"), data()->name()),
+                      qMakePair(i18nc("@info/plain Label for GTFS feed source URLs", 
+                                      "Source"), data()->feedUrl()) );
+}
+
+void ImportGtfsToDatabaseJob::work()
+{
+    Q_ASSERT( m_data );
+
+    emitDescription();
 
     // Start the job by first requesting GTFS feed information
     statFeed();
@@ -195,11 +214,7 @@ void UpdateGtfsToDatabaseJob::work()
         setResult( false );
     } else {
         // Emit a description about what's done in this job
-        emit description( this, i18nc("@info", "Updating GTFS feed"),
-                          qMakePair(i18nc("@info/plain Label for GTFS service provider",
-                                          "Service Provider"), data()->name()),
-                          qMakePair(i18nc("@info/plain Label for GTFS feed source URLs", "Source"),
-                                    data()->feedUrl()) );
+        emitDescription();
         setCapabilities( Suspendable | Killable );
 
         // Start the job by first requesting GTFS feed information
@@ -385,6 +400,9 @@ void ImportGtfsToDatabaseJob::statFeedFinished( QNetworkReply *reply )
             setResult( true );
         }
     } else {
+        // Track this job to show the error
+        registerAtJobTracker();
+
         kDebug() << "GTFS feed not available: " << m_data->feedUrl() << reply->errorString();
         m_state = ErrorDownloadingFeed;
         setError( GtfsErrorDownloadFailed );
@@ -414,6 +432,11 @@ void ImportGtfsToDatabaseJob::downloadFeed()
         return;
     }
 
+    // Track this job at least from now on,
+    // because the download/import can take some time
+    registerAtJobTracker();
+
+    kDebug() << "Start GTFS feed import for" << m_data->id();
     KTemporaryFile tmpFile;
     if ( tmpFile.open() ) {
         kDebug() << "Downloading GTFS feed from" << m_data->feedUrl() << "to" << tmpFile.fileName();
@@ -609,26 +632,22 @@ Plasma::ServiceJob* GtfsService::createJob(
     if ( operation == QLatin1String("updateGtfsDatabase") ) {
         UpdateGtfsToDatabaseJob *updateJob =
                 new UpdateGtfsToDatabaseJob( "PublicTransport", operation, parameters, this );
-        // Track update jobs
-        KJobTrackerInterface *jobTracker = KIO::getJobTracker();
-        jobTracker->registerJob( updateJob );
         return updateJob;
     } else if ( operation == QLatin1String("importGtfsFeed") ) {
         ImportGtfsToDatabaseJob *importJob =
                 new ImportGtfsToDatabaseJob( "PublicTransport", operation, parameters, this );
-        // Track import jobs
-        KJobTrackerInterface *jobTracker = KIO::getJobTracker();
-        jobTracker->registerJob( importJob );
+        // Directly register import jobs, ie. also show "Check Feed Source"
+        importJob->registerAtJobTracker();
         return importJob;
     } else if ( operation == QLatin1String("deleteGtfsDatabase") ) {
         DeleteGtfsDatabaseJob *deleteJob =
                 new DeleteGtfsDatabaseJob( "PublicTransport", operation, parameters, this );
         return deleteJob;
     } else if ( operation == QLatin1String("updateGtfsFeedInfo") ) {
-        ImportGtfsToDatabaseJob *importJob =
+        ImportGtfsToDatabaseJob *updateFeedInfoJob =
                 new ImportGtfsToDatabaseJob( "PublicTransport", operation, parameters, this );
-        importJob->setOnlyGetInformation( true );
-        return importJob;
+        updateFeedInfoJob->setOnlyGetInformation( true );
+        return updateFeedInfoJob;
     } else {
         kWarning() << "Operation" << operation << "not supported";
         return 0;
diff --git a/engine/gtfs/gtfsservice.h b/engine/gtfs/gtfsservice.h
index f74eae2..2821f6f 100644
--- a/engine/gtfs/gtfsservice.h
+++ b/engine/gtfs/gtfsservice.h
@@ -117,6 +117,9 @@ public:
                              const QMap< QString, QVariant > &parameters, QObject *parent = 0 );
     virtual ~ImportGtfsToDatabaseJob();
 
+    void registerAtJobTracker();
+    virtual void emitDescription();
+
     inline const ServiceProviderData *data() const { return m_data; };
     virtual QString serviceProviderId() const;
 
@@ -202,6 +205,8 @@ public:
     UpdateGtfsToDatabaseJob( const QString &destination, const QString &operation,
                              const QMap< QString, QVariant > &parameters, QObject *parent = 0 );
 
+    virtual void emitDescription();
+
 protected slots:
     /**
      * @brief Overwritten to test if the GTFS feed was imported.

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic