|
|
@@ -0,0 +1,161 @@
|
|
|
+#include "SettingsDialog.hpp"
|
|
|
+#include <gtkmm/filechooserdialog.h>
|
|
|
+#include <glibmm/miscutils.h>
|
|
|
+
|
|
|
+// Setting keys
|
|
|
+static constexpr const char* SETTING_TILE_SIZE = "tile_size";
|
|
|
+static constexpr const char* SETTING_IMPORT_FOLDER = "import_folder";
|
|
|
+
|
|
|
+// Defaults
|
|
|
+static constexpr int DEFAULT_TILE_SIZE = 180;
|
|
|
+
|
|
|
+SettingsDialog::SettingsDialog(Gtk::Window& parent, DatabaseManager& db)
|
|
|
+ : Gtk::Dialog()
|
|
|
+ , m_db(db)
|
|
|
+{
|
|
|
+ set_title("Settings");
|
|
|
+ set_transient_for(parent);
|
|
|
+ set_modal(true);
|
|
|
+ set_default_size(400, -1);
|
|
|
+
|
|
|
+ // Configure tile size spin button
|
|
|
+ m_tileSizeSpinButton.set_range(80, 300);
|
|
|
+ m_tileSizeSpinButton.set_increments(10, 50);
|
|
|
+ m_tileSizeSpinButton.set_value(DEFAULT_TILE_SIZE);
|
|
|
+
|
|
|
+ // Style hints
|
|
|
+ m_tileSizeHint.add_css_class("dim-label");
|
|
|
+ m_tileSizeHint.set_xalign(0.0f);
|
|
|
+ m_importFolderHint.add_css_class("dim-label");
|
|
|
+ m_importFolderHint.set_xalign(0.0f);
|
|
|
+
|
|
|
+ // Configure import folder button
|
|
|
+ m_importFolderButton.set_hexpand(true);
|
|
|
+ m_importFolderButton.set_halign(Gtk::Align::FILL);
|
|
|
+
|
|
|
+ // Build grid layout
|
|
|
+ m_grid.set_row_spacing(6);
|
|
|
+ m_grid.set_column_spacing(12);
|
|
|
+ m_grid.set_margin(12);
|
|
|
+
|
|
|
+ // Row 0: Tile size
|
|
|
+ m_tileSizeLabel.set_halign(Gtk::Align::END);
|
|
|
+ m_grid.attach(m_tileSizeLabel, 0, 0);
|
|
|
+ m_grid.attach(m_tileSizeSpinButton, 1, 0);
|
|
|
+
|
|
|
+ // Row 1: Tile size hint
|
|
|
+ m_grid.attach(m_tileSizeHint, 1, 1);
|
|
|
+
|
|
|
+ // Row 2: spacing
|
|
|
+ auto* spacer1 = Gtk::make_managed<Gtk::Label>("");
|
|
|
+ spacer1->set_margin_top(6);
|
|
|
+ m_grid.attach(*spacer1, 0, 2);
|
|
|
+
|
|
|
+ // Row 3: Import folder
|
|
|
+ m_importFolderLabel.set_halign(Gtk::Align::END);
|
|
|
+ m_grid.attach(m_importFolderLabel, 0, 3);
|
|
|
+ m_grid.attach(m_importFolderButton, 1, 3);
|
|
|
+
|
|
|
+ // Row 4: Import folder hint
|
|
|
+ m_grid.attach(m_importFolderHint, 1, 4);
|
|
|
+
|
|
|
+ // Row 5: spacing
|
|
|
+ auto* spacer2 = Gtk::make_managed<Gtk::Label>("");
|
|
|
+ spacer2->set_margin_top(12);
|
|
|
+ m_grid.attach(*spacer2, 0, 5);
|
|
|
+
|
|
|
+ // Row 6: Library maintenance
|
|
|
+ m_maintenanceLabel.set_halign(Gtk::Align::END);
|
|
|
+ m_grid.attach(m_maintenanceLabel, 0, 6);
|
|
|
+ m_scanButton.set_hexpand(false);
|
|
|
+ m_scanButton.set_halign(Gtk::Align::START);
|
|
|
+ m_grid.attach(m_scanButton, 1, 6);
|
|
|
+
|
|
|
+ // Row 7: Scan hint
|
|
|
+ m_scanHint.add_css_class("dim-label");
|
|
|
+ m_scanHint.set_xalign(0.0f);
|
|
|
+ m_grid.attach(m_scanHint, 1, 7);
|
|
|
+
|
|
|
+ m_contentBox.append(m_grid);
|
|
|
+
|
|
|
+ // Button box
|
|
|
+ auto* buttonBox = Gtk::make_managed<Gtk::Box>(Gtk::Orientation::HORIZONTAL, 6);
|
|
|
+ buttonBox->set_margin(12);
|
|
|
+ buttonBox->set_halign(Gtk::Align::END);
|
|
|
+ m_cancelButton.add_css_class("destructive-action");
|
|
|
+ m_saveButton.add_css_class("suggested-action");
|
|
|
+ buttonBox->append(m_cancelButton);
|
|
|
+ buttonBox->append(m_saveButton);
|
|
|
+ m_contentBox.append(*buttonBox);
|
|
|
+
|
|
|
+ // Add to dialog
|
|
|
+ get_content_area()->append(m_contentBox);
|
|
|
+
|
|
|
+ // Connect signals
|
|
|
+ m_saveButton.signal_clicked().connect(
|
|
|
+ sigc::mem_fun(*this, &SettingsDialog::onSaveClicked));
|
|
|
+ m_cancelButton.signal_clicked().connect(
|
|
|
+ sigc::mem_fun(*this, &SettingsDialog::onCancelClicked));
|
|
|
+ m_scanButton.signal_clicked().connect([this]() {
|
|
|
+ m_signalScanRequested.emit();
|
|
|
+ });
|
|
|
+
|
|
|
+ // Import folder button opens file chooser
|
|
|
+ m_importFolderButton.signal_clicked().connect([this]() {
|
|
|
+ auto dialog = Gtk::FileChooserDialog(
|
|
|
+ "Select Default Import Folder",
|
|
|
+ Gtk::FileChooser::Action::SELECT_FOLDER);
|
|
|
+ dialog.set_transient_for(*this);
|
|
|
+ dialog.set_modal(true);
|
|
|
+ dialog.add_button("Cancel", Gtk::ResponseType::CANCEL);
|
|
|
+ dialog.add_button("Select", Gtk::ResponseType::ACCEPT);
|
|
|
+
|
|
|
+ if (!m_importFolderPath.empty()) {
|
|
|
+ dialog.set_current_folder(Gio::File::create_for_path(m_importFolderPath));
|
|
|
+ }
|
|
|
+
|
|
|
+ dialog.signal_response().connect([this, &dialog](int response) {
|
|
|
+ if (response == Gtk::ResponseType::ACCEPT) {
|
|
|
+ auto file = dialog.get_file();
|
|
|
+ if (file) {
|
|
|
+ m_importFolderPath = file->get_path();
|
|
|
+ m_importFolderButton.set_label(m_importFolderPath);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ dialog.close();
|
|
|
+ });
|
|
|
+
|
|
|
+ dialog.present();
|
|
|
+ });
|
|
|
+
|
|
|
+ // Load current settings
|
|
|
+ loadSettings();
|
|
|
+}
|
|
|
+
|
|
|
+void SettingsDialog::loadSettings() {
|
|
|
+ int tileSize = m_db.get_setting_int(SETTING_TILE_SIZE, DEFAULT_TILE_SIZE);
|
|
|
+ m_tileSizeSpinButton.set_value(tileSize);
|
|
|
+
|
|
|
+ m_importFolderPath = m_db.get_setting(SETTING_IMPORT_FOLDER,
|
|
|
+ Glib::get_home_dir());
|
|
|
+ if (m_importFolderPath.empty()) {
|
|
|
+ m_importFolderPath = Glib::get_home_dir();
|
|
|
+ }
|
|
|
+ m_importFolderButton.set_label(m_importFolderPath);
|
|
|
+}
|
|
|
+
|
|
|
+void SettingsDialog::saveSettings() {
|
|
|
+ int tileSize = static_cast<int>(m_tileSizeSpinButton.get_value());
|
|
|
+ m_db.set_setting_int(SETTING_TILE_SIZE, tileSize);
|
|
|
+ m_db.set_setting(SETTING_IMPORT_FOLDER, m_importFolderPath);
|
|
|
+}
|
|
|
+
|
|
|
+void SettingsDialog::onSaveClicked() {
|
|
|
+ saveSettings();
|
|
|
+ m_signalSettingsChanged.emit();
|
|
|
+ close();
|
|
|
+}
|
|
|
+
|
|
|
+void SettingsDialog::onCancelClicked() {
|
|
|
+ close();
|
|
|
+}
|