diff options
author | Leandro A. F. Pereira <leandro@hardinfo.org> | 2009-05-03 12:24:48 -0300 |
---|---|---|
committer | Leandro A. F. Pereira <leandro@hardinfo.org> | 2009-05-03 12:24:48 -0300 |
commit | efbc771b490d50279b3b9cacfd5f4e9ca8621a68 (patch) | |
tree | a28b95408b25c236506b5b4362cdab436591d549 /hardinfo2/remote.c | |
parent | 6553dc00fe6d10baaa3b3faaddedace625f90c5a (diff) |
Change module.getModuleList(), so it also sends the module's icon filename. Stability fixes to the remote feature.
Diffstat (limited to 'hardinfo2/remote.c')
-rw-r--r-- | hardinfo2/remote.c | 343 |
1 files changed, 198 insertions, 145 deletions
diff --git a/hardinfo2/remote.c b/hardinfo2/remote.c index dff44d03..026f7d75 100644 --- a/hardinfo2/remote.c +++ b/hardinfo2/remote.c @@ -65,28 +65,31 @@ typedef struct _RemoteDialog RemoteDialog; struct _RemoteDialog { - GtkWidget *dialog; - GtkWidget *btn_connect, *btn_cancel; + GtkWidget *dialog; + GtkWidget *btn_connect, *btn_cancel; }; -static RemoteDialog *remote_dialog_new(GtkWidget *parent); +static RemoteDialog *remote_dialog_new(GtkWidget * parent); static gboolean remote_version_is_supported(void) { gint remote_ver; shell_status_update("Obtaining remote server API version..."); - remote_ver = xmlrpc_get_integer("http://localhost:4242/xmlrpc", "server.getAPIVersion", NULL); + remote_ver = + xmlrpc_get_integer("http://localhost:4242/xmlrpc", + "server.getAPIVersion", NULL); switch (remote_ver) { case -1: - g_warning("Remote Host didn't respond."); - break; + g_warning("Remote Host didn't respond."); + break; case XMLRPC_SERVER_VERSION: - return TRUE; + return TRUE; default: - g_warning("Remote Host has an unsupported API version (%d). Expected version is %d.", - remote_ver, XMLRPC_SERVER_VERSION); + g_warning + ("Remote Host has an unsupported API version (%d). Expected version is %d.", + remote_ver, XMLRPC_SERVER_VERSION); } return FALSE; @@ -96,40 +99,62 @@ static gchar *remote_module_entry_func() { Shell *shell = shell_get_main_shell(); gchar *ret; - - ret = xmlrpc_get_string("http://localhost:4242/xmlrpc", "module.entryFunction", - "%s%i", shell->selected_module_name, shell->selected->number); - + + ret = + xmlrpc_get_string("http://localhost:4242/xmlrpc", + "module.entryFunction", "%s%i", + shell->selected_module_name, + shell->selected->number); + + if (!ret) { + ret = g_strdup(""); + } + return ret; } -static void remote_module_entry_scan_func() +static void remote_module_entry_scan_func(gboolean reload) { Shell *shell = shell_get_main_shell(); - - xmlrpc_get_string("http://localhost:4242/xmlrpc", "module.entryScan", - "%s%i", shell->selected_module_name, shell->selected->number); + + if (reload) { + xmlrpc_get_string("http://localhost:4242/xmlrpc", + "module.entryReload", "%s%i", + shell->selected_module_name, + shell->selected->number); + } else { + xmlrpc_get_string("http://localhost:4242/xmlrpc", + "module.entryScan", "%s%i", + shell->selected_module_name, + shell->selected->number); + } } -static gchar *remote_module_entry_field_func(gchar *entry) +static gchar *remote_module_entry_field_func(gchar * entry) { Shell *shell = shell_get_main_shell(); gchar *ret; - - ret = xmlrpc_get_string("http://localhost:4242/xmlrpc", "module.entryGetField", - "%s%i%s", shell->selected_module_name, shell->selected->number, entry); - - return ret; + + ret = + xmlrpc_get_string("http://localhost:4242/xmlrpc", + "module.entryGetField", "%s%i%s", + shell->selected_module_name, + shell->selected->number, entry); + + return ret; } -static gchar *remote_module_entry_more_func(gchar *entry) +static gchar *remote_module_entry_more_func(gchar * entry) { Shell *shell = shell_get_main_shell(); gchar *ret; - - ret = xmlrpc_get_string("http://localhost:4242/xmlrpc", "module.entryGetMoreInfo", - "%s%i%s", shell->selected_module_name, shell->selected->number, entry); - + + ret = + xmlrpc_get_string("http://localhost:4242/xmlrpc", + "module.entryGetMoreInfo", "%s%i%s", + shell->selected_module_name, + shell->selected->number, entry); + return ret; } @@ -137,97 +162,119 @@ static gchar *remote_module_entry_note_func(gint entry) { Shell *shell = shell_get_main_shell(); gchar *note; - - note = xmlrpc_get_string("http://localhost:4242/xmlrpc", "module.entryGetNote", - "%s%i", shell->selected_module_name, shell->selected->number); + + note = + xmlrpc_get_string("http://localhost:4242/xmlrpc", + "module.entryGetNote", "%s%i", + shell->selected_module_name, + shell->selected->number); if (note && *note == '\0') { - g_free(note); - return NULL; + g_free(note); + return NULL; } - + return note; } +static ModuleAbout *remote_module_get_about() +{ + return NULL; +} + static gboolean load_module_list() { Shell *shell; GValueArray *modules; int i = 0; - + shell_status_update("Unloading local modules..."); module_unload_all(); - + shell_status_update("Obtaining remote server module list..."); - modules = xmlrpc_get_array("http://localhost:4242/xmlrpc", "module.getModuleList", NULL); + modules = + xmlrpc_get_array("http://localhost:4242/xmlrpc", + "module.getModuleList", NULL); if (!modules) { - return FALSE; + return FALSE; } - + shell = shell_get_main_shell(); - + for (; i < modules->n_values; i++) { - ShellModule *m; - ShellModuleEntry *e; - GValueArray *entries; - const gchar *module = g_value_get_string(&modules->values[i]); - int j = 0; - - m = g_new0(ShellModule, 1); - m->name = g_strdup(module); - m->icon = icon_cache_get_pixbuf("module.png"); /* FIXME */ - - shell_status_pulse(); - entries = xmlrpc_get_array("http://localhost:4242/xmlrpc", "module.getEntryList", "%s", module); - if (entries) { - for (; j < entries->n_values; j++) { - GValueArray *tuple = g_value_get_boxed(&entries->values[j]); - - e = g_new0(ShellModuleEntry, 1); - e->name = g_strdup(g_value_get_string(&tuple->values[0])); - e->icon = icon_cache_get_pixbuf(g_value_get_string(&tuple->values[1])); - e->icon_file = g_strdup(g_value_get_string(&tuple->values[1])); - e->number = j; - - e->func = remote_module_entry_func; - e->scan_func = remote_module_entry_scan_func; - e->fieldfunc = remote_module_entry_field_func; - e->morefunc = remote_module_entry_more_func; - e->notefunc = remote_module_entry_note_func; - - m->entries = g_slist_append(m->entries, e); - - shell_status_pulse(); - } - - g_value_array_free(entries); - } - - shell->tree->modules = g_slist_append(shell->tree->modules, m); + ShellModule *m; + ShellModuleEntry *e; + GValueArray *entries, *module; + int j = 0; + + module = g_value_get_boxed(&modules->values[i]); + DEBUG("%s - %s", + g_value_get_string(&module->values[0]), + g_value_get_string(&module->values[1])); + + m = g_new0(ShellModule, 1); + m->name = g_strdup(g_value_get_string(&module->values[0])); + m->icon = icon_cache_get_pixbuf(g_value_get_string(&module->values[1])); + m->aboutfunc = (gpointer) remote_module_get_about; + + shell_status_pulse(); + entries = + xmlrpc_get_array("http://localhost:4242/xmlrpc", + "module.getEntryList", "%s", m->name); + if (entries) { + for (; j < entries->n_values; j++) { + GValueArray *tuple = + g_value_get_boxed(&entries->values[j]); + + e = g_new0(ShellModuleEntry, 1); + e->name = g_strdup(g_value_get_string(&tuple->values[0])); + e->icon = + icon_cache_get_pixbuf(g_value_get_string + (&tuple->values[1])); + e->icon_file = + g_strdup(g_value_get_string(&tuple->values[1])); + e->number = j; + + e->func = remote_module_entry_func; + e->scan_func = remote_module_entry_scan_func; + e->fieldfunc = remote_module_entry_field_func; + e->morefunc = remote_module_entry_more_func; + e->notefunc = remote_module_entry_note_func; + + m->entries = g_slist_append(m->entries, e); + + shell_status_pulse(); + } + + g_value_array_free(entries); + } + + shell->tree->modules = g_slist_append(shell->tree->modules, m); } - - g_slist_foreach(shell->tree->modules, shell_add_modules_to_gui, shell->tree); + + g_slist_foreach(shell->tree->modules, shell_add_modules_to_gui, + shell->tree); gtk_tree_view_expand_all(GTK_TREE_VIEW(shell->tree->view)); - + g_value_array_free(modules); - + return TRUE; } -static void remote_connect(RemoteDialog *rd) +static void remote_connect(RemoteDialog * rd) { xmlrpc_init(); - + /* check API version */ if (remote_version_is_supported()) { - if (!load_module_list()) { - g_warning("Remote module list couldn't be loaded."); - } + if (!load_module_list()) { + g_warning("Remote module list couldn't be loaded."); + } } - + shell_status_update("Done."); } -void remote_dialog_show(GtkWidget *parent) +void remote_dialog_show(GtkWidget * parent) { gboolean success; RemoteDialog *rd = remote_dialog_new(parent); @@ -236,9 +283,9 @@ void remote_dialog_show(GtkWidget *parent) gtk_widget_hide(rd->dialog); shell_view_set_enabled(FALSE); shell_status_set_enabled(TRUE); - + remote_connect(rd); - + shell_status_set_enabled(FALSE); shell_view_set_enabled(TRUE); } @@ -252,52 +299,55 @@ static void populate_store(GtkListStore * store) GKeyFile *remote; GtkTreeIter iter; gchar *path; - + gtk_list_store_clear(store); gtk_list_store_append(store, &iter); gtk_list_store_set(store, &iter, - 0, icon_cache_get_pixbuf("home.png"), - 1, g_strdup("Local Computer"), - 2, GINT_TO_POINTER(-1), - -1); + 0, icon_cache_get_pixbuf("home.png"), + 1, g_strdup("Local Computer"), + 2, GINT_TO_POINTER(-1), -1); remote = g_key_file_new(); - path = g_build_filename(g_get_home_dir(), ".hardinfo", "remote.conf", NULL); + path = + g_build_filename(g_get_home_dir(), ".hardinfo", "remote.conf", + NULL); if (g_key_file_load_from_file(remote, path, 0, NULL)) { - gint no_hosts, i; - - no_hosts = g_key_file_get_integer(remote, "global", "no_hosts", NULL); - for (i = 0; i < no_hosts; i++) { - gchar *hostname; - gchar *hostgroup; - gchar *icon; - - hostgroup = g_strdup_printf("host%d", i); - - hostname = g_key_file_get_string(remote, hostgroup, "name", NULL); - icon = g_key_file_get_string(remote, hostgroup, "icon", NULL); - - gtk_list_store_append(store, &iter); - gtk_list_store_set(store, &iter, - 0, icon_cache_get_pixbuf(icon ? icon : "server.png"), - 1, hostname, - 2, GINT_TO_POINTER(i), - -1); - - g_free(hostgroup); - g_free(icon); - } + gint no_hosts, i; + + no_hosts = + g_key_file_get_integer(remote, "global", "no_hosts", NULL); + for (i = 0; i < no_hosts; i++) { + gchar *hostname; + gchar *hostgroup; + gchar *icon; + + hostgroup = g_strdup_printf("host%d", i); + + hostname = + g_key_file_get_string(remote, hostgroup, "name", NULL); + icon = g_key_file_get_string(remote, hostgroup, "icon", NULL); + + gtk_list_store_append(store, &iter); + gtk_list_store_set(store, &iter, + 0, + icon_cache_get_pixbuf(icon ? icon : + "server.png"), 1, + hostname, 2, GINT_TO_POINTER(i), -1); + + g_free(hostgroup); + g_free(icon); + } } - + g_free(path); g_key_file_free(remote); } -static GtkWidget *host_editor_dialog_new(GtkWidget *parent, gchar *title) +static GtkWidget *host_editor_dialog_new(GtkWidget * parent, gchar * title) { GtkWidget *dialog, *dialog1_action_area, *button7, *button8; - + dialog = gtk_dialog_new(); gtk_window_set_title(GTK_WINDOW(dialog), title); gtk_container_set_border_width(GTK_CONTAINER(dialog), 5); @@ -328,53 +378,56 @@ static GtkWidget *host_editor_dialog_new(GtkWidget *parent, gchar *title) return dialog; } -static void remote_dialog_add(GtkWidget *button, gpointer data) +static void remote_dialog_add(GtkWidget * button, gpointer data) { - RemoteDialog *rd = (RemoteDialog *)data; - GtkWidget *host_editor = host_editor_dialog_new(rd->dialog, "Add a host"); + RemoteDialog *rd = (RemoteDialog *) data; + GtkWidget *host_editor = + host_editor_dialog_new(rd->dialog, "Add a host"); if (gtk_dialog_run(GTK_DIALOG(host_editor)) == GTK_RESPONSE_ACCEPT) { - DEBUG("saving"); + DEBUG("saving"); } gtk_widget_destroy(host_editor); } -static void remote_dialog_edit(GtkWidget *button, gpointer data) +static void remote_dialog_edit(GtkWidget * button, gpointer data) { - RemoteDialog *rd = (RemoteDialog *)data; - GtkWidget *host_editor = host_editor_dialog_new(rd->dialog, "Edit a host"); + RemoteDialog *rd = (RemoteDialog *) data; + GtkWidget *host_editor = + host_editor_dialog_new(rd->dialog, "Edit a host"); if (gtk_dialog_run(GTK_DIALOG(host_editor)) == GTK_RESPONSE_ACCEPT) { - DEBUG("saving"); + DEBUG("saving"); } gtk_widget_destroy(host_editor); } -static void remote_dialog_remove(GtkWidget *button, gpointer data) +static void remote_dialog_remove(GtkWidget * button, gpointer data) { - RemoteDialog *rd = (RemoteDialog *)data; + RemoteDialog *rd = (RemoteDialog *) data; GtkWidget *dialog; dialog = gtk_message_dialog_new(GTK_WINDOW(rd->dialog), - GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_QUESTION, - GTK_BUTTONS_NONE, - "Remove the host <b>%s</b>?", "selected.host.name"); + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_QUESTION, + GTK_BUTTONS_NONE, + "Remove the host <b>%s</b>?", + "selected.host.name"); gtk_dialog_add_buttons(GTK_DIALOG(dialog), - GTK_STOCK_NO, GTK_RESPONSE_REJECT, - GTK_STOCK_DELETE, GTK_RESPONSE_ACCEPT, NULL); + GTK_STOCK_NO, GTK_RESPONSE_REJECT, + GTK_STOCK_DELETE, GTK_RESPONSE_ACCEPT, NULL); if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) { - DEBUG("removing"); + DEBUG("removing"); } gtk_widget_destroy(dialog); } -static RemoteDialog *remote_dialog_new(GtkWidget *parent) +static RemoteDialog *remote_dialog_new(GtkWidget * parent) { RemoteDialog *rd; GtkWidget *dialog; @@ -426,15 +479,14 @@ static RemoteDialog *remote_dialog_new(GtkWidget *parent) FALSE, FALSE, 0); gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, TRUE, 0); gtk_widget_show_all(hbox); - + hbox = gtk_hbox_new(FALSE, 5); gtk_box_pack_start(GTK_BOX(dialog1_vbox), hbox, TRUE, TRUE, 0); gtk_widget_show(hbox); scrolledwindow2 = gtk_scrolled_window_new(NULL, NULL); gtk_widget_show(scrolledwindow2); - gtk_box_pack_start(GTK_BOX(hbox), scrolledwindow2, TRUE, TRUE, - 0); + gtk_box_pack_start(GTK_BOX(hbox), scrolledwindow2, TRUE, TRUE, 0); gtk_widget_set_size_request(scrolledwindow2, -1, 200); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwindow2), GTK_POLICY_AUTOMATIC, @@ -442,7 +494,8 @@ static RemoteDialog *remote_dialog_new(GtkWidget *parent) gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW (scrolledwindow2), GTK_SHADOW_IN); - store = gtk_list_store_new(3, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_INT); + store = + gtk_list_store_new(3, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_INT); model = GTK_TREE_MODEL(store); treeview2 = gtk_tree_view_new_with_model(model); @@ -464,7 +517,7 @@ static RemoteDialog *remote_dialog_new(GtkWidget *parent) TREE_COL_NAME); populate_store(store); - + vbuttonbox3 = gtk_vbutton_box_new(); gtk_widget_show(vbuttonbox3); gtk_box_pack_start(GTK_BOX(hbox), vbuttonbox3, FALSE, TRUE, 0); |