[niepce] ui: request a new folder name



commit d1908236ddaaf815ba45225bfecbce53324199b3
Author: Hubert Figuière <hub figuiere net>
Date:   Thu Nov 16 20:56:35 2017 -0500

    ui: request a new folder name
    
    - add gtk-rs
    - provide an init function for the Rust library

 Cargo.toml                                |    3 ++
 src/Makefile.am                           |    4 ++
 src/fwk/utils/init.cpp                    |    4 ++
 src/lib.rs                                |   11 ++++++
 src/libraryclient/mod.rs                  |    3 ++
 src/niepce/mod.rs                         |    3 ++
 src/niepce/ui/dialogs/mod.rs              |    3 ++
 src/niepce/ui/dialogs/requestnewfolder.rs |   56 +++++++++++++++++++++++++++++
 src/niepce/ui/mod.rs                      |    3 ++
 src/niepce/ui/workspacecontroller.cpp     |    4 ++-
 src/rust_bindings.hpp                     |    6 +++
 11 files changed, 99 insertions(+), 1 deletions(-)
---
diff --git a/Cargo.toml b/Cargo.toml
index e7c4feb..216f846 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -8,8 +8,11 @@ build = "build.rs"
 chrono = "0.4.0"
 exempi = { version = "2.5.0", git = "https://github.com/hfiguiere/exempi-rs.git"; }
 glib-sys = "0.4.0"
+glib = "0.3.1"
 gio-sys = "0.4.0"
 gio = "0.2.0"
+gtk-sys = { version = "0.4.0", features = ["v3_16"] }
+gtk = "0.2.0"
 libc = "0.2.23"
 rusqlite = { version = "0.12.0", features = ["functions"] }
 try_opt = "0.1.1"
diff --git a/src/Makefile.am b/src/Makefile.am
index 15eebe4..97156c8 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -39,6 +39,10 @@ RUST_SOURCES = \
        @top_srcdir@/src/libraryclient/clientinterface.rs \
        @top_srcdir@/src/libraryclient/libraryclient.rs \
        @top_srcdir@/src/libraryclient/mod.rs \
+       @top_srcdir@/src/niepce/mod.rs \
+       @top_srcdir@/src/niepce/ui/mod.rs \
+       @top_srcdir@/src/niepce/ui/dialogs/mod.rs \
+       @top_srcdir@/src/niepce/ui/dialogs/requestnewfolder.rs \
        $(NULL)
 
 EXTRA_DIST = \
diff --git a/src/fwk/utils/init.cpp b/src/fwk/utils/init.cpp
index 5238541..14ac565 100644
--- a/src/fwk/utils/init.cpp
+++ b/src/fwk/utils/init.cpp
@@ -24,6 +24,8 @@
 
 #include "init.hpp"
 
+#include "rust_bindings.hpp"
+
 namespace fwk {
 namespace utils {
 
@@ -31,6 +33,8 @@ namespace utils {
 void init()
 {
   Gio::init();
+
+  ffi::niepce_init();
 }
 
 
diff --git a/src/lib.rs b/src/lib.rs
index 7a61001..c24c705 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -20,8 +20,11 @@
 extern crate chrono;
 extern crate exempi;
 extern crate glib_sys;
+extern crate glib;
 extern crate gio_sys;
 extern crate gio;
+extern crate gtk_sys;
+extern crate gtk;
 extern crate libc;
 extern crate rusqlite;
 #[macro_use]
@@ -32,5 +35,13 @@ pub mod fwk;
 pub mod engine;
 pub mod libraryclient;
 pub mod capi;
+pub mod niepce;
 
 include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
+
+
+/// Call this to initialize the gtk-rs bindings
+#[no_mangle]
+pub extern "C" fn niepce_init() {
+    gtk::init().unwrap();
+}
diff --git a/src/libraryclient/mod.rs b/src/libraryclient/mod.rs
index fbe3dd2..4d63126 100644
--- a/src/libraryclient/mod.rs
+++ b/src/libraryclient/mod.rs
@@ -20,3 +20,6 @@
 pub mod clientimpl;
 pub mod clientinterface;
 pub mod libraryclient;
+
+pub use self::clientinterface::ClientInterfaceSync;
+pub use self::libraryclient::LibraryClientWrapper;
diff --git a/src/niepce/mod.rs b/src/niepce/mod.rs
new file mode 100644
index 0000000..e22bb4a
--- /dev/null
+++ b/src/niepce/mod.rs
@@ -0,0 +1,3 @@
+
+
+pub mod ui;
diff --git a/src/niepce/ui/dialogs/mod.rs b/src/niepce/ui/dialogs/mod.rs
new file mode 100644
index 0000000..77354fe
--- /dev/null
+++ b/src/niepce/ui/dialogs/mod.rs
@@ -0,0 +1,3 @@
+
+
+pub mod requestnewfolder;
diff --git a/src/niepce/ui/dialogs/requestnewfolder.rs b/src/niepce/ui/dialogs/requestnewfolder.rs
new file mode 100644
index 0000000..0fe208c
--- /dev/null
+++ b/src/niepce/ui/dialogs/requestnewfolder.rs
@@ -0,0 +1,56 @@
+/*
+ * niepce - niepce/ui/dialogs/requestnewfolder.rs
+ *
+ * Copyright (C) 2017 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 glib::translate::*;
+use gtk::prelude::*;
+use gtk;
+use gtk_sys;
+use gtk::{
+    Dialog,
+    Entry,
+    Label,
+};
+
+use libraryclient::{ClientInterfaceSync,LibraryClientWrapper};
+
+#[no_mangle]
+pub extern "C" fn dialog_request_new_folder(client: &mut LibraryClientWrapper,
+                                            parent: *mut gtk_sys::GtkWindow) {
+    let parent = unsafe { gtk::Window::from_glib_none(parent) };
+    let dialog = Dialog::new_with_buttons(Some("New folder"), Some(&parent),
+                                          gtk::DIALOG_MODAL,
+                                          &[("OK", 0), ("Cancel", 1)]);
+    let label = Label::new("Folder name:");
+    dialog.get_content_area().pack_start(&label, true, false, 4);
+    let entry = Entry::new();
+    entry.set_text("foobar");
+    dialog.get_content_area().pack_end(&entry, true, false, 4);
+
+    dialog.get_content_area().show_all();
+    let cancel = match dialog.run() {
+        0 => false,
+        _ => true,
+    };
+    let folder_name = entry.get_text();
+    dialog.destroy();
+    if !cancel {
+        /*let id =*/ client.unwrap_mut().create_folder_sync(folder_name.unwrap(), None);
+    }
+}
+
diff --git a/src/niepce/ui/mod.rs b/src/niepce/ui/mod.rs
new file mode 100644
index 0000000..3f3da9c
--- /dev/null
+++ b/src/niepce/ui/mod.rs
@@ -0,0 +1,3 @@
+
+
+pub mod dialogs;
diff --git a/src/niepce/ui/workspacecontroller.cpp b/src/niepce/ui/workspacecontroller.cpp
index 15b2a36..c010704 100644
--- a/src/niepce/ui/workspacecontroller.cpp
+++ b/src/niepce/ui/workspacecontroller.cpp
@@ -33,6 +33,7 @@
 #include "niepcewindow.hpp"
 #include "workspacecontroller.hpp"
 
+#include "rust_bindings.hpp"
 
 using fwk::Application;
 
@@ -84,8 +85,9 @@ fwk::Configuration::Ptr WorkspaceController::getLibraryConfig() const
 
 void WorkspaceController::action_new_folder()
 {
+    auto& window = std::dynamic_pointer_cast<NiepceWindow>(m_parent.lock())->gtkWindow();
+    ui::dialog_request_new_folder(getLibraryClient()->client(), window.gobj());
     // XXX get a unique name
-    auto id = ffi::libraryclient_create_folder_sync(getLibraryClient()->client(), "foobar", nullptr);
     // select folder in tree
 }
 
diff --git a/src/rust_bindings.hpp b/src/rust_bindings.hpp
index 6016971..c6de18b 100644
--- a/src/rust_bindings.hpp
+++ b/src/rust_bindings.hpp
@@ -21,6 +21,8 @@
 
 #if !RUST_BINDGEN
 
+#include <gtk/gtk.h>
+
 #include "engine/db/properties-enum.hpp"
 
 namespace fwk {
@@ -65,4 +67,8 @@ typedef ffi::Np Np;
 typedef ffi::FolderVirtualType FolderVirtualType;
 }
 
+namespace ui {
+  using ffi::dialog_request_new_folder;
+}
+
 #endif


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