Author: peter
Date: 2007-01-16 11:21:34 +0000 (Tue, 16 Jan 2007)
New Revision: 24503

Modified:
   squeeze/trunk/libsqueeze/archive-support-rar.c
   squeeze/trunk/libsqueeze/archive-support.c
   squeeze/trunk/libsqueeze/archive.c
   squeeze/trunk/libsqueeze/archive.h
   squeeze/trunk/src/archive_store.c
   squeeze/trunk/src/main_window.c
   squeeze/trunk/src/widget_factory.c
Log:
fixed leading spaces in rar
support for delete in archive store


Modified: squeeze/trunk/libsqueeze/archive-support-rar.c
===================================================================
--- squeeze/trunk/libsqueeze/archive-support-rar.c      2007-01-16 10:08:36 UTC 
(rev 24502)
+++ squeeze/trunk/libsqueeze/archive-support-rar.c      2007-01-16 11:21:34 UTC 
(rev 24503)
@@ -424,8 +424,8 @@
                                break;
                        }
 
-                       temp_filename = g_strchomp(line);
-                       g_debug(temp_filename);
+                       temp_filename = line+1;
+                       line[strlen(temp_filename)] = '\0';
                        entry = lsq_archive_add_file(archive, temp_filename);
 
                        status = g_io_channel_read_line(ioc, &line, 
NULL,NULL,NULL);

Modified: squeeze/trunk/libsqueeze/archive-support.c
===================================================================
--- squeeze/trunk/libsqueeze/archive-support.c  2007-01-16 10:08:36 UTC (rev 
24502)
+++ squeeze/trunk/libsqueeze/archive-support.c  2007-01-16 11:21:34 UTC (rev 
24503)
@@ -230,6 +230,23 @@
 {
        if(support->remove)
        {
+               gchar *path;
+               LSQArchiveIter *entry, *child;
+               GSList *iter, *del = iter = g_slist_copy(files);
+               /* TODO: is add children really nesecery? */
+               lsq_archive_add_children(archive, files);
+               while(iter)
+               {
+                       path = g_strdup((const gchar*)iter->data);
+                       *strrchr(path, '/') = '\0';
+                       entry = lsq_archive_get_iter(archive, path);
+                       g_free(path);
+                       child = lsq_archive_get_iter(archive, (const 
gchar*)iter->data);
+                       lsq_archive_iter_del_child(archive, entry, child);
+                       iter = g_slist_next(iter);
+               }
+               g_slist_free(del);
+               g_debug("removed");
                lsq_archive_set_status(archive, LSQ_ARCHIVESTATUS_REMOVE);
                archive->support = support;
                return support->remove(archive, files);

Modified: squeeze/trunk/libsqueeze/archive.c
===================================================================
--- squeeze/trunk/libsqueeze/archive.c  2007-01-16 10:08:36 UTC (rev 24502)
+++ squeeze/trunk/libsqueeze/archive.c  2007-01-16 11:21:34 UTC (rev 24503)
@@ -68,11 +68,14 @@
 lsq_entry_new(LSQArchive *, const gchar *);
 
 static void
-lsq_archive_entry_free(LSQArchive *, LSQEntry *);
+lsq_archive_entry_free(const LSQArchive *, LSQEntry *);
 
 static LSQEntry *
 lsq_entry_get_child(const LSQEntry *entry, const gchar *filename);
 
+static gboolean
+lsq_archive_entry_del_child(const LSQArchive*, LSQEntry *entry, const gchar 
*filename);
+
 static void
 lsq_archive_entry_add_child(LSQArchive *, LSQEntry *, LSQEntry *);
 
@@ -94,6 +97,9 @@
 static const gchar *
 lsq_archive_iter_get_mimetype(const LSQArchive *, const LSQArchiveIter *);
 
+static gchar *
+lsq_archive_get_iter_part(const LSQArchive *archive, const gchar *path);
+
 static gint
 lsq_entry_filename_compare(LSQEntry *, LSQEntry *);
 
@@ -174,7 +180,7 @@
                        0,
                        NULL,
                        NULL,
-                       g_cclosure_marshal_VOID__POINTER,
+                       g_cclosure_marshal_VOID__STRING,
                        G_TYPE_NONE,
                        1,
                        G_TYPE_STRING,
@@ -277,6 +283,7 @@
 {
        gchar **path = NULL;
        gchar *_path = NULL;
+       gchar *_path_ = NULL;
 
        if(LSQ_IS_ARCHIVE(archive))
        {
@@ -289,11 +296,16 @@
                                g_signal_emit(G_OBJECT(archive), 
lsq_archive_signals[LSQ_ARCHIVE_SIGNAL_REFRESHED], 0, NULL);
                        if((archive->old_status == LSQ_ARCHIVESTATUS_REMOVE) && 
(archive->files))
                        {
-                               path = g_strsplit(archive->files, " ", 2);
-                               _path = g_path_get_dirname(path[0]);
-                               g_signal_emit(G_OBJECT(archive), 
lsq_archive_signals[LSQ_ARCHIVE_SIGNAL_PATH_CHANGED], 0, _path, NULL);
+                               /* FIXME: can not be space in path */
+                               _path = archive->files;
+                               while(*_path == ' ') _path++;
+                               path = g_strsplit(_path, " ", 2);
+                               _path = g_shell_unquote(path[0], NULL);
+                               _path_ = lsq_archive_get_iter_part(archive, 
_path);
+                               g_signal_emit(G_OBJECT(archive), 
lsq_archive_signals[LSQ_ARCHIVE_SIGNAL_PATH_CHANGED], 0, _path_, NULL);
+                               g_free(_path_);
+                               g_free(_path);
                                g_strfreev(path);
-                               g_free(_path);
                        }
                } 
        }
@@ -520,7 +532,7 @@
 }
 
 LSQArchiveIter *
-lsq_archive_get_iter(LSQArchive *archive, const gchar *path)
+lsq_archive_get_iter(const LSQArchive *archive, const gchar *path)
 {
 
        if(!path)
@@ -532,6 +544,7 @@
 
        if(path[0] == '/' && lsq_archive_iter_get_child(archive, 
archive->root_entry, "/"))
        {
+               g_free(iter[0]);
                iter[0] = strdup("/");
        }
 
@@ -554,7 +567,52 @@
        return entry;
 }
 
+static gchar *
+lsq_archive_get_iter_part(const LSQArchive *archive, const gchar *path)
+{
+       if(!path)
+               return NULL;
 
+       gchar **buf = g_strsplit_set(path, "/\n", -1);
+       gchar **iter = buf;
+       gchar *result, *tmp = NULL;
+       LSQArchiveIter *entry = (LSQArchiveIter *)archive->root_entry;
+
+       if(path[0] == '/' && lsq_archive_iter_get_child(archive, 
archive->root_entry, "/"))
+       {
+               tmp = iter[0];
+               iter[0] = strdup("/");
+       }
+
+       while(iter[1]) /* next iter must exist */
+       {
+               g_debug(*iter);
+               if((*iter)[0])
+               {
+                       entry = lsq_archive_iter_get_child(archive, entry, 
*iter);
+                       if(!entry) /*&& lsq_archive_iter_is_directory(archive, 
entry))*/
+                       {
+                               break;
+                       }
+               }
+               iter++;
+       }
+
+       if(tmp)
+       {
+               g_free(iter[0]);
+               iter[0] = tmp;
+       }
+       tmp = *iter;
+       *iter = NULL;
+       result = g_strjoinv("/", buf);
+       *iter = tmp;
+
+       g_strfreev(buf);
+
+       return result;
+}
+
 /******************
  * LSQEntry stuff *
  ******************/
@@ -581,7 +639,7 @@
 }
 
 static void
-lsq_archive_entry_free(LSQArchive *archive, LSQEntry *entry)
+lsq_archive_entry_free(const LSQArchive *archive, LSQEntry *entry)
 {
        guint i = 0; 
        gpointer props_iter = entry->props;
@@ -695,6 +753,79 @@
        return NULL;
 }
 
+static gboolean
+lsq_archive_entry_del_child(const LSQArchive *archive, LSQEntry *entry, const 
gchar *filename)
+{
+       LSQSList *buffer_iter = NULL, *prev_iter = NULL;
+       /* the first element of the array (*entry->children) contains the size 
of the array */
+       guint total_size, size = total_size = 
entry->children?GPOINTER_TO_UINT(*entry->children):0;
+       guint pos = 0;
+       guint begin = 1;
+       gint cmp = 0;
+       const gchar *_pos = strchr(filename, '/');
+       gchar *_filename;
+
+       if(_pos)
+               _filename = g_strndup(filename, (gsize)(_pos - filename));
+       else
+               _filename = g_strdup(filename);
+
+
+       /* binary search algoritme */
+       while(size)
+       {
+               pos = (size / 2);
+
+               cmp = strcmp(_filename, entry->children[begin+pos]->filename);
+               if(!cmp)
+               {
+                       g_free(_filename);
+                       lsq_archive_entry_free(archive, 
entry->children[begin+pos]);
+                       total_size -= 1;
+                       for(;pos < total_size; ++pos)
+                       {
+                               entry->children[begin+pos] = 
entry->children[begin+pos+1];
+                       }
+                       *entry->children = GUINT_TO_POINTER(total_size);
+                       return TRUE;
+               }
+
+               if(cmp < 0)
+               {
+                       size = pos;
+               }
+               else
+               {
+                       size -= ++pos;
+                       begin += pos;
+               }
+       }
+
+       /* search the buffer */
+       for(buffer_iter = entry->buffer; buffer_iter; buffer_iter = 
buffer_iter->next)
+       {
+               cmp = strcmp(_filename, buffer_iter->entry->filename);
+
+               if(!cmp)
+               {
+                       g_free(_filename);
+                       lsq_archive_entry_free(archive, buffer_iter->entry);
+                       if(prev_iter)
+                               prev_iter->next = buffer_iter->next;
+                       else
+                               entry->buffer = buffer_iter->next;
+                       g_free(buffer_iter);
+                       return TRUE;
+               }
+               if(cmp < 0)
+                       break;
+               prev_iter = buffer_iter;
+       }
+
+       g_free(_filename);
+       return FALSE;
+}
+
 static void
 lsq_archive_entry_add_child(LSQArchive *archive, LSQEntry *parent, LSQEntry 
*child)
 {
@@ -896,8 +1027,7 @@
 gboolean
 lsq_archive_iter_del_child(LSQArchive *archive, LSQArchiveIter *parent, 
LSQArchiveIter *child)
 {
-       g_warning("not implemented yet");
-       return FALSE;
+       return lsq_archive_entry_del_child(archive, parent, child->filename);
 }
 
 /**
@@ -1384,3 +1514,23 @@
        else
                g_value_set_string(value, NULL);
 }
+
+void
+lsq_archive_add_children(LSQArchive *archive, GSList *files)
+{
+       GSList *iter = files;
+       LSQArchiveIter *entry;
+       guint i;
+
+       /* TODO: could by cyclic? */
+       while(iter)
+       {
+               entry = lsq_archive_get_iter(archive, (const gchar*)iter->data);
+               for(i = 0; i < lsq_archive_iter_n_children(archive, entry); ++i)
+               {
+                       files = g_slist_append(files, g_strconcat((const 
gchar*)iter->data, "/", lsq_archive_iter_nth_child(archive, entry, 
i)->filename, NULL));
+               }
+
+               iter = g_slist_next(iter);
+       }
+}

Modified: squeeze/trunk/libsqueeze/archive.h
===================================================================
--- squeeze/trunk/libsqueeze/archive.h  2007-01-16 10:08:36 UTC (rev 24502)
+++ squeeze/trunk/libsqueeze/archive.h  2007-01-16 11:21:34 UTC (rev 24503)
@@ -136,7 +136,7 @@
 void                lsq_archive_iter_get_icon_name(const LSQArchive *, const 
LSQArchiveIter *, GValue *, GtkIconTheme *icon_theme);
 
 LSQArchiveIter     *lsq_archive_add_file(LSQArchive *, const gchar *) 
G_GNUC_INTERNAL;
-LSQArchiveIter     *lsq_archive_get_iter(LSQArchive *, const gchar *);
+LSQArchiveIter     *lsq_archive_get_iter(const LSQArchive *, const gchar *);
 GType               lsq_archive_get_entry_property_type(LSQArchive *, guint);
 const gchar        *lsq_archive_get_entry_property_name(LSQArchive *, guint);
 void                lsq_archive_clear_entry_property_types(LSQArchive *) 
G_GNUC_INTERNAL;
@@ -146,6 +146,8 @@
 guint64             lsq_archive_get_n_files(LSQArchive *);
 guint64             lsq_archive_get_n_directories(LSQArchive *);
 
+void                lsq_archive_add_children(LSQArchive *, GSList *) 
G_GNUC_INTERNAL;
+
 G_END_DECLS
 
 #endif /* __LIBSQUEEZE_ARCHIVE_H__ */

Modified: squeeze/trunk/src/archive_store.c
===================================================================
--- squeeze/trunk/src/archive_store.c   2007-01-16 10:08:36 UTC (rev 24502)
+++ squeeze/trunk/src/archive_store.c   2007-01-16 11:21:34 UTC (rev 24503)
@@ -131,6 +131,8 @@
 
 static void
 cb_sq_archive_store_archive_refreshed(LSQArchive *archive, gpointer user_data);
+static void
+cb_sq_archive_store_archive_path_changed(LSQArchive *archive, const gchar 
*path, gpointer user_data);
 
 GType
 sq_archive_store_get_type()
@@ -1094,6 +1096,7 @@
        if(store->archive)
        {
                g_signal_handlers_disconnect_by_func(store->archive, 
cb_sq_archive_store_archive_refreshed, store);
+               g_signal_handlers_disconnect_by_func(store->archive, 
cb_sq_archive_store_archive_path_changed, store);
                g_object_unref(store->archive);
                store->archive = NULL;
        }
@@ -1102,6 +1105,7 @@
                g_slist_free(list_iter->data);
 
        g_list_free(store->navigation.history);
+       g_slist_free(store->navigation.trailing);
 
        store->navigation.history = NULL;
        store->navigation.present = NULL;
@@ -1130,6 +1134,7 @@
 
        g_signal_emit(store, 
sq_archive_store_signals[SQ_ARCHIVE_STORE_SIGNAL_NEW_ARCHIVE], 0, NULL);
        g_signal_connect(store->archive, "lsq_refreshed", 
G_CALLBACK(cb_sq_archive_store_archive_refreshed), store);
+       g_signal_connect(store->archive, "lsq_path_changed", 
G_CALLBACK(cb_sq_archive_store_archive_path_changed), store);
 }
 
 gchar *
@@ -1252,6 +1257,7 @@
 
        if(path[0] == '/' && lsq_archive_iter_get_child(store->archive, entry, 
"/"))
        {
+               g_free(iter[0]);
                iter[0] = strdup("/");
        }
 
@@ -1264,7 +1270,7 @@
                        {
                                g_strfreev(buf);
                                g_slist_free(stack);
-                               return -1;
+                               return FALSE;
                        }
                        stack = g_slist_prepend(stack, entry);
                }
@@ -1450,9 +1456,9 @@
 static void
 sq_archive_store_append_history(SQArchiveStore *store, GSList *entry)
 {
-       if(lsq_archive_get_status(store->archive) != LSQ_ARCHIVESTATUS_IDLE)
+/*     if(lsq_archive_get_status(store->archive) != LSQ_ARCHIVESTATUS_IDLE)
                return;
-
+*/
        GList *iter = store->navigation.present;
 
        if(store->navigation.present)
@@ -1577,6 +1583,78 @@
        }
 }
 
+static void
+cb_sq_archive_store_archive_path_changed(LSQArchive *archive, const gchar 
*path, gpointer user_data)
+{
+       g_debug("%s %s", __FUNCTION__, path);
+       SQArchiveStore *store = SQ_ARCHIVE_STORE(user_data);
+
+       if(store->archive != archive)
+               return;
+
+#ifdef DEBUG
+       g_return_if_fail(store->navigation.present);
+       g_return_if_fail(store->navigation.present->data);
+#endif
+
+       GValue value;
+       gchar **buf = g_strsplit_set(path, "/\n", -1);
+       gchar **iter = buf;
+       GSList *entry, *back_list = NULL;
+       entry = (GSList*)store->navigation.present->data;
+
+       memset(&value, 0, sizeof(GValue));
+       
+       while(entry)
+       {
+               back_list = g_slist_prepend(back_list, entry->data);
+
+               entry = g_slist_next(entry);
+       }
+
+       if(path[0] == '/' && lsq_archive_iter_get_child(store->archive, 
lsq_archive_get_iter(archive, NULL), "/"))
+       {
+               g_free(iter[0]);
+               iter[0] = strdup("/");
+       }
+
+       entry = back_list;
+
+       while(*iter)
+       {
+               if((*iter)[0])
+               {
+                       lsq_archive_iter_get_prop_value(archive, 
(LSQArchiveIter*)entry, LSQ_ARCHIVE_PROP_FILENAME, &value);
+                       if(strcmp(*iter, g_value_get_string(&value)) == 0)
+                       {
+                               g_value_unset(&value);
+                               g_slist_free(back_list);
+                               g_strfreev(buf);
+                               return;
+                       }
+                       g_value_unset(&value);
+                       entry = g_slist_next(entry);
+               }
+               iter++;
+       }
+
+       g_slist_free(back_list);
+       g_strfreev(buf);
+
+       GList *list_iter;
+       for(list_iter = store->navigation.history; list_iter; list_iter = 
list_iter->next)
+               g_slist_free(list_iter->data);
+
+       g_list_free(store->navigation.history);
+
+       store->navigation.history = NULL;
+       store->navigation.present = NULL;
+       store->navigation.trailing = NULL;
+
+       sq_archive_store_append_history(store, g_slist_prepend(NULL, 
lsq_archive_get_iter(archive, NULL)));
+       sq_archive_store_set_pwd(store, path);
+}
+
 LSQArchive *
 sq_archive_store_get_archive(SQArchiveStore *archive_store)
 {

Modified: squeeze/trunk/src/main_window.c
===================================================================
--- squeeze/trunk/src/main_window.c     2007-01-16 10:08:36 UTC (rev 24502)
+++ squeeze/trunk/src/main_window.c     2007-01-16 11:21:34 UTC (rev 24503)
@@ -770,7 +770,7 @@
 
        if(filenames)
        {
-               dialog = gtk_message_dialog_new(GTK_WINDOW(window), 
GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_MODAL, GTK_MESSAGE_QUESTION, 
GTK_BUTTONS_YES_NO, "Are you sure you want to remove the selected files?");
+               dialog = gtk_message_dialog_new(GTK_WINDOW(window), 
GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO, "Are 
you sure you want to remove the selected files?");
                result = gtk_dialog_run(GTK_DIALOG(dialog));
                if(result == GTK_RESPONSE_YES)
                {

Modified: squeeze/trunk/src/widget_factory.c
===================================================================
--- squeeze/trunk/src/widget_factory.c  2007-01-16 10:08:36 UTC (rev 24502)
+++ squeeze/trunk/src/widget_factory.c  2007-01-16 11:21:34 UTC (rev 24503)
@@ -1001,7 +1001,7 @@
 static void
 sq_widget_factory_notify(LSQCustomAction *action, const gchar *message)
 {
-       GtkWidget *dialog = gtk_message_dialog_new(NULL, GTK_DIALOG_MODAL, 
GTK_MESSAGE_INFO, GTK_BUTTONS_CLOSE, "%s: %s", action->support->id, message);
+       GtkWidget *dialog = gtk_message_dialog_new(NULL, 
GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_INFO, GTK_BUTTONS_CLOSE, "%s: %s", 
action->support->id, message);
        gtk_dialog_run(GTK_DIALOG(dialog));
        gtk_widget_destroy(dialog);
 }

_______________________________________________
Xfce4-commits mailing list
[email protected]
http://foo-projects.org/mailman/listinfo/xfce4-commits

Reply via email to