gnome-commander r1948 - in branches/gcmd-1-3: . src



Author: epiotr
Date: Tue Aug  5 21:12:18 2008
New Revision: 1948
URL: http://svn.gnome.org/viewvc/gnome-commander?rev=1948&view=rev

Log:
Convert Filter struct into C++ class

Modified:
   branches/gcmd-1-3/ChangeLog
   branches/gcmd-1-3/src/filter.cc
   branches/gcmd-1-3/src/filter.h
   branches/gcmd-1-3/src/gnome-cmd-data.cc
   branches/gcmd-1-3/src/gnome-cmd-data.h
   branches/gcmd-1-3/src/gnome-cmd-file-list.cc
   branches/gcmd-1-3/src/gnome-cmd-options-dialog.cc
   branches/gcmd-1-3/src/gnome-cmd-search-dialog.cc

Modified: branches/gcmd-1-3/src/filter.cc
==============================================================================
--- branches/gcmd-1-3/src/filter.cc	(original)
+++ branches/gcmd-1-3/src/filter.cc	Tue Aug  5 21:12:18 2008
@@ -28,96 +28,55 @@
 using namespace std;
 
 
-inline Filter *new_regex (const gchar *exp, gboolean case_sens)
+Filter::Filter(const gchar *exp, gboolean case_sens, Type type): re_exp(NULL), fn_exp(NULL), fn_flags(0)
 {
-    Filter *filter = g_new0 (Filter, 1);
+    this->type = type;
 
-    filter->type = FILTER_TYPE_REGEX;
-    filter->re_exp = g_new (regex_t, 1);
-
-    int flags = case_sens ? REG_ICASE : 0;
-
-    regcomp (filter->re_exp, exp, flags);
-
-    return filter;
-}
-
-
-inline Filter *new_fnmatch (const gchar *exp, gboolean case_sens)
-{
-    Filter *filter = g_new0 (Filter, 1);
-
-    filter->type = FILTER_TYPE_FNMATCH;
-    filter->fn_exp = g_strdup (exp);
-    filter->fn_flags = FNM_NOESCAPE;
-
-#ifdef FNM_CASEFOLD
-    if (!case_sens)
-        filter->fn_flags |= FNM_CASEFOLD;
-#endif
-
-    return filter;
-}
-
-
-Filter *filter_new (const gchar *exp, gboolean case_sens, FilterType type)
-{
     switch (type)
     {
-        case FILTER_TYPE_REGEX:
-            return new_regex (exp, case_sens);
+        case TYPE_REGEX:
+            re_exp = g_new (regex_t, 1);
+            regcomp (re_exp, exp, case_sens ? REG_ICASE : 0);
+            break;
 
-        case FILTER_TYPE_FNMATCH:
-            return new_fnmatch (exp, case_sens);
+        case TYPE_FNMATCH:
+            fn_exp = g_strdup (exp);
+            fn_flags = FNM_NOESCAPE;
+#ifdef FNM_CASEFOLD
+            if (!case_sens)
+                fn_flags |= FNM_CASEFOLD;
+#endif
+            break;
 
         default:
-            g_printerr ("Unknown FilterType (%d) in filter_new\n", type);
+            g_printerr ("Unknown Filter::Type (%d) in constructor\n", type);
     }
-
-    return NULL;
 }
 
 
-void filter_free (Filter *filter)
+Filter::~Filter()
 {
-    g_return_if_fail (filter != NULL);
-
-    switch (filter->type)
-    {
-        case FILTER_TYPE_REGEX:
-            regfree (filter->re_exp);
-            g_free (filter->re_exp);
-            break;
+    if (type==TYPE_REGEX)
+        regfree (re_exp);
 
-        case FILTER_TYPE_FNMATCH:
-            g_free (filter->fn_exp);
-            break;
-
-        default:
-            g_printerr ("Unknown FilterType (%d) in filter_free\n", filter->type);
-    }
-
-    g_free (filter);
+    g_free (re_exp);
+    g_free (fn_exp);
 }
 
 
-gboolean filter_match (Filter *filter, gchar *text)
+gboolean Filter::match(const gchar *text)
 {
     static regmatch_t match;
 
-    g_return_val_if_fail (filter != NULL, FALSE);
-
-    switch (filter->type)
+    switch (type)
     {
-        case FILTER_TYPE_REGEX:
-            return regexec (filter->re_exp, text, 1, &match, 0) == 0;
+        case TYPE_REGEX:
+            return regexec (re_exp, text, 1, &match, 0) == 0;
 
-        case FILTER_TYPE_FNMATCH:
-            return fnmatch (filter->fn_exp, text, filter->fn_flags) == 0;
+        case TYPE_FNMATCH:
+            return fnmatch (fn_exp, text, fn_flags) == 0;
 
         default:
-            g_printerr ("Unknown FilterType (%d) in filter_match\n", filter->type);
+            return FALSE;
     }
-
-    return FALSE;
 }

Modified: branches/gcmd-1-3/src/filter.h
==============================================================================
--- branches/gcmd-1-3/src/filter.h	(original)
+++ branches/gcmd-1-3/src/filter.h	Tue Aug  5 21:12:18 2008
@@ -22,24 +22,24 @@
 
 #include <regex.h>
 
-typedef enum
-{
-    FILTER_TYPE_REGEX,
-    FILTER_TYPE_FNMATCH
-} FilterType;
-
 
 struct Filter
 {
-    FilterType type;    // common stuff
+    enum Type
+    {
+        TYPE_REGEX,
+        TYPE_FNMATCH
+    };
+
+    Type type;          // common stuff
     regex_t *re_exp;    // regex filtering stuff
     char *fn_exp;       // fnmatch filtering stuff
     int fn_flags;       // fnmatch filtering stuff
-};
 
+    Filter(const gchar *exp, gboolean case_sens,Type type);
+    ~Filter();
 
-Filter *filter_new (const gchar *exp, gboolean case_sens, FilterType type);
-void filter_free (Filter *filter);
-gboolean filter_match (Filter *filter, gchar *text);
+    gboolean match(const gchar *text);
+};
 
 #endif // __FILTER_H__

Modified: branches/gcmd-1-3/src/gnome-cmd-data.cc
==============================================================================
--- branches/gcmd-1-3/src/gnome-cmd-data.cc	(original)
+++ branches/gcmd-1-3/src/gnome-cmd-data.cc	Tue Aug  5 21:12:18 2008
@@ -77,7 +77,7 @@
     gint                 cmdline_history_length;
     GList                *cmdline_history;
     GtkReliefStyle       btn_relief;
-    FilterType           filter_type;
+    Filter::Type         filter_type;
     gboolean             device_only_icon;
     gint                 dir_cache_size;
     gboolean             use_ls_colors;
@@ -1436,7 +1436,7 @@
     g_free (document_icon_dir);
     data->priv->cmdline_history_length = gnome_cmd_data_get_int ("/options/cmdline_history_length", 16);
     data->priv->btn_relief = (GtkReliefStyle) gnome_cmd_data_get_int ("/options/btn_relief", GTK_RELIEF_NONE);
-    data->priv->filter_type = (FilterType) gnome_cmd_data_get_int ("/options/filter_type", FILTER_TYPE_FNMATCH);
+    data->priv->filter_type = (Filter::Type) gnome_cmd_data_get_int ("/options/filter_type", Filter::TYPE_FNMATCH);
     data->priv->list_orientation = gnome_cmd_data_get_bool ("/options/list_orientation", FALSE);
     data->priv->conbuttons_visibility = gnome_cmd_data_get_bool ("/options/conbuttons_visibility", TRUE);
     data->priv->cmdline_visibility = gnome_cmd_data_get_bool ("/options/cmdline_visibility", TRUE);
@@ -2178,13 +2178,13 @@
 }
 
 
-void gnome_cmd_data_set_filter_type (FilterType type)
+void gnome_cmd_data_set_filter_type (Filter::Type type)
 {
     data->priv->filter_type = type;
 }
 
 
-FilterType gnome_cmd_data_get_filter_type (void)
+Filter::Type gnome_cmd_data_get_filter_type (void)
 {
     return data->priv->filter_type;
 }

Modified: branches/gcmd-1-3/src/gnome-cmd-data.h
==============================================================================
--- branches/gcmd-1-3/src/gnome-cmd-data.h	(original)
+++ branches/gcmd-1-3/src/gnome-cmd-data.h	Tue Aug  5 21:12:18 2008
@@ -199,8 +199,8 @@
 GtkReliefStyle gnome_cmd_data_get_button_relief (void);
 void gnome_cmd_data_set_button_relief (GtkReliefStyle relief);
 
-FilterType gnome_cmd_data_get_filter_type (void);
-void gnome_cmd_data_set_filter_type (FilterType type);
+Filter::Type gnome_cmd_data_get_filter_type (void);
+void gnome_cmd_data_set_filter_type (Filter::Type type);
 
 gboolean gnome_cmd_data_get_device_only_icon (void);
 void gnome_cmd_data_set_device_only_icon (gboolean value);

Modified: branches/gcmd-1-3/src/gnome-cmd-file-list.cc
==============================================================================
--- branches/gcmd-1-3/src/gnome-cmd-file-list.cc	(original)
+++ branches/gcmd-1-3/src/gnome-cmd-file-list.cc	Tue Aug  5 21:12:18 2008
@@ -421,8 +421,7 @@
 {
     g_return_if_fail (GNOME_CMD_IS_FILE_LIST (fl));
 
-    Filter *filter = filter_new (pattern, case_sens, gnome_cmd_data_get_filter_type ());
-    g_return_if_fail (filter != NULL);
+    Filter filter(pattern, case_sens, gnome_cmd_data_get_filter_type ());
 
     for (GList *tmp=gnome_cmd_file_list_get_all_files (fl); tmp; tmp = tmp->next)
     {
@@ -430,7 +429,7 @@
 
         if (finfo && finfo->info)
         {
-            if (filter_match (filter, finfo->info->name))
+            if (filter.match(finfo->info->name))
             {
                 if (mode)
                     select_file (fl, finfo);
@@ -439,8 +438,6 @@
             }
         }
     }
-
-    filter_free (filter);
 }
 
 

Modified: branches/gcmd-1-3/src/gnome-cmd-options-dialog.cc
==============================================================================
--- branches/gcmd-1-3/src/gnome-cmd-options-dialog.cc	(original)
+++ branches/gcmd-1-3/src/gnome-cmd-options-dialog.cc	Tue Aug  5 21:12:18 2008
@@ -79,11 +79,11 @@
 
     radio = create_radio (parent, NULL, _("Shell syntax"), "ft_shell_radio");
     gtk_container_add (GTK_CONTAINER (cat_box), radio);
-    if (gnome_cmd_data_get_filter_type () == FILTER_TYPE_FNMATCH)
+    if (gnome_cmd_data_get_filter_type () == Filter::TYPE_FNMATCH)
         gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio), TRUE);
     radio = create_radio (parent, get_radio_group(radio), _("Regex syntax"), "ft_regex_radio");
     gtk_container_add (GTK_CONTAINER (cat_box), radio);
-    if (gnome_cmd_data_get_filter_type () == FILTER_TYPE_REGEX)
+    if (gnome_cmd_data_get_filter_type () == Filter::TYPE_REGEX)
         gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio), TRUE);
 
 
@@ -139,9 +139,9 @@
         gnome_cmd_data_set_right_mouse_button_mode (RIGHT_BUTTON_SELECTS);
 
     if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (ft_regex_radio)))
-        gnome_cmd_data_set_filter_type (FILTER_TYPE_REGEX);
+        gnome_cmd_data_set_filter_type (Filter::TYPE_REGEX);
     else
-        gnome_cmd_data_set_filter_type (FILTER_TYPE_FNMATCH);
+        gnome_cmd_data_set_filter_type (Filter::TYPE_FNMATCH);
 
     gnome_cmd_data_set_case_sens_sort (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (case_sens_check)));
     gnome_cmd_data_set_dir_cache_size (gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (dir_cache_size)));

Modified: branches/gcmd-1-3/src/gnome-cmd-search-dialog.cc
==============================================================================
--- branches/gcmd-1-3/src/gnome-cmd-search-dialog.cc	(original)
+++ branches/gcmd-1-3/src/gnome-cmd-search-dialog.cc	Tue Aug  5 21:12:18 2008
@@ -252,7 +252,7 @@
  */
 inline gboolean name_matches (gchar *name, SearchData *data)
 {
-    return filter_match (data->name_filter, name);
+    return data->name_filter->match(name);
 }
 
 
@@ -360,7 +360,7 @@
     search_dir_r (data->start_dir, data);
 
     // free regexps
-    filter_free (data->name_filter);
+    delete data->name_filter;
     data->name_filter = NULL;
 
     if (data->content_search)
@@ -542,9 +542,9 @@
     // create an re for filename matching
     GtkWidget *regex_radio = lookup_widget (GTK_WIDGET (dialog), "regex_radio");
 
-    data->name_filter = filter_new (data->name_pattern, data->case_sens,
-                                    gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (regex_radio)) ? FILTER_TYPE_REGEX
-                                                                                                   : FILTER_TYPE_FNMATCH);
+    data->name_filter = new Filter(data->name_pattern, data->case_sens,
+                                    gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (regex_radio)) ? Filter::TYPE_REGEX
+                                                                                                   : Filter::TYPE_FNMATCH);
 
     // if we're going to search through file content create an re for that too
     if (data->content_search)
@@ -868,11 +868,11 @@
 
     radio = create_radio_with_mnemonic (window, NULL, _("She_ll syntax"), "shell_radio");
     gtk_container_add (GTK_CONTAINER (hbox), radio);
-    if (gnome_cmd_data_get_filter_type () == FILTER_TYPE_FNMATCH)
+    if (gnome_cmd_data_get_filter_type () == Filter::TYPE_FNMATCH)
         gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio), TRUE);
     radio = create_radio_with_mnemonic (window, get_radio_group (radio), _("Rege_x syntax"), "regex_radio");
     gtk_container_add (GTK_CONTAINER (hbox), radio);
-    if (gnome_cmd_data_get_filter_type () == FILTER_TYPE_REGEX)
+    if (gnome_cmd_data_get_filter_type () == Filter::TYPE_REGEX)
         gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio), TRUE);
 
     table_add (table, hbox, 1, 2, GTK_FILL);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]