summaryrefslogtreecommitdiff
path: root/liszt/main.c
blob: 00f5092c36a08494c9b16528f15b971921ebd215 (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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#include <mx/mx.h>
#include <folks/folks.h>

#include "factory.h"

enum
{
  COLUMN_INDIVIDUAL,
  N_COLUMNS
};

static void
aggregator_individuals_changed_cb (FolksIndividualAggregator *aggregator,
    GList *added,
    GList *removed,
    const char *message,
    FolksPersona *actor,
    guint reason,
    ClutterModel *model)
{
  GList *l;

  for (l = added; l != NULL; l = l->next)
    {
      FolksIndividual *individual = l->data;

      if (folks_individual_get_is_user (individual))
        continue;

      clutter_model_append (model,
          COLUMN_INDIVIDUAL, individual,
          -1);
    }
}

/* breaks avatars for now
static gint
model_sort_func (ClutterModel *model,
    const GValue *a,
    const GValue *b,
    gpointer user_data)
{
  FolksIndividual *one = g_value_get_object (a);
  FolksIndividual *two = g_value_get_object (b);
  gint ret;

  ret = folks_presence_typecmp (
      folks_presence_get_presence_type (FOLKS_PRESENCE (one)),
      folks_presence_get_presence_type (FOLKS_PRESENCE (two)));

  if (ret != 0)
    return ret;

  return strcmp (folks_aliasable_get_alias (FOLKS_ALIASABLE (one)),
      folks_aliasable_get_alias (FOLKS_ALIASABLE (two)));
}
*/

static ClutterModel *
create_model (FolksIndividualAggregator *aggregator)
{
  ClutterModel *model;

  model = clutter_list_model_new (N_COLUMNS,
      FOLKS_TYPE_INDIVIDUAL, "individual");

  /*
  clutter_model_set_sort (model, COLUMN_INDIVIDUAL, model_sort_func,
      NULL, NULL);
  */

  folks_individual_aggregator_prepare (aggregator, NULL, NULL);

  g_signal_connect (aggregator, "individuals-changed",
      G_CALLBACK (aggregator_individuals_changed_cb), model);

  return model;
}

int
main (int argc, char **argv)
{
  MxApplication *application;
  FolksIndividualAggregator *aggregator;
  MxWindow *window;
  ClutterActor *stage, *toolbar, *layout, *combo, *scroll, *view;

  application = mx_application_new (&argc, &argv, "Contact list",
      MX_APPLICATION_SINGLE_INSTANCE);

  aggregator = folks_individual_aggregator_new ();

  window = mx_application_create_window (application);
  stage = (ClutterActor *) mx_window_get_clutter_stage (window);

  /* toolbar */
  toolbar = (ClutterActor *) mx_window_get_toolbar (window);
  mx_bin_set_fill (MX_BIN (toolbar), TRUE, FALSE);

  layout = mx_box_layout_new ();

  combo = mx_combo_box_new ();
  clutter_container_add_actor (CLUTTER_CONTAINER (layout), combo);
  mx_combo_box_append_text (MX_COMBO_BOX (combo), "All Contacts");
  mx_combo_box_append_text (MX_COMBO_BOX (combo), "Work");
  mx_combo_box_append_text (MX_COMBO_BOX (combo), "Play");
  mx_combo_box_append_text (MX_COMBO_BOX (combo), "Girls");
  mx_combo_box_set_index (MX_COMBO_BOX (combo), 0);

  clutter_container_add_actor (CLUTTER_CONTAINER (toolbar), layout);

  /* main stage */
  scroll = mx_scroll_view_new ();
  mx_window_set_child (window, scroll);

  view = mx_list_view_new ();
  mx_list_view_add_attribute (MX_LIST_VIEW (view), "individual", COLUMN_INDIVIDUAL);

  mx_list_view_set_factory (MX_LIST_VIEW (view), MX_ITEM_FACTORY (lol_factory_new ()));
  mx_list_view_set_model (MX_LIST_VIEW (view), create_model (aggregator));

  clutter_container_add_actor (CLUTTER_CONTAINER (scroll), view);

  clutter_actor_show (stage);

  mx_application_run (application);

  g_object_unref (aggregator);

  return 0;
}