From 15122ffa647a54ccbb86d3ecb8d09cd3cec1cfcf Mon Sep 17 00:00:00 2001 From: Pierre Pronchery Date: Sat, 10 Feb 2018 15:20:32 +0100 Subject: [PATCH] Import the "shutdown" applet --- po/POTFILES | 1 + src/applets/project.conf | 10 +++- src/applets/shutdown.c | 112 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 122 insertions(+), 1 deletion(-) create mode 100644 src/applets/shutdown.c diff --git a/po/POTFILES b/po/POTFILES index 4c6cf11..bfbdeaf 100644 --- a/po/POTFILES +++ b/po/POTFILES @@ -18,6 +18,7 @@ ../src/applets/network.c ../src/applets/pager.c ../src/applets/rotate.c +../src/applets/shutdown.c ../src/applets/swap.c ../src/applets/systray.c ../src/applets/tasks.c diff --git a/src/applets/project.conf b/src/applets/project.conf index 07ca9b8..c34ed9c 100644 --- a/src/applets/project.conf +++ b/src/applets/project.conf @@ -1,4 +1,4 @@ -targets=battery,bluetooth,brightness,clock,close,cpu,cpufreq,desktop,embed,gps,gsm,leds,lock,logout,menu,memory,mixer,mpd,network,pager,phone,rotate,separator,spacer,swap,systray,tasks,template,title,usb,user,volume,wpa_supplicant +targets=battery,bluetooth,brightness,clock,close,cpu,cpufreq,desktop,embed,gps,gsm,leds,lock,logout,menu,memory,mixer,mpd,network,pager,phone,rotate,separator,shutdown,spacer,swap,systray,tasks,template,title,usb,user,volume,wpa_supplicant cppflags_force=-I ../../include #cppflags=-D EMBEDDED cflags=-W -Wall -g -O2 -pedantic -D_FORTIFY_SOURCE=2 -fstack-protector @@ -212,6 +212,14 @@ install=$(LIBDIR)/Panel/applets [separator.c] depends=../../include/Panel.h +[shutdown] +type=plugin +sources=shutdown.c +install=$(LIBDIR)/Panel/applets + +[shutdown.c] +depends=../../include/Panel.h + [spacer] type=plugin sources=spacer.c diff --git a/src/applets/shutdown.c b/src/applets/shutdown.c new file mode 100644 index 0000000..dc2270e --- /dev/null +++ b/src/applets/shutdown.c @@ -0,0 +1,112 @@ +/* $Id$ */ +/* Copyright (c) 2010-2018 Pierre Pronchery */ +/* This file is part of DeforaOS Desktop Panel */ +/* 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, version 3 of the License. + * + * 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 . */ + + + +#include +#include +#include +#include +#include +#include "Panel/applet.h" +#define _(string) gettext(string) + + +/* Shutdown */ +/* private */ +/* types */ +typedef struct _PanelApplet +{ + PanelAppletHelper * helper; + GtkWidget * widget; +} Shutdown; + + +/* prototypes */ +static Shutdown * _shutdown_init(PanelAppletHelper * helper, GtkWidget ** widget); +static void _shutdown_destroy(Shutdown * shutdown); + +/* callbacks */ +static void _shutdown_on_clicked(gpointer data); + + +/* public */ +/* variables */ +PanelAppletDefinition applet = +{ + "Shutdown", + "gnome-shutdown", + NULL, + _shutdown_init, + _shutdown_destroy, + NULL, + FALSE, + TRUE +}; + + +/* private */ +/* functions */ +/* shutdown_init */ +static Shutdown * _shutdown_init(PanelAppletHelper * helper, + GtkWidget ** widget) +{ + Shutdown * shutdown; + GtkWidget * image; + + if((shutdown = malloc(sizeof(*shutdown))) == NULL) + { + error_set("%s: %s", applet.name, strerror(errno)); + return NULL; + } + shutdown->helper = helper; + if(helper->shutdown_dialog == NULL) + { + error_set("%s: %s", applet.name, + _("Shutting down is not allowed")); + return NULL; + } + shutdown->widget = gtk_button_new(); + image = gtk_image_new_from_icon_name("gnome-shutdown", + panel_window_get_icon_size(helper->window)); + gtk_button_set_image(GTK_BUTTON(shutdown->widget), image); + gtk_button_set_relief(GTK_BUTTON(shutdown->widget), GTK_RELIEF_NONE); +#if GTK_CHECK_VERSION(2, 12, 0) + gtk_widget_set_tooltip_text(shutdown->widget, _("Shutdown")); +#endif + g_signal_connect_swapped(shutdown->widget, "clicked", G_CALLBACK( + _shutdown_on_clicked), shutdown); + gtk_widget_show_all(shutdown->widget); + *widget = shutdown->widget; + return shutdown; +} + + +/* shutdown_destroy */ +static void _shutdown_destroy(Shutdown * shutdown) +{ + gtk_widget_destroy(shutdown->widget); + free(shutdown); +} + + +/* callbacks */ +/* shutdown_on_clicked */ +static void _shutdown_on_clicked(gpointer data) +{ + Shutdown * shutdown = data; + + shutdown->helper->shutdown_dialog(shutdown->helper->panel); +}