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
|
GtkWidget* create_icon_view_with_symbols(){
// load symbol pictures into pixbufs
icons[state_off] = gdk_pixbuf_new_from_file("/opt/labcontrol/icons/client_off.svg", NULL);
icons[state_booting] = gdk_pixbuf_new_from_file("/opt/labcontrol/icons/booting.svg", NULL);
icons[state_on] = gdk_pixbuf_new_from_file("/usr/share/icons/Humanity/devices/48/computer.svg", NULL);
icons[state_zleaf_running] = gdk_pixbuf_new_from_file("/opt/labcontrol/icons/leafrunning.svg", NULL);
icons[state_shutdowning] = gdk_pixbuf_new_from_file("/opt/labcontrol/icons/halting.svg", NULL);
icons[state_undefined] = gdk_pixbuf_new_from_file("/opt/labcontrol/icons/unknown.svg", NULL);
// create icon view with suitable properities
icon_view = gtk_icon_view_new();
gtk_icon_view_set_pixbuf_column(GTK_ICON_VIEW(icon_view), 0);
gtk_icon_view_set_text_column(GTK_ICON_VIEW(icon_view), 1);
gtk_icon_view_set_columns(GTK_ICON_VIEW(icon_view), get_symbols_no_cols());
gtk_icon_view_set_selection_mode(GTK_ICON_VIEW(icon_view), GTK_SELECTION_MULTIPLE);
gtk_icon_view_set_spacing(GTK_ICON_VIEW(icon_view), 6);
gtk_icon_view_set_row_spacing(GTK_ICON_VIEW(icon_view), 20);
gtk_icon_view_set_column_spacing(GTK_ICON_VIEW(icon_view), 20);
gtk_icon_view_set_margin(GTK_ICON_VIEW(icon_view), 10);
gtk_icon_view_set_item_width(GTK_ICON_VIEW(icon_view), 48);
// create symbols on the icon view, and during doing that counting number of clients, too
store = gtk_list_store_new (2, GDK_TYPE_PIXBUF, G_TYPE_STRING);
gtk_icon_view_set_model (GTK_ICON_VIEW (icon_view), GTK_TREE_MODEL (store));
GtkTreeIter iter;
for (guint i=1; i<=g_slist_length(symbols); i++){
if (GPOINTER_TO_INT(g_slist_nth_data(symbols, i-1)) == 0){
gtk_list_store_insert_with_values (store, &iter, 100, -1);
}
else {
gtk_list_store_insert_with_values (store, &iter, 100, 0, icons[state_undefined], 1, g_strdup_printf("%i", GPOINTER_TO_INT(g_slist_nth_data(symbols, i-1))), -1);
}
}
g_signal_connect(icon_view, "selection_changed", G_CALLBACK(Platzhalter_demarkieren), NULL);
return(icon_view);
}
/*
* Function is attached to main loop in get_state.c, polls the queue for new messages and update the symbols if necessary
*/
gboolean poll_state_queue_and_update_symbols(gpointer state_queue){
// create structure in which the data from the queue can be stored
struct state_update *state_message;
// poll queue until there are no more messages
state_message = g_async_queue_try_pop(state_queue);
while (state_message!=NULL) {
// update the symbol:
// make GtkTreeModel (liste where the symbols are stored) accessable
GtkTreeModel *model;
model = gtk_icon_view_get_model(GTK_ICON_VIEW(icon_view));
// set iteratoren to the position of the fitting client symbol
GtkTreeIter citer;
gtk_tree_model_get_iter_first(model, &citer);
for (gint j=1; j<=g_slist_index(symbols, GUINT_TO_POINTER(state_message->client_no)); j++){
gtk_tree_model_iter_next(model, &citer);
}
// update symbol Symbol
gtk_list_store_set (store, &citer, 0, icons[state_message->client_state], -1);
// try to poll queue again
state_message = g_async_queue_try_pop(state_queue);
}
// return True because otherwise the signal source would be destroyed
return TRUE;
};
/*
* This function is called everytime the selection of the symbols changes. It de-selects all empty symbols which do not represent a client.
*/
void Platzhalter_demarkieren(){
// make GtkTreeModel (liste where the symbols are stored) accessable
GtkTreeModel *model = gtk_icon_view_get_model(GTK_ICON_VIEW(icon_view));
// set iteratoren to the position of the fitting client symbol
GtkTreeIter iter;
gtk_tree_model_get_iter_first(model, &iter);
GtkTreePath *path = gtk_tree_model_get_path(model, &iter);
// go through all symbols
for(guint i=0; i<=g_slist_length(symbols); i++){
// if symbol = 0 then de-select
if (GPOINTER_TO_UINT(g_slist_nth_data(symbols, i)) == 0){
gtk_icon_view_unselect_path (GTK_ICON_VIEW(icon_view), path);
}
gtk_tree_path_next(path);
}
}
|