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

/* application.vala
 *
 * Copyright (C) 2017 Red Hat, Inc.
 *
 * 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
 * (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, see <http://www.gnu.org/licenses/>.
 *
 * Authors: Petr Štětka <pstetka@redhat.com>
 */

#include <adwaita.h>
#include <glib-object.h>
#include <gio/gio.h>
#include <glib.h>
#include <gtk/gtk.h>
#include <stdlib.h>
#include <string.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
#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 USAGE_TYPE_APPLICATION (usage_application_get_type ())
#define USAGE_APPLICATION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), USAGE_TYPE_APPLICATION, UsageApplication))
#define USAGE_APPLICATION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), USAGE_TYPE_APPLICATION, UsageApplicationClass))
#define USAGE_IS_APPLICATION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), USAGE_TYPE_APPLICATION))
#define USAGE_IS_APPLICATION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), USAGE_TYPE_APPLICATION))
#define USAGE_APPLICATION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), USAGE_TYPE_APPLICATION, UsageApplicationClass))

typedef struct _UsageApplication UsageApplication;
typedef struct _UsageApplicationClass UsageApplicationClass;
typedef struct _UsageApplicationPrivate UsageApplicationPrivate;

#define USAGE_TYPE_WINDOW (usage_window_get_type ())
#define USAGE_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), USAGE_TYPE_WINDOW, UsageWindow))
#define USAGE_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), USAGE_TYPE_WINDOW, UsageWindowClass))
#define USAGE_IS_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), USAGE_TYPE_WINDOW))
#define USAGE_IS_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), USAGE_TYPE_WINDOW))
#define USAGE_WINDOW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), USAGE_TYPE_WINDOW, UsageWindowClass))

typedef struct _UsageWindow UsageWindow;
typedef struct _UsageWindowClass UsageWindowClass;
enum  {
	USAGE_APPLICATION_0_PROPERTY,
	USAGE_APPLICATION_NUM_PROPERTIES
};
static GParamSpec* usage_application_properties[USAGE_APPLICATION_NUM_PROPERTIES];
typedef void (*GSimpleActionActivateCallback) (GSimpleAction* action, GVariant* parameter, gpointer user_data);
typedef void (*GSimpleActionChangeStateCallback) (GSimpleAction* action, GVariant* value, gpointer user_data);
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))

#define USAGE_TYPE_SYSTEM_MONITOR (usage_system_monitor_get_type ())
#define USAGE_SYSTEM_MONITOR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), USAGE_TYPE_SYSTEM_MONITOR, UsageSystemMonitor))
#define USAGE_SYSTEM_MONITOR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), USAGE_TYPE_SYSTEM_MONITOR, UsageSystemMonitorClass))
#define USAGE_IS_SYSTEM_MONITOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), USAGE_TYPE_SYSTEM_MONITOR))
#define USAGE_IS_SYSTEM_MONITOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), USAGE_TYPE_SYSTEM_MONITOR))
#define USAGE_SYSTEM_MONITOR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), USAGE_TYPE_SYSTEM_MONITOR, UsageSystemMonitorClass))

typedef struct _UsageSystemMonitor UsageSystemMonitor;
typedef struct _UsageSystemMonitorClass UsageSystemMonitorClass;

struct _UsageApplication {
	AdwApplication parent_instance;
	UsageApplicationPrivate * priv;
};

struct _UsageApplicationClass {
	AdwApplicationClass parent_class;
};

struct _UsageApplicationPrivate {
	UsageWindow* window;
};

static gint UsageApplication_private_offset;
static gpointer usage_application_parent_class = NULL;

VALA_EXTERN GType usage_application_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (UsageApplication, g_object_unref)
VALA_EXTERN GType usage_window_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (UsageWindow, g_object_unref)
static void usage_application_on_about (UsageApplication* self,
                                 GSimpleAction* action,
                                 GVariant* parameter);
static void _usage_application_on_about_gsimple_action_activate_callback (GSimpleAction* action,
                                                                   GVariant* parameter,
                                                                   gpointer self);
static void usage_application_on_search (UsageApplication* self,
                                  GSimpleAction* action,
                                  GVariant* parameter);
static void _usage_application_on_search_gsimple_action_activate_callback (GSimpleAction* action,
                                                                    GVariant* parameter,
                                                                    gpointer self);
static void usage_application_on_quit (UsageApplication* self,
                                GSimpleAction* action,
                                GVariant* parameter);
static void _usage_application_on_quit_gsimple_action_activate_callback (GSimpleAction* action,
                                                                  GVariant* parameter,
                                                                  gpointer self);
static void usage_application_on_activate_radio (UsageApplication* self,
                                          GSimpleAction* action,
                                          GVariant* state);
static void _usage_application_on_activate_radio_gsimple_action_activate_callback (GSimpleAction* action,
                                                                            GVariant* parameter,
                                                                            gpointer self);
static void usage_application_change_filter_processes_state (UsageApplication* self,
                                                      GSimpleAction* action,
                                                      GVariant* state);
static void _usage_application_change_filter_processes_state_gsimple_action_change_state_callback (GSimpleAction* action,
                                                                                            GVariant* value,
                                                                                            gpointer self);
VALA_EXTERN UsageApplication* usage_application_new (void);
VALA_EXTERN UsageApplication* usage_application_construct (GType object_type);
VALA_EXTERN UsageWindow* usage_application_get_window (UsageApplication* self);
static void usage_application_real_activate (GApplication* base);
VALA_EXTERN UsageWindow* usage_window_new (GtkApplication* application);
VALA_EXTERN UsageWindow* usage_window_construct (GType object_type,
                                     GtkApplication* application);
static void usage_application_real_startup (GApplication* base);
static gchar** _vala_array_dup1 (gchar** self,
                          gssize length);
static gchar** _vala_array_dup2 (gchar** self,
                          gssize length);
VALA_EXTERN void usage_window_action_on_search (UsageWindow* self);
VALA_EXTERN GType usage_system_monitor_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (UsageSystemMonitor, g_object_unref)
VALA_EXTERN UsageSystemMonitor* usage_system_monitor_get_default (void);
VALA_EXTERN void usage_system_monitor_set_group_system_apps (UsageSystemMonitor* self,
                                                 gboolean value);
static void usage_application_finalize (GObject * obj);
static GType usage_application_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 const GActionEntry USAGE_APPLICATION_app_entries[4] = {{"about", _usage_application_on_about_gsimple_action_activate_callback}, {"search", _usage_application_on_search_gsimple_action_activate_callback}, {"quit", _usage_application_on_quit_gsimple_action_activate_callback}, {"filter-processes", _usage_application_on_activate_radio_gsimple_action_activate_callback, "s", "'group-system'", _usage_application_change_filter_processes_state_gsimple_action_change_state_callback}};

static inline gpointer
usage_application_get_instance_private (UsageApplication* self)
{
	return G_STRUCT_MEMBER_P (self, UsageApplication_private_offset);
}

static void
_usage_application_on_about_gsimple_action_activate_callback (GSimpleAction* action,
                                                              GVariant* parameter,
                                                              gpointer self)
{
	usage_application_on_about ((UsageApplication*) self, action, parameter);
}

static void
_usage_application_on_search_gsimple_action_activate_callback (GSimpleAction* action,
                                                               GVariant* parameter,
                                                               gpointer self)
{
	usage_application_on_search ((UsageApplication*) self, action, parameter);
}

static void
_usage_application_on_quit_gsimple_action_activate_callback (GSimpleAction* action,
                                                             GVariant* parameter,
                                                             gpointer self)
{
	usage_application_on_quit ((UsageApplication*) self, action, parameter);
}

static void
_usage_application_on_activate_radio_gsimple_action_activate_callback (GSimpleAction* action,
                                                                       GVariant* parameter,
                                                                       gpointer self)
{
	usage_application_on_activate_radio ((UsageApplication*) self, action, parameter);
}

static void
_usage_application_change_filter_processes_state_gsimple_action_change_state_callback (GSimpleAction* action,
                                                                                       GVariant* value,
                                                                                       gpointer self)
{
	usage_application_change_filter_processes_state ((UsageApplication*) self, action, value);
}

UsageApplication*
usage_application_construct (GType object_type)
{
	UsageApplication * self = NULL;
	self = (UsageApplication*) g_object_new (object_type, "application-id", APPLICATION_ID, "flags", G_APPLICATION_DEFAULT_FLAGS, "resource-base-path", APPLICATION_RESOURCE_PATH, NULL);
	return self;
}

UsageApplication*
usage_application_new (void)
{
	return usage_application_construct (USAGE_TYPE_APPLICATION);
}

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

UsageWindow*
usage_application_get_window (UsageApplication* self)
{
	UsageWindow* _tmp0_;
	UsageWindow* _tmp1_;
	UsageWindow* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->window;
	_tmp1_ = _g_object_ref0 (_tmp0_);
	result = _tmp1_;
	return result;
}

static void
usage_application_real_activate (GApplication* base)
{
	UsageApplication * self;
	UsageWindow* _tmp0_;
	UsageWindow* _tmp2_;
	self = (UsageApplication*) base;
	_tmp0_ = self->priv->window;
	if (_tmp0_ == NULL) {
		UsageWindow* _tmp1_;
		_tmp1_ = usage_window_new ((GtkApplication*) self);
		g_object_ref_sink (_tmp1_);
		_g_object_unref0 (self->priv->window);
		self->priv->window = _tmp1_;
	}
	_tmp2_ = self->priv->window;
	gtk_window_present ((GtkWindow*) _tmp2_);
}

static void
usage_application_real_startup (GApplication* base)
{
	UsageApplication * self;
	gchar* _tmp0_;
	gchar** _tmp1_;
	gchar** _tmp2_;
	gint _tmp2__length1;
	gchar* _tmp3_;
	gchar** _tmp4_;
	gchar** _tmp5_;
	gint _tmp5__length1;
	self = (UsageApplication*) base;
	G_APPLICATION_CLASS (usage_application_parent_class)->startup ((GApplication*) G_TYPE_CHECK_INSTANCE_CAST (self, adw_application_get_type (), AdwApplication));
	g_action_map_add_action_entries ((GActionMap*) self, USAGE_APPLICATION_app_entries, (gint) G_N_ELEMENTS (USAGE_APPLICATION_app_entries), self);
	_tmp0_ = g_strdup ("<Control>f");
	_tmp1_ = g_new0 (gchar*, 1 + 1);
	_tmp1_[0] = _tmp0_;
	_tmp2_ = _tmp1_;
	_tmp2__length1 = 1;
	gtk_application_set_accels_for_action ((GtkApplication*) self, "app.search", _tmp2_);
	_tmp2_ = (_vala_array_free (_tmp2_, _tmp2__length1, (GDestroyNotify) g_free), NULL);
	_tmp3_ = g_strdup ("<Control>q");
	_tmp4_ = g_new0 (gchar*, 1 + 1);
	_tmp4_[0] = _tmp3_;
	_tmp5_ = _tmp4_;
	_tmp5__length1 = 1;
	gtk_application_set_accels_for_action ((GtkApplication*) self, "app.quit", _tmp5_);
	_tmp5_ = (_vala_array_free (_tmp5_, _tmp5__length1, (GDestroyNotify) g_free), NULL);
	gtk_window_set_default_icon_name ("org.gnome.Usage");
}

static gchar**
_vala_array_dup1 (gchar** self,
                  gssize length)
{
	if (length >= 0) {
		gchar** result;
		gssize i;
		result = g_new0 (gchar*, length + 1);
		for (i = 0; i < length; i++) {
			gchar* _tmp0_;
			_tmp0_ = g_strdup (self[i]);
			result[i] = _tmp0_;
		}
		return result;
	}
	return NULL;
}

static gchar**
_vala_array_dup2 (gchar** self,
                  gssize length)
{
	if (length >= 0) {
		gchar** result;
		gssize i;
		result = g_new0 (gchar*, length + 1);
		for (i = 0; i < length; i++) {
			gchar* _tmp0_;
			_tmp0_ = g_strdup (self[i]);
			result[i] = _tmp0_;
		}
		return result;
	}
	return NULL;
}

static void
usage_application_on_about (UsageApplication* self,
                            GSimpleAction* action,
                            GVariant* parameter)
{
	gchar** authors = NULL;
	gchar* _tmp0_;
	gchar* _tmp1_;
	gchar** _tmp2_;
	gint authors_length1;
	gint _authors_size_;
	gchar** artists = NULL;
	gchar* _tmp3_;
	gchar* _tmp4_;
	gchar* _tmp5_;
	gchar** _tmp6_;
	gint artists_length1;
	gint _artists_size_;
	gchar** _tmp7_;
	gchar** _tmp8_;
	gchar** _tmp9_;
	gint _tmp9__length1;
	const gchar* _tmp10_;
	gchar* _tmp11_;
	gchar** _tmp12_;
	gint _tmp12__length1;
	gchar** _tmp13_;
	gint _tmp13__length1;
	gchar* _tmp14_;
	AdwAboutDialog* _tmp15_ = NULL;
	AdwAboutDialog* _tmp16_;
	UsageWindow* _tmp17_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (action != NULL);
	_tmp0_ = g_strdup ("Petr Štětka <pstetka@redhat.com>");
	_tmp1_ = g_strdup ("Markus Göllnitz <camelcasenick@bewares.it>");
	_tmp2_ = g_new0 (gchar*, 2 + 1);
	_tmp2_[0] = _tmp0_;
	_tmp2_[1] = _tmp1_;
	authors = _tmp2_;
	authors_length1 = 2;
	_authors_size_ = authors_length1;
	_tmp3_ = g_strdup ("Allan Day <aday@gnome.org>");
	_tmp4_ = g_strdup ("Jon McCann <jmccann@redhat.com>");
	_tmp5_ = g_strdup ("Jakub Steiner <jsteiner@redhat.com>");
	_tmp6_ = g_new0 (gchar*, 3 + 1);
	_tmp6_[0] = _tmp3_;
	_tmp6_[1] = _tmp4_;
	_tmp6_[2] = _tmp5_;
	artists = _tmp6_;
	artists_length1 = 3;
	_artists_size_ = artists_length1;
	_tmp8_ = _tmp7_ = g_strsplit (VERSION, "-", 0);
	_tmp9_ = _tmp8_;
	_tmp9__length1 = _vala_array_length (_tmp7_);
	_tmp10_ = _tmp9_[0];
	_tmp11_ = g_strdup (_ ("A nice way to view information about use of system resources, like mem" \
"ory and disk space."));
	_tmp12_ = (authors != NULL) ? _vala_array_dup1 (authors, authors_length1) : authors;
	_tmp12__length1 = authors_length1;
	_tmp13_ = (artists != NULL) ? _vala_array_dup2 (artists, artists_length1) : artists;
	_tmp13__length1 = artists_length1;
	_tmp14_ = g_strdup (_ ("translator-credits"));
	_tmp15_ = (AdwAboutDialog*) adw_about_dialog_new_from_appdata (APPLICATION_RESOURCE_PATH "org.gnome.Usage" ".metainfo.xml", _tmp10_);
	adw_about_dialog_set_comments (_tmp15_, _tmp11_);
	_g_free0 (_tmp11_);
	adw_about_dialog_set_developers (_tmp15_, _tmp12_);
	_tmp12_ = (_vala_array_free (_tmp12_, _tmp12__length1, (GDestroyNotify) g_free), NULL);
	adw_about_dialog_set_designers (_tmp15_, _tmp13_);
	_tmp13_ = (_vala_array_free (_tmp13_, _tmp13__length1, (GDestroyNotify) g_free), NULL);
	adw_about_dialog_set_translator_credits (_tmp15_, _tmp14_);
	_g_free0 (_tmp14_);
	g_object_ref_sink (_tmp15_);
	_tmp16_ = _tmp15_;
	_tmp17_ = self->priv->window;
	adw_dialog_present ((AdwDialog*) _tmp16_, (GtkWidget*) _tmp17_);
	_g_object_unref0 (_tmp16_);
	_tmp9_ = (_vala_array_free (_tmp9_, _tmp9__length1, (GDestroyNotify) g_free), NULL);
	artists = (_vala_array_free (artists, artists_length1, (GDestroyNotify) g_free), NULL);
	authors = (_vala_array_free (authors, authors_length1, (GDestroyNotify) g_free), NULL);
}

static void
usage_application_on_quit (UsageApplication* self,
                           GSimpleAction* action,
                           GVariant* parameter)
{
	UsageWindow* _tmp0_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (action != NULL);
	_tmp0_ = self->priv->window;
	gtk_window_destroy ((GtkWindow*) _tmp0_);
}

static void
usage_application_on_search (UsageApplication* self,
                             GSimpleAction* action,
                             GVariant* parameter)
{
	UsageWindow* _tmp0_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (action != NULL);
	_tmp0_ = self->priv->window;
	usage_window_action_on_search (_tmp0_);
}

static void
usage_application_on_activate_radio (UsageApplication* self,
                                     GSimpleAction* action,
                                     GVariant* state)
{
	g_return_if_fail (self != NULL);
	g_return_if_fail (action != NULL);
	g_signal_emit_by_name (action, "change-state", state);
}

static void
usage_application_change_filter_processes_state (UsageApplication* self,
                                                 GSimpleAction* action,
                                                 GVariant* state)
{
	gboolean _tmp0_ = FALSE;
	const gchar* _tmp1_;
	UsageSystemMonitor* _tmp2_;
	UsageSystemMonitor* _tmp3_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (action != NULL);
	g_simple_action_set_state (action, state);
	_tmp1_ = g_variant_get_string (state, NULL);
	if (g_strcmp0 (_tmp1_, "group-system") == 0) {
		_tmp0_ = TRUE;
	} else {
		_tmp0_ = FALSE;
	}
	_tmp2_ = usage_system_monitor_get_default ();
	_tmp3_ = _tmp2_;
	usage_system_monitor_set_group_system_apps (_tmp3_, _tmp0_);
	_g_object_unref0 (_tmp3_);
}

static void
usage_application_class_init (UsageApplicationClass * klass,
                              gpointer klass_data)
{
	usage_application_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &UsageApplication_private_offset);
	((GApplicationClass *) klass)->activate = (void (*) (GApplication*)) usage_application_real_activate;
	((GApplicationClass *) klass)->startup = (void (*) (GApplication*)) usage_application_real_startup;
	G_OBJECT_CLASS (klass)->finalize = usage_application_finalize;
}

static void
usage_application_instance_init (UsageApplication * self,
                                 gpointer klass)
{
	self->priv = usage_application_get_instance_private (self);
}

static void
usage_application_finalize (GObject * obj)
{
	UsageApplication * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, USAGE_TYPE_APPLICATION, UsageApplication);
	_g_object_unref0 (self->priv->window);
	G_OBJECT_CLASS (usage_application_parent_class)->finalize (obj);
}

static GType
usage_application_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (UsageApplicationClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) usage_application_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (UsageApplication), 0, (GInstanceInitFunc) usage_application_instance_init, NULL };
	GType usage_application_type_id;
	usage_application_type_id = g_type_register_static (adw_application_get_type (), "UsageApplication", &g_define_type_info, 0);
	UsageApplication_private_offset = g_type_add_instance_private (usage_application_type_id, sizeof (UsageApplicationPrivate));
	return usage_application_type_id;
}

GType
usage_application_get_type (void)
{
	static volatile gsize usage_application_type_id__once = 0;
	if (g_once_init_enter (&usage_application_type_id__once)) {
		GType usage_application_type_id;
		usage_application_type_id = usage_application_get_type_once ();
		g_once_init_leave (&usage_application_type_id__once, usage_application_type_id);
	}
	return usage_application_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;
}

