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

/*
    AddFileDialog.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 <gtk/gtk.h>
#include <glib-object.h>
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <glib/gi18n-lib.h>
#include <gdk/gdk.h>
#include <gio/gio.h>
#include <cairo-gobject.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 STEADYFLOW_UI_TYPE_IGTK_BUILDER_CONTAINER (steadyflow_ui_igtk_builder_container_get_type ())
#define STEADYFLOW_UI_IGTK_BUILDER_CONTAINER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), STEADYFLOW_UI_TYPE_IGTK_BUILDER_CONTAINER, SteadyflowUIIGtkBuilderContainer))
#define STEADYFLOW_UI_IS_IGTK_BUILDER_CONTAINER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), STEADYFLOW_UI_TYPE_IGTK_BUILDER_CONTAINER))
#define STEADYFLOW_UI_IGTK_BUILDER_CONTAINER_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), STEADYFLOW_UI_TYPE_IGTK_BUILDER_CONTAINER, SteadyflowUIIGtkBuilderContainerIface))

typedef struct _SteadyflowUIIGtkBuilderContainer SteadyflowUIIGtkBuilderContainer;
typedef struct _SteadyflowUIIGtkBuilderContainerIface SteadyflowUIIGtkBuilderContainerIface;

#define STEADYFLOW_UI_TYPE_GTK_BUILDER_DIALOG (steadyflow_ui_gtk_builder_dialog_get_type ())
#define STEADYFLOW_UI_GTK_BUILDER_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), STEADYFLOW_UI_TYPE_GTK_BUILDER_DIALOG, SteadyflowUIGtkBuilderDialog))
#define STEADYFLOW_UI_GTK_BUILDER_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), STEADYFLOW_UI_TYPE_GTK_BUILDER_DIALOG, SteadyflowUIGtkBuilderDialogClass))
#define STEADYFLOW_UI_IS_GTK_BUILDER_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), STEADYFLOW_UI_TYPE_GTK_BUILDER_DIALOG))
#define STEADYFLOW_UI_IS_GTK_BUILDER_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), STEADYFLOW_UI_TYPE_GTK_BUILDER_DIALOG))
#define STEADYFLOW_UI_GTK_BUILDER_DIALOG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), STEADYFLOW_UI_TYPE_GTK_BUILDER_DIALOG, SteadyflowUIGtkBuilderDialogClass))

typedef struct _SteadyflowUIGtkBuilderDialog SteadyflowUIGtkBuilderDialog;
typedef struct _SteadyflowUIGtkBuilderDialogClass SteadyflowUIGtkBuilderDialogClass;
typedef struct _SteadyflowUIGtkBuilderDialogPrivate SteadyflowUIGtkBuilderDialogPrivate;

#define STEADYFLOW_TYPE_ADD_FILE_DIALOG (steadyflow_add_file_dialog_get_type ())
#define STEADYFLOW_ADD_FILE_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), STEADYFLOW_TYPE_ADD_FILE_DIALOG, SteadyflowAddFileDialog))
#define STEADYFLOW_ADD_FILE_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), STEADYFLOW_TYPE_ADD_FILE_DIALOG, SteadyflowAddFileDialogClass))
#define STEADYFLOW_IS_ADD_FILE_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), STEADYFLOW_TYPE_ADD_FILE_DIALOG))
#define STEADYFLOW_IS_ADD_FILE_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), STEADYFLOW_TYPE_ADD_FILE_DIALOG))
#define STEADYFLOW_ADD_FILE_DIALOG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), STEADYFLOW_TYPE_ADD_FILE_DIALOG, SteadyflowAddFileDialogClass))

typedef struct _SteadyflowAddFileDialog SteadyflowAddFileDialog;
typedef struct _SteadyflowAddFileDialogClass SteadyflowAddFileDialogClass;
typedef struct _SteadyflowAddFileDialogPrivate SteadyflowAddFileDialogPrivate;
enum  {
	STEADYFLOW_ADD_FILE_DIALOG_0_PROPERTY,
	STEADYFLOW_ADD_FILE_DIALOG_NUM_PROPERTIES
};
static GParamSpec* steadyflow_add_file_dialog_properties[STEADYFLOW_ADD_FILE_DIALOG_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))

#define STEADYFLOW_CORE_TYPE_ISETTINGS_SERVICE (steadyflow_core_isettings_service_get_type ())
#define STEADYFLOW_CORE_ISETTINGS_SERVICE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), STEADYFLOW_CORE_TYPE_ISETTINGS_SERVICE, SteadyflowCoreISettingsService))
#define STEADYFLOW_CORE_IS_ISETTINGS_SERVICE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), STEADYFLOW_CORE_TYPE_ISETTINGS_SERVICE))
#define STEADYFLOW_CORE_ISETTINGS_SERVICE_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), STEADYFLOW_CORE_TYPE_ISETTINGS_SERVICE, SteadyflowCoreISettingsServiceIface))

typedef struct _SteadyflowCoreISettingsService SteadyflowCoreISettingsService;
typedef struct _SteadyflowCoreISettingsServiceIface SteadyflowCoreISettingsServiceIface;
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 ())
enum  {
	STEADYFLOW_ADD_FILE_DIALOG_FILE_ADD_REQUEST_SIGNAL,
	STEADYFLOW_ADD_FILE_DIALOG_NUM_SIGNALS
};
static guint steadyflow_add_file_dialog_signals[STEADYFLOW_ADD_FILE_DIALOG_NUM_SIGNALS] = {0};

struct _SteadyflowUIIGtkBuilderContainerIface {
	GTypeInterface parent_iface;
	GtkBuilder* (*get_builder) (SteadyflowUIIGtkBuilderContainer* self);
};

struct _SteadyflowUIGtkBuilderDialog {
	GtkDialog parent_instance;
	SteadyflowUIGtkBuilderDialogPrivate * priv;
};

struct _SteadyflowUIGtkBuilderDialogClass {
	GtkDialogClass parent_class;
};

struct _SteadyflowAddFileDialog {
	SteadyflowUIGtkBuilderDialog parent_instance;
	SteadyflowAddFileDialogPrivate * priv;
};

struct _SteadyflowAddFileDialogClass {
	SteadyflowUIGtkBuilderDialogClass parent_class;
};

struct _SteadyflowAddFileDialogPrivate {
	GtkWidget* custom_command_area;
	GtkEntry* url_entry;
	GtkEntry* local_name;
	GtkEntry* custom_command;
	GtkCheckButton* append_filename;
	GtkFileChooserButton* save_to;
	GtkComboBox* finished_action;
};

struct _SteadyflowCoreISettingsServiceIface {
	GTypeInterface parent_iface;
	gboolean (*get_boolean) (SteadyflowCoreISettingsService* self, const gchar* key);
	gint (*get_int) (SteadyflowCoreISettingsService* self, const gchar* key);
	gint (*get_enum) (SteadyflowCoreISettingsService* self, const gchar* key);
	gchar* (*get_string) (SteadyflowCoreISettingsService* self, const gchar* key);
	void (*set_boolean) (SteadyflowCoreISettingsService* self, const gchar* key, gboolean value);
	void (*set_int) (SteadyflowCoreISettingsService* self, const gchar* key, gint value);
	void (*set_enum) (SteadyflowCoreISettingsService* self, const gchar* key, gint value);
	void (*set_string) (SteadyflowCoreISettingsService* self, const gchar* key, const gchar* value);
	void (*save) (SteadyflowCoreISettingsService* self);
};

static gint SteadyflowAddFileDialog_private_offset;
static gpointer steadyflow_add_file_dialog_parent_class = NULL;

VALA_EXTERN GType steadyflow_ui_igtk_builder_container_get_type (void) G_GNUC_CONST ;
VALA_EXTERN GType steadyflow_ui_gtk_builder_dialog_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (SteadyflowUIGtkBuilderDialog, g_object_unref)
VALA_EXTERN GType steadyflow_add_file_dialog_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (SteadyflowAddFileDialog, g_object_unref)
VALA_EXTERN SteadyflowAddFileDialog* steadyflow_add_file_dialog_new (const gchar* url);
VALA_EXTERN SteadyflowAddFileDialog* steadyflow_add_file_dialog_construct (GType object_type,
                                                               const gchar* url);
VALA_EXTERN SteadyflowUIGtkBuilderDialog* steadyflow_ui_gtk_builder_dialog_construct (GType object_type,
                                                                          const gchar* file_id,
                                                                          GtkWindow* parent,
                                                                          gboolean modal);
VALA_EXTERN GObject* steadyflow_ui_igtk_builder_container_get_object (SteadyflowUIIGtkBuilderContainer* self,
                                                          const gchar* id);
VALA_EXTERN gchar* steadyflow_services_get_default_download_folder (void);
VALA_EXTERN GType steadyflow_core_isettings_service_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (SteadyflowCoreISettingsService, g_object_unref)
VALA_EXTERN SteadyflowCoreISettingsService* steadyflow_services_get_settings (void);
VALA_EXTERN gint steadyflow_core_isettings_service_get_enum (SteadyflowCoreISettingsService* self,
                                                 const gchar* key);
VALA_EXTERN void steadyflow_ui_ui_util_install_clear_handler (GtkEntry* entry);
static void steadyflow_add_file_dialog_on_dialog_response (SteadyflowAddFileDialog* self,
                                                    gint response_id);
static void _steadyflow_add_file_dialog_on_dialog_response_gtk_dialog_response (GtkDialog* _sender,
                                                                         gint response_id,
                                                                         gpointer self);
VALA_EXTERN void steadyflow_ui_igtk_builder_container_autoconnect (SteadyflowUIIGtkBuilderContainer* self);
static void ___lambda11_ (SteadyflowAddFileDialog* self,
                   GtkClipboard* clipboard,
                   const gchar* cbtext);
VALA_EXTERN gboolean steadyflow_core_util_is_valid_url (const gchar* url);
static void ____lambda11__gtk_clipboard_text_received_func (GtkClipboard* clipboard,
                                                     const gchar* text,
                                                     gpointer self);
VALA_EXTERN gchar* steadyflow_add_file_dialog_get_url (SteadyflowAddFileDialog* self);
VALA_EXTERN gchar* steadyflow_add_file_dialog_get_local_name (SteadyflowAddFileDialog* self);
VALA_EXTERN gchar* steadyflow_add_file_dialog_get_save_path (SteadyflowAddFileDialog* self);
VALA_EXTERN GType steadyflow_core_idownload_file_finish_action_get_type (void) G_GNUC_CONST ;
VALA_EXTERN SteadyflowCoreIDownloadFileFinishAction steadyflow_add_file_dialog_get_finish_action (SteadyflowAddFileDialog* self);
VALA_EXTERN gchar* steadyflow_add_file_dialog_get_finish_command (SteadyflowAddFileDialog* self);
VALA_EXTERN void steadyflow_add_file_dialog_on_url_changed (GtkEntry* sender,
                                                SteadyflowAddFileDialog* self);
VALA_EXTERN void steadyflow_add_file_dialog_on_finished_action_changed (GtkComboBox* sender,
                                                            SteadyflowAddFileDialog* self);
static void steadyflow_add_file_dialog_finalize (GObject * obj);
static GType steadyflow_add_file_dialog_get_type_once (void);

static inline gpointer
steadyflow_add_file_dialog_get_instance_private (SteadyflowAddFileDialog* self)
{
	return G_STRUCT_MEMBER_P (self, SteadyflowAddFileDialog_private_offset);
}

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

static void
_steadyflow_add_file_dialog_on_dialog_response_gtk_dialog_response (GtkDialog* _sender,
                                                                    gint response_id,
                                                                    gpointer self)
{
	steadyflow_add_file_dialog_on_dialog_response ((SteadyflowAddFileDialog*) self, response_id);
}

static gchar*
string_strip (const gchar* self)
{
	gchar* _result_ = NULL;
	gchar* _tmp0_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = g_strdup (self);
	_result_ = _tmp0_;
	g_strstrip (_result_);
	result = _result_;
	return result;
}

static void
___lambda11_ (SteadyflowAddFileDialog* self,
              GtkClipboard* clipboard,
              const gchar* cbtext)
{
	gchar* text = NULL;
	gchar* _tmp0_;
	const gchar* _tmp1_;
	g_return_if_fail (clipboard != NULL);
	_tmp0_ = string_strip (cbtext);
	text = _tmp0_;
	_tmp1_ = text;
	if (steadyflow_core_util_is_valid_url (_tmp1_)) {
		GtkEntry* _tmp2_;
		const gchar* _tmp3_;
		_tmp2_ = self->priv->url_entry;
		_tmp3_ = text;
		gtk_entry_set_text (_tmp2_, _tmp3_);
	}
	_g_free0 (text);
}

static void
____lambda11__gtk_clipboard_text_received_func (GtkClipboard* clipboard,
                                                const gchar* text,
                                                gpointer self)
{
	___lambda11_ ((SteadyflowAddFileDialog*) self, clipboard, text);
	g_object_unref (self);
}

SteadyflowAddFileDialog*
steadyflow_add_file_dialog_construct (GType object_type,
                                      const gchar* url)
{
	SteadyflowAddFileDialog * self = NULL;
	GtkBox* vbox = NULL;
	GtkBox* _tmp0_;
	GtkBox* _tmp1_;
	GtkBox* _tmp2_;
	GtkBox* _tmp3_;
	GObject* _tmp4_;
	GObject* _tmp5_;
	GObject* _tmp6_;
	GtkFileChooserButton* _tmp7_;
	gchar* _tmp8_;
	gchar* _tmp9_;
	GObject* _tmp10_;
	GtkCellRendererText* renderer = NULL;
	GtkCellRendererText* _tmp11_;
	GtkComboBox* _tmp12_;
	GtkCellRendererText* _tmp13_;
	GtkComboBox* _tmp14_;
	GtkCellRendererText* _tmp15_;
	GtkComboBox* _tmp16_;
	SteadyflowCoreISettingsService* _tmp17_;
	SteadyflowCoreISettingsService* _tmp18_;
	GObject* _tmp19_;
	GObject* _tmp20_;
	GObject* _tmp21_;
	GtkEntry* _tmp22_;
	GtkEntry* _tmp23_;
	GtkEntry* _tmp24_;
	g_return_val_if_fail (url != NULL, NULL);
	self = (SteadyflowAddFileDialog*) steadyflow_ui_gtk_builder_dialog_construct (object_type, "AddFileDialog", NULL, FALSE);
	gtk_window_set_title ((GtkWindow*) self, _ ("Add File for Download"));
	gtk_window_set_resizable ((GtkWindow*) self, TRUE);
	gtk_container_set_border_width ((GtkContainer*) self, (guint) 5);
	_tmp0_ = gtk_dialog_get_content_area ((GtkDialog*) self);
	_tmp1_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_tmp0_, gtk_box_get_type (), GtkBox));
	vbox = _tmp1_;
	_tmp2_ = vbox;
	gtk_container_set_border_width ((GtkContainer*) _tmp2_, (guint) 5);
	_tmp3_ = vbox;
	gtk_box_set_spacing (_tmp3_, 8);
	_tmp4_ = steadyflow_ui_igtk_builder_container_get_object ((SteadyflowUIIGtkBuilderContainer*) self, "url_entry");
	_g_object_unref0 (self->priv->url_entry);
	self->priv->url_entry = G_TYPE_CHECK_INSTANCE_CAST (_tmp4_, gtk_entry_get_type (), GtkEntry);
	_tmp5_ = steadyflow_ui_igtk_builder_container_get_object ((SteadyflowUIIGtkBuilderContainer*) self, "local_name");
	_g_object_unref0 (self->priv->local_name);
	self->priv->local_name = G_TYPE_CHECK_INSTANCE_CAST (_tmp5_, gtk_entry_get_type (), GtkEntry);
	_tmp6_ = steadyflow_ui_igtk_builder_container_get_object ((SteadyflowUIIGtkBuilderContainer*) self, "save_to");
	_g_object_unref0 (self->priv->save_to);
	self->priv->save_to = G_TYPE_CHECK_INSTANCE_CAST (_tmp6_, gtk_file_chooser_button_get_type (), GtkFileChooserButton);
	_tmp7_ = self->priv->save_to;
	_tmp8_ = steadyflow_services_get_default_download_folder ();
	_tmp9_ = _tmp8_;
	gtk_file_chooser_set_current_folder ((GtkFileChooser*) _tmp7_, _tmp9_);
	_g_free0 (_tmp9_);
	_tmp10_ = steadyflow_ui_igtk_builder_container_get_object ((SteadyflowUIIGtkBuilderContainer*) self, "finished_action");
	_g_object_unref0 (self->priv->finished_action);
	self->priv->finished_action = G_TYPE_CHECK_INSTANCE_CAST (_tmp10_, gtk_combo_box_get_type (), GtkComboBox);
	_tmp11_ = (GtkCellRendererText*) gtk_cell_renderer_text_new ();
	g_object_ref_sink (_tmp11_);
	renderer = _tmp11_;
	_tmp12_ = self->priv->finished_action;
	_tmp13_ = renderer;
	gtk_cell_layout_pack_start ((GtkCellLayout*) _tmp12_, (GtkCellRenderer*) _tmp13_, TRUE);
	_tmp14_ = self->priv->finished_action;
	_tmp15_ = renderer;
	gtk_cell_layout_add_attribute ((GtkCellLayout*) _tmp14_, (GtkCellRenderer*) _tmp15_, "text", 0);
	_tmp16_ = self->priv->finished_action;
	_tmp17_ = steadyflow_services_get_settings ();
	_tmp18_ = _tmp17_;
	gtk_combo_box_set_active (_tmp16_, steadyflow_core_isettings_service_get_enum (_tmp18_, "default-post-download-action"));
	_tmp19_ = steadyflow_ui_igtk_builder_container_get_object ((SteadyflowUIIGtkBuilderContainer*) self, "custom_command_area");
	_g_object_unref0 (self->priv->custom_command_area);
	self->priv->custom_command_area = G_TYPE_CHECK_INSTANCE_CAST (_tmp19_, gtk_widget_get_type (), GtkWidget);
	_tmp20_ = steadyflow_ui_igtk_builder_container_get_object ((SteadyflowUIIGtkBuilderContainer*) self, "custom_command");
	_g_object_unref0 (self->priv->custom_command);
	self->priv->custom_command = G_TYPE_CHECK_INSTANCE_CAST (_tmp20_, gtk_entry_get_type (), GtkEntry);
	_tmp21_ = steadyflow_ui_igtk_builder_container_get_object ((SteadyflowUIIGtkBuilderContainer*) self, "append_filename");
	_g_object_unref0 (self->priv->append_filename);
	self->priv->append_filename = G_TYPE_CHECK_INSTANCE_CAST (_tmp21_, gtk_check_button_get_type (), GtkCheckButton);
	_tmp22_ = self->priv->url_entry;
	steadyflow_ui_ui_util_install_clear_handler (_tmp22_);
	_tmp23_ = self->priv->local_name;
	steadyflow_ui_ui_util_install_clear_handler (_tmp23_);
	g_signal_connect_object ((GtkDialog*) self, "response", (GCallback) _steadyflow_add_file_dialog_on_dialog_response_gtk_dialog_response, self, 0);
	gtk_dialog_add_button ((GtkDialog*) self, GTK_STOCK_CANCEL, (gint) GTK_RESPONSE_CANCEL);
	gtk_dialog_add_button ((GtkDialog*) self, GTK_STOCK_ADD, (gint) GTK_RESPONSE_OK);
	gtk_dialog_set_default_response ((GtkDialog*) self, (gint) GTK_RESPONSE_OK);
	steadyflow_ui_igtk_builder_container_autoconnect ((SteadyflowUIIGtkBuilderContainer*) self);
	_tmp24_ = self->priv->url_entry;
	gtk_entry_set_text (_tmp24_, url);
	if (g_strcmp0 (url, "") == 0) {
		GtkClipboard* _tmp25_;
		_tmp25_ = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
		gtk_clipboard_request_text (_tmp25_, ____lambda11__gtk_clipboard_text_received_func, g_object_ref (self));
	}
	_g_object_unref0 (renderer);
	_g_object_unref0 (vbox);
	return self;
}

SteadyflowAddFileDialog*
steadyflow_add_file_dialog_new (const gchar* url)
{
	return steadyflow_add_file_dialog_construct (STEADYFLOW_TYPE_ADD_FILE_DIALOG, url);
}

gchar*
steadyflow_add_file_dialog_get_url (SteadyflowAddFileDialog* self)
{
	GtkEntry* _tmp0_;
	const gchar* _tmp1_;
	const gchar* _tmp2_;
	gchar* _tmp3_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->url_entry;
	_tmp1_ = gtk_entry_get_text (_tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = g_strdup (_tmp2_);
	result = _tmp3_;
	return result;
}

gchar*
steadyflow_add_file_dialog_get_local_name (SteadyflowAddFileDialog* self)
{
	GtkEntry* _tmp0_;
	const gchar* _tmp1_;
	const gchar* _tmp2_;
	gchar* _tmp3_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->local_name;
	_tmp1_ = gtk_entry_get_text (_tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = g_strdup (_tmp2_);
	result = _tmp3_;
	return result;
}

gchar*
steadyflow_add_file_dialog_get_save_path (SteadyflowAddFileDialog* self)
{
	GtkEntry* _tmp0_;
	const gchar* _tmp1_;
	const gchar* _tmp2_;
	GError* _inner_error0_ = NULL;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->local_name;
	_tmp1_ = gtk_entry_get_text (_tmp0_);
	_tmp2_ = _tmp1_;
	if (g_strcmp0 (_tmp2_, "") == 0) {
		result = NULL;
		return result;
	}
	{
		GFile* _tmp3_ = NULL;
		GtkFileChooserButton* _tmp4_;
		GFile* _tmp5_;
		GFile* _tmp6_;
		GtkEntry* _tmp7_;
		const gchar* _tmp8_;
		const gchar* _tmp9_;
		GFile* _tmp10_;
		GFile* _tmp11_;
		gchar* _tmp12_;
		_tmp4_ = self->priv->save_to;
		_tmp5_ = gtk_file_chooser_get_current_folder_file ((GtkFileChooser*) _tmp4_);
		_tmp6_ = _tmp5_;
		_tmp7_ = self->priv->local_name;
		_tmp8_ = gtk_entry_get_text (_tmp7_);
		_tmp9_ = _tmp8_;
		_tmp10_ = g_file_get_child_for_display_name (_tmp6_, _tmp9_, &_inner_error0_);
		_tmp11_ = _tmp10_;
		_g_object_unref0 (_tmp6_);
		_tmp3_ = _tmp11_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
		_tmp12_ = g_file_get_path (_tmp3_);
		result = _tmp12_;
		_g_object_unref0 (_tmp3_);
		return result;
	}
	goto __finally0;
	__catch0_g_error:
	{
		g_clear_error (&_inner_error0_);
		result = NULL;
		return result;
	}
	__finally0:
	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 NULL;
}

SteadyflowCoreIDownloadFileFinishAction
steadyflow_add_file_dialog_get_finish_action (SteadyflowAddFileDialog* self)
{
	GtkComboBox* _tmp0_;
	gint _tmp1_;
	gint _tmp2_;
	SteadyflowCoreIDownloadFileFinishAction result;
	g_return_val_if_fail (self != NULL, 0);
	_tmp0_ = self->priv->finished_action;
	_tmp1_ = gtk_combo_box_get_active (_tmp0_);
	_tmp2_ = _tmp1_;
	result = (SteadyflowCoreIDownloadFileFinishAction) _tmp2_;
	return result;
}

gchar*
steadyflow_add_file_dialog_get_finish_command (SteadyflowAddFileDialog* self)
{
	gchar* command = NULL;
	GtkEntry* _tmp0_;
	const gchar* _tmp1_;
	const gchar* _tmp2_;
	gchar* _tmp3_;
	const gchar* _tmp4_;
	GtkCheckButton* _tmp5_;
	gboolean _tmp6_;
	gboolean _tmp7_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	if (steadyflow_add_file_dialog_get_finish_action (self) != STEADYFLOW_CORE_IDOWNLOAD_FILE_FINISH_ACTION_RUN_COMMAND) {
		result = NULL;
		return result;
	}
	_tmp0_ = self->priv->custom_command;
	_tmp1_ = gtk_entry_get_text (_tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = string_strip (_tmp2_);
	command = _tmp3_;
	_tmp4_ = command;
	if (g_strcmp0 (_tmp4_, "") == 0) {
		result = NULL;
		_g_free0 (command);
		return result;
	}
	_tmp5_ = self->priv->append_filename;
	_tmp6_ = gtk_toggle_button_get_active ((GtkToggleButton*) _tmp5_);
	_tmp7_ = _tmp6_;
	if (_tmp7_) {
		gchar* save_path = NULL;
		gchar* _tmp8_;
		const gchar* _tmp9_;
		_tmp8_ = steadyflow_add_file_dialog_get_save_path (self);
		save_path = _tmp8_;
		_tmp9_ = save_path;
		if (_tmp9_ != NULL) {
			const gchar* _tmp10_;
			const gchar* _tmp11_;
			gchar* _tmp12_;
			gchar* _tmp13_;
			gchar* _tmp14_;
			gchar* _tmp15_;
			gchar* _tmp16_;
			_tmp10_ = command;
			_tmp11_ = save_path;
			_tmp12_ = g_shell_quote (_tmp11_);
			_tmp13_ = _tmp12_;
			_tmp14_ = g_strconcat (" ", _tmp13_, NULL);
			_tmp15_ = _tmp14_;
			_tmp16_ = g_strconcat (_tmp10_, _tmp15_, NULL);
			_g_free0 (command);
			command = _tmp16_;
			_g_free0 (_tmp15_);
			_g_free0 (_tmp13_);
		}
		_g_free0 (save_path);
	}
	result = command;
	return result;
}

void
steadyflow_add_file_dialog_on_url_changed (GtkEntry* sender,
                                           SteadyflowAddFileDialog* self)
{
	gchar* text = NULL;
	const gchar* _tmp0_;
	const gchar* _tmp1_;
	gchar* _tmp2_;
	const gchar* _tmp3_;
	const gchar* _tmp4_;
	const gchar* _tmp5_;
	GFile* file = NULL;
	const gchar* _tmp7_;
	GFile* _tmp8_;
	gchar* basename = NULL;
	GFile* _tmp9_;
	gchar* _tmp10_;
	const gchar* _tmp11_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (sender != NULL);
	_tmp0_ = gtk_entry_get_text (sender);
	_tmp1_ = _tmp0_;
	_tmp2_ = string_strip (_tmp1_);
	text = _tmp2_;
	_tmp3_ = gtk_entry_get_text (sender);
	_tmp4_ = _tmp3_;
	_tmp5_ = text;
	if (g_strcmp0 (_tmp4_, _tmp5_) != 0) {
		const gchar* _tmp6_;
		_tmp6_ = text;
		gtk_entry_set_text (sender, _tmp6_);
	}
	_tmp7_ = text;
	_tmp8_ = g_file_new_for_uri (_tmp7_);
	file = _tmp8_;
	_tmp9_ = file;
	_tmp10_ = g_file_get_basename (_tmp9_);
	basename = _tmp10_;
	_tmp11_ = basename;
	if (_tmp11_ != NULL) {
		GtkEntry* _tmp12_;
		const gchar* _tmp13_;
		_tmp12_ = self->priv->local_name;
		_tmp13_ = basename;
		gtk_entry_set_text (_tmp12_, _tmp13_);
	}
	_g_free0 (basename);
	_g_object_unref0 (file);
	_g_free0 (text);
}

void
steadyflow_add_file_dialog_on_finished_action_changed (GtkComboBox* sender,
                                                       SteadyflowAddFileDialog* self)
{
	g_return_if_fail (self != NULL);
	g_return_if_fail (sender != NULL);
	if (steadyflow_add_file_dialog_get_finish_action (self) == STEADYFLOW_CORE_IDOWNLOAD_FILE_FINISH_ACTION_RUN_COMMAND) {
		GtkWidget* _tmp0_;
		_tmp0_ = self->priv->custom_command_area;
		gtk_widget_show (_tmp0_);
	} else {
		GtkWidget* _tmp1_;
		gboolean _tmp2_;
		gboolean _tmp3_;
		_tmp1_ = self->priv->custom_command_area;
		_tmp2_ = gtk_widget_get_visible (_tmp1_);
		_tmp3_ = _tmp2_;
		if (_tmp3_) {
			GtkAllocation alloc = {0};
			GtkWidget* _tmp4_;
			GtkAllocation _tmp5_ = {0};
			gint height = 0;
			GtkAllocation _tmp6_;
			GtkWidget* _tmp7_;
			GtkAllocation _tmp8_ = {0};
			GtkAllocation _tmp9_;
			GtkAllocation _tmp10_;
			_tmp4_ = self->priv->custom_command_area;
			gtk_widget_get_allocation (_tmp4_, &_tmp5_);
			alloc = _tmp5_;
			_tmp6_ = alloc;
			height = _tmp6_.height;
			_tmp7_ = self->priv->custom_command_area;
			gtk_widget_hide (_tmp7_);
			gtk_widget_get_allocation ((GtkWidget*) self, &_tmp8_);
			alloc = _tmp8_;
			_tmp9_ = alloc;
			_tmp10_ = alloc;
			gtk_window_resize ((GtkWindow*) self, _tmp9_.width, (_tmp10_.height - height) - 6);
		}
	}
}

static void
steadyflow_add_file_dialog_on_dialog_response (SteadyflowAddFileDialog* self,
                                               gint response_id)
{
	g_return_if_fail (self != NULL);
	if (response_id == ((gint) GTK_RESPONSE_OK)) {
		g_signal_emit (self, steadyflow_add_file_dialog_signals[STEADYFLOW_ADD_FILE_DIALOG_FILE_ADD_REQUEST_SIGNAL], 0);
	} else {
		gtk_widget_destroy ((GtkWidget*) self);
	}
}

static void
steadyflow_add_file_dialog_class_init (SteadyflowAddFileDialogClass * klass,
                                       gpointer klass_data)
{
	steadyflow_add_file_dialog_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &SteadyflowAddFileDialog_private_offset);
	G_OBJECT_CLASS (klass)->finalize = steadyflow_add_file_dialog_finalize;
	steadyflow_add_file_dialog_signals[STEADYFLOW_ADD_FILE_DIALOG_FILE_ADD_REQUEST_SIGNAL] = g_signal_new ("file-add-request", STEADYFLOW_TYPE_ADD_FILE_DIALOG, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
}

static void
steadyflow_add_file_dialog_instance_init (SteadyflowAddFileDialog * self,
                                          gpointer klass)
{
	self->priv = steadyflow_add_file_dialog_get_instance_private (self);
}

static void
steadyflow_add_file_dialog_finalize (GObject * obj)
{
	SteadyflowAddFileDialog * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, STEADYFLOW_TYPE_ADD_FILE_DIALOG, SteadyflowAddFileDialog);
	_g_object_unref0 (self->priv->custom_command_area);
	_g_object_unref0 (self->priv->url_entry);
	_g_object_unref0 (self->priv->local_name);
	_g_object_unref0 (self->priv->custom_command);
	_g_object_unref0 (self->priv->append_filename);
	_g_object_unref0 (self->priv->save_to);
	_g_object_unref0 (self->priv->finished_action);
	G_OBJECT_CLASS (steadyflow_add_file_dialog_parent_class)->finalize (obj);
}

static GType
steadyflow_add_file_dialog_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (SteadyflowAddFileDialogClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) steadyflow_add_file_dialog_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (SteadyflowAddFileDialog), 0, (GInstanceInitFunc) steadyflow_add_file_dialog_instance_init, NULL };
	GType steadyflow_add_file_dialog_type_id;
	steadyflow_add_file_dialog_type_id = g_type_register_static (STEADYFLOW_UI_TYPE_GTK_BUILDER_DIALOG, "SteadyflowAddFileDialog", &g_define_type_info, 0);
	SteadyflowAddFileDialog_private_offset = g_type_add_instance_private (steadyflow_add_file_dialog_type_id, sizeof (SteadyflowAddFileDialogPrivate));
	return steadyflow_add_file_dialog_type_id;
}

GType
steadyflow_add_file_dialog_get_type (void)
{
	static volatile gsize steadyflow_add_file_dialog_type_id__once = 0;
	if (g_once_init_enter (&steadyflow_add_file_dialog_type_id__once)) {
		GType steadyflow_add_file_dialog_type_id;
		steadyflow_add_file_dialog_type_id = steadyflow_add_file_dialog_get_type_once ();
		g_once_init_leave (&steadyflow_add_file_dialog_type_id__once, steadyflow_add_file_dialog_type_id);
	}
	return steadyflow_add_file_dialog_type_id__once;
}

