2
* This file is a part of the Cairo-Dock project
4
* Copyright : (C) see the 'copyright' file.
5
* E-mail : see the 'copyright' file.
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.
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/>.
20
/******************************************************************************
22
This file is a part of the cairo-dock program,
23
released under the terms of the GNU General Public License.
25
Written by RĆ©my Robertson (for any bug report, please mail me to changfu@cairo-dock.org)
27
******************************************************************************/
29
#include <glib/gstdio.h>
31
#include "applet-struct.h"
32
#include "applet-load-icons.h"
33
#include "applet-stack.h"
36
void cd_stack_check_local (CairoDockModuleInstance *myApplet, GKeyFile *pKeyFile) {
38
if (myConfig.cStackDir == NULL) // applet nouvellement instanciee.
40
GString *sDirPath = g_string_new ("");
46
g_string_printf (sDirPath, "%s/stack", g_cCairoDockDataDir);
48
g_string_printf (sDirPath, "%s/stack-%d", g_cCairoDockDataDir, i);
50
g_print ("stack : test de %s\n", sDirPath->str);
51
} while (g_file_test (sDirPath->str, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_EXECUTABLE));
53
myConfig.cStackDir = sDirPath->str;
54
g_string_free (sDirPath, FALSE);
55
g_key_file_set_string (pKeyFile, "Configuration", "stack dir", myConfig.cStackDir);
56
cairo_dock_write_keys_to_file (pKeyFile, myApplet->cConfFilePath);
58
cd_debug ("Stack : reperoire local : %s", myConfig.cStackDir);
60
if (! g_file_test (myConfig.cStackDir, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_EXECUTABLE)) {
61
g_mkdir_with_parents (myConfig.cStackDir, 7*8*8+7*8+5);
62
cd_debug ("Stack local directory created (%s)", myConfig.cStackDir);
66
void cd_stack_clear_stack (CairoDockModuleInstance *myApplet) {
67
gchar *cCommand = g_strdup_printf("rm -rf \"%s\"/*", myConfig.cStackDir);
68
cd_debug("Stack: will use '%s'", cCommand);
69
int r = system (cCommand);
72
CD_APPLET_DELETE_MY_ICONS_LIST;
76
void cd_stack_remove_item (CairoDockModuleInstance *myApplet, Icon *pIcon)
78
gchar *cFilePath = g_strdup_printf ("%s/%s", myConfig.cStackDir, pIcon->acDesktopFileName);
79
cd_message ("removing %s...", cFilePath);
85
cairo_dock_detach_icon_from_dock (pIcon, myIcon->pSubDock, FALSE);
86
cairo_dock_update_dock_size (myIcon->pSubDock);
90
myDesklet->icons = g_list_remove (myDesklet->icons, pIcon);
91
gtk_widget_queue_draw (myDesklet->pWidget);
93
cairo_dock_free_icon (pIcon);
98
Icon *cd_stack_create_item (CairoDockModuleInstance *myApplet, const gchar *cStackDirectory, const gchar *cContent)
104
if (cairo_dock_string_is_adress (cContent) || *cContent == '/')
106
if (strncmp (cContent, "http://", 7) == 0 || strncmp (cContent, "www", 3) == 0)
108
gchar *buf = g_strdup (cContent);
109
gchar *str = strchr (buf, '?');
112
if (str[strlen(str)-1] == '/')
113
str[strlen(str)-1] = '\0';
114
str = strrchr (buf, '/');
115
if (str != NULL && *(str+1) != '\0')
117
cName = g_strdup (str+1);
127
gchar *cFileName = (*cContent == '/' ? g_strdup (cContent) : g_filename_from_uri (cContent, NULL, NULL)); // virer l'extension ?
128
cName = g_path_get_basename (cFileName);
134
cName = cairo_dock_cut_string (cContent, 15); // 15 caracteres par defaut.
136
g_return_val_if_fail (cName != NULL, NULL);
138
GList *pIconsList = (myDock ? (myIcon->pSubDock != NULL ? myIcon->pSubDock->icons : NULL) : myDesklet->icons);
141
for (ic = pIconsList; ic != NULL; ic = ic->next)
144
fOrder = MAX (fOrder, icon->fOrder);
149
GKeyFile *pKeyFile = g_key_file_new();
150
g_key_file_set_string (pKeyFile, "Desktop Entry", "Name", cName);
151
g_key_file_set_integer (pKeyFile, "Desktop Entry", "Date", iDate);
152
g_key_file_set_double (pKeyFile, "Desktop Entry", "Order", fOrder);
153
if (*cContent == '/')
155
gchar *cURI = g_filename_to_uri (cContent, NULL, NULL);
158
g_key_file_free (pKeyFile);
160
cd_warning ("stack : '%s' is not a valid adress", cContent);
163
g_key_file_set_string (pKeyFile, "Desktop Entry", "Content", cURI);
167
g_key_file_set_string (pKeyFile, "Desktop Entry", "Content", cContent);
169
GString *sConfFilePath = g_string_new ("");
174
g_string_printf (sConfFilePath, "%s/%s", cStackDirectory, cName);
176
g_string_printf (sConfFilePath, "%s/%s.%d", cStackDirectory, cName, i);
177
} while (g_file_test (sConfFilePath->str, G_FILE_TEST_EXISTS));
179
cairo_dock_write_keys_to_file (pKeyFile, sConfFilePath->str);
181
Icon *pIcon = cd_stack_build_one_icon (myApplet, pKeyFile);
183
pIcon->acDesktopFileName = g_path_get_basename (sConfFilePath->str);
185
g_key_file_free (pKeyFile);
186
g_string_free (sConfFilePath, TRUE);
190
void cd_stack_create_and_load_item (CairoDockModuleInstance *myApplet, const gchar *cContent)
192
Icon *pIcon = cd_stack_create_item (myApplet, myConfig.cStackDir, cContent);
193
if (pIcon == NULL) // peut arriver si l'icone est filtree.
198
if (myIcon->pSubDock == NULL)
200
GList *pStacksIconList = NULL;
201
pStacksIconList = g_list_prepend (pStacksIconList, pIcon);
202
CD_APPLET_CREATE_MY_SUBDOCK (pStacksIconList, myConfig.cRenderer);
206
cairo_dock_load_one_icon_from_scratch (pIcon, CAIRO_CONTAINER (myIcon->pSubDock));
207
GCompareFunc pCompareFunc = NULL;
208
switch (myConfig.iSortType)
210
case CD_STACK_SORT_BY_DATE :
211
case CD_STACK_SORT_MANUALLY :
212
pCompareFunc = (GCompareFunc) cairo_dock_compare_icons_order;
214
case CD_STACK_SORT_BY_NAME :
215
pCompareFunc = (GCompareFunc) cairo_dock_compare_icons_name;
217
case CD_STACK_SORT_BY_TYPE :
219
pCompareFunc = (GCompareFunc) cairo_dock_compare_icons_extension;
222
cairo_dock_insert_icon_in_dock_full (pIcon, myIcon->pSubDock, CAIRO_DOCK_UPDATE_DOCK_SIZE, CAIRO_DOCK_ANIMATE_ICON, ! CAIRO_DOCK_INSERT_SEPARATOR, pCompareFunc);
227
GList *pStacksIconList = (myDock ? (myIcon->pSubDock != NULL ? myIcon->pSubDock->icons : NULL) : myDesklet->icons);
228
pStacksIconList = cd_stack_insert_icon_in_list (myApplet, pStacksIconList, pIcon);
230
cairo_dock_load_one_icon_from_scratch (pIcon, CAIRO_CONTAINER (myDesklet));
231
myDesklet->icons = pStacksIconList;
232
gtk_widget_queue_draw (myDesklet->pWidget); /// il faudrait recharger le Tree non ?...
236
void cd_stack_set_item_name (const gchar *cDesktopFilePath, const gchar *cName)
238
cairo_dock_update_conf_file (cDesktopFilePath,
239
G_TYPE_STRING, "Desktop Entry", "Name", cName,
243
void cd_stack_set_item_order (const gchar *cDesktopFilePath, double fOrder)
245
cairo_dock_update_conf_file (cDesktopFilePath,
246
G_TYPE_DOUBLE, "Desktop Entry", "Order", fOrder,