90
static void _get_html_page (CDHtmlLink *pHtmlLink)
92
CairoDockModuleInstance *myApplet = pHtmlLink->pApplet;
93
// get the HTML page content
94
gchar *cPageContent = cairo_dock_get_url_data (pHtmlLink->cURL, NULL);
95
if (cPageContent == NULL)
97
cd_warning ("Stack: couldn't get the html page '%s'\n -> can't get the title and favicon", pHtmlLink->cURL);
98
return; // we could still draw the emblem in case it's already local, but not the title; so it wouldn't be really better.
102
gchar *str = strstr (cPageContent, "<title>");
104
str = strstr (cPageContent, "<TITLE>");
108
gchar *str2 = strstr (str, "</title>");
110
str2 = strstr (str, "</TITLE>");
113
pHtmlLink->cTitle = g_strndup (str, str2 - str);
114
// remove carriage returns.
115
gchar *str = pHtmlLink->cTitle;
116
while (str = strchr (str, '\n'))
118
*str = ' '; // replace the carriage returns with a space.
119
str ++; // begining of the new line.
123
if (str2 != str) // remove spaces at the begining of the new line.
127
cd_debug ("cTitle: '%s'", pHtmlLink->cTitle);
130
// get the domain name.
131
gchar *cDomainName = NULL;
132
str = strstr (pHtmlLink->cURL, "://");
136
gchar *str2 = strchr (str, '/');
138
cDomainName = g_strndup (str, str2 - str);
140
cd_debug ("cDomainName: %s", cDomainName);
142
// get the favicon or use the existing one.
143
gchar *cLocalFaviconPath = NULL;
144
if (cDomainName != NULL)
146
// check the favicons folder.
147
gchar *cFaviconDir = g_strdup_printf ("%s/favicons", g_cCairoDockDataDir);
148
if (! g_file_test (cFaviconDir, G_FILE_TEST_EXISTS))
150
g_mkdir (cFaviconDir, 7*8*8+7*8+5);
152
cLocalFaviconPath = g_strdup_printf ("%s/%s", cFaviconDir, cDomainName);
153
g_free (cFaviconDir);
155
// if favicon is not already on hard-disk, download it.
156
if (! g_file_test (cLocalFaviconPath, G_FILE_TEST_EXISTS))
158
gboolean bGotFavIcon = FALSE;
160
// try to get the favicon path specified in the html page.
161
gchar *cRelPath = NULL;
162
str = strstr (cPageContent, "<link rel=\"shortcut icon\"");
164
str = strstr (cPageContent, "<link rel=\"SHORTCUT ICON\"");
168
// get its remote relative path.
169
gchar *str2 = strstr (str, "href=\"");
173
gchar *str3 = strchr (str2, '"');
176
cRelPath = g_strndup (str2, str3 - str2);
177
cd_debug ("favicon: '%s'", cRelPath);
181
else // no standard favicon, get the default one in the remote root dir.
183
cd_debug ("no favicon defined, looking for a default favicon.ico...");
184
cRelPath = g_strdup ("favicon.ico");
188
if (cRelPath != NULL)
190
gchar *cFaviconURL = NULL;
191
if (*cRelPath == '/' && *(cRelPath+1) == '/')
193
cFaviconURL = g_strdup_printf ("http:%s", cRelPath);
195
else if (strstr (cRelPath, "://") != NULL)
197
cFaviconURL = cRelPath;
202
cFaviconURL = g_strdup_printf ("%s/%s", cDomainName, cRelPath);
204
cd_debug ("cFaviconURL: %s", cFaviconURL);
206
gchar *cTmpFavIconPath = cairo_dock_download_file (NULL, NULL, cFaviconURL, NULL, NULL);
207
if (cTmpFavIconPath != NULL)
209
gchar *cCommand = g_strdup_printf ("mv \"%s\" \"%s\"", cTmpFavIconPath, cLocalFaviconPath);
210
cd_debug ("%s", cCommand);
211
int r = system (cCommand);
213
g_free (cTmpFavIconPath);
216
g_free (cFaviconURL);
220
if (! bGotFavIcon) // couldn't get the favicon -> no favicon defined.
222
g_free (cLocalFaviconPath);
223
cLocalFaviconPath = NULL;
227
pHtmlLink->cFaviconPath = cLocalFaviconPath;
230
static gboolean _update_html_link (CDHtmlLink *pHtmlLink)
232
CairoDockModuleInstance *myApplet = pHtmlLink->pApplet;
235
// store in the conf file.
236
cairo_dock_update_conf_file (pHtmlLink->cConfFilePath,
237
G_TYPE_STRING, "Desktop Entry", "Favicon", pHtmlLink->cFaviconPath,
238
G_TYPE_STRING, "Desktop Entry", "Name", pHtmlLink->cTitle,
242
gchar *cDesktopFileName = g_path_get_basename (pHtmlLink->cConfFilePath);
243
if (cDesktopFileName)
246
GList *pIconsList = CD_APPLET_MY_ICONS_LIST;
248
for (ic = pIconsList; ic != NULL; ic = ic->next)
251
if (pIcon->cDesktopFileName && strcmp (pIcon->cDesktopFileName, cDesktopFileName) == 0)
253
CairoContainer *pContainer = CD_APPLET_MY_ICONS_LIST_CONTAINER;
255
cairo_dock_set_icon_name (pHtmlLink->cTitle, pIcon, pContainer);
257
cd_debug ("draw emblem on %s", pIcon->cName);
258
CairoEmblem *pEmblem = cairo_dock_make_emblem (pHtmlLink->cFaviconPath, pIcon, pContainer);
259
cairo_dock_set_emblem_position (pEmblem, CAIRO_DOCK_EMBLEM_LOWER_RIGHT);
260
cairo_dock_draw_emblem_on_icon (pEmblem, pIcon, pContainer);
261
cairo_dock_free_emblem (pEmblem);
262
cairo_dock_redraw_icon (pIcon, pContainer);
266
g_free (cDesktopFileName);
269
cairo_dock_discard_task (pHtmlLink->pTask);
270
myData.pGetPageTaskList = g_list_remove (myData.pGetPageTaskList, pHtmlLink->pTask);
272
CD_APPLET_LEAVE (TRUE);
275
static void _free_html_link (CDHtmlLink *pHtmlLink)
277
g_free (pHtmlLink->cURL);
278
g_free (pHtmlLink->cTitle);
279
g_free (pHtmlLink->cFaviconPath);
280
g_free (pHtmlLink->cConfFilePath);
84
284
static void _set_icon_order (Icon *pIcon, CairoDockModuleInstance *myApplet, GCompareFunc comp)
86
286
GList *pIconsList = CD_APPLET_MY_ICONS_LIST;
109
309
double fOrder = 0;
311
CDHtmlLink *pHtmlLink = NULL;
313
cd_debug ("Stack: got '%s'", cContent);
112
314
//\_______________________ On lui trouve un petit nom.
113
315
if (cairo_dock_string_is_adress (cContent) || *cContent == '/')
115
317
if (strncmp (cContent, "http://", 7) == 0 || strncmp (cContent, "www", 3) == 0 || strncmp (cContent, "https://", 8) == 0)
319
cd_debug (" -> html page");
320
pHtmlLink = g_new0 (CDHtmlLink, 1);
321
pHtmlLink->pApplet = myApplet;
322
pHtmlLink->cURL = g_strdup (cContent);
323
pHtmlLink->pTask = cairo_dock_new_task_full (0,
324
(CairoDockGetDataAsyncFunc)_get_html_page,
325
(CairoDockUpdateSyncFunc)_update_html_link,
326
(GFreeFunc)_free_html_link,
328
myData.pGetPageTaskList = g_list_prepend (myData.pGetPageTaskList, pHtmlLink->pTask);
329
cairo_dock_launch_task (pHtmlLink->pTask);
117
331
gchar *buf = g_strdup (cContent);
118
332
gchar *str = strchr (buf, '?');