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

/*
* Copyright (c) 2017 Robert San <robertsanseries@gmail.com>
*
* 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 <gtk/gtk.h>
#include <glib-object.h>
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <glib/gi18n-lib.h>
#include <granite.h>

#define CIANO_CONFIGS_CONSTANTS_PROGRAME_NAME "Ciano"
#define CIANO_CONFIGS_PROPERTIES_TEXT_OPEN_OUTPUT_FOLDER _ ("Open output folder")
#define CIANO_CONFIGS_PROPERTIES_TEXT_SETTINGS _ ("Settings")
#define CIANO_CONFIGS_PROPERTIES_TEXT_PREFERENCES _ ("Preferences")
#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 CIANO_WIDGETS_TYPE_HEADER_BAR (ciano_widgets_header_bar_get_type ())
#define CIANO_WIDGETS_HEADER_BAR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CIANO_WIDGETS_TYPE_HEADER_BAR, CianoWidgetsHeaderBar))
#define CIANO_WIDGETS_HEADER_BAR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), CIANO_WIDGETS_TYPE_HEADER_BAR, CianoWidgetsHeaderBarClass))
#define CIANO_WIDGETS_IS_HEADER_BAR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CIANO_WIDGETS_TYPE_HEADER_BAR))
#define CIANO_WIDGETS_IS_HEADER_BAR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CIANO_WIDGETS_TYPE_HEADER_BAR))
#define CIANO_WIDGETS_HEADER_BAR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), CIANO_WIDGETS_TYPE_HEADER_BAR, CianoWidgetsHeaderBarClass))

typedef struct _CianoWidgetsHeaderBar CianoWidgetsHeaderBar;
typedef struct _CianoWidgetsHeaderBarClass CianoWidgetsHeaderBarClass;
typedef struct _CianoWidgetsHeaderBarPrivate CianoWidgetsHeaderBarPrivate;
enum  {
	CIANO_WIDGETS_HEADER_BAR_0_PROPERTY,
	CIANO_WIDGETS_HEADER_BAR_NUM_PROPERTIES
};
static GParamSpec* ciano_widgets_header_bar_properties[CIANO_WIDGETS_HEADER_BAR_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

#define CIANO_SERVICES_TYPE_SETTINGS (ciano_services_settings_get_type ())
#define CIANO_SERVICES_SETTINGS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CIANO_SERVICES_TYPE_SETTINGS, CianoServicesSettings))
#define CIANO_SERVICES_SETTINGS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), CIANO_SERVICES_TYPE_SETTINGS, CianoServicesSettingsClass))
#define CIANO_SERVICES_IS_SETTINGS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CIANO_SERVICES_TYPE_SETTINGS))
#define CIANO_SERVICES_IS_SETTINGS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CIANO_SERVICES_TYPE_SETTINGS))
#define CIANO_SERVICES_SETTINGS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), CIANO_SERVICES_TYPE_SETTINGS, CianoServicesSettingsClass))

typedef struct _CianoServicesSettings CianoServicesSettings;
typedef struct _CianoServicesSettingsClass CianoServicesSettingsClass;
enum  {
	CIANO_WIDGETS_HEADER_BAR_ITEM_SELECTED_SIGNAL,
	CIANO_WIDGETS_HEADER_BAR_NUM_SIGNALS
};
static guint ciano_widgets_header_bar_signals[CIANO_WIDGETS_HEADER_BAR_NUM_SIGNALS] = {0};

struct _CianoWidgetsHeaderBar {
	GtkHeaderBar parent_instance;
	CianoWidgetsHeaderBarPrivate * priv;
	GtkMenuButton* app_menu;
	GtkMenu* menu;
};

struct _CianoWidgetsHeaderBarClass {
	GtkHeaderBarClass parent_class;
};

static gpointer ciano_widgets_header_bar_parent_class = NULL;

VALA_EXTERN GType ciano_widgets_header_bar_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (CianoWidgetsHeaderBar, g_object_unref)
VALA_EXTERN CianoWidgetsHeaderBar* ciano_widgets_header_bar_new (void);
VALA_EXTERN CianoWidgetsHeaderBar* ciano_widgets_header_bar_construct (GType object_type);
static void ciano_widgets_header_bar_icon_open_output_folder (CianoWidgetsHeaderBar* self);
static void ciano_widgets_header_bar_icon_settings (CianoWidgetsHeaderBar* self);
static void __lambda4_ (CianoWidgetsHeaderBar* self);
VALA_EXTERN GType ciano_services_settings_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (CianoServicesSettings, g_object_unref)
VALA_EXTERN CianoServicesSettings* ciano_services_settings_get_instance (void);
VALA_EXTERN void ciano_utils_file_util_open_folder_file_app (const gchar* uri);
VALA_EXTERN const gchar* ciano_services_settings_get_output_folder (CianoServicesSettings* self);
static void ___lambda4__gtk_button_clicked (GtkButton* _sender,
                                     gpointer self);
static void ciano_widgets_header_bar_menu_settings (CianoWidgetsHeaderBar* self);
static void __lambda5_ (CianoWidgetsHeaderBar* self);
static void ___lambda5__gtk_menu_item_activate (GtkMenuItem* _sender,
                                         gpointer self);
static void ciano_widgets_header_bar_finalize (GObject * obj);
static GType ciano_widgets_header_bar_get_type_once (void);

/**
         * Constructs a new {@code HeaderBar} object. Sets the title of the top bar and
         * adds widgets that are displayed.
         *
         * @see Ciano.Configs.Properties
         * @see icon_settings
         */
CianoWidgetsHeaderBar*
ciano_widgets_header_bar_construct (GType object_type)
{
	CianoWidgetsHeaderBar * self = NULL;
	self = (CianoWidgetsHeaderBar*) g_object_new (object_type, NULL);
	gtk_header_bar_set_title ((GtkHeaderBar*) self, CIANO_CONFIGS_CONSTANTS_PROGRAME_NAME);
	gtk_header_bar_set_show_close_button ((GtkHeaderBar*) self, TRUE);
	ciano_widgets_header_bar_icon_open_output_folder (self);
	ciano_widgets_header_bar_icon_settings (self);
	return self;
}

CianoWidgetsHeaderBar*
ciano_widgets_header_bar_new (void)
{
	return ciano_widgets_header_bar_construct (CIANO_WIDGETS_TYPE_HEADER_BAR);
}

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

static void
__lambda4_ (CianoWidgetsHeaderBar* self)
{
	CianoServicesSettings* settings = NULL;
	CianoServicesSettings* _tmp0_;
	CianoServicesSettings* _tmp1_;
	const gchar* _tmp2_;
	const gchar* _tmp3_;
	_tmp0_ = ciano_services_settings_get_instance ();
	_tmp1_ = _g_object_ref0 (_tmp0_);
	settings = _tmp1_;
	_tmp2_ = ciano_services_settings_get_output_folder (settings);
	_tmp3_ = _tmp2_;
	ciano_utils_file_util_open_folder_file_app (_tmp3_);
	_g_object_unref0 (settings);
}

static void
___lambda4__gtk_button_clicked (GtkButton* _sender,
                                gpointer self)
{
	__lambda4_ ((CianoWidgetsHeaderBar*) self);
}

static void
ciano_widgets_header_bar_icon_open_output_folder (CianoWidgetsHeaderBar* self)
{
	GtkButton* output_folder = NULL;
	GtkButton* _tmp0_;
	GtkImage* _tmp1_;
	GtkImage* _tmp2_;
	g_return_if_fail (self != NULL);
	_tmp0_ = (GtkButton*) gtk_button_new ();
	g_object_ref_sink (_tmp0_);
	output_folder = _tmp0_;
	_tmp1_ = (GtkImage*) gtk_image_new_from_icon_name ("folder-saved-search", (GtkIconSize) GTK_ICON_SIZE_LARGE_TOOLBAR);
	g_object_ref_sink (_tmp1_);
	_tmp2_ = _tmp1_;
	gtk_button_set_image (output_folder, (GtkWidget*) _tmp2_);
	_g_object_unref0 (_tmp2_);
	gtk_widget_set_tooltip_text ((GtkWidget*) output_folder, CIANO_CONFIGS_PROPERTIES_TEXT_OPEN_OUTPUT_FOLDER);
	g_signal_connect_object (output_folder, "clicked", (GCallback) ___lambda4__gtk_button_clicked, self, 0);
	gtk_header_bar_pack_start ((GtkHeaderBar*) self, (GtkWidget*) output_folder);
	_g_object_unref0 (output_folder);
}

/**
         * Add gear icon to open settings menu.
         * 
         * @see menu_settings
         * @return {@code void}
         */
static void
ciano_widgets_header_bar_icon_settings (CianoWidgetsHeaderBar* self)
{
	GtkMenuButton* _tmp0_;
	GtkMenuButton* _tmp1_;
	GtkImage* _tmp2_;
	GtkImage* _tmp3_;
	GtkMenuButton* _tmp4_;
	GtkMenuButton* _tmp5_;
	GtkMenu* _tmp6_;
	GtkMenuButton* _tmp7_;
	g_return_if_fail (self != NULL);
	_tmp0_ = (GtkMenuButton*) gtk_menu_button_new ();
	g_object_ref_sink (_tmp0_);
	_g_object_unref0 (self->app_menu);
	self->app_menu = _tmp0_;
	_tmp1_ = self->app_menu;
	_tmp2_ = (GtkImage*) gtk_image_new_from_icon_name ("open-menu", (GtkIconSize) GTK_ICON_SIZE_LARGE_TOOLBAR);
	g_object_ref_sink (_tmp2_);
	_tmp3_ = _tmp2_;
	gtk_button_set_image ((GtkButton*) _tmp1_, (GtkWidget*) _tmp3_);
	_g_object_unref0 (_tmp3_);
	_tmp4_ = self->app_menu;
	gtk_widget_set_tooltip_text ((GtkWidget*) _tmp4_, CIANO_CONFIGS_PROPERTIES_TEXT_SETTINGS);
	ciano_widgets_header_bar_menu_settings (self);
	_tmp5_ = self->app_menu;
	_tmp6_ = self->menu;
	gtk_menu_button_set_popup (_tmp5_, _tmp6_);
	_tmp7_ = self->app_menu;
	gtk_header_bar_pack_end ((GtkHeaderBar*) self, (GtkWidget*) _tmp7_);
}

/**
         * Creates the settings menu. When the user clicks the preferences option, {@code Gtk.MenuItem} will call
         * the signal "item_selected". The actions of this signal are in the "on_activate_button_preferences" method
         * of the ConverterController;
         *
         * @see Ciano.Controllers.ConverterController;
         * @return {@code void}
         */
static void
__lambda5_ (CianoWidgetsHeaderBar* self)
{
	g_signal_emit (self, ciano_widgets_header_bar_signals[CIANO_WIDGETS_HEADER_BAR_ITEM_SELECTED_SIGNAL], 0);
}

static void
___lambda5__gtk_menu_item_activate (GtkMenuItem* _sender,
                                    gpointer self)
{
	__lambda5_ ((CianoWidgetsHeaderBar*) self);
}

static void
ciano_widgets_header_bar_menu_settings (CianoWidgetsHeaderBar* self)
{
	GtkMenuItem* about_item = NULL;
	GtkMenuItem* _tmp0_;
	GtkMenu* _tmp1_;
	GtkMenu* _tmp2_;
	GtkMenu* _tmp3_;
	g_return_if_fail (self != NULL);
	_tmp0_ = (GtkMenuItem*) gtk_menu_item_new_with_label (CIANO_CONFIGS_PROPERTIES_TEXT_PREFERENCES);
	g_object_ref_sink (_tmp0_);
	about_item = _tmp0_;
	g_signal_connect_object (about_item, "activate", (GCallback) ___lambda5__gtk_menu_item_activate, self, 0);
	_tmp1_ = (GtkMenu*) gtk_menu_new ();
	g_object_ref_sink (_tmp1_);
	_g_object_unref0 (self->menu);
	self->menu = _tmp1_;
	_tmp2_ = self->menu;
	gtk_container_add ((GtkContainer*) _tmp2_, (GtkWidget*) about_item);
	_tmp3_ = self->menu;
	gtk_widget_show_all ((GtkWidget*) _tmp3_);
	_g_object_unref0 (about_item);
}

static void
ciano_widgets_header_bar_class_init (CianoWidgetsHeaderBarClass * klass,
                                     gpointer klass_data)
{
	ciano_widgets_header_bar_parent_class = g_type_class_peek_parent (klass);
	G_OBJECT_CLASS (klass)->finalize = ciano_widgets_header_bar_finalize;
	ciano_widgets_header_bar_signals[CIANO_WIDGETS_HEADER_BAR_ITEM_SELECTED_SIGNAL] = g_signal_new ("item-selected", CIANO_WIDGETS_TYPE_HEADER_BAR, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
}

static void
ciano_widgets_header_bar_instance_init (CianoWidgetsHeaderBar * self,
                                        gpointer klass)
{
}

static void
ciano_widgets_header_bar_finalize (GObject * obj)
{
	CianoWidgetsHeaderBar * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, CIANO_WIDGETS_TYPE_HEADER_BAR, CianoWidgetsHeaderBar);
	_g_object_unref0 (self->app_menu);
	_g_object_unref0 (self->menu);
	G_OBJECT_CLASS (ciano_widgets_header_bar_parent_class)->finalize (obj);
}

/**
     * The {@code HeaderBar} class is responsible for displaying top bar. Similar to a horizontal box.
     *
     * @see Gtk.HeaderBar
     * @since 0.1.0
     */
static GType
ciano_widgets_header_bar_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (CianoWidgetsHeaderBarClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) ciano_widgets_header_bar_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (CianoWidgetsHeaderBar), 0, (GInstanceInitFunc) ciano_widgets_header_bar_instance_init, NULL };
	GType ciano_widgets_header_bar_type_id;
	ciano_widgets_header_bar_type_id = g_type_register_static (gtk_header_bar_get_type (), "CianoWidgetsHeaderBar", &g_define_type_info, 0);
	return ciano_widgets_header_bar_type_id;
}

GType
ciano_widgets_header_bar_get_type (void)
{
	static volatile gsize ciano_widgets_header_bar_type_id__once = 0;
	if (g_once_init_enter (&ciano_widgets_header_bar_type_id__once)) {
		GType ciano_widgets_header_bar_type_id;
		ciano_widgets_header_bar_type_id = ciano_widgets_header_bar_get_type_once ();
		g_once_init_leave (&ciano_widgets_header_bar_type_id__once, ciano_widgets_header_bar_type_id);
	}
	return ciano_widgets_header_bar_type_id__once;
}

