Back to index

unity-lens-music  6.0.0
main.c
Go to the documentation of this file.
00001 /* main.c generated by valac 0.14.2, the Vala compiler
00002  * generated from main.vala, do not modify */
00003 
00004 /*
00005  * Copyright (C) 2011 Canonical Ltd
00006  *
00007  * This program is free software: you can redistribute it and/or modify
00008  * it under the terms of the GNU General Public License version 3 as
00009  * published by the Free Software Foundation.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00018  *
00019  * Authored by Mikkel Kamstrup Erlandsen <mikkel.kamstrup@canonical.com>
00020  *             Alex Launi <alex.launi@canonical.com>
00021  *
00022  */
00023 
00024 #include <glib.h>
00025 #include <glib-object.h>
00026 #include <gio/gio.h>
00027 #include <stdlib.h>
00028 #include <string.h>
00029 #include <glib/gi18n-lib.h>
00030 #include <locale.h>
00031 
00032 
00033 #define UNITY_MUSIC_LENS_TYPE_DAEMON (unity_music_lens_daemon_get_type ())
00034 #define UNITY_MUSIC_LENS_DAEMON(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), UNITY_MUSIC_LENS_TYPE_DAEMON, UnityMusicLensDaemon))
00035 #define UNITY_MUSIC_LENS_DAEMON_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), UNITY_MUSIC_LENS_TYPE_DAEMON, UnityMusicLensDaemonClass))
00036 #define UNITY_MUSIC_LENS_IS_DAEMON(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), UNITY_MUSIC_LENS_TYPE_DAEMON))
00037 #define UNITY_MUSIC_LENS_IS_DAEMON_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), UNITY_MUSIC_LENS_TYPE_DAEMON))
00038 #define UNITY_MUSIC_LENS_DAEMON_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), UNITY_MUSIC_LENS_TYPE_DAEMON, UnityMusicLensDaemonClass))
00039 
00040 typedef struct _UnityMusicLensDaemon UnityMusicLensDaemon;
00041 typedef struct _UnityMusicLensDaemonClass UnityMusicLensDaemonClass;
00042 #define _g_variant_type_free0(var) ((var == NULL) ? NULL : (var = (g_variant_type_free (var), NULL)))
00043 #define _g_variant_unref0(var) ((var == NULL) ? NULL : (var = (g_variant_unref (var), NULL)))
00044 #define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
00045 #define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
00046 
00047 
00048 extern GApplication* unity_music_lens_app;
00049 GApplication* unity_music_lens_app = NULL;
00050 extern UnityMusicLensDaemon* unity_music_lens_daemon;
00051 UnityMusicLensDaemon* unity_music_lens_daemon = NULL;
00052 
00053 GType unity_music_lens_daemon_get_type (void) G_GNUC_CONST;
00054 gboolean unity_music_lens_dbus_name_has_owner (const gchar* name);
00055 gint unity_music_lens_main (gchar** args, int args_length1);
00056 #define CONFIG_PACKAGE "unity-lens-music"
00057 #define CONFIG_LOCALEDIR "/usr/local/share/locale"
00058 UnityMusicLensDaemon* unity_music_lens_daemon_new (void);
00059 UnityMusicLensDaemon* unity_music_lens_daemon_construct (GType object_type);
00060 
00061 
00062 gboolean unity_music_lens_dbus_name_has_owner (const gchar* name) {
00063        gboolean result = FALSE;
00064        GError * _inner_error_ = NULL;
00065        g_return_val_if_fail (name != NULL, FALSE);
00066        {
00067               gboolean has_owner = FALSE;
00068               GDBusConnection* _tmp0_ = NULL;
00069               GDBusConnection* bus;
00070               GDBusConnection* _tmp1_;
00071               const gchar* _tmp2_;
00072               GVariant* _tmp3_;
00073               GVariant* _tmp4_;
00074               GVariantType* _tmp5_;
00075               GVariantType* _tmp6_;
00076               GVariant* _tmp7_ = NULL;
00077               GVariant* _tmp8_;
00078               GVariant* _result_;
00079               GVariant* _tmp9_;
00080               _tmp0_ = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &_inner_error_);
00081               bus = _tmp0_;
00082               if (_inner_error_ != NULL) {
00083                      goto __catch3_g_error;
00084               }
00085               _tmp1_ = bus;
00086               _tmp2_ = name;
00087               _tmp3_ = g_variant_new ("(s)", _tmp2_, NULL);
00088               _tmp4_ = g_variant_ref_sink (_tmp3_);
00089               _tmp5_ = g_variant_type_new ("(b)");
00090               _tmp6_ = _tmp5_;
00091               _tmp7_ = g_dbus_connection_call_sync (_tmp1_, "org.freedesktop.DBus", "/org/freedesktop/dbus", "org.freedesktop.DBus", "NameHasOwner", _tmp4_, _tmp6_, G_DBUS_CALL_FLAGS_NO_AUTO_START, -1, NULL, &_inner_error_);
00092               _tmp8_ = _tmp7_;
00093               _g_variant_type_free0 (_tmp6_);
00094               _g_variant_unref0 (_tmp4_);
00095               _result_ = _tmp8_;
00096               if (_inner_error_ != NULL) {
00097                      _g_object_unref0 (bus);
00098                      goto __catch3_g_error;
00099               }
00100               _tmp9_ = _result_;
00101               g_variant_get (_tmp9_, "(b)", &has_owner, NULL);
00102               result = has_owner;
00103               _g_variant_unref0 (_result_);
00104               _g_object_unref0 (bus);
00105               return result;
00106        }
00107        goto __finally3;
00108        __catch3_g_error:
00109        {
00110               GError* e = NULL;
00111               const gchar* _tmp10_;
00112               GError* _tmp11_;
00113               const gchar* _tmp12_;
00114               e = _inner_error_;
00115               _inner_error_ = NULL;
00116               _tmp10_ = name;
00117               _tmp11_ = e;
00118               _tmp12_ = _tmp11_->message;
00119               g_warning ("main.vala:47: Unable to decide whether '%s' is running: %s", _tmp10_, _tmp12_);
00120               _g_error_free0 (e);
00121        }
00122        __finally3:
00123        if (_inner_error_ != NULL) {
00124               g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
00125               g_clear_error (&_inner_error_);
00126               return FALSE;
00127        }
00128        result = FALSE;
00129        return result;
00130 }
00131 
00132 
00133 gint unity_music_lens_main (gchar** args, int args_length1) {
00134        gint result = 0;
00135        gboolean _tmp0_ = FALSE;
00136        UnityMusicLensDaemon* _tmp1_;
00137        GApplication* _tmp2_;
00138        GApplication* _tmp6_;
00139        gboolean _tmp7_ = FALSE;
00140        GApplication* _tmp8_;
00141        GApplication* _tmp9_;
00142        gint _tmp10_ = 0;
00143        GError * _inner_error_ = NULL;
00144        textdomain (CONFIG_PACKAGE);
00145        bindtextdomain (CONFIG_PACKAGE, CONFIG_LOCALEDIR);
00146        bind_textdomain_codeset (CONFIG_PACKAGE, "UTF-8");
00147        setlocale (LC_ALL, "");
00148        _tmp0_ = unity_music_lens_dbus_name_has_owner ("com.canonical.Unity.Lens.Music");
00149        if (_tmp0_) {
00150               g_print ("%s", "Another instance of the Unity Music Daemon " "already appears to be running.\nBailing out.\n");
00151               result = 2;
00152               return result;
00153        }
00154        _tmp1_ = unity_music_lens_daemon_new ();
00155        _g_object_unref0 (unity_music_lens_daemon);
00156        unity_music_lens_daemon = _tmp1_;
00157        _tmp2_ = g_application_new ("com.canonical.Unity.Lens.Music", G_APPLICATION_IS_SERVICE);
00158        _g_object_unref0 (unity_music_lens_app);
00159        unity_music_lens_app = _tmp2_;
00160        {
00161               GApplication* _tmp3_;
00162               _tmp3_ = unity_music_lens_app;
00163               g_application_register (_tmp3_, NULL, &_inner_error_);
00164               if (_inner_error_ != NULL) {
00165                      goto __catch4_g_error;
00166               }
00167        }
00168        goto __finally4;
00169        __catch4_g_error:
00170        {
00171               GError* e = NULL;
00172               GError* _tmp4_;
00173               const gchar* _tmp5_;
00174               e = _inner_error_;
00175               _inner_error_ = NULL;
00176               _tmp4_ = e;
00177               _tmp5_ = _tmp4_->message;
00178               g_print ("Failed to start music daemon: %s\n", _tmp5_);
00179               result = 1;
00180               _g_error_free0 (e);
00181               return result;
00182        }
00183        __finally4:
00184        if (_inner_error_ != NULL) {
00185               g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
00186               g_clear_error (&_inner_error_);
00187               return 0;
00188        }
00189        _tmp6_ = unity_music_lens_app;
00190        _tmp7_ = g_application_get_is_remote (_tmp6_);
00191        if (_tmp7_) {
00192               g_print ("%s", "Another instance of the Unity Music Daemon " "already appears to be running.\nBailing out.\n");
00193               result = 2;
00194               return result;
00195        }
00196        _tmp8_ = unity_music_lens_app;
00197        g_application_hold (_tmp8_);
00198        _tmp9_ = unity_music_lens_app;
00199        _tmp10_ = g_application_run (_tmp9_, 0, NULL);
00200        result = _tmp10_;
00201        return result;
00202 }
00203 
00204 
00205 int main (int argc, char ** argv) {
00206        g_type_init ();
00207        return unity_music_lens_main (argv, argc);
00208 }
00209 
00210 
00211