Mercurial > wow > mailopener
diff Core.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/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
