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/>.
22
#define __USE_XOPEN_EXTENDED
24
#include <glib/gi18n.h>
26
#include "cairo-dock-modules.h"
27
#include "cairo-dock-log.h"
28
#include "cairo-dock-keyfile-utilities.h"
29
#include "cairo-dock-gui-manager.h"
30
#include "cairo-dock-gui-factory.h"
31
#include "cairo-dock-gui-filter.h"
33
extern gchar *g_cConfFile;
35
static GString *sBuffer = NULL;
36
static inline void _copy_string_to_buffer (const gchar *cSentence)
38
g_string_assign (sBuffer, cSentence);
40
for (str = sBuffer->str; *str != '\0'; str ++)
42
if (*str >= 'A' && *str <= 'Z')
44
*str = *str - 'A' + 'a';
48
#define _search_in_buffer(cKeyWord) g_strstr_len (sBuffer->str, -1, cKeyWord)
49
static gchar *cairo_dock_highlight_key_word (const gchar *cSentence, const gchar *cKeyWord, gboolean bBold)
51
//_copy_string_to_buffer (cSentence);
52
gchar *cModifiedString = NULL;
53
gchar *str = _search_in_buffer (cKeyWord);
56
//g_print ("* trouve %s dans '%s'\n", cKeyWord, sBuffer->str);
57
gchar *cBuffer = g_strdup (cSentence);
58
str = cBuffer + (str - sBuffer->str);
60
cModifiedString = g_strdup_printf ("%s<span color=\"red\">%s%s%s</span>%s", cBuffer, (bBold?"<b>":""), cKeyWord, (bBold?"</b>":""), str + strlen (cKeyWord));
64
return cModifiedString;
67
static gboolean _cairo_dock_search_words_in_frame_title (gchar **pKeyWords, GtkWidget *pCurrentFrame, gboolean bAllWords, gboolean bHighLightText, gboolean bHideOther)
69
//\______________ On recupere son titre.
70
GtkWidget *pFrameLabel = NULL;
71
GtkWidget *pLabelContainer = (GTK_IS_FRAME (pCurrentFrame) ?
72
gtk_frame_get_label_widget (GTK_FRAME (pCurrentFrame)) :
73
gtk_expander_get_label_widget (GTK_EXPANDER (pCurrentFrame)));
74
//g_print ("pLabelContainer : %x\n", pLabelContainer);
75
if (GTK_IS_LABEL (pLabelContainer))
77
pFrameLabel = pLabelContainer;
79
else if (pLabelContainer != NULL)
81
GList *pChildList = gtk_container_get_children (GTK_CONTAINER (pLabelContainer));
82
if (pChildList != NULL && pChildList->next != NULL)
83
pFrameLabel = pChildList->next->data;
86
//\______________ On cherche les mots-cles dedans.
87
gchar *cModifiedText = NULL, *str = NULL, *cKeyWord;
88
gboolean bFoundInFrameTitle = FALSE;
89
if (pFrameLabel != NULL)
91
const gchar *cFrameTitle = gtk_label_get_text (GTK_LABEL (pFrameLabel));
93
for (i = 0; pKeyWords[i] != NULL; i ++)
95
cKeyWord = pKeyWords[i];
96
_copy_string_to_buffer (cFrameTitle);
98
cModifiedText = cairo_dock_highlight_key_word (cFrameTitle, cKeyWord, TRUE);
100
str = _search_in_buffer (cKeyWord);
101
if (cModifiedText != NULL || str != NULL) // on a trouve ce mot.
103
//g_print (" on a trouve %s dans le titre\n", cKeyWord);
104
bFoundInFrameTitle = TRUE;
105
if (cModifiedText != NULL)
107
gtk_label_set_markup (GTK_LABEL (pFrameLabel), cModifiedText);
108
cFrameTitle = gtk_label_get_label (GTK_LABEL (pFrameLabel)); // Pango inclus.
109
g_free (cModifiedText);
110
cModifiedText = NULL;
119
bFoundInFrameTitle = FALSE;
123
if (! bFoundInFrameTitle) // on remet le texte par defaut.
125
cModifiedText = g_strdup_printf ("<b>%s</b>", cFrameTitle);
126
gtk_label_set_markup (GTK_LABEL (pFrameLabel), cModifiedText);
127
g_free (cModifiedText);
128
cModifiedText = NULL;
131
return bFoundInFrameTitle;
135
void cairo_dock_apply_filter_on_group_widget (gchar **pKeyWords, gboolean bAllWords, gboolean bSearchInToolTip, gboolean bHighLightText, gboolean bHideOther, GSList *pWidgetList)
137
//g_print ("%s ()\n", __func__);
139
sBuffer = g_string_new ("");
140
gpointer *pGroupKeyWidget;
141
GList *pSubWidgetList;
142
GtkWidget *pLabel, *pKeyBox, *pVBox, *pFrame, *pCurrentFrame = NULL, *pExpander;
143
const gchar *cDescription;
144
gchar *cToolTip = NULL;
145
gchar *cModifiedText=NULL, *str=NULL;
146
gboolean bFound, bFrameVisible = !bHideOther;
150
for (w = pWidgetList; w != NULL; w = w->next)
153
pGroupKeyWidget = w->data;
154
//g_print ("widget : %s - %s\n", pGroupKeyWidget[0], pGroupKeyWidget[1]);
155
pSubWidgetList = pGroupKeyWidget[2];
156
if (pSubWidgetList == NULL)
158
pLabel = pGroupKeyWidget[4];
161
pKeyBox = pGroupKeyWidget[5];
164
pVBox = gtk_widget_get_parent (pKeyBox);
165
pFrame = gtk_widget_get_parent (pVBox);
167
//\______________ On cache une frame vide, ou au contraire on montre son contenu si elle contient les mots-cles.
168
if (pFrame != pCurrentFrame) // on a change de frame.
172
gboolean bFoundInFrameTitle = _cairo_dock_search_words_in_frame_title (pKeyWords, pCurrentFrame, bAllWords, bHighLightText, bHideOther);
173
if (! bFrameVisible && bHideOther)
175
if (! bFoundInFrameTitle)
176
gtk_widget_hide (pCurrentFrame);
178
gtk_widget_show_all (pCurrentFrame); // montre tous les widgets du groupe.
181
gtk_widget_show (pCurrentFrame);
184
if (GTK_IS_FRAME (pFrame)) // devient la frame courante.
186
pExpander = gtk_widget_get_parent (pFrame);
187
if (GTK_IS_EXPANDER (pExpander))
188
pFrame = pExpander; // c'est l'expander qui a le texte, c'est donc ca qu'on veut cacher.
189
pCurrentFrame = pFrame;
190
bFrameVisible = FALSE;
194
pCurrentFrame = NULL;
196
//g_print ("pCurrentFrame <- %x\n", pCurrentFrame);
199
cDescription = gtk_label_get_text (GTK_LABEL (pLabel)); // sans les markup Pango.
200
if (bSearchInToolTip)
201
cToolTip = gtk_widget_get_tooltip_text (pKeyBox);
202
//g_print ("cDescription : %s (%s)\n", cDescription, cToolTip);
205
for (i = 0; pKeyWords[i] != NULL; i ++)
207
cKeyWord = pKeyWords[i];
208
_copy_string_to_buffer (cDescription);
210
cModifiedText = cairo_dock_highlight_key_word (cDescription, cKeyWord, FALSE);
212
str = _search_in_buffer (cKeyWord);
213
if (cModifiedText == NULL && str == NULL)
215
if (cToolTip != NULL)
217
_copy_string_to_buffer (cToolTip);
218
str = _search_in_buffer (cKeyWord);
222
if (cModifiedText != NULL || str != NULL)
224
//g_print (" on a trouve %s\n", cKeyWord);
226
if (cModifiedText != NULL)
228
gtk_label_set_markup (GTK_LABEL (pLabel), cModifiedText);
229
cDescription = gtk_label_get_label (GTK_LABEL (pLabel)); // Pango inclus.
230
g_free (cModifiedText);
231
cModifiedText = NULL;
235
gtk_label_set_text (GTK_LABEL (pLabel), cDescription);
249
//g_print ("on montre ce widget\n");
250
gtk_widget_show (pKeyBox);
251
if (pCurrentFrame != NULL)
252
bFrameVisible = TRUE;
256
//g_print ("on cache ce widget\n");
257
gtk_widget_hide (pKeyBox);
260
gtk_widget_show (pKeyBox);
263
if (pCurrentFrame) // la derniere frame.
265
gboolean bFoundInFrameTitle = _cairo_dock_search_words_in_frame_title (pKeyWords, pCurrentFrame, bAllWords, bHighLightText, bHideOther);
266
if (! bFrameVisible && bHideOther)
268
if (! bFoundInFrameTitle)
269
gtk_widget_hide (pCurrentFrame);
271
gtk_widget_show_all (pCurrentFrame); // montre tous les widgets du groupe.
274
gtk_widget_show (pCurrentFrame);
278
void cairo_dock_apply_filter_on_group_list (gchar **pKeyWords, gboolean bAllWords, gboolean bSearchInToolTip, gboolean bHighLightText, gboolean bHideOther, GList *pGroupDescriptionList)
280
//g_print ("%s ()\n", __func__);
282
sBuffer = g_string_new ("");
283
CairoDockGroupDescription *pGroupDescription, *pInternalGroupDescription;
284
gchar *cKeyWord, *str = NULL, *cModifiedText = NULL, *cDescription, *cToolTip = NULL;
285
gboolean bFound, bFrameVisible;
286
GtkWidget *pGroupBox, *pLabel, *pCategoryFrame, *pCurrentCategoryFrame = NULL;
288
GKeyFile *pMainKeyFile = cairo_dock_open_key_file (g_cConfFile);
292
const gchar *cGettextDomain;
293
for (gd = pGroupDescriptionList; gd != NULL; gd = gd->next)
295
pGroupDescription = gd->data;
296
pGroupDescription->bMatchFilter = FALSE;
298
for (gd = pGroupDescriptionList; gd != NULL; gd = gd->next)
300
//g_print ("pGroupDescription:%x\n", gd->data);
301
//\_______________ On recupere le group description.
302
pGroupDescription = gd->data;
304
if (pGroupDescription->cInternalModule)
306
g_print ("%s : bouton emprunte a %s\n", pGroupDescription->cGroupName, pGroupDescription->cInternalModule);
307
pInternalGroupDescription = cairo_dock_find_module_description (pGroupDescription->cInternalModule);
308
if (pInternalGroupDescription != NULL)
309
pGroupBox = gtk_widget_get_parent (pInternalGroupDescription->pActivateButton);
312
pLabel = pInternalGroupDescription->pLabel;
313
g_print ("ok, found pGroupBox\n");
317
pGroupBox = gtk_widget_get_parent (pGroupDescription->pActivateButton);
318
pLabel = pGroupDescription->pLabel;
320
//g_print (" %x\n", pGroupDescription->pActivateButton);
321
pCategoryFrame = gtk_widget_get_parent (pGroupBox);
322
cGettextDomain = pGroupDescription->cGettextDomain;
325
cDescription = dgettext (cGettextDomain, pGroupDescription->cGroupName);
326
if (bSearchInToolTip)
327
cToolTip = dgettext (cGettextDomain, pGroupDescription->cDescription);
328
//g_print ("cDescription : %s (%s)(%x,%x)\n", cDescription, cToolTip, cModifiedText, str);
330
//\_______________ On change de frame.
331
if (pCategoryFrame != pCurrentCategoryFrame) // on a change de frame.
333
if (pCurrentCategoryFrame)
335
if (! bFrameVisible && bHideOther)
337
//g_print (" on cache cette categorie\n");
338
gtk_widget_hide (pCurrentCategoryFrame);
341
gtk_widget_show (pCurrentCategoryFrame);
343
pCurrentCategoryFrame = pCategoryFrame;
344
//g_print (" pCurrentCategoryFrame <- %x\n", pCurrentCategoryFrame);
347
//\_______________ On cherche chaque mot dans la description du module.
348
for (i = 0; pKeyWords[i] != NULL; i ++)
350
cKeyWord = pKeyWords[i];
351
_copy_string_to_buffer (cDescription);
353
cModifiedText = cairo_dock_highlight_key_word (cDescription, cKeyWord, TRUE);
355
str = _search_in_buffer (cKeyWord);
356
if (cModifiedText == NULL && str == NULL)
358
if (cToolTip != NULL)
360
_copy_string_to_buffer (cToolTip);
361
str = _search_in_buffer (cKeyWord);
365
if (cModifiedText != NULL || str != NULL)
367
//g_print (">>> on a trouve direct %s\n", cKeyWord);
369
if (cModifiedText != NULL)
371
gtk_label_set_use_markup (GTK_LABEL (pLabel), TRUE);
372
gtk_label_set_markup (GTK_LABEL (pLabel), cModifiedText);
373
g_free (cModifiedText);
374
cModifiedText = NULL;
378
gtk_label_set_text (GTK_LABEL (pLabel), cDescription);
391
//\_______________ On cherche chaque mot a l'interieur du module.
392
if (! bFound && pGroupDescription->cOriginalConfFilePath != NULL)
394
//\_______________ On recupere les groupes du module.
395
//g_print ("* on cherche dans le fichier de conf %s ...\n", pGroupDescription->cOriginalConfFilePath);
396
gchar **pGroupList = NULL;
397
CairoDockModule *pModule = cairo_dock_find_module_from_name (pGroupDescription->cGroupName);
400
pKeyFile = cairo_dock_open_key_file (pModule->cConfFilePath);
401
if (pKeyFile != NULL)
404
pGroupList = g_key_file_get_groups (pKeyFile, &length);
407
else // groupe interne, le fichier de conf n'est ouvert qu'une seule fois.
409
pKeyFile = pMainKeyFile;
410
pGroupList = g_new0 (gchar *, 2);
411
pGroupList[0] = g_strdup (pGroupDescription->cGroupName);
414
//\_______________ Pour chaque groupe on parcourt toutes les cles.
415
if (pGroupList != NULL)
418
for (iNbWords = 0; pKeyWords[iNbWords] != NULL; iNbWords ++);
419
gboolean *bFoundWords = g_new0 (gboolean , iNbWords);
421
gchar *cUsefulComment;
424
gchar **pAuthorizedValuesList;
428
gchar *cGroupName, *cKeyName, *cKeyComment;
430
for (k = 0; pGroupList[k] != NULL; k ++)
432
cGroupName = pGroupList[k];
433
pKeyList = g_key_file_get_keys (pKeyFile, cGroupName, NULL, NULL);
434
for (j = 0; pKeyList[j] != NULL; j ++)
436
cKeyName = pKeyList[j];
437
//\_______________ On recupere la description + bulle d'aide de la cle.
438
cKeyComment = g_key_file_get_comment (pKeyFile, cGroupName, cKeyName, NULL);
439
cUsefulComment = cairo_dock_parse_key_comment (cKeyComment, &iElementType, &iNbElements, &pAuthorizedValuesList, &bIsAligned, &cTipString);
440
if (cUsefulComment == NULL)
442
g_free (cKeyComment);
446
cUsefulComment = dgettext (cGettextDomain, cUsefulComment);
447
if (cTipString != NULL)
449
if (bSearchInToolTip)
450
cTipString = dgettext (cGettextDomain, cTipString);
454
//\_______________ On y cherche les mots-cles.
455
for (i = 0; pKeyWords[i] != NULL; i ++)
459
cKeyWord = pKeyWords[i];
463
_copy_string_to_buffer (cUsefulComment);
464
str = _search_in_buffer (cKeyWord);
466
if (! str && cTipString)
468
_copy_string_to_buffer (cTipString);
469
str = _search_in_buffer (cKeyWord);
471
if (! str && pAuthorizedValuesList)
474
for (l = 0; pAuthorizedValuesList[l] != NULL; l ++)
476
_copy_string_to_buffer (dgettext (cGettextDomain, pAuthorizedValuesList[l]));
477
str = _search_in_buffer (cKeyWord);
485
//g_print (">>>on a trouve %s\n", pKeyWords[i]);
492
bFoundWords[i] = TRUE;
496
g_free (cKeyComment);
497
if (! bAllWords && bFound)
499
} // fin de parcours du groupe.
500
g_strfreev (pKeyList);
501
if (! bAllWords && bFound)
503
} // fin de parcours des groupes.
504
g_strfreev (pGroupList);
506
if (bAllWords && bFound)
508
for (i = 0; i < iNbWords; i ++)
510
if (! bFoundWords[i])
512
//g_print ("par contre il manque %s, dommage\n", pKeyWords[i]);
518
g_free (bFoundWords);
519
} // fin du cas ou on avait des groupes a etudier.
520
if (pKeyFile != pMainKeyFile)
521
g_key_file_free (pKeyFile);
522
//g_print ("bFound : %d\n", bFound);
524
if (bHighLightText && bFound) // on passe le label du groupe en bleu + gras.
526
cModifiedText = g_strdup_printf ("<b><span color=\"blue\">%s</span></b>", cDescription);
527
//g_print ("cModifiedText : %s\n", cModifiedText);
528
gtk_label_set_markup (GTK_LABEL (pLabel), dgettext (cGettextDomain, cModifiedText));
529
g_free (cModifiedText);
530
cModifiedText = NULL;
532
} // fin du cas ou on devait chercher dans le groupe.
534
if (pGroupDescription->cInternalModule)
536
pInternalGroupDescription = cairo_dock_find_module_description (pGroupDescription->cInternalModule);
537
if (pInternalGroupDescription != NULL)
539
pInternalGroupDescription->bMatchFilter |= bFound;
540
bFound = pInternalGroupDescription->bMatchFilter;
545
pGroupDescription->bMatchFilter |= bFound;
546
bFound = pGroupDescription->bMatchFilter;
550
//g_print ("on montre ce groupe\n");
551
gtk_widget_show (pGroupBox);
552
if (pCurrentCategoryFrame != NULL)
553
bFrameVisible = TRUE;
557
//g_print ("on cache ce groupe (%s)\n", pGroupDescription->cGroupName);
558
gtk_widget_hide (pGroupBox);
561
gtk_widget_show (pGroupBox);
562
if (! bHighLightText || ! bFound)
564
gtk_label_set_markup (GTK_LABEL (pLabel), dgettext (cGettextDomain, cDescription));
567
g_key_file_free (pMainKeyFile);