Commit 560b7c7d authored by winckel's avatar winckel

Created code to save filters file.

Added a cursor change function (normal/busy), not always working !
Changed open file functions to hide selector window before reading the file.

git-svn-id: http://svn.eurecom.fr/openair4G/trunk@4323 818b1a75-f10b-46b9-bf7c-635c3b92a50f
parent d0ef6fcf
......@@ -10,10 +10,12 @@ const uint32_t FILTER_ALLOC_NUMBER = 100;
ui_filters_t ui_filters;
static int ui_init_filter(ui_filter_t *filter, int reset, int clear_ids)
static int ui_init_filter(ui_filter_t *filter, int reset, int clear_ids, char *name)
{
if (filter->items == NULL)
{
filter->name = name;
/* Allocate some filter entries */
filter->items = malloc (FILTER_ALLOC_NUMBER * sizeof(ui_filter_item_t));
filter->allocated = FILTER_ALLOC_NUMBER;
......@@ -42,9 +44,9 @@ static int ui_init_filter(ui_filter_t *filter, int reset, int clear_ids)
int ui_init_filters(int reset, int clear_ids)
{
ui_init_filter (&ui_filters.messages, reset, clear_ids);
ui_init_filter (&ui_filters.origin_tasks, reset, clear_ids);
ui_init_filter (&ui_filters.destination_tasks, reset, clear_ids);
ui_init_filter (&ui_filters.messages, reset, clear_ids, "messages");
ui_init_filter (&ui_filters.origin_tasks, reset, clear_ids, "origin_tasks");
ui_init_filter (&ui_filters.destination_tasks, reset, clear_ids, "destination_tasks");
ui_destroy_filter_menus();
......@@ -112,58 +114,37 @@ void ui_filters_add(ui_filter_e filter, uint32_t value, char *name)
}
}
static int write_filters_file(void)
static void write_filter(FILE *filter_file, ui_filter_t *filter)
{
int item;
fprintf (filter_file, " <%s>\n", filter->name);
for (item = 0; item < filter->used; item++)
{
fprintf (filter_file, " %s=\"%d\"\n", filter->items[item].name, filter->items[item].enabled ? 1 :0);
}
fprintf (filter_file, " </%s>\n", filter->name);
}
int ui_write_filters_file(char *file_name)
{
char *filter_file_name = "./filters.xml";
FILE *filter_file;
// types_t *types;
filter_file = fopen (filter_file_name, "w");
filter_file = fopen (file_name, "w");
if (filter_file == NULL)
{
g_warning("Failed to open file \"%s\": %s", filter_file_name, g_strerror (errno));
g_warning("Failed to open file \"%s\": %s", file_name, g_strerror (errno));
return RC_FAIL;
}
fprintf (filter_file, "<filters>\n");
/* types = messages_id_enum;
if (types != NULL)
{
types = types->child;
}
fprintf (filter_file, " <messages>\n");
while (types != NULL) {
fprintf (filter_file, " %s=\"1\"\n", types->name);
types = types->next;
}
fprintf (filter_file, " </messages>\n");
write_filter (filter_file, &ui_filters.messages);
write_filter (filter_file, &ui_filters.origin_tasks);
write_filter (filter_file, &ui_filters.destination_tasks);
types = origin_task_id_type;
if (types != NULL)
{
types = types->child->child;
}
fprintf (filter_file, " <origin_tasks>\n");
while (types != NULL) {
fprintf (filter_file, " %s=\"1\"\n", types->name);
types = types->next;
}
fprintf (filter_file, " </origin_tasks>\n");
types = destination_task_id_type;
if (types != NULL)
{
types = types->child->child;
}
fprintf (filter_file, " <destination_tasks>\n");
while (types != NULL) {
fprintf (filter_file, " %s=\"1\"\n", types->name);
types = types->next;
}
fprintf (filter_file, " </destination_tasks>\n");
*/
fprintf (filter_file, "</filters>\n");
fclose (filter_file);
......
......@@ -19,6 +19,7 @@ typedef struct
typedef struct
{
char *name;
uint32_t allocated;
uint32_t used;
ui_filter_item_t *items;
......@@ -37,4 +38,6 @@ int ui_init_filters(int reset, int clear_ids);
void ui_filters_add(ui_filter_e filter, uint32_t value, char *name);
int ui_write_filters_file(char *file_name);
#endif /* UI_FILTERS_H_ */
......@@ -13,6 +13,7 @@
#include "ui_menu_bar.h"
#include "ui_notifications.h"
#include "ui_callbacks.h"
#include "ui_filters.h"
#include "xml_parse.h"
......@@ -34,6 +35,33 @@ int ui_enable_connect_button(void)
return RC_OK;
}
void ui_change_cursor(gboolean busy)
{
static GdkWindow *window;
if (busy)
{
GdkDisplay *display;
GdkCursor *cursor;
// gint x, y;
cursor = gdk_cursor_new (GDK_WATCH);
display = gdk_display_get_default();
window = gtk_widget_get_window(GTK_WIDGET(ui_main_data.window));
// window = gdk_display_get_window_at_pointer(display, &x, &y);
gdk_window_set_cursor (window, cursor);
gdk_display_sync(display);
gdk_cursor_unref (cursor);
gtk_widget_set_sensitive (ui_main_data.window, FALSE);
}
else
{
gdk_window_set_cursor (window, NULL);
gtk_widget_set_sensitive (ui_main_data.window, TRUE);
}
}
int ui_messages_read(char *filename)
{
int result = RC_OK;
......@@ -43,6 +71,8 @@ int ui_messages_read(char *filename)
size_t input_data_length = 0;
int read_messages = 0;
ui_change_cursor(TRUE);
source = open (filename, O_RDONLY);
if (source < 0)
{
......@@ -132,60 +162,64 @@ int ui_messages_read(char *filename)
close (source);
}
ui_change_cursor(FALSE);
return result;
}
int ui_messages_open_file_chooser(void)
{
GtkWidget *filechooser;
int result = RC_OK;
GtkWidget *filechooser;
gboolean accept;
char *filename;
filechooser = gtk_file_chooser_dialog_new ("Select file", GTK_WINDOW (ui_main_data.window),
GTK_FILE_CHOOSER_ACTION_OPEN,
GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
NULL);
GTK_FILE_CHOOSER_ACTION_OPEN, GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, NULL);
/* Process the response */
if (gtk_dialog_run (GTK_DIALOG (filechooser)) == GTK_RESPONSE_ACCEPT)
{
char *filename;
accept = gtk_dialog_run (GTK_DIALOG (filechooser)) == GTK_RESPONSE_ACCEPT;
if (accept)
{
filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (filechooser));
result = ui_messages_read(filename);
g_free (filename);
}
gtk_widget_destroy (filechooser);
if (accept)
{
result = ui_messages_read (filename);
g_free (filename);
}
return result;
}
int ui_filters_open_file_chooser(void)
{
GtkWidget *filechooser;
int result = RC_OK;
GtkWidget *filechooser;
gboolean accept;
char *filename;
filechooser = gtk_file_chooser_dialog_new ("Select file", GTK_WINDOW (ui_main_data.window),
GTK_FILE_CHOOSER_ACTION_OPEN,
GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
NULL);
GTK_FILE_CHOOSER_ACTION_OPEN, GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, NULL);
/* Process the response */
if (gtk_dialog_run (GTK_DIALOG (filechooser)) == GTK_RESPONSE_ACCEPT)
{
char *filename;
accept = gtk_dialog_run (GTK_DIALOG (filechooser)) == GTK_RESPONSE_ACCEPT;
if (accept)
{
filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (filechooser));
g_free (filename);
}
gtk_widget_destroy (filechooser);
if (accept)
{
g_free (filename);
}
return RC_OK;
return result;
}
int ui_filters_save_file_chooser(void)
......@@ -211,12 +245,14 @@ int ui_filters_save_file_chooser(void)
filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (filechooser));
result = ui_write_filters_file(filename);
g_free (filename);
}
gtk_widget_destroy (filechooser);
return RC_OK;
return result;
}
int ui_progress_bar_set_fraction(double fraction)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment