diff options
| author | Leandro A. F. Pereira <leandro@hardinfo.org> | 2009-04-29 22:16:47 -0300 | 
|---|---|---|
| committer | Leandro A. F. Pereira <leandro@hardinfo.org> | 2009-04-29 22:16:47 -0300 | 
| commit | 64f6c0ba3c0f8a7d67d813cb3498987134477d83 (patch) | |
| tree | 0b3a6bbb709852e6863bf25c9fb49e686980699b | |
| parent | 20731a3f2e262440e00da501452b1efe5e6f1d52 (diff) | |
Implement more remote client features
| -rw-r--r-- | hardinfo2/hardinfo.h | 2 | ||||
| -rw-r--r-- | hardinfo2/remote.c | 132 | ||||
| -rw-r--r-- | hardinfo2/shell.h | 2 | ||||
| -rw-r--r-- | hardinfo2/util.c | 11 | ||||
| -rw-r--r-- | hardinfo2/xmlrpc-client.c | 6 | 
5 files changed, 138 insertions, 15 deletions
| diff --git a/hardinfo2/hardinfo.h b/hardinfo2/hardinfo.h index 2314c043..5bad88e9 100644 --- a/hardinfo2/hardinfo.h +++ b/hardinfo2/hardinfo.h @@ -116,7 +116,7 @@ void	      module_entry_scan(ShellModuleEntry *module_entry);  gchar	     *module_entry_function(ShellModuleEntry *module_entry);  const gchar  *module_entry_get_note(ShellModuleEntry *module_entry);  gchar        *module_entry_get_field(ShellModuleEntry * module_entry, gchar * field); -gchar        *module_entry_get_moreinfo(ShellModuleEntry * module_entry); +gchar        *module_entry_get_moreinfo(ShellModuleEntry * module_entry, gchar * field);  /* BinReloc stuff */ diff --git a/hardinfo2/remote.c b/hardinfo2/remote.c index 5abf3a91..f0922d3f 100644 --- a/hardinfo2/remote.c +++ b/hardinfo2/remote.c @@ -86,6 +86,46 @@ static gboolean remote_version_is_supported(void)      return FALSE;  } +static gchar *remote_module_entry_func() +{ +    Shell *shell = shell_get_main_shell(); +     +    return xmlrpc_get_string("http://localhost:4242/xmlrpc", "module.entryFunction", +                             "%s%i", shell->selected_module_name, shell->selected->number); +} + +static gchar *remote_module_entry_scan_func() +{ +    Shell *shell = shell_get_main_shell(); +     +    return 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) +{ +    Shell *shell = shell_get_main_shell(); +     +    return xmlrpc_get_string("http://localhost:4242/xmlrpc", "module.entryGetField", +                             "%s%i%s", shell->selected_module_name, shell->selected->number, entry); +} + +static gchar *remote_module_entry_more_func(gchar *entry) +{ +    Shell *shell = shell_get_main_shell(); +     +    return xmlrpc_get_string("http://localhost:4242/xmlrpc", "module.entryGetMoreInfo", +                             "%s%i%s", shell->selected_module_name, shell->selected->number, entry); +} + +static gchar *remote_module_entry_note_func(gint entry) +{ +    Shell *shell = shell_get_main_shell(); +     +    return xmlrpc_get_string("http://localhost:4242/xmlrpc", "module.entryGetNote", +                             "%s%i", shell->selected_module_name, shell->selected->number); +} +  static gboolean load_module_list()  {      GValueArray *modules; @@ -209,6 +249,86 @@ static void populate_store(GtkListStore * store)      g_key_file_free(remote);  } +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); +    gtk_window_set_default_size(GTK_WINDOW(dialog), 420, 260); +    gtk_window_set_transient_for(GTK_WINDOW(dialog), GTK_WINDOW(parent)); +    gtk_window_set_position(GTK_WINDOW(dialog), +			    GTK_WIN_POS_CENTER_ON_PARENT); +    gtk_window_set_type_hint(GTK_WINDOW(dialog), +			     GDK_WINDOW_TYPE_HINT_DIALOG); + +    dialog1_action_area = GTK_DIALOG(dialog)->action_area; +    gtk_widget_show(dialog1_action_area); +    gtk_button_box_set_layout(GTK_BUTTON_BOX(dialog1_action_area), +			      GTK_BUTTONBOX_END); + +    button8 = gtk_button_new_from_stock(GTK_STOCK_CANCEL); +    gtk_widget_show(button8); +    gtk_dialog_add_action_widget(GTK_DIALOG(dialog), button8, +				 GTK_RESPONSE_CANCEL); +    GTK_WIDGET_SET_FLAGS(button8, GTK_CAN_DEFAULT); + +    button7 = gtk_button_new_from_stock(GTK_STOCK_SAVE); +    gtk_widget_show(button7); +    gtk_dialog_add_action_widget(GTK_DIALOG(dialog), button7, +				 GTK_RESPONSE_ACCEPT); +    GTK_WIDGET_SET_FLAGS(button7, GTK_CAN_DEFAULT); + +    return dialog; +} + +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"); + +    if (gtk_dialog_run(GTK_DIALOG(host_editor)) == GTK_RESPONSE_ACCEPT) { +        DEBUG("saving"); +    } + +    gtk_widget_destroy(host_editor); +} + +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"); + +    if (gtk_dialog_run(GTK_DIALOG(host_editor)) == GTK_RESPONSE_ACCEPT) { +        DEBUG("saving"); +    } + +    gtk_widget_destroy(host_editor); +} + +static void remote_dialog_remove(GtkWidget *button, gpointer 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_add_buttons(GTK_DIALOG(dialog), +                           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"); +    } + +    gtk_widget_destroy(dialog); +} +  static RemoteDialog *remote_dialog_new(GtkWidget *parent)  {      RemoteDialog *rd; @@ -311,22 +431,22 @@ static RemoteDialog *remote_dialog_new(GtkWidget *parent)      gtk_widget_show(button3);      gtk_container_add(GTK_CONTAINER(vbuttonbox3), button3);      GTK_WIDGET_SET_FLAGS(button3, GTK_CAN_DEFAULT); -//    g_signal_connect(button3, "clicked", -//		     G_CALLBACK(remote_dialog_sel_none), rd); +    g_signal_connect(button3, "clicked", +		     G_CALLBACK(remote_dialog_add), rd);      button6 = gtk_button_new_with_mnemonic("_Edit");      gtk_widget_show(button6);      gtk_container_add(GTK_CONTAINER(vbuttonbox3), button6);      GTK_WIDGET_SET_FLAGS(button6, GTK_CAN_DEFAULT); -//    g_signal_connect(button6, "clicked", G_CALLBACK(remote_dialog_sel_all), -//		     rd); +    g_signal_connect(button6, "clicked", G_CALLBACK(remote_dialog_edit), +		     rd);      button6 = gtk_button_new_with_mnemonic("_Remove");      gtk_widget_show(button6);      gtk_container_add(GTK_CONTAINER(vbuttonbox3), button6);      GTK_WIDGET_SET_FLAGS(button6, GTK_CAN_DEFAULT); -//    g_signal_connect(button6, "clicked", G_CALLBACK(remote_dialog_sel_all), -//		     rd); +    g_signal_connect(button6, "clicked", G_CALLBACK(remote_dialog_remove), +		     rd);      dialog1_action_area = GTK_DIALOG(dialog)->action_area;      gtk_widget_show(dialog1_action_area); diff --git a/hardinfo2/shell.h b/hardinfo2/shell.h index c8e1e185..2d7c4043 100644 --- a/hardinfo2/shell.h +++ b/hardinfo2/shell.h @@ -92,6 +92,8 @@ struct _Shell {      gint		_pulses;      ShellOrderType	_order_type; +     +    gchar		*selected_module_name;  };  struct _ShellTree { diff --git a/hardinfo2/util.c b/hardinfo2/util.c index 723077cf..27e44943 100644 --- a/hardinfo2/util.c +++ b/hardinfo2/util.c @@ -407,12 +407,14 @@ void parameters_init(int *argc, char ***argv, ProgramParameters * param)  	 .arg = G_OPTION_ARG_NONE,  	 .arg_data = &autoload_deps,  	 .description = "automatically load module dependencies"}, +#ifdef HAS_LIBSOUP  	{  	 .long_name = "xmlrpc-server",  	 .short_name = 'x',  	 .arg = G_OPTION_ARG_NONE,  	 .arg_data = &run_xmlrpc_server,  	 .description = "run in XML-RPC server mode"}, +#endif	/* HAS_LIBSOUP */  	{  	 .long_name = "version",  	 .short_name = 'v', @@ -1112,7 +1114,6 @@ void module_entry_scan(ShellModuleEntry * module_entry)  gchar *module_entry_get_field(ShellModuleEntry * module_entry, gchar * field)  {     if (module_entry->fieldfunc) { -   	DEBUG("field=%s, entry=%s", field, module_entry->name);     	return module_entry->fieldfunc(field);     } @@ -1122,16 +1123,16 @@ gchar *module_entry_get_field(ShellModuleEntry * module_entry, gchar * field)  gchar *module_entry_function(ShellModuleEntry * module_entry)  {      if (module_entry->func) { -	return g_strdup(module_entry->func()); +	return module_entry->func();      } -    return g_strdup("[Error]\n" "Invalid module="); +    return NULL;  } -gchar *module_entry_get_moreinfo(ShellModuleEntry * module_entry) +gchar *module_entry_get_moreinfo(ShellModuleEntry * module_entry, gchar * field)  {      if (module_entry->morefunc) { -	return g_strdup(module_entry->morefunc(module_entry->name)); +	return module_entry->morefunc(field);      }      return NULL; diff --git a/hardinfo2/xmlrpc-client.c b/hardinfo2/xmlrpc-client.c index 81177381..ae8b1078 100644 --- a/hardinfo2/xmlrpc-client.c +++ b/hardinfo2/xmlrpc-client.c @@ -179,9 +179,9 @@ static void xmlrpc_response_get_array(SoupSession *s,  }                                  GValueArray *xmlrpc_get_array(gchar *addr, -                                     gchar *method, -                                     const gchar *param_types, -                                     ...) +                              gchar *method, +                              const gchar *param_types, +                              ...)  {      GValueArray *params, *answer = NULL;      SoupMessage *msg; | 
