From b5a001f838dc0820e52dee7210cefe26f11fc8c0 Mon Sep 17 00:00:00 2001 From: "scott%scott-macgregor.org" Date: Sat, 4 Nov 2006 05:17:04 +0000 Subject: [PATCH] Bug #359469 --> undo the changes to make offline support a (non-optional) extension. sr=bienvenu --- mail/base/content/commandglue.js | 3 +- mail/base/content/mail-offline.js | 260 ++++ mail/base/content/mailContextMenus.js | 2 + mail/base/content/mailCore.js | 6 - mail/base/content/mailWindowOverlay.xul | 21 + mail/base/jar.mn | 1 + mail/config/installed-chrome.txt | 48 - mail/config/mail-locales.manifest | 26 - mail/extensions/Makefile.in | 2 +- mail/extensions/offline/Makefile.in | 0 .../offline/content/mail-offline.js | 0 .../offline/content/msgOfflineOverlay.xul | 0 mail/extensions/offline/install.js | 0 mail/extensions/offline/jar.mn | 0 mail/installer/removed-files.in | 1 + mail/installer/windows/config.it | 1225 ----------------- mail/installer/windows/installer.cfg | 15 - .../chrome/messenger-offline/offline.dtd | 0 .../messenger-offline/offline.properties | 0 .../en-US/chrome/messenger/messenger.dtd | 10 + mail/locales/jar.mn | 3 - 21 files changed, 298 insertions(+), 1325 deletions(-) create mode 100644 mail/base/content/mail-offline.js delete mode 100644 mail/extensions/offline/Makefile.in delete mode 100644 mail/extensions/offline/content/mail-offline.js delete mode 100644 mail/extensions/offline/content/msgOfflineOverlay.xul delete mode 100644 mail/extensions/offline/install.js delete mode 100644 mail/extensions/offline/jar.mn delete mode 100644 mail/locales/en-US/chrome/messenger-offline/offline.dtd delete mode 100644 mail/locales/en-US/chrome/messenger-offline/offline.properties diff --git a/mail/base/content/commandglue.js b/mail/base/content/commandglue.js index 913fef549ef..038b672d2cc 100644 --- a/mail/base/content/commandglue.js +++ b/mail/base/content/commandglue.js @@ -1005,10 +1005,11 @@ function Redo() { messenger.Redo(msgWindow); } + var mailOfflineObserver = { observe: function(subject, topic, state) { // sanity checks - if (topic != "network:offline-status-changed") return; + if (topic == "network:offline-status-changed") MailOfflineStateChanged(state == "offline"); } } diff --git a/mail/base/content/mail-offline.js b/mail/base/content/mail-offline.js new file mode 100644 index 00000000000..a0f09d35782 --- /dev/null +++ b/mail/base/content/mail-offline.js @@ -0,0 +1,260 @@ +# -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- +# ***** BEGIN LICENSE BLOCK ***** +# Version: MPL 1.1/GPL 2.0/LGPL 2.1 +# +# The contents of this file are subject to the Mozilla Public License Version +# 1.1 (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# http://www.mozilla.org/MPL/ +# +# Software distributed under the License is distributed on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License +# for the specific language governing rights and limitations under the +# License. +# +# The Original Code is Mozilla Communicator client code, released +# March 31, 1998. +# +# The Initial Developer of the Original Code is +# Netscape Communications Corporation. +# Portions created by the Initial Developer are Copyright (C) 1998-2001 +# the Initial Developer. All Rights Reserved. +# +# Contributor(s): +# +# Alternatively, the contents of this file may be used under the terms of +# either the GNU General Public License Version 2 or later (the "GPL"), or +# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), +# in which case the provisions of the GPL or the LGPL are applicable instead +# of those above. If you wish to allow use of your version of this file only +# under the terms of either the GPL or the LGPL, and not to allow others to +# use your version of this file under the terms of the MPL, indicate your +# decision by deleting the provisions above and replace them with the notice +# and other provisions required by the GPL or the LGPL. If you do not delete +# the provisions above, a recipient may use your version of this file under +# the terms of any one of the MPL, the GPL or the LGPL. +# +# ***** END LICENSE BLOCK ***** + +var gMailOfflinePrefs = null; +var gOfflinePromptsBundle; +var gPromptService; +var gOfflineManager; + + +function MailOfflineStateChanged(goingOffline) +{ + // tweak any mail UI here that needs to change when we go offline or come back online + gFolderJustSwitched = true; +} + +function MsgSettingsOffline() +{ + window.parent.MsgAccountManager('am-offline.xul'); +} + +// Init PrefsService +function GetMailOfflinePrefs() +{ + gMailOfflinePrefs = Components.classes["@mozilla.org/preferences-service;1"] + .getService(Components.interfaces.nsIPrefService).getBranch(null); +} + +// Check for unsent messages +function CheckForUnsentMessages() +{ + try + { + var am = Components.classes["@mozilla.org/messenger/account-manager;1"] + .getService(Components.interfaces.nsIMsgAccountManager); + var msgSendlater = Components.classes["@mozilla.org/messengercompose/sendlater;1"] + .getService(Components.interfaces.nsIMsgSendLater); + var identitiesCount, allIdentities, currentIdentity, numMessages, msgFolder; + + if(am) { + allIdentities = am.allIdentities; + identitiesCount = allIdentities.Count(); + for (var i = 0; i < identitiesCount; i++) { + currentIdentity = allIdentities.QueryElementAt(i, Components.interfaces.nsIMsgIdentity); + msgFolder = msgSendlater.getUnsentMessagesFolder(currentIdentity); + if(msgFolder) { + // if true, descends into all subfolders + numMessages = msgFolder.getTotalMessages(false); + if(numMessages > 0) return true; + } + } + } + } + catch(ex) { + } + return false; +} + +// Init nsIPromptService & strings. +function InitPrompts() +{ + if(!gPromptService) { + gPromptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].getService(); + gPromptService = gPromptService.QueryInterface(Components.interfaces.nsIPromptService); + } + if (!gOfflinePromptsBundle) + gOfflinePromptsBundle = document.getElementById("bundle_offlinePrompts"); +} + +// prompt for sending messages while going online, and go online. +function PromptSendMessages() +{ + InitPrompts(); + InitServices(); + + if (gPromptService) { + var checkValue = {value:true}; + var buttonPressed = gPromptService.confirmEx(window, + gOfflinePromptsBundle.getString('sendMessagesWindowTitle'), + gOfflinePromptsBundle.getString('sendMessagesLabel'), + gPromptService.BUTTON_TITLE_IS_STRING * (gPromptService.BUTTON_POS_0 + + gPromptService.BUTTON_POS_1 + gPromptService.BUTTON_POS_2), + gOfflinePromptsBundle.getString('sendMessagesSendButtonLabel'), + gOfflinePromptsBundle.getString('sendMessagesCancelButtonLabel'), + gOfflinePromptsBundle.getString('sendMessagesNoSendButtonLabel'), + gOfflinePromptsBundle.getString('sendMessagesCheckboxLabel'), + checkValue); + if(buttonPressed == 0) { + gMailOfflinePrefs.setIntPref("offline.send.unsent_messages", !checkValue.value); + gOfflineManager.goOnline(true, true, msgWindow); + return true; + } + if(buttonPressed == 1) { + return false; + } + if(buttonPressed == 2) { + gMailOfflinePrefs.setIntPref("offline.send.unsent_messages", 2*!checkValue.value); + gOfflineManager.goOnline(false, true, msgWindow); + return true; + } + } + return false; +} + +// prompt for downlading messages while going offline, and synchronise +function PromptDownloadMessages() +{ + InitPrompts(); + InitServices(); + + if(gPromptService) { + var checkValue = {value:true}; + var buttonPressed = gPromptService.confirmEx(window, + gOfflinePromptsBundle.getString('downloadMessagesWindowTitle'), + gOfflinePromptsBundle.getString('downloadMessagesLabel'), + gPromptService.BUTTON_TITLE_IS_STRING * (gPromptService.BUTTON_POS_0 + + gPromptService.BUTTON_POS_1 + gPromptService.BUTTON_POS_2), + gOfflinePromptsBundle.getString('downloadMessagesDownloadButtonLabel'), + gOfflinePromptsBundle.getString('downloadMessagesCancelButtonLabel'), + gOfflinePromptsBundle.getString('downloadMessagesNoDownloadButtonLabel'), + gOfflinePromptsBundle.getString('downloadMessagesCheckboxLabel'), + checkValue); + if(buttonPressed == 0) { + gMailOfflinePrefs.setIntPref("offline.download.download_messages", !checkValue.value); + gOfflineManager.synchronizeForOffline(true, true, false, true, msgWindow); + return true; + } + if(buttonPressed == 1) { + return false; + } + if(buttonPressed == 2) { + gMailOfflinePrefs.setIntPref("offline.download.download_messages", 2*!checkValue.value); + gOfflineManager.synchronizeForOffline(false, false, false, true, msgWindow); + return true; + } + } + return false; +} + +// online? +function CheckOnline() +{ + var ioService = Components.classes["@mozilla.org/network/io-service;1"] + .getService(Components.interfaces.nsIIOService); + return (!ioService.offline); +} + +// Init Pref Service & Offline Manager +function InitServices() +{ + if (!gMailOfflinePrefs) + GetMailOfflinePrefs(); + + if (!gOfflineManager) + GetOfflineMgrService(); +} + +// Init Offline Manager +function GetOfflineMgrService() +{ + if (!gOfflineManager) { + gOfflineManager = Components.classes["@mozilla.org/messenger/offline-manager;1"] + .getService(Components.interfaces.nsIMsgOfflineManager); + } +} + +// This function must always return false to prevent toggling of offline state because +// we change the offline state ourselves +function MailCheckBeforeOfflineChange() +{ + var ioService = Components.classes["@mozilla.org/network/io-service;1"] + .getService(Components.interfaces.nsIIOService); + + var goingOnline = ioService.offline; + var bundle = srGetStrBundle("chrome://communicator/locale/utilityOverlay.properties"); + +// messenger.SetWindow(window, msgWindow); + + InitServices(); + + var prefSendUnsentMessages = gMailOfflinePrefs.getIntPref("offline.send.unsent_messages"); + var prefDownloadMessages = gMailOfflinePrefs.getIntPref("offline.download.download_messages"); + + if(goingOnline) { + switch(prefSendUnsentMessages) { + case 0: + if(CheckForUnsentMessages()) { + if(! PromptSendMessages()) + return false; + } + else + gOfflineManager.goOnline(false /* sendUnsentMessages */, + true /* playbackOfflineImapOperations */, + msgWindow); + break; + case 1: + gOfflineManager.goOnline(CheckForUnsentMessages() /* sendUnsentMessages */, + true /* playbackOfflineImapOperations */, + msgWindow); + break; + case 2: + gOfflineManager.goOnline(false /* sendUnsentMessages */, + true /* playbackOfflineImapOperations */, + msgWindow); + break; + } + } + else { + // going offline + switch(prefDownloadMessages) { + case 0: + if(! PromptDownloadMessages()) return false; + break; + case 1: + // download news, download mail, send unsent messages, go offline when done, msg window + gOfflineManager.synchronizeForOffline(true, true, false, true, msgWindow); + break; + case 2: + // download news, download mail, send unsent messages, go offline when done, msg window + gOfflineManager.synchronizeForOffline(false, false, false, true, msgWindow); + break; + } + } + return false; +} + diff --git a/mail/base/content/mailContextMenus.js b/mail/base/content/mailContextMenus.js index 4ae972747cf..019b5a8d2e2 100644 --- a/mail/base/content/mailContextMenus.js +++ b/mail/base/content/mailContextMenus.js @@ -149,6 +149,8 @@ function fillThreadPaneContextMenu() ShowMenuItem("threadPaneContext-sep-edit", (numSelected <= 1)); + EnableMenuItem('downloadSelected', GetNumSelectedMessages() > 0); + return(true); } diff --git a/mail/base/content/mailCore.js b/mail/base/content/mailCore.js index bd39f84fc23..0461dbee5ce 100644 --- a/mail/base/content/mailCore.js +++ b/mail/base/content/mailCore.js @@ -147,12 +147,6 @@ function toImport() window.openDialog("chrome://messenger/content/importDialog.xul","importDialog","chrome, modal, titlebar", {importType: "addressbook"}); } -// this method is overridden by mail-offline.js if we build with the offline extensions -function CheckOnline() -{ - return true; -} - // aPaneID function openOptionsDialog(aPaneID, aTabID) { diff --git a/mail/base/content/mailWindowOverlay.xul b/mail/base/content/mailWindowOverlay.xul index 80a6ed0ebb0..a88efc34298 100644 --- a/mail/base/content/mailWindowOverlay.xul +++ b/mail/base/content/mailWindowOverlay.xul @@ -62,6 +62,7 @@