/*
 * Copyright (C) 2006-2007 Imendio AB.
 * Copyright (C) 2007-2008 Collabora Ltd.
 *
 * This library 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 library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * Authors: Based on Novell's e-image-chooser.
 *          Xavier Claessens <xclaesse@gmail.com>
 */
#include <gtk/gtk.h>

/* Calling gtk_button_set_image from ::init leaks the GtkImage, calling
 * it from ::constructed does not leak it
 */
#define LEAK 1


#define TPAW_IMAGE_AVATAR_DEFAULT      "avatar-default-symbolic"
#define TPAW_TYPE_AVATAR_CHOOSER        (tpaw_avatar_chooser_get_type ())

typedef struct _TpawAvatarChooser        TpawAvatarChooser;
typedef struct _TpawAvatarChooserClass   TpawAvatarChooserClass;

struct _TpawAvatarChooser
{
  GtkButton parent;
};

struct _TpawAvatarChooserClass
{
  GtkButtonClass parent_class;
};

GType tpaw_avatar_chooser_get_type (void);

GtkWidget *tpaw_avatar_chooser_new (void);

G_DEFINE_TYPE (TpawAvatarChooser, tpaw_avatar_chooser, GTK_TYPE_BUTTON);

static void
avatar_chooser_clear_image (TpawAvatarChooser *self)
{
  GtkWidget *image;

  image = gtk_image_new_from_icon_name (TPAW_IMAGE_AVATAR_DEFAULT,
    GTK_ICON_SIZE_DIALOG);
  gtk_button_set_image (GTK_BUTTON (self), image);
}

static void
avatar_chooser_constructed (GObject *object)
{
  G_OBJECT_CLASS (tpaw_avatar_chooser_parent_class)->constructed (object);

#ifndef LEAK
  avatar_chooser_clear_image ((TpawAvatarChooser *)object);
#endif
}

static void
tpaw_avatar_chooser_class_init (TpawAvatarChooserClass *klass)
{
  GObjectClass *object_class = G_OBJECT_CLASS (klass);

  object_class->constructed = avatar_chooser_constructed;
}

static void
tpaw_avatar_chooser_init (TpawAvatarChooser *self)
{
#ifdef LEAK
  avatar_chooser_clear_image (self);
#endif
}

GtkWidget *
tpaw_avatar_chooser_new (void)
{
  return g_object_new (TPAW_TYPE_AVATAR_CHOOSER, NULL);
}

int main(int argc, char **argv)
{
  GtkWidget *chooser;

  gtk_init (&argc, &argv);
  chooser = tpaw_avatar_chooser_new ();
  gtk_button_set_image (GTK_BUTTON (chooser), NULL);
  gtk_widget_destroy (chooser);

  return 0;
}
