comparison Modules/OpenAll.lua @ 131:f662ee4d9c05

Fixed the retrieval of a single attachment from mail when you are close to the keep free space limit.
author Zerotorescue
date Wed, 20 Oct 2010 22:32:51 +0200
parents 981c6ac45a3f
children 4b4e25bf2c2e
comparison
equal deleted inserted replaced
130:43a7124c9847 131:f662ee4d9c05
8 --[[ 8 --[[
9 Dev notes: 9 Dev notes:
10 When shift clicking the Open All button it should override all filters. 10 When shift clicking the Open All button it should override all filters.
11 ]] 11 ]]
12 12
13 local MAIL_ITEM_INDEX, MAIL_OPEN_EVERYTHING, mailTimer, inventoryFull, inventoryFullSoundPlayed, inventoryFullSoundPlayedThisVisit, opening, lastSync, numCurrentMail, numHiddenMail, continue, firstOpenThisSync; 13 local MAIL_ITEM_INDEX, MAIL_OPEN_EVERYTHING, mailTimer, inventoryFull, inventoryFullSoundPlayed, inventoryFullSoundPlayedThisVisit, opening, lastSync, numCurrentMail, numHiddenMail, continue, firstOpenThisSync, takingSingleItem;
14 14
15 function mod:OnInitialize() 15 function mod:OnInitialize()
16 local defaults = { 16 local defaults = {
17 profile = { 17 profile = {
18 speed = 0.05, 18 speed = 0.05,
347 function mod:BAG_UPDATE() 347 function mod:BAG_UPDATE()
348 -- If the bags are updated we should check if the inventory is full again 348 -- If the bags are updated we should check if the inventory is full again
349 inventoryFull = false; 349 inventoryFull = false;
350 -- Replay sound 350 -- Replay sound
351 inventoryFullSoundPlayed = nil; 351 inventoryFullSoundPlayed = nil;
352
353 if opening and takingSingleItem then
354 self:ScheduleTimer("Continue", self.db.profile.speed);
355 end
352 end 356 end
353 357
354 -- We registered this event to look for the inventory full error message because this is faster than counting the amount of items in the inventory all the time 358 -- We registered this event to look for the inventory full error message because this is faster than counting the amount of items in the inventory all the time
355 function mod:UI_ERROR_MESSAGE(e, errorMessage) 359 function mod:UI_ERROR_MESSAGE(e, errorMessage)
356 if errorMessage == ERR_INV_FULL then 360 if errorMessage == ERR_INV_FULL then
452 end 456 end
453 457
454 return; -- not auction mail 458 return; -- not auction mail
455 end 459 end
456 460
461 local slotsAvailable;
462
457 function mod:OpenMail(index) 463 function mod:OpenMail(index)
458 if index and index > 0 then 464 if index and index > 0 then
459 -- LUA arrays start at 1, so mail with index 0 doesn't exist, so we're finished 465 -- LUA arrays start at 1, so mail with index 0 doesn't exist, so we're finished
460 466
461 local sender, subject, gold, cod, _, items, _, _, _, _, isGM = select(3, GetInboxHeaderInfo(index)); 467 local sender, subject, gold, cod, _, items, _, _, _, _, isGM = select(3, GetInboxHeaderInfo(index));
486 492
487 return; 493 return;
488 elseif ((gold and gold > 0) or (items and items > 0)) then 494 elseif ((gold and gold > 0) or (items and items > 0)) then
489 -- Mail with some sort of attachments 495 -- Mail with some sort of attachments
490 496
491 local slotsAvailable;
492 if self.db.profile.keepFreeSpace > 0 then 497 if self.db.profile.keepFreeSpace > 0 then
493 slotsAvailable = 0; 498 slotsAvailable = 0;
494 499
495 -- First find out the amount of empty bag slots 500 -- First find out the amount of empty bag slots
496 for bag = 0, NUM_BAG_SLOTS do 501 for bag = 0, NUM_BAG_SLOTS do
613 -- If we still have slots available, then loot this one item 618 -- If we still have slots available, then loot this one item
614 619
615 self:Debug("Taking attachment " .. attachIndex); 620 self:Debug("Taking attachment " .. attachIndex);
616 621
617 TakeInboxItem(index, attachIndex); 622 TakeInboxItem(index, attachIndex);
623 takingSingleItem = true;
624
625 -- We want to open the next attachment for this same mail again, so set the index one back
626 MAIL_ITEM_INDEX = ( MAIL_ITEM_INDEX + 1 );
618 627
619 -- Gained an item, lost an available slot 628 -- Gained an item, lost an available slot
620 slotsAvailable = ( slotsAvailable - 1 ); 629 slotsAvailable = ( slotsAvailable - 1 );
630
631 break;
621 else 632 else
622 -- No more room available, announce and go to next item 633 -- No more room available, announce and go to next item
623 if MailOpener.db.profile.notifications.skipped.all and onlyShowOnceCheck and MailOpener.db.profile.notifications.skipped.keepFreeSpaceLimit then 634 if MailOpener.db.profile.notifications.skipped.all and onlyShowOnceCheck and MailOpener.db.profile.notifications.skipped.keepFreeSpaceLimit then
624 print(skippingString:format(index, subject, L["keep free space limit"])); 635 print(skippingString:format(index, subject, L["keep free space limit"]));
625 end 636 end
644 else 655 else
645 print(L["Processing %d: %s"]:format(index, subject)); 656 print(L["Processing %d: %s"]:format(index, subject));
646 end 657 end
647 end 658 end
648 659
660 self:CancelTimer(self.tmrMailOpener, true);
649 -- And prepare for the next 661 -- And prepare for the next
650 self.tmrMailOpener = self:ScheduleTimer("OpenNext", self.db.profile.speed); 662 self.tmrMailOpener = self:ScheduleTimer("OpenNext", self.db.profile.speed);
651 end 663 end
652 end 664 end
653 else 665 else
686 -- Open it 698 -- Open it
687 self:OpenMail(MAIL_ITEM_INDEX); 699 self:OpenMail(MAIL_ITEM_INDEX);
688 else 700 else
689 -- Try again at the next interval 701 -- Try again at the next interval
690 702
703 self:CancelTimer(self.tmrMailOpener, true);
691 self.tmrMailOpener = self:ScheduleTimer("OpenNext", self.db.profile.speed); 704 self.tmrMailOpener = self:ScheduleTimer("OpenNext", self.db.profile.speed);
692 end 705 end
693 end 706 end
694 707
695 function mod:Continue() 708 function mod:Continue()
696 continue = true; 709 continue = true;
697 self:OpenNext(); 710 takingSingleItem = nil;
698 end 711 end
699 712
700 local mailRemainingPatterns = { 713 local mailRemainingPatterns = {
701 minutesSeconds = L["|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)."], 714 minutesSeconds = L["|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)."],
702 minutes = L["|cffffffff%d|r/|cffffffff%d|r mail remaining, opening everything will take about |cffffffff%d|r minutes (next refresh in |cffffffff%d|r seconds)."], 715 minutes = L["|cffffffff%d|r/|cffffffff%d|r mail remaining, opening everything will take about |cffffffff%d|r minutes (next refresh in |cffffffff%d|r seconds)."],
799 MAIL_ITEM_INDEX = 0; 812 MAIL_ITEM_INDEX = 0;
800 -- Reset open everything state 813 -- Reset open everything state
801 MAIL_OPEN_EVERYTHING = nil; 814 MAIL_OPEN_EVERYTHING = nil;
802 -- Stopped opening, so allow to continue 815 -- Stopped opening, so allow to continue
803 continue = true; 816 continue = true;
817
818 takingSingleItem = nil;
804 819
805 self:SetOpeningStatus(false); 820 self:SetOpeningStatus(false);
806 end 821 end
807 822
808 function mod:SetOpeningStatus(openingStatus) 823 function mod:SetOpeningStatus(openingStatus)