summaryrefslogtreecommitdiff
path: root/liszt/factory.c
blob: 9b17f62012d1b9ff9da20b04ca895eef41fd16bf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include "factory.h"
#include "contact-view.h"

static void item_factory_init (gpointer g_iface, gpointer data);

G_DEFINE_TYPE_WITH_CODE (LolFactory, lol_factory, G_TYPE_OBJECT,
    G_IMPLEMENT_INTERFACE (MX_TYPE_ITEM_FACTORY, item_factory_init))

struct _LolFactoryPrivate
{
  LolContactView *selected;
};

static void
lol_factory_init (LolFactory *self)
{
  self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, LOL_TYPE_FACTORY,
      LolFactoryPrivate);
}

static void
lol_factory_class_init (LolFactoryClass *cls)
{
  g_type_class_add_private (cls, sizeof (LolFactoryPrivate));
}

LolFactory *
lol_factory_new (void)
{
  return g_object_new (LOL_TYPE_FACTORY,
      NULL);
}

static void
selected_cb (LolContactView *view,
    gboolean status,
    LolFactory *self)
{
  LolFactoryPrivate *priv = self->priv;

  /* current selected contact has been de-selected */
  if (priv->selected == view && !status)
    {
      priv->selected = NULL;
      return;
    }

  /* unselect the curently selected contact */
  if (priv->selected != NULL)
    lol_contact_view_toggle_selected (LOL_CONTACT_VIEW (priv->selected));

  priv->selected = view;
}

static gboolean
button_press_event_cb (ClutterActor *actor,
    ClutterEvent *event,
    LolFactory *self)
{
  lol_contact_view_toggle_selected (LOL_CONTACT_VIEW (actor));

  return TRUE;
}

static ClutterActor *
create (MxItemFactory *factory)
{
  ClutterActor *out = CLUTTER_ACTOR (lol_contact_view_new ());

  g_signal_connect (out, "button-press-event",
      G_CALLBACK (button_press_event_cb), factory);
  g_signal_connect (out, "selected",
      G_CALLBACK (selected_cb), factory);

  return out;
}

static void
item_factory_init (gpointer g_iface,
    gpointer data G_GNUC_UNUSED)
{
  MxItemFactoryIface *iface = g_iface;

  iface->create = create;
}