File indexing completed on 2024-12-08 12:08:59
0001 /* 0002 SPDX-FileCopyrightText: 2021 Valentin Boettcher <hiro at protagon.space; @hiro98:tchncs.de> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #ifndef CATALOGSDBUI_H 0008 #define CATALOGSDBUI_H 0009 0010 #include <QDialog> 0011 #include "catalogsdb.h" 0012 0013 namespace Ui 0014 { 0015 class CatalogsDBUI; 0016 } 0017 0018 /** 0019 * A simple UI to manage downloaded and custom Catalogs. 0020 * 0021 * It holds it's own instance of `CatalogsDB::DBManager` and can import, 0022 * export, delete, enable, disable and clone catalogs. On request it 0023 * spawns a `CatalogDetails` dialog which can be be used to edit 0024 * `mutable` catalogs. 0025 */ 0026 class CatalogsDBUI : public QDialog 0027 { 0028 Q_OBJECT 0029 public: 0030 explicit CatalogsDBUI(QWidget *parent, const QString &db_path); 0031 ~CatalogsDBUI(); 0032 0033 private slots: 0034 /** 0035 * Activates the apropriate buttons. 0036 */ 0037 void row_selected(int row, int); 0038 0039 /** 0040 * Disables all catalog related buttons if no row is selected.c 0041 */ 0042 void disable_buttons(); 0043 0044 /** 0045 * Enables or disables the currently selected catalog. 0046 */ 0047 void enable_disable_catalog(); 0048 0049 /** 0050 * Opens a file selection dialog and exports the selected catalog. 0051 */ 0052 void export_catalog(); 0053 0054 /** 0055 * Opens a file selection dialog and imports the selected catalog. 0056 */ 0057 void import_catalog(bool force = false); 0058 0059 /** 0060 * Removes the selected catalog. 0061 */ 0062 void remove_catalog(); 0063 0064 /** 0065 * Creates a new catalog by prompting for the relevant details. 0066 * The smallest available id for custom catalogs is proposed. 0067 */ 0068 void create_new_catalog(); 0069 0070 /** 0071 * Creates a new catalog based on \p `catalog` by prompting for the 0072 * relevant details. 0073 * 0074 * returns wether a catalog was created and the id of the created catalog 0075 */ 0076 std::pair<bool, int> create_new_catalog(const CatalogsDB::Catalog &catalog); 0077 0078 /** 0079 * Shows the `CatalogDetails` dialog for the currently selected 0080 * catalog. 0081 */ 0082 void show_more_dialog(); 0083 0084 /** 0085 * Shows the `CatalogColorEditor` dialog for the currently selected 0086 * catalog. 0087 */ 0088 void show_color_editor(); 0089 0090 /** 0091 * Dublicate the selected catalog, inserting it as a new catalog 0092 * and prompt for meta-data edit. 0093 */ 0094 void dublicate_catalog(); 0095 0096 /** 0097 * Refresh the table by reloading the catalogs from the database. 0098 */ 0099 void refresh_db_table(); 0100 0101 private: 0102 Ui::CatalogsDBUI *ui; 0103 0104 /** 0105 * The database instance for accessing a catalog database. 0106 */ 0107 CatalogsDB::DBManager m_manager; 0108 0109 /** 0110 * The currently loaded catalogs. Relates row number to catalog 0111 * id. 0112 */ 0113 std::vector<int> m_catalogs; 0114 0115 /** 0116 * \returns if a catalog is selected and the catalog itself 0117 */ 0118 const std::pair<bool, CatalogsDB::Catalog> get_selected_catalog(); 0119 0120 /** Remeber the directory where we last loaded a catalog from */ 0121 QString m_last_dir; 0122 }; 0123 0124 #endif // CATALOGSDBUI_H