[bijiben] Archive: start on UI for archive



commit 4ce8ce220891c8d3acf18727468f469b83498cce
Author: Pierre-Yves Luyten <py luyten fr>
Date:   Sun Dec 1 01:41:40 2013 +0100

    Archive: start on UI for archive
    
    Land some buttons. Clicking still has no effect.

 src/bjb-selection-toolbar.c   |    1 +
 src/bjb-trash-bar.c           |  126 ++++++++++++++++++++++++++++++++++++++--
 src/bjb-trash-bar.h           |    1 +
 src/libbiji/biji-item.c       |   21 +++++++
 src/libbiji/biji-item.h       |    8 +++
 src/libbiji/biji-local-note.c |   30 ++++++++++
 src/libbiji/biji-manager.c    |    6 ++
 src/libbiji/biji-manager.h    |    3 +
 8 files changed, 189 insertions(+), 7 deletions(-)
---
diff --git a/src/bjb-selection-toolbar.c b/src/bjb-selection-toolbar.c
index 016864b..bed3205 100644
--- a/src/bjb-selection-toolbar.c
+++ b/src/bjb-selection-toolbar.c
@@ -395,6 +395,7 @@ bjb_selection_toolbar_constructed(GObject *obj)
           bjb_window_base_get_controller (
                 BJB_WINDOW_BASE (
                   bjb_main_view_get_window (self->priv->view))),
+          self->priv->view,
           self->priv->selection);
 
 
diff --git a/src/bjb-trash-bar.c b/src/bjb-trash-bar.c
index 1b8bdbd..ba952bf 100644
--- a/src/bjb-trash-bar.c
+++ b/src/bjb-trash-bar.c
@@ -32,6 +32,7 @@ enum
 {
   PROP_0,
   PROP_BJB_SELECTION,
+  PROP_BJB_MAIN_VIEW,
   PROP_BJB_CONTROLLER,
   NUM_PROPERTIES
 };
@@ -45,11 +46,15 @@ struct BjbTrashBarPrivate_
 {
   GtkWidget     *bar;
   BjbController *controller;
+  BjbMainView   *view;
   GdMainView    *selection;
 
+  GtkWidget     *normal_box;
+  GtkWidget     *empty_bin;
+
+  GtkWidget     *selection_box;
   GtkWidget     *restore;
   GtkWidget     *delete;
-  GtkWidget     *empty_bin;
 };
 
 
@@ -58,26 +63,60 @@ struct BjbTrashBarPrivate_
 G_DEFINE_TYPE (BjbTrashBar, bjb_trash_bar, GTK_TYPE_BOX)
 
 
+
+static void
+on_empty_clicked_callback        (BjbTrashBar *self)
+{
+  GList *selection;
+
+  selection = bjb_main_view_get_selected_items (self->priv->view);
+  g_list_free (selection);
+}
+
+
+static void
+on_restore_clicked_callback      (BjbTrashBar *self)
+{
+  GList *selection;
+
+  selection = bjb_main_view_get_selected_items (self->priv->view);
+  g_list_free (selection);
+}
+
+
+static void
+on_delete_clicked_callback        (BjbTrashBar *self)
+{
+  GList *selection;
+
+  selection = bjb_main_view_get_selected_items (self->priv->view);
+  g_list_free (selection);
+}
+
+
 void
 bjb_trash_bar_set_visibility      (BjbTrashBar *self)
 {
-/*
   BjbTrashBarPrivate *priv;
   GList *items;
 
   priv = self->priv;
+
+
+  gtk_widget_hide (priv->normal_box);
+  gtk_widget_hide (priv->selection_box);
   items = gd_main_view_get_selection (priv->selection);
 
   if (items != NULL)
-    gtk_widget_hide (priv->empty_bin);
+    gtk_widget_show (priv->selection_box);
 
   else
-    gtk_widget_show (priv->empty_bin);
+    gtk_widget_show (priv->normal_box);
 
   g_list_free (items);
-*/
 }
 
+
 void
 bjb_trash_bar_fade_in             (BjbTrashBar *self)
 {
@@ -134,6 +173,10 @@ bjb_trash_bar_set_property (GObject  *object,
       self->priv->controller = g_value_get_object (value);
       break;
 
+    case PROP_BJB_MAIN_VIEW:
+      self->priv->view = g_value_get_object (value);
+      break;
+
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
       break;
@@ -146,14 +189,71 @@ bjb_trash_bar_constructed (GObject *obj)
 {
   BjbTrashBar *self;
   BjbTrashBarPrivate *priv;
+  GtkWidget *super_box, *separator;
 
   G_OBJECT_CLASS (bjb_trash_bar_parent_class)->constructed (obj);
 
   self = BJB_TRASH_BAR (obj);
   priv = self->priv;
 
-  priv->empty_bin = gtk_label_new (_("Empty"));
-  //gtk_container_add (GTK_CONTAINER (self), priv->empty_bin);
+  super_box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
+  gtk_container_add (GTK_CONTAINER (self), super_box);
+
+  /* No selection : just offer to empty bin */
+  priv->normal_box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 2);
+  gtk_widget_set_hexpand (priv->normal_box, TRUE);
+  priv->empty_bin = gtk_button_new_with_label(_("Empty"));
+  gtk_widget_set_halign (priv->empty_bin, GTK_ALIGN_CENTER);
+  gtk_box_pack_start (GTK_BOX (priv->normal_box),
+                      priv->empty_bin,
+                      TRUE,
+                      FALSE,
+                      0);
+  gtk_container_add (GTK_CONTAINER (super_box), priv->normal_box);
+  g_signal_connect_swapped (priv->empty_bin,
+                            "clicked",
+                            G_CALLBACK (on_empty_clicked_callback),
+                            self);
+
+
+  /* Selection : delete or restore selected items */
+  priv->selection_box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 2);
+  gtk_widget_set_hexpand (priv->selection_box, TRUE);
+  priv->restore = gtk_button_new_with_label (_("Restore"));
+  gtk_widget_set_halign (priv->restore, GTK_ALIGN_START);
+  gtk_box_pack_start (GTK_BOX (priv->selection_box),
+                      priv->restore,
+                      FALSE,
+                      FALSE,
+                      4);
+  g_signal_connect_swapped (priv->restore,
+                            "clicked",
+                            G_CALLBACK (on_restore_clicked_callback),
+                            self);
+
+  separator = gtk_frame_new (NULL);
+  gtk_frame_set_shadow_type (GTK_FRAME (separator), GTK_SHADOW_NONE);
+  gtk_widget_set_hexpand (priv->selection_box, TRUE);
+  gtk_box_pack_start (GTK_BOX (priv->selection_box),
+                      separator,
+                      TRUE,
+                      FALSE,
+                      4);
+
+  priv->delete = gtk_button_new_with_label (_("Permanently Delete"));
+  gtk_widget_set_halign (priv->delete, GTK_ALIGN_END);
+  gtk_box_pack_start (GTK_BOX (priv->selection_box),
+                      priv->delete,
+                      FALSE,
+                      FALSE,
+                      4);
+  gtk_container_add (GTK_CONTAINER (super_box), priv->selection_box);
+  g_signal_connect_swapped (priv->delete,
+                            "clicked",
+                            G_CALLBACK (on_delete_clicked_callback),
+                            self);
+
+
   gtk_widget_show_all (GTK_WIDGET (self));
 }
 
@@ -186,6 +286,16 @@ bjb_trash_bar_class_init (BjbTrashBarClass *klass)
                                                          G_PARAM_CONSTRUCT |
                                                          G_PARAM_STATIC_STRINGS);
 
+
+  properties[PROP_BJB_MAIN_VIEW] = g_param_spec_object ("view",
+                                                        "view",
+                                                        "View",
+                                                        BJB_TYPE_MAIN_VIEW,
+                                                        G_PARAM_READWRITE  |
+                                                        G_PARAM_CONSTRUCT |
+                                                        G_PARAM_STATIC_STRINGS);
+
+
   g_object_class_install_properties (object_class, NUM_PROPERTIES, properties);
 
   g_type_class_add_private ((gpointer)klass, sizeof (BjbTrashBarPrivate));
@@ -202,12 +312,14 @@ bjb_trash_bar_init (BjbTrashBar *self)
 
 BjbTrashBar *
 bjb_trash_bar_new (BjbController *controller,
+                   BjbMainView   *parent,
                    GdMainView *view)
 {
   return g_object_new (BJB_TYPE_TRASH_BAR,
                        "orientation", GTK_ORIENTATION_HORIZONTAL,
                        "spacing", 2,
                        "controller", controller,
+                       "view", parent,
                        "selection", view,
                         NULL);
 }
diff --git a/src/bjb-trash-bar.h b/src/bjb-trash-bar.h
index 3a8a3be..d5734cb 100644
--- a/src/bjb-trash-bar.h
+++ b/src/bjb-trash-bar.h
@@ -56,6 +56,7 @@ GType                 bjb_trash_bar_get_type            (void);
 
 
 BjbTrashBar *         bjb_trash_bar_new                 (BjbController *controller,
+                                                         BjbMainView   *view,
                                                          GdMainView    *selection);
 
 
diff --git a/src/libbiji/biji-item.c b/src/libbiji/biji-item.c
index 2454ee7..87a0854 100644
--- a/src/libbiji/biji-item.c
+++ b/src/libbiji/biji-item.c
@@ -204,6 +204,27 @@ biji_item_trash               (BijiItem *item)
   return BIJI_ITEM_GET_CLASS (item)->trash (item);
 }
 
+
+gboolean
+biji_item_restore             (BijiItem *item)
+{
+  g_return_val_if_fail (BIJI_IS_ITEM (item), FALSE);
+
+  return BIJI_ITEM_GET_CLASS (item)->restore (item);
+}
+
+
+
+gboolean
+biji_item_delete               (BijiItem *item)
+{
+  g_return_val_if_fail (BIJI_IS_ITEM (item), FALSE);
+
+  return BIJI_ITEM_GET_CLASS (item)->delete (item);
+}
+
+
+
 gboolean
 biji_item_is_collectable       (BijiItem *item)
 {
diff --git a/src/libbiji/biji-item.h b/src/libbiji/biji-item.h
index c57d7ba..59d5222 100644
--- a/src/libbiji/biji-item.h
+++ b/src/libbiji/biji-item.h
@@ -70,6 +70,8 @@ struct BijiItemClass_
   gboolean      (*has_color)            (BijiItem *item);
 
   gboolean      (*trash)                (BijiItem *item);
+  gboolean      (*restore)              (BijiItem *item);
+  gboolean      (*delete)               (BijiItem *item);
 
   gboolean      (*is_collectable)       (BijiItem *item);
   gboolean      (*has_notebook)       (BijiItem *item, gchar *coll);
@@ -117,6 +119,12 @@ gint64           biji_item_get_mtime           (BijiItem *item);
 gboolean         biji_item_trash               (BijiItem *item);
 
 
+gboolean         biji_item_restore             (BijiItem *item);
+
+
+gboolean         biji_item_delete              (BijiItem *item);
+
+
 gboolean         biji_item_is_collectable      (BijiItem *item);
 
 
diff --git a/src/libbiji/biji-local-note.c b/src/libbiji/biji-local-note.c
index 7b0758b..a83bdc6 100644
--- a/src/libbiji/biji-local-note.c
+++ b/src/libbiji/biji-local-note.c
@@ -196,6 +196,34 @@ local_note_archive (BijiNoteObj *note)
 }
 
 
+static gboolean
+local_note_restore (BijiItem *item)
+{
+  BijiLocalNote *self;
+
+  g_return_val_if_fail (BIJI_IS_LOCAL_NOTE (item), FALSE);
+  self = BIJI_LOCAL_NOTE (item);
+
+  g_warning ("local note restore");
+
+  return FALSE;
+}
+
+
+static gboolean
+local_note_delete (BijiItem *item)
+{
+  BijiLocalNote *self;
+
+  g_return_val_if_fail (BIJI_IS_LOCAL_NOTE (item), FALSE);
+  self = BIJI_LOCAL_NOTE (item);
+
+  g_warning ("local note delete");
+
+  return FALSE;
+}
+
+
 static gchar*
 local_note_get_basename (BijiNoteObj *note)
 {
@@ -219,6 +247,8 @@ biji_local_note_class_init (BijiLocalNoteClass *klass)
   item_class->is_collectable = item_yes;
   item_class->has_color = item_yes;
   item_class->get_place = local_note_get_place;
+  item_class->restore = local_note_restore;
+  item_class->delete = local_note_delete;
 
   note_class->get_basename = local_note_get_basename;
   note_class->get_html = local_note_get_html;
diff --git a/src/libbiji/biji-manager.c b/src/libbiji/biji-manager.c
index c01c2ed..2ad4dfb 100644
--- a/src/libbiji/biji-manager.c
+++ b/src/libbiji/biji-manager.c
@@ -629,6 +629,12 @@ biji_manager_load_archives          (BijiManager        *manager)
 
 
 
+void
+biji_manager_empty_bin              (BijiManager        *manager)
+{
+}
+
+
 BijiItem *
 biji_manager_get_item_at_path (BijiManager *manager, const gchar *path)
 {
diff --git a/src/libbiji/biji-manager.h b/src/libbiji/biji-manager.h
index 55b6b86..9524770 100644
--- a/src/libbiji/biji-manager.h
+++ b/src/libbiji/biji-manager.h
@@ -130,6 +130,9 @@ void             biji_manager_load_archives          (BijiManager        *manage
 
 
 
+void             biji_manager_empty_bin              (BijiManager        *manager);
+
+
 // deprecated - instead we'll use new import / providers facilities
 BijiNoteObj     *biji_note_get_new_from_file          (BijiManager *manager,
                                                        const gchar* tomboy_format_note_path);


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