toplevel.h File Reference


Detailed Description

Headers for main toplevel window.

Author:
Jeremy A. Mowery jmowery@tresys.com

Jason Tang jtang@tresys.com

Brandon Whalen bwhalen@tresys.com

Randy Wicks rwicks@tresys.com

Copyright (C) 2005-2007 Tresys Technology, LLC

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

Definition in file toplevel.h.

#include "progress.h"
#include "results.h"
#include "sediffx.h"
#include <apol/policy-path.h>
#include <gtk/gtk.h>
#include <poldiff/poldiff.h>

Go to the source code of this file.


Typedefs

typedef toplevel toplevel_t

Functions

toplevel_ttoplevel_create (sediffx_t *s)
 Allocate and return an instance of the toplevel window object.
void toplevel_destroy (toplevel_t **top)
 Destroy the toplevel window.
int toplevel_open_policies (toplevel_t *top, apol_policy_path_t *orig_path, apol_policy_path_t *mod_path)
 Open the policy files.
void toplevel_run_diff (toplevel_t *top)
 Run the current poldiff object.
void toplevel_show_policy_line (toplevel_t *top, sediffx_policy_e which, unsigned long line)
 Switch to the given policy's source tab, if not already visible, and then scroll the view to show the given line.
void toplevel_set_sort_menu_sensitivity (toplevel_t *top, gboolean sens)
 Enable or disable the toplevel's sort menu.
void toplevel_set_sort_menu_selection (toplevel_t *top, results_sort_e field, results_sort_dir_e dir)
 Set the current sort menu selection to the given field and direction.
char * toplevel_get_glade_xml (toplevel_t *top)
 Return the filename containing sediffx's glade file.
gint toplevel_get_notebook_page (toplevel_t *top)
 Return the current page number for the toplevel main notebook.
progress_ttoplevel_get_progress (toplevel_t *top)
 Return the progress object, so that sub-windows may also show the threaded progress object.
GtkWindow * toplevel_get_window (toplevel_t *top)
 Return the main application window.
GtkTextView * toplevel_get_text_view (toplevel_t *top)
 Get the currently showing text view.
poldiff_ttoplevel_get_poldiff (toplevel_t *top)
 Retrieve the currently active poldiff object.
uint32_t toplevel_get_poldiff_run_flags (toplevel_t *top)
 Get the flags that were used the most recently run poldiff.
void toplevel_ERR (toplevel_t *top, const char *format,...) __attribute__((format(printf
 Pop-up an error dialog with a line of text and wait for the user to dismiss the dialog.
void toplevel_WARN (toplevel_t *top, const char *format,...) __attribute__((format(printf
 Pop-up a warning dialog with a line of text and wait for the user to dismiss the dialog.

Typedef Documentation

typedef struct toplevel toplevel_t
 

Definition at line 30 of file toplevel.h.


Function Documentation

toplevel_t* toplevel_create sediffx_t s  ) 
 

Allocate and return an instance of the toplevel window object.

This will create the window, set up the menus and icons, then display the window.

Parameters:
s Main sediffx object that will control the toplevel.
Returns:
An initialized toplevel object, or NULL upon error. The caller must call toplevel_destroy() afterwards.

Definition at line 163 of file toplevel.c.

References apol_file_find_path(), find_dialog_create(), init_icons(), policy_view_create(), progress_create(), results_create(), toplevel::s, sediffx_policy_e, sediffx_t, toplevel_destroy(), toplevel_on_switch_page(), and toplevel_t.

Referenced by main().

00164 {
00165         toplevel_t *top;
00166         int error = 0;
00167         sediffx_policy_e i;
00168         if ((top = calloc(1, sizeof(*top))) == NULL) {
00169                 error = errno;
00170                 goto cleanup;
00171         }
00172         top->s = s;
00173         if ((top->xml_filename = apol_file_find_path("sediffx.glade")) == NULL ||
00174             (top->xml = glade_xml_new(top->xml_filename, "toplevel", NULL)) == NULL) {
00175                 fprintf(stderr, "Could not open sediffx.glade.\n");
00176                 error = EIO;
00177                 goto cleanup;
00178         }
00179         top->w = GTK_WINDOW(glade_xml_get_widget(top->xml, "toplevel"));
00180         top->notebook = GTK_NOTEBOOK(glade_xml_get_widget(top->xml, "toplevel main notebook"));
00181         assert(top->w != NULL && top->notebook != NULL);
00182         init_icons(top);
00183         g_object_set_data(G_OBJECT(top->w), "toplevel", top);
00184         gtk_widget_show(GTK_WIDGET(top->w));
00185         g_signal_connect(G_OBJECT(top->notebook), "switch-page", G_CALLBACK(toplevel_on_switch_page), top);
00186 
00187         /* initialize sub-windows, now that glade XML file has been
00188          * read */
00189         if ((top->find = find_dialog_create(top)) == NULL ||
00190             (top->progress = progress_create(top)) == NULL || (top->results = results_create(top)) == NULL) {
00191                 error = errno;
00192                 goto cleanup;
00193         }
00194         for (i = SEDIFFX_POLICY_ORIG; i < SEDIFFX_POLICY_NUM; i++) {
00195                 if ((top->views[i] = policy_view_create(top, i)) == NULL) {
00196                         fprintf(stderr, "%s\n", strerror(errno));
00197                         error = errno;
00198                         goto cleanup;
00199                 }
00200         }
00201 
00202         glade_xml_signal_autoconnect(top->xml);
00203 
00204       cleanup:
00205         if (error != 0) {
00206                 toplevel_destroy(&top);
00207                 errno = error;
00208                 return NULL;
00209         }
00210         return top;
00211 }

void toplevel_destroy toplevel_t **  top  ) 
 

Destroy the toplevel window.

This function will recursively destroy all other windows. This does nothing if the pointer is set to NULL.

Parameters:
top Reference to a toplevel object. Afterwards the pointer will be set to NULL.

Definition at line 470 of file toplevel.c.

References apol_vector_destroy(), find_dialog_destroy(), policy_view_destroy(), progress_destroy(), results_destroy(), sediffx_policy_e, and toplevel_t.

Referenced by seaudit_destroy(), and toplevel_create().

00471 {
00472         if (top != NULL && *top != NULL) {
00473                 if ((*top)->monitor_id > 0) {
00474                         g_source_remove((*top)->monitor_id);
00475                 }
00476                 policy_view_destroy(&(*top)->pv);
00477                 apol_vector_destroy(&(*top)->views);
00478                 free((*top)->xml_filename);
00479                 g_free((*top)->view_filename);
00480                 progress_destroy(&(*top)->progress);
00481                 if ((*top)->w != NULL) {
00482                         gtk_widget_destroy(GTK_WIDGET((*top)->w));
00483                 }
00484                 free(*top);
00485                 *top = NULL;
00486         }
00487 }

int toplevel_open_policies toplevel_t top,
apol_policy_path_t orig_path,
apol_policy_path_t mod_path
 

Open the policy files.

Upon success destroy the existing policies and current poldiff objects.

Parameters:
top Toplevel object, used for UI control.
orig_path Path to the original policy. This function takes ownership of this object.
mod_path Path to the modified policy. This function takes ownership of this object.
Returns:
0 on successful open, < 0 on error.

Definition at line 273 of file toplevel.c.

References apol_policy_path_destroy(), apol_policy_path_t, FALSE, policy_view_update(), toplevel::progress, progress_hide(), progress_show(), progress_wait(), remap_types_update(), toplevel::results, results_open_policies(), results_update(), toplevel::s, sediffx_policy_e, SEDIFFX_POLICY_MOD, SEDIFFX_POLICY_ORIG, sediffx_set_policy(), policy_run_datum::top, toplevel_enable_policy_items(), toplevel_ERR(), toplevel_open_policy_runner(), toplevel_t, toplevel_update_title_bar(), TRUE, util_cursor_clear(), util_cursor_wait(), toplevel::views, and toplevel::w.

Referenced by delayed_main(), and open_policies_dialog_run().

00274 {
00275         struct policy_run_datum run;
00276         memset(&run, 0, sizeof(run));
00277         run.top = top;
00278         run.paths[0] = orig_path;
00279         run.paths[1] = mod_path;
00280         sediffx_policy_e i;
00281 
00282         util_cursor_wait(GTK_WIDGET(top->w));
00283         progress_show(top->progress, "Loading Policies");
00284         g_thread_create(toplevel_open_policy_runner, &run, FALSE, NULL);
00285         progress_wait(top->progress);
00286         progress_hide(top->progress);
00287         util_cursor_clear(GTK_WIDGET(top->w));
00288         if (run.result < 0) {
00289                 apol_policy_path_destroy(&run.paths[0]);
00290                 apol_policy_path_destroy(&run.paths[1]);
00291                 return run.result;
00292         }
00293         if (remap_types_update(run.policies[SEDIFFX_POLICY_ORIG], run.policies[SEDIFFX_POLICY_MOD]) < 0) {
00294                 toplevel_ERR(top, "%s", strerror(errno));
00295                 apol_policy_path_destroy(&run.paths[0]);
00296                 apol_policy_path_destroy(&run.paths[1]);
00297                 return -1;
00298         }
00299         results_open_policies(top->results, run.policies[SEDIFFX_POLICY_ORIG], run.policies[SEDIFFX_POLICY_MOD]);
00300         for (i = SEDIFFX_POLICY_ORIG; i < SEDIFFX_POLICY_NUM; i++) {
00301                 policy_view_update(top->views[i], run.policies[i], run.paths[i]);
00302                 sediffx_set_policy(top->s, i, run.policies[i], run.paths[i]);
00303         }
00304         results_update(top->results);
00305         toplevel_enable_policy_items(top, TRUE);
00306         toplevel_update_title_bar(top);
00307         return 0;
00308 }

void toplevel_run_diff toplevel_t top  ) 
 

Run the current poldiff object.

Afterwards this function will notify the results object to update its view.

Parameters:
top Toplevel object whose poldiff to run.

Definition at line 339 of file toplevel.c.

References FALSE, toplevel::progress, progress_hide(), progress_show(), progress_wait(), run_datum::result, toplevel::results, results_clear(), results_update(), run_datum::run_flags, select_diff_dialog_run(), run_datum::top, toplevel_run_diff_runner(), toplevel_t, util_cursor_clear(), util_cursor_wait(), and toplevel::w.

Referenced by delayed_main(), open_policies_dialog_run(), toplevel_on_run_diff_activate(), and toplevel_on_run_diff_button_click().

00340 {
00341         struct run_datum r;
00342 
00343         r.run_flags = select_diff_dialog_run(top);
00344         if (r.run_flags == 0) {
00345                 return;
00346         }
00347         r.top = top;
00348         r.result = 0;
00349 
00350         results_clear(top->results);
00351         util_cursor_wait(GTK_WIDGET(top->w));
00352         progress_show(top->progress, "Running Diff");
00353         g_thread_create(toplevel_run_diff_runner, &r, FALSE, NULL);
00354         progress_wait(top->progress);
00355         progress_hide(top->progress);
00356         util_cursor_clear(GTK_WIDGET(top->w));
00357         if (r.result == 0) {
00358                 results_update(top->results);
00359         }
00360 }

void toplevel_show_policy_line toplevel_t top,
sediffx_policy_e  which,
unsigned long  line
 

Switch to the given policy's source tab, if not already visible, and then scroll the view to show the given line.

Policy line numbers are zero-indexed.

Parameters:
top Toplevel object containing policy source tabs.
which Which policy's source tab to show.
line Line to show.

Definition at line 362 of file toplevel.c.

References toplevel::notebook, policy_view_show_policy_line(), toplevel_t, and toplevel::views.

Referenced by result_item_on_mod_activate(), result_item_on_orig_activate(), and results_on_line_event().

00363 {
00364         gtk_notebook_set_current_page(top->notebook, 1 + which);
00365         policy_view_show_policy_line(top->views[which], line);
00366 }

void toplevel_set_sort_menu_sensitivity toplevel_t top,
gboolean  sens
 

Enable or disable the toplevel's sort menu.

The sort menu should be enabled only when showing the differences for TE rules; otherwise it should be disabled.

Parameters:
top Toplevel object containing sort menu.
sens New sensitivity for the menu.

Definition at line 368 of file toplevel.c.

References toplevel_t, and toplevel::xml.

Referenced by results_summary_on_change(), results_switch_to_page(), and toplevel_on_switch_page().

00369 {
00370         GtkWidget *w = glade_xml_get_widget(top->xml, "sort menu item");
00371         assert(w != NULL);
00372         gtk_widget_set_sensitive(w, sens);
00373 }

void toplevel_set_sort_menu_selection toplevel_t top,
results_sort_e  field,
results_sort_dir_e  dir
 

Set the current sort menu selection to the given field and direction.

Parameters:
top Toplevel object containing sort menu.
field Sort field to select.
dir Sort direction to select.

Definition at line 375 of file toplevel.c.

References toplevel_t, TRUE, and toplevel::xml.

Referenced by results_summary_on_change().

00376 {
00377         static const char *menu_items[][2] = {
00378                 {"Default Sort", "Default Sort"},
00379                 {"Ascending source type", "Descending source type"},
00380                 {"Ascending target type", "Descending target type"},
00381                 {"Ascending object class", "Descending object class"},
00382                 {"Ascending conditional", "Descending conditonal"}
00383         };
00384         int direction = 1;
00385         if (dir == RESULTS_SORT_ASCEND) {
00386                 direction = 0;
00387         }
00388         GtkWidget *w = glade_xml_get_widget(top->xml, menu_items[field][direction]);
00389         assert(w != NULL);
00390         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(w), TRUE);
00391 }

char* toplevel_get_glade_xml toplevel_t top  ) 
 

Return the filename containing sediffx's glade file.

Parameters:
top Toplevel containing glade XML declarations.
Returns:
Name of the glade file. Do not modify this string.

Definition at line 857 of file toplevel.c.

References toplevel_t, and toplevel::xml_filename.

Referenced by filter_view_run(), find_dialog_create(), modify_view_run(), open_policies_dialog_run(), open_policy_window_run(), policy_components_view_run(), policy_view_create(), preferences_view_run(), remap_types_run(), report_window_run(), and select_diff_dialog_run().

00858 {
00859         return top->xml_filename;
00860 }

gint toplevel_get_notebook_page toplevel_t top  ) 
 

Return the current page number for the toplevel main notebook.

Parameters:
top Toplevel to query.
Returns:
Page number for the currently showing tab.

Definition at line 398 of file toplevel.c.

References toplevel::notebook, and toplevel_t.

Referenced by policy_view_notebook_on_event_after().

00399 {
00400         return gtk_notebook_get_current_page(top->notebook);
00401 }

progress_t* toplevel_get_progress toplevel_t top  ) 
 

Return the progress object, so that sub-windows may also show the threaded progress object.

Parameters:
top Toplevel containing progress object.
Returns:
Progress object. Do not free() this pointer.

Definition at line 862 of file toplevel.c.

References toplevel::progress, progress_t, and toplevel_t.

Referenced by policy_view_on_find_terules_click(), report_window_run(), and results_get_slow_buffer().

00863 {
00864         return top->progress;
00865 }

GtkWindow* toplevel_get_window toplevel_t top  ) 
 

Return the main application window.

Sub-windows should be set transient to this window.

Parameters:
top Toplevel containing main window.
Returns:
Main window.

Definition at line 867 of file toplevel.c.

References toplevel_t, and toplevel::w.

Referenced by message_view_export_all_messages(), message_view_export_selected_messages(), message_view_messages_vector(), message_view_save(), message_view_saveas(), policy_view_create(), results_create(), results_get_slow_buffer(), and select_diff_dialog_run().

00868 {
00869         return top->w;
00870 }

GtkTextView* toplevel_get_text_view toplevel_t top  ) 
 

Get the currently showing text view.

This depends upon which toplevel notebook page is showing.

Parameters:
top Toplevel containing text views.
Returns:
Currently visible text view.

Definition at line 413 of file toplevel.c.

References toplevel::notebook, policy_view_get_text_view(), toplevel::results, results_get_text_view(), SEDIFFX_POLICY_MOD, SEDIFFX_POLICY_ORIG, toplevel_t, and toplevel::views.

Referenced by find_dialog_search(), toplevel_on_copy_activate(), toplevel_on_edit_menu_activate(), and toplevel_on_select_all_activate().

00414 {
00415         gint pagenum = gtk_notebook_get_current_page(top->notebook);
00416         switch (pagenum) {
00417         case 0:
00418                 return results_get_text_view(top->results);
00419         case 1:
00420                 return policy_view_get_text_view(top->views[SEDIFFX_POLICY_ORIG]);
00421         case 2:
00422                 return policy_view_get_text_view(top->views[SEDIFFX_POLICY_MOD]);
00423         }
00424         /* should never get here */
00425         assert(0);
00426         return NULL;
00427 }

poldiff_t* toplevel_get_poldiff toplevel_t top  ) 
 

Retrieve the currently active poldiff object.

If policies have not yet been loaded then this returns NULL. Note that the poldiff object will not be run yet; for that call toplevel_run_diff().

Parameters:
top Toplevel containing poldiff object.
Returns:
poldiff object, or NULL if none availble or upon error.

Definition at line 429 of file toplevel.c.

References poldiff_t, toplevel::progress, progress_poldiff_handle_func(), toplevel::s, sediffx_get_poldiff(), and toplevel_t.

Referenced by remap_types_run(), and results_update().

00430 {
00431         return sediffx_get_poldiff(top->s, progress_poldiff_handle_func, top->progress);
00432 }

uint32_t toplevel_get_poldiff_run_flags toplevel_t top  ) 
 

Get the flags that were used the most recently run poldiff.

Parameters:
top Toplevel object to query.
Returns:
poldiff run flags, or 0 in none set.

Definition at line 434 of file toplevel.c.

References toplevel::s, sediffx_get_poldiff_run_flags(), and toplevel_t.

00435 {
00436         return sediffx_get_poldiff_run_flags(top->s);
00437 }

void toplevel_ERR toplevel_t top,
const char *  format,
  ...
 

Pop-up an error dialog with a line of text and wait for the user to dismiss the dialog.

Parameters:
top Toplevel window; this message dialog will be centered upon it.
format Format string to print, using syntax of printf(3).

Referenced by filter_view_apply(), filter_view_apply_context(), filter_view_apply_entry(), filter_view_apply_other(), filter_view_get_policy_classes(), filter_view_get_policy_roles(), filter_view_get_policy_types(), filter_view_get_policy_users(), filter_view_init_context(), filter_view_on_entry_focus_out(), message_view_create(), message_view_dialog_response(), message_view_entire_message(), message_view_export_messages_vector(), message_view_export_selected_messages(), message_view_messages_vector(), message_view_on_column_click(), message_view_save(), message_view_saveas(), message_view_store_get_value(), modify_view_on_add_click(), modify_view_on_export_click(), modify_view_on_import_click(), modify_view_run(), open_policy_build_path(), open_policy_init_value(), open_policy_init_values(), open_policy_load_module(), open_policy_on_export_click(), open_policy_on_import_click(), policy_components_view_init_lists(), policy_components_view_run(), policy_view_display_avrule_results(), policy_view_load_policy_source(), policy_view_on_find_terules_click(), policy_view_source_update(), policy_view_stats_update(), progress_wait(), remap_types_on_add_click(), remap_types_update_view(), seaudit_set_log(), seaudit_set_policy(), select_diff_dialog_run(), toplevel_add_new_model(), toplevel_add_new_view(), toplevel_monitor_log_timer(), toplevel_on_help_activate(), toplevel_on_open_recent_policy_activate(), toplevel_on_open_view_activate(), toplevel_open_policies(), toplevel_set_recent_policies_submenu(), toplevel_update_status_bar(), and toplevel_update_title_bar().

void toplevel_WARN toplevel_t top,
const char *  format,
  ...
 

Pop-up a warning dialog with a line of text and wait for the user to dismiss the dialog.

Parameters:
top Toplevel window; this message dialog will be centered upon it.
format Format string to print, using syntax of printf(3).

Referenced by progress_wait().