10#include "catalogsdbui.h"
11#include "ui_catalogsdbui.h"
12#include "catalogeditform.h"
13#include "catalogdetails.h"
14#include "catalogcoloreditor.h"
30 ui->objectsTable->setColumnCount(labels.
size());
31 ui->objectsTable->setHorizontalHeaderLabels(labels);
36 &CatalogsDBUI::row_selected);
39 &CatalogsDBUI::disable_buttons);
42 &CatalogsDBUI::enable_disable_catalog);
51 qOverload<>(&CatalogsDBUI::create_new_catalog));
56 &CatalogsDBUI::dublicate_catalog);
59 &CatalogsDBUI::show_color_editor);
62CatalogsDBUI::~CatalogsDBUI()
67QWidget *centered_check_box_widget(
bool checked)
73 pCheckBox->setChecked(checked);
74 pCheckBox->setEnabled(
false);
75 pLayout->addWidget(pCheckBox);
77 pLayout->setContentsMargins(0, 0, 0, 0);
79 pWidget->setLayout(pLayout);
84void CatalogsDBUI::refresh_db_table()
88 m_catalogs.resize(catalogs.size());
90 auto &table = *ui->objectsTable;
91 table.setRowCount(catalogs.size());
94 for (
const auto &catalog : catalogs)
96 m_catalogs[row] = catalog.id;
99 table.setCellWidget(row, 0, centered_check_box_widget(catalog.enabled));
103 table.setItem(row, 3,
106 table.setCellWidget(row, 5, centered_check_box_widget(catalog.mut));
114void CatalogsDBUI::row_selected(
int row,
int)
116 const auto &success = m_manager.
get_catalog(m_catalogs[row]);
120 const auto cat = success.second;
121 ui->activateButton->setText(!cat.enabled ?
i18n(
"Enable") :
i18n(
"Disable"));
122 ui->activateButton->setEnabled(
true);
123 ui->moreButton->setEnabled(
true);
124 ui->removeButton->setEnabled(
true);
125 ui->exportButton->setEnabled(
true);
126 ui->dublicateButton->setEnabled(
true);
127 ui->colorButton->setEnabled(
true);
130void CatalogsDBUI::disable_buttons()
132 if (ui->objectsTable->selectedItems().length() > 0)
135 ui->activateButton->setText(
i18n(
"Enable"));
136 ui->activateButton->setEnabled(
false);
137 ui->moreButton->setEnabled(
false);
138 ui->removeButton->setEnabled(
false);
139 ui->exportButton->setEnabled(
false);
140 ui->dublicateButton->setEnabled(
false);
143void CatalogsDBUI::enable_disable_catalog()
145 const auto catalog = get_selected_catalog();
153 this,
i18n(
"Warning"),
154 i18n(
"Could not enable/disable the catalog.<br>%1", success.second));
157 row_selected(ui->objectsTable->selectedItems().first()->row(), 0);
160const std::pair<bool, CatalogsDB::Catalog> CatalogsDBUI::get_selected_catalog()
162 const auto items = ui->objectsTable->selectedItems();
163 if (items.length() == 0)
164 return {
false, {} };
166 return m_manager.
get_catalog(m_catalogs[items.first()->row()]);
169void CatalogsDBUI::export_catalog()
171 const auto cat = get_selected_catalog();
175 QFileDialog dialog(
this,
i18nc(
"@title:window",
"Export Catalog"), m_last_dir,
177 QString(
" (*.%1);;").arg(CatalogsDB::db_file_extension));
179 dialog.setDefaultSuffix(CatalogsDB::db_file_extension);
184 const auto fileName = dialog.selectedUrls().value(0).toLocalFile();
185 const auto success = m_manager.
dump_catalog(cat.second.id, fileName);
190 i18n(
"Could not export the catalog.<br>%1", success.second));
193void CatalogsDBUI::import_catalog(
bool force)
195 QFileDialog dialog(
this,
i18nc(
"@title:window",
"Import Catalog"), m_last_dir,
197 QString(
" (*.%1);;").arg(CatalogsDB::db_file_extension));
199 dialog.setDefaultSuffix(CatalogsDB::db_file_extension);
204 const auto fileName = dialog.selectedUrls().value(0).toLocalFile();
208 if (!success.first && !force)
211 i18n(
"Could not import the catalog.<br>%1", success.second));
215 import_catalog(
true);
221void CatalogsDBUI::remove_catalog()
223 const auto cat = get_selected_catalog();
231 i18n(
"Could not remove the catalog.<br>%1", success.second));
240 return {
false, -1 };
242 auto cat = dialog->getCatalog();
249 i18n(
"Could not create the catalog.<br>%1", success.second));
250 return create_new_catalog(cat);
254 return {
true, cat.id };
257void CatalogsDBUI::create_new_catalog()
262void CatalogsDBUI::dublicate_catalog()
264 const auto &success = get_selected_catalog();
268 const auto &src = success.second;
272 src_new.enabled =
false;
273 src_new.precedence = 1;
275 const auto &create_success = create_new_catalog(src_new);
277 if (!create_success.first)
280 const auto copy_success = m_manager.
copy_objects(src.id, create_success.second);
281 if (!copy_success.first)
284 i18n(
"Could not copy the objects to the new catalog.<br>%1")
285 .arg(copy_success.second));
287 const auto &remove_success = m_manager.
remove_catalog(create_success.second);
288 if (!remove_success.first)
290 this,
i18n(
"Critical error"),
291 i18n(
"Could not clean up and remove the new catalog.<br>%1",
292 remove_success.second));
296void CatalogsDBUI::show_more_dialog()
298 const auto success = get_selected_catalog();
310void CatalogsDBUI::show_color_editor()
312 const auto &success = get_selected_catalog();
A form for editing catalog color scheme mappings.
A dialog that shows catalog information and provides facilities to edit catalog meta information and ...
A simple UI to manage downloaded and custom Catalogs.
int find_suitable_catalog_id()
Finds the smallest free id for a catalog.
const QString & db_file_name() const
std::pair< bool, QString > set_catalog_enabled(const int id, const bool enabled)
Enable or disable a catalog.
std::pair< bool, QString > remove_catalog(const int id)
remove a catalog
const std::pair< bool, Catalog > get_catalog(const int id)
std::pair< bool, QString > register_catalog(const int id, const QString &name, const bool mut, const bool enabled, const double precedence, const QString &author=cat_defaults.author, const QString &source=cat_defaults.source, const QString &description=cat_defaults.description, const int version=cat_defaults.version, const QString &color=cat_defaults.color, const QString &license=cat_defaults.license, const QString &maintainer=cat_defaults.maintainer, const QDateTime ×tamp=cat_defaults.timestamp)
Registers a new catalog in the database.
std::pair< bool, QString > import_catalog(const QString &file_path, const bool overwrite=false)
Loads a dumped catalog from path `file_path`.
const std::vector< Catalog > get_catalogs(bool include_disabled=false)
std::pair< bool, QString > dump_catalog(int catalog_id, QString file_path)
Dumps the catalog with `id` into the file under the path file_path.
std::pair< bool, QString > copy_objects(const int id_1, const int id_2)
Clone objects from the catalog with `id_1` to another with id_2.
QString i18nc(const char *context, const char *text, const TYPE &arg...)
QString i18n(const char *text, const TYPE &arg...)
void finished(int result)
QString absolutePath() const const
qsizetype size() const const
StandardButton critical(QWidget *parent, const QString &title, const QString &text, StandardButtons buttons, StandardButton defaultButton)
StandardButton question(QWidget *parent, const QString &title, const QString &text, StandardButtons buttons, StandardButton defaultButton)
StandardButton warning(QWidget *parent, const QString &title, const QString &text, StandardButtons buttons, StandardButton defaultButton)
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
QString number(double n, char format, int precision)
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
A simple struct to hold information about catalogs.