michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: const NS_XUL = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"; michael@0: michael@0: var gUpdateHistory = { michael@0: _view: null, michael@0: michael@0: /** michael@0: * Initialize the User Interface michael@0: */ michael@0: onLoad: function() { michael@0: this._view = document.getElementById("historyItems"); michael@0: michael@0: var um = michael@0: Components.classes["@mozilla.org/updates/update-manager;1"]. michael@0: getService(Components.interfaces.nsIUpdateManager); michael@0: var uc = um.updateCount; michael@0: if (uc) { michael@0: while (this._view.hasChildNodes()) michael@0: this._view.removeChild(this._view.firstChild); michael@0: michael@0: var bundle = document.getElementById("updateBundle"); michael@0: michael@0: for (var i = 0; i < uc; ++i) { michael@0: var update = um.getUpdateAt(i); michael@0: if (!update || !update.name) michael@0: continue; michael@0: michael@0: // Don't display updates that are downloading since they don't have michael@0: // valid statusText for the UI (bug 485493). michael@0: if (!update.statusText) michael@0: continue; michael@0: michael@0: var element = document.createElementNS(NS_XUL, "update"); michael@0: this._view.appendChild(element); michael@0: element.name = bundle.getFormattedString("updateFullName", michael@0: [update.name, update.buildID]); michael@0: element.type = bundle.getString("updateType_" + update.type); michael@0: element.installDate = this._formatDate(update.installDate); michael@0: if (update.detailsURL) michael@0: element.detailsURL = update.detailsURL; michael@0: else michael@0: element.hideDetailsURL = true; michael@0: element.status = update.statusText; michael@0: } michael@0: } michael@0: var cancelbutton = document.documentElement.getButton("cancel"); michael@0: cancelbutton.focus(); michael@0: }, michael@0: michael@0: /** michael@0: * Formats a date into human readable form michael@0: * @param seconds michael@0: * A date in seconds since 1970 epoch michael@0: * @returns A human readable date string michael@0: */ michael@0: _formatDate: function(seconds) { michael@0: var sdf = michael@0: Components.classes["@mozilla.org/intl/scriptabledateformat;1"]. michael@0: getService(Components.interfaces.nsIScriptableDateFormat); michael@0: var date = new Date(seconds); michael@0: return sdf.FormatDateTime("", sdf.dateFormatLong, michael@0: sdf.timeFormatSeconds, michael@0: date.getFullYear(), michael@0: date.getMonth() + 1, michael@0: date.getDate(), michael@0: date.getHours(), michael@0: date.getMinutes(), michael@0: date.getSeconds()); michael@0: } michael@0: }; michael@0: