Add utilities functions #140

Merged
merged 2 commits into from Nov 6, 2016

Projects

None yet

4 participants

@GuillaumeGomez
Member

cc @gkoz @EPashkin

@jo: It should fulfill your needs.

@jo
jo commented Nov 4, 2016

@GuillaumeGomez awesome!

How can I test this? Would it be enough to point to this branch from Cargo.toml?

Thank you so much.

@GuillaumeGomez
Member

When merged, you can just put the glib dependency like this:

glib = { git = "https://github.com/gtk-rs/glib" }

To test it, you have to make it point to my own repo:

glib = { git = "https://github.com/guillaumegomez/glib", branch = "missing_functions" }
@jo
jo commented Nov 4, 2016

I get an error:

[jo@jolap simple-gtk-application]$ cargo run
    Updating git repository `https://github.com/guillaumegomez/glib`
    Updating git repository `https://github.com/gtk-rs/sys`
error: native library `glib` is being linked to by more than one package, and can only be linked to by one package

  glib-sys v0.3.1
  glib-sys v0.3.1 (https://github.com/gtk-rs/sys#774929a2)
@jo
jo commented Nov 4, 2016

My Cargo.toml looks like this:

[package]
name = "simple-gtk-application"
version = "0.1.0"
authors = ["Johannes J. Schmidt <jo@die-tf.de>"]

[dependencies]
glib = { git = "https://github.com/guillaumegomez/glib", branch = "missing_functions" }
gio = "0.1.0"
hyper = "0.9.10"
serde = "0.8"
serde_json = "0.8"
serde_derive = "0.8"

[dependencies.gtk]
version = "0.1.0"
features = ["v3_12"]
@jo
jo commented Nov 4, 2016

Should I point the other gtk-rs deps to git#master?

@GuillaumeGomez
Member

Hum... I think it's because of gtk. Just fork our gtk and update its glib dependency like I showed you and then put your gtk dependency on your repo.

Sorry to have you put through this. :-/

@GuillaumeGomez
Member

You don't use gtk? Well, what I said for gtk is still valid for gio.

@jo
jo commented Nov 4, 2016

No worry, I am so happy you help!

Yes, I do use gtk, look at the last section of my Cargo. Do I also need to for gio?

@jo
jo commented Nov 4, 2016

Oh, the problems continue:

[jo@jolap gtk]$ cargo build
    Updating git repository `https://github.com/gtk-rs/sys`
    ...

error[E0432]: unresolved import `glib::signal::Inhibit`
 --> src/signal.rs:8:9
  |
8 | pub use glib::signal::Inhibit;
  |         ^^^^^^^^^^^^^^^^^^^^^ no `Inhibit` in `glib::signal`
@jo
jo commented Nov 4, 2016

Those cross repository dependencies are always a pain. I know this from node so well :(

@GuillaumeGomez
Member

Sorry, my branch wasn't up-to-date with master. Refresh and retry.

@jo
jo commented Nov 4, 2016 edited

How do I refresh? I deleted target directory and run cargo build again but still get the same errors

@jo
jo commented Nov 5, 2016

This is my fork of gtk: https://github.com/jo/gtk
I did the following changes:

[jo@jolap gtk]$ git diff
diff --git a/Cargo.toml b/Cargo.toml
index f3d959c..1f39a68 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -71,8 +71,11 @@ git = "https://github.com/gtk-rs/gio"
 version = "0.1.0"

 [dependencies.glib]
-git = "https://github.com/gtk-rs/glib"
-version = "0.1.0"
+# git = "https://github.com/gtk-rs/glib"
+# version = "0.1.0"
+git = "https://github.com/guillaumegomez/glib"
+branch = "missing_functions"
+

 [dependencies.gdk]
 git = "https://github.com/gtk-rs/gdk"
@GuillaumeGomez
Member

It should be ok now, no?

@jo
jo commented Nov 5, 2016

no :(
Maybe Cargo did not update the git checkout of your branch? How can I enforce this?

@GuillaumeGomez
Member
GuillaumeGomez commented Nov 5, 2016 edited

Well, it's not convenient to try to explain. So for now, please clone the repo locally and replace glib dependencies with glib = { path = "../glib" } (if glib and gtk are at the same level). Then from your project, replace gtk dependency with gtk = { path = "../gtk" } (if gtk is at the same level than your project).

I hope it'll make things easier while we wait this PR to get merged.

PS: for glib, don't forget to git checkout missing_functions!

@jo
jo commented Nov 5, 2016

OK, will try this during the next days.
Now I learned how to use local dependencies, thank you so much!

@GuillaumeGomez
Member

No problem. Like I said, once merged, you won't have to trouble yourself with all this.

+ UserDirectory::PublicShare => ffi::G_USER_DIRECTORY_PUBLIC_SHARE,
+ UserDirectory::Templates => ffi::G_USER_DIRECTORY_TEMPLATES,
+ UserDirectory::Videos => ffi::G_USER_DIRECTORY_VIDEOS,
+ UserDirectory::NDirectories => ffi::G_USER_N_DIRECTORIES,
@EPashkin
EPashkin Nov 5, 2016 Member

We really need this case in manual code?

@GuillaumeGomez
GuillaumeGomez Nov 5, 2016 Member

Well, it's part of the enum so yes.

@EPashkin
EPashkin Nov 5, 2016 Member

And why also don't remove (comment) in enum?

+ UserDirectory::NDirectories => ffi::G_USER_N_DIRECTORIES,
+ }
+ }
+}
@EPashkin
EPashkin Nov 5, 2016 Member

Empty line at end pls.

src/utils.rs
+use translate::*;
+use UserDirectory;
+
+pub fn get_application_name() -> String {
@EPashkin
EPashkin Nov 5, 2016 Member

human-readable application name. may return NULL => Option<String>

@GuillaumeGomez
GuillaumeGomez Nov 5, 2016 Member

Good catch!

@EPashkin
EPashkin Nov 5, 2016 Member

But it still String

src/utils.rs
+
+pub fn path_get_basename(file_name: &str) -> Option<String> {
+ unsafe {
+ from_glib_none(ffi::g_path_get_basename(file_name.to_glib_none().0))
@EPashkin
EPashkin Nov 5, 2016 Member

Returns: a newly allocated string containing the last component of the filename. => from_glib_full?

src/utils.rs
+ }
+}
+
+pub fn path_get_dirname(file_name: &str) -> Option<String> {
@EPashkin
EPashkin Nov 5, 2016 Member

Also from_glib_full

src/utils.rs
+ }
+}
+
+pub fn find_program_in_path(program: &str) -> Option<String> {
@EPashkin
EPashkin Nov 5, 2016 Member

Also from_glib_full

src/utils.rs
+
+pub fn get_environ() -> Vec<String> {
+ unsafe {
+ FromGlibPtrContainer::from_glib_none(ffi::g_get_environ())
@EPashkin
EPashkin Nov 5, 2016 Member

Also transfer full but not sure which case.

@GuillaumeGomez
Member

Updated.

GuillaumeGomez added some commits Nov 4, 2016
@GuillaumeGomez GuillaumeGomez Add utilities functions e92a97a
@GuillaumeGomez GuillaumeGomez remove some functions from windows platform
ecd090c
@GuillaumeGomez
Member

Should be good now.

@EPashkin
Member
EPashkin commented Nov 5, 2016

👍
But I still not like NDirectories in rust code.

@GuillaumeGomez
Member

Me neither but it doesn't harm to have it so...

@jo
jo commented Nov 6, 2016

@GuillaumeGomez I give up trying to compile gtk-rs packages with local dependencies. I ended up with clones of cairo, gdk, gdk-pixbuf, gio, glib, gtk, pango and sys, used path references everywhere but I get the error:

[jo@jolap gdk]$ cargo build
error: native library `cairo` is being linked to by more than one package, and can only be linked to by one package

  cairo-sys-rs v0.3.1 (https://github.com/gtk-rs/cairo#4a61ff90)
  cairo-sys-rs v0.3.1 (file:///home/jo/github/gtk-rs/cairo/cairo-sys-rs)

This error does not tell me where it happens :/

I will wait for this pr to get landed. Its not urgent for me anyway, I just wanted to contribute my testing. Although its interesting how the libs work together.

@GuillaumeGomez
Member

I'll merge it for now. If we encounter issues, we'll just update.

@GuillaumeGomez GuillaumeGomez merged commit 768a969 into gtk-rs:master Nov 6, 2016

2 checks passed

continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@GuillaumeGomez GuillaumeGomez deleted the GuillaumeGomez:missing_functions branch Nov 6, 2016
@jo
jo commented Nov 6, 2016

\o/ it works: when I now set

glib::utils::set_program_name(Some("Simple Gtk App"));

it shows the name in the menubar:
bildschirmfoto vom 2016-11-06 11-52-40

Without set_program_name it just displays a dot:
bildschirmfoto vom 2016-11-06 11-56-54

Thank you so much for your work on gtk-rs!

@GuillaumeGomez
Member

Great!

@GuillaumeGomez GuillaumeGomez referenced this pull request in GuillaumeGomez/process-viewer Nov 6, 2016
Open

Add set_application_name #50

@gkoz
Member
gkoz commented Nov 8, 2016

I'd recommend removing anything that's already available via std::env, std::fs, std::net. GLib makes sense as a standard library for C, but not for Rust.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment