1 /* Copyright 2013-2019 MultiMC Contributors
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #pragma once
17 
18 #include <QMainWindow>
19 
20 #include "minecraft/MinecraftInstance.h"
21 #include "pages/BasePage.h"
22 #include <MultiMC.h>
23 
24 class ModFolderModel;
25 namespace Ui
26 {
27 class ModFolderPage;
28 }
29 
30 class ModFolderPage : public QMainWindow, public BasePage
31 {
32     Q_OBJECT
33 
34 public:
35     explicit ModFolderPage(
36         BaseInstance *inst,
37         std::shared_ptr<ModFolderModel> mods,
38         QString id,
39         QString iconName,
40         QString displayName,
41         QString helpPage = "",
42         QWidget *parent = 0
43     );
44     virtual ~ModFolderPage();
45 
setFilter(const QString & filter)46     void setFilter(const QString & filter)
47     {
48         m_fileSelectionFilter = filter;
49     }
50 
displayName()51     virtual QString displayName() const override
52     {
53         return m_displayName;
54     }
icon()55     virtual QIcon icon() const override
56     {
57         return MMC->getThemedIcon(m_iconName);
58     }
id()59     virtual QString id() const override
60     {
61         return m_id;
62     }
helpPage()63     virtual QString helpPage() const override
64     {
65         return m_helpName;
66     }
67     virtual bool shouldDisplay() const override;
68 
69     virtual void openedImpl() override;
70     virtual void closedImpl() override;
71 protected:
72     bool eventFilter(QObject *obj, QEvent *ev) override;
73     bool modListFilter(QKeyEvent *ev);
74     QMenu * createPopupMenu() override;
75 
76 protected:
77     BaseInstance *m_inst = nullptr;
78 
79 protected:
80     Ui::ModFolderPage *ui = nullptr;
81     std::shared_ptr<ModFolderModel> m_mods;
82     QSortFilterProxyModel *m_filterModel = nullptr;
83     QString m_iconName;
84     QString m_id;
85     QString m_displayName;
86     QString m_helpName;
87     QString m_fileSelectionFilter;
88     QString m_viewFilter;
89     bool m_controlsEnabled = true;
90 
91 public
92 slots:
93     void modCurrent(const QModelIndex &current, const QModelIndex &previous);
94 
95 private
96 slots:
97     void modItemActivated(const QModelIndex &index);
98     void on_filterTextChanged(const QString & newContents);
99     void on_RunningState_changed(bool running);
100     void on_actionAdd_triggered();
101     void on_actionRemove_triggered();
102     void on_actionEnable_triggered();
103     void on_actionDisable_triggered();
104     void on_actionView_Folder_triggered();
105     void on_actionView_configs_triggered();
106     void ShowContextMenu(const QPoint &pos);
107 };
108 
109 class CoreModFolderPage : public ModFolderPage
110 {
111 public:
112     explicit CoreModFolderPage(BaseInstance *inst, std::shared_ptr<ModFolderModel> mods, QString id,
113                                QString iconName, QString displayName, QString helpPage = "",
114                                QWidget *parent = 0);
~CoreModFolderPage()115     virtual ~CoreModFolderPage()
116     {
117     }
118     virtual bool shouldDisplay() const;
119 };
120