Mercurial > wow > mailopener
comparison 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 |
comparison
equal
deleted
inserted
replaced
| 2:57ba1593ac42 | 3:c6f0976069c7 |
|---|---|
| 1 local MailOpener = LibStub("AceAddon-3.0"):GetAddon("MailOpener"); | 1 local MailOpener = LibStub("AceAddon-3.0"):GetAddon("MailOpener"); |
| 2 local OpenAll = MailOpener:NewModule("OpenAll", "AceEvent-3.0", "AceTimer-3.0"); | 2 local OpenAll = MailOpener:NewModule("OpenAll", "AceEvent-3.0", "AceTimer-3.0"); |
| 3 | |
| 4 --[[ | |
| 5 Module name: OpenAll | |
| 6 Description: The actual mail opening initiated by the core. | |
| 7 Required: Yes. | |
| 8 | |
| 9 Dev notes: | |
| 10 When shift clicking the Open All button it should override all filters. | |
| 11 ]] | |
| 3 | 12 |
| 4 local MAIL_ITEM_INDEX, mailTimer, inventoryFull, inventoryFullSoundPlayed, opening, lastSync, numCurrentMail, numHiddenMail, continue; | 13 local MAIL_ITEM_INDEX, mailTimer, inventoryFull, inventoryFullSoundPlayed, opening, lastSync, numCurrentMail, numHiddenMail, continue; |
| 5 | 14 |
| 6 function OpenAll:OnInitialize() | 15 function OpenAll:OnInitialize() |
| 7 local defaults = { | 16 local defaults = { |
| 77 self.timeLeftFrame = frame; | 86 self.timeLeftFrame = frame; |
| 78 end | 87 end |
| 79 | 88 |
| 80 self.timeLeftFrame:Show(); | 89 self.timeLeftFrame:Show(); |
| 81 | 90 |
| 82 -- Go through all children of the mail frame to find QA's elements and hide these | 91 -- Go through all children of the mail frame to find QA's element and hide it |
| 83 local kids = { MailFrame:GetChildren() }; | 92 local kids = { MailFrame:GetChildren() }; |
| 84 | 93 |
| 85 for _, child in ipairs(kids) do | 94 for _, child in ipairs(kids) do |
| 86 if child and child.text then | 95 if child and child.text then |
| 87 child.text:Hide(); | 96 child.text:Hide(); |
| 146 self:RegisterEvent("BAG_UPDATE"); | 155 self:RegisterEvent("BAG_UPDATE"); |
| 147 | 156 |
| 148 -- We need to know when to start opening | 157 -- We need to know when to start opening |
| 149 self:RegisterMessage("MO_OPEN_MAIL", "Open"); | 158 self:RegisterMessage("MO_OPEN_MAIL", "Open"); |
| 150 self:RegisterMessage("MO_SERVER_SYNCED"); | 159 self:RegisterMessage("MO_SERVER_SYNCED"); |
| 151 self:RegisterMessage("MO_MAIL_DELETED"); | 160 self:RegisterMessage("MO_MAIL_EMPTIED"); |
| 152 | 161 |
| 153 self:CancelTimer(self.tmrTimeRemaining, true); | 162 self:CancelTimer(self.tmrTimeRemaining, true); |
| 154 self.tmrTimeRemaining = self:ScheduleRepeatingTimer("UpdateTimer", 1); | 163 self.tmrTimeRemaining = self:ScheduleRepeatingTimer("UpdateTimer", 1); |
| 155 self:UpdateTimer(); | 164 self:UpdateTimer(); |
| 156 end | 165 end |
| 167 self:UnregisterEvent("BAG_UPDATE"); | 176 self:UnregisterEvent("BAG_UPDATE"); |
| 168 | 177 |
| 169 -- We no longer care | 178 -- We no longer care |
| 170 self:UnregisterMessage("MO_OPEN_MAIL"); | 179 self:UnregisterMessage("MO_OPEN_MAIL"); |
| 171 self:UnregisterMessage("MO_SERVER_SYNCED"); | 180 self:UnregisterMessage("MO_SERVER_SYNCED"); |
| 172 self:UnregisterMessage("MO_MAIL_DELETED"); | 181 self:UnregisterMessage("MO_MAIL_EMPTIED"); |
| 173 | 182 |
| 174 self:CancelTimer(self.tmrMailOpener, true); | 183 self:CancelTimer(self.tmrMailOpener, true); |
| 175 self:CancelTimer(self.tmrTimeRemaining, true); | 184 self:CancelTimer(self.tmrTimeRemaining, true); |
| 176 | 185 |
| 177 self:SetOpeningStatus(false); | 186 self:SetOpeningStatus(false); |
| 186 lastSync = GetTime(); | 195 lastSync = GetTime(); |
| 187 | 196 |
| 188 self:UpdateMailCount(); | 197 self:UpdateMailCount(); |
| 189 end | 198 end |
| 190 | 199 |
| 191 function OpenAll:MO_MAIL_DELETED() | 200 function OpenAll:MO_MAIL_EMPTIED() |
| 192 self:Debug("MO_MAIL_DELETED"); | 201 -- A mail has been processed so we can process the next |
| 193 | |
| 194 -- A mail has been deleted so we can process the next | |
| 195 continue = true; | 202 continue = true; |
| 196 | 203 |
| 197 self:UpdateMailCount(); | 204 self:UpdateTimer(); |
| 198 end | 205 end |
| 199 | 206 |
| 200 function OpenAll:UpdateMailCount() | 207 function OpenAll:UpdateMailCount() |
| 201 local numItems, totalItems = GetInboxNumItems(); | 208 local numItems, totalItems = GetInboxNumItems(); |
| 202 | 209 |
| 203 numCurrentMail = numItems; | 210 numCurrentMail = numItems; |
| 204 numHiddenMail = ( totalItems - numItems ); | 211 numHiddenMail = ( totalItems - numItems ); |
| 205 | |
| 206 self:UpdateTimer(); | |
| 207 end | 212 end |
| 208 | 213 |
| 209 function OpenAll:BAG_UPDATE() | 214 function OpenAll:BAG_UPDATE() |
| 210 -- If the bags are updated we should check if the inventory is full again | 215 -- If the bags are updated we should check if the inventory is full again |
| 211 inventoryFull = false; | 216 inventoryFull = false; |
| 430 self:OpenNext(); | 435 self:OpenNext(); |
| 431 | 436 |
| 432 return; | 437 return; |
| 433 else | 438 else |
| 434 continue = false; | 439 continue = false; |
| 440 | |
| 441 self:Debug("MO_OPENING_MAIL"); | |
| 435 | 442 |
| 436 -- Notifiy other modules of opening | 443 -- Notifiy other modules of opening |
| 437 self:SendMessage("MO_OPENING_MAIL"); | 444 self:SendMessage("MO_OPENING_MAIL"); |
| 438 | 445 |
| 439 -- Open current mail | 446 -- Open current mail |
| 468 if MailOpener.db.profile.notifications.finishedCurrentBatch then | 475 if MailOpener.db.profile.notifications.finishedCurrentBatch then |
| 469 print("Finished opening the current batch."); | 476 print("Finished opening the current batch."); |
| 470 end | 477 end |
| 471 | 478 |
| 472 self:SetOpeningStatus(false); | 479 self:SetOpeningStatus(false); |
| 473 | 480 |
| 474 self:Debug("MO_OPEN_COMPLETE"); | 481 self:Debug("MO_OPEN_COMPLETE"); |
| 475 | 482 |
| 476 -- Report that we're all done | 483 -- Report that we're all done |
| 477 self:SendMessage("MO_OPEN_COMPLETE"); | 484 self:SendMessage("MO_OPEN_COMPLETE"); |
| 478 end | 485 end |
| 498 continue = true; | 505 continue = true; |
| 499 self:OpenNext(); | 506 self:OpenNext(); |
| 500 end | 507 end |
| 501 | 508 |
| 502 local mailRemainingPatterns = { | 509 local mailRemainingPatterns = { |
| 503 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)"; | 510 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)."; |
| 504 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)"; | 511 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)."; |
| 505 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)"; | 512 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)."; |
| 513 nextRefresh = "|cffffffff%d|r/|cffffffff%d|r mail remaining, next refresh in |cffffffff%d|r seconds."; | |
| 506 waitingBatch = "|cffffffff%d|r/|cffffffff%d|r mail remaining - waiting for something from the current batch to be opened..."; | 514 waitingBatch = "|cffffffff%d|r/|cffffffff%d|r mail remaining - waiting for something from the current batch to be opened..."; |
| 507 waitingSync = "|cffffffff%d|r/|cffffffff%d|r mail remaining - waiting for the next mailbox refresh..."; | 515 waitingSync = "|cffffffff%d|r/|cffffffff%d|r mail remaining - waiting for the next mailbox refresh..."; |
| 508 soon = "|cffffffff%d|r/|cffffffff%d|r mail remaining - everything will be opened soon..."; | 516 soon = "|cffffffff%d|r/|cffffffff%d|r mail remaining - everything will be opened soon..."; |
| 509 }; | 517 }; |
| 510 | 518 |
| 511 function OpenAll:UpdateTimer() | 519 function OpenAll:UpdateTimer() |
| 512 if lastSync then | 520 if lastSync then |
| 521 self:UpdateMailCount(); | |
| 522 | |
| 513 -- Calculate the total amount of mail waiting | 523 -- Calculate the total amount of mail waiting |
| 514 local numTotalMail = ( numHiddenMail + numCurrentMail ); | 524 local numTotalMail = ( numHiddenMail + numCurrentMail ); |
| 515 | 525 |
| 516 -- Resize the font based on mail left so the counter always fits perfectly | 526 -- Resize the font based on mail left so the counter always fits perfectly |
| 517 if numTotalMail < 100 then | 527 if numTotalMail < 100 then |
| 520 self.timeLeftFrame.text:SetFont(GameFontHighlight:GetFont(), 24, "THICKOUTLINE"); | 530 self.timeLeftFrame.text:SetFont(GameFontHighlight:GetFont(), 24, "THICKOUTLINE"); |
| 521 else | 531 else |
| 522 self.timeLeftFrame.text:SetFont(GameFontHighlight:GetFont(), 18, "THICKOUTLINE"); | 532 self.timeLeftFrame.text:SetFont(GameFontHighlight:GetFont(), 18, "THICKOUTLINE"); |
| 523 end | 533 end |
| 524 self.timeLeftFrame.text:SetText(numTotalMail); | 534 self.timeLeftFrame.text:SetText(numTotalMail); |
| 525 | 535 |
| 526 if numHiddenMail > 0 then | 536 -- Calculate the next server sync based on the last server sync plus sync interval |
| 527 -- Calculate the next server sync based on the last server sync plus sync interval | 537 local nextSync = ( lastSync + 61 ); |
| 528 local nextSync = ( lastSync + 61 ); | 538 |
| 529 | 539 -- Calculate the timer remaining untill the next sync |
| 530 -- Calculate the timer remaining untill the next sync | 540 local timeRemaining = floor( nextSync - GetTime() ); |
| 531 local timeRemaining = floor( nextSync - GetTime() ); | 541 |
| 542 if numHiddenMail > 0 or timeRemaining > 0 then | |
| 543 -- If there is still mail being hidden or the timer is still know, display stuff | |
| 544 | |
| 532 -- If the next sync was already due, our nextSync calculation was wrong and we must wait a little longer (lag?) | 545 -- If the next sync was already due, our nextSync calculation was wrong and we must wait a little longer (lag?) |
| 533 local syncTimeOut = false; | 546 local syncTimeOut = false; |
| 534 -- If time remaining is below 0, next sync should be soon | 547 -- If time remaining is below 0, next sync should be soon |
| 535 if timeRemaining < 0 then | 548 if timeRemaining < 0 then |
| 536 timeRemaining = 0; | 549 timeRemaining = 0; |
| 545 local minutes = floor( timeRequired / 60 ); | 558 local minutes = floor( timeRequired / 60 ); |
| 546 local seconds = floor( timeRequired % 60 ); | 559 local seconds = floor( timeRequired % 60 ); |
| 547 | 560 |
| 548 local remainingText; | 561 local remainingText; |
| 549 if syncTimeOut then | 562 if syncTimeOut then |
| 563 -- Previous server sync was expected earlier, notify user | |
| 564 | |
| 550 if numCurrentMail == 50 then | 565 if numCurrentMail == 50 then |
| 566 -- Sync couldn't occur because we were still waiting for the current batch to be opened | |
| 551 remainingText = format(mailRemainingPatterns.waitingBatch, numCurrentMail, numTotalMail); | 567 remainingText = format(mailRemainingPatterns.waitingBatch, numCurrentMail, numTotalMail); |
| 552 else | 568 else |
| 553 remainingText = format(mailRemainingPatterns.waitingSync, numCurrentMail, numTotalMail); | 569 remainingText = format(mailRemainingPatterns.waitingSync, numCurrentMail, numTotalMail); |
| 554 end | 570 end |
| 571 elseif numHiddenMail == 0 then | |
| 572 -- If no hidden mail is remaining, only show the timer for as long as we can be sure | |
| 573 | |
| 574 remainingText = format(mailRemainingPatterns.nextRefresh, numCurrentMail, numTotalMail, timeRemaining); | |
| 555 elseif minutes ~= 0 then | 575 elseif minutes ~= 0 then |
| 556 if seconds ~= 0 then | 576 if seconds ~= 0 then |
| 557 remainingText = format(mailRemainingPatterns.minutesSeconds, numCurrentMail, numTotalMail, minutes, seconds, timeRemaining); | 577 remainingText = format(mailRemainingPatterns.minutesSeconds, numCurrentMail, numTotalMail, minutes, seconds, timeRemaining); |
| 558 else | 578 else |
| 559 remainingText = format(mailRemainingPatterns.minutes, numCurrentMail, numTotalMail, minutes, timeRemaining); | 579 remainingText = format(mailRemainingPatterns.minutes, numCurrentMail, numTotalMail, minutes, timeRemaining); |
| 563 else | 583 else |
| 564 remainingText = format(mailRemainingPatterns.soon, numCurrentMail, numTotalMail); | 584 remainingText = format(mailRemainingPatterns.soon, numCurrentMail, numTotalMail); |
| 565 end | 585 end |
| 566 | 586 |
| 567 self.timeLeftFrame.smallText:SetText(remainingText); | 587 self.timeLeftFrame.smallText:SetText(remainingText); |
| 568 elseif numHiddenMail == 0 then | 588 else |
| 569 self.timeLeftFrame.smallText:SetText(""); | 589 self.timeLeftFrame.smallText:SetText(""); |
| 570 end | 590 end |
| 571 end | 591 end |
| 572 end | 592 end |
| 573 | 593 |
