~ubuntu-branches/ubuntu/wily/baobab/wily-proposed

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
/* baobab-connect-server.c generated by valac 0.17.4.2-5a035, the Vala compiler
 * generated from baobab-connect-server.vala, do not modify */

/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* Baobab - disk usage analyzer
 *
 * Copyright (C) 2012  Paolo Borelli <pborelli@gnome.org>
 *
 * 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 2
 * 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, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

#include <glib.h>
#include <glib-object.h>
#include <stdlib.h>
#include <string.h>


#define BAOBAB_TYPE_CONNECT_SERVER (baobab_connect_server_get_type ())
#define BAOBAB_CONNECT_SERVER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), BAOBAB_TYPE_CONNECT_SERVER, BaobabConnectServer))
#define BAOBAB_CONNECT_SERVER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), BAOBAB_TYPE_CONNECT_SERVER, BaobabConnectServerClass))
#define BAOBAB_IS_CONNECT_SERVER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), BAOBAB_TYPE_CONNECT_SERVER))
#define BAOBAB_IS_CONNECT_SERVER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), BAOBAB_TYPE_CONNECT_SERVER))
#define BAOBAB_CONNECT_SERVER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), BAOBAB_TYPE_CONNECT_SERVER, BaobabConnectServerClass))

typedef struct _BaobabConnectServer BaobabConnectServer;
typedef struct _BaobabConnectServerClass BaobabConnectServerClass;
typedef struct _BaobabConnectServerPrivate BaobabConnectServerPrivate;
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
#define _g_io_channel_unref0(var) ((var == NULL) ? NULL : (var = (g_io_channel_unref (var), NULL)))

struct _BaobabConnectServer {
	GObject parent_instance;
	BaobabConnectServerPrivate * priv;
};

struct _BaobabConnectServerClass {
	GObjectClass parent_class;
};


static gpointer baobab_connect_server_parent_class = NULL;

GType baobab_connect_server_get_type (void) G_GNUC_CONST;
enum  {
	BAOBAB_CONNECT_SERVER_DUMMY_PROPERTY
};
static void baobab_connect_server_on_child_watch (BaobabConnectServer* self, GPid pid, gint status);
static gboolean baobab_connect_server_on_out_watch (BaobabConnectServer* self, GIOChannel* channel, GIOCondition cond);
void baobab_connect_server_show (BaobabConnectServer* self);
static gboolean _baobab_connect_server_on_out_watch_gio_func (GIOChannel* source, GIOCondition condition, gpointer self);
static void _baobab_connect_server_on_child_watch_gchild_watch_func (GPid pid, gint status, gpointer self);
gboolean baobab_connect_server_available (void);
BaobabConnectServer* baobab_connect_server_new (void);
BaobabConnectServer* baobab_connect_server_construct (GType object_type);

static const gchar* BAOBAB_CONNECT_SERVER_argv[2] = {"nautilus-connect-server", "--print-uri"};

static void baobab_connect_server_on_child_watch (BaobabConnectServer* self, GPid pid, gint status) {
	GPid _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = pid;
	g_spawn_close_pid (_tmp0_);
}


static gchar* string_slice (const gchar* self, glong start, glong end) {
	gchar* result = NULL;
	gint _tmp0_;
	gint _tmp1_;
	glong string_length;
	glong _tmp2_;
	glong _tmp5_;
	gboolean _tmp8_ = FALSE;
	glong _tmp9_;
	gboolean _tmp12_;
	gboolean _tmp13_ = FALSE;
	glong _tmp14_;
	gboolean _tmp17_;
	glong _tmp18_;
	glong _tmp19_;
	glong _tmp20_;
	glong _tmp21_;
	glong _tmp22_;
	gchar* _tmp23_ = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = strlen (self);
	_tmp1_ = _tmp0_;
	string_length = (glong) _tmp1_;
	_tmp2_ = start;
	if (_tmp2_ < ((glong) 0)) {
		glong _tmp3_;
		glong _tmp4_;
		_tmp3_ = string_length;
		_tmp4_ = start;
		start = _tmp3_ + _tmp4_;
	}
	_tmp5_ = end;
	if (_tmp5_ < ((glong) 0)) {
		glong _tmp6_;
		glong _tmp7_;
		_tmp6_ = string_length;
		_tmp7_ = end;
		end = _tmp6_ + _tmp7_;
	}
	_tmp9_ = start;
	if (_tmp9_ >= ((glong) 0)) {
		glong _tmp10_;
		glong _tmp11_;
		_tmp10_ = start;
		_tmp11_ = string_length;
		_tmp8_ = _tmp10_ <= _tmp11_;
	} else {
		_tmp8_ = FALSE;
	}
	_tmp12_ = _tmp8_;
	g_return_val_if_fail (_tmp12_, NULL);
	_tmp14_ = end;
	if (_tmp14_ >= ((glong) 0)) {
		glong _tmp15_;
		glong _tmp16_;
		_tmp15_ = end;
		_tmp16_ = string_length;
		_tmp13_ = _tmp15_ <= _tmp16_;
	} else {
		_tmp13_ = FALSE;
	}
	_tmp17_ = _tmp13_;
	g_return_val_if_fail (_tmp17_, NULL);
	_tmp18_ = start;
	_tmp19_ = end;
	g_return_val_if_fail (_tmp18_ <= _tmp19_, NULL);
	_tmp20_ = start;
	_tmp21_ = end;
	_tmp22_ = start;
	_tmp23_ = g_strndup (((gchar*) self) + _tmp20_, (gsize) (_tmp21_ - _tmp22_));
	result = _tmp23_;
	return result;
}


static gboolean baobab_connect_server_on_out_watch (BaobabConnectServer* self, GIOChannel* channel, GIOCondition cond) {
	gboolean result = FALSE;
	gchar* uri;
	GIOCondition _tmp0_;
	const gchar* _tmp9_;
	GError * _inner_error_ = NULL;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (channel != NULL, FALSE);
	uri = NULL;
	_tmp0_ = cond;
	if ((_tmp0_ & G_IO_IN) == G_IO_IN) {
		{
			gsize len = 0UL;
			gsize lineend = 0UL;
			GIOChannel* _tmp1_;
			gchar* _tmp2_ = NULL;
			gsize _tmp3_ = 0UL;
			gsize _tmp4_ = 0UL;
			gsize _tmp5_;
			_tmp1_ = channel;
			g_io_channel_read_line (_tmp1_, &_tmp2_, &_tmp3_, &_tmp4_, &_inner_error_);
			_g_free0 (uri);
			uri = _tmp2_;
			len = _tmp3_;
			lineend = _tmp4_;
			if (_inner_error_ != NULL) {
				goto __catch2_g_error;
			}
			_tmp5_ = len;
			if (_tmp5_ > ((gsize) 0)) {
				const gchar* _tmp6_;
				gsize _tmp7_;
				gchar* _tmp8_ = NULL;
				_tmp6_ = uri;
				_tmp7_ = lineend;
				_tmp8_ = string_slice (_tmp6_, (glong) 0, (glong) ((gint) _tmp7_));
				_g_free0 (uri);
				uri = _tmp8_;
			}
		}
		goto __finally2;
		__catch2_g_error:
		{
			g_clear_error (&_inner_error_);
			_inner_error_ = NULL;
		}
		__finally2:
		if (_inner_error_ != NULL) {
			_g_free0 (uri);
			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);
			g_clear_error (&_inner_error_);
			return FALSE;
		}
	}
	_tmp9_ = uri;
	g_signal_emit_by_name (self, "selected", _tmp9_);
	result = FALSE;
	_g_free0 (uri);
	return result;
}


static gboolean _baobab_connect_server_on_out_watch_gio_func (GIOChannel* source, GIOCondition condition, gpointer self) {
	gboolean result;
	result = baobab_connect_server_on_out_watch (self, source, condition);
	return result;
}


static void _baobab_connect_server_on_child_watch_gchild_watch_func (GPid pid, gint status, gpointer self) {
	baobab_connect_server_on_child_watch (self, pid, status);
}


void baobab_connect_server_show (BaobabConnectServer* self) {
	GPid pid = 0;
	gint out_fd = 0;
	GIOChannel* _tmp4_;
	GIOChannel* out_channel;
	GError * _inner_error_ = NULL;
	g_return_if_fail (self != NULL);
	{
		GPid _tmp0_ = 0;
		gint _tmp1_ = 0;
		g_spawn_async_with_pipes (NULL, BAOBAB_CONNECT_SERVER_argv, NULL, G_SPAWN_SEARCH_PATH | G_SPAWN_STDERR_TO_DEV_NULL, NULL, NULL, &_tmp0_, NULL, &_tmp1_, NULL, &_inner_error_);
		pid = _tmp0_;
		out_fd = _tmp1_;
		if (_inner_error_ != NULL) {
			if (_inner_error_->domain == G_SPAWN_ERROR) {
				goto __catch3_g_spawn_error;
			}
			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);
			g_clear_error (&_inner_error_);
			return;
		}
	}
	goto __finally3;
	__catch3_g_spawn_error:
	{
		GError* e = NULL;
		GError* _tmp2_;
		const gchar* _tmp3_;
		e = _inner_error_;
		_inner_error_ = NULL;
		_tmp2_ = e;
		_tmp3_ = _tmp2_->message;
		g_warning ("baobab-connect-server.vala:73: Failed to run nautilus-connect-server: " \
"%s", _tmp3_);
		_g_error_free0 (e);
	}
	__finally3:
	if (_inner_error_ != NULL) {
		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);
		g_clear_error (&_inner_error_);
		return;
	}
	_tmp4_ = g_io_channel_unix_new (out_fd);
	out_channel = _tmp4_;
	g_io_add_watch (out_channel, G_IO_IN | G_IO_HUP, _baobab_connect_server_on_out_watch_gio_func, self);
	g_child_watch_add_full (G_PRIORITY_DEFAULT_IDLE, pid, _baobab_connect_server_on_child_watch_gchild_watch_func, g_object_ref (self), g_object_unref);
	_g_io_channel_unref0 (out_channel);
}


gboolean baobab_connect_server_available (void) {
	gboolean result = FALSE;
	const gchar* _tmp0_;
	gchar* _tmp1_ = NULL;
	gchar* _tmp2_;
	gboolean _tmp3_;
	_tmp0_ = BAOBAB_CONNECT_SERVER_argv[0];
	_tmp1_ = g_find_program_in_path (_tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = _tmp2_ != NULL;
	_g_free0 (_tmp2_);
	result = _tmp3_;
	return result;
}


BaobabConnectServer* baobab_connect_server_construct (GType object_type) {
	BaobabConnectServer * self = NULL;
	self = (BaobabConnectServer*) g_object_new (object_type, NULL);
	return self;
}


BaobabConnectServer* baobab_connect_server_new (void) {
	return baobab_connect_server_construct (BAOBAB_TYPE_CONNECT_SERVER);
}


static void baobab_connect_server_class_init (BaobabConnectServerClass * klass) {
	baobab_connect_server_parent_class = g_type_class_peek_parent (klass);
	g_signal_new ("selected", BAOBAB_TYPE_CONNECT_SERVER, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__STRING, G_TYPE_NONE, 1, G_TYPE_STRING);
}


static void baobab_connect_server_instance_init (BaobabConnectServer * self) {
}


GType baobab_connect_server_get_type (void) {
	static volatile gsize baobab_connect_server_type_id__volatile = 0;
	if (g_once_init_enter (&baobab_connect_server_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (BaobabConnectServerClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) baobab_connect_server_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (BaobabConnectServer), 0, (GInstanceInitFunc) baobab_connect_server_instance_init, NULL };
		GType baobab_connect_server_type_id;
		baobab_connect_server_type_id = g_type_register_static (G_TYPE_OBJECT, "BaobabConnectServer", &g_define_type_info, 0);
		g_once_init_leave (&baobab_connect_server_type_id__volatile, baobab_connect_server_type_id);
	}
	return baobab_connect_server_type_id__volatile;
}