149 lines
5.2 KiB
C
149 lines
5.2 KiB
C
//
|
|
// Created by xajhuang on 2023/4/12.
|
|
//
|
|
#include <gtk/gtk.h>
|
|
|
|
typedef enum {
|
|
COL_VNI = 0,
|
|
COL_MAC,
|
|
COL_HOSTNAME,
|
|
COL_STEP,
|
|
COL_RESULT,
|
|
COL_STATUS,
|
|
NUM_COLS
|
|
} COL_NAME;
|
|
|
|
static GtkBuilder *g_main_builder;
|
|
|
|
static void load_css(void) {
|
|
GtkCssProvider *provider;
|
|
GdkDisplay *display;
|
|
GdkScreen *screen;
|
|
GFile *css_fp = g_file_new_for_path("./res/style.css");
|
|
GError *error = 0;
|
|
|
|
provider = gtk_css_provider_new();
|
|
display = gdk_display_get_default();
|
|
screen = gdk_display_get_default_screen(display);
|
|
|
|
gtk_style_context_add_provider_for_screen(screen,
|
|
GTK_STYLE_PROVIDER(provider),
|
|
GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
|
|
|
|
gtk_css_provider_load_from_file(provider, css_fp, &error);
|
|
}
|
|
|
|
G_MODULE_EXPORT void __mainWnd_on_destroy(GObject *object, gpointer user_data) {
|
|
gtk_main_quit();
|
|
}
|
|
|
|
static void add_item_to_list_view(GtkWidget *list,
|
|
int idx,
|
|
const char *pMac,
|
|
const char *pHostname,
|
|
const char *pDiscover,
|
|
const char *pOffer,
|
|
const char *pRequest,
|
|
const char *pAck) {
|
|
int i, j;
|
|
GtkTreeIter iter, iter_child, iter_sub;
|
|
GtkTreeStore *store = GTK_TREE_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(list)));
|
|
|
|
for (i = 0; i < 1000; i++) {
|
|
char buf[24] = {0};
|
|
char bufHost[32] = {0};
|
|
char bufVni[16] = {0};
|
|
|
|
sprintf(bufVni, "%d", i);
|
|
sprintf(bufHost, "hostname%d", i);
|
|
sprintf(buf, "06:01:02:%02X:%02X:%02X", (i & 0xFF0000) >> 16, (i & 0xFF00) >> 8, (i & 0xFF));
|
|
|
|
gtk_tree_store_append(store, &iter, NULL);
|
|
// clang-format off
|
|
gtk_tree_store_set(store, &iter,
|
|
COL_VNI, bufVni,
|
|
COL_MAC, buf,
|
|
COL_HOSTNAME, bufHost,
|
|
COL_STATUS, 20.0,
|
|
-1);
|
|
gtk_tree_store_append(store, &iter_child, &iter);
|
|
gtk_tree_store_set(store, &iter_child,
|
|
COL_VNI, "",
|
|
COL_STEP, "Discover",
|
|
COL_RESULT, "",
|
|
COL_STATUS, 10.0,
|
|
-1);
|
|
gtk_tree_store_append(store, &iter_child, &iter);
|
|
gtk_tree_store_set(store, &iter_child,
|
|
COL_VNI, "",
|
|
COL_STEP, "Offer",
|
|
COL_RESULT, "",
|
|
COL_STATUS, 10.0,
|
|
-1);
|
|
|
|
gtk_tree_store_append(store, &iter_child, &iter);
|
|
gtk_tree_store_set(store, &iter_child,
|
|
COL_VNI, "",
|
|
COL_STEP, "Request",
|
|
COL_RESULT, "",
|
|
COL_STATUS, 10.0,
|
|
-1);
|
|
gtk_tree_store_append(store, &iter_child, &iter);
|
|
gtk_tree_store_set(store, &iter_child,
|
|
COL_VNI, "",
|
|
COL_STEP, "ACK",
|
|
COL_RESULT, "",
|
|
COL_STATUS, 10.0,
|
|
-1);
|
|
// clang-format on
|
|
}
|
|
}
|
|
|
|
int main(int argc, char **argv) {
|
|
gtk_init(&argc, &argv);
|
|
load_css();
|
|
|
|
g_main_builder = gtk_builder_new();
|
|
gtk_builder_add_from_file(g_main_builder, "./res/main.glade", NULL);
|
|
|
|
GtkWidget *mainWnd = GTK_WIDGET(gtk_builder_get_object(g_main_builder, "wndMain"));
|
|
|
|
GtkWidget *macTxt = GTK_WIDGET(gtk_builder_get_object(g_main_builder, "txtMacStart"));
|
|
//gtk_style_context_add_class(gtk_widget_get_style_context(GTK_WIDGET(macTxt)), "txtMacStart");
|
|
|
|
GtkWidget *numInc = GTK_WIDGET(gtk_builder_get_object(g_main_builder, "sbReqNum"));
|
|
GtkAdjustment *adj = gtk_adjustment_new(1000, 1, 100000, 1, 0, 0);
|
|
gtk_spin_button_set_adjustment(GTK_SPIN_BUTTON(numInc), adj);
|
|
|
|
GtkWidget *numVni = GTK_WIDGET(gtk_builder_get_object(g_main_builder, "sbVni"));
|
|
GtkAdjustment *adjVni = gtk_adjustment_new(1, 1, 10000000, 1, 0, 0);
|
|
gtk_spin_button_set_adjustment(GTK_SPIN_BUTTON(numVni), adjVni);
|
|
#if 1
|
|
GtkWidget *view = GTK_WIDGET(gtk_builder_get_object(g_main_builder, "treeResult"));
|
|
GtkTreeStore *store = GTK_TREE_STORE(gtk_builder_get_object(g_main_builder, "tsDhcpInfo"));
|
|
#if 0
|
|
gtk_list_store_new(NUM_COLS,
|
|
G_TYPE_INT,
|
|
G_TYPE_STRING,
|
|
G_TYPE_STRING,
|
|
G_TYPE_STRING,
|
|
G_TYPE_STRING,
|
|
G_TYPE_STRING,
|
|
G_TYPE_STRING,
|
|
G_TYPE_FLOAT);
|
|
#endif
|
|
gtk_tree_view_set_model(GTK_TREE_VIEW(view), GTK_TREE_MODEL(store));
|
|
|
|
add_item_to_list_view(view, 0, NULL, NULL, NULL, NULL, NULL, NULL);
|
|
g_object_unref(store);
|
|
|
|
#endif
|
|
|
|
gtk_builder_connect_signals(g_main_builder, NULL);
|
|
//g_object_unref(G_OBJECT(g_main_builder));
|
|
gtk_widget_show(mainWnd);
|
|
|
|
gtk_main();
|
|
|
|
return 0;
|
|
} |