diff Modules/OpenAll.lua @ 3:c6f0976069c7

Default value for the welcome / bye notification is now set to false The mailframe checkbox now primarily toggles the mail opening, however if you hold shift you can still disable the entire addon Now properly removes QuickAuction?s mail count Now tracks when a mail lost all attachments rather than it being deleted in order to continue processing the next item (mail sent by players containing text should now work properly). This should also be good for a nice speed increase. Added a variable called ?busy? to the MailOpener object indicating whether or not Mail Opener is currently working. Other addons (or macros) can retrieve it with ?LibStub("AceAddon-3.0"):GetAddon("MailOpener").busy? A mail refresh from the Postal service should no longer occur while mail is being opened but will happen instantly afterwards. Postal?s module toggling will now be handled by Postal itself. Added a short summary to the top of all modules for other developers. The time remaining until next mail box refresh should be displayed for as long as Mail Opener can be sure.
author Zerotorescue
date Tue, 07 Sep 2010 17:46:27 +0200
parents 57ba1593ac42
children 1ba07a64bf14
line wrap: on
line diff
--- a/Modules/OpenAll.lua	Sun Sep 05 17:26:35 2010 +0200
+++ b/Modules/OpenAll.lua	Tue Sep 07 17:46:27 2010 +0200
@@ -1,6 +1,15 @@
 local MailOpener = LibStub("AceAddon-3.0"):GetAddon("MailOpener");
 local OpenAll = MailOpener:NewModule("OpenAll", "AceEvent-3.0", "AceTimer-3.0");
 
+--[[
+Module name:	OpenAll
+Description:	The actual mail opening initiated by the core.
+Required:		Yes.
+
+Dev notes:
+When shift clicking the Open All button it should override all filters.
+]]
+
 local MAIL_ITEM_INDEX, mailTimer, inventoryFull, inventoryFullSoundPlayed, opening, lastSync, numCurrentMail, numHiddenMail, continue;
 
 function OpenAll:OnInitialize()
@@ -79,7 +88,7 @@
 	
 	self.timeLeftFrame:Show();
 	
-	-- Go through all children of the mail frame to find QA's elements and hide these
+	-- Go through all children of the mail frame to find QA's element and hide it
 	local kids = { MailFrame:GetChildren() };
 	
 	for _, child in ipairs(kids) do
@@ -148,7 +157,7 @@
     -- We need to know when to start opening
 	self:RegisterMessage("MO_OPEN_MAIL", "Open");
 	self:RegisterMessage("MO_SERVER_SYNCED");
-	self:RegisterMessage("MO_MAIL_DELETED");
+	self:RegisterMessage("MO_MAIL_EMPTIED");
 	
 	self:CancelTimer(self.tmrTimeRemaining, true);
 	self.tmrTimeRemaining = self:ScheduleRepeatingTimer("UpdateTimer", 1);
@@ -169,7 +178,7 @@
 	-- We no longer care
 	self:UnregisterMessage("MO_OPEN_MAIL");
 	self:UnregisterMessage("MO_SERVER_SYNCED");
-	self:UnregisterMessage("MO_MAIL_DELETED");
+	self:UnregisterMessage("MO_MAIL_EMPTIED");
     
 	self:CancelTimer(self.tmrMailOpener, true);
 	self:CancelTimer(self.tmrTimeRemaining, true);
@@ -188,13 +197,11 @@
 	self:UpdateMailCount();
 end
 
-function OpenAll:MO_MAIL_DELETED()
-	self:Debug("MO_MAIL_DELETED");
-	
-	-- A mail has been deleted so we can process the next
+function OpenAll:MO_MAIL_EMPTIED()
+	-- A mail has been processed so we can process the next
 	continue = true;
 	
-	self:UpdateMailCount();
+	self:UpdateTimer();
 end
 
 function OpenAll:UpdateMailCount()
@@ -202,8 +209,6 @@
 	
 	numCurrentMail = numItems;
 	numHiddenMail = ( totalItems - numItems );
-	
-	self:UpdateTimer();
 end
 
 function OpenAll:BAG_UPDATE()
@@ -432,6 +437,8 @@
 					return;
 				else
 					continue = false;
+			
+					self:Debug("MO_OPENING_MAIL");
 					
 					-- Notifiy other modules of opening
 					self:SendMessage("MO_OPENING_MAIL");
@@ -470,7 +477,7 @@
 		end
 		
 		self:SetOpeningStatus(false);
-			
+		
 		self:Debug("MO_OPEN_COMPLETE");
 		
 		-- Report that we're all done
@@ -500,9 +507,10 @@
 end
 
 local mailRemainingPatterns = {
-	minutesSeconds = "|cffffffff%d|r/|cffffffff%d|r mail remaining, opening everything will take about |cffffffff%d|r minutes and |cffffffff%d|r seconds (next refresh in |cffffffff%d|r seconds)";
-	minutes = "|cffffffff%d|r/|cffffffff%d|r mail remaining, opening everything will take about |cffffffff%d|r minutes (next refresh in |cffffffff%d|r seconds)";
-	seconds = "|cffffffff%d|r/|cffffffff%d|r mail remaining, opening everything will take about |cffffffff%d|r seconds (next refresh in |cffffffff%d|r seconds)";
+	minutesSeconds = "|cffffffff%d|r/|cffffffff%d|r mail remaining, opening everything will take about |cffffffff%d|r minutes and |cffffffff%d|r seconds (next refresh in |cffffffff%d|r seconds).";
+	minutes = "|cffffffff%d|r/|cffffffff%d|r mail remaining, opening everything will take about |cffffffff%d|r minutes (next refresh in |cffffffff%d|r seconds).";
+	seconds = "|cffffffff%d|r/|cffffffff%d|r mail remaining, opening everything will take about |cffffffff%d|r seconds (next refresh in |cffffffff%d|r seconds).";
+	nextRefresh = "|cffffffff%d|r/|cffffffff%d|r mail remaining, next refresh in |cffffffff%d|r seconds.";
 	waitingBatch = "|cffffffff%d|r/|cffffffff%d|r mail remaining - waiting for something from the current batch to be opened...";
 	waitingSync = "|cffffffff%d|r/|cffffffff%d|r mail remaining - waiting for the next mailbox refresh...";
 	soon = "|cffffffff%d|r/|cffffffff%d|r mail remaining - everything will be opened soon...";
@@ -510,6 +518,8 @@
 
 function OpenAll:UpdateTimer()
 	if lastSync then
+		self:UpdateMailCount();
+		
 		-- Calculate the total amount of mail waiting
 		local numTotalMail = ( numHiddenMail + numCurrentMail );
 		
@@ -522,13 +532,16 @@
 			self.timeLeftFrame.text:SetFont(GameFontHighlight:GetFont(), 18, "THICKOUTLINE");
 		end
 		self.timeLeftFrame.text:SetText(numTotalMail);
+		
+		-- Calculate the next server sync based on the last server sync plus sync interval
+		local nextSync = ( lastSync + 61 );
 	
-		if numHiddenMail > 0 then
-			-- Calculate the next server sync based on the last server sync plus sync interval
-			local nextSync = ( lastSync + 61 );
+		-- Calculate the timer remaining untill the next sync
+		local timeRemaining = floor( nextSync - GetTime() );
+		
+		if numHiddenMail > 0 or timeRemaining > 0 then
+			-- If there is still mail being hidden or the timer is still know, display stuff
 			
-			-- Calculate the timer remaining untill the next sync
-			local timeRemaining = floor( nextSync - GetTime() );
 			-- If the next sync was already due, our nextSync calculation was wrong and we must wait a little longer (lag?)
 			local syncTimeOut = false;
 			-- If time remaining is below 0, next sync should be soon
@@ -547,11 +560,18 @@
 			
 			local remainingText;
 			if syncTimeOut then
+				-- Previous server sync was expected earlier, notify user
+				
 				if numCurrentMail == 50 then
+					-- Sync couldn't occur because we were still waiting for the current batch to be opened
 					remainingText = format(mailRemainingPatterns.waitingBatch, numCurrentMail, numTotalMail);
 				else
 					remainingText = format(mailRemainingPatterns.waitingSync, numCurrentMail, numTotalMail);
 				end
+			elseif numHiddenMail == 0 then
+				-- If no hidden mail is remaining, only show the timer for as long as we can be sure
+				
+				remainingText = format(mailRemainingPatterns.nextRefresh, numCurrentMail, numTotalMail, timeRemaining);
 			elseif minutes ~= 0 then
 				if seconds ~= 0 then
 					remainingText = format(mailRemainingPatterns.minutesSeconds, numCurrentMail, numTotalMail, minutes, seconds, timeRemaining);
@@ -565,7 +585,7 @@
 			end
 			
 			self.timeLeftFrame.smallText:SetText(remainingText);
-		elseif numHiddenMail == 0 then
+		else
 			self.timeLeftFrame.smallText:SetText("");
 		end
 	end