~ubuntu-branches/ubuntu/precise/gwibber/precise-proposed

« back to all changes in this revision

Viewing changes to lens/src/main.c

  • Committer: Bazaar Package Importer
  • Author(s): Ken VanDine
  • Date: 2011-07-15 17:14:14 UTC
  • mto: This revision was merged to the branch mainline in revision 80.
  • Revision ID: james.westby@ubuntu.com-20110715171414-80ca971vzd56gtmh
Tags: upstream-3.1.2
ImportĀ upstreamĀ versionĀ 3.1.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* main.c generated by valac 0.12.0, 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 it
 
8
 * under the terms of the GNU General Public License version 3, as published
 
9
 * by the Free Software Foundation.
 
10
 
 
11
 * This program is distributed in the hope that it will be useful, but
 
12
 * WITHOUT ANY WARRANTY; without even the implied warranties of
 
13
 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
 
14
 * PURPOSE.  See the GNU General Public License for more details.
 
15
 
 
16
 * You should have received a copy of the GNU General Public License along
 
17
 * with this program.  If not, see <http://www.gnu.org/licenses/>.
 
18
 *
 
19
 * Authored by Ken VanDine <ken.vandine@canonical.com>
 
20
 */
 
21
 
 
22
#include <glib.h>
 
23
#include <glib-object.h>
 
24
#include <gio/gio.h>
 
25
#include <stdlib.h>
 
26
#include <string.h>
 
27
#include <glib/gi18n-lib.h>
 
28
#include <config.h>
 
29
#include <locale.h>
 
30
#include <gio/gdesktopappinfo.h>
 
31
 
 
32
 
 
33
#define GWIBBER_TYPE_DAEMON (gwibber_daemon_get_type ())
 
34
#define GWIBBER_DAEMON(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GWIBBER_TYPE_DAEMON, GwibberDaemon))
 
35
#define GWIBBER_DAEMON_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GWIBBER_TYPE_DAEMON, GwibberDaemonClass))
 
36
#define GWIBBER_IS_DAEMON(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GWIBBER_TYPE_DAEMON))
 
37
#define GWIBBER_IS_DAEMON_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GWIBBER_TYPE_DAEMON))
 
38
#define GWIBBER_DAEMON_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GWIBBER_TYPE_DAEMON, GwibberDaemonClass))
 
39
 
 
40
typedef struct _GwibberDaemon GwibberDaemon;
 
41
typedef struct _GwibberDaemonClass GwibberDaemonClass;
 
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* gwibber_app;
 
49
GApplication* gwibber_app = NULL;
 
50
extern GwibberDaemon* gwibber_daemon;
 
51
GwibberDaemon* gwibber_daemon = NULL;
 
52
 
 
53
GType gwibber_daemon_get_type (void) G_GNUC_CONST;
 
54
gboolean gwibber_dbus_name_has_owner (const gchar* name);
 
55
gint gwibber_main (gchar** args, int args_length1);
 
56
GwibberDaemon* gwibber_daemon_new (void);
 
57
GwibberDaemon* gwibber_daemon_construct (GType object_type);
 
58
 
 
59
 
 
60
gboolean gwibber_dbus_name_has_owner (const gchar* name) {
 
61
        gboolean result = FALSE;
 
62
        gboolean has_owner = FALSE;
 
63
        GDBusConnection* _tmp0_ = NULL;
 
64
        GDBusConnection* bus;
 
65
        GVariant* _tmp1_ = NULL;
 
66
        GVariant* _tmp2_;
 
67
        GVariantType* _tmp3_ = NULL;
 
68
        GVariantType* _tmp4_;
 
69
        GVariant* _tmp5_ = NULL;
 
70
        GVariant* _tmp6_;
 
71
        GVariant* _result_;
 
72
        GError * _inner_error_ = NULL;
 
73
        g_return_val_if_fail (name != NULL, FALSE);
 
74
        _tmp0_ = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &_inner_error_);
 
75
        bus = _tmp0_;
 
76
        if (_inner_error_ != NULL) {
 
77
                if (_inner_error_->domain == G_IO_ERROR) {
 
78
                        goto __catch1_g_io_error;
 
79
                }
 
80
                g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
 
81
                g_clear_error (&_inner_error_);
 
82
                return FALSE;
 
83
        }
 
84
        _tmp1_ = g_variant_new ("(s)", name, NULL);
 
85
        _tmp2_ = g_variant_ref_sink (_tmp1_);
 
86
        _tmp3_ = g_variant_type_new ("(b)");
 
87
        _tmp4_ = _tmp3_;
 
88
        _tmp5_ = g_dbus_connection_call_sync (bus, "org.freedesktop.DBus", "/org/freedesktop/dbus", "org.freedesktop.DBus", "NameHasOwner", _tmp2_, _tmp4_, G_DBUS_CALL_FLAGS_NO_AUTO_START, -1, NULL, &_inner_error_);
 
89
        _tmp6_ = _tmp5_;
 
90
        _g_variant_type_free0 (_tmp4_);
 
91
        _g_variant_unref0 (_tmp2_);
 
92
        _result_ = _tmp6_;
 
93
        if (_inner_error_ != NULL) {
 
94
                _g_object_unref0 (bus);
 
95
                if (_inner_error_->domain == G_IO_ERROR) {
 
96
                        goto __catch1_g_io_error;
 
97
                }
 
98
                goto __finally1;
 
99
        }
 
100
        g_variant_get (_result_, "(b)", &has_owner, NULL);
 
101
        result = has_owner;
 
102
        _g_variant_unref0 (_result_);
 
103
        _g_object_unref0 (bus);
 
104
        return result;
 
105
        _g_variant_unref0 (_result_);
 
106
        _g_object_unref0 (bus);
 
107
        goto __finally1;
 
108
        __catch1_g_io_error:
 
109
        {
 
110
                GError * e;
 
111
                e = _inner_error_;
 
112
                _inner_error_ = NULL;
 
113
                g_warning ("main.vala:42: Unable to decide whether '%s' is running: %s", name, e->message);
 
114
                _g_error_free0 (e);
 
115
        }
 
116
        __finally1:
 
117
        if (_inner_error_ != NULL) {
 
118
                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);
 
119
                g_clear_error (&_inner_error_);
 
120
                return FALSE;
 
121
        }
 
122
        result = FALSE;
 
123
        return result;
 
124
}
 
125
 
 
126
 
 
127
gint gwibber_main (gchar** args, int args_length1) {
 
128
        gint result = 0;
 
129
        gboolean _tmp0_;
 
130
        GwibberDaemon* _tmp1_ = NULL;
 
131
        GApplication* _tmp2_ = NULL;
 
132
        gboolean _tmp3_;
 
133
        gint _tmp4_;
 
134
        GError * _inner_error_ = NULL;
 
135
        textdomain (PACKAGE);
 
136
        bindtextdomain (PACKAGE, LOCALE_DIR);
 
137
        bind_textdomain_codeset (PACKAGE, "UTF-8");
 
138
        setlocale (LC_ALL, "");
 
139
        g_desktop_app_info_set_desktop_env ("GNOME");
 
140
        _tmp0_ = gwibber_dbus_name_has_owner ("com.canonical.Unity.Gwibber");
 
141
        if (_tmp0_) {
 
142
                g_print ("%s", "Another instance of the Unity Gwibber Daemon " "already appears to be running.\nBailing out.\n");
 
143
                result = 2;
 
144
                return result;
 
145
        }
 
146
        _tmp1_ = gwibber_daemon_new ();
 
147
        _g_object_unref0 (gwibber_daemon);
 
148
        gwibber_daemon = _tmp1_;
 
149
        _tmp2_ = g_application_new ("com.canonical.Unity.Gwibber", G_APPLICATION_IS_SERVICE);
 
150
        _g_object_unref0 (gwibber_app);
 
151
        gwibber_app = _tmp2_;
 
152
        g_application_register (gwibber_app, NULL, &_inner_error_);
 
153
        if (_inner_error_ != NULL) {
 
154
                goto __catch2_g_error;
 
155
        }
 
156
        goto __finally2;
 
157
        __catch2_g_error:
 
158
        {
 
159
                GError * e;
 
160
                e = _inner_error_;
 
161
                _inner_error_ = NULL;
 
162
                g_print ("Failed to start applications daemon: %s\n", e->message);
 
163
                result = 1;
 
164
                _g_error_free0 (e);
 
165
                return result;
 
166
        }
 
167
        __finally2:
 
168
        if (_inner_error_ != NULL) {
 
169
                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);
 
170
                g_clear_error (&_inner_error_);
 
171
                return 0;
 
172
        }
 
173
        _tmp3_ = g_application_get_is_remote (gwibber_app);
 
174
        if (_tmp3_) {
 
175
                g_print ("%s", "Another instance of the Unity Applications Daemon " "already appears to be running.\nBailing out.\n");
 
176
                result = 2;
 
177
                return result;
 
178
        }
 
179
        g_application_hold (gwibber_app);
 
180
        _tmp4_ = g_application_run (gwibber_app, 0, NULL);
 
181
        result = _tmp4_;
 
182
        return result;
 
183
}
 
184
 
 
185
 
 
186
int main (int argc, char ** argv) {
 
187
        g_type_init ();
 
188
        return gwibber_main (argv, argc);
 
189
}
 
190
 
 
191
 
 
192