src/frame-new-dialog.c File Reference

Source code for the functions used in the new frame dialog. More...

#include <gtk/gtk.h>
#include <stdlib.h>
#include "application-data.h"
#include "frame-common.h"
#include "frame-new-dialog.h"
#include "frame-private.h"
#include "frame-utilities.h"
#include "machine.h"
#include "time-period.h"
Include dependency graph for frame-new-dialog.c:

Go to the source code of this file.

Functions

void frame_populate_time_period_combo (GtkWidget *combo, plugin_t *plugin, time_period_t *active_period)
 Fills a combo box with the list of time periods available for a given plugin.
void frame_populate_tool_type_combo (GtkWidget *combo, machine_t *machine, gchar *active_tool)
 Fills a combo box with the list of plugins available for a given machine.
void frame_populate_machine_combo (GtkWidget *combo, GList *machines_list, machine_t *active_machine)
 Fills a combo box with the list of currently available machines.
void frame_on_new (GtkToolButton *button, gpointer user_data)
 Displays a New Frame dialog.

Detailed Description

Source code for the functions used in the new frame dialog.

Author:
Steve Dodier <sidnioulz@gmail.com>

This source code file contains functions described in frame-new-dialog.h. These functions are used in the New Frame dialog of Synema.

Definition in file frame-new-dialog.c.


Function Documentation

void frame_on_new ( GtkToolButton *  button,
gpointer  user_data 
)

Displays a New Frame dialog.

This function displays a dialog that allows creating a new frame.

Parameters:
[in] button the button which was clicked to trigger the handler
[in] user_data a pointer to the main GUI's GtkBuilder, currently not used

Definition at line 306 of file frame-new-dialog.c.

00307 {
00308     synema_instance_t   *inst           = synema_instance ();
00309     frame_t             *frame          = NULL;
00310     gchar               *path           = NULL;
00311     gchar               *cur_plugin     = NULL;
00312     gchar               *dlg_objects[]  = {"new_frame_dialog", "type_store", "time_store", "machine_store", "window-new_image", NULL};
00313     GError              *err            = NULL;
00314     GtkCellRenderer     *renderer       = NULL;
00315     GtkTreeIter         iter            = {0};
00316     GtkWidget           *dialog         = NULL;
00317     GtkWidget           *machine        = NULL;
00318     GtkWidget           *tooltype       = NULL;
00319     GtkWidget           *period         = NULL;
00320     GValue              value           = {0,};
00321     machine_t           *cur_machine    = NULL;
00322     plugin_t            *plugin         = NULL;
00323     size_ratio_t        cur_size        = NORMAL;
00324     time_period_t       *cur_period     = NULL;
00325 
00326 
00327     // Add a new dialog to the builder
00328     path = g_strdup_printf ("%s/window.ui", inst->data_dir);
00329     gtk_builder_add_objects_from_file (inst->builder, path, dlg_objects, &err);
00330     g_free (path);
00331     if (err) {
00332         g_warning ("frame_on_new: %s", err->message);
00333         g_clear_error (&err);
00334         return;
00335     }
00336 
00337 
00338     // Machines combo box
00339     machine = (GtkWidget *) gtk_builder_get_object (inst->builder, "machine_combo");
00340     renderer = gtk_cell_renderer_text_new ();
00341     gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (machine), renderer, FALSE);
00342     gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (machine), renderer,
00343                                     "text", 0, NULL);
00344 
00345     frame_populate_machine_combo (machine, inst->machines_list, NULL);
00346     g_signal_connect (machine, "changed",
00347                     G_CALLBACK (frame_new_dialog_machine_changed),
00348                     (gpointer) &plugin);
00349 
00350 
00351     // Monitoring tool combo box
00352     tooltype = (GtkWidget *) gtk_builder_get_object (inst->builder, "type_combo");
00353     renderer = gtk_cell_renderer_text_new ();
00354     gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (tooltype), renderer, FALSE);
00355     gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (tooltype), renderer,
00356                                     "text", 0, NULL);
00357 
00358     if (gtk_combo_box_get_active_iter (GTK_COMBO_BOX (machine), &iter)) {
00359         gtk_tree_model_get_value (gtk_combo_box_get_model (GTK_COMBO_BOX(machine)),
00360                                 &iter, 1, &value);
00361         cur_machine = (machine_t *) g_value_get_pointer (&value);
00362         g_value_unset (&value);
00363     }
00364 
00365     frame_populate_tool_type_combo (tooltype, cur_machine, NULL);
00366     g_signal_connect (tooltype, "changed",
00367                     G_CALLBACK (frame_new_dialog_tool_type_changed),
00368                     (gpointer) &plugin);
00369 
00370 
00371     // Time period combo box
00372     period = (GtkWidget *) gtk_builder_get_object (inst->builder, "time_combo");
00373     renderer = gtk_cell_renderer_text_new ();
00374     gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (period), renderer, FALSE);
00375     gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (period), renderer,
00376                                     "text", 0, NULL);
00377 
00378     if (gtk_combo_box_get_active_iter (GTK_COMBO_BOX (tooltype), &iter)) {
00379         gtk_tree_model_get_value (gtk_combo_box_get_model (GTK_COMBO_BOX(tooltype)),
00380                                     &iter, 1, &value);
00381         gchar *cur_tool = g_value_dup_string (&value);
00382         plugin = plugin_list_find (cur_tool);
00383         g_free (cur_tool);
00384         g_value_unset (&value);
00385     }
00386 
00387     frame_populate_time_period_combo (period, plugin, NULL);
00388 
00389     gtk_widget_set_sensitive ((GtkWidget *) gtk_builder_get_object (inst->builder, "create_button"),
00390                             (gtk_combo_box_get_active (GTK_COMBO_BOX (tooltype)) != -1));
00391 
00392 
00393     // Now running the dialog
00394     dialog = (GtkWidget *) gtk_builder_get_object (inst->builder, "new_frame_dialog");
00395     gint result = gtk_dialog_run (GTK_DIALOG (dialog));
00396 
00397 
00398     // Exploiting the result here - it's likely that some events changed the
00399     // value of each iter during gtk_dialog_run, so we grab the values again now
00400     // that the dialog is closed.
00401     switch (result) {
00402         case GTK_RESPONSE_OK:
00403             if (gtk_combo_box_get_active_iter (GTK_COMBO_BOX (machine), &iter)) {
00404                 gtk_tree_model_get_value (gtk_combo_box_get_model (GTK_COMBO_BOX(machine)),
00405                                         &iter, 1, &value);
00406                 cur_machine = (machine_t *) g_value_get_pointer (&value);
00407                 g_value_unset (&value);
00408             }
00409 
00410             if (gtk_combo_box_get_active_iter (GTK_COMBO_BOX (tooltype), &iter)) {
00411                 gtk_tree_model_get_value (gtk_combo_box_get_model (GTK_COMBO_BOX(tooltype)),
00412                                             &iter, 1, &value);
00413                 cur_plugin = g_value_dup_string (&value);
00414                 g_value_unset (&value);
00415             }
00416 
00417             if (gtk_combo_box_get_active_iter (GTK_COMBO_BOX (period), &iter)) {
00418                 gtk_tree_model_get_value (gtk_combo_box_get_model (GTK_COMBO_BOX(period)),
00419                                             &iter, 1, &value);
00420                 cur_period = (time_period_t *) g_value_get_pointer (&value);
00421                 g_value_unset (&value);
00422             }
00423 
00424             // Turn the size to large if the large radio button is active
00425             if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON((GtkWidget *)
00426                         gtk_builder_get_object (inst->builder, "size_large"))))
00427                 cur_size = LARGE;
00428             frame = frame_new (cur_plugin);
00429             if (!frame) {
00430                 g_warning ("frame_on_new: Could not create frame of type %s", cur_plugin);
00431                 error_dialog ("<b>Failed to create frame</b>\n\nCould not create a frame for the plugin ā€˜%s’", cur_plugin);
00432             } else {
00433                 if (frame_initialise (frame, cur_size, cur_machine, cur_period) == 0) {
00434                     if (frame_table_add (inst->current_table, frame) != 0) {
00435                         g_warning ("frame_on_new: Error while adding the new frame to the table");
00436                         error_dialog ("<b>Failed to create frame</b>\n\nThe frame could not be added to the table");
00437                     }
00438                 } else {
00439                     g_warning ("frame_on_new: Error while initialising the new frame");
00440                     error_dialog ("<b>Failed to create frame</b>\n\nThe frame could not be initialised");
00441                 }
00442             }
00443             
00444             g_free (cur_plugin);
00445             break;
00446         default:
00447             break;
00448     }
00449 
00450     gtk_tree_model_foreach (gtk_combo_box_get_model (GTK_COMBO_BOX(period)),
00451                             time_period_combo_free_each,
00452                             NULL);
00453     gtk_widget_destroy (dialog);
00454 }

void frame_populate_machine_combo ( GtkWidget *  combo,
GList *  machines_list,
machine_t active_machine 
)

Fills a combo box with the list of currently available machines.

This function fills a combo box with the list of machines available from the current Synema instance.

Parameters:
[in,out] combo the combo box to populate with a list of machines
[in] machines_list the list of machines to put in the combo box
[in] active_machine the machine to set as active, NULL to ignore

Definition at line 176 of file frame-new-dialog.c.

00177 {
00178     GList               *list_iter  = NULL;
00179     GtkListStore        *store      = GTK_LIST_STORE (gtk_combo_box_get_model (GTK_COMBO_BOX(combo)));
00180     GtkTreeIter         iter        = {0};
00181 
00182     gtk_list_store_clear (store);
00183 
00184     if (machines_list) {
00185         list_iter = machines_list;
00186         do {
00187             machine_t *mac = list_iter->data;
00188             const char *name = machine_get_display_name (mac);
00189             gtk_list_store_append (store, &iter);
00190             gtk_list_store_set (store, &iter, 0, name, 1, (gpointer)mac, -1);
00191 
00192             if (machine_cmp (active_machine, mac) == 0)
00193                 gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combo), &iter);
00194         } while ((list_iter = g_list_next (list_iter)) != NULL);
00195     }
00196 
00197     gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store), 0, GTK_SORT_ASCENDING);
00198     if (gtk_combo_box_get_active (GTK_COMBO_BOX (combo)) == -1)
00199         gtk_combo_box_set_active (GTK_COMBO_BOX (combo), 0);
00200 }

void frame_populate_time_period_combo ( GtkWidget *  combo,
plugin_t plugin,
time_period_t active_period 
)

Fills a combo box with the list of time periods available for a given plugin.

This function fills a combo box with a list time periods available for a plugin passed in parameter. The combobox's model must be (gchararray, gpointer). The third parameter can either be NULL or a valid time period. If it's not NULL and if a line of the combobox matches it, then this line will be defined as active.

Parameters:
[in,out] combo the combo box to populate with a list of time periods
[in] plugin a pointer to the plugin representing the current plugin type
[in] active_period the time period to set as active in the box, NULL to ignore

Definition at line 67 of file frame-new-dialog.c.

00068 {
00069     gchar               *name       = NULL;
00070     GtkListStore        *store      = GTK_LIST_STORE (gtk_combo_box_get_model (GTK_COMBO_BOX(combo)));
00071     GtkTreeIter         iter        = {0};
00072     GList               *list       = NULL;
00073     GList               *list_iter  = NULL;
00074 
00075     gtk_tree_model_foreach (GTK_TREE_MODEL (store),
00076                             time_period_combo_free_each,
00077                             NULL);
00078     gtk_list_store_clear (store);
00079 
00080     if (plugin)
00081         list = plugin_get_time_periods (plugin);
00082     else
00083         return;
00084 
00085     if (list) {
00086         list_iter = list;
00087         do {
00088             time_period_t *p = list_iter->data;
00089             name = time_period_get_display_name (p, TRUE);
00090             gtk_list_store_append (store, &iter);
00091             gtk_list_store_set (store, &iter, 0, name, 1, (gpointer) p, -1);
00092             g_free (name);
00093 
00094             if (time_period_cmp (p, active_period) == 0)
00095                 gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combo), &iter);
00096         } while ((list_iter = g_list_next (list_iter)) != NULL);
00097 
00098         g_list_free (list);
00099     }
00100 
00101     if (gtk_combo_box_get_active (GTK_COMBO_BOX (combo)) == -1)
00102         gtk_combo_box_set_active (GTK_COMBO_BOX (combo), 0);
00103 }

void frame_populate_tool_type_combo ( GtkWidget *  combo,
machine_t machine,
gchar *  active_tool 
)

Fills a combo box with the list of plugins available for a given machine.

This function fills a combo box with a list of plugins available for a machine passed in parameter. The combobox's model must be (gchararray, gchararray). The third parameter can either be NULL or a valid plugin type. If it's not NULL and if a line of the combobox matches it, then this line will be defined as active.

Parameters:
[in,out] combo the combo box to populate with a list of plugins
[in] machine the machine whose plugins list will be used
[in] active_tool the plugin type to set as active in the box, NULL to ignore

Definition at line 114 of file frame-new-dialog.c.

00115 {
00116     synema_instance_t   *inst   = synema_instance ();
00117     GList               *list   = NULL;
00118     GtkListStore        *store  = GTK_LIST_STORE (gtk_combo_box_get_model (GTK_COMBO_BOX(combo)));
00119     GtkTreeIter         iter    = {0};
00120 
00121     gtk_list_store_clear (store);
00122 
00123     if (machine) {
00124         if (machine_is_all_machines (machine)) {
00125             char    *name       = NULL;
00126             char    *prev       = NULL;
00127             GList   *maciter    = inst->machines_list;
00128             GList   *allplugins = g_list_copy (machine->monitoring_tools);
00129             GList   *pliter     = NULL;
00130 
00131             if (maciter) {
00132                 do {
00133                     machine_t *tmpmac = maciter->data;
00134                     pliter = g_list_copy (tmpmac->monitoring_tools);
00135                     if (pliter)
00136                         allplugins = g_list_concat (allplugins, pliter);
00137                 } while ((maciter = g_list_next (maciter)) != NULL);
00138             }
00139 
00140             allplugins = g_list_sort (allplugins, g_strcmp0_func);
00141 
00142             if (allplugins) {
00143                 pliter = allplugins;
00144                 do {
00145                     prev = name;
00146                     name = pliter->data;
00147                     if (!g_strcmp0 (prev, name) == 0) {
00148                         gtk_list_store_append (store, &iter);
00149                         gtk_list_store_set (store, &iter, 0, plugin_get_display_name (plugin_list_find (name)), 1, name, -1);
00150                         if (g_strcmp0 (name, active_tool) == 0)
00151                             gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combo), &iter);
00152                     }
00153                 } while ((pliter = g_list_next (pliter)) != NULL);
00154             }
00155             g_list_free (allplugins);
00156         
00157         } else if (machine->monitoring_tools) {
00158             list = machine->monitoring_tools;
00159             do {
00160                 char *tool = list->data;
00161                 gtk_list_store_append (store, &iter);
00162                 gtk_list_store_set (store, &iter, 0, plugin_get_display_name (plugin_list_find (tool)), 1, tool, -1);
00163                 if (g_strcmp0 (tool, active_tool) == 0)
00164                     gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combo), &iter);
00165             } while ((list = g_list_next (list)) != NULL);
00166         }
00167     }
00168 
00169     gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store), 0, GTK_SORT_ASCENDING);
00170     if (gtk_combo_box_get_active (GTK_COMBO_BOX (combo)) == -1)
00171         gtk_combo_box_set_active (GTK_COMBO_BOX (combo), 0);
00172 }

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines

Generated on Tue Jan 12 00:48:44 2010 for ENSIBSynema by  doxygen 1.6.1