GNOME Bugzilla – Bug 637443
Missing signal open in Gio::Application
Last modified: 2010-12-23 21:11:56 UTC
The Gio::Application class does not offer a way to connect to the signal "open" of GApplication.
Yes. We haven't wrapped it because it has awkward parameters, as I've just mentioned in bug #637457. If necessary, we can probably wrap this by hand, I guess.
In order to discover how glibmm is coded, I wrap by hand the close signal (it's my first attemp to adapt glibmm). I join it.
Created attachment 176861 [details] [review] A patch to add the signal open to Gio::Application
It looks right to me. Well done. Does it work for you?
Yes, I attach an example (the one given in the mailing-list).
Created attachment 176886 [details] Gio::Application example
Created attachment 176899 [details] [review] Gio::Application example for gtkmm-documentation Here is the Gio::Application for the gtkmm documentation. It follows the advices of Murray Cummings given throw the mailing list.
Review of attachment 176899 [details] [review]: Please patch the ChangeLog. Please create a git patch. Just do this when you have made the changes to a git checkout and have committed the changes locally: git format-patch HEAD^ The files are missing the usual license comments at the top. Please see the other files. ::: examples/book/giomm/application/exampleapplication.cc @@ +9,3 @@ +void ExampleApplication::new_window(const Glib::RefPtr<Gio::File>& file) +{ + Gtk::Window * window = new ExampleWindow(file); The other examples use "Thing* thing" rather than "Thing * thing". @@ +12,3 @@ + add_window(*window); + window->signal_hide().connect(sigc::bind<Gtk::Window *>(sigc::mem_fun(*this, + &ExampleApplication::window_hide_cb), window)); The other examples use an on_ prefix rather than a _cb suffix. Please be consistent with the other examples. @@ +15,3 @@ +} + +void ExampleApplication::window_hide_cb(Gtk::Window * window) Again, the other examples use "Thing* thing" rather than "Thing * thing". @@ +22,3 @@ +void ExampleApplication::on_activate() +{ + new_window(Glib::RefPtr<Gio::File>(0)); The 0 should be unnecessary here. ::: examples/book/giomm/application/exampleapplication.h @@ +7,3 @@ +{ +public: + ExampleApplication(const Glib::ustring& appid, Gio::ApplicationFlags flags = This should be explicit because it can have one parameter. @@ +8,3 @@ +public: + ExampleApplication(const Glib::ustring& appid, Gio::ApplicationFlags flags = + Gio::APPLICATION_FLAGS_NONE); Please use multiples of two spaces for indentation. ::: examples/book/giomm/application/examplewindow.cc @@ +5,3 @@ +ExampleWindow::ExampleWindow(const Glib::RefPtr<Gio::File>& file) +{ + set_title("Bloatpad"); "Gio::Application example" would be more appropriate. @@ +10,3 @@ + scrolled.add(view); + + if (file) The other examples use if(something) rather than if (something). Also, this might be cleaner with just if(!file) return; which would avoid the nesting. @@ +12,3 @@ + if (file) + { + gchar *contents; We use char* instead of gchar*. It's the same anyway. And I would initialize these to 0 and put them just before their use, instead of at the top of the method. @@ +19,3 @@ + if (file->load_contents(contents, length)) + { + Glib::ustring text = Glib::ustring(contents, length); const Glib::ustring text(contents, length) would be slightly better. I would do an if(contents && length) first though. @@ +27,3 @@ + g_free(contents); + } + } catch (Glib::Error& e) Exceptions should be caught as const &, not just &. @@ +33,3 @@ + } + + show_all(); We generally avoid using show_all(), because constructors should not decide when their widgets/windows are shown. The caller should decide when to call show() on them. You probably mean show_all_children(). ::: examples/book/giomm/application/examplewindow.h @@ +7,3 @@ +{ +public: + ExampleWindow(const Glib::RefPtr<Gio::File>& file); This should be explicit. ::: examples/book/giomm/application/main.cc @@ +14,3 @@ + Gtk::Main kit(argc, argv); + + ExampleApplication bloat_pad("org.gtkmm.Test.bloatpad", bloatpad is a bad name.
Review of attachment 176861 [details] [review]: Committed with minor changes.
Created attachment 176932 [details] [review] A Gtk::Application example
I post a new version of the example. Thanks to Murray Cumming for its review. I have tried to follow its recommendations. However I put the example in the examples/book/application directory since it is indeed a Gtk::Application example and not really a Gio::Application example.
Created attachment 176935 [details] [review] A Gtk::Application example Correct the preceding patch (a window->show() forgotten)
Created attachment 176937 [details] [review] A Gtk::Application example There was another bug in the example : I used "const Glib::ustring text(contents, length);" to construct the UTF-8 string but length was the size in bytes, not in UTF-8 characters. A simpler const Glib::ustring text(contents); suffices since the contents is allways NULL terminated.
Thanks. I have applied that and made some minor changes. It's a good start, though I think we'll want to expand it as we discover more about how it should be used.