[niepce/lr-import: 3/20] Foundation for Import Library




commit f08150c65c3b6b69488166f5c91b91b3f2098d91
Author: Hubert Figuière <hub figuiere net>
Date:   Tue Feb 6 01:08:09 2018 -0500

    Foundation for Import Library

 niepce-main/src/niepce/ui/dialogs.rs               |  3 +-
 niepce-main/src/niepce/ui/dialogs/importlibrary.rs | 96 ++++++++++++++++++++++
 src/Makefile.am                                    |  1 +
 src/niepce/Makefile.am                             |  1 +
 src/niepce/gresource.xml                           |  1 +
 src/niepce/ui/dialogs/importlibrary.ui             | 48 +++++++++++
 src/niepce/ui/workspacecontroller.cpp              | 10 +++
 src/niepce/ui/workspacecontroller.hpp              |  9 +-
 src/rust_bindings.hpp                              |  3 +-
 9 files changed, 164 insertions(+), 8 deletions(-)
---
diff --git a/niepce-main/src/niepce/ui/dialogs.rs b/niepce-main/src/niepce/ui/dialogs.rs
index 4bb2738..7ec1a45 100644
--- a/niepce-main/src/niepce/ui/dialogs.rs
+++ b/niepce-main/src/niepce/ui/dialogs.rs
@@ -1,7 +1,7 @@
 /*
  * niepce - niepce/ui/dialogs/mod.rs
  *
- * Copyright (C) 2017 Hubert Figuière
+ * Copyright (C) 2017-2020 Hubert Figuière
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -18,4 +18,5 @@
  */
 
 pub mod confirm;
+pub mod importlibrary;
 pub mod requestnewfolder;
diff --git a/niepce-main/src/niepce/ui/dialogs/importlibrary.rs 
b/niepce-main/src/niepce/ui/dialogs/importlibrary.rs
new file mode 100644
index 0000000..f17f95a
--- /dev/null
+++ b/niepce-main/src/niepce/ui/dialogs/importlibrary.rs
@@ -0,0 +1,96 @@
+/*
+ * niepce - niepce/ui/dialogs/importlibrary.rs
+ *
+ * Copyright (C) 2021 Hubert Figuière
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+use std::cell::RefCell;
+use std::path::PathBuf;
+use std::rc::Rc;
+
+use glib::clone;
+use glib::translate::*;
+use gtk;
+use gtk::prelude::*;
+use gtk::{Assistant, Builder};
+use gtk_sys;
+
+use crate::libraryclient::LibraryClientWrapper;
+
+#[no_mangle]
+pub extern "C" fn dialog_import_library(
+    _client: &mut LibraryClientWrapper,
+    parent: *mut gtk_sys::GtkWindow,
+) {
+    let parent_window = unsafe { gtk::Window::from_glib_none(parent) };
+    ImportLibraryDialog::run(&parent_window);
+}
+
+#[derive(Default)]
+struct ImportState {
+    library_path: Option<PathBuf>,
+}
+
+type ImportStateRef = Rc<RefCell<ImportState>>;
+
+struct ImportLibraryDialog {}
+
+impl ImportLibraryDialog {
+    fn run(parent: &gtk::Window) {
+        let assistant = Assistant::new();
+
+        let state: ImportStateRef = Rc::new(RefCell::new(ImportState::default()));
+
+        assistant.connect_cancel(Self::cancel);
+        assistant.set_forward_page_func(Some(Box::new(Self::forward_page)));
+
+        let builder = Builder::new();
+        if let Err(result) = builder.add_from_resource("/org/gnome/Niepce/ui/importlibrary.ui") {
+            err_out!("couldn't find ui file: {}", result);
+            return;
+        }
+        if let Some(page) = builder.object::<gtk::Widget>("page0") {
+            assistant.insert_page(&page, 0);
+            assistant.set_current_page(0);
+        }
+        if let Some(file_chooser) = builder.object::<gtk::FileChooserButton>("file_chooser") {
+            file_chooser.connect_file_set(clone!(@weak state => move |w| {
+                Self::library_file_set(w, state)
+            }));
+        }
+
+        assistant.set_transient_for(Some(parent));
+        assistant.set_modal(true);
+        assistant.present();
+    }
+
+    fn forward_page(current: i32) -> i32 {
+        match current {
+            0 => 1,
+            _ => 0,
+        }
+    }
+
+    fn library_file_set(file_chooser: &gtk::FileChooserButton, state_ref: ImportStateRef) {
+        let path = file_chooser.filename();
+        state_ref.borrow_mut().library_path = path;
+    }
+
+    fn cancel(assistant: &Assistant) {
+        dbg_out!("Assistant cancel");
+        unsafe { assistant.destroy(); }
+    }
+}
diff --git a/src/Makefile.am b/src/Makefile.am
index 6238fbe..1b94dbc 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -61,6 +61,7 @@ RUST_SOURCES = \
        @top_srcdir@/niepce-main/src/niepce/ui/image_list_store.rs \
        @top_srcdir@/niepce-main/src/niepce/ui/dialogs.rs \
        @top_srcdir@/niepce-main/src/niepce/ui/dialogs/confirm.rs \
+       @top_srcdir@/niepce-main/src/niepce/ui/dialogs/importlibrary.rs \
        @top_srcdir@/niepce-main/src/niepce/ui/dialogs/requestnewfolder.rs \
        @top_srcdir@/niepce-main/src/niepce/ui/thumb_nav.rs \
        @top_srcdir@/niepce-main/src/niepce/ui/library_cell_renderer.rs \
diff --git a/src/niepce/Makefile.am b/src/niepce/Makefile.am
index 0c55d25..0e2d670 100644
--- a/src/niepce/Makefile.am
+++ b/src/niepce/Makefile.am
@@ -33,6 +33,7 @@ niepce_LDADD = \
 
 gladefiles = ui/dialogs/preferences.ui \
        ui/dialogs/importdialog.ui \
+       ui/dialogs/importlibrary.ui \
        ui/dialogs/editlabels.ui \
        ui/dialogs/importers/directoryimporterui.ui \
        ui/dialogs/importers/cameraimporterui.ui \
diff --git a/src/niepce/gresource.xml b/src/niepce/gresource.xml
index b493a19..86820a9 100644
--- a/src/niepce/gresource.xml
+++ b/src/niepce/gresource.xml
@@ -21,6 +21,7 @@
 
     <file alias="/ui/editlabels.ui">src/niepce/ui/dialogs/editlabels.ui</file>
     <file alias="/ui/importdialog.ui">src/niepce/ui/dialogs/importdialog.ui</file>
+    <file alias="/ui/importlibrary.ui">src/niepce/ui/dialogs/importlibrary.ui</file>
     <file alias="/ui/preferences.ui">src/niepce/ui/dialogs/preferences.ui</file>
     <file alias="/ui/cameraimporterui.ui">src/niepce/ui/dialogs/importers/cameraimporterui.ui</file>
     <file alias="/ui/directoryimporterui.ui">src/niepce/ui/dialogs/importers/directoryimporterui.ui</file>
diff --git a/src/niepce/ui/dialogs/importlibrary.ui b/src/niepce/ui/dialogs/importlibrary.ui
new file mode 100644
index 0000000..941c21c
--- /dev/null
+++ b/src/niepce/ui/dialogs/importlibrary.ui
@@ -0,0 +1,48 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated with glade 3.22.1 -->
+<interface>
+  <requires lib="gtk+" version="3.20"/>
+  <object class="GtkFrame" id="page0">
+    <property name="visible">True</property>
+    <property name="can_focus">False</property>
+    <property name="label_xalign">0</property>
+    <property name="shadow_type">none</property>
+    <child>
+      <object class="GtkAlignment">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="left_padding">12</property>
+        <child>
+          <object class="GtkBox">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="orientation">vertical</property>
+            <child>
+              <object class="GtkFileChooserButton" id="file_chooser">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="title" translatable="yes"/>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">True</property>
+                <property name="padding">12</property>
+                <property name="position">0</property>
+              </packing>
+            </child>
+            <child>
+              <placeholder/>
+            </child>
+          </object>
+        </child>
+      </object>
+    </child>
+    <child type="label">
+      <object class="GtkLabel">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="label" translatable="yes">Import Library</property>
+      </object>
+    </child>
+  </object>
+</interface>
diff --git a/src/niepce/ui/workspacecontroller.cpp b/src/niepce/ui/workspacecontroller.cpp
index ef3c609..2bf52ee 100644
--- a/src/niepce/ui/workspacecontroller.cpp
+++ b/src/niepce/ui/workspacecontroller.cpp
@@ -151,6 +151,12 @@ void WorkspaceController::action_file_import()
 }
 
 
+void WorkspaceController::action_import_library()
+{
+    auto& window = std::dynamic_pointer_cast<NiepceWindow>(m_parent.lock())->gtkWindow();
+    ui::dialog_import_library(getLibraryClient()->client(), window.gobj());
+}
+
 void WorkspaceController::on_lib_notification(const eng::LibNotification &ln)
 {
     DBG_OUT("notification for workspace");
@@ -454,6 +460,10 @@ Gtk::Widget * WorkspaceController::buildWidget()
                          sigc::mem_fun(*this,
                                        &WorkspaceController::action_file_import),
                          section, _("_Import..."), "workspace");
+    fwk::add_menu_action(m_action_group.get(), "ImportLibrary",
+                         sigc::mem_fun(*this,
+                                       &WorkspaceController::action_import_library),
+                         section, _("_Import Library..."), "workspace");
 
     add_btn->set_menu_model(menu);
 
diff --git a/src/niepce/ui/workspacecontroller.hpp b/src/niepce/ui/workspacecontroller.hpp
index ff15f29..af91626 100644
--- a/src/niepce/ui/workspacecontroller.hpp
+++ b/src/niepce/ui/workspacecontroller.hpp
@@ -1,7 +1,7 @@
 /*
  * niepce - ui/workspacecontroller.h
  *
- * Copyright (C) 2007-2014 Hubert Figuiere
+ * Copyright (C) 2007-2020 Hubert Figuière
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -17,8 +17,7 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#ifndef __UI_WORKSPACECONTROLLER_H__
-#define __UI_WORKSPACECONTROLLER_H__
+#pragma once
 
 #include <array>
 
@@ -94,6 +93,7 @@ private:
     void action_delete_folder();
     /** action to import images */
     void action_file_import();
+    void action_import_library();
 
     void on_row_expanded_collapsed(const Gtk::TreeIter& iter,
                                    const Gtk::TreePath& path, bool expanded);
@@ -155,10 +155,7 @@ private:
     std::map<eng::library_id_t, Gtk::TreeIter>   m_keywordsidmap;
 };
 
-
 }
-
-#endif
 /*
   Local Variables:
   mode:c++
diff --git a/src/rust_bindings.hpp b/src/rust_bindings.hpp
index 571a005..e19e8e8 100644
--- a/src/rust_bindings.hpp
+++ b/src/rust_bindings.hpp
@@ -64,6 +64,7 @@ typedef ffi::FolderVirtualType FolderVirtualType;
 }
 
 namespace ui {
-  using ffi::dialog_request_new_folder;
   using ffi::dialog_confirm;
+  using ffi::dialog_import_library;
+  using ffi::dialog_request_new_folder;
 }


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