gfio: move more code to ghelpers.c
authorJens Axboe <axboe@kernel.dk>
Fri, 16 Mar 2012 11:05:17 +0000 (12:05 +0100)
committerJens Axboe <axboe@kernel.dk>
Fri, 16 Mar 2012 11:05:17 +0000 (12:05 +0100)
Signed-off-by: Jens Axboe <axboe@kernel.dk>
gfio.c
gfio.h
ghelpers.c
ghelpers.h

diff --git a/gfio.c b/gfio.c
index 675a87754777bad33f6ff8e02c2f6c4626bce319..5413da29d7fd153f82f054e91725e9b16c9d067c 100644 (file)
--- a/gfio.c
+++ b/gfio.c
@@ -76,7 +76,7 @@ static struct button_spec {
 
 static void gfio_update_thread_status(struct gui_entry *ge, char *status_message, double perc);
 static void gfio_update_thread_status_all(char *status_message, double perc);
-void report_error(GError *error);
+static void report_error(GError *error);
 
 static struct graph *setup_iops_graph(void)
 {
@@ -117,54 +117,6 @@ static void setup_graphs(struct gfio_graphs *g)
        g->bandwidth_graph = setup_bandwidth_graph();
 }
 
-static void multitext_add_entry(struct multitext_widget *mt, const char *text)
-{
-       mt->text = realloc(mt->text, (mt->max_text + 1) * sizeof(char *));
-       mt->text[mt->max_text] = strdup(text);
-       mt->max_text++;
-}
-
-static void multitext_set_entry(struct multitext_widget *mt, unsigned int index)
-{
-       if (index >= mt->max_text)
-               return;
-       if (!mt->text || !mt->text[index])
-               return;
-
-       mt->cur_text = index;
-       gtk_entry_set_text(GTK_ENTRY(mt->entry), mt->text[index]);
-}
-
-static void multitext_update_entry(struct multitext_widget *mt,
-                                  unsigned int index, const char *text)
-{
-       if (!mt->text)
-               return;
-
-       if (mt->text[index])
-               free(mt->text[index]);
-
-       mt->text[index] = strdup(text);
-       if (mt->cur_text == index)
-               gtk_entry_set_text(GTK_ENTRY(mt->entry), mt->text[index]);
-}
-
-static void multitext_free(struct multitext_widget *mt)
-{
-       int i;
-
-       gtk_entry_set_text(GTK_ENTRY(mt->entry), "");
-
-       for (i = 0; i < mt->max_text; i++) {
-               if (mt->text[i])
-                       free(mt->text[i]);
-       }
-
-       free(mt->text);
-       mt->cur_text = -1;
-       mt->max_text = 0;
-}
-
 static void clear_ge_ui_info(struct gui_entry *ge)
 {
        gtk_label_set_text(GTK_LABEL(ge->probe.hostname), "");
@@ -359,51 +311,6 @@ static void gfio_set_state(struct gui_entry *ge, unsigned int state)
        update_button_states(ge->ui, ge);
 }
 
-#define ALIGN_LEFT 1
-#define ALIGN_RIGHT 2
-#define INVISIBLE 4
-#define UNSORTABLE 8
-
-GtkTreeViewColumn *tree_view_column(GtkWidget *tree_view, int index, const char *title, unsigned int flags)
-{
-       GtkCellRenderer *renderer;
-       GtkTreeViewColumn *col;
-       double xalign = 0.0; /* left as default */
-       PangoAlignment align;
-       gboolean visible;
-
-       align = (flags & ALIGN_LEFT) ? PANGO_ALIGN_LEFT :
-               (flags & ALIGN_RIGHT) ? PANGO_ALIGN_RIGHT :
-               PANGO_ALIGN_CENTER;
-       visible = !(flags & INVISIBLE);
-
-       renderer = gtk_cell_renderer_text_new();
-       col = gtk_tree_view_column_new();
-
-       gtk_tree_view_column_set_title(col, title);
-       if (!(flags & UNSORTABLE))
-               gtk_tree_view_column_set_sort_column_id(col, index);
-       gtk_tree_view_column_set_resizable(col, TRUE);
-       gtk_tree_view_column_pack_start(col, renderer, TRUE);
-       gtk_tree_view_column_add_attribute(col, renderer, "text", index);
-       gtk_object_set(GTK_OBJECT(renderer), "alignment", align, NULL);
-       switch (align) {
-       case PANGO_ALIGN_LEFT:
-               xalign = 0.0;
-               break;
-       case PANGO_ALIGN_CENTER:
-               xalign = 0.5;
-               break;
-       case PANGO_ALIGN_RIGHT:
-               xalign = 1.0;
-               break;
-       }
-       gtk_cell_renderer_set_alignment(GTK_CELL_RENDERER(renderer), xalign, 0.5);
-       gtk_tree_view_column_set_visible(col, visible);
-       gtk_tree_view_append_column(GTK_TREE_VIEW(tree_view), col);
-       return col;
-}
-
 static void gfio_ui_setup_log(struct gui *ui)
 {
        GtkTreeSelection *selection;
@@ -1993,7 +1900,7 @@ static void on_info_bar_response(GtkWidget *widget, gint response,
        }
 }
 
-void report_error(GError *error)
+static void report_error(GError *error)
 {
        struct gui *ui = &main_ui;
 
diff --git a/gfio.h b/gfio.h
index 3b572041107c8e5c8cec3887fcb53ab5e9db64ee..d115f7c75b7a204df68b5bc279a3be6c6e974e24 100644 (file)
--- a/gfio.h
+++ b/gfio.h
@@ -3,6 +3,8 @@
 
 #include <gtk/gtk.h>
 
+#include "ghelpers.h"
+
 struct probe_widget {
        GtkWidget *hostname;
        GtkWidget *os;
@@ -10,13 +12,6 @@ struct probe_widget {
        GtkWidget *fio_ver;
 };
 
-struct multitext_widget {
-       GtkWidget *entry;
-       char **text;
-       unsigned int cur_text;
-       unsigned int max_text;
-};
-
 struct eta_widget {
        GtkWidget *names;
        struct multitext_widget iotype;
index d49af10ef20b0b2e046661472b7baa8ec0aee0e0..e2e8192c974fdd66ad7af1262d6ed54fdbeb7523 100644 (file)
@@ -1,5 +1,9 @@
+#include <stdlib.h>
+#include <string.h>
 #include <gtk/gtk.h>
 
+#include "ghelpers.h"
+
 GtkWidget *new_combo_entry_in_frame(GtkWidget *box, const char *label)
 {
        GtkWidget *entry, *frame;
@@ -69,3 +73,91 @@ void entry_set_int_value(GtkWidget *entry, unsigned int val)
        sprintf(tmp, "%u", val);
        gtk_entry_set_text(GTK_ENTRY(entry), tmp);
 }
+
+GtkTreeViewColumn *tree_view_column(GtkWidget *tree_view, int index, const char *title, unsigned int flags)
+{
+       GtkCellRenderer *renderer;
+       GtkTreeViewColumn *col;
+       double xalign = 0.0; /* left as default */
+       PangoAlignment align;
+       gboolean visible;
+
+       align = (flags & ALIGN_LEFT) ? PANGO_ALIGN_LEFT :
+               (flags & ALIGN_RIGHT) ? PANGO_ALIGN_RIGHT :
+               PANGO_ALIGN_CENTER;
+       visible = !(flags & INVISIBLE);
+
+       renderer = gtk_cell_renderer_text_new();
+       col = gtk_tree_view_column_new();
+
+       gtk_tree_view_column_set_title(col, title);
+       if (!(flags & UNSORTABLE))
+               gtk_tree_view_column_set_sort_column_id(col, index);
+       gtk_tree_view_column_set_resizable(col, TRUE);
+       gtk_tree_view_column_pack_start(col, renderer, TRUE);
+       gtk_tree_view_column_add_attribute(col, renderer, "text", index);
+       gtk_object_set(GTK_OBJECT(renderer), "alignment", align, NULL);
+       switch (align) {
+       case PANGO_ALIGN_LEFT:
+               xalign = 0.0;
+               break;
+       case PANGO_ALIGN_CENTER:
+               xalign = 0.5;
+               break;
+       case PANGO_ALIGN_RIGHT:
+               xalign = 1.0;
+               break;
+       }
+       gtk_cell_renderer_set_alignment(GTK_CELL_RENDERER(renderer), xalign, 0.5);
+       gtk_tree_view_column_set_visible(col, visible);
+       gtk_tree_view_append_column(GTK_TREE_VIEW(tree_view), col);
+       return col;
+}
+
+void multitext_add_entry(struct multitext_widget *mt, const char *text)
+{
+       mt->text = realloc(mt->text, (mt->max_text + 1) * sizeof(char *));
+       mt->text[mt->max_text] = strdup(text);
+       mt->max_text++;
+}
+
+void multitext_set_entry(struct multitext_widget *mt, unsigned int index)
+{
+       if (index >= mt->max_text)
+               return;
+       if (!mt->text || !mt->text[index])
+               return;
+
+       mt->cur_text = index;
+       gtk_entry_set_text(GTK_ENTRY(mt->entry), mt->text[index]);
+}
+
+void multitext_update_entry(struct multitext_widget *mt, unsigned int index,
+                           const char *text)
+{
+       if (!mt->text)
+               return;
+
+       if (mt->text[index])
+               free(mt->text[index]);
+
+       mt->text[index] = strdup(text);
+       if (mt->cur_text == index)
+               gtk_entry_set_text(GTK_ENTRY(mt->entry), mt->text[index]);
+}
+
+void multitext_free(struct multitext_widget *mt)
+{
+       int i;
+
+       gtk_entry_set_text(GTK_ENTRY(mt->entry), "");
+
+       for (i = 0; i < mt->max_text; i++) {
+               if (mt->text[i])
+                       free(mt->text[i]);
+       }
+
+       free(mt->text);
+       mt->cur_text = -1;
+       mt->max_text = 0;
+}
index c98b6122ed32d9d6c43c214a6994fa463d1c0d90..dec147fe717420928d57895f71e4b5f2a4e2cab6 100644 (file)
@@ -8,4 +8,25 @@ GtkWidget *create_spinbutton(GtkWidget *hbox, double min, double max, double def
 void label_set_int_value(GtkWidget *entry, unsigned int val);
 void entry_set_int_value(GtkWidget *entry, unsigned int val);
 
+
+struct multitext_widget {
+       GtkWidget *entry;
+       char **text;
+       unsigned int cur_text;
+       unsigned int max_text;
+};
+
+void multitext_add_entry(struct multitext_widget *mt, const char *text);
+void multitext_set_entry(struct multitext_widget *mt, unsigned int index);
+void multitext_update_entry(struct multitext_widget *mt, unsigned int index,
+                           const char *text);
+void multitext_free(struct multitext_widget *mt);
+
+#define ALIGN_LEFT 1
+#define ALIGN_RIGHT 2
+#define INVISIBLE 4
+#define UNSORTABLE 8
+
+GtkTreeViewColumn *tree_view_column(GtkWidget *tree_view, int index, const char *title, unsigned int flags);
+
 #endif