Skip to content
This repository has been archived by the owner on Jun 8, 2021. It is now read-only.

Add utilities functions #140

Merged
merged 2 commits into from
Nov 6, 2016

Conversation

GuillaumeGomez
Copy link
Member

cc @gkoz @EPashkin

@jo: It should fulfill your needs.

@jo
Copy link

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
Copy link
Member Author

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
Copy link

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
Copy link

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
Copy link

jo commented Nov 4, 2016

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

@GuillaumeGomez
Copy link
Member Author

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
Copy link
Member Author

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

@jo
Copy link

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
Copy link

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
Copy link

jo commented Nov 4, 2016

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

@GuillaumeGomez
Copy link
Member Author

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

@jo
Copy link

jo commented Nov 4, 2016

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

@jo
Copy link

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
Copy link
Member Author

It should be ok now, no?

@jo
Copy link

jo commented Nov 5, 2016

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

@GuillaumeGomez
Copy link
Member Author

GuillaumeGomez commented Nov 5, 2016

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
Copy link

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
Copy link
Member Author

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,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We really need this case in manual code?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

UserDirectory::NDirectories => ffi::G_USER_N_DIRECTORIES,
}
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Empty line at end pls.

use translate::*;
use UserDirectory;

pub fn get_application_name() -> String {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But it still String


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))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

}
}

pub fn path_get_dirname(file_name: &str) -> Option<String> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also from_glib_full

}
}

pub fn find_program_in_path(program: &str) -> Option<String> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also from_glib_full


pub fn get_environ() -> Vec<String> {
unsafe {
FromGlibPtrContainer::from_glib_none(ffi::g_get_environ())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also transfer full but not sure which case.

@GuillaumeGomez
Copy link
Member Author

Updated.

@GuillaumeGomez
Copy link
Member Author

Should be good now.

@EPashkin
Copy link
Member

EPashkin commented Nov 5, 2016

👍
But I still not like NDirectories in rust code.

@GuillaumeGomez
Copy link
Member Author

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

@jo
Copy link

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
Copy link
Member Author

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
@GuillaumeGomez GuillaumeGomez deleted the missing_functions branch November 6, 2016 09:59
@jo
Copy link

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
Copy link
Member Author

Great!

@gkoz
Copy link
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 subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants