reapack

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

about.hpp (3811B)


      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 #ifndef REAPACK_ABOUT_HPP
     19 #define REAPACK_ABOUT_HPP
     20 
     21 #include "dialog.hpp"
     22 
     23 #include "version.hpp"
     24 
     25 #include <map>
     26 #include <memory>
     27 #include <vector>
     28 
     29 class AboutDelegate;
     30 class Index;
     31 class ListView;
     32 class Menu;
     33 class Metadata;
     34 class RichEdit;
     35 class TabBar;
     36 struct Link;
     37 
     38 typedef std::shared_ptr<const Index> IndexPtr;
     39 
     40 class About : public Dialog {
     41 public:
     42   typedef std::shared_ptr<AboutDelegate> DelegatePtr;
     43 
     44   About();
     45   void setDelegate(const DelegatePtr &, bool focus = true);
     46   template<typename T>
     47   bool testDelegate() { return dynamic_cast<T *>(m_delegate.get()) != nullptr; }
     48 
     49   void setTitle(const std::string &);
     50   void setMetadata(const Metadata *, bool substitution = false);
     51   void setAction(const std::string &);
     52 
     53   TabBar *tabs() const { return m_tabs; }
     54   RichEdit *desc() const { return m_desc; }
     55   ListView *menu() const { return m_menu; }
     56   ListView *list() const { return m_list; }
     57 
     58 protected:
     59   void onInit() override;
     60   void onCommand(int, int) override;
     61   bool onKeyDown(int, int) override;
     62   void onClose() override;
     63 
     64 private:
     65   void selectLink(int control);
     66   void openLink(const Link *);
     67   void updateList();
     68 
     69   int m_currentIndex;
     70   std::map<int, std::vector<const Link *> > m_links;
     71 
     72   TabBar *m_tabs;
     73   RichEdit *m_desc;
     74   ListView *m_menu;
     75   ListView *m_list;
     76 
     77   DelegatePtr m_delegate;
     78   Serializer m_serializer;
     79 };
     80 
     81 class AboutDelegate {
     82 protected:
     83   friend About;
     84 
     85   virtual ~AboutDelegate() = default;
     86 
     87   virtual void init(About *) = 0;
     88   virtual void updateList(int) = 0;
     89   virtual bool fillContextMenu(Menu &, int) const = 0;
     90   virtual void itemActivated() = 0;
     91   virtual void itemCopy() = 0;
     92   virtual void onCommand(int) = 0;
     93 
     94   virtual const void *data() const = 0;
     95 };
     96 
     97 class AboutIndexDelegate : public AboutDelegate {
     98 public:
     99   AboutIndexDelegate(const IndexPtr &);
    100 
    101 protected:
    102   void init(About *) override;
    103   void updateList(int) override;
    104   bool fillContextMenu(Menu &, int) const override;
    105   void itemActivated() override { aboutPackage(); }
    106   void itemCopy() override;
    107   void onCommand(int) override;
    108 
    109   const void *data() const override
    110   {
    111     return static_cast<const void *>(m_index.get());
    112   }
    113 
    114 private:
    115   void initInstalledFiles();
    116   const Package *currentPackage() const;
    117   void findInBrowser();
    118   void aboutPackage();
    119   void install();
    120 
    121   IndexPtr m_index;
    122 
    123   About *m_dialog;
    124 };
    125 
    126 class AboutPackageDelegate : public AboutDelegate {
    127 public:
    128   AboutPackageDelegate(const Package *, const VersionName &current);
    129 
    130 protected:
    131   void init(About *) override;
    132   void updateList(int) override;
    133   bool fillContextMenu(Menu &, int) const override;
    134   void itemActivated() override { locate(); }
    135   void itemCopy() override { copySourceUrl(); }
    136   void onCommand(int) override;
    137 
    138   const void *data() const override
    139   {
    140     return static_cast<const void *>(m_package);
    141   }
    142 
    143 private:
    144   const Source *currentSource() const;
    145   void copySourceUrl();
    146   void locate();
    147 
    148   const Package *m_package;
    149   VersionName m_current;
    150   IndexPtr m_index; // keeps the package loaded in memory
    151 
    152   About *m_dialog;
    153 };
    154 
    155 #endif