gtk+3: fix dependencies for new gnome/accessibility/at-spi2-core
[oi-userland.git] / components / desktop / mate / caja / patches / 02-timeslider-caja-zfs-bar.patch
blob50f5353503db4d5f254f4c9ed2455d5d231af4d4
1 --- caja-1.28.0/src/caja-zfs-bar.h.orig 2024-02-26 08:42:41.083373824 +0100
2 +++ caja-1.28.0/src/caja-zfs-bar.h 2024-02-26 08:42:41.083327328 +0100
3 @@ -0,0 +1,56 @@
4 +#ifndef __CAJA_ZFS_BAR_H
5 +#define __CAJA_ZFS_BAR_H
7 +#include <gtk/gtk.h>
8 +#include <libcaja-private/caja-directory.h>
9 +#include "caja-window-slot.h"
11 +G_BEGIN_DECLS
13 +#define CAJA_TYPE_ZFS_BAR (caja_zfs_bar_get_type ())
14 +#define CAJA_ZFS_BAR(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), CAJA_TYPE_ZFS_BAR, CajaZfsBar))
15 +#define CAJA_ZFS_BAR_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), CAJA_TYPE_ZFS_BAR, CajaZfsBarClass))
16 +#define CAJA_IS_ZFS_BAR(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), CAJA_TYPE_ZFS_BAR))
17 +#define CAJA_IS_ZFS_BAR_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), CAJA_TYPE_ZFS_BAR))
18 +#define CAJA_ZFS_BAR_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), CAJA_TYPE_ZFS_BAR, CajaZfsBarClass))
20 +typedef struct CajaZfsBarPrivate CajaZfsBarPrivate;
22 +typedef struct
24 + GtkEventBox eventbox;
25 + CajaZfsBarPrivate *priv;
26 +} CajaZfsBar;
28 +typedef struct
30 + GtkEventBoxClass parent_class;
31 +} CajaZfsBarClass;
33 +GType caja_zfs_bar_get_type (void) G_GNUC_CONST;
35 +GtkWidget * caja_zfs_bar_new ();
37 +void caja_zfs_bar_setup (CajaZfsBar* bar,
38 + CajaDirectory *dir,
39 + CajaWindowSlot *active_slot,
40 + GtkToggleAction* action);
42 +void caja_zfs_bar_display (CajaZfsBar *bar,
43 + CajaWindow *window,
44 + CajaDirectory *new_dir,
45 + GCancellable* cancellable);
47 +void caja_zfs_set_snap (CajaZfsBar *bar,
48 + CajaDirectory *dir);
49 +void caja_zfs_bar_remove_and_skip_snap
50 + (CajaZfsBar *bar, char *path);
52 +void caja_zfs_bar_hide (CajaZfsBar *bar);
54 +void caja_zfs_bar_cancel_tasks (CajaWindow *window);
55 +CajaDirectory * caja_zfs_bar_get_dir (CajaZfsBar* bar);
57 +G_END_DECLS
59 +#endif /* __CAJA_ZFS_BAR_H */
60 --- caja-1.28.0/src/caja-zfs-bar.c.orig 2024-02-26 08:42:41.083214681 +0100
61 +++ caja-1.28.0/src/caja-zfs-bar.c 2024-02-26 08:42:41.083165019 +0100
62 @@ -0,0 +1,851 @@
63 +/*
64 + * Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved.
65 + *
66 + */
68 +#include "config.h"
69 +#include <strings.h>
70 +#include <glib/gi18n-lib.h>
71 +#include <gtk/gtk.h>
73 +#include "caja-zfs-bar.h"
74 +#include "caja-window.h"
75 +#include "caja-window-private.h"
76 +#include "timescale.h"
77 +#include <libcaja-private/caja-zfs.h>
78 +#include <libcaja-private/caja-file.h>
79 +#include <libcaja-private/caja-global-preferences.h>
80 +#include "caja-window-slot.h"
81 +#include "caja-navigation-window.h"
83 +#define CAJA_ZFS_BAR_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), CAJA_TYPE_ZFS_BAR, CajaZfsBarPrivate))
85 +struct CajaZfsBarPrivate
87 + CajaDirectory *dir;
88 + GtkWidget *scale;
89 + GtkWidget *delete_button;
90 + GdkColor in_snapshot;
91 + GtkToggleAction *action;
92 + CajaWindowSlot *slot;
93 + int num_range_items;
94 + gboolean is_setup;
95 + gboolean set_only;
96 + char *current_path;
97 + ZfsSnapDirMonitor *zfs_dir_monitor_data;
98 + gboolean in_snapshot_dir;
99 + GtkWidget *camera_image;
100 + GtkWidget *delete_image;
101 + gboolean explicit_user_hide;
104 +G_DEFINE_TYPE (CajaZfsBar, caja_zfs_bar, GTK_TYPE_EVENT_BOX)
106 +static void
107 +close_clicked_callback (GtkWidget *widget,
108 + CajaZfsBar *bar);
109 +static void
110 +slider_moved_callback (TimeScale *ts,
111 + CajaZfsBar *bar);
112 +static void
113 +update_delete_or_snap_button (CajaZfsBar *bar,
114 + gboolean in_snap);
116 +static void
117 +caja_zfs_bar_class_init (CajaZfsBarClass *klass)
119 + GObjectClass *object_class;
121 + object_class = G_OBJECT_CLASS (klass);
123 + g_type_class_add_private (klass, sizeof (CajaZfsBarPrivate));
126 +static void
127 +set_scale_range (CajaZfsBar *bar, gboolean set_initial_position)
129 + int i;
130 + GList *tmp;
132 + if (bar->priv->dir)
134 + i = caja_directory_get_num_snapshots (bar->priv->dir);
136 + if (i==0)
137 + return;
139 + bar->priv->num_range_items = i;
141 + tmp = caja_directory_get_snapshots (bar->priv->dir);
143 + if (set_initial_position)
144 + timescale_set_snapshots (TIMESCALE (bar->priv->scale), tmp, -1);
145 + else
146 + timescale_set_snapshots (TIMESCALE (bar->priv->scale), tmp, bar->priv->num_range_items);
150 +static void
151 +update_range (CajaZfsBar *bar)
153 + if (caja_directory_get_snapshots (bar->priv->dir))
155 + set_scale_range (bar, FALSE);
156 + slider_moved_callback (TIMESCALE (bar->priv->scale), bar);
158 + else
159 + close_clicked_callback (NULL, bar);
162 +static int
163 +match_func (ZfsDataSet *set, char *dir)
165 + /* remove trailing slash from dir */
166 + char mountp[PATH_MAX+1];
167 + int length = strlen (set->mountpoint);
169 + if (set->mountpoint[length-1] == '/')
171 + memcpy (mountp, set->mountpoint, length - 1);
172 + mountp[length-1] = NULL;
173 + return strcmp (mountp, dir);
175 + else
176 + return strcmp (set->mountpoint, dir);
179 +void
180 +caja_zfs_bar_remove_and_skip_snap (CajaZfsBar *bar, char *path)
182 + GList* match = NULL;
183 + GList* snap_list = NULL;
184 + ZfsDataSet *snap;
186 + snap_list = caja_directory_get_snapshots (bar->priv->dir);
187 + match = g_list_find_custom (snap_list, path, (GCompareFunc)match_func);
189 + if (match)
191 + snap = (ZfsDataSet*) match->data;
192 + caja_directory_remove_snapshot (bar->priv->dir, snap);
193 + update_range (bar);
197 +static void
198 +update_delete_or_snap_button (CajaZfsBar *bar, gboolean in_snap)
200 + if (in_snap)
202 + if (!bar->priv->in_snapshot_dir)
203 + { /*in main dir to snap */
204 + bar->priv->in_snapshot_dir = TRUE;
205 + g_object_ref (bar->priv->camera_image);
206 + gtk_button_set_image (GTK_BUTTON (bar->priv->delete_button),
207 + bar->priv->delete_image);
208 + gtk_widget_set_tooltip_text (bar->priv->delete_button,
209 + /* SUN_BRANDING */
210 + _("Delete this snapshot"));
213 + else
215 + if (bar->priv->in_snapshot_dir)
216 + { /* in snap to main dir */
217 + bar->priv->in_snapshot_dir = FALSE;
218 + g_object_ref (bar->priv->delete_image);
219 + gtk_button_set_image (GTK_BUTTON (bar->priv->delete_button),
220 + bar->priv->camera_image);
221 + gtk_widget_set_tooltip_text (bar->priv->delete_button,
222 + /* SUN_BRANDING */
223 + _("Take a zfs snapshot of this directory now"));
228 +static void
229 +slider_moved_callback (TimeScale *ts,
230 + CajaZfsBar *bar)
232 + GList *tmp;
233 + ZfsDataSet *snap;
234 + GFile *snap_file;
235 + int pos = timescale_get_position (ts);
237 + if (pos < bar->priv->num_range_items)
239 + tmp = caja_directory_get_snapshots (bar->priv->dir);
241 + snap = g_list_nth_data (tmp, pos);
243 + snap_file = g_file_new_for_path (snap->mountpoint);
245 + else
247 + snap_file = caja_directory_get_location (bar->priv->dir);
248 + pos = bar->priv->num_range_items;
251 + if (!bar->priv->set_only)
253 + gboolean in_snap = FALSE;
254 + char *path = g_file_get_path (snap_file);
256 + if (g_file_test (path, G_FILE_TEST_IS_DIR))
258 + caja_window_slot_go_to (bar->priv->slot,
259 + snap_file,
260 + FALSE);
261 + if (bar->priv->current_path)
262 + g_free (bar->priv->current_path);
263 + bar->priv->current_path = path;
265 + else
266 + { /* the snapshot diappeared try the next one */
267 + g_free (path);
268 + g_object_unref (snap_file);
269 + /* remove snap from list */
270 + caja_directory_remove_snapshot (bar->priv->dir, snap);
271 + update_range (bar);
272 + return;
275 + in_snap = ts_is_in_snapshot (path);
276 + update_delete_or_snap_button (bar, ts_is_in_snapshot (path));
280 + g_object_unref (snap_file);
284 +static void
285 +delete_clicked_callback (GtkWidget *widget,
286 + CajaZfsBar *bar)
288 + GList *tmp;
289 + ZfsDataSet *snap;
290 + GFile *snap_file;
291 + char *path;
292 + char *full_command;
293 + int pos = timescale_get_position (TIMESCALE (bar->priv->scale));
295 + if (bar->priv->in_snapshot_dir)
297 + tmp = caja_directory_get_snapshots (bar->priv->dir);
298 + snap = g_list_nth_data (tmp, pos);
299 + snap_file = g_file_new_for_path (snap->mountpoint);
300 + path = g_file_get_path (snap_file);
302 + g_object_unref (snap_file);
303 + if (snap->type)
305 + /*printf ("path %s snapshot to delete %s\n", path, snap->name);*/
306 + full_command = g_strdup_printf ("/usr/lib/time-slider-delete '%s'", snap->name);
308 + else
310 + /*printf ("path %s backup to delete %s\n", path, snap->name);*/
311 + full_command = g_strdup_printf ("/usr/lib/time-slider-delete '%s'", path);
314 + mate_gdk_spawn_command_line_on_screen (gtk_widget_get_screen (widget),
315 + full_command, NULL);
317 + else
319 + path = g_file_get_path (caja_directory_get_location (bar->priv->dir));
320 + char *fs = ts_get_zfs_filesystem (path);
321 + /* printf ("take a snapshot of zfs fs %s for dir %s\n", fs, path); */
322 + full_command = g_strdup_printf ("/usr/lib/time-slider-snapshot '%s' '%s'", path, fs);
323 + mate_gdk_spawn_command_line_on_screen (gtk_widget_get_screen (widget),
324 + full_command, NULL);
325 + g_free (fs);
328 + g_free (full_command);
329 + g_free (path);
332 +static void
333 +close_clicked_callback (GtkWidget *widget,
334 + CajaZfsBar *bar)
336 + GFile *snap_file = caja_directory_get_location (bar->priv->dir);
338 + caja_window_slot_go_to (bar->priv->slot,
339 + snap_file,
340 + FALSE);
341 + g_object_unref (snap_file);
343 + bar->priv->is_setup = FALSE;
345 + gtk_widget_hide (GTK_WIDGET (bar));
346 + gtk_toggle_action_set_active (bar->priv->action, FALSE);
350 +static void
351 +caja_zfs_bar_init (CajaZfsBar *bar)
353 + GtkWidget *hbox, *toolbar, *close, *delete, *image, *button_vbox;
354 + GtkToolItem *item;
355 + char *path;
357 + bar->priv = CAJA_ZFS_BAR_GET_PRIVATE (bar);
359 + bar->priv->dir = NULL;
360 + bar->priv->num_range_items = 0;
361 + bar->priv->action = NULL;
362 + bar->priv->slot = NULL;
363 + bar->priv->is_setup = FALSE;
364 + bar->priv->set_only = FALSE;
366 + /* GUI init */
368 + toolbar = gtk_toolbar_new ();
369 + gtk_widget_show (toolbar);
371 + item = gtk_tool_item_new ();
372 + gtk_widget_show (GTK_WIDGET (item));
373 + gtk_tool_item_set_expand (item, TRUE);
375 + hbox = gtk_hbox_new (FALSE, 2);
376 + gtk_widget_show (GTK_WIDGET (hbox));
378 + gtk_container_add (GTK_CONTAINER (item),hbox);
380 + gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
381 + gtk_container_add (GTK_CONTAINER (bar),toolbar);
382 + gtk_container_set_border_width (GTK_CONTAINER (bar), 0);
384 + /* buttons */
386 + button_vbox = gtk_vbox_new (FALSE, 0);
387 + gtk_widget_show (button_vbox);
389 + close = gtk_button_new ();
390 + gtk_button_set_relief (GTK_BUTTON (close), GTK_RELIEF_NONE);
391 + gtk_widget_set_tooltip_text (close,
392 + /* SUN_BRANDING */
393 + _("Close Time Slider and return to original directory"));
394 + gtk_widget_show (close);
396 + g_signal_connect (close,
397 + "clicked",
398 + G_CALLBACK (close_clicked_callback),
399 + bar);
401 + image = gtk_image_new_from_stock (GTK_STOCK_CLOSE,
402 + GTK_ICON_SIZE_MENU);
403 + gtk_widget_show (image);
405 + gtk_container_add (GTK_CONTAINER (close), image);
407 + gtk_box_pack_start (GTK_BOX (button_vbox), close, FALSE, FALSE, 0);
409 + delete = gtk_button_new ();
410 + gtk_button_set_relief (GTK_BUTTON (delete), GTK_RELIEF_NONE);
411 + gtk_widget_set_tooltip_text (delete,
412 + /* SUN_BRANDING */
413 + _("Take a zfs snapshot of this directory now"));
414 + gtk_widget_show (delete);
416 + g_signal_connect (delete,
417 + "clicked",
418 + G_CALLBACK (delete_clicked_callback),
419 + bar);
422 + GtkIconTheme *it = gtk_icon_theme_get_default ();
423 + GdkPixbuf * pb = gtk_icon_theme_load_icon (it,
424 + "user-trash-full.png",
425 + 16,
426 + GTK_ICON_LOOKUP_GENERIC_FALLBACK,
427 + NULL);
428 + bar->priv->delete_image = gtk_image_new_from_pixbuf (pb);
429 + g_object_unref (pb);
432 + path = caja_pixmap_file ("camera.png");
433 + bar->priv->camera_image = gtk_image_new_from_file (path);
434 + g_free (path);
436 + gtk_widget_show (bar->priv->delete_image);
437 + gtk_widget_show (bar->priv->camera_image);
439 + gtk_container_add (GTK_CONTAINER (delete), bar->priv->camera_image);
441 + gtk_box_pack_end (GTK_BOX (button_vbox), delete, FALSE, FALSE, 0);
442 + gtk_box_pack_end (GTK_BOX (hbox), button_vbox, FALSE, FALSE, 0);
444 + bar->priv->delete_button = delete;
446 + bar->priv->scale = timescale_new();
448 + g_signal_connect (bar->priv->scale,
449 + "value-changed",
450 + G_CALLBACK (slider_moved_callback),
451 + bar);
453 + gtk_widget_show (bar->priv->scale);
455 + gtk_box_pack_start (GTK_BOX (hbox), bar->priv->scale, TRUE, TRUE, 0);
459 + CajaDirectory *
460 +caja_zfs_bar_get_dir (CajaZfsBar* bar)
462 + g_return_val_if_fail (CAJA_IS_ZFS_BAR (bar), NULL);
463 + return bar->priv->dir;
466 +static void
467 +snapshot_data_ready (CajaDirectory *dir,
468 + GCancellable *cancellable,
469 + gpointer callback_data)
471 + CajaWindowSlot *slot;
472 + GFile *location;
473 + GFile *dir_location;
474 + CajaWindow *window = (CajaWindow*)callback_data;
476 + g_return_if_fail (CAJA_IS_WINDOW (window));
478 + slot = caja_window_get_active_slot (window);
479 + location = caja_window_slot_get_location (slot);
480 + dir_location = caja_directory_get_location (dir);
482 + if (g_cancellable_is_cancelled (cancellable) && g_file_equal (location, dir_location))
484 + caja_navigation_window_set_spinner_active (CAJA_NAVIGATION_WINDOW (window), FALSE);
485 + caja_navigation_window_set_restore_icon ( CAJA_NAVIGATION_WINDOW (window), RESTORE_NO);
487 + else if (g_file_equal (location, dir_location))
489 + char *path = g_file_get_path (dir_location);
490 + g_cancellable_cancel (cancellable);
491 + caja_window_slot_set_allow_stop (slot, FALSE);
492 + caja_navigation_window_set_restore_icon ( CAJA_NAVIGATION_WINDOW (window),
493 + caja_directory_has_snapshots (dir) ? RESTORE_NORMAL : RESTORE_NO);
494 + if (caja_directory_has_snapshots (dir))
495 + caja_window_allow_restore (window, TRUE);
496 + else
497 + caja_window_allow_restore (window, FALSE);
498 + g_free (path);
500 + else
502 + caja_window_slot_set_allow_stop (slot, FALSE);
504 + g_object_unref (location);
505 + g_object_unref (dir_location);
509 +void
510 +caja_zfs_bar_cancel_tasks (CajaWindow *window)
512 + if (CAJA_IS_WINDOW (window))
514 + if (CAJA_IS_WINDOW_SLOT (window->details->active_pane->active_slot))
516 + CajaDirectory *directory = NULL;
517 + g_cancellable_cancel (window->details->active_pane->active_slot->find_zfs_snapshots_cancellable);
518 + g_object_unref (window->details->active_pane->active_slot->find_zfs_snapshots_cancellable);
519 + window->details->active_pane->active_slot->find_zfs_snapshots_cancellable = NULL;
520 + directory = caja_directory_get (window->details->active_pane->active_slot->location);
521 + if (directory)
523 + caja_directory_cancel_restore_info (directory);
524 + caja_directory_unref (directory);
527 + if (CAJA_IS_NAVIGATION_WINDOW (window))
529 + CajaZfsBar *bar = CAJA_ZFS_BAR (CAJA_NAVIGATION_WINDOW (window)->zfs_bar);
530 + monitor_zfs_snap_directory_cancel (bar->priv->zfs_dir_monitor_data);
531 + bar->priv->zfs_dir_monitor_data = NULL;
536 +void
537 +caja_zfs_bar_hide (CajaZfsBar *bar)
539 + bar->priv->explicit_user_hide = TRUE;
540 + close_clicked_callback (NULL, bar);
544 +/* Display AND Scan */
546 +void
547 +caja_zfs_bar_display (CajaZfsBar *bar,
548 + CajaWindow *window,
549 + CajaDirectory *new_dir,
550 + GCancellable *cancellable)
552 + gboolean show = FALSE;
553 + gboolean time_slider_enabled = g_settings_get_boolean (caja_preferences,
554 + CAJA_PREFERENCES_ENABLE_TIME_SLIDER);
555 + gboolean visible = gtk_widget_get_visible (GTK_WIDGET (bar));
556 + gboolean enable_button = FALSE;
557 + gboolean do_scan = FALSE;
558 + gboolean do_cancel = FALSE;
561 + /* if bar visible
562 + * if feature disabled
563 + * close bar
564 + * disable button
565 + * if in root dir
566 + * enable button
567 + * else
568 + * if bar was previously displayed and in same tab
569 + * if in snapshot
570 + * redisplay
571 + * re-align
572 + * disable button
573 + * if root dir
574 + * redisplay
575 + * re-align
576 + * enable button
577 + * else
578 + * scan
579 + * else
580 + * if feature enabled
581 + * scan
582 + * disable button
585 + * NOTE : action_restore_callback display bar when enabled
586 + */
588 + if (visible)
590 + if (!time_slider_enabled)
592 + close_clicked_callback (NULL, bar);
593 + return;
595 + if (new_dir == bar->priv->dir)
596 + enable_button = TRUE;
597 + if (caja_directory_is_a_snapshot_dir_of (new_dir, bar->priv->dir) || new_dir == bar->priv->dir)
599 + show = TRUE;
600 + do_cancel = TRUE;
601 + enable_button = TRUE;
603 + else
604 + do_scan = TRUE;
606 + else
607 + { /* bar is not visible */
608 + CajaWindowSlot *slot = caja_window_get_active_slot (window);
610 + if (bar->priv->is_setup && slot == bar->priv->slot && time_slider_enabled) /* check if we can redisplay the bar */
612 + if (caja_directory_is_a_snapshot_dir_of (new_dir, bar->priv->dir) && !bar->priv->explicit_user_hide)
613 + show = TRUE;
615 + if (bar->priv->explicit_user_hide)
616 + enable_button = FALSE;
618 + if (new_dir == bar->priv->dir)
620 + show = TRUE;
621 + enable_button = TRUE;
623 + else
624 + do_scan = TRUE;
626 + else
627 + { /* icon and throbber set is snapshot_data_ready */
628 + if (time_slider_enabled)
629 + do_scan = TRUE;
634 + if (enable_button) /* if button enabled set the icon to normal */
635 + caja_navigation_window_set_restore_icon (CAJA_NAVIGATION_WINDOW (window), RESTORE_NORMAL);
637 + caja_window_allow_restore (window, enable_button);
640 + if (show)
642 + gtk_widget_show (GTK_WIDGET (bar));
643 + caja_zfs_set_snap (bar, new_dir);
645 + else
647 + gtk_widget_hide (GTK_WIDGET (bar));
648 + if (bar->priv->action)
649 + gtk_toggle_action_set_active (bar->priv->action, FALSE);
652 + if (do_cancel)
653 + g_cancellable_cancel (cancellable);
655 + if (do_scan)
657 + g_cancellable_reset (cancellable);
658 + caja_navigation_window_set_restore_icon (CAJA_NAVIGATION_WINDOW (window), RESTORE_SEARCH);
659 + caja_window_slot_set_allow_stop (caja_window_get_active_slot (window), TRUE);
660 + caja_directory_get_snapshots_async (new_dir,
661 + snapshot_data_ready,
662 + cancellable,
663 + window);
666 + /* {
667 + GFile *file = caja_directory_get_location (new_dir);
668 + char *path = g_file_get_path (file);
670 + printf ("caja_zfs_bar_display %s\nenable_button : %s, show : %s, do_cancel : %s, do_scan : %s\n\n",
671 + path,
672 + enable_button ? "true" : "false",
673 + show ? "true" : "false",
674 + do_cancel ? "true" : "false",
675 + do_scan ? "true" : "false");
676 + g_free (path);
677 + }*/
681 +void
682 +caja_zfs_set_snap (CajaZfsBar *bar,
683 + CajaDirectory *dir)
685 + GList* match = NULL;
686 + GList* snap_list = NULL;
687 + gboolean in_snap = FALSE;
688 + char real_path [PATH_MAX+1];
689 + GFile *file;
690 + char* path;
691 + int pos;
692 + int set_pos = -2;
694 + if (!bar->priv->is_setup)
695 + return;
697 + file = caja_directory_get_location (dir);
698 + path = g_file_get_path (file);
699 + ts_realpath (path, real_path);
702 + if (ts_is_in_remote_backup (real_path))
703 + {
704 + /*FIXME: we do not have it */
705 + //mate_vfs_init();
706 + g_object_ref (dir);
709 + in_snap = ts_is_in_snapshot (real_path);
711 + if (in_snap)
713 + snap_list = caja_directory_get_snapshots (bar->priv->dir);
714 + match = g_list_find_custom (snap_list, real_path, (GCompareFunc)match_func);
716 + g_free (path);
717 + g_object_unref (file);
719 + timescale_set_position (TIMESCALE (bar->priv->scale), match ? ((ZfsDataSet*)match->data)->mountpoint : NULL);
720 + update_delete_or_snap_button (bar, in_snap);
722 + /* printf ("caja_zfs_set_snap current_path %s real_path %s match %s\n", bar->priv->current_path, real_path,
723 + match ? "found" : "not found");*/
725 + if (bar->priv->current_path && (strcmp (bar->priv->current_path, real_path) != 0))
727 + bar->priv->set_only = TRUE;
728 + bar->priv->set_only = FALSE;
733 +static void
734 +snapshot_data_ready_from_change (CajaDirectory *dir,
735 + GCancellable *cancellable,
736 + gpointer callback_data)
738 + CajaZfsBar *bar = CAJA_ZFS_BAR (callback_data);
740 + snapshot_data_ready (dir, cancellable, bar->priv->slot->pane->window);
741 + update_range (bar);
742 + gtk_widget_set_sensitive (bar->priv->scale, TRUE);
745 +static void
746 +zfs_dir_change_callback (ZfsSnapDirMonitor *monitor_data,
747 + CajaZfsBar *bar)
749 + gtk_widget_set_sensitive (bar->priv->scale, FALSE);
751 + g_cancellable_reset (bar->priv->slot->find_zfs_snapshots_cancellable);
752 + caja_navigation_window_set_restore_icon (CAJA_NAVIGATION_WINDOW (bar->priv->slot->pane->window), RESTORE_SEARCH);
753 + caja_window_slot_set_allow_stop (bar->priv->slot, TRUE);
754 + caja_directory_get_snapshots_async (bar->priv->dir,
755 + snapshot_data_ready_from_change,
756 + bar->priv->slot->find_zfs_snapshots_cancellable,
757 + bar);
760 +static char*
761 +get_backup_dir (GList *snaplist)
763 + GList *tmp = snaplist;
765 + while (tmp)
767 + ZfsDataSet *snap = (ZfsDataSet*) tmp->data;
768 + if (snap->type == 0)
770 + char **root_split = NULL;
771 + char *result = NULL;
772 + root_split = g_strsplit (snap->mountpoint, snap->name, 2);
773 + /*printf (" name: %s\n mountpoint: %s\n mtime_str :%s\n space used : %s\n size in kilobytes : %f\n",
774 + snap->name, snap->mountpoint, snap->mtime_str, snap->used_space_str, snap->used_space); */
775 + result = g_strdup (root_split[0]);
776 + if (root_split)
777 + g_strfreev (root_split);
778 + return result;
780 + tmp = tmp->next;
782 + return NULL;
785 +void
786 +caja_zfs_bar_setup (CajaZfsBar* bar,
787 + CajaDirectory *dir,
788 + CajaWindowSlot *active_slot,
789 + GtkToggleAction* action)
791 + GFile *file;
792 + char *path, *zfs_dir, *backup_dir = NULL;
793 + bar->priv->dir = dir;
794 + g_object_ref (dir);
795 + bar->priv->slot = active_slot;
796 + g_object_ref (active_slot);
798 + bar->priv->action = action;
799 + set_scale_range (bar, TRUE);
800 + bar->priv->is_setup = TRUE;
801 + bar->priv->explicit_user_hide = FALSE;
803 + file = caja_directory_get_location (dir);
804 + path = g_file_get_path (file);
805 + zfs_dir = ts_get_snapshot_dir (path);
806 + backup_dir = get_backup_dir (caja_directory_get_snapshots (dir));
808 + bar->priv->zfs_dir_monitor_data = monitor_zfs_snap_directory (zfs_dir,
809 + backup_dir,
810 + (ZfsDirChangeCallback) zfs_dir_change_callback,
811 + bar);
812 + caja_zfs_set_snap (bar, dir);
813 + g_free (path);
814 + g_free (zfs_dir);
815 + if (backup_dir)
816 + g_free(backup_dir);
817 + g_object_unref (file);
820 +static void
821 +zfs_bar_show_column (GtkWidget *widget, gpointer user_data)
823 + char **visible_columns;
824 + gboolean restore_col_visible = FALSE;
825 + int i = 0;
826 + GPtrArray *ret = NULL;
828 + visible_columns = g_settings_get_strv (caja_list_view_preferences,
829 + CAJA_PREFERENCES_LIST_VIEW_DEFAULT_VISIBLE_COLUMNS);
831 + ret = g_ptr_array_new ();
833 + /* convert visible_columns in ptr array without "restore_info" */
834 + while (visible_columns[i])
836 + if (strcmp (visible_columns [i], "restore_info") == 0)
838 + restore_col_visible = TRUE;
839 + break;
841 + else
842 + g_ptr_array_add (ret, g_strdup (visible_columns [i]));
843 + i++;
846 + g_strfreev (visible_columns);
848 + if (restore_col_visible)
850 + if (!gtk_widget_get_visible (widget)) /* hide bar remove pref */
852 + char **col_array;
853 + g_ptr_array_add (ret, NULL);
854 + col_array = (char **)g_ptr_array_free (ret, FALSE);
855 + g_settings_set_strv (caja_list_view_preferences,
856 + CAJA_PREFERENCES_LIST_VIEW_DEFAULT_VISIBLE_COLUMNS,
857 + (const char * const *)col_array);
858 + g_strfreev (col_array);
859 + ret = NULL;
862 + else
864 + if (gtk_widget_get_visible (widget))
866 + char **col_array;
867 + g_ptr_array_add (ret,strdup ("restore_info"));
868 + g_ptr_array_add (ret,NULL);
869 + col_array = (char **)g_ptr_array_free (ret, FALSE);
870 + g_settings_set_strv (caja_list_view_preferences,
871 + CAJA_PREFERENCES_LIST_VIEW_DEFAULT_VISIBLE_COLUMNS,
872 + (const char * const *)col_array);
873 + g_strfreev (col_array);
874 + ret = NULL;
879 + if (ret)
880 + g_ptr_array_free (ret, TRUE);
884 +static void
885 +zfs_bar_hidden (GtkWidget *widget, gpointer user_data)
887 + CajaZfsBar *bar = CAJA_ZFS_BAR (user_data);
888 + monitor_zfs_snap_directory_cancel (bar->priv->zfs_dir_monitor_data);
889 + bar->priv->zfs_dir_monitor_data = NULL;
890 + caja_directory_cancel_restore_info (bar->priv->dir);
893 +GtkWidget *
894 +caja_zfs_bar_new ()
896 + GObject *bar;
897 + CajaZfsBar *zfs_bar;
899 + bar = g_object_new (CAJA_TYPE_ZFS_BAR, NULL);
901 + g_signal_connect_object (bar, "show", G_CALLBACK (zfs_bar_show_column), bar, 0);
902 + g_signal_connect_object (bar, "hide", G_CALLBACK (zfs_bar_show_column), bar, 0);
903 + g_signal_connect_object (bar, "hide", G_CALLBACK (zfs_bar_hidden), bar, 0);
905 + zfs_bar_show_column (GTK_WIDGET (bar), NULL);
907 + ts_is_restore_column_enabled_init ();
909 + zfs_bar = CAJA_ZFS_BAR (bar);
911 + return GTK_WIDGET (bar);