diff options
| author | Silarn <jrim@rimpo.org> | 2019-07-22 01:00:42 -0500 |
|---|---|---|
| committer | Silarn <jrim@rimpo.org> | 2019-07-22 01:00:42 -0500 |
| commit | dcd6d624672019727d7effd17aac86f72bff438b (patch) | |
| tree | 1e8d3856f657d898c5992631599cf272d785f973 /src/modinfodialog.h | |
| parent | 179a73857125ee604f42b0d5c2d765183c86d2c7 (diff) | |
| parent | e73c309f08eff98f0dbd2590f594a83b67431eac (diff) | |
Merge branch 'Develop'
Diffstat (limited to 'src/modinfodialog.h')
| -rw-r--r-- | src/modinfodialog.h | 345 |
1 files changed, 175 insertions, 170 deletions
diff --git a/src/modinfodialog.h b/src/modinfodialog.h index 4c731c00..34555b0c 100644 --- a/src/modinfodialog.h +++ b/src/modinfodialog.h @@ -23,231 +23,236 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>. #include "modinfo.h"
#include "tutorabledialog.h"
-#include "plugincontainer.h"
-#include "organizercore.h"
+#include "filerenamer.h"
+#include "modinfodialogfwd.h"
-#include <QDialog>
-#include <QSignalMapper>
-#include <QSettings>
-#include <QNetworkAccessManager>
-#include <QNetworkReply>
-#include <QModelIndex>
-#include <QAction>
-#include <QListWidgetItem>
-#include <QTreeWidgetItem>
-#include <QTextCodec>
-#include <set>
-#include <directoryentry.h>
+namespace Ui { class ModInfoDialog; }
+namespace MOShared { class FilesOrigin; }
-
-namespace Ui {
- class ModInfoDialog;
-}
-
-class QFileSystemModel;
-class QTreeView;
-class CategoryFactory;
+class PluginContainer;
+class OrganizerCore;
+class Settings;
+class ModInfoDialogTab;
+class MainWindow;
/**
- * this is a larger dialog used to visualise information abount the mod.
+ * this is a larger dialog used to visualise information about the mod.
* @todo this would probably a good place for a plugin-system
**/
class ModInfoDialog : public MOBase::TutorableDialog
{
- Q_OBJECT
+ Q_OBJECT;
+
+ // creates a tab, it's a friend because it uses a bunch of member variables
+ // to create ModInfoDialogTabContext
+ //
+ template <class T>
+ friend std::unique_ptr<ModInfoDialogTab> createTab(
+ ModInfoDialog& d, ModInfoTabIDs index);
public:
+ ModInfoDialog(
+ MainWindow* mw, OrganizerCore* core, PluginContainer* plugin,
+ ModInfo::Ptr mod);
- enum ETabs {
- TAB_TEXTFILES,
- TAB_INIFILES,
- TAB_IMAGES,
- TAB_ESPS,
- TAB_CONFLICTS,
- TAB_CATEGORIES,
- TAB_NEXUS,
- TAB_NOTES,
- TAB_FILETREE
- };
+ ~ModInfoDialog();
-public:
+ // switches to the tab with the given id
+ //
+ void selectTab(ModInfoTabIDs id);
- /**
- * @brief constructor
- *
- * @param modInfo info structure about the mod to display
- * @param parent parend widget
- **/
- explicit ModInfoDialog(ModInfo::Ptr modInfo, const MOShared::DirectoryEntry *directory, bool unmanaged, OrganizerCore *organizerCore, PluginContainer *pluginContainer, QWidget *parent = 0);
+ // updates all tabs, selects the initial tab and opens the dialog
+ //
+ int exec() override;
- ~ModInfoDialog();
+ // saves the dialog state and calls saveState() on all tabs
+ //
+ void saveState(Settings& s) const;
+
+ // restores the dialog state and calls restoreState() on all tabs
+ //
+ void restoreState(const Settings& s);
+
+signals:
+ // emitted when a tab changes the origin
+ //
+ void originModified(int originID);
- /**
- * @brief retrieve the (user-modified) version of the mod
- *
- * @return the (user-modified) version of the mod
- **/
- QString getModVersion() const;
+protected:
+ // forwards to tryClose()
+ //
+ void closeEvent(QCloseEvent* e);
- /**
- * @brief retrieve the (user-modified) mod id
- *
- * @return the (user-modified) id of the mod
- **/
- const int getModID() const;
+private:
+ // represents a single tab
+ //
+ struct TabInfo
+ {
+ // tab implementation
+ std::unique_ptr<ModInfoDialogTab> tab;
- /**
- * @brief open the specified tab in the dialog if it's enabled
- *
- * @param tab the tab to activate
- **/
- void openTab(int tab);
+ // actual position in the tab bar, updated every time a tab is moved
+ int realPos;
- void restoreTabState(const QByteArray &state);
+ // widget used by the QTabWidget for this tab
+ //
+ // because QTabWidget doesn't support simply hiding tabs, they have to be
+ // completely removed from the widget when they don't support the current
+ // mod
+ //
+ // therefore, `widget, `caption` and `icon` are remembered so tabs can be
+ // removed and re-added when navigating between mods
+ //
+ // `widget` is also used figure out which tab is where when they're
+ // re-ordered
+ QWidget* widget;
- QByteArray saveTabState() const;
+ // caption for this tab, see `widget`
+ QString caption;
-signals:
+ // icon for this tab, see `widget`
+ QIcon icon;
- void thumbnailClickedSignal(const QString &filename);
- void linkActivated(const QString &link);
- void downloadRequest(const QString &link);
- void modOpen(const QString &modName, int tab);
- void modOpenNext(int tab=-1);
- void modOpenPrev(int tab=-1);
- void originModified(int originID);
- void endorseMod(ModInfo::Ptr nexusID);
-public slots:
+ TabInfo(std::unique_ptr<ModInfoDialogTab> tab);
- void modDetailsUpdated(bool success);
+ // returns whether this tab is part of the tab widget
+ //
+ bool isVisible() const;
+ };
-private:
+ std::unique_ptr<Ui::ModInfoDialog> ui;
+ MainWindow* m_mainWindow;
+ ModInfo::Ptr m_mod;
+ OrganizerCore* m_core;
+ PluginContainer* m_plugin;
+ std::vector<TabInfo> m_tabs;
- void initFiletree(ModInfo::Ptr modInfo);
- void initINITweaks();
+ // initial tab requested by the main window when the dialog is opened; whether
+ // the request can be honoured depends on what tabs are present
+ ModInfoTabIDs m_initialTab;
- void refreshLists();
+ // set to true when tabs are being removed and re-added while navigating
+ // between mods; since the current index changes while this is happening,
+ // onTabSelectionChanged() will be called repeatedly
+ //
+ // however, it will check this flag and ignore the event so first activations
+ // are not fired incorrectly
+ bool m_arrangingTabs;
- void addCategories(const CategoryFactory &factory, const std::set<int> &enabledCategories, QTreeWidgetItem *root, int rootLevel);
- void updateVersionColor();
+ // creates all the tabs and connects events
+ //
+ void createTabs();
- void refreshNexusData(int modID);
- void activateNexusTab();
- QString getFileCategory(int categoryID);
- bool recursiveDelete(const QModelIndex &index);
- void deleteFile(const QModelIndex &index);
- void openFile(const QModelIndex &index);
- void saveIniTweaks();
- void saveCategories(QTreeWidgetItem *currentNode);
- void saveCurrentTextFile();
- void saveCurrentIniFile();
- void openTextFile(const QString &fileName);
- void openIniFile(const QString &fileName);
- bool allowNavigateFromTXT();
- bool allowNavigateFromINI();
- bool hideFile(const QString &oldName);
- bool unhideFile(const QString &oldName);
- void addCheckedCategories(QTreeWidgetItem *tree);
- void refreshPrimaryCategoriesBox();
- int tabIndex(const QString &tabId);
+ // sets the currently selected mod; resets first activation, but doesn't
+ // update anything
+ //
+ void setMod(ModInfo::Ptr mod);
-private slots:
+ // sets the currently selected mod, if found; forwards to setMod() above
+ //
+ void setMod(const QString& name);
- void hideConflictFile();
- void unhideConflictFile();
- int getBinaryExecuteInfo(const QFileInfo &targetInfo, QFileInfo &binaryInfo, QString &arguments);
- void previewDataFile();
- void openDataFile();
+ // returns the origin of the current mod, may be null
+ //
+ MOShared::FilesOrigin* getOrigin();
- void thumbnailClicked(const QString &fileName);
- void linkClicked(const QUrl &url);
- void linkClicked(QString url);
+ // returns the currently selected tab, taking re-ordering in to account;
+ // shouldn't be null, but could be
+ //
+ TabInfo* currentTab();
- void delete_activated();
- void deleteTriggered();
- void renameTriggered();
- void openTriggered();
- void createDirectoryTriggered();
- void hideTriggered();
- void unhideTriggered();
+ // fully updates the dialog; sets the title, the tab visibility and updates
+ // all the tabs; used when the current mod changes
+ //
+ // see setTabsVisibility() for firstTime
+ //
+ void update(bool firstTime=false);
- void on_openInExplorerButton_clicked();
- void on_closeButton_clicked();
- void on_saveButton_clicked();
- void on_activateESP_clicked();
- void on_deactivateESP_clicked();
- void on_saveTXTButton_clicked();
- void on_visitNexusLabel_linkActivated(const QString &link);
- void on_modIDEdit_editingFinished();
- void on_sourceGameEdit_currentIndexChanged(int);
- void on_versionEdit_editingFinished();
- void on_customUrlLineEdit_editingFinished();
- void on_iniFileView_textChanged();
- void on_textFileView_textChanged();
- void on_tabWidget_currentChanged(int index);
- void on_primaryCategoryBox_currentIndexChanged(int index);
- void on_categoriesTree_itemChanged(QTreeWidgetItem *item, int column);
- void on_textFileList_currentItemChanged(QListWidgetItem *current, QListWidgetItem *previous);
- void on_iniFileList_currentItemChanged(QListWidgetItem *current, QListWidgetItem *previous);
- void on_iniTweaksList_currentItemChanged(QListWidgetItem *current, QListWidgetItem *previous);
- void on_overwriteTree_itemDoubleClicked(QTreeWidgetItem *item, int column);
- void on_overwrittenTree_itemDoubleClicked(QTreeWidgetItem *item, int column);
- void on_overwriteTree_customContextMenuRequested(const QPoint &pos);
- void on_overwrittenTree_customContextMenuRequested(const QPoint &pos);
- void on_fileTree_customContextMenuRequested(const QPoint &pos);
+ // builds the list of visible tabs; if the list is different from what's
+ // currently displayed, or firstTime is true, forwards to reAddTabs()
+ void setTabsVisibility(bool firstTime);
- void on_refreshButton_clicked();
+ // clears the tab widgets and re-adds the tabs having the visible flag in
+ // the given vector, following the tab order from the settings
+ //
+ void reAddTabs(const std::vector<bool>& visibility, ModInfoTabIDs sel);
- void on_endorseBtn_clicked();
+ // called by update(); clears tabs, feeds files and calls update() on all
+ // tabs, then setTabsColors()
+ //
+ void updateTabs(bool becauseOriginChanged=false);
- void on_nextButton_clicked();
+ // goes through all files on the filesystem for the current mod and calls
+ // feedFile() on every tab until one accepts it
+ //
+ void feedFiles(std::vector<TabInfo*>& interestedTabs);
- void on_prevButton_clicked();
+ // goes through all tabs and sets the tab text colour depending on whether
+ // they have data or not
+ //
+ void setTabsColors();
- void on_iniTweaksList_customContextMenuRequested(const QPoint &pos);
- void createTweak();
-private:
+ // called when the delete key is pressed anywhere in the dialog; forwards to
+ // ModInfoDialogTab::deleteRequest() for the currently selected tab
+ //
+ void onDeleteShortcut();
+
- Ui::ModInfoDialog *ui;
+ // finds the tab with the given id and selects it
+ //
+ void switchToTab(ModInfoTabIDs id);
- ModInfo::Ptr m_ModInfo;
- int m_OriginID;
- QSignalMapper m_ThumbnailMapper;
- QString m_RootPath;
+ // saves the current tab order; used by saveState(), but also by
+ // setTabsVisibility() to make sure any changes to order are saved before
+ // re-adding tabs
+ //
+ void saveTabOrder(Settings& s) const;
- OrganizerCore *m_OrganizerCore;
- PluginContainer *m_PluginContainer;
+ // returns a list of tab names in the order they should appear on the widget
+ //
+ std::vector<QString> getOrderedTabNames() const;
- QFileSystemModel *m_FileSystemModel;
- QTreeView *m_FileTree;
- QModelIndexList m_FileSelection;
+ // asks all the tabs if they accept closing the dialog, returns false if one
+ // objected
+ //
+ bool tryClose();
- QSettings *m_Settings;
- std::set<int> m_RequestIDs;
- bool m_RequestStarted;
+ // called when the user clicks the close button; closing the dialog by other
+ // means ends up in closeEvent(); forwards to tryClose()
+ //
+ void onCloseButton();
- QAction *m_DeleteAction;
- QAction *m_RenameAction;
- QAction *m_OpenAction;
- QAction *m_NewFolderAction;
- QAction *m_HideAction;
- QAction *m_UnhideAction;
+ // called when the user clicks the previous button; asks the main window for
+ // the previous mod in the list and loads it
+ //
+ void onPreviousMod();
- QTreeWidgetItem *m_ConflictsContextItem;
+ // called when the user clicks the next button; asks the main window for the
+ // next mod in the list and loads it
+ //
+ void onNextMod();
- const MOShared::DirectoryEntry *m_Directory;
- MOShared::FilesOrigin *m_Origin;
+ // called when the selects a tab; handles first activation
+ //
+ void onTabSelectionChanged();
- std::map<int, int> m_RealTabPos;
+ // called when the user re-orders tabs; sets the correct TabInfo::realPos for
+ // all tabs
+ //
+ void onTabMoved();
+ // called when a tab has modified the origin; emits originModified() and
+ // updates all the tabs that use origin files
+ //
+ void onOriginModified(int originID);
};
#endif // MODINFODIALOG_H
|
