[Xfce4-commits] [panel-plugins/xfce4-whiskermenu-plugin] 420/473: Move profile picture to separate class.

noreply at xfce.org noreply at xfce.org
Mon Feb 16 23:59:50 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 ec6e04f9b4d0790b02aeb9474d42b208acc5d607
Author: Graeme Gott <graeme at gottcode.org>
Date:   Mon Dec 8 05:38:16 2014 -0500

    Move profile picture to separate class.
---
 panel-plugin/CMakeLists.txt      |    1 +
 panel-plugin/profile-picture.cpp |   80 ++++++++++++++++++++++++++++++++++++++
 panel-plugin/profile-picture.h   |   48 +++++++++++++++++++++++
 panel-plugin/window.cpp          |   52 ++++---------------------
 panel-plugin/window.h            |    7 +---
 5 files changed, 139 insertions(+), 49 deletions(-)

diff --git a/panel-plugin/CMakeLists.txt b/panel-plugin/CMakeLists.txt
index a433ae1..1a9e5d9 100644
--- a/panel-plugin/CMakeLists.txt
+++ b/panel-plugin/CMakeLists.txt
@@ -82,6 +82,7 @@ add_library(whiskermenu MODULE
 	list-page.cpp
 	page.cpp
 	plugin.cpp
+	profile-picture.cpp
 	query.cpp
 	recent-page.cpp
 	register-plugin.c
diff --git a/panel-plugin/profile-picture.cpp b/panel-plugin/profile-picture.cpp
new file mode 100644
index 0000000..08e2385
--- /dev/null
+++ b/panel-plugin/profile-picture.cpp
@@ -0,0 +1,80 @@
+/*
+ * Copyright (C) 2014 Graeme Gott <graeme at gottcode.org>
+ *
+ * This library 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 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This library 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 library.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "profile-picture.h"
+
+#include "slot.h"
+
+#include <libxfce4panel/libxfce4panel.h>
+
+using namespace WhiskerMenu;
+
+//-----------------------------------------------------------------------------
+
+ProfilePicture::ProfilePicture()
+{
+	m_image = xfce_panel_image_new();
+
+	gchar* path = g_build_filename(g_get_home_dir(), ".face", NULL);
+	GFile* file = g_file_new_for_path(path);
+	g_free(path);
+
+	m_file_monitor = g_file_monitor_file(file, G_FILE_MONITOR_NONE, NULL, NULL);
+	g_signal_connect_slot(m_file_monitor, "changed", &ProfilePicture::on_file_changed, this);
+	on_file_changed(m_file_monitor, file);
+
+	g_object_unref(file);
+
+	m_alignment = gtk_alignment_new(0.5, 0.5, 0, 0);
+	gtk_alignment_set_padding(GTK_ALIGNMENT(m_alignment), 0, 0, 10, 10);
+	gtk_container_add(GTK_CONTAINER(m_alignment), m_image);
+}
+
+//-----------------------------------------------------------------------------
+
+ProfilePicture::~ProfilePicture()
+{
+	g_file_monitor_cancel(m_file_monitor);
+	g_object_unref(m_file_monitor);
+}
+
+//-----------------------------------------------------------------------------
+
+void ProfilePicture::on_file_changed(GFileMonitor*, GFile* file)
+{
+	gint width = 32, height = 32;
+	gtk_icon_size_lookup(GTK_ICON_SIZE_DND, &width, &height);
+
+	gchar* path = g_file_get_path(file);
+	GdkPixbuf* face = gdk_pixbuf_new_from_file_at_size(path, width, height, NULL);
+	g_free(path);
+
+	XfcePanelImage* image = XFCE_PANEL_IMAGE(m_image);
+	if (face)
+	{
+		xfce_panel_image_set_size(image, -1);
+		xfce_panel_image_set_from_pixbuf(image, face);
+		g_object_unref(face);
+	}
+	else
+	{
+		xfce_panel_image_set_size(image, height);
+		xfce_panel_image_set_from_source(image, "avatar-default");
+	}
+}
+
+//-----------------------------------------------------------------------------
diff --git a/panel-plugin/profile-picture.h b/panel-plugin/profile-picture.h
new file mode 100644
index 0000000..f1b5412
--- /dev/null
+++ b/panel-plugin/profile-picture.h
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2014 Graeme Gott <graeme at gottcode.org>
+ *
+ * This library 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 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This library 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 library.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef WHISKERMENU_PROFILE_PICTURE_H
+#define WHISKERMENU_PROFILE_PICTURE_H
+
+#include <gtk/gtk.h>
+
+namespace WhiskerMenu
+{
+
+class ProfilePicture
+{
+public:
+	ProfilePicture();
+	~ProfilePicture();
+
+	GtkWidget* get_widget() const
+	{
+		return m_alignment;
+	}
+
+private:
+	void on_file_changed(GFileMonitor* monitor, GFile* file);
+
+private:
+	GtkWidget* m_alignment;
+	GtkWidget* m_image;
+	GFileMonitor* m_file_monitor;
+};
+
+}
+
+#endif // WHISKERMENU_PROFILE_PICTURE_H
diff --git a/panel-plugin/window.cpp b/panel-plugin/window.cpp
index 586eccc..da83092 100644
--- a/panel-plugin/window.cpp
+++ b/panel-plugin/window.cpp
@@ -21,6 +21,7 @@
 #include "command.h"
 #include "favorites-page.h"
 #include "launcher-view.h"
+#include "profile-picture.h"
 #include "recent-page.h"
 #include "resizer-widget.h"
 #include "search-page.h"
@@ -92,19 +93,7 @@ WhiskerMenu::Window::Window() :
 	gtk_box_pack_start(m_window_box, m_window_contents, true, true, 0);
 
 	// Create the profile picture
-	m_profilepic_image = XFCE_PANEL_IMAGE(xfce_panel_image_new());
-
-	gchar* face_path = g_build_filename(g_get_home_dir(), ".face", 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);
-
-	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(m_profilepic_image));
+	m_profilepic = new ProfilePicture;
 
 	// Create the username label
 	const gchar* name = g_get_real_name();
@@ -184,7 +173,7 @@ WhiskerMenu::Window::Window() :
 	// Create box for packing username, commands, and resize widget
 	m_title_box = GTK_BOX(gtk_hbox_new(false, 0));
 	gtk_box_pack_start(m_vbox, GTK_WIDGET(m_title_box), false, false, 0);
-	gtk_box_pack_start(m_title_box, GTK_WIDGET(m_profilepic), false, false, 0);
+	gtk_box_pack_start(m_title_box, GTK_WIDGET(m_profilepic->get_widget()), false, false, 0);
 	gtk_box_pack_start(m_title_box, GTK_WIDGET(m_username), true, true, 0);
 	gtk_box_pack_start(m_title_box, GTK_WIDGET(m_commands_align), false, false, 0);
 	gtk_box_pack_start(m_title_box, GTK_WIDGET(m_resizer->get_widget()), false, false, 0);
@@ -264,11 +253,9 @@ WhiskerMenu::Window::~Window()
 	delete m_recent;
 	delete m_favorites;
 
+	delete m_profilepic;
 	delete m_resizer;
 
-	g_file_monitor_cancel(m_profilepic_monitor);
-	g_object_unref(m_profilepic_monitor);
-
 	g_object_unref(m_window);
 }
 
@@ -497,7 +484,7 @@ void WhiskerMenu::Window::show(GtkWidget* parent, bool horizontal)
 				gtk_box_reorder_child(m_commands_box, m_commands_button[i], i);
 			}
 
-			gtk_box_reorder_child(m_title_box, GTK_WIDGET(m_profilepic), 0);
+			gtk_box_reorder_child(m_title_box, GTK_WIDGET(m_profilepic->get_widget()), 0);
 			gtk_box_reorder_child(m_title_box, GTK_WIDGET(m_username), 1);
 			gtk_box_reorder_child(m_title_box, GTK_WIDGET(m_resizer->get_widget()), 2);
 
@@ -514,7 +501,7 @@ void WhiskerMenu::Window::show(GtkWidget* parent, bool horizontal)
 				gtk_box_reorder_child(m_commands_box, m_commands_button[i], 3 - i);
 			}
 
-			gtk_box_reorder_child(m_title_box, GTK_WIDGET(m_profilepic), 2);
+			gtk_box_reorder_child(m_title_box, GTK_WIDGET(m_profilepic->get_widget()), 2);
 			gtk_box_reorder_child(m_title_box, GTK_WIDGET(m_username), 1);
 			gtk_box_reorder_child(m_title_box, GTK_WIDGET(m_resizer->get_widget()), 0);
 
@@ -531,7 +518,7 @@ void WhiskerMenu::Window::show(GtkWidget* parent, bool horizontal)
 				gtk_box_reorder_child(m_commands_box, m_commands_button[i], i);
 			}
 
-			gtk_box_reorder_child(m_title_box, GTK_WIDGET(m_profilepic), 0);
+			gtk_box_reorder_child(m_title_box, GTK_WIDGET(m_profilepic->get_widget()), 0);
 			gtk_box_reorder_child(m_title_box, GTK_WIDGET(m_username), 1);
 			gtk_box_reorder_child(m_title_box, GTK_WIDGET(m_commands_align), 2);
 			gtk_box_reorder_child(m_title_box, GTK_WIDGET(m_resizer->get_widget()), 3);
@@ -546,7 +533,7 @@ void WhiskerMenu::Window::show(GtkWidget* parent, bool horizontal)
 				gtk_box_reorder_child(m_commands_box, m_commands_button[i], 3 - i);
 			}
 
-			gtk_box_reorder_child(m_title_box, GTK_WIDGET(m_profilepic), 3);
+			gtk_box_reorder_child(m_title_box, GTK_WIDGET(m_profilepic->get_widget()), 3);
 			gtk_box_reorder_child(m_title_box, GTK_WIDGET(m_username), 2);
 			gtk_box_reorder_child(m_title_box, GTK_WIDGET(m_commands_align), 1);
 			gtk_box_reorder_child(m_title_box, GTK_WIDGET(m_resizer->get_widget()), 0);
@@ -880,29 +867,6 @@ 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 5e5f13d..1345341 100644
--- a/panel-plugin/window.h
+++ b/panel-plugin/window.h
@@ -21,7 +21,6 @@
 #include <vector>
 
 #include <gtk/gtk.h>
-#include <libxfce4panel/libxfce4panel.h>
 
 namespace WhiskerMenu
 {
@@ -29,6 +28,7 @@ namespace WhiskerMenu
 class ApplicationsPage;
 class FavoritesPage;
 class Page;
+class ProfilePicture;
 class ResizerWidget;
 class RecentPage;
 class SearchPage;
@@ -84,7 +84,6 @@ 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();
@@ -108,9 +107,7 @@ private:
 	GtkBox* m_panels_box;
 	GtkBox* m_sidebar_box;
 
-	GtkWidget* m_profilepic;
-	XfcePanelImage* m_profilepic_image;
-	GFileMonitor* m_profilepic_monitor;
+	ProfilePicture* m_profilepic;
 	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