reapack

Package manager for REAPER
Log | Files | Refs | Submodules | README | LICENSE

report.cpp (2554B)


      1 /* ReaPack: Package manager for REAPER
      2  * Copyright (C) 2015-2025  Christian Fillion
      3  *
      4  * This program is free software: you can redistribute it and/or modify
      5  * it under the terms of the GNU Lesser General Public License as published by
      6  * the Free Software Foundation, either version 3 of the License, or
      7  * (at your option) any later version.
      8  *
      9  * This program is distributed in the hope that it will be useful,
     10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     12  * GNU Lesser General Public License for more details.
     13  *
     14  * You should have received a copy of the GNU Lesser General Public License
     15  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
     16  */
     17 
     18 #include "report.hpp"
     19 
     20 #include "receipt.hpp"
     21 #include "resource.hpp"
     22 #include "tabbar.hpp"
     23 #include "win32.hpp"
     24 
     25 Report::Report(const Receipt *receipt)
     26   : Dialog(IDD_REPORT_DIALOG), m_receipt(receipt), m_empty(true)
     27 {
     28 }
     29 
     30 void Report::onInit()
     31 {
     32   Dialog::onInit();
     33 
     34   m_tabbar = createControl<TabBar>(IDC_TABS, this);
     35   m_tabbar->onTabChange >> [=] (const int i) {
     36     Win32::setWindowText(getControl(IDC_REPORT), m_pages[i].c_str());
     37   };
     38 
     39   const ReceiptPage pages[] {
     40     m_receipt->installedPage(),
     41     m_receipt->removedPage(),
     42     m_receipt->exportedPage(),
     43     m_receipt->errorPage(),
     44   };
     45 
     46   for(const auto &page : pages)
     47     addPage(page);
     48 
     49   updateLabel();
     50 
     51   SetFocus(getControl(IDOK));
     52 
     53   if(m_receipt->test(Receipt::RestartNeededFlag))
     54     startTimer(1);
     55 }
     56 
     57 void Report::onTimer(int timer)
     58 {
     59   stopTimer(timer);
     60 
     61   Win32::messageBox(handle(),
     62     "One or more native REAPER extensions were installed.\n"
     63     "These newly installed files won't be loaded until REAPER is restarted.",
     64     "ReaPack Notice", MB_OK);
     65 }
     66 
     67 void Report::updateLabel()
     68 {
     69   const char *label;
     70 
     71   if(m_receipt->flags() == Receipt::ErrorFlag)
     72     label = "Operation failed. The following error(s) occured:";
     73   else if(m_receipt->test(Receipt::ErrorFlag))
     74     label = "The operation was partially completed (one or more errors occured):";
     75   else if(m_receipt->test(Receipt::InstalledOrRemoved))
     76     label = "All done! Description of the changes:";
     77   else
     78     label = "Operation completed successfully!";
     79 
     80   Win32::setWindowText(getControl(IDC_LABEL), label);
     81 }
     82 
     83 void Report::addPage(const ReceiptPage &page)
     84 {
     85   m_pages.emplace_back(page.contents());
     86   m_tabbar->addTab({page.title().c_str()});
     87 
     88   if(m_empty && !page.empty()) {
     89     m_tabbar->setCurrentIndex(m_tabbar->count() - 1);
     90     m_empty = false;
     91   }
     92 }