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

/*
* Copyright (c) 2011-2013 Yorba Foundation
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 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 "io.elementary.photos.h"
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <gio/gio.h>
#include <gee.h>
#include <glib-object.h>
#include <gtk/gtk.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

enum  {
	LIBRARY_TRASH_SIDEBAR_ENTRY_0_PROPERTY,
	LIBRARY_TRASH_SIDEBAR_ENTRY_NUM_PROPERTIES
};
static GParamSpec* library_trash_sidebar_entry_properties[LIBRARY_TRASH_SIDEBAR_ENTRY_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _media_collection_registry_unref0(var) ((var == NULL) ? NULL : (var = (media_collection_registry_unref (var), NULL)))
#define _data_collection_unref0(var) ((var == NULL) ? NULL : (var = (data_collection_unref (var), NULL)))
#define _command_manager_unref0(var) ((var == NULL) ? NULL : (var = (command_manager_unref (var), NULL)))

static gpointer library_trash_sidebar_entry_parent_class = NULL;
static GIcon* library_trash_sidebar_entry_full_icon;
static GIcon* library_trash_sidebar_entry_full_icon = NULL;
static GIcon* library_trash_sidebar_entry_empty_icon;
static GIcon* library_trash_sidebar_entry_empty_icon = NULL;
static SidebarInternalDropTargetEntryIface * library_trash_sidebar_entry_sidebar_internal_drop_target_entry_parent_iface = NULL;

static void library_trash_sidebar_entry_on_trashcan_contents_altered (LibraryTrashSidebarEntry* self);
static void _library_trash_sidebar_entry_on_trashcan_contents_altered_media_source_collection_trashcan_contents_altered (MediaSourceCollection* _sender,
                                                                                                                  GeeCollection* added,
                                                                                                                  GeeCollection* removed,
                                                                                                                  gpointer self);
VALA_EXTERN void library_trash_sidebar_entry_init (void);
VALA_EXTERN void library_trash_sidebar_entry_terminate (void);
static gchar* library_trash_sidebar_entry_real_get_sidebar_name (SidebarSimplePageEntry* base);
static GIcon* library_trash_sidebar_entry_real_get_sidebar_icon (SidebarSimplePageEntry* base);
static GIcon* library_trash_sidebar_entry_get_current_icon (void);
static gboolean library_trash_sidebar_entry_real_internal_drop_received (SidebarInternalDropTargetEntry* base,
                                                                  GeeList* media);
static gboolean library_trash_sidebar_entry_real_internal_drop_received_arbitrary (SidebarInternalDropTargetEntry* base,
                                                                            GtkSelectionData* data);
static Page* library_trash_sidebar_entry_real_create_page (SidebarSimplePageEntry* base);
static void library_trash_sidebar_entry_finalize (GObject * obj);
static GType library_trash_sidebar_entry_get_type_once (void);

static void
_library_trash_sidebar_entry_on_trashcan_contents_altered_media_source_collection_trashcan_contents_altered (MediaSourceCollection* _sender,
                                                                                                             GeeCollection* added,
                                                                                                             GeeCollection* removed,
                                                                                                             gpointer self)
{
	library_trash_sidebar_entry_on_trashcan_contents_altered ((LibraryTrashSidebarEntry*) self);
}

LibraryTrashSidebarEntry*
library_trash_sidebar_entry_construct (GType object_type)
{
	LibraryTrashSidebarEntry * self = NULL;
	self = (LibraryTrashSidebarEntry*) sidebar_simple_page_entry_construct (object_type);
	{
		GeeIterator* _media_sources_it = NULL;
		MediaCollectionRegistry* _tmp0_;
		MediaCollectionRegistry* _tmp1_;
		GeeCollection* _tmp2_;
		GeeCollection* _tmp3_;
		GeeIterator* _tmp4_;
		GeeIterator* _tmp5_;
		_tmp0_ = media_collection_registry_get_instance ();
		_tmp1_ = _tmp0_;
		_tmp2_ = media_collection_registry_get_all (_tmp1_);
		_tmp3_ = _tmp2_;
		_tmp4_ = gee_iterable_iterator ((GeeIterable*) _tmp3_);
		_tmp5_ = _tmp4_;
		_g_object_unref0 (_tmp3_);
		_media_collection_registry_unref0 (_tmp1_);
		_media_sources_it = _tmp5_;
		while (TRUE) {
			GeeIterator* _tmp6_;
			MediaSourceCollection* media_sources = NULL;
			GeeIterator* _tmp7_;
			gpointer _tmp8_;
			MediaSourceCollection* _tmp9_;
			_tmp6_ = _media_sources_it;
			if (!gee_iterator_next (_tmp6_)) {
				break;
			}
			_tmp7_ = _media_sources_it;
			_tmp8_ = gee_iterator_get (_tmp7_);
			media_sources = (MediaSourceCollection*) _tmp8_;
			_tmp9_ = media_sources;
			g_signal_connect_object (_tmp9_, "trashcan-contents-altered", (GCallback) _library_trash_sidebar_entry_on_trashcan_contents_altered_media_source_collection_trashcan_contents_altered, self, 0);
			_data_collection_unref0 (media_sources);
		}
		_g_object_unref0 (_media_sources_it);
	}
	return self;
}

LibraryTrashSidebarEntry*
library_trash_sidebar_entry_new (void)
{
	return library_trash_sidebar_entry_construct (LIBRARY_TYPE_TRASH_SIDEBAR_ENTRY);
}

void
library_trash_sidebar_entry_init (void)
{
	GThemedIcon* _tmp0_;
	GThemedIcon* _tmp1_;
	_tmp0_ = (GThemedIcon*) g_themed_icon_new (RESOURCES_ICON_TRASH_FULL);
	_g_object_unref0 (library_trash_sidebar_entry_full_icon);
	library_trash_sidebar_entry_full_icon = (GIcon*) _tmp0_;
	_tmp1_ = (GThemedIcon*) g_themed_icon_new (RESOURCES_ICON_TRASH_EMPTY);
	_g_object_unref0 (library_trash_sidebar_entry_empty_icon);
	library_trash_sidebar_entry_empty_icon = (GIcon*) _tmp1_;
}

void
library_trash_sidebar_entry_terminate (void)
{
	_g_object_unref0 (library_trash_sidebar_entry_full_icon);
	library_trash_sidebar_entry_full_icon = NULL;
	_g_object_unref0 (library_trash_sidebar_entry_empty_icon);
	library_trash_sidebar_entry_empty_icon = NULL;
}

static gchar*
library_trash_sidebar_entry_real_get_sidebar_name (SidebarSimplePageEntry* base)
{
	LibraryTrashSidebarEntry * self;
	gchar* _tmp0_;
	gchar* result;
	self = (LibraryTrashSidebarEntry*) base;
	_tmp0_ = g_strdup (TRASH_PAGE_NAME);
	result = _tmp0_;
	return result;
}

static GIcon*
library_trash_sidebar_entry_real_get_sidebar_icon (SidebarSimplePageEntry* base)
{
	LibraryTrashSidebarEntry * self;
	GIcon* _tmp0_;
	GIcon* result;
	self = (LibraryTrashSidebarEntry*) base;
	_tmp0_ = library_trash_sidebar_entry_get_current_icon ();
	result = _tmp0_;
	return result;
}

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

static GIcon*
library_trash_sidebar_entry_get_current_icon (void)
{
	GIcon* _tmp12_;
	GIcon* _tmp13_;
	GIcon* result;
	{
		GeeIterator* _media_sources_it = NULL;
		MediaCollectionRegistry* _tmp0_;
		MediaCollectionRegistry* _tmp1_;
		GeeCollection* _tmp2_;
		GeeCollection* _tmp3_;
		GeeIterator* _tmp4_;
		GeeIterator* _tmp5_;
		_tmp0_ = media_collection_registry_get_instance ();
		_tmp1_ = _tmp0_;
		_tmp2_ = media_collection_registry_get_all (_tmp1_);
		_tmp3_ = _tmp2_;
		_tmp4_ = gee_iterable_iterator ((GeeIterable*) _tmp3_);
		_tmp5_ = _tmp4_;
		_g_object_unref0 (_tmp3_);
		_media_collection_registry_unref0 (_tmp1_);
		_media_sources_it = _tmp5_;
		while (TRUE) {
			GeeIterator* _tmp6_;
			MediaSourceCollection* media_sources = NULL;
			GeeIterator* _tmp7_;
			gpointer _tmp8_;
			MediaSourceCollection* _tmp9_;
			_tmp6_ = _media_sources_it;
			if (!gee_iterator_next (_tmp6_)) {
				break;
			}
			_tmp7_ = _media_sources_it;
			_tmp8_ = gee_iterator_get (_tmp7_);
			media_sources = (MediaSourceCollection*) _tmp8_;
			_tmp9_ = media_sources;
			if (media_source_collection_get_trashcan_count (_tmp9_) > 0) {
				GIcon* _tmp10_;
				GIcon* _tmp11_;
				_tmp10_ = library_trash_sidebar_entry_full_icon;
				_tmp11_ = _g_object_ref0 (_tmp10_);
				result = _tmp11_;
				_data_collection_unref0 (media_sources);
				_g_object_unref0 (_media_sources_it);
				return result;
			}
			_data_collection_unref0 (media_sources);
		}
		_g_object_unref0 (_media_sources_it);
	}
	_tmp12_ = library_trash_sidebar_entry_empty_icon;
	_tmp13_ = _g_object_ref0 (_tmp12_);
	result = _tmp13_;
	return result;
}

static gboolean
library_trash_sidebar_entry_real_internal_drop_received (SidebarInternalDropTargetEntry* base,
                                                         GeeList* media)
{
	LibraryTrashSidebarEntry * self;
	CommandManager* _tmp0_;
	CommandManager* _tmp1_;
	TrashUntrashPhotosCommand* _tmp2_;
	TrashUntrashPhotosCommand* _tmp3_;
	gboolean result;
	self = (LibraryTrashSidebarEntry*) base;
	g_return_val_if_fail (media != NULL, FALSE);
	_tmp0_ = app_window_get_command_manager ();
	_tmp1_ = _tmp0_;
	_tmp2_ = trash_untrash_photos_command_new ((GeeCollection*) media, TRUE);
	_tmp3_ = _tmp2_;
	command_manager_execute (_tmp1_, (Command*) _tmp3_);
	_g_object_unref0 (_tmp3_);
	_command_manager_unref0 (_tmp1_);
	result = TRUE;
	return result;
}

static gboolean
library_trash_sidebar_entry_real_internal_drop_received_arbitrary (SidebarInternalDropTargetEntry* base,
                                                                   GtkSelectionData* data)
{
	LibraryTrashSidebarEntry * self;
	gboolean result;
	self = (LibraryTrashSidebarEntry*) base;
	g_return_val_if_fail (data != NULL, FALSE);
	result = FALSE;
	return result;
}

static Page*
library_trash_sidebar_entry_real_create_page (SidebarSimplePageEntry* base)
{
	LibraryTrashSidebarEntry * self;
	TrashPage* _tmp0_;
	Page* result;
	self = (LibraryTrashSidebarEntry*) base;
	_tmp0_ = trash_page_new ();
	g_object_ref_sink (_tmp0_);
	result = (Page*) _tmp0_;
	return result;
}

static void
library_trash_sidebar_entry_on_trashcan_contents_altered (LibraryTrashSidebarEntry* self)
{
	GIcon* _tmp0_;
	GIcon* _tmp1_;
	g_return_if_fail (self != NULL);
	_tmp0_ = library_trash_sidebar_entry_get_current_icon ();
	_tmp1_ = _tmp0_;
	g_signal_emit_by_name ((SidebarEntry*) self, "sidebar-icon-changed", _tmp1_);
	_g_object_unref0 (_tmp1_);
}

static void
library_trash_sidebar_entry_class_init (LibraryTrashSidebarEntryClass * klass,
                                        gpointer klass_data)
{
	library_trash_sidebar_entry_parent_class = g_type_class_peek_parent (klass);
	((SidebarSimplePageEntryClass *) klass)->get_sidebar_name = (gchar* (*) (SidebarSimplePageEntry*)) library_trash_sidebar_entry_real_get_sidebar_name;
	((SidebarSimplePageEntryClass *) klass)->get_sidebar_icon = (GIcon* (*) (SidebarSimplePageEntry*)) library_trash_sidebar_entry_real_get_sidebar_icon;
	((SidebarSimplePageEntryClass *) klass)->create_page = (Page* (*) (SidebarSimplePageEntry*)) library_trash_sidebar_entry_real_create_page;
	G_OBJECT_CLASS (klass)->finalize = library_trash_sidebar_entry_finalize;
}

static void
library_trash_sidebar_entry_sidebar_internal_drop_target_entry_interface_init (SidebarInternalDropTargetEntryIface * iface,
                                                                               gpointer iface_data)
{
	library_trash_sidebar_entry_sidebar_internal_drop_target_entry_parent_iface = g_type_interface_peek_parent (iface);
	iface->internal_drop_received = (gboolean (*) (SidebarInternalDropTargetEntry*, GeeList*)) library_trash_sidebar_entry_real_internal_drop_received;
	iface->internal_drop_received_arbitrary = (gboolean (*) (SidebarInternalDropTargetEntry*, GtkSelectionData*)) library_trash_sidebar_entry_real_internal_drop_received_arbitrary;
}

static void
library_trash_sidebar_entry_instance_init (LibraryTrashSidebarEntry * self,
                                           gpointer klass)
{
}

static void
library_trash_sidebar_entry_finalize (GObject * obj)
{
	LibraryTrashSidebarEntry * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, LIBRARY_TYPE_TRASH_SIDEBAR_ENTRY, LibraryTrashSidebarEntry);
	{
		GeeIterator* _media_sources_it = NULL;
		MediaCollectionRegistry* _tmp0_;
		MediaCollectionRegistry* _tmp1_;
		GeeCollection* _tmp2_;
		GeeCollection* _tmp3_;
		GeeIterator* _tmp4_;
		GeeIterator* _tmp5_;
		_tmp0_ = media_collection_registry_get_instance ();
		_tmp1_ = _tmp0_;
		_tmp2_ = media_collection_registry_get_all (_tmp1_);
		_tmp3_ = _tmp2_;
		_tmp4_ = gee_iterable_iterator ((GeeIterable*) _tmp3_);
		_tmp5_ = _tmp4_;
		_g_object_unref0 (_tmp3_);
		_media_collection_registry_unref0 (_tmp1_);
		_media_sources_it = _tmp5_;
		while (TRUE) {
			GeeIterator* _tmp6_;
			MediaSourceCollection* media_sources = NULL;
			GeeIterator* _tmp7_;
			gpointer _tmp8_;
			MediaSourceCollection* _tmp9_;
			guint _tmp10_;
			_tmp6_ = _media_sources_it;
			if (!gee_iterator_next (_tmp6_)) {
				break;
			}
			_tmp7_ = _media_sources_it;
			_tmp8_ = gee_iterator_get (_tmp7_);
			media_sources = (MediaSourceCollection*) _tmp8_;
			_tmp9_ = media_sources;
			g_signal_parse_name ("trashcan-contents-altered", TYPE_MEDIA_SOURCE_COLLECTION, &_tmp10_, NULL, FALSE);
			g_signal_handlers_disconnect_matched (_tmp9_, G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA, _tmp10_, 0, NULL, (GCallback) _library_trash_sidebar_entry_on_trashcan_contents_altered_media_source_collection_trashcan_contents_altered, self);
			_data_collection_unref0 (media_sources);
		}
		_g_object_unref0 (_media_sources_it);
	}
	G_OBJECT_CLASS (library_trash_sidebar_entry_parent_class)->finalize (obj);
}

static GType
library_trash_sidebar_entry_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (LibraryTrashSidebarEntryClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) library_trash_sidebar_entry_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (LibraryTrashSidebarEntry), 0, (GInstanceInitFunc) library_trash_sidebar_entry_instance_init, NULL };
	static const GInterfaceInfo sidebar_internal_drop_target_entry_info = { (GInterfaceInitFunc) library_trash_sidebar_entry_sidebar_internal_drop_target_entry_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
	GType library_trash_sidebar_entry_type_id;
	library_trash_sidebar_entry_type_id = g_type_register_static (SIDEBAR_TYPE_SIMPLE_PAGE_ENTRY, "LibraryTrashSidebarEntry", &g_define_type_info, 0);
	g_type_add_interface_static (library_trash_sidebar_entry_type_id, SIDEBAR_TYPE_INTERNAL_DROP_TARGET_ENTRY, &sidebar_internal_drop_target_entry_info);
	return library_trash_sidebar_entry_type_id;
}

GType
library_trash_sidebar_entry_get_type (void)
{
	static volatile gsize library_trash_sidebar_entry_type_id__once = 0;
	if (g_once_init_enter (&library_trash_sidebar_entry_type_id__once)) {
		GType library_trash_sidebar_entry_type_id;
		library_trash_sidebar_entry_type_id = library_trash_sidebar_entry_get_type_once ();
		g_once_init_leave (&library_trash_sidebar_entry_type_id__once, library_trash_sidebar_entry_type_id);
	}
	return library_trash_sidebar_entry_type_id__once;
}

