diff options
Diffstat (limited to 'hardinfo2')
-rw-r--r-- | hardinfo2/callbacks.c | 26 | ||||
-rw-r--r-- | hardinfo2/callbacks.h | 2 | ||||
-rw-r--r-- | hardinfo2/hardinfo.h | 3 | ||||
-rw-r--r-- | hardinfo2/menu.c | 5 | ||||
-rw-r--r-- | hardinfo2/remote.c | 155 | ||||
-rw-r--r-- | hardinfo2/shell.c | 76 | ||||
-rw-r--r-- | hardinfo2/shell.h | 4 | ||||
-rw-r--r-- | hardinfo2/stock.c | 1 | ||||
-rw-r--r-- | hardinfo2/stock.h | 1 | ||||
-rw-r--r-- | hardinfo2/uidefs.h | 2 |
10 files changed, 201 insertions, 74 deletions
diff --git a/hardinfo2/callbacks.c b/hardinfo2/callbacks.c index 36788bd1..77cb4732 100644 --- a/hardinfo2/callbacks.c +++ b/hardinfo2/callbacks.c @@ -50,6 +50,32 @@ void cb_manage_hosts() host_manager_show(shell->window); } +void cb_connect_host(GtkAction * action) +{ + gchar *name; + + g_object_get(G_OBJECT(action), "name", &name, NULL); + remote_connect_host(name); + + g_free(name); +} + +void cb_local_computer() +{ + Shell *shell = shell_get_main_shell(); + + shell_status_update("Unloading modules..."); + module_unload_all(); + + shell_status_update("Loading local modules..."); + shell->tree->modules = modules_load_all(); + + g_slist_foreach(shell->tree->modules, shell_add_modules_to_gui, shell->tree); + gtk_tree_view_expand_all(GTK_TREE_VIEW(shell->tree->view)); + + shell_view_set_enabled(TRUE); +} + void cb_save_graphic() { Shell *shell = shell_get_main_shell(); diff --git a/hardinfo2/callbacks.h b/hardinfo2/callbacks.h index a87310f2..9f145554 100644 --- a/hardinfo2/callbacks.h +++ b/hardinfo2/callbacks.h @@ -37,5 +37,7 @@ void cb_report_bug(); void cb_donate(); void cb_connect_to(); void cb_manage_hosts(); +void cb_connect_host(GtkAction * action); +void cb_local_computer(); #endif /* __CALLBACKS_H__ */ diff --git a/hardinfo2/hardinfo.h b/hardinfo2/hardinfo.h index 5bad88e9..235036be 100644 --- a/hardinfo2/hardinfo.h +++ b/hardinfo2/hardinfo.h @@ -92,7 +92,6 @@ gpointer __idle_free(gpointer ptr, gchar *f, gint l); #define idle_free(p) __idle_free(p, __FILE__, __LINE__) #endif /* RELEASE == 1 */ - gchar *find_program(gchar *program_name); inline gchar *size_human_readable(gfloat size); void nonblock_sleep(guint msec); @@ -108,7 +107,6 @@ gchar *h_strdup_cprintf(const gchar *format, gchar *source, ...); gchar *h_strconcat(gchar *string1, ...); void h_hash_table_remove_all (GHashTable *hash_table); - void module_entry_scan_all_except(ModuleEntry *entries, gint except_entry); void module_entry_scan_all(ModuleEntry *entries); void module_entry_reload(ShellModuleEntry *module_entry); @@ -118,7 +116,6 @@ 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 * field); - /* BinReloc stuff */ gboolean binreloc_init(gboolean try_hardcoded); diff --git a/hardinfo2/menu.c b/hardinfo2/menu.c index 1f5f5fe2..3178f79d 100644 --- a/hardinfo2/menu.c +++ b/hardinfo2/menu.c @@ -62,6 +62,11 @@ static GtkActionEntry entries[] = { "_Manage hosts...", NULL, NULL, G_CALLBACK(cb_manage_hosts)}, + + {"LocalComputerAction", GTK_STOCK_HOME, + "_Local computer", NULL, + NULL, + G_CALLBACK(cb_local_computer)}, {"CopyAction", GTK_STOCK_COPY, "_Copy to Clipboard", "<control>C", diff --git a/hardinfo2/remote.c b/hardinfo2/remote.c index e0e327af..5a46f5a5 100644 --- a/hardinfo2/remote.c +++ b/hardinfo2/remote.c @@ -100,19 +100,21 @@ static HostDialog *host_dialog_new(GtkWidget * parent, HostDialogMode mode); static void host_dialog_destroy(HostDialog *hd); -static gboolean remote_version_is_supported(HostManager * rd) +static gchar *xmlrpc_server_uri = NULL; + +static gboolean remote_version_is_supported() { gint remote_ver; GtkWidget *dialog; shell_status_update("Obtaining remote server API version..."); remote_ver = - xmlrpc_get_integer("http://localhost:4242/xmlrpc", + xmlrpc_get_integer(xmlrpc_server_uri, "server.getAPIVersion", NULL); switch (remote_ver) { case -1: - dialog = gtk_message_dialog_new(GTK_WINDOW(rd->dialog), + dialog = gtk_message_dialog_new(NULL, GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, @@ -124,7 +126,7 @@ static gboolean remote_version_is_supported(HostManager * rd) case XMLRPC_SERVER_VERSION: return TRUE; default: - dialog = gtk_message_dialog_new(GTK_WINDOW(rd->dialog), + dialog = gtk_message_dialog_new(NULL, GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, @@ -146,7 +148,7 @@ static gchar *remote_module_entry_func() gchar *ret; ret = - xmlrpc_get_string("http://localhost:4242/xmlrpc", + xmlrpc_get_string(xmlrpc_server_uri, "module.entryFunction", "%s%i", shell->selected_module_name, shell->selected->number); @@ -163,12 +165,12 @@ static void remote_module_entry_scan_func(gboolean reload) Shell *shell = shell_get_main_shell(); if (reload) { - xmlrpc_get_string("http://localhost:4242/xmlrpc", + xmlrpc_get_string(xmlrpc_server_uri, "module.entryReload", "%s%i", shell->selected_module_name, shell->selected->number); } else { - xmlrpc_get_string("http://localhost:4242/xmlrpc", + xmlrpc_get_string(xmlrpc_server_uri, "module.entryScan", "%s%i", shell->selected_module_name, shell->selected->number); @@ -181,7 +183,7 @@ static gchar *remote_module_entry_field_func(gchar * entry) gchar *ret; ret = - xmlrpc_get_string("http://localhost:4242/xmlrpc", + xmlrpc_get_string(xmlrpc_server_uri, "module.entryGetField", "%s%i%s", shell->selected_module_name, shell->selected->number, entry); @@ -195,7 +197,7 @@ static gchar *remote_module_entry_more_func(gchar * entry) gchar *ret; ret = - xmlrpc_get_string("http://localhost:4242/xmlrpc", + xmlrpc_get_string(xmlrpc_server_uri, "module.entryGetMoreInfo", "%s%i%s", shell->selected_module_name, shell->selected->number, entry); @@ -209,7 +211,7 @@ static gchar *remote_module_entry_note_func(gint entry) gchar *note; note = - xmlrpc_get_string("http://localhost:4242/xmlrpc", + xmlrpc_get_string(xmlrpc_server_uri, "module.entryGetNote", "%s%i", shell->selected_module_name, shell->selected->number); @@ -226,7 +228,7 @@ static ModuleAbout *remote_module_get_about() return NULL; } -static gboolean load_module_list(HostManager * rd) +static gboolean load_module_list() { Shell *shell; GValueArray *modules; @@ -237,7 +239,7 @@ static gboolean load_module_list(HostManager * rd) shell_status_update("Obtaining remote server module list..."); modules = - xmlrpc_get_array("http://localhost:4242/xmlrpc", + xmlrpc_get_array(xmlrpc_server_uri, "module.getModuleList", NULL); if (!modules) { return FALSE; @@ -261,7 +263,7 @@ static gboolean load_module_list(HostManager * rd) shell_status_pulse(); entries = - xmlrpc_get_array("http://localhost:4242/xmlrpc", + xmlrpc_get_array(xmlrpc_server_uri, "module.getEntryList", "%s", m->name); if (entries) { for (; j < entries->n_values; j++) { @@ -303,16 +305,19 @@ static gboolean load_module_list(HostManager * rd) return TRUE; } -static void remote_connect(HostManager * rd) +static void remote_connect_direct(gchar *hostname, + gint port) { xmlrpc_init(); + + g_free(xmlrpc_server_uri); + xmlrpc_server_uri = g_strdup_printf("http://%s:%d/xmlrpc", hostname, port); - /* check API version */ - if (remote_version_is_supported(rd)) { - if (!load_module_list(rd)) { + if (remote_version_is_supported()) { + if (!load_module_list()) { GtkWidget *dialog; - dialog = gtk_message_dialog_new(GTK_WINDOW(rd->dialog), + dialog = gtk_message_dialog_new(NULL, GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, @@ -324,6 +329,53 @@ static void remote_connect(HostManager * rd) } shell_status_update("Done."); + shell_view_set_enabled(TRUE); +} + +static void remote_connect_ssh(gchar *hostname, + gint port, + gchar *username, + gchar *password) +{ + /* establish tunnel */ + /* use remote_connect_direct */ +} + +void remote_connect_host(gchar *hostname) +{ + Shell *shell = shell_get_main_shell(); + + if (!g_key_file_has_group(shell->hosts, hostname)) { + GtkWidget *dialog; + + dialog = gtk_message_dialog_new(NULL, + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_ERROR, + GTK_BUTTONS_CLOSE, + "Internal error."); + + gtk_dialog_run(GTK_DIALOG(dialog)); + gtk_widget_destroy(dialog); + + return; + } else { + const gint port = g_key_file_get_integer(shell->hosts, hostname, "port", NULL); + gchar *type = g_key_file_get_string(shell->hosts, hostname, "type", NULL); + + if (g_str_equal(type, "ssh")) { + gchar *username = g_key_file_get_string(shell->hosts, hostname, "username", NULL); + gchar *password = g_key_file_get_string(shell->hosts, hostname, "password", NULL); + + remote_connect_ssh(hostname, port, username, password); + + g_free(username); + g_free(password); + } else { + remote_connect_direct(hostname, port); + } + + g_free(type); + } } void connect_dialog_show(GtkWidget * parent) @@ -331,7 +383,18 @@ void connect_dialog_show(GtkWidget * parent) HostDialog *he = host_dialog_new(parent, "Connect to", HOST_DIALOG_MODE_CONNECT); if (gtk_dialog_run(GTK_DIALOG(he->dialog)) == GTK_RESPONSE_ACCEPT) { - DEBUG("connecting"); + gchar *hostname = (gchar *)gtk_entry_get_text(GTK_ENTRY(he->txt_hostname)); + const gint selected_type = gtk_combo_box_get_active(GTK_COMBO_BOX(he->cmb_type)); + const gint port = (int)gtk_spin_button_get_value(GTK_SPIN_BUTTON(he->txt_port)); + + if (selected_type == 1) { + gchar *username = (gchar *)gtk_entry_get_text(GTK_ENTRY(he->txt_ssh_user)); + gchar *password = (gchar *)gtk_entry_get_text(GTK_ENTRY(he->txt_ssh_password)); + + remote_connect_ssh(hostname, port, username, password); + } else { + remote_connect_direct(hostname, port); + } } host_dialog_destroy(he); @@ -342,16 +405,7 @@ void host_manager_show(GtkWidget * parent) gboolean success; HostManager *rd = host_manager_new(parent); - if (gtk_dialog_run(GTK_DIALOG(rd->dialog)) == GTK_RESPONSE_ACCEPT) { - 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); - } + gtk_dialog_run(GTK_DIALOG(rd->dialog)); host_manager_destroy(rd); } @@ -798,7 +852,21 @@ static void host_manager_edit(GtkWidget * button, gpointer data) gtk_spin_button_set_value(GTK_SPIN_BUTTON(he->txt_port), host_port ? host_port : 4242); if (gtk_dialog_run(GTK_DIALOG(he->dialog)) == GTK_RESPONSE_ACCEPT) { - DEBUG("saving"); + const gchar *type[] = { "direct", "ssh" }; + const gint selected_type = gtk_combo_box_get_active(GTK_COMBO_BOX(he->cmb_type)); + const gint port = (int)gtk_spin_button_get_value(GTK_SPIN_BUTTON(he->txt_port)); + const gchar *hostname = gtk_entry_get_text(GTK_ENTRY(he->txt_hostname)); + + g_key_file_set_string(shell->hosts, hostname, "type", type[selected_type]); + g_key_file_set_integer(shell->hosts, hostname, "port", port); + + if (selected_type == 1) { + const gchar *username = gtk_entry_get_text(GTK_ENTRY(he->txt_ssh_user)); + const gchar *password = gtk_entry_get_text(GTK_ENTRY(he->txt_ssh_password)); + + g_key_file_set_string(shell->hosts, hostname, "username", username); + g_key_file_set_string(shell->hosts, hostname, "password", password); + } } bad: @@ -869,6 +937,7 @@ static void host_manager_tree_sel_changed(GtkTreeSelection * sel, static void host_manager_destroy(HostManager * rd) { shell_save_hosts_file(); + shell_update_remote_menu(); gtk_widget_destroy(rd->dialog); g_free(rd); @@ -887,7 +956,6 @@ static HostManager *host_manager_new(GtkWidget * parent) GtkWidget *button6; GtkWidget *dialog1_action_area; GtkWidget *button8; - GtkWidget *button7; GtkWidget *button2; GtkWidget *label; GtkWidget *hbox; @@ -914,23 +982,6 @@ static HostManager *host_manager_new(GtkWidget * parent) gtk_container_set_border_width(GTK_CONTAINER(dialog1_vbox), 4); gtk_widget_show(dialog1_vbox); -/* - hbox = gtk_hbox_new(FALSE, 5); - gtk_box_pack_start(GTK_BOX(dialog1_vbox), hbox, FALSE, FALSE, 0); - - label = gtk_label_new("<big><b>Connect To</b></big>\n" - "Please choose the remote computer to connect to:"); - gtk_label_set_line_wrap(GTK_LABEL(label), TRUE); - gtk_label_set_use_markup(GTK_LABEL(label), TRUE); - gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5); - - gtk_box_pack_start(GTK_BOX(hbox), - icon_cache_get_image("server-large.png"), - 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); @@ -1007,13 +1058,6 @@ static HostManager *host_manager_new(GtkWidget * parent) GTK_RESPONSE_CANCEL); GTK_WIDGET_SET_FLAGS(button8, GTK_CAN_DEFAULT); -/* - button7 = gtk_button_new_from_stock(GTK_STOCK_CONNECT); - gtk_widget_show(button7); - gtk_dialog_add_action_widget(GTK_DIALOG(dialog), button7, - GTK_RESPONSE_ACCEPT); - GTK_WIDGET_SET_FLAGS(button7, GTK_CAN_DEFAULT); -*/ gtk_tree_view_collapse_all(GTK_TREE_VIEW(treeview2)); sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview2)); @@ -1023,7 +1067,6 @@ static HostManager *host_manager_new(GtkWidget * parent) rd->dialog = dialog; rd->btn_cancel = button8; - rd->btn_connect = button7; rd->btn_add = button3; rd->btn_edit = button6; rd->btn_remove = button2; diff --git a/hardinfo2/shell.c b/hardinfo2/shell.c index 5e7dfdc8..5bbead94 100644 --- a/hardinfo2/shell.c +++ b/hardinfo2/shell.c @@ -497,21 +497,68 @@ static void add_module_to_menu(gchar * name, GdkPixbuf * pixbuf) shell->merge_ids = g_slist_prepend(shell->merge_ids, GINT_TO_POINTER(merge_id)); } +static GSList *remote_merge_ids = NULL; +static void +add_host_to_view_menu(gchar *hostname) +{ + GtkAction *action; + gint merge_id; + GtkActionEntry entry = { + hostname, /* name */ + HI_STOCK_SERVER, /* stockid */ + hostname, /* label */ + NULL, /* accelerator */ + NULL, /* tooltip */ + (GCallback) cb_connect_host, /* callback */ + }; + + if ((action = gtk_action_group_get_action(shell->action_group, hostname))) { + gtk_action_group_remove_action(shell->action_group, action); + } + + gtk_action_group_add_actions(shell->action_group, &entry, 1, NULL /*data */); + + merge_id = gtk_ui_manager_new_merge_id(shell->ui_manager); + gtk_ui_manager_add_ui(shell->ui_manager, + merge_id, + "/menubar/RemoteMenu/RemoteLastSep", + hostname, hostname, GTK_UI_MANAGER_AUTO, FALSE); + remote_merge_ids = g_slist_prepend(remote_merge_ids, GINT_TO_POINTER(merge_id)); +} + +void shell_update_remote_menu(void) +{ + GSList *merge_id; + gchar **hosts; + gint i; + + for (merge_id = remote_merge_ids; merge_id; merge_id = merge_id->next) { + gint id = GPOINTER_TO_INT(merge_id->data); + + gtk_ui_manager_remove_ui(shell->ui_manager, id); + } + + for (i = 0, hosts = g_key_file_get_groups(shell->hosts, NULL); hosts[i]; i++) { + add_host_to_view_menu(g_strdup(hosts[i])); + } + + g_strfreev(hosts); +} + static void add_module_entry_to_view_menu(gchar * module, gchar * name, GdkPixbuf * pixbuf, GtkTreeIter * iter) { GtkAction *action; gint merge_id; - GtkActionEntry entries[] = { - { - name, /* name */ - name, /* stockid */ - name, /* label */ - NULL, /* accelerator */ - NULL, /* tooltip */ - (GCallback) view_menu_select_entry, /* callback */ - }, + gchar *path; + GtkActionEntry entry = { + name, /* name */ + name, /* stockid */ + name, /* label */ + NULL, /* accelerator */ + NULL, /* tooltip */ + (GCallback) view_menu_select_entry, /* callback */ }; stock_icon_register_pixbuf(pixbuf, name); @@ -520,14 +567,16 @@ add_module_entry_to_view_menu(gchar * module, gchar * name, gtk_action_group_remove_action(shell->action_group, action); } - gtk_action_group_add_actions(shell->action_group, entries, 1, iter); + gtk_action_group_add_actions(shell->action_group, &entry, 1, iter); merge_id = gtk_ui_manager_new_merge_id(shell->ui_manager); + path = g_strdup_printf("/menubar/ViewMenu/%s", module); gtk_ui_manager_add_ui(shell->ui_manager, merge_id, - g_strdup_printf("/menubar/ViewMenu/%s", module), + path, name, name, GTK_UI_MANAGER_AUTO, FALSE); shell->merge_ids = g_slist_prepend(shell->merge_ids, GINT_TO_POINTER(merge_id)); + g_free(path); } void shell_add_modules_to_gui(gpointer _shell_module, gpointer _shell_tree) @@ -597,7 +646,7 @@ void shell_save_hosts_file(void) remote_conf = g_key_file_to_data(shell->hosts, &length, NULL); g_file_set_contents(path, remote_conf, length, NULL); - g_chmod(path, 0700); + g_chmod(path, 0600); g_free(remote_conf); g_free(path); @@ -678,8 +727,9 @@ void shell_init(GSList * modules) g_free(path); g_atexit(shell_save_hosts_file); - } + shell_update_remote_menu(); + } #endif } diff --git a/hardinfo2/shell.h b/hardinfo2/shell.h index 4842dc2c..17a62a17 100644 --- a/hardinfo2/shell.h +++ b/hardinfo2/shell.h @@ -195,7 +195,9 @@ void shell_set_title(Shell *shell, char *subtitle); void shell_add_modules_to_gui(gpointer _shell_module, gpointer _shell_tree); -void shell_save_hosts_file(); +void shell_save_hosts_file(void); +void shell_update_remote_menu(void); + #endif /* __SHELL_H__ */ diff --git a/hardinfo2/stock.c b/hardinfo2/stock.c index 5c1a3490..ad1a0135 100644 --- a/hardinfo2/stock.c +++ b/hardinfo2/stock.c @@ -31,6 +31,7 @@ static struct { { "about-modules.png", HI_STOCK_ABOUT_MODULES}, { "syncmanager-small.png", HI_STOCK_SYNC_MENU}, { "face-grin.png", HI_STOCK_DONATE}, + { "server.png", HI_STOCK_SERVER}, }; static GtkIconFactory *icon_factory; diff --git a/hardinfo2/stock.h b/hardinfo2/stock.h index f8c61275..706e5c51 100644 --- a/hardinfo2/stock.h +++ b/hardinfo2/stock.h @@ -25,6 +25,7 @@ #define HI_STOCK_ABOUT_MODULES "hi-stock-about-modules" #define HI_STOCK_SYNC_MENU "hi-stock-sync-menu" #define HI_STOCK_DONATE "hi-stock-donate" +#define HI_STOCK_SERVER "hi-stock-server" void stock_icons_init(void); void stock_icon_register(gchar *filename, gchar *stock_id); diff --git a/hardinfo2/uidefs.h b/hardinfo2/uidefs.h index e15f4367..22289894 100644 --- a/hardinfo2/uidefs.h +++ b/hardinfo2/uidefs.h @@ -15,6 +15,7 @@ " <menuitem name=\"ConnectTo\" action=\"ConnectToAction\" />" \ " <menuitem name=\"Manage\" action=\"ManageAction\" />" \ " <separator/>" \ +" <menuitem name=\"LocalComputer\" action=\"LocalComputerAction\" />" \ " <separator name=\"RemoteLastSep\"/>" \ " </menu>" @@ -66,7 +67,6 @@ REMOTE_MENU_ITEMS " <toolitem name=\"Report\" action=\"ReportAction\"/>" \ " <toolitem name=\"Copy\" action=\"CopyAction\"/>" \ " <separator/>" \ -" <toolitem name=\"ConnectTo\" action=\"ConnectToAction\" />" \ DEBUG_TOOLBAR_ITEMS \ " </placeholder>" \ " </toolbar>" \ |