Mercurial > wow > mailopener
changeset 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 | 2dd6005d41f3 |
| files | Core.lua Modules/Collected.lua Modules/OpenAll.lua |
| diffstat | 3 files changed, 161 insertions(+), 92 deletions(-) [+] |
line wrap: on
line diff
--- a/Core.lua Sun Sep 05 17:26:35 2010 +0200 +++ b/Core.lua Tue Sep 07 17:46:27 2010 +0200 @@ -1,7 +1,9 @@ -MailOpener = LibStub("AceAddon-3.0"):NewAddon("MailOpener", "AceEvent-3.0", "AceTimer-3.0"); +-- 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"); -local enabled = true; -local MailOpenerConfig, lastAmount, lastQuickAuctionsStatus, opening, freshList, mailboxEmptySoundPlayed; +-- You can check if MailOpener is busy with LibStub("AceAddon-3.0"):GetAddon("MailOpener").busy (true or false/nil) + +local AutoOpenMail, MailOpenerConfig, lastAmount, lastQuickAuctionsStatus, freshList, mailboxEmptySoundPlayed; function MailOpener:OnInitialize() local defaults = { @@ -24,8 +26,8 @@ Collected = true, }, notifications = { - welcome = true, - bye = true, + welcome = false, + bye = false, finishedCurrentBatch = true, mailboxIsEmpty = true, @@ -109,16 +111,43 @@ local check = CreateFrame("CheckButton", "cbMailOpenerEnable", MailFrame, "ChatConfigCheckButtonTemplate"); check:SetHeight(26); check:SetWidth(26); - check:SetChecked(enabled); + check:SetChecked(true); check:SetHitRectInsets(0, -80, 0, 0); check:SetScript("OnClick", function(self) - if self:GetChecked() then - MailOpener:Enable(); + if IsShiftKeyDown() then + -- Shift key = toggle addon on or off, since addon is already on there's only one option + + if not MailOpener:IsEnabled() then + print("|cff15ff00Mail Opener|r: Shift key was held down, so |cff00ff00enabling|r the entire addon as well as automatic opening of mail."); + + MailOpener:Enable(); + + -- The above calls MAIL_SHOW which changes AutoOpenMail, so we can't remember the old setting + AutoOpenMail = true; + + self:SetChecked(true); + else + print("|cff15ff00Mail Opener|r: Shift key was held down, so |cffff0000disabling|r the entire addon."); + + MailOpener:Disable(); + + self:SetChecked(false); + end else - MailOpener:Disable(); + -- Normal click + + if self:GetChecked() then + print("|cff15ff00Mail Opener|r: |cff00ff00Enabling|r automatic opening of mail."); + + AutoOpenMail = true; + else + print("|cff15ff00Mail Opener|r: |cffff0000Disabling|r automatic opening of mail."); + + AutoOpenMail = false; + end end end); - check.tooltip = "Toggle Mail Opener on or off."; + check.tooltip = "Toggle automatic mail opening on or off (you can force this by holding shift when opening the mailbox.\n\nHold the |cffffffffSHIFT|r key to disable the entire addon."; check:SetPoint("TOPLEFT", MailFrame, "TOPLEFT", 68, -13) if self.QuickAuctionsEnabled then @@ -222,7 +251,6 @@ self.btnConfig:Hide(); - enabled = false; MailOpener:Stop(); end @@ -248,11 +276,19 @@ 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 - enabled = true; - else - enabled = false; + AutoOpenMail = true; + self.cbOpenAll:SetChecked(true); + elseif self.db.profile.general.defaultStatus == "disabled" then + -- Disable auto opening but leave mail opener enabled + + AutoOpenMail = false; + self.cbOpenAll:SetChecked(false); + elseif self.db.profile.general.defaultStatus == "xdisabled" then + -- Disable entire addon + + MailOpener:Disable(); + self.cbOpenAll:SetChecked(false); end - self.cbOpenAll:SetChecked(enabled); self:ToggleQAStatus(); @@ -261,21 +297,12 @@ InboxTooMuchMail.Show = function() end if self.QuickAuctionsEnabled then - -- Go through all children of the mail frame to find the post button - local kids = { InboxFrame:GetChildren() }; + local QAMail = LibStub("AceAddon-3.0"):GetAddon("QuickAuctions"):GetModule("Mail"); - for _, child in ipairs(kids) do - if child then - local width = floor( child:GetWidth() + .5 ); - local height = floor( child:GetHeight() + .5 ); - - -- The open all button has a static width and height - if width == 130 and height == 24 then - child:Hide(); - break; - end - end - end + -- Hide the open all button + QAMail.massOpening:Hide(); + -- Hide the x mail remaining text + QAMail.totalMail:Hide(); end if self.db.profile.notifications.welcome then @@ -301,16 +328,29 @@ function MailOpener:MAIL_INBOX_UPDATE() local current, total = GetInboxNumItems(); - local tempLastAmount = lastAmount; - lastAmount = current; - - if current ~= tempLastAmount then - self:Debug("MAIL_INBOX_UPDATE - lastAmount:" .. tempLastAmount .. " - current:" .. current); + -- Calculate the amount of mail waiting that actually have attachments + -- If we just compare numbers we won't be including mail that isn't automatically deleted when opened, such as mail with attachments sent by other players + local currentMailWithAttachments = 0; + for i = 1, current do + local _, _, _, _, money, _, _, items = GetInboxHeaderInfo(i); + + if (items and items > 0) or (money and money > 0) then + currentMailWithAttachments = currentMailWithAttachments + 1; + end end - if current > tempLastAmount then + local tempLastAmount = lastAmount; + lastAmount = currentMailWithAttachments; + + if currentMailWithAttachments ~= tempLastAmount then + self:Debug("MAIL_INBOX_UPDATE - lastAmount:" .. tempLastAmount .. " - current:" .. currentMailWithAttachments); + end + + if currentMailWithAttachments > tempLastAmount then -- New messages arrived in our mailbox, so this was a refresh, so set a timer + self:Debug("MO_SERVER_SYNCED"); + -- Yell that we successfully synced with the server self:SendMessage("MO_SERVER_SYNCED"); @@ -338,12 +378,16 @@ -- Open the current mail self:ScheduleOpen(false); end - elseif current < tempLastAmount then + elseif currentMailWithAttachments < tempLastAmount then -- We lost a mail + -- TODO: NYI: May need to delay this until the mail is actually deleted + + self:Debug("MO_MAIL_EMPTIED"); + -- Yell that we successfully opened/removed a mail - self:SendMessage("MO_MAIL_DELETED"); - elseif (current == 50 and tempLastAmount == 50) then + self:SendMessage("MO_MAIL_EMPTIED"); + elseif (currentMailWithAttachments == 50 and tempLastAmount == 50) then if not IsShiftKeyDown() then -- Allow overriding of mailopening with the shift key @@ -351,8 +395,6 @@ self:ScheduleOpen(false); end end - - tempLastAmount = current; end function MailOpener:ScheduleOpen(continued) @@ -373,8 +415,8 @@ end function MailOpener:OpenNow() - self:Debug("OpenNow (" .. ((opening and "1") or "0") .. ")"); - if not opening and MailFrame:IsVisible() then + self:Debug("OpenNow (" .. ((self.busy and "1") or "0") .. ")"); + if not self.busy and 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 @@ -398,7 +440,7 @@ QuickAuctionsAutoMail:Click(); end - opening = true; + self.busy = true; self:Debug("MO_OPEN_MAIL"); @@ -416,7 +458,7 @@ end function MailOpener:MO_OPEN_COMPLETE() - opening = false; + self.busy = false; -- Try a recheck self:Recheck(); @@ -424,31 +466,37 @@ local current, total = GetInboxNumItems(); if (total - current) == 0 then - -- Play the sound + -- There is probably no unopenable mail remaining, so play the sound (if enabled) + if self.db.profile.notifications.mailboxEmptySound and (not MailOpener.db.profile.notifications.mailboxEmptySoundOnlyOnce or not mailboxEmptySoundPlayed) then PlaySoundFile(self.db.profile.notifications.mailboxEmptySoundFile); mailboxEmptySoundPlayed = true; end end - if self.db.profile.general.autoReenableQAAutoMail and self.QuickAuctionsEnabled and QuickAuctionsAutoMail and not QuickAuctionsAutoMail:GetChecked() then - -- If auto re-enable "QA Auto mail" is enabled and QA's auto mail is currently toggled OFF, turn it on - -- We need to do this with a :click to trigger the right events + if self.QuickAuctionsEnabled then + -- Quick Auctions enabled? + -- Toggle automailing as per settings - self:Debug("Turning automail |cff00ff00on|r."); - - QuickAuctionsAutoMail:Click(); - elseif self.db.profile.general.autoSetBackQAAutoMail and self.QuickAuctionsEnabled and QuickAuctionsAutoMail and lastQuickAuctionsStatus ~= QuickAuctionsAutoMail:GetChecked() then - -- If auto set back "QA Auto mail" is enabled and QA's auto mail is currently not the same as it was before starting, toggle it - -- We need to do this with a :click to trigger the right events - - if lastQuickAuctionsStatus then + if self.db.profile.general.autoReenableQAAutoMail and QuickAuctionsAutoMail and not QuickAuctionsAutoMail:GetChecked() then + -- If auto re-enable "QA Auto mail" is enabled and QA's auto mail is currently toggled OFF, turn it on + -- We need to do this with a :click to trigger the right events + self:Debug("Turning automail |cff00ff00on|r."); - else - self:Debug("Turning automail |cffff0000off|r."); + + QuickAuctionsAutoMail:Click(); + elseif self.db.profile.general.autoSetBackQAAutoMail and QuickAuctionsAutoMail and lastQuickAuctionsStatus ~= QuickAuctionsAutoMail:GetChecked() then + -- If auto set back "QA Auto mail" is enabled and QA's auto mail is currently not the same as it was before starting, toggle it + -- We need to do this with a :click to trigger the right events + + if lastQuickAuctionsStatus then + self:Debug("Turning automail |cff00ff00on|r."); + else + self:Debug("Turning automail |cffff0000off|r."); + end + + QuickAuctionsAutoMail:Click(); end - - QuickAuctionsAutoMail:Click(); end if self.db.profile.general.continueOpening then @@ -463,7 +511,9 @@ -- Freshlist prevents this from being run too often -- It is set to true after a server sync -- and set to false 61 seconds afterwards with a recheck called instantly after it - if not freshList and MailFrame:IsVisible() then + + -- 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 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 @@ -471,7 +521,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 then + if not BeanCounterActive and AutoOpenMail then -- Query the server CheckInbox(); end @@ -491,7 +541,7 @@ print("|cff15ff00Mail Opener|r: Have a nice day. :)"); end - opening = false; + self.busy = false; -- We won't need this anymore self:UnregisterEvent("MAIL_CLOSED"); @@ -541,15 +591,8 @@ if MailOpener.PostalEnabled and Postal then -- Postal must be enabled - -- Remember the setting in Postal - Postal.db.profile.ModuleEnabledState[name] = status; - - -- Toggle module - if status then - Postal:GetModule(name):Enable(); - else - Postal:GetModule(name):Disable(); - end + -- Toggle module (let Postal handle this) + Postal.ToggleModule(nil, name, Postal:GetModule(name), status); end end
--- a/Modules/Collected.lua Sun Sep 05 17:26:35 2010 +0200 +++ b/Modules/Collected.lua Tue Sep 07 17:46:27 2010 +0200 @@ -1,6 +1,12 @@ local MailOpener = LibStub("AceAddon-3.0"):GetAddon("MailOpener"); local Collected = MailOpener:NewModule("Collected", "AceEvent-3.0", "AceTimer-3.0"); +--[[ +Module name: Collected +Description: Shows a simple summary of what has been collected at the mailbox. +Required: No. +]] + local previousGold, earned, sessionEarned; local previousFreeSlotsAvailable, itemsGained, sessionItemsgained; local previousMailCount, mailOpened, sessionMailOpened;
--- 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
