Stephen M. Cameron | ff1f328 | 2012-02-24 08:17:30 +0100 | [diff] [blame] | 1 | /* |
| 2 | * gfio - gui front end for fio - the flexible io tester |
| 3 | * |
| 4 | * Copyright (C) 2012 Stephen M. Cameron <stephenmcameron@gmail.com> |
| 5 | * |
| 6 | * The license below covers all files distributed with fio unless otherwise |
| 7 | * noted in the file itself. |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License version 2 as |
| 11 | * published by the Free Software Foundation. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 21 | * |
| 22 | */ |
| 23 | #include <gtk/gtk.h> |
| 24 | |
Stephen M. Cameron | f307400 | 2012-02-24 08:17:30 +0100 | [diff] [blame^] | 25 | #define ARRAYSIZE(x) (sizeof((x)) / (sizeof((x)[0]))) |
| 26 | |
| 27 | typedef void (*clickfunction)(GtkWidget *widget, gpointer data); |
| 28 | |
| 29 | static void quit_clicked(GtkWidget *widget, gpointer data); |
| 30 | static void start_job_clicked(GtkWidget *widget, gpointer data); |
| 31 | |
| 32 | static struct button_spec { |
| 33 | const char *buttontext; |
| 34 | clickfunction f; |
| 35 | const char *tooltiptext; |
| 36 | } buttonspeclist[] = { |
| 37 | #define START_JOB_BUTTON 0 |
| 38 | { "Start Job", |
| 39 | start_job_clicked, |
| 40 | "Send current fio job to fio server to be executed" }, |
| 41 | #define QUIT_BUTTON 1 |
| 42 | { "Quit", quit_clicked, "Quit gfio" }, |
| 43 | }; |
| 44 | |
Stephen M. Cameron | ff1f328 | 2012-02-24 08:17:30 +0100 | [diff] [blame] | 45 | struct gui { |
| 46 | GtkWidget *window; |
Stephen M. Cameron | f307400 | 2012-02-24 08:17:30 +0100 | [diff] [blame^] | 47 | GtkWidget *buttonbox; |
| 48 | GtkWidget *button[ARRAYSIZE(buttonspeclist)]; |
Stephen M. Cameron | ff1f328 | 2012-02-24 08:17:30 +0100 | [diff] [blame] | 49 | }; |
| 50 | |
| 51 | static void quit_clicked(__attribute__((unused)) GtkWidget *widget, |
| 52 | __attribute__((unused)) gpointer data) |
| 53 | { |
| 54 | gtk_main_quit(); |
| 55 | } |
| 56 | |
Stephen M. Cameron | f307400 | 2012-02-24 08:17:30 +0100 | [diff] [blame^] | 57 | static void start_job_clicked(__attribute__((unused)) GtkWidget *widget, |
| 58 | __attribute__((unused)) gpointer data) |
| 59 | { |
| 60 | printf("Start job button was clicked.\n"); |
| 61 | } |
| 62 | |
| 63 | static void add_button(struct gui *ui, int i, GtkWidget *buttonbox, |
| 64 | struct button_spec *buttonspec) |
| 65 | { |
| 66 | ui->button[i] = gtk_button_new_with_label(buttonspec->buttontext); |
| 67 | g_signal_connect(ui->button[i], "clicked", G_CALLBACK (buttonspec->f), ui); |
| 68 | gtk_box_pack_start(GTK_BOX (ui->buttonbox), ui->button[i], TRUE, TRUE, 0); |
| 69 | gtk_widget_set_tooltip_text(ui->button[i], buttonspeclist[i].tooltiptext); |
| 70 | } |
| 71 | |
| 72 | static void add_buttons(struct gui *ui, |
| 73 | struct button_spec *buttonlist, |
| 74 | int nbuttons) |
| 75 | { |
| 76 | int i; |
| 77 | |
| 78 | ui->buttonbox = gtk_hbox_new(FALSE, 0); |
| 79 | gtk_container_add(GTK_CONTAINER (ui->window), ui->buttonbox); |
| 80 | for (i = 0; i < nbuttons; i++) |
| 81 | add_button(ui, i, ui->buttonbox, &buttonlist[i]); |
| 82 | } |
| 83 | |
Stephen M. Cameron | ff1f328 | 2012-02-24 08:17:30 +0100 | [diff] [blame] | 84 | static void init_ui(int *argc, char **argv[], struct gui *ui) |
| 85 | { |
| 86 | gtk_init(argc, argv); |
| 87 | |
| 88 | ui->window = gtk_window_new(GTK_WINDOW_TOPLEVEL); |
| 89 | gtk_window_set_title(GTK_WINDOW(ui->window), "fio"); |
| 90 | gtk_window_set_default_size(GTK_WINDOW(ui->window), 700, 500); |
| 91 | |
| 92 | g_signal_connect(ui->window, "delete-event", G_CALLBACK (quit_clicked), NULL); |
| 93 | g_signal_connect(ui->window, "destroy", G_CALLBACK (quit_clicked), NULL); |
| 94 | |
Stephen M. Cameron | f307400 | 2012-02-24 08:17:30 +0100 | [diff] [blame^] | 95 | add_buttons(ui, buttonspeclist, ARRAYSIZE(buttonspeclist)); |
Stephen M. Cameron | ff1f328 | 2012-02-24 08:17:30 +0100 | [diff] [blame] | 96 | gtk_widget_show_all(ui->window); |
| 97 | } |
| 98 | |
| 99 | int main(int argc, char *argv[]) |
| 100 | { |
| 101 | struct gui ui; |
| 102 | |
| 103 | init_ui(&argc, &argv, &ui); |
| 104 | gtk_main(); |
| 105 | return 0; |
| 106 | } |