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



Author: epiotr
Date: Mon Aug  4 21:27:49 2008
New Revision: 1942
URL: http://svn.gnome.org/viewvc/gnome-commander?rev=1942&view=rev

Log:
Convert History struct to C++ class

Modified:
   branches/gcmd-1-3/ChangeLog
   branches/gcmd-1-3/src/gnome-cmd-advrename-dialog.cc
   branches/gcmd-1-3/src/gnome-cmd-con.cc
   branches/gcmd-1-3/src/gnome-cmd-data.cc
   branches/gcmd-1-3/src/gnome-cmd-file-selector.cc
   branches/gcmd-1-3/src/history.cc
   branches/gcmd-1-3/src/history.h

Modified: branches/gcmd-1-3/src/gnome-cmd-advrename-dialog.cc
==============================================================================
--- branches/gcmd-1-3/src/gnome-cmd-advrename-dialog.cc	(original)
+++ branches/gcmd-1-3/src/gnome-cmd-advrename-dialog.cc	Mon Aug  4 21:27:49 2008
@@ -874,7 +874,7 @@
 {
     const gchar *template_string = gtk_entry_get_text (GTK_ENTRY (dialog->priv->templ_entry));
 
-    history_add (dialog->priv->defaults->templates, g_strdup (template_string));
+    dialog->priv->defaults->templates->add(g_strdup (template_string));
 }
 
 

Modified: branches/gcmd-1-3/src/gnome-cmd-con.cc
==============================================================================
--- branches/gcmd-1-3/src/gnome-cmd-con.cc	(original)
+++ branches/gcmd-1-3/src/gnome-cmd-con.cc	Mon Aug  4 21:27:49 2008
@@ -101,6 +101,9 @@
         gnome_cmd_dir_unref (con->priv->default_dir);
     if (con->priv->root_dir)
         gnome_cmd_dir_unref (con->priv->root_dir);
+
+    delete con->priv->dir_history;
+
     g_free (con->priv);
 
     if (GTK_OBJECT_CLASS (parent_class)->destroy)
@@ -200,7 +203,7 @@
     con->priv = g_new0 (GnomeCmdConPrivate, 1);
     con->priv->cwd = NULL;
     con->priv->default_dir = NULL;
-    con->priv->dir_history = history_new (20);
+    con->priv->dir_history = new History(20);
     con->priv->bookmarks = g_new0 (GnomeCmdBookmarkGroup, 1);
     con->priv->bookmarks->con = con;
     // con->priv->bookmarks->bookmarks = NULL;

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	Mon Aug  4 21:27:49 2008
@@ -1005,7 +1005,6 @@
     gint size;
     GList *from=NULL, *to=NULL, *csens=NULL;
     GList *tmp_from, *tmp_to, *tmp_csens;
-    GList *templates;
 
     data->priv->advrename_defaults = g_new0 (AdvrenameDefaults, 1);
 
@@ -1023,9 +1022,9 @@
     data->priv->advrename_defaults->sep_value = gnome_cmd_data_get_int ("/advrename/sep_value", 150);
 
     size = gnome_cmd_data_get_int ("/template-history/size", 0);
-    templates = load_string_history ("/template-history/template%d", size);
+    GList *templates = load_string_history ("/template-history/template%d", size);
 
-    data->priv->advrename_defaults->templates = history_new (10);
+    data->priv->advrename_defaults->templates = new History(10);
     data->priv->advrename_defaults->templates->ents = templates;
     data->priv->advrename_defaults->templates->pos = templates;
 
@@ -1148,6 +1147,8 @@
             g_free (data->priv->term);
             g_free (data->priv->mime_editor);
 
+            delete data->priv->advrename_defaults->templates;
+
             g_free (data->priv);
         }
 

Modified: branches/gcmd-1-3/src/gnome-cmd-file-selector.cc
==============================================================================
--- branches/gcmd-1-3/src/gnome-cmd-file-selector.cc	(original)
+++ branches/gcmd-1-3/src/gnome-cmd-file-selector.cc	Mon Aug  4 21:27:49 2008
@@ -1072,10 +1072,10 @@
     con = gnome_cmd_file_selector_get_connection (fs);
     gnome_cmd_con_set_cwd (con, dir);
 
-    if (fs->priv->dir_history && !fs->priv->dir_history->lock)
+    if (fs->priv->dir_history && !fs->priv->dir_history->is_locked)
     {
         gchar *fpath = gnome_cmd_file_get_path (GNOME_CMD_FILE (dir));
-        history_add (fs->priv->dir_history, fpath);
+        fs->priv->dir_history->add(fpath);
         g_free (fpath);
         update_dir_combo (fs);
     }
@@ -1477,14 +1477,12 @@
 {
     g_return_if_fail (GNOME_CMD_IS_FILE_SELECTOR (fs));
 
-    if (!fs->priv->dir_history) return;
+    if (!fs->priv->dir_history || !fs->priv->dir_history->can_back())
+        return;
 
-    if (history_can_back (fs->priv->dir_history))
-    {
-        fs->priv->dir_history->lock = TRUE;
-        goto_directory (fs, history_first (fs->priv->dir_history));
-        fs->priv->dir_history->lock = FALSE;
-    }
+    fs->priv->dir_history->lock();
+    goto_directory (fs, fs->priv->dir_history->first());
+    fs->priv->dir_history->unlock();
 }
 
 
@@ -1492,13 +1490,12 @@
 {
     g_return_if_fail (GNOME_CMD_IS_FILE_SELECTOR (fs));
 
-    if (!fs->priv->dir_history) return;
+    if (!fs->priv->dir_history || !fs->priv->dir_history->can_back())
+        return;
 
-    if (history_can_back (fs->priv->dir_history)) {
-        fs->priv->dir_history->lock = TRUE;
-        goto_directory (fs, history_back (fs->priv->dir_history));
-        fs->priv->dir_history->lock = FALSE;
-    }
+    fs->priv->dir_history->lock();
+    goto_directory (fs, fs->priv->dir_history->back());
+    fs->priv->dir_history->unlock();
 }
 
 
@@ -1506,14 +1503,12 @@
 {
     g_return_if_fail (GNOME_CMD_IS_FILE_SELECTOR (fs));
 
-    if (!fs->priv->dir_history) return;
+    if (!fs->priv->dir_history || !fs->priv->dir_history->can_forward())
+        return;
 
-    if (history_can_forward (fs->priv->dir_history))
-    {
-        fs->priv->dir_history->lock = TRUE;
-        goto_directory (fs, history_forward (fs->priv->dir_history));
-        fs->priv->dir_history->lock = FALSE;
-    }
+    fs->priv->dir_history->lock();
+    goto_directory (fs, fs->priv->dir_history->forward());
+    fs->priv->dir_history->unlock();
 }
 
 
@@ -1521,14 +1516,12 @@
 {
     g_return_if_fail (GNOME_CMD_IS_FILE_SELECTOR (fs));
 
-    if (!fs->priv->dir_history) return;
+    if (!fs->priv->dir_history || !fs->priv->dir_history->can_forward())
+        return;
 
-    if (history_can_forward (fs->priv->dir_history))
-    {
-        fs->priv->dir_history->lock = TRUE;
-        goto_directory (fs, history_last (fs->priv->dir_history));
-        fs->priv->dir_history->lock = FALSE;
-    }
+    fs->priv->dir_history->lock();
+    goto_directory (fs, fs->priv->dir_history->last());
+    fs->priv->dir_history->unlock();
 }
 
 
@@ -1538,7 +1531,7 @@
 
     if (!fs->priv->dir_history) return FALSE;
 
-    return history_can_back (fs->priv->dir_history);
+    return fs->priv->dir_history->can_back();
 }
 
 
@@ -1548,7 +1541,7 @@
 
     if (!fs->priv->dir_history) return FALSE;
 
-    return history_can_forward (fs->priv->dir_history);
+    return fs->priv->dir_history->can_forward();
 }
 
 

Modified: branches/gcmd-1-3/src/history.cc
==============================================================================
--- branches/gcmd-1-3/src/history.cc	(original)
+++ branches/gcmd-1-3/src/history.cc	Mon Aug  4 21:27:49 2008
@@ -25,43 +25,24 @@
 using namespace std;
 
 
-History *history_new (gint max)
+History::~History()
 {
-    History *history = g_new0 (History, 1);
-
-    // history->ents = NULL;
-    // history->pos = NULL;
-    history->max = max;
-    // history->lock = FALSE;
-
-    return history;
-}
-
-
-void history_free (History *history)
-{
-    g_return_if_fail (history != NULL);
-
-    if (history->ents)
+    if (ents)
     {
-        g_list_foreach (history->ents, (GFunc)g_free, NULL);
-        g_list_free (history->ents);
+        g_list_foreach (ents, (GFunc) g_free, NULL);
+        g_list_free (ents);
     }
-
-    g_free (history);
 }
 
 
-void history_add (History *history, const gchar *text)
+void History::add(const gchar *text)
 {
-    g_return_if_fail (history != NULL);
-
-    if (history->lock)
+    if (is_locked)
         return;
 
-    /* If we are in the middle of the history list, lets kill all items that are in front of us */
-    GList *l = history->ents;
-    while (l && l != history->pos)
+    // If we are in the middle of the history list, lets kill all items that are in front of us
+    GList *l = ents;
+    while (l && l != pos)
     {
         g_free (l->data);
         GList *n = g_list_remove_link (l, l);
@@ -69,72 +50,50 @@
         l = n;
     }
 
-    history->ents = string_history_add (l, text, history->max);
-    history->pos = history->ents;
-}
-
-
-gboolean history_can_back (History *history)
-{
-    g_return_val_if_fail (history != NULL, FALSE);
-    g_return_val_if_fail (history->pos != NULL, FALSE);
-
-    return history->pos->next != NULL;
-}
-
-
-gboolean history_can_forward (History *history)
-{
-    g_return_val_if_fail (history != NULL, FALSE);
-    g_return_val_if_fail (history->pos != NULL, FALSE);
-
-    return history->pos->prev != NULL;
+    ents = string_history_add (l, text, max);
+    pos = ents;
 }
 
 
-const gchar *history_first (History *history)
+const gchar *History::first()
 {
-    g_return_val_if_fail (history != NULL, NULL);
-    g_return_val_if_fail (history->pos != NULL, NULL);
+    g_return_val_if_fail (pos != NULL, NULL);
 
-    if (history->pos->next)
-        history->pos = g_list_last(history->pos);
+    if (pos->next)
+        pos = g_list_last(pos);
 
-    return (const gchar*) history->pos->data;
+    return (const gchar *) pos->data;
 }
 
 
-const gchar *history_back (History *history)
+const gchar *History::back()
 {
-    g_return_val_if_fail (history != NULL, NULL);
-    g_return_val_if_fail (history->pos != NULL, NULL);
+    g_return_val_if_fail (pos != NULL, NULL);
 
-    if (history->pos->next)
-        history->pos = history->pos->next;
+    if (pos->next)
+        pos = pos->next;
 
-    return (const gchar*) history->pos->data;
+    return (const gchar *) pos->data;
 }
 
 
-const gchar *history_forward (History *history)
+const gchar *History::forward()
 {
-    g_return_val_if_fail (history != NULL, NULL);
-    g_return_val_if_fail (history->pos != NULL, NULL);
+    g_return_val_if_fail (pos != NULL, NULL);
 
-    if (history->pos->prev)
-        history->pos = history->pos->prev;
+    if (pos->prev)
+        pos = pos->prev;
 
-    return (const gchar*) history->pos->data;
+    return (const gchar *) pos->data;
 }
 
 
-const gchar *history_last (History *history)
+const gchar *History::last()
 {
-    g_return_val_if_fail (history != NULL, NULL);
-    g_return_val_if_fail (history->pos != NULL, NULL);
+    g_return_val_if_fail (pos != NULL, NULL);
 
-    if (history->pos->prev)
-        history->pos = g_list_first(history->pos);
+    if (pos->prev)
+        pos = g_list_first(pos);
 
-    return (const gchar*) history->pos->data;
+    return (const gchar *) pos->data;
 }

Modified: branches/gcmd-1-3/src/history.h
==============================================================================
--- branches/gcmd-1-3/src/history.h	(original)
+++ branches/gcmd-1-3/src/history.h	Mon Aug  4 21:27:49 2008
@@ -20,26 +20,28 @@
 #ifndef __HISTORY_H__
 #define __HISTORY_H__
 
-typedef struct
+struct History
 {
     GList *ents;
     GList *pos;
     gint max;
-    gboolean lock;
-} History;
+    gboolean is_locked;
 
+    History(gint max): ents(NULL), pos(NULL), is_locked(FALSE)  {  this->max = max;  }
+    ~History();
 
-History *history_new (gint max);
-void     history_free (History *history);
+    void add(const gchar *text);
 
-void     history_add (History *history, const gchar *text);
+    gboolean can_back()                                 {  return pos && pos->next;  }
+    gboolean can_forward()                              {  return pos && pos->prev;  }
 
-gboolean history_can_back (History *history);
-gboolean history_can_forward (History *history);
+    const gchar *first();
+    const gchar *back();
+    const gchar *forward();
+    const gchar *last();
 
-const gchar   *history_first (History *history);
-const gchar   *history_back (History *history);
-const gchar   *history_forward (History *history);
-const gchar   *history_last (History *history);
+    void lock()                                         {  is_locked = TRUE;         }
+    void unlock()                                       {  is_locked = FALSE;        }
+};
 
 #endif // __HISTORY_H__



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