| 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 <string.h> |
| 22 |
#include <time.h> |
| 23 |
|
| 24 |
#include <glib/gstdio.h> |
| 25 |
|
| 26 |
#include "applet-struct.h" |
| 27 |
#include "applet-notifications.h" |
| 28 |
#include "applet-session.h" |
| 29 |
#include "applet-listing.h" |
| 30 |
#include "applet-search.h" |
| 31 |
#include "applet-backend-command.h" |
| 32 |
|
| 33 |
// sub-listing |
| 34 |
// fill entry |
| 35 |
// actions |
| 36 |
static void _cd_do_execute_command (CDEntry *pEntry); |
| 37 |
|
| 38 |
////////// |
| 39 |
// INIT // |
| 40 |
////////// |
| 41 |
|
| 42 |
|
| 43 |
//////////////// |
| 44 |
// FILL ENTRY // |
| 45 |
//////////////// |
| 46 |
|
| 47 |
|
| 48 |
///////////// |
| 49 |
// ACTIONS // |
| 50 |
///////////// |
| 51 |
|
| 52 |
static void _cd_do_execute_command (CDEntry *pEntry) |
| 53 |
{ |
| 54 |
gchar *cCommand = g_strdup_printf ("%s/calc.sh '%s'", MY_APPLET_SHARE_DATA_DIR, myData.sCurrentText->str); |
| 55 |
gchar *cResult = cairo_dock_launch_command_sync (cCommand); |
| 56 |
g_free (cCommand); |
| 57 |
if (cResult != NULL && strcmp (cResult, "0") != 0) |
| 58 |
{ |
| 59 |
cd_debug (" resultat du calcul : '%s'", cResult); |
| 60 |
GtkClipboard *pClipBoard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD); |
| 61 |
gtk_clipboard_set_text (pClipBoard, cResult, -1); |
| 62 |
Icon *pIcon = gldi_icons_get_any_without_dialog (); |
| 63 |
gldi_dialog_show_temporary_with_icon_printf (D_("The value %s has been copied into the clipboard."), |
| 64 |
pIcon, |
| 65 |
CAIRO_CONTAINER (g_pMainDock), |
| 66 |
3000, |
| 67 |
MY_APPLET_SHARE_DATA_DIR"/"MY_APPLET_ICON_FILE, |
| 68 |
cResult); |
| 69 |
} |
| 70 |
else // le calcul n'a rien donne, on execute sans chercher. |
| 71 |
{ |
| 72 |
cd_debug (" pas un calcul => on execute '%s'", myData.sCurrentText->str); |
| 73 |
cairo_dock_launch_command (myData.sCurrentText->str); |
| 74 |
} |
| 75 |
g_free (cResult); |
| 76 |
} |
| 77 |
|
| 78 |
|
| 79 |
///////////////// |
| 80 |
// SUB-LISTING // |
| 81 |
///////////////// |
| 82 |
|
| 83 |
|
| 84 |
//////////// |
| 85 |
// SEARCH // |
| 86 |
//////////// |
| 87 |
|
| 88 |
static GList * search (const gchar *cText, gint iFilter, gboolean bSearchAll, int *iNbEntries) |
| 89 |
{ |
| 90 |
cd_debug ("%s (%s)", __func__, cText); |
| 91 |
GList *pEntries = NULL; |
| 92 |
CDEntry *pEntry; |
| 93 |
|
| 94 |
pEntry = g_new0 (CDEntry, 1); |
| 95 |
pEntry->cName = g_strdup (D_("Execute")); |
| 96 |
pEntry->cIconName = g_strdup (GLDI_ICON_NAME_EXECUTE); |
| 97 |
pEntry->bMainEntry = TRUE; |
| 98 |
pEntry->execute = _cd_do_execute_command; |
| 99 |
pEntry->fill = cd_do_fill_default_entry; |
| 100 |
pEntries = g_list_prepend (pEntries, pEntry); |
| 101 |
|
| 102 |
*iNbEntries = 1; |
| 103 |
return pEntries; |
| 104 |
} |
| 105 |
////////////// |
| 106 |
// REGISTER // |
| 107 |
////////////// |
| 108 |
|
| 109 |
void cd_do_register_command_backend (void) |
| 110 |
{ |
| 111 |
CDBackend *pBackend = g_new0 (CDBackend, 1); |
| 112 |
pBackend->cName = "Command"; |
| 113 |
pBackend->bIsThreaded = FALSE; |
| 114 |
pBackend->bStaticResults = TRUE; |
| 115 |
pBackend->init = (CDBackendInitFunc) NULL; |
| 116 |
pBackend->search = (CDBackendSearchFunc) search; |
| 117 |
myData.pBackends = g_list_prepend (myData.pBackends, pBackend); |
| 118 |
} |