/* main.c generated by valac 0.56.19, the Vala compiler
 * generated from main.vala, do not modify */

/*
* BudgieExtrasDaemon
* Author: David Mohammed
* Copyright © 2019 Ubuntu Budgie Developers
* Website=https://ubuntubudgie.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 3 of the License, or 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, see
* <https://www.gnu.org/licenses/>.
*/

#include <glib.h>
#include <gio/gio.h>
#include <gtk/gtk.h>
#include <glib-object.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
#if !defined(VALA_EXTERN)
#if defined(_MSC_VER)
#define VALA_EXTERN __declspec(dllexport) extern
#elif __GNUC__ >= 4
#define VALA_EXTERN __attribute__((visibility("default"))) extern
#else
#define VALA_EXTERN extern
#endif
#endif

#define _g_option_context_free0(var) ((var == NULL) ? NULL : (var = (g_option_context_free (var), NULL)))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))

#define BUDGIE_EXTRAS_TYPE_DBUS_MANAGER (budgie_extras_dbus_manager_get_type ())
#define BUDGIE_EXTRAS_DBUS_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), BUDGIE_EXTRAS_TYPE_DBUS_MANAGER, BudgieExtrasDbusManager))
#define BUDGIE_EXTRAS_DBUS_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), BUDGIE_EXTRAS_TYPE_DBUS_MANAGER, BudgieExtrasDbusManagerClass))
#define BUDGIE_EXTRAS_IS_DBUS_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), BUDGIE_EXTRAS_TYPE_DBUS_MANAGER))
#define BUDGIE_EXTRAS_IS_DBUS_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), BUDGIE_EXTRAS_TYPE_DBUS_MANAGER))
#define BUDGIE_EXTRAS_DBUS_MANAGER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), BUDGIE_EXTRAS_TYPE_DBUS_MANAGER, BudgieExtrasDbusManagerClass))

typedef struct _BudgieExtrasDbusManager BudgieExtrasDbusManager;
typedef struct _BudgieExtrasDbusManagerClass BudgieExtrasDbusManagerClass;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

VALA_EXTERN gboolean replace;
gboolean replace = FALSE;
VALA_EXTERN gboolean budgie_extras_setup;
gboolean budgie_extras_setup = FALSE;
VALA_EXTERN gboolean budgie_extras_spammed;
gboolean budgie_extras_spammed = FALSE;

VALA_EXTERN void budgie_extras_DaemonNameLost (GDBusConnection* conn,
                                   const gchar* name);
static gint _vala_main (gchar** args,
                 gint args_length1);
VALA_EXTERN GType budgie_extras_dbus_manager_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (BudgieExtrasDbusManager, g_object_unref)
VALA_EXTERN guint budgie_extras_dbus_manager_register_object (void* object,
                                                  GDBusConnection* connection,
                                                  const gchar* path,
                                                  GError** error);
VALA_EXTERN BudgieExtrasDbusManager* budgie_extras_dbus_manager_new (void);
VALA_EXTERN BudgieExtrasDbusManager* budgie_extras_dbus_manager_construct (GType object_type);
VALA_EXTERN void budgie_extras_dbus_manager_setup_dbus (BudgieExtrasDbusManager* self,
                                            gboolean replace);

const GOptionEntry options[2] = {{"replace", (gchar) 0, (gint) 0, G_OPTION_ARG_NONE, &replace, "Replace currently running daemon"}, {NULL}};

void
budgie_extras_DaemonNameLost (GDBusConnection* conn,
                              const gchar* name)
{
	g_return_if_fail (conn != NULL);
	g_return_if_fail (name != NULL);
	g_warning ("main.vala:35: budgie-extras-daemon lost d-bus name %s", name);
	if (!budgie_extras_spammed) {
		if (budgie_extras_setup) {
			g_message ("main.vala:38: Replaced existing budgie-extras-daemon");
		} else {
			g_message ("main.vala:40: Another instance of budgie-extras-daemon is running. Use" \
" --replace");
		}
		budgie_extras_spammed = TRUE;
	}
	gtk_main_quit ();
}

/**
 * Main entry for the daemon
 */
static gint
_vala_main (gchar** args,
            gint args_length1)
{
	GOptionContext* ctx = NULL;
	GOptionContext* _tmp0_;
	GOptionContext* _tmp1_;
	GOptionContext* _tmp2_;
	GOptionContext* _tmp3_;
	GOptionGroup* _tmp4_;
	BudgieExtrasDbusManager* dbus = NULL;
	BudgieExtrasDbusManager* _tmp9_;
	BudgieExtrasDbusManager* _tmp10_;
	GError* _inner_error0_ = NULL;
	gint result;
	gtk_init ((gint*) (&args_length1), &args);
	_tmp0_ = g_option_context_new ("- Budgie Extras Daemon");
	_g_option_context_free0 (ctx);
	ctx = _tmp0_;
	_tmp1_ = ctx;
	g_option_context_set_help_enabled (_tmp1_, TRUE);
	_tmp2_ = ctx;
	g_option_context_add_main_entries (_tmp2_, options, NULL);
	_tmp3_ = ctx;
	_tmp4_ = gtk_get_option_group (FALSE);
	g_option_context_add_group (_tmp3_, _tmp4_);
	{
		GOptionContext* _tmp5_;
		_tmp5_ = ctx;
		g_option_context_parse (_tmp5_, (gint*) (&args_length1), &args, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
	}
	goto __finally0;
	__catch0_g_error:
	{
		GError* e = NULL;
		GError* _tmp6_;
		const gchar* _tmp7_;
		e = _inner_error0_;
		_inner_error0_ = NULL;
		_tmp6_ = e;
		_tmp7_ = _tmp6_->message;
		g_message ("main.vala:63: Error: %s\n", _tmp7_);
		result = 0;
		_g_error_free0 (e);
		_g_option_context_free0 (ctx);
		return result;
	}
	__finally0:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		gint _tmp8_ = -1;
		_g_option_context_free0 (ctx);
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
		g_clear_error (&_inner_error0_);
		return _tmp8_;
	}
	_tmp9_ = budgie_extras_dbus_manager_new ();
	dbus = _tmp9_;
	_tmp10_ = dbus;
	budgie_extras_dbus_manager_setup_dbus (_tmp10_, replace);
	gtk_main ();
	result = 0;
	_g_object_unref0 (dbus);
	_g_option_context_free0 (ctx);
	return result;
}

int
main (int argc,
      char ** argv)
{
	return _vala_main (argv, argc);
}

