📄 prefs_scope_tree.c
字号:
/* $Id: prefs_scope_tree.c,v 1.10.2.2 2006/11/04 23:22:37 renaud Exp $ * * Copyright (C) 2004 by Intevation GmbH * Author(s): * Thomas Arendsen Hein <thomas@intevation.de> * * This program is free software under the GNU GPL (>=v2) * Read the file COPYING coming with the software for details. * * In addition, as a special exception, Intevation GmbH gives * permission to link the code of this program with the OpenSSL * library (or with modified versions of OpenSSL that use the same * license as OpenSSL), and distribute linked combinations including * the two. You must obey the GNU General Public License in all * respects for all of the code used other than OpenSSL. If you * modify this file, you may extend this exception to your version * of the file, but you are not obligated to do so. If you do not * wish to do so, delete this exception statement from your version. */#include <includes.h>#include "nessus_i18n.h"#ifdef USE_GTK#include <gtk/gtk.h>#include "globals.h"#include "nessus.h"#include "context.h"#include "preferences.h"#include "prefs_context.h"#include "prefs_dialog.h"#include "prefs_scope_tree.h"#include "error_dialog.h"#include "report.h"#include "report_utils.h"#include "backend.h"enum{ COL_CONTEXT = 0, COL_NAME, COL_NOTE, COL_WARN, COL_HOLE, COL_EDITABLE, NUM_COLS};voidscopetree_save_treerowref(context, model, iter) struct context *context; GtkTreeModel *model; GtkTreeIter iter;{ GtkTreePath *path; gtk_tree_row_reference_free(context->treerowref); path = gtk_tree_model_get_path(model, &iter); context->treerowref = gtk_tree_row_reference_new(model, path);}voidscope_move_menuitem_enable(context, enable) struct context *context; gboolean enable;{ context = context_by_type(context, CONTEXT_TASK); if(context && context->move_menuitem && GTK_IS_WIDGET(context->move_menuitem)) gtk_widget_set_sensitive(context->move_menuitem, enable);}voidscopetree_move(context, new_parent) struct context *context; struct context *new_parent;{ GtkWidget *scopetree = GTK_WIDGET( arg_get_value(arg_get_value(MainDialog, "SCOPETREE"), "TREEVIEW")); GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(scopetree)); GtkTreeRowReference *old_treerowref; GtkTreePath *path; GtkTreeIter iter, parent; struct context *next; const char *copy_name; int copy_note, copy_warn, copy_hole; gboolean copy_editable; /* read old context */ old_treerowref = context->treerowref; context->treerowref = NULL; path = gtk_tree_row_reference_get_path(old_treerowref); gtk_tree_model_get_iter(model, &iter, path); gtk_tree_path_free(path); gtk_tree_model_get(model, &iter, COL_NAME, ©_name, COL_NOTE, ©_note, COL_WARN, ©_warn, COL_HOLE, ©_hole, COL_EDITABLE, ©_editable, -1); /* create the target context */ path = gtk_tree_row_reference_get_path(new_parent->treerowref); gtk_tree_model_get_iter(model, &parent, path); gtk_tree_path_free(path); gtk_tree_store_append(GTK_TREE_STORE(model), &iter, &parent); gtk_tree_store_set(GTK_TREE_STORE(model), &iter, COL_CONTEXT, context, COL_NAME, copy_name, COL_NOTE, copy_note, COL_WARN, copy_warn, COL_HOLE, copy_hole, COL_EDITABLE, copy_editable, -1); scopetree_save_treerowref(context, model, iter); /* move children */ next = context->children; while(next) { scopetree_move(next, context); next = next->next; } /* remove old context */ path = gtk_tree_row_reference_get_path(old_treerowref); gtk_tree_model_get_iter(model, &iter, path); gtk_tree_path_free(path); gtk_tree_row_reference_free(old_treerowref); gtk_tree_store_remove(GTK_TREE_STORE(model), &iter);}voidscope_menu_moveto(menuitem, context) GtkMenuItem *menuitem; struct context *context;{ GtkWidget *scopetree = GTK_WIDGET( arg_get_value(arg_get_value(MainDialog, "SCOPETREE"), "TREEVIEW")); struct context *scope = context_by_type(Context, CONTEXT_SCOPE); GtkTreePath *parentpath; prefs_context_update(scope); scope_move_menuitem_enable(scope, TRUE); if(context_move(scope, context)) scopetree_move(scope, context); parentpath = gtk_tree_row_reference_get_path(context->treerowref); gtk_tree_view_expand_row(GTK_TREE_VIEW(scopetree), parentpath, FALSE); gtk_tree_path_free(parentpath); prefs_context_update(scope);}voidscopetree_move_menuitem_add(context) struct context *context;{ GtkWidget *menu = arg_get_value(MainDialog, "MOVESCOPE_SUBMENU"); GtkWidget *menuitem; menuitem = gtk_menu_item_new_with_label(prefs_get_string(context, "name")); gtk_widget_show(menuitem); gtk_container_add(GTK_CONTAINER(menu), menuitem); g_signal_connect(G_OBJECT(menuitem), "activate", G_CALLBACK(scope_menu_moveto), context); context->move_menuitem = menuitem;}voidscopetree_rename(type) context_type type;{ GtkWidget *scopetree = GTK_WIDGET( arg_get_value(arg_get_value(MainDialog, "SCOPETREE"), "TREEVIEW")); GtkTreePath *path; GtkTreeViewColumn *column; struct context *context = context_by_type(Context, type); if(!context) { show_error(_("scopetree_rename() called with illegal type")); return; } prefs_context_update(context); column = gtk_tree_view_get_column(GTK_TREE_VIEW(scopetree), 0); if(!column->editable_widget) /* avoid a bug in GTK+ 2.0.2 */ { gtk_tree_view_get_cursor(GTK_TREE_VIEW(scopetree), &path, NULL); gtk_tree_view_set_cursor(GTK_TREE_VIEW(scopetree), path, column, TRUE); gtk_widget_grab_focus(scopetree); gtk_tree_path_free(path); }}voidtask_menu_rename(menuitem, user_data) GtkMenuItem *menuitem; gpointer user_data;{ scopetree_rename(CONTEXT_TASK);}voidscope_menu_rename(menuitem, user_data) GtkMenuItem *menuitem; gpointer user_data;{ scopetree_rename(CONTEXT_SCOPE);}voidreport_menu_rename(menuitem, user_data) GtkMenuItem *menuitem; gpointer user_data;{ scopetree_rename(CONTEXT_REPORT);}struct context *scopetree_new(type, name, filename) context_type type; const char *name; const char *filename;{ return scopetree_new_with_parent(NULL, type, name, filename);}struct context *scopetree_new_with_parent(parentscope, type, name, filename) struct context * parentscope; context_type type; const char *name; const char *filename;{ GtkWidget *scopetree = GTK_WIDGET( arg_get_value(arg_get_value(MainDialog, "SCOPETREE"), "TREEVIEW")); GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(scopetree)); GtkTreePath *path, *parentpath = NULL; GtkTreeViewColumn *column; GtkTreeIter iter, parent; struct context *context; switch(type) { case CONTEXT_TASK: context = Global; break; case CONTEXT_SCOPE: case CONTEXT_REPORT: if (parentscope != NULL) { if (parentscope->type >= type) { show_error(_("scopetree_new_with_parent(): parent type >= child type")); return NULL; } context = parentscope; parentpath = gtk_tree_row_reference_get_path(context->treerowref); gtk_tree_model_get_iter(model, &parent, parentpath); } else { gtk_tree_view_get_cursor(GTK_TREE_VIEW(scopetree), &parentpath, &column); while(gtk_tree_path_get_depth(parentpath) >= type) gtk_tree_path_up(parentpath); gtk_tree_model_get_iter(model, &parent, parentpath); gtk_tree_model_get(model, &parent, COL_CONTEXT, &context, -1); } break; default: show_error(_("context_rename() called with illegal type")); return NULL; } context = context_new(context, name, filename); if(context) { if(type == CONTEXT_TASK) { gtk_tree_store_append(GTK_TREE_STORE(model), &iter, NULL); scopetree_move_menuitem_add(context); } else gtk_tree_store_append(GTK_TREE_STORE(model), &iter, &parent); gtk_tree_store_set(GTK_TREE_STORE(model), &iter, COL_CONTEXT, context, COL_NAME, prefs_get_string(context, "name"), COL_NOTE, -1, COL_WARN, -1, COL_HOLE, -1, COL_EDITABLE, TRUE, -1); scopetree_save_treerowref(context, model, iter); if(parentpath) gtk_tree_view_expand_row(GTK_TREE_VIEW(scopetree), parentpath, FALSE); path = gtk_tree_model_get_path(model, &iter); column = gtk_tree_view_get_column(GTK_TREE_VIEW(scopetree), 0); if(!column->editable_widget) /* avoid a bug in GTK+ 2.0.2 */ { gtk_tree_view_set_cursor(GTK_TREE_VIEW(scopetree), path, column, !name); gtk_widget_grab_focus(scopetree); } gtk_tree_path_free(path); } if(parentpath) gtk_tree_path_free(parentpath); return context;}voidtask_menu_new(menuitem, user_data) GtkMenuItem *menuitem; gpointer user_data;{ scopetree_new(CONTEXT_TASK, NULL, NULL);}voidscope_menu_new(menuitem, user_data) GtkMenuItem *menuitem; gpointer user_data;{ scopetree_new(CONTEXT_SCOPE, NULL, NULL);}voidscopetree_context_new(button, user_data) GtkWidget *button; gpointer user_data;{ if(Context->type >= CONTEXT_TASK) scopetree_new(CONTEXT_SCOPE, NULL, NULL); else scopetree_new(CONTEXT_TASK, NULL, NULL);}/* * Delete menu widgets, tree row references and tree rows for a subtree. */voidscopetree_delete_recurse(context) struct context *context;{ struct context *child = context->children; GtkWidget *scopetree = GTK_WIDGET( arg_get_value(arg_get_value(MainDialog, "SCOPETREE"), "TREEVIEW")); GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(scopetree)); GtkTreePath *path; GtkTreeIter iter; while(child) { scopetree_delete_recurse(child); child = child->next; } if(context->move_menuitem) gtk_widget_destroy(context->move_menuitem); path = gtk_tree_row_reference_get_path(context->treerowref); gtk_tree_model_get_iter(model, &iter, path); gtk_tree_path_free(path); gtk_tree_row_reference_free(context->treerowref); gtk_tree_store_remove(GTK_TREE_STORE(model), &iter);}voidscopetree_delete(type) context_type type;{ GtkWindow *window = GTK_WINDOW(arg_get_value(MainDialog, "WINDOW")); GtkWidget *dialog; const char *question; struct context *context = context_by_type(Context, type); prefs_context_update(context); switch(type) { case CONTEXT_TASK: question = _("Really delete task\n `%s'\nand all scopes and reports in it?"); break; case CONTEXT_SCOPE: question = _("Really delete scope\n `%s'\nall reports in it?"); break; case CONTEXT_REPORT: question = _("Really delete report\n `%s'?"); break; default: show_error(_("scopetree_delete() called with illegal type")); return; } dialog = gtk_message_dialog_new(window, GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_QUESTION, GTK_BUTTONS_OK_CANCEL, question, prefs_get_string(context, "name")); arg_set_value(MainDialog, "CONTEXT", -1, dialog); switch (gtk_dialog_run(GTK_DIALOG(dialog))) { case GTK_RESPONSE_OK: scopetree_delete_recurse(context); if(context->next) prefs_context_update(context->next); else if(context->parent->children == context) prefs_context_update(context->parent); else { struct context *sibling = context->parent->children; while(sibling->next != context) sibling = sibling->next; prefs_context_update(sibling); } context_delete(context); break; default: break; } gtk_widget_destroy(dialog); arg_set_value(MainDialog, "CONTEXT", -1, window);}voidtask_menu_delete(menuitem, user_data) GtkMenuItem *menuitem; gpointer user_data;{ scopetree_delete(CONTEXT_TASK);}voidscope_menu_delete(menuitem, user_data) GtkMenuItem *menuitem; gpointer user_data;{ scopetree_delete(CONTEXT_SCOPE);}voidreport_menu_delete(menuitem, user_data) GtkMenuItem *menuitem; gpointer user_data;{ scopetree_delete(CONTEXT_REPORT);}voidscopetree_context_delete(button, user_data) GtkWidget *button; gpointer user_data;{ if(Context->type == CONTEXT_TASK) scopetree_delete(CONTEXT_TASK); else if(Context->type == CONTEXT_SCOPE) scopetree_delete(CONTEXT_SCOPE); else if(Context->type >= CONTEXT_REPORT) scopetree_delete(CONTEXT_REPORT); else show_error(_("scopetree_context_delete() called with illegal type"));}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -