[vinagre/vala-rewrite: 1/2] Port application entry point to Vala



commit 2d060fab3e25ccccfb8254f93946dc50bd8f2cb4
Author: David King <amigadave amigadave com>
Date:   Fri Jul 8 20:50:45 2011 +0200

    Port application entry point to Vala

 Makefile.am                      |    6 +-
 autogen.sh                       |    4 +-
 configure.ac                     |    2 +-
 vinagre/vapi/config.vapi         |    2 +
 vinagre/vinagre-application.vala |  149 +++++++++++++++++++++++++++++++++++++
 vinagre/vinagre-options.c        |  151 --------------------------------------
 vinagre/vinagre-options.h        |   43 -----------
 7 files changed, 155 insertions(+), 202 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index 9ed1bad..34f7bf7 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -5,9 +5,6 @@ DISTCHECK_CONFIGURE_FLAGS = --disable-scrollkeeper
 
 common_cppflags = \
 	-I$(top_builddir) \
-	-I$(top_builddir)/vinagre \
-	-I$(top_srcdir) \
-	-I$(top_srcdir)/vinagre/view \
 	-DBINDIR=\"$(bindir)\" \
 	-DDATADIR=\"$(datadir)\" \
 	-DPREFIX=\""$(prefix)"\" \
@@ -15,7 +12,6 @@ common_cppflags = \
 	-DLIBDIR=\""$(libdir)"\" \
 	-DVINAGRE_DATADIR=\""$(pkgdatadir)"\" \
 	-DPACKAGE_LOCALE_DIR=\""$(datadir)/locale"\" \
-	-DSSH_PROGRAM=\"$(SSH_PROGRAM)\" \
 	$(VINAGRE_CFLAGS) \
 	$(WARN_FLAGS) \
 	$(DISABLE_DEPRECATED_FLAGS)
@@ -37,7 +33,7 @@ ifaddrs_sources = \
 endif
 
 vinagre_vinagre_SOURCES = \
-	vinagre/vinagre-main.c \
+	vinagre/vinagre-application.vala \
 	vinagre/vinagre-options.c
 
 vinagre_vinagre_LDADD = \
diff --git a/autogen.sh b/autogen.sh
index 053cb11..8146851 100755
--- a/autogen.sh
+++ b/autogen.sh
@@ -6,14 +6,14 @@ test -z "$srcdir" && srcdir=.
 
 PKG_NAME="vinagre"
 
-(test -f $srcdir/vinagre/vinagre-main.c) || {
+(test -f $srcdir/vinagre/vinagre-application.vala) || {
     echo -n "**Error**: Directory "\`$srcdir\'" does not look like the"
     echo " top-level $PKG_NAME directory"
     exit 1
 }
 
 which gnome-autogen.sh || {
-    echo "You need to install gnome-common from the GNOME git"
+    echo "You need to install gnome-common from GNOME git"
     exit 1
 }
 
diff --git a/configure.ac b/configure.ac
index 9e443ee..0989487 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1,7 +1,7 @@
 AC_PREREQ([2.64])
 AC_INIT([Vinagre], [3.1.4], [https://bugzilla.gnome.org/enter_bug.cgi?product=vinagre], [vinagre], [http://projects.gnome.org/vinagre/])
 AC_CONFIG_AUX_DIR([build-aux])
-AC_CONFIG_SRCDIR([vinagre/vinagre-main.c])
+AC_CONFIG_SRCDIR([vinagre/vinagre-application.vala])
 AC_CONFIG_HEADERS([config.h])
 AC_CONFIG_MACRO_DIR([m4])
 
diff --git a/vinagre/vapi/config.vapi b/vinagre/vapi/config.vapi
index 4f13d60..d711690 100644
--- a/vinagre/vapi/config.vapi
+++ b/vinagre/vapi/config.vapi
@@ -4,6 +4,8 @@ namespace Vinagre.Config
 {
     public const string DATADIR;
     public const string LIBDIR;
+    public const string GETTEXT_PACKAGE;
+    public const string PACKAGE_LOCALEDIR;
     public const string PACKAGE_TARNAME;
     public const string PACKAGE_URL;
     public const string PACKAGE_VERSION;
diff --git a/vinagre/vinagre-application.vala b/vinagre/vinagre-application.vala
new file mode 100644
index 0000000..b6db00d
--- /dev/null
+++ b/vinagre/vinagre-application.vala
@@ -0,0 +1,149 @@
+/*  Vinagre - GNOME Remote Desktop viewer
+ *
+ *  Copyright (C) 2011  David King <amigadave amigadave com>
+ *
+ *  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/>.
+ */
+
+public class Vinagre.Application : Gtk.Application {
+    // FIXME: Place in optionstate struct.
+    static string geometry;
+    static bool fullscreen;
+    static bool new_window;
+    static string filenames[];
+    static string uris[];
+
+    private const string application_path = "org.gnome.Vinagre";
+    // FIXME: Move into Vinagre.Options?
+    const OptionEntry[] options = {
+        {"geometry", 0, 0, OptionArg.STRING, ref geometry,
+            N_("Specify geometry of the main Vinagre window"), null},
+        {"fullscreen", 'f', 0, OptionArg.NONE, ref fullscreen,
+            N_("Open Vinagre in fullscreen mode"), null},
+        {"new-window", 'n', 0, OptionArg.NONE, ref new_window,
+            N_("Create a new toplevel window in an existing instance of Vinagre"),
+            null},
+        {"file", 'F', 0, OptionArg.FILENAME_ARRAY, ref filenames,
+            N_("Open a file recognized by Vinagre"), null},
+        // "" in this case is equivalent to G_OPTION_REMAINING.
+        {"", 0, 0, OptionArg.STRING_ARRAY, ref uris, null, N_("[server:port]")},
+        {null}
+    };
+
+    public Application (string app_id, ApplicationFlags flags) {
+        GLib.Object (application_id: app_id, flags: flags);
+    }
+
+    construct {
+        activate.connect (on_activate);
+        command_line.connect (on_command_line);
+    }
+
+    public void on_activate () {
+        var windows = get_windows ();
+        if (windows != null) {
+            windows.foreach ((window) => {
+                window.present_with_time (Gdk.CURRENT_TIME);
+            });
+        } else {
+            var window = new Gtk.Window ();
+
+            Environment.set_application_name (_("Remote Desktop Viewer"));
+            window.set_default_icon_name (Config.PACKAGE_TARNAME);
+
+            window.destroy.connect (Gtk.main_quit);
+            window.show ();
+        }
+    }
+
+    public int on_command_line (ApplicationCommandLine command_line) {
+        var arguments = command_line.get_arguments ();
+
+        try {
+            // FIXME: make the string the same as above, and use printf.
+            var context = new OptionContext (_("â Remote Desktop Viewer"));
+            context.add_main_entries (options, Config.GETTEXT_PACKAGE);
+            context.add_group (Gtk.get_option_group (true));
+
+            // TODO: Register plugin stuff with the context here.
+            context.parse (ref arguments);
+            process_parsed_command_line ();
+        }
+        catch (OptionError error) {
+            command_line.printerr ("%s\n", error.message);
+            command_line.printerr (_("Run â%s --helpâ to see a full list of available command-line options.\n"), arguments[0]);
+            // FIXME: EXIT_FAILURE?
+            command_line.set_exit_status (1);
+        }
+    }
+
+    // FIXME: Should accept a window parameter.
+    private void process_parsed_command_line () {
+        SList<string> errors;
+
+        if (filenames != null) {
+            foreach (string file in filenames) {
+                stdout.printf ("New connection from file: %s", file);
+            };
+        }
+
+        if (uris != null) {
+            foreach (string uri in uris) {
+                stdout.printf ("New connection from URI: %s", uri);
+            };
+        }
+
+        if (/* connections != null && */ new_window) {
+            // TODO: Replace with Application.new_window().
+            var window = new Gtk.Window ();
+            window.show_all ();
+            window.set_application (this);
+        }
+
+        var windows = get_windows ();
+        // Set all windows to have the supplied geometry.
+        if (geometry != null) {
+            windows.foreach ((window) => {
+                if (!window.parse_geometry (geometry))
+                    errors.append (_("Invalid argument %s for --geometry").printf (geometry));
+            });
+        }
+
+        // Use the first window as the parent.
+        if (errors != null)
+            Utils.show_many_errors (ngettext
+                ("The following error has occurred:",
+                "The following errors have occurred:", errors.length ()),
+                errors, windows.first ());
+
+        windows.foreach ((window) => {window.present ();});
+    }
+}
+
+// Application entry point.
+public int main (string[] args) {
+    Intl.bindtextdomain (Vinagre.Config.GETTEXT_PACKAGE,
+        Vinagre.Config.PACKAGE_LOCALEDIR);
+    Intl.bind_textdomain_codeset (Vinagre.Config.GETTEXT_PACKAGE, "UTF-8");
+    Intl.textdomain (Vinagre.Config.GETTEXT_PACKAGE);
+
+    // This used to be "org.gnome.vinagre".
+    var app = new Vinagre.Application ("org.gnome.Vinagre",
+        ApplicationFlags.HANDLES_COMMAND_LINE);
+
+    // run() initialises GTK+, so there is no need to do it manually.
+    var result = app.run (args);
+
+    return result;
+}



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