[gnome-flashback] desktop: add show-home and show-trash settings



commit 51934f45fc8c8a8796237b64e82c67d53d9a964a
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date:   Fri Nov 15 04:09:02 2019 +0200

    desktop: add show-home and show-trash settings

 ...gnome.gnome-flashback.desktop.icons.gschema.xml |  12 ++
 gnome-flashback/libdesktop/Makefile.am             |   4 +
 gnome-flashback/libdesktop/gf-home-icon.c          |  72 ++++++++
 gnome-flashback/libdesktop/gf-home-icon.h          |  33 ++++
 gnome-flashback/libdesktop/gf-icon-view.c          | 194 ++++++++++++++++++---
 gnome-flashback/libdesktop/gf-icon-view.h          |   2 +
 gnome-flashback/libdesktop/gf-trash-icon.c         |  72 ++++++++
 gnome-flashback/libdesktop/gf-trash-icon.h         |  33 ++++
 8 files changed, 397 insertions(+), 25 deletions(-)
---
diff --git a/data/schemas/org.gnome.gnome-flashback.desktop.icons.gschema.xml 
b/data/schemas/org.gnome.gnome-flashback.desktop.icons.gschema.xml
index 792357e..8e43c0c 100644
--- a/data/schemas/org.gnome.gnome-flashback.desktop.icons.gschema.xml
+++ b/data/schemas/org.gnome.gnome-flashback.desktop.icons.gschema.xml
@@ -38,5 +38,17 @@
       <summary>Row spacing</summary>
       <description>The amount of space between rows.</description>
     </key>
+
+    <key type="b" name="show-home">
+      <default>true</default>
+      <summary>Show home icon</summary>
+      <description>If this is set to true, an icon linking to the home folder will be put on the 
desktop.</description>
+    </key>
+
+    <key type="b" name="show-trash">
+      <default>true</default>
+      <summary>Show trash icon</summary>
+      <description>If this is set to true, an icon linking to the trash will be put on the 
desktop.</description>
+    </key>
   </schema>
 </schemalist>
diff --git a/gnome-flashback/libdesktop/Makefile.am b/gnome-flashback/libdesktop/Makefile.am
index 93077a0..82a8799 100644
--- a/gnome-flashback/libdesktop/Makefile.am
+++ b/gnome-flashback/libdesktop/Makefile.am
@@ -27,6 +27,10 @@ libdesktop_la_SOURCES = \
        gf-desktop.h \
        gf-dummy-icon.c \
        gf-dummy-icon.h \
+       gf-home-icon.c \
+       gf-home-icon.h \
+       gf-trash-icon.c \
+       gf-trash-icon.h \
        gf-icon-view.c \
        gf-icon-view.h \
        gf-icon.c \
diff --git a/gnome-flashback/libdesktop/gf-home-icon.c b/gnome-flashback/libdesktop/gf-home-icon.c
new file mode 100644
index 0000000..f31b2aa
--- /dev/null
+++ b/gnome-flashback/libdesktop/gf-home-icon.c
@@ -0,0 +1,72 @@
+/*
+ * Copyright (C) 2019 Alberts Muktupāvels
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+#include "gf-home-icon.h"
+
+struct _GfHomeIcon
+{
+  GfIcon parent;
+};
+
+G_DEFINE_TYPE (GfHomeIcon, gf_home_icon, GF_TYPE_ICON)
+
+static void
+gf_home_icon_class_init (GfHomeIconClass *self_class)
+{
+}
+
+static void
+gf_home_icon_init (GfHomeIcon *self)
+{
+}
+
+GtkWidget *
+gf_home_icon_new (GfIconView  *icon_view,
+                  GError     **error)
+{
+  GFile *file;
+  char *attributes;
+  GFileQueryInfoFlags flags;
+  GFileInfo *info;
+  GtkWidget *widget;
+
+  file = g_file_new_for_path (g_get_home_dir ());
+
+  attributes = gf_icon_view_get_file_attributes (icon_view);
+  flags = G_FILE_QUERY_INFO_NONE;
+
+  info = g_file_query_info (file, attributes, flags, NULL, error);
+  g_free (attributes);
+
+  if (info == NULL)
+    {
+      g_object_unref (file);
+      return NULL;
+    }
+
+  widget = g_object_new (GF_TYPE_HOME_ICON,
+                         "icon-view", icon_view,
+                         "file", file,
+                         "info", info,
+                         NULL);
+
+  g_object_unref (file);
+  g_object_unref (info);
+
+  return widget;
+}
diff --git a/gnome-flashback/libdesktop/gf-home-icon.h b/gnome-flashback/libdesktop/gf-home-icon.h
new file mode 100644
index 0000000..f185f29
--- /dev/null
+++ b/gnome-flashback/libdesktop/gf-home-icon.h
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2019 Alberts Muktupāvels
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GF_HOME_ICON_H
+#define GF_HOME_ICON_H
+
+#include "gf-icon.h"
+
+G_BEGIN_DECLS
+
+#define GF_TYPE_HOME_ICON (gf_home_icon_get_type ())
+G_DECLARE_FINAL_TYPE (GfHomeIcon, gf_home_icon, GF, HOME_ICON, GfIcon)
+
+GtkWidget *gf_home_icon_new (GfIconView  *icon_view,
+                             GError     **error);
+
+G_END_DECLS
+
+#endif
diff --git a/gnome-flashback/libdesktop/gf-icon-view.c b/gnome-flashback/libdesktop/gf-icon-view.c
index 31b1416..c0fd18f 100644
--- a/gnome-flashback/libdesktop/gf-icon-view.c
+++ b/gnome-flashback/libdesktop/gf-icon-view.c
@@ -26,9 +26,11 @@
 #include "gf-desktop-enums.h"
 #include "gf-dummy-icon.h"
 #include "gf-file-manager-gen.h"
+#include "gf-home-icon.h"
 #include "gf-icon.h"
 #include "gf-monitor-view.h"
 #include "gf-nautilus-gen.h"
+#include "gf-trash-icon.h"
 #include "gf-utils.h"
 
 typedef struct
@@ -61,6 +63,9 @@ struct _GfIconView
 
   GList            *icons;
 
+  GfIconInfo       *home_info;
+  GfIconInfo       *trash_info;
+
   GList            *selected_icons;
 
   GtkCssProvider   *rubberband_css;
@@ -105,21 +110,6 @@ build_attributes_list (const char *first,
   return g_string_free (attributes, FALSE);
 }
 
-static char *
-get_required_attributes (void)
-{
-  return build_attributes_list (G_FILE_ATTRIBUTE_STANDARD_NAME,
-                                G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME,
-                                G_FILE_ATTRIBUTE_STANDARD_ICON,
-                                G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
-                                G_FILE_ATTRIBUTE_STANDARD_IS_HIDDEN,
-                                G_FILE_ATTRIBUTE_STANDARD_IS_BACKUP,
-                                G_FILE_ATTRIBUTE_STANDARD_TYPE,
-                                G_FILE_ATTRIBUTE_STANDARD_SIZE,
-                                G_FILE_ATTRIBUTE_TIME_MODIFIED,
-                                NULL);
-}
-
 static GfIconInfo *
 gf_icon_info_new (GtkWidget *icon)
 {
@@ -515,13 +505,8 @@ show_item_properties_cb (GObject      *object,
 
 static GfIconInfo *
 create_icon_info (GfIconView *self,
-                  GFile      *file,
-                  GFileInfo  *info)
+                  GtkWidget  *icon)
 {
-  GtkWidget *icon;
-
-  icon = gf_icon_new (self, file, info);
-
   g_signal_connect (icon, "selected",
                     G_CALLBACK (icon_selected_cb),
                     self);
@@ -546,6 +531,7 @@ query_info_cb (GObject      *object,
   GFileInfo *file_info;
   GError *error;
   GfIconView *self;
+  GtkWidget *icon;
   GfIconInfo *icon_info;
 
   file = G_FILE (object);
@@ -564,9 +550,10 @@ query_info_cb (GObject      *object,
 
   self = GF_ICON_VIEW (user_data);
 
-  icon_info = create_icon_info (self, file, file_info);
+  icon = gf_icon_new (self, file, file_info);
   g_object_unref (file_info);
 
+  icon_info = create_icon_info (self, icon);
   self->icons = g_list_prepend (self->icons, icon_info);
 
   if (self->placement == GF_PLACEMENT_AUTO_ARRANGE_ICONS)
@@ -582,7 +569,7 @@ file_created (GfIconView *self,
 
   char *attributes;
 
-  attributes = get_required_attributes ();
+  attributes = gf_icon_view_get_file_attributes (self);
 
   g_file_query_info_async (created_file,
                            attributes,
@@ -1325,6 +1312,52 @@ size_changed_cb (GtkWidget  *view,
   add_icons (self);
 }
 
+static void
+append_home_icon (GfIconView *self)
+{
+  GError *error;
+  GtkWidget *icon;
+
+  if (self->home_info != NULL)
+    return;
+
+  error = NULL;
+  icon = gf_home_icon_new (self, &error);
+
+  if (error != NULL)
+    {
+      g_warning ("%s", error->message);
+      g_error_free (error);
+      return;
+    }
+
+  self->home_info = create_icon_info (self, icon);
+  self->icons = g_list_prepend (self->icons, self->home_info);
+}
+
+static void
+append_trash_icon (GfIconView *self)
+{
+  GError *error;
+  GtkWidget *icon;
+
+  if (self->trash_info != NULL)
+    return;
+
+  error = NULL;
+  icon = gf_trash_icon_new (self, &error);
+
+  if (error != NULL)
+    {
+      g_warning ("%s", error->message);
+      g_error_free (error);
+      return;
+    }
+
+  self->trash_info = create_icon_info (self, icon);
+  self->icons = g_list_prepend (self->icons, self->trash_info);
+}
+
 static void
 next_files_cb (GObject      *object,
                GAsyncResult *res,
@@ -1356,17 +1389,25 @@ next_files_cb (GObject      *object,
     {
       GFileInfo *info;
       GFile *file;
+      GtkWidget *icon;
       GfIconInfo *icon_info;
 
       info = l->data;
       file = g_file_enumerator_get_child (enumerator, info);
 
-      icon_info = create_icon_info (self, file, info);
+      icon = gf_icon_new (self, file, info);
       g_object_unref (file);
 
+      icon_info = create_icon_info (self, icon);
       self->icons = g_list_prepend (self->icons, icon_info);
     }
 
+  if (g_settings_get_boolean (self->settings, "show-home"))
+    append_home_icon (self);
+
+  if (g_settings_get_boolean (self->settings, "show-trash"))
+    append_trash_icon (self);
+
   g_list_free_full (files, g_object_unref);
 
   if (self->placement == GF_PLACEMENT_AUTO_ARRANGE_ICONS)
@@ -1413,7 +1454,7 @@ enumerate_desktop (GfIconView *self)
 {
   char *attributes;
 
-  attributes = get_required_attributes ();
+  attributes = gf_icon_view_get_file_attributes (self);
 
   g_file_enumerate_children_async (self->desktop,
                                    attributes,
@@ -1653,6 +1694,86 @@ sort_by_changed_cb (GSettings  *settings,
     resort_icons (self);
 }
 
+static void
+show_home_changed_cb (GSettings  *settings,
+                      const char *key,
+                      GfIconView *self)
+{
+  if (g_settings_get_boolean (self->settings, key))
+    {
+      append_home_icon (self);
+
+      if (self->placement == GF_PLACEMENT_AUTO_ARRANGE_ICONS)
+        resort_icons (self);
+    }
+  else if (self->home_info != NULL)
+    {
+      GfIconInfo *info;
+
+      info = self->home_info;
+
+      if (info->view != NULL)
+        {
+          GtkWidget *icon;
+
+          icon = info->icon;
+
+          gf_monitor_view_remove_icon (GF_MONITOR_VIEW (info->view), icon);
+          info->view = NULL;
+
+          self->selected_icons = g_list_remove (self->selected_icons, icon);
+          self->rubberband_icons = g_list_remove (self->rubberband_icons, icon);
+        }
+
+      self->icons = g_list_remove (self->icons, self->home_info);
+      gf_icon_info_free (self->home_info);
+      self->home_info = NULL;
+
+      if (self->placement == GF_PLACEMENT_AUTO_ARRANGE_ICONS)
+        remove_and_readd_icons (self);
+    }
+}
+
+static void
+show_trash_changed_cb (GSettings  *settings,
+                       const char *key,
+                       GfIconView *self)
+{
+  if (g_settings_get_boolean (self->settings, key))
+    {
+      append_trash_icon (self);
+
+      if (self->placement == GF_PLACEMENT_AUTO_ARRANGE_ICONS)
+        resort_icons (self);
+    }
+  else if (self->trash_info != NULL)
+    {
+      GfIconInfo *info;
+
+      info = self->trash_info;
+
+      if (info->view != NULL)
+        {
+          GtkWidget *icon;
+
+          icon = info->icon;
+
+          gf_monitor_view_remove_icon (GF_MONITOR_VIEW (info->view), icon);
+          info->view = NULL;
+
+          self->selected_icons = g_list_remove (self->selected_icons, icon);
+          self->rubberband_icons = g_list_remove (self->rubberband_icons, icon);
+        }
+
+      self->icons = g_list_remove (self->icons, self->trash_info);
+      gf_icon_info_free (self->trash_info);
+      self->trash_info = NULL;
+
+      if (self->placement == GF_PLACEMENT_AUTO_ARRANGE_ICONS)
+        remove_and_readd_icons (self);
+    }
+}
+
 static GdkFilterReturn
 filter_func (GdkXEvent *xevent,
              GdkEvent  *event,
@@ -1974,6 +2095,14 @@ gf_icon_view_init (GfIconView *self)
                     G_CALLBACK (sort_by_changed_cb),
                     self);
 
+  g_signal_connect (self->settings, "changed::show-home",
+                    G_CALLBACK (show_home_changed_cb),
+                    self);
+
+  g_signal_connect (self->settings, "changed::show-trash",
+                    G_CALLBACK (show_trash_changed_cb),
+                    self);
+
   self->placement = g_settings_get_enum (self->settings, "placement");
   self->placement = warn_if_placement_not_implemented (self, self->placement);
   self->sort_by = g_settings_get_enum (self->settings, "sort-by");
@@ -2034,6 +2163,21 @@ gf_icon_view_new (void)
                        NULL);
 }
 
+char *
+gf_icon_view_get_file_attributes (GfIconView *self)
+{
+  return build_attributes_list (G_FILE_ATTRIBUTE_STANDARD_NAME,
+                                G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME,
+                                G_FILE_ATTRIBUTE_STANDARD_ICON,
+                                G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
+                                G_FILE_ATTRIBUTE_STANDARD_IS_HIDDEN,
+                                G_FILE_ATTRIBUTE_STANDARD_IS_BACKUP,
+                                G_FILE_ATTRIBUTE_STANDARD_TYPE,
+                                G_FILE_ATTRIBUTE_STANDARD_SIZE,
+                                G_FILE_ATTRIBUTE_TIME_MODIFIED,
+                                NULL);
+}
+
 void
 gf_icon_view_set_representative_color (GfIconView *self,
                                        GdkRGBA    *color)
diff --git a/gnome-flashback/libdesktop/gf-icon-view.h b/gnome-flashback/libdesktop/gf-icon-view.h
index d716c51..bcfc8ab 100644
--- a/gnome-flashback/libdesktop/gf-icon-view.h
+++ b/gnome-flashback/libdesktop/gf-icon-view.h
@@ -27,6 +27,8 @@ G_DECLARE_FINAL_TYPE (GfIconView, gf_icon_view, GF, ICON_VIEW, GtkEventBox)
 
 GtkWidget *gf_icon_view_new                      (void);
 
+char      *gf_icon_view_get_file_attributes      (GfIconView         *self);
+
 void       gf_icon_view_set_representative_color (GfIconView         *self,
                                                   GdkRGBA            *color);
 
diff --git a/gnome-flashback/libdesktop/gf-trash-icon.c b/gnome-flashback/libdesktop/gf-trash-icon.c
new file mode 100644
index 0000000..edbeeba
--- /dev/null
+++ b/gnome-flashback/libdesktop/gf-trash-icon.c
@@ -0,0 +1,72 @@
+/*
+ * Copyright (C) 2019 Alberts Muktupāvels
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+#include "gf-trash-icon.h"
+
+struct _GfTrashIcon
+{
+  GfIcon parent;
+};
+
+G_DEFINE_TYPE (GfTrashIcon, gf_trash_icon, GF_TYPE_ICON)
+
+static void
+gf_trash_icon_class_init (GfTrashIconClass *self_class)
+{
+}
+
+static void
+gf_trash_icon_init (GfTrashIcon *self)
+{
+}
+
+GtkWidget *
+gf_trash_icon_new (GfIconView  *icon_view,
+                   GError     **error)
+{
+  GFile *file;
+  char *attributes;
+  GFileQueryInfoFlags flags;
+  GFileInfo *info;
+  GtkWidget *widget;
+
+  file = g_file_new_for_uri ("trash:///");
+
+  attributes = gf_icon_view_get_file_attributes (icon_view);
+  flags = G_FILE_QUERY_INFO_NONE;
+
+  info = g_file_query_info (file, attributes, flags, NULL, error);
+  g_free (attributes);
+
+  if (info == NULL)
+    {
+      g_object_unref (file);
+      return NULL;
+    }
+
+  widget = g_object_new (GF_TYPE_TRASH_ICON,
+                         "icon-view", icon_view,
+                         "file", file,
+                         "info", info,
+                         NULL);
+
+  g_object_unref (file);
+  g_object_unref (info);
+
+  return widget;
+}
diff --git a/gnome-flashback/libdesktop/gf-trash-icon.h b/gnome-flashback/libdesktop/gf-trash-icon.h
new file mode 100644
index 0000000..f16a67b
--- /dev/null
+++ b/gnome-flashback/libdesktop/gf-trash-icon.h
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2019 Alberts Muktupāvels
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GF_TRASH_ICON_H
+#define GF_TRASH_ICON_H
+
+#include "gf-icon.h"
+
+G_BEGIN_DECLS
+
+#define GF_TYPE_TRASH_ICON (gf_trash_icon_get_type ())
+G_DECLARE_FINAL_TYPE (GfTrashIcon, gf_trash_icon, GF, TRASH_ICON, GfIcon)
+
+GtkWidget *gf_trash_icon_new (GfIconView  *icon_view,
+                              GError     **error);
+
+G_END_DECLS
+
+#endif


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