changeset 8:1b2d819b4fa8

Now using the global MailAddonBusy to indicate MailOpener is busy, read comments in Core.lua for more info. Default status is now ?enabled without automatic mail opening? to let first time users look around before MailOpener messes up their heads. A StaticPopupDialog will be added later to ask if they want to auto-enable. When ?enabled without automatic mail opening? is on and you toggle the mail opening checkbox on, mail opening will automatically start.
author Zerotorescue
date Thu, 09 Sep 2010 10:53:19 +0200
parents 7249f9f1205a
children 582929c413c3 fb952805d8b7
files Core.lua
diffstat 1 files changed, 37 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/Core.lua	Wed Sep 08 22:18:07 2010 +0200
+++ b/Core.lua	Thu Sep 09 10:53:19 2010 +0200
@@ -1,18 +1,18 @@
 -- You can access this addon's object through: LibStub("AceAddon-3.0"):GetAddon("MailOpener")
 local MailOpener = LibStub("AceAddon-3.0"):NewAddon("MailOpener", "AceEvent-3.0", "AceTimer-3.0");
 
--- You can check if MailOpener is busy with LibStub("AceAddon-3.0"):GetAddon("MailOpener").busy (true or false/nil)
+-- You can check if MailOpener is busy with the global MailAddonBusy (if not MailAddonBusy then ...do something... end)
+-- MailAddonBusy will be nil when nothing is happening or filled with the addon name when MO is working
+-- Another addon can use this variable to indicate they're working too, MailOpener will then wait for that to finish
 
 local AutoOpenMail, MailOpenerConfig, lastAmount, lastQuickAuctionsStatus, freshList, mailboxEmptySoundPlayed;
 
 function MailOpener:OnInitialize()
 	local defaults = {
-		--BETA:global = {
-		--BETA:	uses = 0;
-		--BETA:},
 		profile = {
+			uses = 0,
 			general = {
-				defaultStatus = "_enabled",
+				defaultStatus = "disabled", -- addon enabled, but mail opening not auto on
 				defaultQAStatus = "__remember",
 				continueOpeningStackableItems = false,
 				autoDisableQAAutoMail = true,
@@ -141,6 +141,7 @@
 				print("|cff15ff00Mail Opener|r: |cff00ff00Enabling|r automatic opening of mail.");
 				
 				AutoOpenMail = true;
+				MailOpener:ScheduleOpen(false);
 			else
 				print("|cff15ff00Mail Opener|r: |cffff0000Disabling|r automatic opening of mail.");
 				
@@ -180,7 +181,7 @@
 		
 		MailOpenerConfig:Show();
 	
-		--BETA:if MailOpener.db.global.uses >= 15 then
+		--BETA:if MailOpener.db.profile.uses >= 15 then
 		--BETA:	MailOpener:ShowBetaPopup();
 		--BETA:end
 	end);
@@ -235,9 +236,7 @@
 	lastAmount = 0;
 	self.debugChannel = nil;
 	
-	--BETA:self.db.global.uses = ( self.db.global.uses + 1 );
-	
-	--BETA:if (self.db.global.uses % 15) == 0 then
+	--BETA:if (self.db.profile.uses % 15) == 0 then
 	--BETA:	-- Automatically show once every 15 uses
 	--BETA:	self:ShowBetaPopup();
 	--BETA:end
@@ -275,6 +274,12 @@
 	-- We need to know when opening has completed
 	self:RegisterMessage("MO_OPEN_COMPLETE");
 	
+	if self.db.profile.uses == 0 then
+		--TODO:statispopupdialog
+	end
+	
+	self.db.profile.uses = ( self.db.profile.uses + 1 );
+	
 	self:Debug("defaultStatus:" .. self.db.profile.general.defaultStatus);
 	-- Change the mail opening status according to our settings
 	if self.db.profile.general.defaultStatus == "_enabled" then
@@ -299,12 +304,14 @@
 	InboxTooMuchMail.Show = function() end
 	
 	if self.QuickAuctionsEnabled then
-		local QAMail = LibStub("AceAddon-3.0"):GetAddon("QuickAuctions"):GetModule("Mail");
+		local QAMail = LibStub("AceAddon-3.0"):GetAddon("QuickAuctions", true):GetModule("Mail", true);
 		
-		-- Hide the open all button
-		QAMail.massOpening:Hide();
-		-- Hide the x mail remaining text
-		QAMail.totalMail:Hide();
+		if QAMail then
+			-- Hide the open all button
+			QAMail.massOpening:Hide();
+			-- Hide the x mail remaining text
+			QAMail.totalMail:Hide();
+		end
 	end
 	
 	if self.db.profile.notifications.welcome then
@@ -418,15 +425,15 @@
 end
 
 function MailOpener:OpenNow()
-	self:Debug("OpenNow (" .. ((self.busy and "1") or "0") .. ")");
-	if not self.busy and MailFrame:IsVisible() and AutoOpenMail then
+	self:Debug("OpenNow (" .. ((MailAddonBusy and "1") or "0") .. ")");
+	if MailFrame:IsVisible() and AutoOpenMail then
 		self:Debug("OpenNow");
 			
 		-- BeanCounter is the only addon hiding the mail close button while busy, so we can look for that
 		local BeanCounterActive = not InboxCloseButton:IsVisible();
 		
-		if not BeanCounterActive then
-			-- BeanCounter is INACTIVE
+		if not BeanCounterActive and not MailAddonBusy then
+			-- No other addon is currently active
 			
 			self:CancelTimer(self.tmrTryAgain, true); -- Insurance
 			
@@ -443,25 +450,27 @@
 				QuickAuctionsAutoMail:Click();
 			end
 			
-			self.busy = true;
+			MailAddonBusy = self:GetName();
 			
 			self:Debug("MO_OPEN_MAIL");
 			
 			-- Summon the mail opening gods
 			self:SendMessage("MO_OPEN_MAIL");
 		else
-			-- BeanCounter is ACTIVE
-			self:Debug("BeanCounter active, waiting .5 seconds...");
+			-- Another addon is ACTIVE
+			self:Debug("Another addon active, waiting .5 seconds...");
 			
 			self:CancelTimer(self.tmrTryAgain, true); -- Insurance
-			-- Wait with summoning until BeanCounter is done, try again every 0.5 seconds
+			-- Try again every 0.5 seconds
 			self.tmrTryAgain = self:ScheduleTimer("OpenNow", 0.5);
 		end
 	end
 end
 
 function MailOpener:MO_OPEN_COMPLETE()
-	self.busy = false;
+	if MailAddonBusy == self:GetName() then
+		MailAddonBusy = nil;
+	end
 	
 	-- Try a recheck
 	self:Recheck();
@@ -516,7 +525,7 @@
 	-- and set to false 61 seconds afterwards with a recheck called instantly after it
 	
 	-- We're not refreshing while we're opening because it is automatically done when current batch was completely opened
-	if not freshList and not self.busy and MailFrame:IsVisible() then
+	if not freshList and MailFrame:IsVisible() then
 		self:Debug("|cff00ff00Recheck|r");
 		
 		-- If this isn't a fresh list (so messages weren't received within the last 60 seconds) and the mailbox wasn't closed
@@ -524,7 +533,7 @@
 		-- BeanCounter is the only addon hiding the mail close button while busy, so we can look for that
 		local BeanCounterActive = not InboxCloseButton:IsVisible();
 		
-		if not BeanCounterActive and AutoOpenMail then
+		if not BeanCounterActive and AutoOpenMail and not MailAddonBusy then
 			-- Query the server
 			CheckInbox();
 		end
@@ -544,7 +553,9 @@
 		print("|cff15ff00Mail Opener|r: Have a nice day. :)");
 	end
 	
-	self.busy = false;
+	if MailAddonBusy == self:GetName() then
+		MailAddonBusy = nil;
+	end
 	
 	-- We won't need this anymore
 	self:UnregisterEvent("MAIL_CLOSED");