[niepce] ui: fixed opening the library



commit 164d421920c8831e7d30a86f49c17e8ffc4afacd
Author: Hubert Figuière <hub figuiere net>
Date:   Mon Sep 26 22:30:50 2022 -0400

    ui: fixed opening the library
    
    - this was a gtk4 regression

 src/niepce/ui/niepcewindow.cpp | 68 ++++++++++++++++++++----------------------
 src/niepce/ui/niepcewindow.hpp |  2 +-
 2 files changed, 33 insertions(+), 37 deletions(-)
---
diff --git a/src/niepce/ui/niepcewindow.cpp b/src/niepce/ui/niepcewindow.cpp
index 7014c560..52fdbb91 100644
--- a/src/niepce/ui/niepcewindow.cpp
+++ b/src/niepce/ui/niepcewindow.cpp
@@ -266,18 +266,14 @@ void NiepceWindow::on_open_library()
     if(reopen) {
         libMoniker = cfg.getValue("last_open_catalog", "");
     }
-    if(libMoniker.empty()) {
-        libMoniker = prompt_open_library();
-    }
-    else {
+    if (libMoniker.empty()) {
+        prompt_open_library();
+    } else {
         DBG_OUT("last library is %s", libMoniker.c_str());
-    }
-    if(!libMoniker.empty()) {
-        if(!open_library(libMoniker)) {
+        if (!open_library(libMoniker)) {
             ERR_OUT("library %s cannot be open. Prompting.",
                     libMoniker.c_str());
-            libMoniker = prompt_open_library();
-            open_library(libMoniker);
+            prompt_open_library();
         }
     }
 }
@@ -334,34 +330,34 @@ void NiepceWindow::on_lib_notification(const eng::LibNotification& ln)
     }
 }
 
-std::string NiepceWindow::prompt_open_library()
+/** Prompt to open a library and open it on success */
+void NiepceWindow::prompt_open_library()
 {
-    std::string libMoniker;
-    Gtk::FileChooserDialog dialog(gtkWindow(), _("Open catalog"),
-                                  Gtk::FileChooser::Action::SELECT_FOLDER);
-    dialog.add_button(_("Cancel"), Gtk::ResponseType::CANCEL);
-    dialog.add_button(_("Open"), Gtk::ResponseType::OK);
-
-    int result = 0;
-    // XXX todo
-    dialog.show();
-    Glib::ustring libraryToCreate;
-    switch(result)
-    {
-    case Gtk::ResponseType::OK: {
-        Configuration & cfg = Application::app()->config();
-        libraryToCreate = dialog.get_current_name();
-        // pass it to the library
-        libMoniker = "local:";
-        libMoniker += libraryToCreate.c_str();
-        cfg.setValue("last_open_catalog", libMoniker);
-        DBG_OUT("created catalog %s", libMoniker.c_str());
-        break;
-    }
-    default:
-        break;
-    }
-    return libMoniker;
+    auto dialog = new Gtk::FileChooserDialog(
+        gtkWindow(), _("Open catalog"),
+        Gtk::FileChooser::Action::SELECT_FOLDER);
+    dialog->add_button(_("Cancel"), Gtk::ResponseType::CANCEL);
+    dialog->add_button(_("Open"), Gtk::ResponseType::OK);
+    dialog->set_create_folders(true);
+
+    dialog->signal_response().connect(
+        [this, dialog] (int response) {
+            DBG_OUT("response %d", response);
+            if (response == Gtk::ResponseType::OK) {
+                DBG_OUT("Accepted");
+                Configuration & cfg = Application::app()->config();
+                auto file = dialog->get_file();
+                Glib::ustring libraryToCreate = file->get_path();
+                // pass it to the library
+                std::string libMoniker = "local:";
+                libMoniker += libraryToCreate.c_str();
+                cfg.setValue("last_open_catalog", libMoniker);
+                DBG_OUT("created catalog %s", libMoniker.c_str());
+                this->open_library(libMoniker);
+            }
+            delete dialog;
+        });
+    dialog->show();
 }
 
 bool NiepceWindow::open_library(const std::string & libMoniker)
diff --git a/src/niepce/ui/niepcewindow.hpp b/src/niepce/ui/niepcewindow.hpp
index 84b72f0e..5fc8f2ae 100644
--- a/src/niepce/ui/niepcewindow.hpp
+++ b/src/niepce/ui/niepcewindow.hpp
@@ -65,7 +65,7 @@ private:
     void init_actions();
 
     // UI to open library
-    std::string prompt_open_library();
+    void prompt_open_library();
     // open the library
     // @return false if error.
     bool open_library(const std::string & libMoniker);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]