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

/*
* Copyright (c) 2010-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 <gee.h>
#include <glib-object.h>
#include <glib.h>
#include <string.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  {
	LAST_IMPORT_PAGE_0_PROPERTY,
	LAST_IMPORT_PAGE_NUM_PROPERTIES
};
static GParamSpec* last_import_page_properties[LAST_IMPORT_PAGE_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 _alteration_unref0(var) ((var == NULL) ? NULL : (var = (alteration_unref (var), NULL)))
#define _import_id_free0(var) ((var == NULL) ? NULL : (var = (import_id_free (var), NULL)))

#define LAST_IMPORT_PAGE_TYPE_LAST_IMPORT_VIEW_MANAGER (last_import_page_last_import_view_manager_get_type ())
#define LAST_IMPORT_PAGE_LAST_IMPORT_VIEW_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), LAST_IMPORT_PAGE_TYPE_LAST_IMPORT_VIEW_MANAGER, LastImportPageLastImportViewManager))
#define LAST_IMPORT_PAGE_LAST_IMPORT_VIEW_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), LAST_IMPORT_PAGE_TYPE_LAST_IMPORT_VIEW_MANAGER, LastImportPageLastImportViewManagerClass))
#define LAST_IMPORT_PAGE_IS_LAST_IMPORT_VIEW_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), LAST_IMPORT_PAGE_TYPE_LAST_IMPORT_VIEW_MANAGER))
#define LAST_IMPORT_PAGE_IS_LAST_IMPORT_VIEW_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), LAST_IMPORT_PAGE_TYPE_LAST_IMPORT_VIEW_MANAGER))
#define LAST_IMPORT_PAGE_LAST_IMPORT_VIEW_MANAGER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), LAST_IMPORT_PAGE_TYPE_LAST_IMPORT_VIEW_MANAGER, LastImportPageLastImportViewManagerClass))

typedef struct _LastImportPageLastImportViewManager LastImportPageLastImportViewManager;
typedef struct _LastImportPageLastImportViewManagerClass LastImportPageLastImportViewManagerClass;
#define _view_collection_monitor_unref0(var) ((var == NULL) ? NULL : (var = (view_collection_monitor_unref (var), NULL)))
#define _view_manager_unref0(var) ((var == NULL) ? NULL : (var = (view_manager_unref (var), NULL)))
typedef struct _LastImportPageLastImportViewManagerPrivate LastImportPageLastImportViewManagerPrivate;

struct _LastImportPagePrivate {
	ImportID last_import_id;
	Alteration* last_import_alteration;
};

struct _LastImportPageLastImportViewManager {
	CollectionViewManager parent_instance;
	LastImportPageLastImportViewManagerPrivate * priv;
};

struct _LastImportPageLastImportViewManagerClass {
	CollectionViewManagerClass parent_class;
};

struct _LastImportPageLastImportViewManagerPrivate {
	ImportID import_id;
};

static gint LastImportPage_private_offset;
static gpointer last_import_page_parent_class = NULL;
static gint LastImportPageLastImportViewManager_private_offset;
static gpointer last_import_page_last_import_view_manager_parent_class = NULL;

static void last_import_page_on_import_rolls_altered (LastImportPage* self);
static void _last_import_page_on_import_rolls_altered_media_source_collection_import_roll_altered (MediaSourceCollection* _sender,
                                                                                            gpointer self);
static LastImportPageLastImportViewManager* last_import_page_last_import_view_manager_new (LastImportPage* owner,
                                                                                    ImportID* import_id);
static LastImportPageLastImportViewManager* last_import_page_last_import_view_manager_construct (GType object_type,
                                                                                          LastImportPage* owner,
                                                                                          ImportID* import_id);
static GType last_import_page_last_import_view_manager_get_type (void) G_GNUC_CONST  G_GNUC_UNUSED ;
static gboolean last_import_page_last_import_view_manager_real_include_in_view (ViewManager* base,
                                                                         DataSource* source);
static void last_import_page_last_import_view_manager_finalize (ViewManager * obj);
static GType last_import_page_last_import_view_manager_get_type_once (void);
static void last_import_page_finalize (GObject * obj);
static GType last_import_page_get_type_once (void);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static inline gpointer
last_import_page_get_instance_private (LastImportPage* self)
{
	return G_STRUCT_MEMBER_P (self, LastImportPage_private_offset);
}

static void
_last_import_page_on_import_rolls_altered_media_source_collection_import_roll_altered (MediaSourceCollection* _sender,
                                                                                       gpointer self)
{
	last_import_page_on_import_rolls_altered ((LastImportPage*) self);
}

LastImportPage*
last_import_page_construct (GType object_type)
{
	LastImportPage * self = NULL;
	self = (LastImportPage*) collection_page_construct (object_type, LAST_IMPORT_PAGE_NAME);
	{
		GeeIterator* _col_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_);
		_col_it = _tmp5_;
		while (TRUE) {
			GeeIterator* _tmp6_;
			MediaSourceCollection* col = NULL;
			GeeIterator* _tmp7_;
			gpointer _tmp8_;
			MediaSourceCollection* _tmp9_;
			_tmp6_ = _col_it;
			if (!gee_iterator_next (_tmp6_)) {
				break;
			}
			_tmp7_ = _col_it;
			_tmp8_ = gee_iterator_get (_tmp7_);
			col = (MediaSourceCollection*) _tmp8_;
			_tmp9_ = col;
			g_signal_connect_object (_tmp9_, "import-roll-altered", (GCallback) _last_import_page_on_import_rolls_altered_media_source_collection_import_roll_altered, self, 0);
			_data_collection_unref0 (col);
		}
		_g_object_unref0 (_col_it);
	}
	last_import_page_on_import_rolls_altered (self);
	return self;
}

LastImportPage*
last_import_page_new (void)
{
	return last_import_page_construct (TYPE_LAST_IMPORT_PAGE);
}

static void
last_import_page_on_import_rolls_altered (LastImportPage* self)
{
	ImportID* current_last_import_id = NULL;
	MediaCollectionRegistry* _tmp0_;
	MediaCollectionRegistry* _tmp1_;
	ImportID* _tmp2_;
	ImportID* _tmp3_;
	ImportID* _tmp4_;
	ImportID* _tmp9_;
	ImportID _tmp10_;
	ImportID* _tmp11_;
	ViewCollection* _tmp12_;
	ViewCollection* _tmp13_;
	ViewCollection* _tmp14_;
	ViewCollection* _tmp15_;
	g_return_if_fail (self != NULL);
	_tmp0_ = media_collection_registry_get_instance ();
	_tmp1_ = _tmp0_;
	_tmp2_ = media_collection_registry_get_last_import_id (_tmp1_);
	_tmp3_ = _tmp2_;
	_media_collection_registry_unref0 (_tmp1_);
	current_last_import_id = _tmp3_;
	_tmp4_ = current_last_import_id;
	if (_tmp4_ == NULL) {
		ViewCollection* _tmp5_;
		ViewCollection* _tmp6_;
		ViewCollection* _tmp7_;
		ViewCollection* _tmp8_;
		_tmp5_ = page_get_view ((Page*) self);
		_tmp6_ = _tmp5_;
		view_collection_halt_all_monitoring (_tmp6_);
		_data_collection_unref0 (_tmp6_);
		_tmp7_ = page_get_view ((Page*) self);
		_tmp8_ = _tmp7_;
		data_collection_clear ((DataCollection*) _tmp8_);
		_data_collection_unref0 (_tmp8_);
		_import_id_free0 (current_last_import_id);
		return;
	}
	_tmp9_ = current_last_import_id;
	_tmp10_ = self->priv->last_import_id;
	if ((*_tmp9_).id == _tmp10_.id) {
		_import_id_free0 (current_last_import_id);
		return;
	}
	_tmp11_ = current_last_import_id;
	self->priv->last_import_id = *_tmp11_;
	_tmp12_ = page_get_view ((Page*) self);
	_tmp13_ = _tmp12_;
	view_collection_halt_all_monitoring (_tmp13_);
	_data_collection_unref0 (_tmp13_);
	_tmp14_ = page_get_view ((Page*) self);
	_tmp15_ = _tmp14_;
	data_collection_clear ((DataCollection*) _tmp15_);
	_data_collection_unref0 (_tmp15_);
	{
		GeeIterator* _col_it = NULL;
		MediaCollectionRegistry* _tmp16_;
		MediaCollectionRegistry* _tmp17_;
		GeeCollection* _tmp18_;
		GeeCollection* _tmp19_;
		GeeIterator* _tmp20_;
		GeeIterator* _tmp21_;
		_tmp16_ = media_collection_registry_get_instance ();
		_tmp17_ = _tmp16_;
		_tmp18_ = media_collection_registry_get_all (_tmp17_);
		_tmp19_ = _tmp18_;
		_tmp20_ = gee_iterable_iterator ((GeeIterable*) _tmp19_);
		_tmp21_ = _tmp20_;
		_g_object_unref0 (_tmp19_);
		_media_collection_registry_unref0 (_tmp17_);
		_col_it = _tmp21_;
		while (TRUE) {
			GeeIterator* _tmp22_;
			MediaSourceCollection* col = NULL;
			GeeIterator* _tmp23_;
			gpointer _tmp24_;
			ViewCollection* _tmp25_;
			ViewCollection* _tmp26_;
			MediaSourceCollection* _tmp27_;
			ImportID _tmp28_;
			LastImportPageLastImportViewManager* _tmp29_;
			LastImportPageLastImportViewManager* _tmp30_;
			Alteration* _tmp31_;
			ViewCollectionMonitor* _tmp32_;
			ViewCollectionMonitor* _tmp33_;
			_tmp22_ = _col_it;
			if (!gee_iterator_next (_tmp22_)) {
				break;
			}
			_tmp23_ = _col_it;
			_tmp24_ = gee_iterator_get (_tmp23_);
			col = (MediaSourceCollection*) _tmp24_;
			_tmp25_ = page_get_view ((Page*) self);
			_tmp26_ = _tmp25_;
			_tmp27_ = col;
			_tmp28_ = self->priv->last_import_id;
			_tmp29_ = last_import_page_last_import_view_manager_new (self, &_tmp28_);
			_tmp30_ = _tmp29_;
			_tmp31_ = self->priv->last_import_alteration;
			_tmp32_ = view_collection_monitor_source_collection (_tmp26_, (SourceCollection*) _tmp27_, (ViewManager*) _tmp30_, _tmp31_, NULL, NULL, NULL);
			_tmp33_ = _tmp32_;
			_view_collection_monitor_unref0 (_tmp33_);
			_view_manager_unref0 (_tmp30_);
			_data_collection_unref0 (_tmp26_);
			_data_collection_unref0 (col);
		}
		_g_object_unref0 (_col_it);
	}
	_import_id_free0 (current_last_import_id);
}

static inline gpointer
last_import_page_last_import_view_manager_get_instance_private (LastImportPageLastImportViewManager* self)
{
	return G_STRUCT_MEMBER_P (self, LastImportPageLastImportViewManager_private_offset);
}

static LastImportPageLastImportViewManager*
last_import_page_last_import_view_manager_construct (GType object_type,
                                                     LastImportPage* owner,
                                                     ImportID* import_id)
{
	LastImportPageLastImportViewManager* self = NULL;
	ImportID _tmp0_;
	g_return_val_if_fail (owner != NULL, NULL);
	g_return_val_if_fail (import_id != NULL, NULL);
	self = (LastImportPageLastImportViewManager*) collection_view_manager_construct (object_type, (CollectionPage*) owner);
	_tmp0_ = *import_id;
	self->priv->import_id = _tmp0_;
	return self;
}

static LastImportPageLastImportViewManager*
last_import_page_last_import_view_manager_new (LastImportPage* owner,
                                               ImportID* import_id)
{
	return last_import_page_last_import_view_manager_construct (LAST_IMPORT_PAGE_TYPE_LAST_IMPORT_VIEW_MANAGER, owner, import_id);
}

static gboolean
last_import_page_last_import_view_manager_real_include_in_view (ViewManager* base,
                                                                DataSource* source)
{
	LastImportPageLastImportViewManager * self;
	ImportID _tmp0_ = {0};
	ImportID _tmp1_;
	gboolean result;
	self = (LastImportPageLastImportViewManager*) base;
	g_return_val_if_fail (source != NULL, FALSE);
	media_source_get_import_id (G_TYPE_CHECK_INSTANCE_CAST (source, TYPE_MEDIA_SOURCE, MediaSource), &_tmp0_);
	_tmp1_ = self->priv->import_id;
	result = _tmp0_.id == _tmp1_.id;
	return result;
}

static void
last_import_page_last_import_view_manager_class_init (LastImportPageLastImportViewManagerClass * klass,
                                                      gpointer klass_data)
{
	last_import_page_last_import_view_manager_parent_class = g_type_class_peek_parent (klass);
	((ViewManagerClass *) klass)->finalize = last_import_page_last_import_view_manager_finalize;
	g_type_class_adjust_private_offset (klass, &LastImportPageLastImportViewManager_private_offset);
	((ViewManagerClass *) klass)->include_in_view = (gboolean (*) (ViewManager*, DataSource*)) last_import_page_last_import_view_manager_real_include_in_view;
}

static void
last_import_page_last_import_view_manager_instance_init (LastImportPageLastImportViewManager * self,
                                                         gpointer klass)
{
	self->priv = last_import_page_last_import_view_manager_get_instance_private (self);
}

static void
last_import_page_last_import_view_manager_finalize (ViewManager * obj)
{
	LastImportPageLastImportViewManager * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, LAST_IMPORT_PAGE_TYPE_LAST_IMPORT_VIEW_MANAGER, LastImportPageLastImportViewManager);
	VIEW_MANAGER_CLASS (last_import_page_last_import_view_manager_parent_class)->finalize (obj);
}

static GType
last_import_page_last_import_view_manager_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (LastImportPageLastImportViewManagerClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) last_import_page_last_import_view_manager_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (LastImportPageLastImportViewManager), 0, (GInstanceInitFunc) last_import_page_last_import_view_manager_instance_init, NULL };
	GType last_import_page_last_import_view_manager_type_id;
	last_import_page_last_import_view_manager_type_id = g_type_register_static (TYPE_COLLECTION_VIEW_MANAGER, "LastImportPageLastImportViewManager", &g_define_type_info, 0);
	LastImportPageLastImportViewManager_private_offset = g_type_add_instance_private (last_import_page_last_import_view_manager_type_id, sizeof (LastImportPageLastImportViewManagerPrivate));
	return last_import_page_last_import_view_manager_type_id;
}

static GType
last_import_page_last_import_view_manager_get_type (void)
{
	static volatile gsize last_import_page_last_import_view_manager_type_id__once = 0;
	if (g_once_init_enter (&last_import_page_last_import_view_manager_type_id__once)) {
		GType last_import_page_last_import_view_manager_type_id;
		last_import_page_last_import_view_manager_type_id = last_import_page_last_import_view_manager_get_type_once ();
		g_once_init_leave (&last_import_page_last_import_view_manager_type_id__once, last_import_page_last_import_view_manager_type_id);
	}
	return last_import_page_last_import_view_manager_type_id__once;
}

static void
last_import_page_class_init (LastImportPageClass * klass,
                             gpointer klass_data)
{
	last_import_page_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &LastImportPage_private_offset);
	G_OBJECT_CLASS (klass)->finalize = last_import_page_finalize;
}

static void
last_import_page_instance_init (LastImportPage * self,
                                gpointer klass)
{
	Alteration* _tmp0_;
	self->priv = last_import_page_get_instance_private (self);
	import_id_init (&self->priv->last_import_id, IMPORT_ID_INVALID);
	_tmp0_ = alteration_new ("metadata", "import-id");
	self->priv->last_import_alteration = _tmp0_;
}

static void
last_import_page_finalize (GObject * obj)
{
	LastImportPage * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, TYPE_LAST_IMPORT_PAGE, LastImportPage);
	{
		GeeIterator* _col_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_);
		_col_it = _tmp5_;
		while (TRUE) {
			GeeIterator* _tmp6_;
			MediaSourceCollection* col = NULL;
			GeeIterator* _tmp7_;
			gpointer _tmp8_;
			MediaSourceCollection* _tmp9_;
			guint _tmp10_;
			_tmp6_ = _col_it;
			if (!gee_iterator_next (_tmp6_)) {
				break;
			}
			_tmp7_ = _col_it;
			_tmp8_ = gee_iterator_get (_tmp7_);
			col = (MediaSourceCollection*) _tmp8_;
			_tmp9_ = col;
			g_signal_parse_name ("import-roll-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) _last_import_page_on_import_rolls_altered_media_source_collection_import_roll_altered, self);
			_data_collection_unref0 (col);
		}
		_g_object_unref0 (_col_it);
	}
	_alteration_unref0 (self->priv->last_import_alteration);
	G_OBJECT_CLASS (last_import_page_parent_class)->finalize (obj);
}

static GType
last_import_page_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (LastImportPageClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) last_import_page_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (LastImportPage), 0, (GInstanceInitFunc) last_import_page_instance_init, NULL };
	GType last_import_page_type_id;
	last_import_page_type_id = g_type_register_static (TYPE_COLLECTION_PAGE, "LastImportPage", &g_define_type_info, 0);
	LastImportPage_private_offset = g_type_add_instance_private (last_import_page_type_id, sizeof (LastImportPagePrivate));
	return last_import_page_type_id;
}

GType
last_import_page_get_type (void)
{
	static volatile gsize last_import_page_type_id__once = 0;
	if (g_once_init_enter (&last_import_page_type_id__once)) {
		GType last_import_page_type_id;
		last_import_page_type_id = last_import_page_get_type_once ();
		g_once_init_leave (&last_import_page_type_id__once, last_import_page_type_id);
	}
	return last_import_page_type_id__once;
}

static inline gpointer
_vala_memdup2 (gconstpointer mem,
               gsize byte_size)
{
	gpointer new_mem;
	if (mem && byte_size != 0) {
		new_mem = g_malloc (byte_size);
		memcpy (new_mem, mem, byte_size);
	} else {
		new_mem = NULL;
	}
	return new_mem;
}

