[gnome-documents/gnome-3-6] application: don't try to start miners for account types we don't have



commit 9311f4afaf1e54d9db1432314d2aae135bb42571
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Thu Oct 25 15:59:41 2012 -0400

    application: don't try to start miners for account types we don't have
    
    Right now we just start the miner processes, which will just return in
    case no matching account is found.
    Instead, only run a miner in case we know there's an account of a
    certain type configured, and connect to signals for when accounts are
    added or removed to check again.

 src/application.js |   42 ++++++++++++++++++++++++++++++------------
 src/sources.js     |   21 +++++++++++++++++++++
 2 files changed, 51 insertions(+), 12 deletions(-)
---
diff --git a/src/application.js b/src/application.js
index 13fed51..468e8a7 100644
--- a/src/application.js
+++ b/src/application.js
@@ -246,6 +246,35 @@ const Application = new Lang.Class({
         return false;
     },
 
+    _refreshMiners: function() {
+        if (Global.sourceManager.hasProviderType('google')) {
+            try {
+                // startup a refresh of the gdocs cache
+                this._refreshMinerNow(this.gdataMiner);
+            } catch (e) {
+                log('Unable to start GData miner: ' + e.message);
+            }
+        }
+
+        if (Global.sourceManager.hasProviderType('windows_live')) {
+            try {
+                // startup a refresh of the skydrive cache
+                this._refreshMinerNow(this.zpjMiner);
+            } catch (e) {
+                log('Unable to start Zpj miner: ' + e.message);
+            }
+        }
+    },
+
+    _initMiners: function() {
+        this.gdataMiner = new Miners.GDataMiner();
+        this.zpjMiner = new Miners.ZpjMiner();
+        this._refreshMiners();
+
+        Global.sourceManager.connect('item-added', Lang.bind(this, this._refreshMiners));
+        Global.sourceManager.connect('item-removed', Lang.bind(this, this._refreshMiners));
+    },
+
     vfunc_startup: function() {
         this.parent();
         String.prototype.format = Format.format;
@@ -283,18 +312,7 @@ const Application = new Lang.Class({
         Global.modeController = new WindowMode.ModeController();
         Global.notificationManager = new Notifications.NotificationManager();
 
-        try {
-          // startup a refresh of the gdocs cache
-          let gdataMiner = new Miners.GDataMiner();
-          this._refreshMinerNow(gdataMiner);
-
-          // startup a refresh of the skydrive cache
-          let zpjMiner = new Miners.ZpjMiner();
-          this._refreshMinerNow(zpjMiner);
-        } catch (e) {
-	  log('Unable to start miners: ' + e.message);
-        }
-
+        this._initMiners();
         this._initActions();
         this._initAppMenu();
         this._mainWindow = new MainWindow.MainWindow(this);
diff --git a/src/sources.js b/src/sources.js
index e3fe16f..c42c31b 100644
--- a/src/sources.js
+++ b/src/sources.js
@@ -132,5 +132,26 @@ const SourceManager = new Lang.Class({
             });
 
         return hasOnline;
+    },
+
+    hasProviderType: function(providerType) {
+        let found = false;
+        this.forEachItem(Lang.bind(this,
+            function(source) {
+                if (!source.object)
+                    return;
+
+                let account = source.object.get_account();
+                if (!account)
+                    return;
+
+                if (found)
+                    return;
+
+                if (account.provider_type == providerType)
+                    found = true;
+            }));
+
+        return found;
     }
 });



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]