~ricmm/+junk/unity-lens_music-sc

« back to all changes in this revision

Viewing changes to src/main.c

  • Committer: Ricardo Mendoza
  • Date: 2012-09-05 14:20:15 UTC
  • Revision ID: ricardo.mendoza@canonical.com-20120905142015-prem6hiyfshwgm8q
Initial commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* main.c generated by valac 0.16.1, the Vala compiler
 
2
 * generated from main.vala, do not modify */
 
3
 
 
4
/*
 
5
 * Copyright (C) 2011 Canonical Ltd
 
6
 *
 
7
 * This program is free software: you can redistribute it and/or modify
 
8
 * it under the terms of the GNU General Public License version 3 as
 
9
 * published by the Free Software Foundation.
 
10
 *
 
11
 * This program is distributed in the hope that it will be useful,
 
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 * GNU General Public License for more details.
 
15
 *
 
16
 * You should have received a copy of the GNU General Public License
 
17
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
18
 *
 
19
 * Authored by Mikkel Kamstrup Erlandsen <mikkel.kamstrup@canonical.com>
 
20
 *             Alex Launi <alex.launi@canonical.com>
 
21
 *
 
22
 */
 
23
 
 
24
#include <glib.h>
 
25
#include <glib-object.h>
 
26
#include <gio/gio.h>
 
27
#include <stdlib.h>
 
28
#include <string.h>
 
29
#include <glib/gi18n-lib.h>
 
30
#include <locale.h>
 
31
 
 
32
 
 
33
#define UNITY_MUSIC_LENS_TYPE_DAEMON (unity_music_lens_daemon_get_type ())
 
34
#define UNITY_MUSIC_LENS_DAEMON(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), UNITY_MUSIC_LENS_TYPE_DAEMON, UnityMusicLensDaemon))
 
35
#define UNITY_MUSIC_LENS_DAEMON_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), UNITY_MUSIC_LENS_TYPE_DAEMON, UnityMusicLensDaemonClass))
 
36
#define UNITY_MUSIC_LENS_IS_DAEMON(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), UNITY_MUSIC_LENS_TYPE_DAEMON))
 
37
#define UNITY_MUSIC_LENS_IS_DAEMON_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), UNITY_MUSIC_LENS_TYPE_DAEMON))
 
38
#define UNITY_MUSIC_LENS_DAEMON_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), UNITY_MUSIC_LENS_TYPE_DAEMON, UnityMusicLensDaemonClass))
 
39
 
 
40
typedef struct _UnityMusicLensDaemon UnityMusicLensDaemon;
 
41
typedef struct _UnityMusicLensDaemonClass UnityMusicLensDaemonClass;
 
42
#define _g_variant_type_free0(var) ((var == NULL) ? NULL : (var = (g_variant_type_free (var), NULL)))
 
43
#define _g_variant_unref0(var) ((var == NULL) ? NULL : (var = (g_variant_unref (var), NULL)))
 
44
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
 
45
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
 
46
 
 
47
 
 
48
extern GApplication* unity_music_lens_app;
 
49
GApplication* unity_music_lens_app = NULL;
 
50
extern UnityMusicLensDaemon* unity_music_lens_daemon;
 
51
UnityMusicLensDaemon* unity_music_lens_daemon = NULL;
 
52
 
 
53
GType unity_music_lens_daemon_get_type (void) G_GNUC_CONST;
 
54
gboolean unity_music_lens_dbus_name_has_owner (const gchar* name);
 
55
gint unity_music_lens_main (gchar** args, int args_length1);
 
56
#define CONFIG_PACKAGE "unity-lens-music"
 
57
#define CONFIG_LOCALEDIR "/usr/share/locale"
 
58
UnityMusicLensDaemon* unity_music_lens_daemon_new (void);
 
59
UnityMusicLensDaemon* unity_music_lens_daemon_construct (GType object_type);
 
60
 
 
61
 
 
62
gboolean unity_music_lens_dbus_name_has_owner (const gchar* name) {
 
63
        gboolean result = FALSE;
 
64
        GError * _inner_error_ = NULL;
 
65
        g_return_val_if_fail (name != NULL, FALSE);
 
66
        {
 
67
                gboolean has_owner = FALSE;
 
68
                GDBusConnection* _tmp0_ = NULL;
 
69
                GDBusConnection* bus;
 
70
                GDBusConnection* _tmp1_;
 
71
                const gchar* _tmp2_;
 
72
                GVariant* _tmp3_;
 
73
                GVariant* _tmp4_;
 
74
                GVariantType* _tmp5_;
 
75
                GVariantType* _tmp6_;
 
76
                GVariant* _tmp7_ = NULL;
 
77
                GVariant* _tmp8_;
 
78
                GVariant* _result_;
 
79
                GVariant* _tmp9_;
 
80
                _tmp0_ = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &_inner_error_);
 
81
                bus = _tmp0_;
 
82
                if (_inner_error_ != NULL) {
 
83
                        goto __catch3_g_error;
 
84
                }
 
85
                _tmp1_ = bus;
 
86
                _tmp2_ = name;
 
87
                _tmp3_ = g_variant_new ("(s)", _tmp2_, NULL);
 
88
                _tmp4_ = g_variant_ref_sink (_tmp3_);
 
89
                _tmp5_ = g_variant_type_new ("(b)");
 
90
                _tmp6_ = _tmp5_;
 
91
                _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_);
 
92
                _tmp8_ = _tmp7_;
 
93
                _g_variant_type_free0 (_tmp6_);
 
94
                _g_variant_unref0 (_tmp4_);
 
95
                _result_ = _tmp8_;
 
96
                if (_inner_error_ != NULL) {
 
97
                        _g_object_unref0 (bus);
 
98
                        goto __catch3_g_error;
 
99
                }
 
100
                _tmp9_ = _result_;
 
101
                g_variant_get (_tmp9_, "(b)", &has_owner, NULL);
 
102
                result = has_owner;
 
103
                _g_variant_unref0 (_result_);
 
104
                _g_object_unref0 (bus);
 
105
                return result;
 
106
        }
 
107
        goto __finally3;
 
108
        __catch3_g_error:
 
109
        {
 
110
                GError* e = NULL;
 
111
                const gchar* _tmp10_;
 
112
                GError* _tmp11_;
 
113
                const gchar* _tmp12_;
 
114
                e = _inner_error_;
 
115
                _inner_error_ = NULL;
 
116
                _tmp10_ = name;
 
117
                _tmp11_ = e;
 
118
                _tmp12_ = _tmp11_->message;
 
119
                g_warning ("main.vala:47: Unable to decide whether '%s' is running: %s", _tmp10_, _tmp12_);
 
120
                _g_error_free0 (e);
 
121
        }
 
122
        __finally3:
 
123
        if (_inner_error_ != NULL) {
 
124
                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);
 
125
                g_clear_error (&_inner_error_);
 
126
                return FALSE;
 
127
        }
 
128
        result = FALSE;
 
129
        return result;
 
130
}
 
131
 
 
132
 
 
133
gint unity_music_lens_main (gchar** args, int args_length1) {
 
134
        gint result = 0;
 
135
        gboolean _tmp0_ = FALSE;
 
136
        UnityMusicLensDaemon* _tmp1_;
 
137
        GApplication* _tmp2_;
 
138
        GApplication* _tmp6_;
 
139
        gboolean _tmp7_ = FALSE;
 
140
        GApplication* _tmp8_;
 
141
        GApplication* _tmp9_;
 
142
        gint _tmp10_ = 0;
 
143
        GError * _inner_error_ = NULL;
 
144
        textdomain (CONFIG_PACKAGE);
 
145
        bindtextdomain (CONFIG_PACKAGE, CONFIG_LOCALEDIR);
 
146
        bind_textdomain_codeset (CONFIG_PACKAGE, "UTF-8");
 
147
        setlocale (LC_ALL, "");
 
148
        _tmp0_ = unity_music_lens_dbus_name_has_owner ("com.canonical.Unity.Lens.Music");
 
149
        if (_tmp0_) {
 
150
                g_print ("%s", "Another instance of the Unity Music Daemon " "already appears to be running.\nBailing out.\n");
 
151
                result = 2;
 
152
                return result;
 
153
        }
 
154
        _tmp1_ = unity_music_lens_daemon_new ();
 
155
        _g_object_unref0 (unity_music_lens_daemon);
 
156
        unity_music_lens_daemon = _tmp1_;
 
157
        _tmp2_ = g_application_new ("com.canonical.Unity.Lens.Music", G_APPLICATION_IS_SERVICE);
 
158
        _g_object_unref0 (unity_music_lens_app);
 
159
        unity_music_lens_app = _tmp2_;
 
160
        {
 
161
                GApplication* _tmp3_;
 
162
                _tmp3_ = unity_music_lens_app;
 
163
                g_application_register (_tmp3_, NULL, &_inner_error_);
 
164
                if (_inner_error_ != NULL) {
 
165
                        goto __catch4_g_error;
 
166
                }
 
167
        }
 
168
        goto __finally4;
 
169
        __catch4_g_error:
 
170
        {
 
171
                GError* e = NULL;
 
172
                GError* _tmp4_;
 
173
                const gchar* _tmp5_;
 
174
                e = _inner_error_;
 
175
                _inner_error_ = NULL;
 
176
                _tmp4_ = e;
 
177
                _tmp5_ = _tmp4_->message;
 
178
                g_print ("Failed to start music daemon: %s\n", _tmp5_);
 
179
                result = 1;
 
180
                _g_error_free0 (e);
 
181
                return result;
 
182
        }
 
183
        __finally4:
 
184
        if (_inner_error_ != NULL) {
 
185
                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);
 
186
                g_clear_error (&_inner_error_);
 
187
                return 0;
 
188
        }
 
189
        _tmp6_ = unity_music_lens_app;
 
190
        _tmp7_ = g_application_get_is_remote (_tmp6_);
 
191
        if (_tmp7_) {
 
192
                g_print ("%s", "Another instance of the Unity Music Daemon " "already appears to be running.\nBailing out.\n");
 
193
                result = 2;
 
194
                return result;
 
195
        }
 
196
        _tmp8_ = unity_music_lens_app;
 
197
        g_application_hold (_tmp8_);
 
198
        _tmp9_ = unity_music_lens_app;
 
199
        _tmp10_ = g_application_run (_tmp9_, 0, NULL);
 
200
        result = _tmp10_;
 
201
        return result;
 
202
}
 
203
 
 
204
 
 
205
int main (int argc, char ** argv) {
 
206
        g_type_init ();
 
207
        return unity_music_lens_main (argv, argc);
 
208
}
 
209
 
 
210
 
 
211