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

/*
    UIUtil.vala
    Copyright (C) 2010 Maia Kozheva <sikon@ubuntu.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 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/>.
*/

#include <glib-object.h>
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <gio/gio.h>
#include <gtk/gtk.h>
#include <gdk/gdk.h>
#include <stdio.h>
#include <glib/gi18n-lib.h>

#define STEADYFLOW_UI_UI_UTIL_MESSAGE_FORMAT "<span weight='bold' size='larger'>%s</span>\n\n%s\n"
#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 STEADYFLOW_UI_TYPE_UI_UTIL (steadyflow_ui_ui_util_get_type ())
#define STEADYFLOW_UI_UI_UTIL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), STEADYFLOW_UI_TYPE_UI_UTIL, SteadyflowUIUIUtil))
#define STEADYFLOW_UI_UI_UTIL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), STEADYFLOW_UI_TYPE_UI_UTIL, SteadyflowUIUIUtilClass))
#define STEADYFLOW_UI_IS_UI_UTIL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), STEADYFLOW_UI_TYPE_UI_UTIL))
#define STEADYFLOW_UI_IS_UI_UTIL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), STEADYFLOW_UI_TYPE_UI_UTIL))
#define STEADYFLOW_UI_UI_UTIL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), STEADYFLOW_UI_TYPE_UI_UTIL, SteadyflowUIUIUtilClass))

typedef struct _SteadyflowUIUIUtil SteadyflowUIUIUtil;
typedef struct _SteadyflowUIUIUtilClass SteadyflowUIUIUtilClass;
typedef struct _SteadyflowUIUIUtilPrivate SteadyflowUIUIUtilPrivate;
enum  {
	STEADYFLOW_UI_UI_UTIL_0_PROPERTY,
	STEADYFLOW_UI_UI_UTIL_NUM_PROPERTIES
};
static GParamSpec* steadyflow_ui_ui_util_properties[STEADYFLOW_UI_UI_UTIL_NUM_PROPERTIES];

#define STEADYFLOW_CORE_TYPE_IDOWNLOAD_FILE (steadyflow_core_idownload_file_get_type ())
#define STEADYFLOW_CORE_IDOWNLOAD_FILE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), STEADYFLOW_CORE_TYPE_IDOWNLOAD_FILE, SteadyflowCoreIDownloadFile))
#define STEADYFLOW_CORE_IS_IDOWNLOAD_FILE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), STEADYFLOW_CORE_TYPE_IDOWNLOAD_FILE))
#define STEADYFLOW_CORE_IDOWNLOAD_FILE_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), STEADYFLOW_CORE_TYPE_IDOWNLOAD_FILE, SteadyflowCoreIDownloadFileIface))

typedef struct _SteadyflowCoreIDownloadFile SteadyflowCoreIDownloadFile;
typedef struct _SteadyflowCoreIDownloadFileIface SteadyflowCoreIDownloadFileIface;
typedef enum  {
	STEADYFLOW_CORE_IDOWNLOAD_FILE_STATUS_CONNECTING = 0,
	STEADYFLOW_CORE_IDOWNLOAD_FILE_STATUS_DOWNLOADING,
	STEADYFLOW_CORE_IDOWNLOAD_FILE_STATUS_PAUSED,
	STEADYFLOW_CORE_IDOWNLOAD_FILE_STATUS_FINISHED,
	STEADYFLOW_CORE_IDOWNLOAD_FILE_STATUS_NETWORK_ERROR
} SteadyflowCoreIDownloadFileStatus;

#define STEADYFLOW_CORE_IDOWNLOAD_FILE_TYPE_STATUS (steadyflow_core_idownload_file_status_get_type ())
typedef enum  {
	STEADYFLOW_CORE_IDOWNLOAD_FILE_FINISH_ACTION_DO_NOTHING = 0,
	STEADYFLOW_CORE_IDOWNLOAD_FILE_FINISH_ACTION_OPEN_FILE,
	STEADYFLOW_CORE_IDOWNLOAD_FILE_FINISH_ACTION_OPEN_FOLDER,
	STEADYFLOW_CORE_IDOWNLOAD_FILE_FINISH_ACTION_RUN_COMMAND
} SteadyflowCoreIDownloadFileFinishAction;

#define STEADYFLOW_CORE_IDOWNLOAD_FILE_TYPE_FINISH_ACTION (steadyflow_core_idownload_file_finish_action_get_type ())
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
typedef struct _Block2Data Block2Data;

struct _SteadyflowUIUIUtil {
	GObject parent_instance;
	SteadyflowUIUIUtilPrivate * priv;
};

struct _SteadyflowUIUIUtilClass {
	GObjectClass parent_class;
};

struct _SteadyflowCoreIDownloadFileIface {
	GTypeInterface parent_iface;
	void (*start) (SteadyflowCoreIDownloadFile* self, gboolean resume);
	void (*pause) (SteadyflowCoreIDownloadFile* self);
	void (*serialize) (SteadyflowCoreIDownloadFile* self, GKeyFile* file);
	SteadyflowCoreIDownloadFileStatus (*get_status) (SteadyflowCoreIDownloadFile* self);
	gint (*get_uid) (SteadyflowCoreIDownloadFile* self);
	const gchar* (*get_url) (SteadyflowCoreIDownloadFile* self);
	const gchar* (*get_local_name) (SteadyflowCoreIDownloadFile* self);
	const gchar* (*get_local_basename) (SteadyflowCoreIDownloadFile* self);
	gint64 (*get_size) (SteadyflowCoreIDownloadFile* self);
	gint64 (*get_downloaded_size) (SteadyflowCoreIDownloadFile* self);
	gint (*get_speed) (SteadyflowCoreIDownloadFile* self);
	const gchar* (*get_icon_name) (SteadyflowCoreIDownloadFile* self);
	SteadyflowCoreIDownloadFileFinishAction (*get_finish_action) (SteadyflowCoreIDownloadFile* self);
	const gchar* (*get_finish_command) (SteadyflowCoreIDownloadFile* self);
	GError* (*get_error) (SteadyflowCoreIDownloadFile* self);
};

struct _Block2Data {
	int _ref_count_;
	GtkEntry* entry;
};

static gpointer steadyflow_ui_ui_util_parent_class = NULL;

VALA_EXTERN GType steadyflow_ui_ui_util_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (SteadyflowUIUIUtil, g_object_unref)
static SteadyflowUIUIUtil* steadyflow_ui_ui_util_new (void);
static SteadyflowUIUIUtil* steadyflow_ui_ui_util_construct (GType object_type);
VALA_EXTERN GType steadyflow_core_idownload_file_status_get_type (void) G_GNUC_CONST ;
VALA_EXTERN GType steadyflow_core_idownload_file_finish_action_get_type (void) G_GNUC_CONST ;
VALA_EXTERN GType steadyflow_core_idownload_file_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (SteadyflowCoreIDownloadFile, g_object_unref)
VALA_EXTERN void steadyflow_ui_ui_util_open_file (SteadyflowCoreIDownloadFile* file);
VALA_EXTERN const gchar* steadyflow_core_idownload_file_get_local_name (SteadyflowCoreIDownloadFile* self);
VALA_EXTERN void steadyflow_ui_ui_util_open_folder (SteadyflowCoreIDownloadFile* file);
VALA_EXTERN void steadyflow_ui_ui_util_install_clear_handler (GtkEntry* entry);
static Block2Data* block2_data_ref (Block2Data* _data2_);
static void block2_data_unref (void * _userdata_);
static void __lambda8_ (Block2Data* _data2_);
static void ___lambda8__gtk_editable_changed (GtkEditable* _sender,
                                       gpointer self);
static void __lambda9_ (Block2Data* _data2_,
                 GtkEntryIconPosition position,
                 GdkEvent* event);
static void ___lambda9__gtk_entry_icon_press (GtkEntry* _sender,
                                       GtkEntryIconPosition icon_pos,
                                       GdkEvent* event,
                                       gpointer self);
static GType steadyflow_ui_ui_util_get_type_once (void);

static SteadyflowUIUIUtil*
steadyflow_ui_ui_util_construct (GType object_type)
{
	SteadyflowUIUIUtil * self = NULL;
	self = (SteadyflowUIUIUtil*) g_object_new (object_type, NULL);
	return self;
}

static SteadyflowUIUIUtil*
steadyflow_ui_ui_util_new (void)
{
	return steadyflow_ui_ui_util_construct (STEADYFLOW_UI_TYPE_UI_UTIL);
}

void
steadyflow_ui_ui_util_open_file (SteadyflowCoreIDownloadFile* file)
{
	GFile* gfile = NULL;
	const gchar* _tmp0_;
	const gchar* _tmp1_;
	GFile* _tmp2_;
	GError* _inner_error0_ = NULL;
	g_return_if_fail (file != NULL);
	_tmp0_ = steadyflow_core_idownload_file_get_local_name (file);
	_tmp1_ = _tmp0_;
	_tmp2_ = g_file_new_for_path (_tmp1_);
	gfile = _tmp2_;
	{
		GdkScreen* _tmp3_;
		gchar* _tmp4_;
		gchar* _tmp5_;
		_tmp3_ = gdk_screen_get_default ();
		_tmp4_ = g_file_get_uri (gfile);
		_tmp5_ = _tmp4_;
		gtk_show_uri (_tmp3_, _tmp5_, (guint32) GDK_CURRENT_TIME, &_inner_error0_);
		_g_free0 (_tmp5_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
	}
	goto __finally0;
	__catch0_g_error:
	{
		FILE* _tmp6_;
		g_clear_error (&_inner_error0_);
		_tmp6_ = stderr;
		fprintf (_tmp6_, "Could not execute post-download action\n");
	}
	__finally0:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		_g_object_unref0 (gfile);
		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;
	}
	_g_object_unref0 (gfile);
}

void
steadyflow_ui_ui_util_open_folder (SteadyflowCoreIDownloadFile* file)
{
	GFile* gfile = NULL;
	const gchar* _tmp0_;
	const gchar* _tmp1_;
	GFile* _tmp2_;
	GError* _inner_error0_ = NULL;
	g_return_if_fail (file != NULL);
	_tmp0_ = steadyflow_core_idownload_file_get_local_name (file);
	_tmp1_ = _tmp0_;
	_tmp2_ = g_file_new_for_path (_tmp1_);
	gfile = _tmp2_;
	{
		GdkScreen* _tmp3_;
		GFile* _tmp4_;
		GFile* _tmp5_;
		gchar* _tmp6_;
		gchar* _tmp7_;
		_tmp3_ = gdk_screen_get_default ();
		_tmp4_ = g_file_get_parent (gfile);
		_tmp5_ = _tmp4_;
		_tmp6_ = g_file_get_uri (_tmp5_);
		_tmp7_ = _tmp6_;
		gtk_show_uri (_tmp3_, _tmp7_, (guint32) GDK_CURRENT_TIME, &_inner_error0_);
		_g_free0 (_tmp7_);
		_g_object_unref0 (_tmp5_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
	}
	goto __finally0;
	__catch0_g_error:
	{
		FILE* _tmp8_;
		g_clear_error (&_inner_error0_);
		_tmp8_ = stderr;
		fprintf (_tmp8_, "Could not execute post-download action\n");
	}
	__finally0:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		_g_object_unref0 (gfile);
		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;
	}
	_g_object_unref0 (gfile);
}

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

static Block2Data*
block2_data_ref (Block2Data* _data2_)
{
	g_atomic_int_inc (&_data2_->_ref_count_);
	return _data2_;
}

static void
block2_data_unref (void * _userdata_)
{
	Block2Data* _data2_;
	_data2_ = (Block2Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data2_->_ref_count_)) {
		_g_object_unref0 (_data2_->entry);
		g_slice_free (Block2Data, _data2_);
	}
}

static void
__lambda8_ (Block2Data* _data2_)
{
	const gchar* _tmp0_;
	const gchar* _tmp1_;
	_tmp0_ = gtk_entry_get_text (_data2_->entry);
	_tmp1_ = _tmp0_;
	if (g_strcmp0 (_tmp1_, "") == 0) {
		g_object_set (_data2_->entry, "secondary-icon-name", NULL, NULL);
	} else {
		GtkIconTheme* _tmp2_;
		g_object_set (_data2_->entry, "secondary-icon-activatable", TRUE, NULL);
		g_object_set (_data2_->entry, "secondary-icon-tooltip-text", _ ("Clear"), NULL);
		_tmp2_ = gtk_icon_theme_get_default ();
		if (gtk_icon_theme_has_icon (_tmp2_, "edit-clear-symbolic")) {
			g_object_set (_data2_->entry, "secondary-icon-name", "edit-clear-symbolic", NULL);
		} else {
			g_object_set (_data2_->entry, "secondary-icon-stock", GTK_STOCK_CLEAR, NULL);
		}
	}
}

static void
___lambda8__gtk_editable_changed (GtkEditable* _sender,
                                  gpointer self)
{
	__lambda8_ (self);
}

static void
__lambda9_ (Block2Data* _data2_,
            GtkEntryIconPosition position,
            GdkEvent* event)
{
	g_return_if_fail (event != NULL);
	if (position == GTK_ENTRY_ICON_SECONDARY) {
		gtk_entry_set_text (_data2_->entry, "");
	}
}

static void
___lambda9__gtk_entry_icon_press (GtkEntry* _sender,
                                  GtkEntryIconPosition icon_pos,
                                  GdkEvent* event,
                                  gpointer self)
{
	__lambda9_ (self, icon_pos, event);
}

void
steadyflow_ui_ui_util_install_clear_handler (GtkEntry* entry)
{
	Block2Data* _data2_;
	GtkEntry* _tmp0_;
	g_return_if_fail (entry != NULL);
	_data2_ = g_slice_new0 (Block2Data);
	_data2_->_ref_count_ = 1;
	_tmp0_ = _g_object_ref0 (entry);
	_g_object_unref0 (_data2_->entry);
	_data2_->entry = _tmp0_;
	g_signal_connect_data ((GtkEditable*) _data2_->entry, "changed", (GCallback) ___lambda8__gtk_editable_changed, block2_data_ref (_data2_), (GClosureNotify) block2_data_unref, 0);
	g_signal_connect_data (_data2_->entry, "icon-press", (GCallback) ___lambda9__gtk_entry_icon_press, block2_data_ref (_data2_), (GClosureNotify) block2_data_unref, 0);
	block2_data_unref (_data2_);
	_data2_ = NULL;
}

static void
steadyflow_ui_ui_util_class_init (SteadyflowUIUIUtilClass * klass,
                                  gpointer klass_data)
{
	steadyflow_ui_ui_util_parent_class = g_type_class_peek_parent (klass);
}

static void
steadyflow_ui_ui_util_instance_init (SteadyflowUIUIUtil * self,
                                     gpointer klass)
{
}

static GType
steadyflow_ui_ui_util_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (SteadyflowUIUIUtilClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) steadyflow_ui_ui_util_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (SteadyflowUIUIUtil), 0, (GInstanceInitFunc) steadyflow_ui_ui_util_instance_init, NULL };
	GType steadyflow_ui_ui_util_type_id;
	steadyflow_ui_ui_util_type_id = g_type_register_static (G_TYPE_OBJECT, "SteadyflowUIUIUtil", &g_define_type_info, 0);
	return steadyflow_ui_ui_util_type_id;
}

GType
steadyflow_ui_ui_util_get_type (void)
{
	static volatile gsize steadyflow_ui_ui_util_type_id__once = 0;
	if (g_once_init_enter (&steadyflow_ui_ui_util_type_id__once)) {
		GType steadyflow_ui_ui_util_type_id;
		steadyflow_ui_ui_util_type_id = steadyflow_ui_ui_util_get_type_once ();
		g_once_init_leave (&steadyflow_ui_ui_util_type_id__once, steadyflow_ui_ui_util_type_id);
	}
	return steadyflow_ui_ui_util_type_id__once;
}

