summaryrefslogtreecommitdiff
path: root/src/modlist.h
blob: aeff799ae2e8a12e3d658b1cc8411d4d35a9b29e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
/*
Copyright (C) 2012 Sebastian Herbord. All rights reserved.

This file is part of Mod Organizer.

Mod Organizer is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

Mod Organizer is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with Mod Organizer.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef MODLIST_H
#define MODLIST_H


#include "categories.h"
#include "nexusinterface.h"
#include "modinfo.h"
#include "profile.h"

#include <QFile>
#include <QListWidget>
#include <QNetworkReply>
#include <QNetworkAccessManager>

#include <set>
#include <vector>
#include <QVector>


/**
 * Model presenting an overview of the installed mod
 * This is used in a view in the main window of MO. It combines general information about
 * the mods from ModInfo with status information from the Profile
 **/
class ModList : public QAbstractItemModel
{
  Q_OBJECT

public:

  enum EColumn {
    COL_NAME,
    COL_FLAGS,
    COL_CATEGORY,
    COL_MODID,
    COL_VERSION,
    COL_PRIORITY,

    COL_LASTCOLUMN = COL_PRIORITY
  };

public:

  /**
   * @brief constructor
   * @todo ensure this view works without a profile set, otherwise there are intransparent dependencies on the initialisation order
   **/
  ModList(QObject *parent = NULL);

  /**
   * @brief set the profile used for status information
   *
   * @param profile the profile to use
   **/
  void setProfile(Profile *profile);

  /**
   * @brief retrieve the current sorting mode
   * @note this is used to store the sorting mode between sessions
   * @return current sorting mode, encoded to be compatible to previous versions
   **/
  int getCurrentSortingMode() const;

  /**
   * @brief remove the specified mod without asking for confirmation
   * @param row the row to remove
   */
  void removeRowForce(int row);

  void notifyChange(int rowStart, int rowEnd = -1);
  static QString getColumnName(int column);

  void changeModPriority(int sourceIndex, int newPriority);

public: // implementation of virtual functions of QAbstractItemModel

  virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
  virtual bool hasChildren(const QModelIndex &parent = QModelIndex()) const;
  virtual int columnCount(const QModelIndex &parent = QModelIndex()) const;
  virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
  virtual bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
  virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
  virtual Qt::ItemFlags flags(const QModelIndex &modelIndex) const;
  virtual Qt::DropActions supportedDropActions() const { return Qt::MoveAction | Qt::CopyAction; }
  virtual QStringList mimeTypes() const;
  virtual bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent);
  virtual void removeRow(int row, const QModelIndex &parent);

  virtual QModelIndex index(int row, int column,
                            const QModelIndex &parent = QModelIndex()) const;
  virtual QModelIndex parent(const QModelIndex &child) const;

  virtual QMap<int, QVariant> itemData(const QModelIndex &index) const;

public slots:

  void dropModeUpdate(bool dropOnItems);

signals:

  /**
   * @brief emitted whenever the sorting in the list was changed by the user
   *
   * the sorting of the list can only be manually changed if the list is sorted by priority
   * in which case the move is intended to change the priority of a mod
   **/
  void modorder_changed();

  /**
   * @brief emitted when the model wants a text to be displayed by the UI
   *
   * @param message the message to display
   **/
  void showMessage(const QString &message);

  /**
   * @brief signals change to the count of headers
   */
  void resizeHeaders();

  /**
   * @brief requestColumnSelect is emitted whenever the user requested a menu to select visible columns
   * @param pos the position to display the menu at
   */
  void requestColumnSelect(QPoint pos);

  /**
   * @brief emitted to remove a file origin
   * @param name name of the orign to remove
   */
  void removeOrigin(const QString &name);

  /**
   * @brief emitted after a mod has been renamed
   * This signal MUST be used to fix the mod names in profiles (except the active one) and to invalidate/refresh other
   * structures that may have become invalid with the rename
   *
   * @param oldName the old name of the mod
   * @param newName new name of the mod
   */
  void modRenamed(const QString &oldName, const QString &newName);

  /**
   * @brief emitted whenever a row in the list has changed
   *
   * @param index the index of the changed field
   * @param role role of the field that changed
   * @note this signal must only be emitted if the row really did change.
   *       Slots handling this signal therefore do not have to verify that a change has happened
   * @note this signal is currently only used in tutorials
   **/
  void modlist_changed(const QModelIndex &index, int role);

  /**
   * @brief emitted to have all selected mods deleted
   */
  void removeSelectedMods();

protected:

  // event filter, handles event from the header and the tree view itself
  bool eventFilter(QObject *obj, QEvent *event);

private:

  bool testValid(const QString &modDir);

  void changeModPriority(std::vector<int> sourceIndices, int newPriority);

  QVariant getOverwriteData(int column, int role) const;

  QString getFlagText(ModInfo::EFlag flag, ModInfo::Ptr modInfo) const;

  static QString getColumnToolTip(int column);

  ModList::EColumn getEnabledColumn(int index) const;

  QVariant categoryData(int categoryID, int column, int role) const;
  QVariant modData(int modID, int modelColumn, int role) const;

  bool renameMod(int index, const QString &newName);

  bool dropURLs(const QMimeData *mimeData, int row, const QModelIndex &parent);

  bool dropMod(const QMimeData *mimeData, int row, const QModelIndex &parent);

private slots:

private:

  struct TModInfo {
    TModInfo(unsigned int index, ModInfo::Ptr modInfo)
        : modInfo(modInfo), nameOrder(index) {}
    ModInfo::Ptr modInfo;
    unsigned int nameOrder;
    unsigned int priorityOrder;
    unsigned int modIDOrder;
    unsigned int categoryOrder;
  };

private:

  Profile *m_Profile;

  NexusInterface *m_NexusInterface;
  std::set<int> m_RequestIDs;

  mutable bool m_Modified;

  QFontMetrics m_FontMetrics;

  bool m_DropOnItems;

};

#endif // MODLIST_H