| 1 |
/** |
| 2 |
* This file is a part of the Cairo-Dock project |
| 3 |
* |
| 4 |
* Copyright : (C) see the 'copyright' file. |
| 5 |
* E-mail : see the 'copyright' file. |
| 6 |
* |
| 7 |
* This program is free software; you can redistribute it and/or |
| 8 |
* modify it under the terms of the GNU General Public License |
| 9 |
* as published by the Free Software Foundation; either version 3 |
| 10 |
* of the License, or (at your option) any later version. |
| 11 |
* |
| 12 |
* This program is distributed in the hope that it will be useful, |
| 13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 |
* GNU General Public License for more details. |
| 16 |
* You should have received a copy of the GNU General Public License |
| 17 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 18 |
*/ |
| 19 |
|
| 20 |
#include <stdlib.h> |
| 21 |
#include <glib/gi18n.h> |
| 22 |
|
| 23 |
#include "powermanager-upower.h" |
| 24 |
#include "powermanager-draw.h" |
| 25 |
#include "powermanager-struct.h" |
| 26 |
#include "powermanager-menu-functions.h" |
| 27 |
|
| 28 |
|
| 29 |
CD_APPLET_ON_CLICK_BEGIN |
| 30 |
gldi_dialogs_remove_on_icon (myIcon); |
| 31 |
cd_powermanager_bubble (); |
| 32 |
CD_APPLET_ON_CLICK_END |
| 33 |
|
| 34 |
static void power_launch_cmd (GtkMenuItem *menu_item, const gchar *cCommand) |
| 35 |
{ |
| 36 |
GError *erreur = NULL; |
| 37 |
g_spawn_command_line_async (cCommand, &erreur); |
| 38 |
|
| 39 |
if (erreur != NULL) |
| 40 |
{ |
| 41 |
cd_warning ("PM : %s", erreur->message); |
| 42 |
g_error_free (erreur); |
| 43 |
} |
| 44 |
} |
| 45 |
|
| 46 |
CD_APPLET_ON_BUILD_MENU_BEGIN |
| 47 |
gboolean bAddSeparator = FALSE; |
| 48 |
// Power preferences |
| 49 |
static gboolean bPowerPrefChecked = FALSE; |
| 50 |
static const gchar *cPowerPrefCmd = NULL; |
| 51 |
if (!bPowerPrefChecked) |
| 52 |
{ |
| 53 |
bPowerPrefChecked = TRUE; |
| 54 |
gchar *cResult = cairo_dock_launch_command_sync ("which gnome-control-center"); // Gnome3 |
| 55 |
if (cResult != NULL && *cResult == '/') |
| 56 |
{ |
| 57 |
cPowerPrefCmd = "gnome-control-center power"; |
| 58 |
} |
| 59 |
else |
| 60 |
{ |
| 61 |
g_free (cResult); |
| 62 |
cResult = cairo_dock_launch_command_sync ("which gnome-power-preferences"); // Gnome2 |
| 63 |
if (cResult != NULL && *cResult == '/') |
| 64 |
cPowerPrefCmd = "gnome-power-preferences"; |
| 65 |
} /// TODO: handle other DE ... |
| 66 |
g_free (cResult); |
| 67 |
} |
| 68 |
if (cPowerPrefCmd) |
| 69 |
{ |
| 70 |
CD_APPLET_ADD_IN_MENU_WITH_STOCK_AND_DATA (D_("Set up power management"), MY_APPLET_SHARE_DATA_DIR"/default-charge.svg", power_launch_cmd, CD_APPLET_MY_MENU, (gpointer)cPowerPrefCmd); |
| 71 |
bAddSeparator = TRUE; |
| 72 |
} |
| 73 |
|
| 74 |
// Power statistics |
| 75 |
static gboolean bPowerStatsChecked = FALSE; |
| 76 |
static const gchar *cPowerStatsCmd = NULL; |
| 77 |
if (!bPowerStatsChecked) |
| 78 |
{ |
| 79 |
bPowerStatsChecked = TRUE; |
| 80 |
gchar *cResult = cairo_dock_launch_command_sync ("which gnome-power-statistics"); |
| 81 |
if (cResult != NULL && *cResult == '/') /// TODO: other DE... |
| 82 |
cPowerStatsCmd = "gnome-power-statistics"; |
| 83 |
g_free (cResult); |
| 84 |
} |
| 85 |
if (cPowerStatsCmd) |
| 86 |
{ |
| 87 |
CD_APPLET_ADD_IN_MENU_WITH_STOCK_AND_DATA (D_("Power statistics"), MY_APPLET_SHARE_DATA_DIR"/default-charge.svg", power_launch_cmd, CD_APPLET_MY_MENU, (gpointer)cPowerStatsCmd); |
| 88 |
bAddSeparator = TRUE; |
| 89 |
} |
| 90 |
|
| 91 |
if (bAddSeparator) |
| 92 |
CD_APPLET_ADD_SEPARATOR_IN_MENU (CD_APPLET_MY_MENU); |
| 93 |
|
| 94 |
CD_APPLET_ON_BUILD_MENU_END |