1 /* ***** BEGIN LICENSE BLOCK *****
  2  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  3  *
  4  * The contents of this file are subject to the Mozilla Public License Version
  5  * 1.1 (the "License"); you may not use this file except in compliance with
  6  * the License. You may obtain a copy of the License at
  7  * http://www.mozilla.org/MPL/
  8  *
  9  * Software distributed under the License is distributed on an "AS IS" basis,
 10  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 11  * for the specific language governing rights and limitations under the
 12  * License.
 13  *
 14  * The Original Code is gContactSync.
 15  *
 16  * The Initial Developer of the Original Code is
 17  * Josh Geenen <gcontactsync@pirules.org>.
 18  * Portions created by the Initial Developer are Copyright (C) 2008-2010
 19  * the Initial Developer. All Rights Reserved.
 20  *
 21  * Contributor(s):
 22  *
 23  * Alternatively, the contents of this file may be used under the terms of
 24  * either the GNU General Public License Version 2 or later (the "GPL"), or
 25  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
 26  * in which case the provisions of the GPL or the LGPL are applicable instead
 27  * of those above. If you wish to allow use of your version of this file only
 28  * under the terms of either the GPL or the LGPL, and not to allow others to
 29  * use your version of this file under the terms of the MPL, indicate your
 30  * decision by deleting the provisions above and replace them with the notice
 31  * and other provisions required by the GPL or the LGPL. If you do not delete
 32  * the provisions above, a recipient may use your version of this file under
 33  * the terms of any one of the MPL, the GPL or the LGPL.
 34  *
 35  * ***** END LICENSE BLOCK ***** */
 36 
 37 if (!com) var com = {}; // A generic wrapper variable
 38 // A wrapper for all GCS functions and variables
 39 if (!com.gContactSync) com.gContactSync = {};
 40 
 41 window.addEventListener("load",
 42   /** Initializes the FileIO class when the window has finished loading */
 43   function gCS_overlayLoadListener(e) {
 44     com.gContactSync.Overlay.initialize();
 45   },
 46 false);
 47 
 48 /**
 49  * Checks if the authentication token is present and valid.  If so, it starts
 50  * everything up and synchronizes the contacts.  Otherwise it shows the
 51  * login window.
 52  * @class
 53  */
 54 com.gContactSync.Overlay = {
 55   /** The last version of gContactSync */
 56   mLastVersionMajor:   0,
 57   mLastVersionMinor:   0,
 58   mLastVersionRelease: 0,
 59   mLastVersionSuffix:  "",
 60   /**
 61    * Called when the overlay is loaded and initializes everything and begins
 62    * the authentication check and sync or login prompt.
 63    */
 64   initialize: function Overlay_initialize() {
 65     // Find the last version of gContactSync and set the pref to the current
 66     this.mLastVersionMajor   = com.gContactSync.Preferences.mSyncPrefs.lastVersionMajor.value;
 67     this.mLastVersionMinor   = com.gContactSync.Preferences.mSyncPrefs.lastVersionMinor.value;
 68     this.mLastVersionRelease = com.gContactSync.Preferences.mSyncPrefs.lastVersionRelease.value;
 69     this.mLastVersionSuffix  = com.gContactSync.Preferences.mSyncPrefs.lastVersionSuffix.value;
 70     com.gContactSync.AbListener.add(); // add the address book listener
 71 
 72     // call the unload function when the address book window is shut
 73     window.addEventListener("unload", function unloadListener(e) {
 74       com.gContactSync.Overlay.unload();
 75     }, false);
 76   },
 77   /**
 78    * Called when the overlay is unloaded and removes the address book listener.
 79    */
 80   unload: function Overlay_unload() {
 81     com.gContactSync.AbListener.remove();
 82   },
 83   /**
 84    * Sets the text of the status bar to the given value.
 85    * @param aText {string} The text to put on the status bar.
 86    */
 87   setStatusBarText: function Overlay_setStatusBarText(aText) {
 88     com.gContactSync.Preferences.setSyncPref("statusBarText", aText);
 89   },
 90   /**
 91    * Gets the text of the status bar.
 92    * @returns {string} The text of the status bar
 93    */
 94   getStatusBarText: function Overlay_getStatusBarText() {
 95     return com.gContactSync.Preferences.mSyncPrefs.statusBarText.value;
 96   },
 97   /**
 98    * Writes the current time to the status bar along with the sync finished
 99    * string.
100    * When the status text is clicked the log file is opened.
101    */
102   writeTimeToStatusBar: function Overlay_writeTimeToStatusBar() {
103     var hours   = String(new Date().getHours()),
104         minutes = String(new Date().getMinutes()),
105         seconds = String(new Date().getSeconds()),
106         text    = com.gContactSync.StringBundle.getStr("syncFinishedString");
107     // Add any missing 0's to the times
108     hours       = hours.length   === 0 ? "00" + hours   : hours;
109     hours       = hours.length   === 1 ?  "0" + hours   : hours;
110     minutes     = minutes.length === 1 ?  "0" + minutes : minutes;
111     seconds     = seconds.length === 1 ?  "0" + seconds : seconds;
112     this.setStatusBarText(text + " " + hours + ":" + minutes + ":" + seconds);
113   }
114 };
115