Use glib style for function names.
[tele.git] / src / gui.c
bloba26c76b30eddfbe0d53c700a0bdb5f6049312b7f
1 /**
3 * Teleport graphical interface
5 * gui.c
7 * Copyright : (C) 2007 by Diogo Ferreira <diogo@underdev.org>
8 * (C) 2007 by João Oliveirinha <joliveirinha@floodbit.org>
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 3
14 * of the License, or (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 **/
23 #include <gtk/gtk.h>
24 #include <glib.h>
25 #include <glade/glade.h>
26 #include <string.h>
27 #include "teleport-private.h"
28 #include "teleport.h"
30 #define MAIN_WINDOW_GLADE_FILE "glade/gui.glade"
32 static GtkWidget *gMainWindow = NULL;
33 static GtkWidget *gQueryWidget = NULL;
34 static GtkWidget *gResultsTable = NULL;
37 enum
39 COL_RESULT = 0,
40 COL_BACKEND,
41 NUM_COLS
44 static void _gui_add_item (gpointer data, gpointer userdata)
46 TeleportAction *action = (TeleportAction*)data;
47 GtkListStore *pTreeStore = GTK_LIST_STORE (gtk_tree_view_get_model(GTK_TREE_VIEW(gResultsTable)));
48 GtkTreeIter iter;
50 gtk_list_store_append (pTreeStore, &iter);
51 gtk_list_store_set (pTreeStore, &iter,
52 COL_RESULT, action->text,
53 COL_BACKEND, action->backend->vTable->name,
54 -1);
57 gboolean _gui_update_list (gpointer data)
59 g_slist_foreach ((GSList*)data, _gui_add_item, NULL);
60 return FALSE;
63 static void _gui_search (GtkButton *pButton, gpointer data)
65 const char *query = gtk_entry_get_text(GTK_ENTRY(gQueryWidget));
66 GtkListStore *pTreeStore = GTK_LIST_STORE (gtk_tree_view_get_model(GTK_TREE_VIEW(gResultsTable)));
68 if (strlen(query) != 0) {
69 gtk_list_store_clear (pTreeStore);
70 teleport_perform_query (query);
74 static void _gui_init_tree_view ()
76 GtkCellRenderer *pCellRenderer;
77 GtkListStore *pTreeStore;
79 pCellRenderer = gtk_cell_renderer_text_new ();
80 gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (gResultsTable), -1, "Result", pCellRenderer, "text", COL_RESULT, NULL);
81 pCellRenderer = gtk_cell_renderer_text_new ();
82 gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (gResultsTable), -1, "Backend", pCellRenderer, "text", COL_BACKEND, NULL);
84 pTreeStore = gtk_list_store_new (NUM_COLS, G_TYPE_STRING, G_TYPE_STRING);
86 gtk_tree_view_set_model (GTK_TREE_VIEW (gResultsTable), GTK_TREE_MODEL(pTreeStore));
89 static gboolean _gui_quit (GtkWidget *widget, gpointer data)
91 teleport_fini_main_loop ();
93 return FALSE;
96 gboolean _gui_init (int *argc, char **argv[])
98 gtk_init(argc, argv);
100 GladeXML *pGladeXML = glade_xml_new (MAIN_WINDOW_GLADE_FILE, NULL, NULL);
101 GtkWidget *pSearchButton;
103 if (!pGladeXML)
105 g_print ("Unable to load glade file\n");
106 return FALSE;
109 gMainWindow = glade_xml_get_widget (pGladeXML, "TestGui");
110 gQueryWidget = glade_xml_get_widget (pGladeXML, "query_text");
111 gResultsTable = glade_xml_get_widget (pGladeXML, "result_table");
112 pSearchButton = glade_xml_get_widget (pGladeXML, "search_button");
114 g_signal_connect (G_OBJECT (pSearchButton), "clicked", G_CALLBACK (_gui_search), NULL);
115 g_signal_connect (G_OBJECT (gMainWindow), "destroy", G_CALLBACK (_gui_quit), NULL);
117 _gui_init_tree_view ();
119 if (!GTK_WIDGET_VISIBLE (gMainWindow))
120 gtk_widget_show_all (gMainWindow);
122 return TRUE;