/* BackendGoogle.c generated by valac 0.56.18-dirty, the Vala compiler
 * generated from BackendGoogle.vala, do not modify */

/* -*- Mode: Vala; indent-tabs-mode: nil; tab-width: 2 -*-
 *
 * SPDX-License-Identifier: GPL-3.0-or-later
 * SPDX-FileCopyrightText: Michael Terry
 */

#include "deja.h"
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <gio/gio.h>
#include <glib-object.h>
#include <glib/gi18n-lib.h>

#if !defined(VALA_STRICT_C)
#if !defined(__clang__) && defined(__GNUC__) && (__GNUC__ >= 14)
#pragma GCC diagnostic warning "-Wincompatible-pointer-types"
#elif defined(__clang__) && (__clang_major__ >= 16)
#pragma clang diagnostic ignored "-Wincompatible-function-pointer-types"
#pragma clang diagnostic ignored "-Wincompatible-pointer-types"
#endif
#endif

enum  {
	DEJA_DUP_BACKEND_GOOGLE_0_PROPERTY,
	DEJA_DUP_BACKEND_GOOGLE_NUM_PROPERTIES
};
static GParamSpec* deja_dup_backend_google_properties[DEJA_DUP_BACKEND_GOOGLE_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
typedef struct _DejaDupBackendGoogleIsReadyData DejaDupBackendGoogleIsReadyData;
typedef struct _DejaDupBackendGoogleGetSpaceData DejaDupBackendGoogleGetSpaceData;
typedef struct _DejaDupBackendGooglePeekAtFilesData DejaDupBackendGooglePeekAtFilesData;

struct _DejaDupBackendGoogleIsReadyData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	DejaDupBackendGoogle* self;
	gchar* reason;
	gchar* message;
	gboolean result;
	gchar* _tmp0_;
	gchar* _tmp1_;
	DejaDupNetwork* _tmp2_;
	DejaDupNetwork* _tmp3_;
	gchar* _tmp4_;
	gchar* _tmp5_;
	gboolean _tmp6_;
};

struct _DejaDupBackendGoogleGetSpaceData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	DejaDupBackendGoogle* self;
	guint64 free;
	guint64 total;
	guint64 _tmp0_;
	guint64 _tmp1_;
};

struct _DejaDupBackendGooglePeekAtFilesData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	DejaDupBackendGoogle* self;
	GList* result;
	GList* _tmp0_;
};

static gpointer deja_dup_backend_google_parent_class = NULL;

static gchar* deja_dup_backend_google_real_get_redirect_uri (DejaDupBackendOAuth* base);
static void _vala_array_add1 (gchar** * array,
                       gint* length,
                       gint* size,
                       gchar* value);
static gboolean deja_dup_backend_google_real_needs_dependencies (DejaDupBackend* base);
VALA_EXTERN gchar* rclone_rclone_command (void);
static gchar** deja_dup_backend_google_real_get_dependencies (DejaDupBackend* base,
                                                       gint* result_length1);
static GIcon* deja_dup_backend_google_real_get_icon (DejaDupBackend* base);
static void deja_dup_backend_google_real_is_ready_data_free (gpointer _data);
static void deja_dup_backend_google_real_is_ready (DejaDupBackend* base,
                                            GAsyncReadyCallback _callback_,
                                            gpointer _user_data_);
static gboolean deja_dup_backend_google_real_is_ready_co (DejaDupBackendGoogleIsReadyData* _data_);
static void deja_dup_backend_google_is_ready_ready (GObject* source_object,
                                             GAsyncResult* _res_,
                                             gpointer _user_data_);
static gchar* deja_dup_backend_google_real_get_location_pretty (DejaDupBackend* base);
static gchar* deja_dup_backend_google_real_get_unique_location (DejaDupBackend* base);
static void deja_dup_backend_google_real_get_space_data_free (gpointer _data);
static void deja_dup_backend_google_real_get_space (DejaDupBackend* base,
                                             GAsyncReadyCallback _callback_,
                                             gpointer _user_data_);
static gboolean deja_dup_backend_google_real_get_space_co (DejaDupBackendGoogleGetSpaceData* _data_);
VALA_EXTERN void rclone_get_space (DejaDupBackend* backend,
                       GAsyncReadyCallback _callback_,
                       gpointer _user_data_);
VALA_EXTERN void rclone_get_space_finish (GAsyncResult* _res_,
                              guint64* free,
                              guint64* total);
static void deja_dup_backend_google_get_space_ready (GObject* source_object,
                                              GAsyncResult* _res_,
                                              gpointer _user_data_);
static void _g_free0_ (gpointer var);
static inline void _g_list_free__g_free0_ (GList* self);
static void deja_dup_backend_google_real_peek_at_files_data_free (gpointer _data);
static void deja_dup_backend_google_real_peek_at_files (DejaDupBackend* base,
                                                 GAsyncReadyCallback _callback_,
                                                 gpointer _user_data_);
static gboolean deja_dup_backend_google_real_peek_at_files_co (DejaDupBackendGooglePeekAtFilesData* _data_);
VALA_EXTERN void rclone_list_files (DejaDupBackend* backend,
                        gint max,
                        GAsyncReadyCallback _callback_,
                        gpointer _user_data_);
VALA_EXTERN GList* rclone_list_files_finish (GAsyncResult* _res_);
static void deja_dup_backend_google_peek_at_files_ready (GObject* source_object,
                                                  GAsyncResult* _res_,
                                                  gpointer _user_data_);
static GObject * deja_dup_backend_google_constructor (GType type,
                                               guint n_construct_properties,
                                               GObjectConstructParam * construct_properties);
static GType deja_dup_backend_google_get_type_once (void);
static void _vala_array_destroy (gpointer array,
                          gssize array_length,
                          GDestroyNotify destroy_func);
static void _vala_array_free (gpointer array,
                       gssize array_length,
                       GDestroyNotify destroy_func);
static gssize _vala_array_length (gpointer array);

static gpointer
_g_object_ref0 (gpointer self)
{
	return self ? g_object_ref (self) : NULL;
}

DejaDupBackendGoogle*
deja_dup_backend_google_construct (GType object_type,
                                   GSettings* settings)
{
	DejaDupBackendGoogle * self = NULL;
	GSettings* _tmp0_ = NULL;
	if (settings != NULL) {
		GSettings* _tmp1_;
		_tmp1_ = _g_object_ref0 (settings);
		_g_object_unref0 (_tmp0_);
		_tmp0_ = _tmp1_;
	} else {
		DejaDupFilteredSettings* _tmp2_;
		_tmp2_ = deja_dup_get_settings (DEJA_DUP_GOOGLE_ROOT);
		_g_object_unref0 (_tmp0_);
		_tmp0_ = (GSettings*) _tmp2_;
	}
	self = (DejaDupBackendGoogle*) g_object_new (object_type, "kind", DEJA_DUP_BACKEND_KIND_GOOGLE, "settings", _tmp0_, NULL);
	_g_object_unref0 (_tmp0_);
	return self;
}

DejaDupBackendGoogle*
deja_dup_backend_google_new (GSettings* settings)
{
	return deja_dup_backend_google_construct (DEJA_DUP_TYPE_BACKEND_GOOGLE, settings);
}

static void
_vala_array_add1 (gchar** * array,
                  gint* length,
                  gint* size,
                  gchar* value)
{
	if ((*length) == (*size)) {
		*size = (*size) ? (2 * (*size)) : 4;
		*array = g_renew (gchar*, *array, (*size) + 1);
	}
	(*array)[(*length)++] = value;
	(*array)[*length] = NULL;
}

static gchar*
_vala_g_strjoinv (const gchar* separator,
                  gchar** str_array,
                  gint str_array_length1)
{
	gboolean _tmp0_ = FALSE;
	gchar* result;
	if (separator == NULL) {
		separator = "";
	}
	if (str_array != NULL) {
		gboolean _tmp1_ = FALSE;
		if (str_array_length1 > 0) {
			_tmp1_ = TRUE;
		} else {
			gboolean _tmp2_ = FALSE;
			if (str_array_length1 == -1) {
				const gchar* _tmp3_;
				_tmp3_ = str_array[0];
				_tmp2_ = _tmp3_ != NULL;
			} else {
				_tmp2_ = FALSE;
			}
			_tmp1_ = _tmp2_;
		}
		_tmp0_ = _tmp1_;
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		gint i = 0;
		gsize len = 0UL;
		gint _tmp16_;
		gint _tmp17_;
		const gchar* res = NULL;
		void* _tmp18_;
		const gchar* _tmp19_ = NULL;
		const gchar* _tmp20_;
		void* ptr = NULL;
		const gchar* _tmp22_;
		void* _tmp23_;
		const gchar* _tmp33_;
		len = (gsize) 1;
		{
			gboolean _tmp4_ = FALSE;
			i = 0;
			_tmp4_ = TRUE;
			while (TRUE) {
				gboolean _tmp6_ = FALSE;
				gboolean _tmp7_ = FALSE;
				gint _tmp10_ = 0;
				const gchar* _tmp11_;
				if (!_tmp4_) {
					gint _tmp5_;
					_tmp5_ = i;
					i = _tmp5_ + 1;
				}
				_tmp4_ = FALSE;
				if (str_array_length1 != -1) {
					_tmp7_ = i < str_array_length1;
				} else {
					_tmp7_ = FALSE;
				}
				if (_tmp7_) {
					_tmp6_ = TRUE;
				} else {
					gboolean _tmp8_ = FALSE;
					if (str_array_length1 == -1) {
						const gchar* _tmp9_;
						_tmp9_ = str_array[i];
						_tmp8_ = _tmp9_ != NULL;
					} else {
						_tmp8_ = FALSE;
					}
					_tmp6_ = _tmp8_;
				}
				if (!_tmp6_) {
					break;
				}
				_tmp11_ = str_array[i];
				if (_tmp11_ != NULL) {
					const gchar* _tmp12_;
					gint _tmp13_;
					gint _tmp14_;
					_tmp12_ = str_array[i];
					_tmp13_ = strlen ((const gchar*) _tmp12_);
					_tmp14_ = _tmp13_;
					_tmp10_ = _tmp14_;
				} else {
					_tmp10_ = 0;
				}
				len += (gsize) _tmp10_;
			}
		}
		if (i == 0) {
			gchar* _tmp15_;
			_tmp15_ = g_strdup ("");
			result = _tmp15_;
			return result;
		}
		str_array_length1 = i;
		_tmp16_ = strlen ((const gchar*) separator);
		_tmp17_ = _tmp16_;
		len += (gsize) (_tmp17_ * (i - 1));
		_tmp18_ = g_malloc (len);
		res = _tmp18_;
		_tmp20_ = str_array[0];
		if (_tmp20_ != NULL) {
			const gchar* _tmp21_;
			_tmp21_ = str_array[0];
			_tmp19_ = (const gchar*) _tmp21_;
		} else {
			_tmp19_ = "";
		}
		_tmp22_ = res;
		_tmp23_ = g_stpcpy ((void*) _tmp22_, _tmp19_);
		ptr = _tmp23_;
		{
			gboolean _tmp24_ = FALSE;
			i = 1;
			_tmp24_ = TRUE;
			while (TRUE) {
				void* _tmp26_;
				void* _tmp27_;
				const gchar* _tmp28_ = NULL;
				const gchar* _tmp29_;
				void* _tmp31_;
				void* _tmp32_;
				if (!_tmp24_) {
					gint _tmp25_;
					_tmp25_ = i;
					i = _tmp25_ + 1;
				}
				_tmp24_ = FALSE;
				if (!(i < str_array_length1)) {
					break;
				}
				_tmp26_ = ptr;
				_tmp27_ = g_stpcpy (_tmp26_, (const gchar*) separator);
				ptr = _tmp27_;
				_tmp29_ = str_array[i];
				if (_tmp29_ != NULL) {
					const gchar* _tmp30_;
					_tmp30_ = str_array[i];
					_tmp28_ = (const gchar*) _tmp30_;
				} else {
					_tmp28_ = "";
				}
				_tmp31_ = ptr;
				_tmp32_ = g_stpcpy (_tmp31_, _tmp28_);
				ptr = _tmp32_;
			}
		}
		_tmp33_ = res;
		res = NULL;
		result = (gchar*) _tmp33_;
		return result;
	} else {
		gchar* _tmp34_;
		_tmp34_ = g_strdup ("");
		result = _tmp34_;
		return result;
	}
}

static gchar*
deja_dup_backend_google_real_get_redirect_uri (DejaDupBackendOAuth* base)
{
	DejaDupBackendGoogle * self;
	gchar** id_parts = NULL;
	const gchar* _tmp0_;
	gchar** _tmp1_;
	gchar** _tmp2_;
	gint id_parts_length1;
	gint _id_parts_size_;
	gchar** reversed = NULL;
	gchar** _tmp3_;
	gint reversed_length1;
	gint _reversed_size_;
	gchar** _tmp10_;
	gint _tmp10__length1;
	gchar* _tmp11_;
	gchar* _tmp12_;
	gchar* _tmp13_;
	gchar* _tmp14_;
	gchar* result;
	self = (DejaDupBackendGoogle*) base;
	_tmp0_ = ((DejaDupBackendOAuth*) self)->client_id;
	_tmp2_ = _tmp1_ = g_strsplit (_tmp0_, ".", 0);
	id_parts = _tmp2_;
	id_parts_length1 = _vala_array_length (_tmp1_);
	_id_parts_size_ = id_parts_length1;
	_tmp3_ = g_new0 (gchar*, 0 + 1);
	reversed = _tmp3_;
	reversed_length1 = 0;
	_reversed_size_ = reversed_length1;
	{
		gint i = 0;
		gchar** _tmp4_;
		gint _tmp4__length1;
		_tmp4_ = id_parts;
		_tmp4__length1 = id_parts_length1;
		i = _tmp4__length1 - 1;
		{
			gboolean _tmp5_ = FALSE;
			_tmp5_ = TRUE;
			while (TRUE) {
				gchar** _tmp7_;
				gint _tmp7__length1;
				const gchar* _tmp8_;
				gchar* _tmp9_;
				if (!_tmp5_) {
					gint _tmp6_;
					_tmp6_ = i;
					i = _tmp6_ - 1;
				}
				_tmp5_ = FALSE;
				if (!(i >= 0)) {
					break;
				}
				_tmp7_ = id_parts;
				_tmp7__length1 = id_parts_length1;
				_tmp8_ = _tmp7_[i];
				_tmp9_ = g_strdup (_tmp8_);
				_vala_array_add1 (&reversed, &reversed_length1, &_reversed_size_, _tmp9_);
			}
		}
	}
	_tmp10_ = reversed;
	_tmp10__length1 = reversed_length1;
	_tmp11_ = _vala_g_strjoinv (".", _tmp10_, (gint) _tmp10__length1);
	_tmp12_ = _tmp11_;
	_tmp13_ = g_strdup_printf ("%s:/oauth2redirect", _tmp12_);
	_tmp14_ = _tmp13_;
	_g_free0 (_tmp12_);
	result = _tmp14_;
	reversed = (_vala_array_free (reversed, reversed_length1, (GDestroyNotify) g_free), NULL);
	id_parts = (_vala_array_free (id_parts, id_parts_length1, (GDestroyNotify) g_free), NULL);
	return result;
}

static gboolean
deja_dup_backend_google_real_needs_dependencies (DejaDupBackend* base)
{
	DejaDupBackendGoogle * self;
	gchar* _tmp0_;
	gchar* _tmp1_;
	gchar* _tmp2_;
	gchar* _tmp3_;
	gboolean _tmp4_;
	gboolean result;
	self = (DejaDupBackendGoogle*) base;
	_tmp0_ = rclone_rclone_command ();
	_tmp1_ = _tmp0_;
	_tmp2_ = g_find_program_in_path (_tmp1_);
	_tmp3_ = _tmp2_;
	_tmp4_ = _tmp3_ == NULL;
	_g_free0 (_tmp3_);
	_g_free0 (_tmp1_);
	result = _tmp4_;
	return result;
}

static gchar**
deja_dup_backend_google_real_get_dependencies (DejaDupBackend* base,
                                               gint* result_length1)
{
	DejaDupBackendGoogle * self;
	gchar** _tmp0_;
	gchar** _tmp1_;
	gchar** _tmp2_;
	gint _tmp2__length1;
	gchar** result;
	self = (DejaDupBackendGoogle*) base;
	_tmp1_ = _tmp0_ = g_strsplit (RCLONE_PACKAGES, ",", 0);
	_tmp2_ = _tmp1_;
	_tmp2__length1 = _vala_array_length (_tmp0_);
	if (result_length1) {
		*result_length1 = _tmp2__length1;
	}
	result = _tmp2_;
	return result;
}

static GIcon*
deja_dup_backend_google_real_get_icon (DejaDupBackend* base)
{
	DejaDupBackendGoogle * self;
	GThemedIcon* _tmp0_;
	GIcon* result;
	self = (DejaDupBackendGoogle*) base;
	_tmp0_ = (GThemedIcon*) g_themed_icon_new ("deja-dup-google-drive");
	result = (GIcon*) _tmp0_;
	return result;
}

static void
deja_dup_backend_google_real_is_ready_data_free (gpointer _data)
{
	DejaDupBackendGoogleIsReadyData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->self);
	g_slice_free (DejaDupBackendGoogleIsReadyData, _data_);
}

static void
deja_dup_backend_google_real_is_ready (DejaDupBackend* base,
                                       GAsyncReadyCallback _callback_,
                                       gpointer _user_data_)
{
	DejaDupBackendGoogle * self;
	DejaDupBackendGoogleIsReadyData* _data_;
	DejaDupBackendGoogle* _tmp0_;
	self = (DejaDupBackendGoogle*) base;
	_data_ = g_slice_new0 (DejaDupBackendGoogleIsReadyData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, deja_dup_backend_google_real_is_ready_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	deja_dup_backend_google_real_is_ready_co (_data_);
}

static gboolean
deja_dup_backend_google_is_ready_finish (DejaDupBackend* base,
                                         GAsyncResult* _res_,
                                         gchar** reason,
                                         gchar** message)
{
	gboolean result;
	DejaDupBackendGoogleIsReadyData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
	if (reason) {
		*reason = _data_->reason;
	} else {
		_g_free0 (_data_->reason);
	}
	_data_->reason = NULL;
	if (message) {
		*message = _data_->message;
	} else {
		_g_free0 (_data_->message);
	}
	_data_->message = NULL;
	result = _data_->result;
	return result;
}

static void
deja_dup_backend_google_is_ready_ready (GObject* source_object,
                                        GAsyncResult* _res_,
                                        gpointer _user_data_)
{
	DejaDupBackendGoogleIsReadyData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	deja_dup_backend_google_real_is_ready_co (_data_);
}

static gboolean
deja_dup_backend_google_real_is_ready_co (DejaDupBackendGoogleIsReadyData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = g_strdup ("google-reachable");
	_g_free0 (_data_->reason);
	_data_->reason = _data_->_tmp0_;
	_data_->_tmp1_ = g_strdup (_ ("Backup will begin when a network connection becomes available."));
	_g_free0 (_data_->message);
	_data_->message = _data_->_tmp1_;
	_data_->_tmp2_ = deja_dup_network_get ();
	_data_->_tmp3_ = _data_->_tmp2_;
	_data_->_tmp4_ = g_strdup_printf ("https://%s/", DEJA_DUP_GOOGLE_SERVER);
	_data_->_tmp5_ = _data_->_tmp4_;
	_data_->_state_ = 1;
	deja_dup_network_can_reach (_data_->_tmp3_, _data_->_tmp5_, deja_dup_backend_google_is_ready_ready, _data_);
	return FALSE;
	_state_1:
	_data_->_tmp6_ = deja_dup_network_can_reach_finish (_data_->_tmp3_, _data_->_res_);
	_g_free0 (_data_->_tmp5_);
	_g_object_unref0 (_data_->_tmp3_);
	_data_->result = _data_->_tmp6_;
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

gchar*
deja_dup_backend_google_get_folder (DejaDupBackendGoogle* self)
{
	GSettings* _tmp0_;
	GSettings* _tmp1_;
	gchar* _tmp2_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = deja_dup_backend_get_settings ((DejaDupBackend*) self);
	_tmp1_ = _tmp0_;
	_tmp2_ = deja_dup_get_folder_key (_tmp1_, DEJA_DUP_GOOGLE_FOLDER_KEY, FALSE);
	result = _tmp2_;
	return result;
}

static gchar*
deja_dup_backend_google_real_get_location_pretty (DejaDupBackend* base)
{
	DejaDupBackendGoogle * self;
	gchar* folder = NULL;
	gchar* _tmp0_;
	const gchar* _tmp1_;
	gchar* result;
	self = (DejaDupBackendGoogle*) base;
	_tmp0_ = deja_dup_backend_google_get_folder (self);
	folder = _tmp0_;
	_tmp1_ = folder;
	if (g_strcmp0 (_tmp1_, "") == 0) {
		gchar* _tmp2_;
		_tmp2_ = g_strdup (_ ("Google Drive"));
		result = _tmp2_;
		_g_free0 (folder);
		return result;
	} else {
		const gchar* _tmp3_;
		gchar* _tmp4_;
		_tmp3_ = folder;
		_tmp4_ = g_strdup_printf (_ ("%s on Google Drive"), _tmp3_);
		result = _tmp4_;
		_g_free0 (folder);
		return result;
	}
}

static gchar*
deja_dup_backend_google_real_get_unique_location (DejaDupBackend* base)
{
	DejaDupBackendGoogle * self;
	gchar* _tmp0_;
	gchar* _tmp1_;
	gchar* _tmp2_;
	gchar* _tmp3_;
	gchar* result;
	self = (DejaDupBackendGoogle*) base;
	_tmp0_ = deja_dup_backend_google_get_folder (self);
	_tmp1_ = _tmp0_;
	_tmp2_ = g_strconcat ("google:", _tmp1_, NULL);
	_tmp3_ = _tmp2_;
	_g_free0 (_tmp1_);
	result = _tmp3_;
	return result;
}

static void
deja_dup_backend_google_real_get_space_data_free (gpointer _data)
{
	DejaDupBackendGoogleGetSpaceData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->self);
	g_slice_free (DejaDupBackendGoogleGetSpaceData, _data_);
}

static void
deja_dup_backend_google_real_get_space (DejaDupBackend* base,
                                        GAsyncReadyCallback _callback_,
                                        gpointer _user_data_)
{
	DejaDupBackendGoogle * self;
	DejaDupBackendGoogleGetSpaceData* _data_;
	DejaDupBackendGoogle* _tmp0_;
	self = (DejaDupBackendGoogle*) base;
	_data_ = g_slice_new0 (DejaDupBackendGoogleGetSpaceData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, deja_dup_backend_google_real_get_space_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	deja_dup_backend_google_real_get_space_co (_data_);
}

static void
deja_dup_backend_google_get_space_finish (DejaDupBackend* base,
                                          GAsyncResult* _res_,
                                          guint64* free,
                                          guint64* total)
{
	DejaDupBackendGoogleGetSpaceData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
	if (free) {
		*free = _data_->free;
	}
	if (total) {
		*total = _data_->total;
	}
}

static void
deja_dup_backend_google_get_space_ready (GObject* source_object,
                                         GAsyncResult* _res_,
                                         gpointer _user_data_)
{
	DejaDupBackendGoogleGetSpaceData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	deja_dup_backend_google_real_get_space_co (_data_);
}

static gboolean
deja_dup_backend_google_real_get_space_co (DejaDupBackendGoogleGetSpaceData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = 0ULL;
	_data_->_tmp1_ = 0ULL;
	_data_->_state_ = 1;
	rclone_get_space ((DejaDupBackend*) _data_->self, deja_dup_backend_google_get_space_ready, _data_);
	return FALSE;
	_state_1:
	rclone_get_space_finish (_data_->_res_, &_data_->_tmp0_, &_data_->_tmp1_);
	_data_->free = _data_->_tmp0_;
	_data_->total = _data_->_tmp1_;
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

static void
_g_free0_ (gpointer var)
{
	var = (g_free (var), NULL);
}

static inline void
_g_list_free__g_free0_ (GList* self)
{
	g_list_free_full (self, (GDestroyNotify) _g_free0_);
}

static void
deja_dup_backend_google_real_peek_at_files_data_free (gpointer _data)
{
	DejaDupBackendGooglePeekAtFilesData* _data_;
	_data_ = _data;
	(_data_->result == NULL) ? NULL : (_data_->result = (_g_list_free__g_free0_ (_data_->result), NULL));
	_g_object_unref0 (_data_->self);
	g_slice_free (DejaDupBackendGooglePeekAtFilesData, _data_);
}

static void
deja_dup_backend_google_real_peek_at_files (DejaDupBackend* base,
                                            GAsyncReadyCallback _callback_,
                                            gpointer _user_data_)
{
	DejaDupBackendGoogle * self;
	DejaDupBackendGooglePeekAtFilesData* _data_;
	DejaDupBackendGoogle* _tmp0_;
	self = (DejaDupBackendGoogle*) base;
	_data_ = g_slice_new0 (DejaDupBackendGooglePeekAtFilesData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, deja_dup_backend_google_real_peek_at_files_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	deja_dup_backend_google_real_peek_at_files_co (_data_);
}

static GList*
deja_dup_backend_google_peek_at_files_finish (DejaDupBackend* base,
                                              GAsyncResult* _res_)
{
	GList* result;
	DejaDupBackendGooglePeekAtFilesData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
	result = _data_->result;
	_data_->result = NULL;
	return result;
}

static void
deja_dup_backend_google_peek_at_files_ready (GObject* source_object,
                                             GAsyncResult* _res_,
                                             gpointer _user_data_)
{
	DejaDupBackendGooglePeekAtFilesData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	deja_dup_backend_google_real_peek_at_files_co (_data_);
}

static gboolean
deja_dup_backend_google_real_peek_at_files_co (DejaDupBackendGooglePeekAtFilesData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_state_ = 1;
	rclone_list_files ((DejaDupBackend*) _data_->self, 20, deja_dup_backend_google_peek_at_files_ready, _data_);
	return FALSE;
	_state_1:
	_data_->_tmp0_ = rclone_list_files_finish (_data_->_res_);
	_data_->result = _data_->_tmp0_;
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

gchar*
deja_dup_backend_google_fill_envp (DejaDupBackendGoogle* self,
                                   GList** envp)
{
	gchar* _tmp0_;
	const gchar* _tmp1_;
	gchar* _tmp2_;
	const gchar* _tmp3_;
	const gchar* _tmp4_;
	gchar* _tmp5_;
	gchar* _tmp6_;
	gchar* _tmp7_;
	gchar* _tmp8_;
	gchar* _tmp9_;
	gchar* _tmp10_;
	gchar* _tmp11_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = g_strdup ("RCLONE_CONFIG=");
	*envp = g_list_append (*envp, _tmp0_);
	_tmp1_ = ((DejaDupBackendOAuth*) self)->client_id;
	_tmp2_ = g_strconcat ("RCLONE_DRIVE_CLIENT_ID=", _tmp1_, NULL);
	*envp = g_list_append (*envp, _tmp2_);
	_tmp3_ = deja_dup_backend_oauth_get_full_token ((DejaDupBackendOAuth*) self);
	_tmp4_ = _tmp3_;
	_tmp5_ = g_strconcat ("RCLONE_DRIVE_TOKEN=", _tmp4_, NULL);
	*envp = g_list_append (*envp, _tmp5_);
	_tmp6_ = g_strdup ("RCLONE_DRIVE_SCOPE=drive.file");
	*envp = g_list_append (*envp, _tmp6_);
	_tmp7_ = g_strdup ("RCLONE_DRIVE_USE_TRASH=false");
	*envp = g_list_append (*envp, _tmp7_);
	_tmp8_ = deja_dup_backend_google_get_folder (self);
	_tmp9_ = _tmp8_;
	_tmp10_ = g_strconcat (":drive:", _tmp9_, NULL);
	_tmp11_ = _tmp10_;
	_g_free0 (_tmp9_);
	result = _tmp11_;
	return result;
}

static GObject *
deja_dup_backend_google_constructor (GType type,
                                     guint n_construct_properties,
                                     GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	DejaDupBackendGoogle * self;
	gchar* _tmp0_;
	gchar* _tmp1_;
	gchar* _tmp2_;
	gchar* _tmp3_;
	gchar* _tmp4_;
	parent_class = G_OBJECT_CLASS (deja_dup_backend_google_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, DEJA_DUP_TYPE_BACKEND_GOOGLE, DejaDupBackendGoogle);
	_tmp0_ = g_strdup ("Google");
	_g_free0 (((DejaDupBackendOAuth*) self)->brand_name);
	((DejaDupBackendOAuth*) self)->brand_name = _tmp0_;
	_tmp1_ = g_strdup (GOOGLE_CLIENT_ID);
	_g_free0 (((DejaDupBackendOAuth*) self)->client_id);
	((DejaDupBackendOAuth*) self)->client_id = _tmp1_;
	_tmp2_ = g_strdup ("https://accounts.google.com/o/oauth2/v2/auth");
	_g_free0 (((DejaDupBackendOAuth*) self)->auth_url);
	((DejaDupBackendOAuth*) self)->auth_url = _tmp2_;
	_tmp3_ = g_strdup ("https://www.googleapis.com/oauth2/v4/token");
	_g_free0 (((DejaDupBackendOAuth*) self)->token_url);
	((DejaDupBackendOAuth*) self)->token_url = _tmp3_;
	_tmp4_ = g_strdup ("https://www.googleapis.com/auth/drive.file");
	_g_free0 (((DejaDupBackendOAuth*) self)->scope);
	((DejaDupBackendOAuth*) self)->scope = _tmp4_;
	return obj;
}

static void
deja_dup_backend_google_class_init (DejaDupBackendGoogleClass * klass,
                                    gpointer klass_data)
{
	deja_dup_backend_google_parent_class = g_type_class_peek_parent (klass);
	((DejaDupBackendOAuthClass *) klass)->get_redirect_uri = (gchar* (*) (DejaDupBackendOAuth*)) deja_dup_backend_google_real_get_redirect_uri;
	((DejaDupBackendClass *) klass)->needs_dependencies = (gboolean (*) (DejaDupBackend*)) deja_dup_backend_google_real_needs_dependencies;
	((DejaDupBackendClass *) klass)->get_dependencies = (gchar** (*) (DejaDupBackend*, gint*)) deja_dup_backend_google_real_get_dependencies;
	((DejaDupBackendClass *) klass)->get_icon = (GIcon* (*) (DejaDupBackend*)) deja_dup_backend_google_real_get_icon;
	((DejaDupBackendClass *) klass)->is_ready = (void (*) (DejaDupBackend*, GAsyncReadyCallback, gpointer)) deja_dup_backend_google_real_is_ready;
	((DejaDupBackendClass *) klass)->is_ready_finish = (gboolean (*) (DejaDupBackend*, GAsyncResult*, gchar**, gchar**)) deja_dup_backend_google_is_ready_finish;
	((DejaDupBackendClass *) klass)->get_location_pretty = (gchar* (*) (DejaDupBackend*)) deja_dup_backend_google_real_get_location_pretty;
	((DejaDupBackendClass *) klass)->get_unique_location = (gchar* (*) (DejaDupBackend*)) deja_dup_backend_google_real_get_unique_location;
	((DejaDupBackendClass *) klass)->get_space = (void (*) (DejaDupBackend*, GAsyncReadyCallback, gpointer)) deja_dup_backend_google_real_get_space;
	((DejaDupBackendClass *) klass)->get_space_finish = (void (*) (DejaDupBackend*, GAsyncResult*, guint64*, guint64*)) deja_dup_backend_google_get_space_finish;
	((DejaDupBackendClass *) klass)->peek_at_files = (void (*) (DejaDupBackend*, GAsyncReadyCallback, gpointer)) deja_dup_backend_google_real_peek_at_files;
	((DejaDupBackendClass *) klass)->peek_at_files_finish = (GList* (*) (DejaDupBackend*, GAsyncResult*)) deja_dup_backend_google_peek_at_files_finish;
	G_OBJECT_CLASS (klass)->constructor = deja_dup_backend_google_constructor;
}

static void
deja_dup_backend_google_instance_init (DejaDupBackendGoogle * self,
                                       gpointer klass)
{
}

 G_GNUC_NO_INLINE static GType
deja_dup_backend_google_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (DejaDupBackendGoogleClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) deja_dup_backend_google_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (DejaDupBackendGoogle), 0, (GInstanceInitFunc) deja_dup_backend_google_instance_init, NULL };
	GType deja_dup_backend_google_type_id;
	deja_dup_backend_google_type_id = g_type_register_static (DEJA_DUP_TYPE_BACKEND_OAUTH, "DejaDupBackendGoogle", &g_define_type_info, 0);
	return deja_dup_backend_google_type_id;
}

GType
deja_dup_backend_google_get_type (void)
{
	static gsize deja_dup_backend_google_type_id__once = 0;
	if (g_once_init_enter (&deja_dup_backend_google_type_id__once)) {
		GType deja_dup_backend_google_type_id;
		deja_dup_backend_google_type_id = deja_dup_backend_google_get_type_once ();
		g_once_init_leave (&deja_dup_backend_google_type_id__once, deja_dup_backend_google_type_id);
	}
	return deja_dup_backend_google_type_id__once;
}

static void
_vala_array_destroy (gpointer array,
                     gssize array_length,
                     GDestroyNotify destroy_func)
{
	if ((array != NULL) && (destroy_func != NULL)) {
		gssize i;
		for (i = 0; i < array_length; i = i + 1) {
			if (((gpointer*) array)[i] != NULL) {
				destroy_func (((gpointer*) array)[i]);
			}
		}
	}
}

static void
_vala_array_free (gpointer array,
                  gssize array_length,
                  GDestroyNotify destroy_func)
{
	_vala_array_destroy (array, array_length, destroy_func);
	g_free (array);
}

static gssize
_vala_array_length (gpointer array)
{
	gssize length;
	length = 0;
	if (array) {
		while (((gpointer*) array)[length]) {
			length++;
		}
	}
	return length;
}

