[Xfce4-commits] [panel-plugins/xfce4-whiskermenu-plugin] 419/473: Monitor profile picture for changes.

noreply at xfce.org noreply at xfce.org
Mon Feb 16 23:59:49 CET 2015


This is an automated email from the git hooks/post-receive script.

gottcode pushed a commit to branch master
in repository panel-plugins/xfce4-whiskermenu-plugin.

commit 877ce2498d7a01eb6dbef8f8fa81bf129f2ef01d
Author: Graeme Gott <graeme at gottcode.org>
Date:   Sun Dec 7 20:52:41 2014 -0500

    Monitor profile picture for changes.
---
 panel-plugin/slot.h     |    2 +-
 panel-plugin/window.cpp |   52 +++++++++++++++++++++++++++++++----------------
 panel-plugin/window.h   |    4 ++++
 3 files changed, 39 insertions(+), 19 deletions(-)

diff --git a/panel-plugin/slot.h b/panel-plugin/slot.h
index 47576f4..f0202b2 100644
--- a/panel-plugin/slot.h
+++ b/panel-plugin/slot.h
@@ -251,7 +251,7 @@ gulong g_signal_connect_slot(gpointer instance, const gchar* detailed_signal, R(
 	class Slot
 	{
 		T* m_instance;
-		R (T::*m_member)(A1,A2,A3);
+		R (T::*m_member)(A1,A2,A3,A4);
 
 	public:
 		Slot(T* instance, R (T::*member)(A1,A2,A3,A4)) :
diff --git a/panel-plugin/window.cpp b/panel-plugin/window.cpp
index c280f52..586eccc 100644
--- a/panel-plugin/window.cpp
+++ b/panel-plugin/window.cpp
@@ -30,7 +30,6 @@
 
 #include <exo/exo.h>
 #include <gdk/gdkkeysyms.h>
-#include <libxfce4panel/libxfce4panel.h>
 #include <libxfce4ui/libxfce4ui.h>
 
 #include <ctime>
@@ -93,29 +92,19 @@ WhiskerMenu::Window::Window() :
 	gtk_box_pack_start(m_window_box, m_window_contents, true, true, 0);
 
 	// Create the profile picture
-	XfcePanelImage* profilepic = XFCE_PANEL_IMAGE(xfce_panel_image_new());
-
-	gint face_width = 32, face_height = 32;
-	gtk_icon_size_lookup(GTK_ICON_SIZE_DND, &face_width, &face_height);
+	m_profilepic_image = XFCE_PANEL_IMAGE(xfce_panel_image_new());
 
 	gchar* face_path = g_build_filename(g_get_home_dir(), ".face", NULL);
-	GdkPixbuf* face = gdk_pixbuf_new_from_file_at_size(face_path, face_width, face_height, NULL);
+	GFile* face_file = g_file_new_for_path(face_path);
+	m_profilepic_monitor = g_file_monitor_file(face_file, G_FILE_MONITOR_NONE, NULL, NULL);
+	g_signal_connect_slot(m_profilepic_monitor, "changed", &Window::on_profilepic_changed, this);
+	on_profilepic_changed(m_profilepic_monitor, face_file, NULL, G_FILE_MONITOR_EVENT_CHANGED);
+	g_object_unref(face_file);
 	g_free(face_path);
 
-	if (face)
-	{
-		xfce_panel_image_set_from_pixbuf(profilepic, face);
-		g_object_unref(face);
-	}
-	else
-	{
-		xfce_panel_image_set_size(profilepic, face_height);
-		xfce_panel_image_set_from_source(profilepic, "avatar-default");
-	}
-
 	m_profilepic = gtk_alignment_new(0.5, 0.5, 0, 0);
 	gtk_alignment_set_padding(GTK_ALIGNMENT(m_profilepic), 0, 0, 10, 10);
-	gtk_container_add(GTK_CONTAINER(m_profilepic), GTK_WIDGET(profilepic));
+	gtk_container_add(GTK_CONTAINER(m_profilepic), GTK_WIDGET(m_profilepic_image));
 
 	// Create the username label
 	const gchar* name = g_get_real_name();
@@ -276,6 +265,10 @@ WhiskerMenu::Window::~Window()
 	delete m_favorites;
 
 	delete m_resizer;
+
+	g_file_monitor_cancel(m_profilepic_monitor);
+	g_object_unref(m_profilepic_monitor);
+
 	g_object_unref(m_window);
 }
 
@@ -887,6 +880,29 @@ gboolean WhiskerMenu::Window::on_expose_event(GtkWidget* widget, GdkEventExpose*
 
 //-----------------------------------------------------------------------------
 
+void WhiskerMenu::Window::on_profilepic_changed(GFileMonitor*, GFile* file, GFile*, GFileMonitorEvent)
+{
+	gint face_width = 32, face_height = 32;
+	gtk_icon_size_lookup(GTK_ICON_SIZE_DND, &face_width, &face_height);
+
+	gchar* face_path = g_file_get_path(file);
+	GdkPixbuf* face = gdk_pixbuf_new_from_file_at_size(face_path, face_width, face_height, NULL);
+	g_free(face_path);
+
+	if (face)
+	{
+		xfce_panel_image_set_from_pixbuf(m_profilepic_image, face);
+		g_object_unref(face);
+	}
+	else
+	{
+		xfce_panel_image_set_size(m_profilepic_image, face_height);
+		xfce_panel_image_set_from_source(m_profilepic_image, "avatar-default");
+	}
+}
+
+//-----------------------------------------------------------------------------
+
 void WhiskerMenu::Window::favorites_toggled()
 {
 	m_favorites->reset_selection();
diff --git a/panel-plugin/window.h b/panel-plugin/window.h
index 945a80a..5e5f13d 100644
--- a/panel-plugin/window.h
+++ b/panel-plugin/window.h
@@ -21,6 +21,7 @@
 #include <vector>
 
 #include <gtk/gtk.h>
+#include <libxfce4panel/libxfce4panel.h>
 
 namespace WhiskerMenu
 {
@@ -83,6 +84,7 @@ private:
 	gboolean on_configure_event(GtkWidget*, GdkEvent* event);
 	void on_screen_changed_event(GtkWidget* widget, GdkScreen* old_screen);
 	gboolean on_expose_event(GtkWidget* widget, GdkEventExpose* event);
+	void on_profilepic_changed(GFileMonitor* monitor, GFile* file, GFile* other_file, GFileMonitorEvent event_type);
 	void favorites_toggled();
 	void recent_toggled();
 	void category_toggled();
@@ -107,6 +109,8 @@ private:
 	GtkBox* m_sidebar_box;
 
 	GtkWidget* m_profilepic;
+	XfcePanelImage* m_profilepic_image;
+	GFileMonitor* m_profilepic_monitor;
 	GtkLabel* m_username;
 	ResizerWidget* m_resizer;
 

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Xfce4-commits mailing list