Merge lp:~elementary-apps/granite/about-dialog-commandline into lp:~elementary-pantheon/granite/granite

Proposed by Julián Unrrein
Status: Merged
Approved by: David Gomes
Approved revision: 643
Merged at revision: 651
Proposed branch: lp:~elementary-apps/granite/about-dialog-commandline
Merge into: lp:~elementary-pantheon/granite/granite
Diff against target: 121 lines (+71/-2)
2 files modified
lib/Application.vala (+70/-1)
lib/Widgets/AboutDialog.vala (+1/-1)
To merge this branch: bzr merge lp:~elementary-apps/granite/about-dialog-commandline
Reviewer Review Type Date Requested Status
David Gomes (community) Approve
Review via email: mp+185597@code.launchpad.net

Commit message

[Granite.Application] Add "--about" command line parameter that shows the About dialog of the application.

Description of the change

[Granite.Application] Add "--about" command line parameter that shows the About dialog of the application.

This capacity will be needed to trigger showing the About dialog from the launcher menu of an application (see https://lists.launchpad.net/elementary-dev-community/msg02777.html).

That menu entry would be added in the .desktop file of each application that wants to have this feature. This would be the only app-specific change.

This works when the app isn't running, and only spawns the About dialog.

Showing the About dialog with this method happens early in the startup stage of the application, so Gtk needs to be explicitly initialized.

Here is an example .desktop file for Scratch: http://pastebin.com/jwaZZ09F

To post a comment you must log in.
Revision history for this message
Julián Unrrein (junrrein) wrote :

I noticed that using this creates another instance of the application (instead of using a running one if it exists) using around 10 MB just for the about window.

It would be nice to avoid this if there is a running instance.

634. By Julián Unrrein

Use the unique instance.

635. By Julián Unrrein

Properly exit when doing this series of steps:
1) The app is invoked with the --about parameter.
2) The app was normally launched.
3) The About dialog was closed.
4) All windows of the app are closed.

636. By Julián Unrrein

Reuse the same dialog when the --about parameter is used many times.

637. By Julián Unrrein

Handle the register() exception.

638. By Julián Unrrein

Destroy the About dialog if all application windows are destroyed.

639. By Julián Unrrein

Code style improvements.

640. By Julián Unrrein

De-duplicate code. Comment a little more.

641. By Julián Unrrein

Comments.

Revision history for this message
Julián Unrrein (junrrein) wrote :

Now using this doesn't create an additional instance if the app is already running.

This is achieved using a SimpleAction. Actions are messages sent through Dbus, and they are always received by the primary application instance.

It gets ugly when the About dialog is opened, and the actual application is opened after. As the dialog is opened very early, it is needed to manually set the exit conditions for the app to work normally.

I also made it so that the dialog is closed if all windows of the app are also closed.

642. By Julián Unrrein

Improve a comment.

Revision history for this message
David Gomes (davidgomes) wrote :

Closing the dialog doesn't close the process, it seems. I tried it for the demo.

review: Needs Fixing
Revision history for this message
Julián Unrrein (junrrein) wrote :

This is due to issues in granite-demo. Hopefully https://code.launchpad.net/~elementary-apps/granite/demo-multiple-windows/+merge/185947 solves this.

Revision history for this message
Julián Unrrein (junrrein) wrote :

This still gets to be tested against an app that doesn't use an unique instance.

Revision history for this message
David Gomes (davidgomes) wrote :

But with the Demo's fixes shouldn't this work on it now?

Revision history for this message
Julián Unrrein (junrrein) wrote :

I tested this with an app that doesn't force an unique instance and it seems to not cause any trouble.

I now feel ok about this being merged. It still feels very hacky to me though.

643. By Julián Unrrein

Merge changes from trunk

Revision history for this message
David Gomes (davidgomes) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/Application.vala'
2--- lib/Application.vala 2013-08-19 09:23:04 +0000
3+++ lib/Application.vala 2013-12-02 19:05:53 +0000
4@@ -81,6 +81,8 @@
5
6 Intl.bindtextdomain (exec_name, build_data_dir + "/locale");
7
8+ add_actions ();
9+
10 // Deprecated
11 Granite.app = this;
12 }
13@@ -109,13 +111,22 @@
14
15 set_options ();
16
17+ if (ABOUT) {
18+ Gtk.init (ref args);
19+ handle_about_parameter ();
20+
21+ return Posix.EXIT_SUCCESS;
22+ }
23+
24 return base.run (args);
25 }
26
27 protected static bool DEBUG = false;
28+ protected static bool ABOUT = false;
29
30 protected const OptionEntry[] options = {
31 { "debug", 'd', 0, OptionArg.NONE, out DEBUG, "Enable debug logging", null },
32+ { "about", 'a', 0, OptionArg.NONE, out ABOUT, "Show About dialog", null },
33 { null }
34 };
35
36@@ -151,7 +162,7 @@
37 assert (parent is Gtk.Window);
38
39 var developers_string = _("Developers");
40-
41+
42 Granite.Widgets.show_about_dialog ((Gtk.Window) parent,
43 "program_name", program_name,
44 "version", build_version,
45@@ -173,5 +184,63 @@
46 "translate", translate_url,
47 "bug", bug_url);
48 }
49+
50+ /* Allows reusing the About dialog */
51+ private Gtk.Window about_dialog_parent = null;
52+
53+ private void add_actions () {
54+ /* Actions are always executed in the primary instance, provided
55+ that the application was registered.
56+ Take advantage of this by showing the About dialog using the
57+ main instance, saving memory. */
58+ var show_about_action = new SimpleAction ("show-about-dialog", null);
59+
60+ show_about_action.activate.connect (() => {
61+ hold ();
62+
63+ debug ("The show-about-dialog action was activated");
64+
65+ if (this.about_dialog_parent == null)
66+ this.about_dialog_parent = new Gtk.Window ();
67+
68+ show_about (this.about_dialog_parent);
69+
70+ release ();
71+ });
72+
73+ add_action (show_about_action);
74+ }
75+
76+ private void handle_about_parameter () {
77+ try {
78+ register ();
79+ } catch (Error error) {
80+ warning ("Couldn't register application: %s", error.message);
81+ }
82+
83+ activate_action ("show-about-dialog", null);
84+
85+ if (!this.is_remote) {
86+ /* This means that the primary instance was created by running
87+ "app --about".
88+ Manually set up exit conditions and run the main loop of the
89+ application.
90+ This is needed to prevent weird stuff from happening if the
91+ actual application is opened while this is running. */
92+ Gtk.Widget about_dialog = this.about_dialog_parent.get_data ("gtk-about-dialog");
93+
94+ about_dialog.hide.connect (() => {
95+ if (get_windows () == null)
96+ Gtk.main_quit ();
97+ });
98+
99+ window_removed.connect (() => {
100+ if (get_windows () == null)
101+ Gtk.main_quit ();
102+ });
103+
104+ Gtk.main ();
105+ }
106+ }
107 }
108 }
109
110=== modified file 'lib/Widgets/AboutDialog.vala'
111--- lib/Widgets/AboutDialog.vala 2013-03-20 15:42:25 +0000
112+++ lib/Widgets/AboutDialog.vala 2013-12-02 19:05:53 +0000
113@@ -10,7 +10,7 @@
114 but WITHOUT ANY WARRANTY; without even the implied warranty of
115 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
116 Lesser General Public License for more details.
117-
118+
119 You should have received a copy of the GNU Lesser General
120 Public License along with this library; if not, write to the
121 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,

Subscribers

People subscribed via source and target branches