Back to index

unity-lens-music  6.0.0
musicstore-daemon.c
Go to the documentation of this file.
00001 /* musicstore-daemon.c generated by valac 0.14.2, the Vala compiler
00002  * generated from musicstore-daemon.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 Alex Launi <alex.launi@canonical.com>
00020  *
00021  */
00022 
00023 #include <glib.h>
00024 #include <glib-object.h>
00025 #include <gio/gio.h>
00026 #include <stdlib.h>
00027 #include <string.h>
00028 #include <glib/gi18n-lib.h>
00029 #include <locale.h>
00030 
00031 
00032 #define UNITY_MUSIC_LENS_TYPE_SIMPLE_SCOPE (unity_music_lens_simple_scope_get_type ())
00033 #define UNITY_MUSIC_LENS_SIMPLE_SCOPE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), UNITY_MUSIC_LENS_TYPE_SIMPLE_SCOPE, UnityMusicLensSimpleScope))
00034 #define UNITY_MUSIC_LENS_SIMPLE_SCOPE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), UNITY_MUSIC_LENS_TYPE_SIMPLE_SCOPE, UnityMusicLensSimpleScopeClass))
00035 #define UNITY_MUSIC_LENS_IS_SIMPLE_SCOPE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), UNITY_MUSIC_LENS_TYPE_SIMPLE_SCOPE))
00036 #define UNITY_MUSIC_LENS_IS_SIMPLE_SCOPE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), UNITY_MUSIC_LENS_TYPE_SIMPLE_SCOPE))
00037 #define UNITY_MUSIC_LENS_SIMPLE_SCOPE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), UNITY_MUSIC_LENS_TYPE_SIMPLE_SCOPE, UnityMusicLensSimpleScopeClass))
00038 
00039 typedef struct _UnityMusicLensSimpleScope UnityMusicLensSimpleScope;
00040 typedef struct _UnityMusicLensSimpleScopeClass UnityMusicLensSimpleScopeClass;
00041 
00042 #define UNITY_MUSIC_LENS_TYPE_MUSIC_STORE_SCOPE_PROXY (unity_music_lens_music_store_scope_proxy_get_type ())
00043 #define UNITY_MUSIC_LENS_MUSIC_STORE_SCOPE_PROXY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), UNITY_MUSIC_LENS_TYPE_MUSIC_STORE_SCOPE_PROXY, UnityMusicLensMusicStoreScopeProxy))
00044 #define UNITY_MUSIC_LENS_MUSIC_STORE_SCOPE_PROXY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), UNITY_MUSIC_LENS_TYPE_MUSIC_STORE_SCOPE_PROXY, UnityMusicLensMusicStoreScopeProxyClass))
00045 #define UNITY_MUSIC_LENS_IS_MUSIC_STORE_SCOPE_PROXY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), UNITY_MUSIC_LENS_TYPE_MUSIC_STORE_SCOPE_PROXY))
00046 #define UNITY_MUSIC_LENS_IS_MUSIC_STORE_SCOPE_PROXY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), UNITY_MUSIC_LENS_TYPE_MUSIC_STORE_SCOPE_PROXY))
00047 #define UNITY_MUSIC_LENS_MUSIC_STORE_SCOPE_PROXY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), UNITY_MUSIC_LENS_TYPE_MUSIC_STORE_SCOPE_PROXY, UnityMusicLensMusicStoreScopeProxyClass))
00048 
00049 typedef struct _UnityMusicLensMusicStoreScopeProxy UnityMusicLensMusicStoreScopeProxy;
00050 typedef struct _UnityMusicLensMusicStoreScopeProxyClass UnityMusicLensMusicStoreScopeProxyClass;
00051 #define _g_variant_type_free0(var) ((var == NULL) ? NULL : (var = (g_variant_type_free (var), NULL)))
00052 #define _g_variant_unref0(var) ((var == NULL) ? NULL : (var = (g_variant_unref (var), NULL)))
00053 #define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
00054 #define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
00055 
00056 
00057 extern GApplication* unity_music_lens_app;
00058 GApplication* unity_music_lens_app = NULL;
00059 extern UnityMusicLensMusicStoreScopeProxy* unity_music_lens_daemon;
00060 UnityMusicLensMusicStoreScopeProxy* unity_music_lens_daemon = NULL;
00061 
00062 GType unity_music_lens_simple_scope_get_type (void) G_GNUC_CONST;
00063 GType unity_music_lens_music_store_scope_proxy_get_type (void) G_GNUC_CONST;
00064 gboolean unity_music_lens_dbus_name_has_owner (const gchar* name);
00065 gint unity_music_lens_main (gchar** args, int args_length1);
00066 #define CONFIG_PACKAGE "unity-lens-music"
00067 #define CONFIG_LOCALEDIR "/usr/local/share/locale"
00068 UnityMusicLensMusicStoreScopeProxy* unity_music_lens_music_store_scope_proxy_new (void);
00069 UnityMusicLensMusicStoreScopeProxy* unity_music_lens_music_store_scope_proxy_construct (GType object_type);
00070 
00071 
00072 gboolean unity_music_lens_dbus_name_has_owner (const gchar* name) {
00073        gboolean result = FALSE;
00074        GError * _inner_error_ = NULL;
00075        g_return_val_if_fail (name != NULL, FALSE);
00076        {
00077               gboolean has_owner = FALSE;
00078               GDBusConnection* _tmp0_ = NULL;
00079               GDBusConnection* bus;
00080               GDBusConnection* _tmp1_;
00081               const gchar* _tmp2_;
00082               GVariant* _tmp3_;
00083               GVariant* _tmp4_;
00084               GVariantType* _tmp5_;
00085               GVariantType* _tmp6_;
00086               GVariant* _tmp7_ = NULL;
00087               GVariant* _tmp8_;
00088               GVariant* _result_;
00089               GVariant* _tmp9_;
00090               _tmp0_ = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &_inner_error_);
00091               bus = _tmp0_;
00092               if (_inner_error_ != NULL) {
00093                      goto __catch1_g_error;
00094               }
00095               _tmp1_ = bus;
00096               _tmp2_ = name;
00097               _tmp3_ = g_variant_new ("(s)", _tmp2_, NULL);
00098               _tmp4_ = g_variant_ref_sink (_tmp3_);
00099               _tmp5_ = g_variant_type_new ("(b)");
00100               _tmp6_ = _tmp5_;
00101               _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_);
00102               _tmp8_ = _tmp7_;
00103               _g_variant_type_free0 (_tmp6_);
00104               _g_variant_unref0 (_tmp4_);
00105               _result_ = _tmp8_;
00106               if (_inner_error_ != NULL) {
00107                      _g_object_unref0 (bus);
00108                      goto __catch1_g_error;
00109               }
00110               _tmp9_ = _result_;
00111               g_variant_get (_tmp9_, "(b)", &has_owner, NULL);
00112               result = has_owner;
00113               _g_variant_unref0 (_result_);
00114               _g_object_unref0 (bus);
00115               return result;
00116        }
00117        goto __finally1;
00118        __catch1_g_error:
00119        {
00120               GError* e = NULL;
00121               const gchar* _tmp10_;
00122               GError* _tmp11_;
00123               const gchar* _tmp12_;
00124               e = _inner_error_;
00125               _inner_error_ = NULL;
00126               _tmp10_ = name;
00127               _tmp11_ = e;
00128               _tmp12_ = _tmp11_->message;
00129               g_warning ("musicstore-daemon.vala:46: Unable to decide whether '%s' is running: %" \
00130 "s", _tmp10_, _tmp12_);
00131               _g_error_free0 (e);
00132        }
00133        __finally1:
00134        if (_inner_error_ != NULL) {
00135               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);
00136               g_clear_error (&_inner_error_);
00137               return FALSE;
00138        }
00139        result = FALSE;
00140        return result;
00141 }
00142 
00143 
00144 gint unity_music_lens_main (gchar** args, int args_length1) {
00145        gint result = 0;
00146        gboolean _tmp0_ = FALSE;
00147        UnityMusicLensMusicStoreScopeProxy* _tmp1_;
00148        GApplication* _tmp2_;
00149        GApplication* _tmp6_;
00150        gboolean _tmp7_ = FALSE;
00151        GApplication* _tmp8_;
00152        GApplication* _tmp9_;
00153        gint _tmp10_ = 0;
00154        GError * _inner_error_ = NULL;
00155        textdomain (CONFIG_PACKAGE);
00156        bindtextdomain (CONFIG_PACKAGE, CONFIG_LOCALEDIR);
00157        bind_textdomain_codeset (CONFIG_PACKAGE, "UTF-8");
00158        setlocale (LC_ALL, "");
00159        _tmp0_ = unity_music_lens_dbus_name_has_owner ("com.canonical.Unity.Scope.MusicStore");
00160        if (_tmp0_) {
00161               g_print ("%s", "Another instance of the UbuntuOne Music Daemon " "already appears to be running.\nBailing out.\n");
00162               result = 2;
00163               return result;
00164        }
00165        _tmp1_ = unity_music_lens_music_store_scope_proxy_new ();
00166        _g_object_unref0 (unity_music_lens_daemon);
00167        unity_music_lens_daemon = _tmp1_;
00168        _tmp2_ = g_application_new ("com.canonical.Unity.Scope.MusicStore", G_APPLICATION_IS_SERVICE);
00169        _g_object_unref0 (unity_music_lens_app);
00170        unity_music_lens_app = _tmp2_;
00171        {
00172               GApplication* _tmp3_;
00173               _tmp3_ = unity_music_lens_app;
00174               g_application_register (_tmp3_, NULL, &_inner_error_);
00175               if (_inner_error_ != NULL) {
00176                      goto __catch2_g_error;
00177               }
00178        }
00179        goto __finally2;
00180        __catch2_g_error:
00181        {
00182               GError* e = NULL;
00183               GError* _tmp4_;
00184               const gchar* _tmp5_;
00185               e = _inner_error_;
00186               _inner_error_ = NULL;
00187               _tmp4_ = e;
00188               _tmp5_ = _tmp4_->message;
00189               g_print ("Failed to start music daemon: %s\n", _tmp5_);
00190               result = 1;
00191               _g_error_free0 (e);
00192               return result;
00193        }
00194        __finally2:
00195        if (_inner_error_ != NULL) {
00196               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);
00197               g_clear_error (&_inner_error_);
00198               return 0;
00199        }
00200        _tmp6_ = unity_music_lens_app;
00201        _tmp7_ = g_application_get_is_remote (_tmp6_);
00202        if (_tmp7_) {
00203               g_print ("%s", "Another instance of the Unity Music Daemon " "already appears to be running.\nBailing out.\n");
00204               result = 2;
00205               return result;
00206        }
00207        _tmp8_ = unity_music_lens_app;
00208        g_application_hold (_tmp8_);
00209        _tmp9_ = unity_music_lens_app;
00210        _tmp10_ = g_application_run (_tmp9_, 0, NULL);
00211        result = _tmp10_;
00212        return result;
00213 }
00214 
00215 
00216 int main (int argc, char ** argv) {
00217        g_type_init ();
00218        return unity_music_lens_main (argv, argc);
00219 }
00220 
00221 
00222