further code cleanup: don't use the term "marked" for the color filters, the right...
authorulfl <ulfl@f5534014-38df-0310-8fa8-9805f1628bb7>
Mon, 2 Oct 2006 23:01:33 +0000 (23:01 +0000)
committerulfl <ulfl@f5534014-38df-0310-8fa8-9805f1628bb7>
Mon, 2 Oct 2006 23:01:33 +0000 (23:01 +0000)
git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@19399 f5534014-38df-0310-8fa8-9805f1628bb7

color_filters.c
color_filters.h
gtk/color_dlg.c

index eba1867..ffc7561 100644 (file)
@@ -44,7 +44,7 @@
 #include "simple_dialog.h"
 #include "ui_util.h"
 
-static gboolean read_filters(void);
+static gboolean read_users_filters(void);
 static gboolean read_global_filters(void);
 
 /* Variables and routines defined in color.h */
@@ -70,7 +70,7 @@ void color_filter_remove(color_filter_t *colorf)
 
 /* delete the specified filter */
 static void
-delete_color_filter(color_filter_t *colorf)
+color_filter_delete(color_filter_t *colorf)
 {
        if (colorf->filter_name != NULL)
                g_free(colorf->filter_name);
@@ -81,22 +81,25 @@ delete_color_filter(color_filter_t *colorf)
        g_free(colorf);
 }
 
-/* delete the specified filter as an iterator */
+/* delete the specified filter (called from g_slist_foreach) */
 static void
-delete_color_filter_it(gpointer filter_arg, gpointer unused _U_)
+color_filter_delete_cb(gpointer filter_arg, gpointer unused _U_)
 {
        color_filter_t *colorf = filter_arg;
-       delete_color_filter(colorf);
+       color_filter_delete(colorf);
 }
 
 /* delete all the filters */
 static void
-delete_all_color_filters (void)
+color_filters_delete_all(void)
 {
-        g_slist_foreach(color_filter_list, delete_color_filter_it, NULL);
+        /* delete the color_filter_list */
+        g_slist_foreach(color_filter_list, color_filter_delete_cb, NULL);
        g_slist_free(color_filter_list);
        color_filter_list = NULL;
-        g_slist_foreach(removed_filter_list, delete_color_filter_it, NULL);
+
+        /* delete the removed_filter_list */
+        g_slist_foreach(removed_filter_list, color_filter_delete_cb, NULL);
        g_slist_free(removed_filter_list);
        removed_filter_list = NULL;
 }
@@ -105,8 +108,12 @@ delete_all_color_filters (void)
 void
 color_filters_init(void)
 {
-       delete_all_color_filters();
-       if (!read_filters())
+       /* delete all existing filters */
+       color_filters_delete_all();
+
+        /* try to read the users filters */
+       if (!read_users_filters())
+               /* if that failed, try to read the global filters */
                read_global_filters();
 }
 
@@ -126,7 +133,7 @@ color_filter_new(const gchar *name,    /* The name of the filter to create */
        colorf->fg_color = *fg_color;
        colorf->c_colorfilter = NULL;
        colorf->edit_dialog = NULL;
-       colorf->marked = FALSE;
+       colorf->selected = FALSE;
        color_filter_list = g_slist_append(color_filter_list, colorf);
         return colorf;
 }
@@ -189,7 +196,6 @@ color_filters_colorize_packet(gint row, epan_dissect_t *edt)
 }
 
 /* read filters from the given file */
-
 /* XXX - Would it make more sense to use GStrings here instead of reallocing
    our buffers? */
 static gboolean
@@ -338,7 +344,7 @@ read_filters_file(FILE *f, gpointer arg)
 
 /* read filters from the user's filter file */
 static gboolean
-read_filters(void)
+read_users_filters(void)
 {
        gchar *path;
        FILE *f;
@@ -412,7 +418,7 @@ color_filters_import(gchar *path, gpointer arg)
 struct write_filter_data
 {
   FILE * f;
-  gboolean only_marked;
+  gboolean only_selected;
 };
 
 /* save a single filter */
@@ -423,7 +429,7 @@ write_filter(gpointer filter_arg, gpointer data_arg)
        color_filter_t *colorf = filter_arg;
        FILE *f = data->f;
 
-       if (colorf->marked || !data->only_marked) {
+       if (colorf->selected || !data->only_selected) {
                fprintf(f,"@%s@%s@[%d,%d,%d][%d,%d,%d]\n",
                    colorf->filter_name,
                    colorf->filter_text,
@@ -438,12 +444,12 @@ write_filter(gpointer filter_arg, gpointer data_arg)
 
 /* save filters in a filter file */
 static gboolean
-write_filters_file(FILE *f, gboolean only_marked)
+write_filters_file(FILE *f, gboolean only_selected)
 {
        struct write_filter_data data;
 
        data.f = f;
-       data.only_marked = only_marked;
+       data.only_selected = only_selected;
   
        fprintf(f,"# DO NOT EDIT THIS FILE!  It was created by Wireshark\n");
         g_slist_foreach(color_filter_list, write_filter, &data);
@@ -503,6 +509,7 @@ color_filters_revert(void)
 {
        gchar *path;
 
+       /* try to delete the "old" user color filter file */
        path = get_persconffile_path("colorfilters", TRUE);
        if (!deletefile(path)) {
                g_free(path);
index 361032f..50e32e3 100644 (file)
@@ -37,7 +37,7 @@ typedef struct _color_filter {
         dfilter_t *c_colorfilter; /* compiled filter expression */
         void      *edit_dialog;   /* if filter is being edited, dialog
                                    * box for it */
-       gboolean    marked;         /* set if the filter is marked in the color dialog box */
+       gboolean   selected;      /* set if the filter is selected in the color dialog box */
 } color_filter_t;
 
 /* List of all color filters. */
@@ -69,10 +69,10 @@ gboolean color_filters_import(gchar *path, gpointer arg);
 /** Save filters (export) to some other filter file.
  *
  * @param path the path to the filter file
- * @param only_marked TRUE if only the marked filters should be saved
+ * @param only_selected TRUE if only the selected filters should be saved
  * @return TRUE, if write succeeded
  */
-gboolean color_filters_export(gchar *path, gboolean only_marked);
+gboolean color_filters_export(gchar *path, gboolean only_selected);
 
 /* Prime the epan_dissect_t with all the compiler
  * color filters in 'color_filter_list'. 
index 48a1a41..d364376 100644 (file)
@@ -132,23 +132,23 @@ color_display_with_filter(char *filter)
   }
 }
 
-/* if this filter is marked count it in the given int* */
+/* if this filter is selected - count it in the given int* */
 static void
-count_this_mark(gpointer filter_arg, gpointer counter_arg)
+count_this_select(gpointer filter_arg, gpointer counter_arg)
 {
   color_filter_t *colorf = filter_arg;
   int * cnt = counter_arg;
 
-  if (colorf->marked)
+  if (colorf->selected)
     (*cnt)++;
 }
 
 /* TODO: implement count of selected filters. Plug in to file_dlg update of "export selected" checkbox. */
-int color_marked_count(void)
+int color_selected_count(void)
 {
   int count = 0;
 
-  g_slist_foreach(color_filter_list, count_this_mark, &count);
+  g_slist_foreach(color_filter_list, count_this_select, &count);
 
   return count;
 }
@@ -271,7 +271,7 @@ colorize_dialog_new (char *filter)
 #if GTK_MAJOR_VERSION < 2
   WIDGET_SET_SIZE(color_export, BUTTON_SIZE_X, BUTTON_SIZE_Y);
 #endif
-  gtk_tooltips_set_tip(tooltips, color_export, ("Save all/marked filters to a file"), NULL);
+  gtk_tooltips_set_tip(tooltips, color_export, ("Save all/selected filters to a file"), NULL);
 
   color_import = BUTTON_NEW_FROM_STOCK(WIRESHARK_STOCK_IMPORT);
   gtk_box_pack_start (GTK_BOX (manage_vbox), color_import, FALSE, FALSE, 5);
@@ -544,7 +544,7 @@ color_filter_up_cb(GtkButton *button, gpointer user_data _U_)
 
 #if GTK_MAJOR_VERSION < 2
   colorf = gtk_clist_get_row_data(GTK_CLIST(color_filters), 0);
-  if (colorf->marked)
+  if (colorf->selected)
     return;
 #endif
 
@@ -552,7 +552,7 @@ color_filter_up_cb(GtkButton *button, gpointer user_data _U_)
   {
 #if GTK_MAJOR_VERSION < 2
     colorf = gtk_clist_get_row_data(GTK_CLIST(color_filters), filter_number);
-    if (colorf->marked)
+    if (colorf->selected)
       move_this_row (color_filters, filter_number, amount);
 #else
     model = gtk_tree_view_get_model(GTK_TREE_VIEW(color_filters));
@@ -584,7 +584,7 @@ color_filter_down_cb(GtkButton *button, gpointer user_data _U_)
 
 #if GTK_MAJOR_VERSION < 2
     colorf = gtk_clist_get_row_data(GTK_CLIST(color_filters), num_of_filters - 1);
-    if (colorf->marked)
+    if (colorf->selected)
       return;
 #endif
 
@@ -597,7 +597,7 @@ color_filter_down_cb(GtkButton *button, gpointer user_data _U_)
     gtk_tree_model_iter_nth_child(model, &iter, NULL, filter_number);
     gtk_tree_model_get(model, &iter, 4, &colorf, -1);
 #endif
-    if (colorf->marked)
+    if (colorf->selected)
       move_this_row (color_filters, filter_number, amount);
   }
 }
@@ -614,7 +614,7 @@ remember_selected_row(GtkCList *clist, gint row, gint column _U_,
     row_selected = row;
 
     colorf = gtk_clist_get_row_data(clist, row);
-    colorf->marked = TRUE;
+    colorf->selected = TRUE;
     
     /*
      * A row is selected, so we can move it up *if* it's not at the top
@@ -639,8 +639,8 @@ remember_selected_row(GtkCList *clist, gint row, gint column _U_,
 struct remember_data
 {
     gint count;               /* count of selected filters */
-    gboolean first_marked;    /* true if the first filter in the list is marked */
-    gboolean last_marked;     /* true if the last filter in the list is marked */
+    gboolean first_selected;  /* true if the first filter in the list is selected */
+    gboolean last_selected;   /* true if the last filter in the list is selected */
     gpointer color_filters;
 };
 /* called for each selected row in the tree.
@@ -652,7 +652,7 @@ static void remember_this_row (GtkTreeModel *model, GtkTreePath *path, GtkTreeIt
     struct remember_data *data = arg;
     
     gtk_tree_model_get(model, iter, 4, &colorf, -1);
-    colorf->marked = TRUE;
+    colorf->selected = TRUE;
         
     path_index = gtk_tree_path_get_indices(path);   /* not to be freed */
     if (path_index == NULL)       /* can return NULL according to API doc.*/
@@ -662,20 +662,20 @@ static void remember_this_row (GtkTreeModel *model, GtkTreePath *path, GtkTreeIt
     row_selected = path_index[0];
 
     if (row_selected == 0)
-      data->first_marked = TRUE;
+      data->first_selected = TRUE;
     if (row_selected == num_of_filters - 1)
-      data->last_marked = TRUE;
+      data->last_selected = TRUE;
 
     data->count++;
 }
 
-/* clear the mark on this filter */
+/* clear the selection of this filter */
 static void
-clear_mark(gpointer filter_arg, gpointer arg _U_)
+clear_select(gpointer filter_arg, gpointer arg _U_)
 {
   color_filter_t *colorf = filter_arg;
 
-  colorf->marked = FALSE;
+  colorf->selected = FALSE;
 }
 
 /* The gtk+2.0 version gets called for, (maybe multiple,) changes in the selection. */
@@ -685,11 +685,11 @@ remember_selected_row(GtkTreeSelection *sel, gpointer color_filters)
     GtkWidget    *button;
     struct remember_data data;
 
-    data.first_marked = data.last_marked = FALSE;
+    data.first_selected = data.last_selected = FALSE;
     data.count = 0; 
     data.color_filters = color_filters;
 
-    g_slist_foreach(color_filter_list, clear_mark, NULL);
+    g_slist_foreach(color_filter_list, clear_select, NULL);
     gtk_tree_selection_selected_foreach(sel,remember_this_row, &data);
                                       
     if (data.count > 0)
@@ -710,9 +710,9 @@ remember_selected_row(GtkTreeSelection *sel, gpointer color_filters)
        * and move them down *if* one of them isn't the bottom row.
       */
       button = (GtkWidget *)OBJECT_GET_DATA(color_filters, COLOR_UP_LB);
-      gtk_widget_set_sensitive(button, !data.first_marked);
+      gtk_widget_set_sensitive(button, !data.first_selected);
       button = (GtkWidget *)OBJECT_GET_DATA(color_filters, COLOR_DOWN_LB);
-      gtk_widget_set_sensitive(button, !data.last_marked);
+      gtk_widget_set_sensitive(button, !data.last_selected);
     }
     else
     {
@@ -749,9 +749,9 @@ unremember_selected_row                 (GtkCList        *clist,
   row_selected = -1;
 
   colorf = gtk_clist_get_row_data(clist, row);
-  colorf->marked = FALSE;
+  colorf->selected = FALSE;
 
-  if (color_marked_count() == 0)
+  if (color_selected_count() == 0)
   {
     /*
      * No row is selected, so we can't do operations that affect the
@@ -1002,7 +1002,7 @@ color_delete_cb(GtkWidget *widget, gpointer user_data _U_)
   {
 #if GTK_MAJOR_VERSION < 2
     colorf = gtk_clist_get_row_data(GTK_CLIST(color_filters), row);
-    if (colorf->marked)
+    if (colorf->selected)
       color_delete (row, color_filters);
 #else
     gtk_tree_model_iter_nth_child(model, &iter, NULL, row);