| 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 |
|
| 32 |
gboolean cd_do_fill_default_entry (CDEntry *pEntry) |
| 33 |
{ |
| 34 |
if (pEntry->cIconName && pEntry->pIconSurface == NULL) |
| 35 |
{ |
| 36 |
pEntry->pIconSurface = cairo_dock_create_surface_from_icon (pEntry->cIconName, |
| 37 |
myDialogsParam.dialogTextDescription.iSize + 2, |
| 38 |
myDialogsParam.dialogTextDescription.iSize + 2); |
| 39 |
return TRUE; |
| 40 |
} |
| 41 |
return FALSE; |
| 42 |
} |
| 43 |
|
| 44 |
static inline void _discard_results (CDBackend *pBackend) |
| 45 |
{ |
| 46 |
g_list_foreach (pBackend->pSearchResults, (GFunc) cd_do_free_entry, NULL); |
| 47 |
g_list_free (pBackend->pSearchResults); |
| 48 |
pBackend->pSearchResults = NULL; |
| 49 |
pBackend->iNbSearchResults = 0; |
| 50 |
} |
| 51 |
|
| 52 |
static void _launch_async_search (CDBackend *pBackend) |
| 53 |
{ |
| 54 |
pBackend->pSearchResults = pBackend->search (pBackend->cCurrentLocateText, |
| 55 |
pBackend->iLocateFilter, |
| 56 |
FALSE, |
| 57 |
&pBackend->iNbSearchResults); |
| 58 |
cd_debug (" -> %d resultats asynchrones en plus", pBackend->iNbSearchResults); |
| 59 |
if (pBackend->pSearchResults != NULL) |
| 60 |
{ |
| 61 |
CDEntry *pMainEntry = pBackend->pSearchResults->data; |
| 62 |
if (pMainEntry->bMainEntry) |
| 63 |
pMainEntry->pBackend = pBackend; |
| 64 |
} |
| 65 |
} |
| 66 |
|
| 67 |
static gboolean _update_entries (CDBackend *pBackend) |
| 68 |
{ |
| 69 |
cd_debug ("%s ()", __func__); |
| 70 |
pBackend->bFoundNothing = FALSE; |
| 71 |
pBackend->bTooManyResults = FALSE; |
| 72 |
|
| 73 |
if (! cd_do_session_is_running () || myData.pListingHistory != NULL) // on a quitte la session ou on a choisi une entree en cours de route. |
| 74 |
{ |
| 75 |
cd_debug (" on a quitte la session ou on a choisi une entree en cours de route\n"); |
| 76 |
_discard_results (pBackend); |
| 77 |
pBackend->cCurrentLocateText = NULL; |
| 78 |
pBackend->iLocateFilter = 0; |
| 79 |
return FALSE; |
| 80 |
} |
| 81 |
|
| 82 |
if (pBackend->iLocateFilter != myData.iCurrentFilter || |
| 83 |
cairo_dock_strings_differ (pBackend->cCurrentLocateText, myData.sCurrentText->str)) // la situation a change entre le lancement de la tache et la mise a jour, on va relancer la recherche immediatement. |
| 84 |
{ |
| 85 |
if ((pBackend->iLocateFilter & myData.iCurrentFilter) == pBackend->iLocateFilter && |
| 86 |
pBackend->cCurrentLocateText && |
| 87 |
strncmp (pBackend->cCurrentLocateText, myData.sCurrentText->str, strlen (pBackend->cCurrentLocateText)) == 0) // c'est une sous-recherche. |
| 88 |
{ |
| 89 |
cd_debug (" c'est une sous-recherche\n"); |
| 90 |
if (pBackend->pSearchResults == NULL) // on n'a rien trouve, on vide le listing et on ne la relance pas. |
| 91 |
{ |
| 92 |
cd_debug (" aucun resultat, on enleve les precedents resultats et on ne la relance pas\n"); |
| 93 |
pBackend->bFoundNothing = TRUE; |
| 94 |
cd_do_remove_entries_from_listing (pBackend); |
| 95 |
return FALSE; |
| 96 |
} |
| 97 |
else // la recherche a ete fructueuse, on regarde si on peut la filtrer ou s'il faut la relancer. |
| 98 |
{ |
| 99 |
if (pBackend->iNbSearchResults < 3+1/*myConfig.iNbResultMax*/) // on a des resultats mais pas trop, on les charge et on leur applique le filtre. |
| 100 |
{ |
| 101 |
cd_do_remove_entries_from_listing (pBackend); |
| 102 |
cd_do_filter_entries (pBackend->pSearchResults, pBackend->iNbSearchResults); |
| 103 |
cd_do_append_entries_to_listing (pBackend->pSearchResults, pBackend->iNbSearchResults); |
| 104 |
pBackend->bTooManyResults = TRUE; |
| 105 |
pBackend->pLastShownResults = pBackend->pSearchResults; |
| 106 |
pBackend->iNbLastShownResults = pBackend->iNbSearchResults; |
| 107 |
return FALSE; |
| 108 |
} |
| 109 |
else // on a trop de resultats, on bache tout et on relance. |
| 110 |
{ |
| 111 |
_discard_results (pBackend); |
| 112 |
} |
| 113 |
} |
| 114 |
} |
| 115 |
else // c'est une nouvelle recherche, on bache tout et on relance. |
| 116 |
{ |
| 117 |
cd_debug (" c'est une nouvelle recherche, on bache tout et on relance\n"); |
| 118 |
_discard_results (pBackend); |
| 119 |
|
| 120 |
if (myData.pMatchingIcons != NULL || myData.sCurrentText->len == 0) // avec le texte courant on a des applis, on quitte. |
| 121 |
{ |
| 122 |
cd_do_hide_listing (); |
| 123 |
g_free (pBackend->cCurrentLocateText); |
| 124 |
pBackend->cCurrentLocateText = NULL; |
| 125 |
pBackend->iLocateFilter = 0; |
| 126 |
return FALSE; |
| 127 |
} |
| 128 |
} |
| 129 |
|
| 130 |
// on relance. |
| 131 |
cd_debug (" on relance\n"); |
| 132 |
cd_do_set_status (D_("Searching ...")); |
| 133 |
pBackend->iLocateFilter = myData.iCurrentFilter; |
| 134 |
g_free (pBackend->cCurrentLocateText); |
| 135 |
pBackend->cCurrentLocateText = g_strdup (myData.sCurrentText->str); |
| 136 |
gldi_task_change_frequency_and_relaunch (pBackend->pTask, 0); |
| 137 |
} |
| 138 |
else // la situation n'a pas change, on montre les resultats. |
| 139 |
{ |
| 140 |
cd_do_remove_entries_from_listing (pBackend); |
| 141 |
cd_do_append_entries_to_listing (pBackend->pSearchResults, pBackend->iNbSearchResults); |
| 142 |
///pBackend->bTooManyResults = (pBackend->iNbSearchResults >= myConfig.iNbResultMax); |
| 143 |
pBackend->bTooManyResults = TRUE; |
| 144 |
pBackend->pLastShownResults = pBackend->pSearchResults; |
| 145 |
pBackend->iNbLastShownResults = pBackend->iNbSearchResults; |
| 146 |
pBackend->pSearchResults = NULL; |
| 147 |
pBackend->iNbSearchResults = 0; |
| 148 |
} |
| 149 |
return FALSE; |
| 150 |
} |
| 151 |
void cd_do_launch_backend (CDBackend *pBackend) |
| 152 |
{ |
| 153 |
cd_debug ("%s (%s)", __func__, pBackend->cName); |
| 154 |
// On initialise le backend si c'est son 1er appel. |
| 155 |
if (pBackend->iState == 0) |
| 156 |
{ |
| 157 |
if (pBackend->init) |
| 158 |
pBackend->iState = (pBackend->init () ? 1 : -1); |
| 159 |
else |
| 160 |
pBackend->iState = 1; |
| 161 |
|
| 162 |
if (pBackend->bIsThreaded && pBackend->search != NULL) |
| 163 |
{ |
| 164 |
pBackend->pTask = gldi_task_new (0, |
| 165 |
(GldiGetDataAsyncFunc) _launch_async_search, |
| 166 |
(GldiUpdateSyncFunc) _update_entries, |
| 167 |
pBackend); |
| 168 |
} |
| 169 |
} |
| 170 |
|
| 171 |
// On le lance. |
| 172 |
if (pBackend->pTask != NULL) // asynchrone |
| 173 |
{ |
| 174 |
if (gldi_task_is_running (pBackend->pTask)) // on la laisse se finir, et lorsqu'elle aura fini, on la relancera avec le nouveau texte/filtre. |
| 175 |
{ |
| 176 |
cd_debug (" on laisse la tache courante se finir\n"); |
| 177 |
return ; |
| 178 |
} |
| 179 |
|
| 180 |
if (myData.pListingHistory != NULL || |
| 181 |
((pBackend->iLocateFilter & myData.iCurrentFilter) == pBackend->iLocateFilter |
| 182 |
&& pBackend->cCurrentLocateText != NULL |
| 183 |
&& strncmp (pBackend->cCurrentLocateText, |
| 184 |
myData.sCurrentText->str, |
| 185 |
strlen (pBackend->cCurrentLocateText)) == 0 |
| 186 |
&& ! pBackend->bTooManyResults)) // c'est une sous-recherche de la precedente qui etait fructueuse, ou un filtre sur un sous-listing. |
| 187 |
{ |
| 188 |
cd_debug (" filtrage de la recherche\n"); |
| 189 |
cd_do_filter_entries (pBackend->pLastShownResults, pBackend->iNbLastShownResults); |
| 190 |
|
| 191 |
|
| 192 |
cairo_dock_redraw_container (CAIRO_CONTAINER (myData.pListing)); |
| 193 |
} |
| 194 |
else |
| 195 |
{ |
| 196 |
pBackend->cCurrentLocateText = g_strdup (myData.sCurrentText->str); |
| 197 |
pBackend->iLocateFilter = myData.iCurrentFilter; |
| 198 |
gldi_task_launch (pBackend->pTask); |
| 199 |
} |
| 200 |
} |
| 201 |
else if (! pBackend->bStaticResults || pBackend->pLastShownResults == NULL) // synchrone |
| 202 |
{ |
| 203 |
// on enleve ses precedents resultats. |
| 204 |
cd_do_remove_entries_from_listing (pBackend); |
| 205 |
|
| 206 |
// on lance la nouvelle recherche. |
| 207 |
int iNbEntries; |
| 208 |
GList *pEntries = pBackend->search (myData.sCurrentText->str, |
| 209 |
myData.iCurrentFilter, |
| 210 |
FALSE, |
| 211 |
&iNbEntries); |
| 212 |
cd_debug (" -> %d resultats en plus", iNbEntries); |
| 213 |
if (pEntries != NULL) |
| 214 |
{ |
| 215 |
CDEntry *pMainEntry = pEntries->data; |
| 216 |
if (pMainEntry->bMainEntry) |
| 217 |
pMainEntry->pBackend = pBackend; |
| 218 |
} |
| 219 |
|
| 220 |
// on rajoute les nouveaux resultats. |
| 221 |
cd_do_append_entries_to_listing (pEntries, iNbEntries); |
| 222 |
pBackend->pLastShownResults = pEntries; |
| 223 |
pBackend->iNbLastShownResults = iNbEntries; |
| 224 |
///pBackend->bTooManyResults = (iNbEntries >= myConfig.iNbResultMax); |
| 225 |
pBackend->bTooManyResults = TRUE; |
| 226 |
} |
| 227 |
} |
| 228 |
|
| 229 |
void cd_do_launch_all_backends (void) |
| 230 |
{ |
| 231 |
cd_debug ("%s ()", __func__); |
| 232 |
cd_do_show_listing (); |
| 233 |
g_list_foreach (myData.pBackends, (GFunc) cd_do_launch_backend, NULL); |
| 234 |
} |
| 235 |
|
| 236 |
void cd_do_stop_backend (CDBackend *pBackend) |
| 237 |
{ |
| 238 |
// stop activity. |
| 239 |
if (pBackend->pTask != NULL) |
| 240 |
{ |
| 241 |
gldi_task_stop (pBackend->pTask); |
| 242 |
} |
| 243 |
// reset last result. |
| 244 |
pBackend->pLastShownResults = NULL; |
| 245 |
pBackend->iNbLastShownResults = 0; |
| 246 |
// reset shared memory. |
| 247 |
g_free (pBackend->cCurrentLocateText); |
| 248 |
pBackend->cCurrentLocateText = NULL; |
| 249 |
pBackend->iLocateFilter = 0; |
| 250 |
pBackend->bFoundNothing = FALSE; |
| 251 |
pBackend->bTooManyResults = FALSE; |
| 252 |
} |
| 253 |
|
| 254 |
void cd_do_stop_all_backends (void) |
| 255 |
{ |
| 256 |
g_list_foreach (myData.pBackends, (GFunc) cd_do_stop_backend, NULL); |
| 257 |
} |
| 258 |
|
| 259 |
|
| 260 |
void cd_do_free_backend (CDBackend *pBackend) |
| 261 |
{ |
| 262 |
if (pBackend == NULL) |
| 263 |
return; |
| 264 |
|
| 265 |
cd_do_stop_backend (pBackend); |
| 266 |
|
| 267 |
if (pBackend->stop) |
| 268 |
pBackend->stop (); |
| 269 |
|
| 270 |
g_free (pBackend); |
| 271 |
} |
| 272 |
|
| 273 |
void cd_do_free_all_backends (void) |
| 274 |
{ |
| 275 |
g_list_foreach (myData.pBackends, (GFunc) cd_do_stop_backend, NULL); |
| 276 |
g_list_free (myData.pBackends); |
| 277 |
myData.pBackends = NULL; |
| 278 |
} |
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
void cd_do_append_entries_to_listing (GList *pEntries, gint iNbEntries) |
| 283 |
{ |
| 284 |
cd_debug ("%s (%d)", __func__, iNbEntries); |
| 285 |
if (myData.pListing == NULL) |
| 286 |
return ; |
| 287 |
cd_do_show_listing (); |
| 288 |
|
| 289 |
myData.pListing->pEntries = g_list_concat (myData.pListing->pEntries, pEntries); |
| 290 |
if (myData.pListing->pCurrentEntry == NULL) |
| 291 |
cd_do_rewind_current_entry (); |
| 292 |
myData.pListing->iNbEntries += iNbEntries; |
| 293 |
myData.pListing->iNbVisibleEntries += iNbEntries; |
| 294 |
|
| 295 |
cd_do_fill_listing_entries (myData.pListing); |
| 296 |
cd_debug (" => %d elements (%d/%d)", g_list_length (myData.pListing->pEntries), myData.pListing->iNbEntries, myData.pListing->iNbVisibleEntries); |
| 297 |
} |
| 298 |
|
| 299 |
|
| 300 |
void cd_do_remove_entries_from_listing (CDBackend *pBackend) |
| 301 |
{ |
| 302 |
cd_debug ("%s (%s, %d)", __func__, pBackend->cName, pBackend->iNbLastShownResults); |
| 303 |
g_return_if_fail (myData.pListing != NULL); |
| 304 |
if (pBackend->pLastShownResults == NULL) |
| 305 |
return ; |
| 306 |
|
| 307 |
GList *e; |
| 308 |
for (e = myData.pListing->pEntries; e != NULL; e = e->next) |
| 309 |
{ |
| 310 |
if (e == pBackend->pLastShownResults) |
| 311 |
break ; |
| 312 |
} |
| 313 |
if (e == NULL) |
| 314 |
return ; |
| 315 |
|
| 316 |
GList *pLeftLink = NULL, *pRightLink = NULL; |
| 317 |
|
| 318 |
pLeftLink = pBackend->pLastShownResults->prev; |
| 319 |
if (pLeftLink) |
| 320 |
{ |
| 321 |
pLeftLink->next = NULL; |
| 322 |
pBackend->pLastShownResults->prev = NULL; |
| 323 |
} |
| 324 |
|
| 325 |
CDEntry *pEntry; |
| 326 |
int i, j = 0; |
| 327 |
for (e = pBackend->pLastShownResults, i = 0; e != NULL && i < pBackend->iNbLastShownResults; e = e->next, i ++) |
| 328 |
{ |
| 329 |
pEntry = e->data; |
| 330 |
if (! pEntry->bHidden) |
| 331 |
j ++; |
| 332 |
} |
| 333 |
myData.pListing->iNbEntries -= i; |
| 334 |
myData.pListing->iNbVisibleEntries -= j; |
| 335 |
cd_debug ("iNbEntries <- %d/%d", myData.pListing->iNbEntries, myData.pListing->iNbVisibleEntries); |
| 336 |
|
| 337 |
pRightLink = e; |
| 338 |
if (pRightLink != NULL) |
| 339 |
{ |
| 340 |
if (pLeftLink) |
| 341 |
{ |
| 342 |
pLeftLink->next = pRightLink; |
| 343 |
} |
| 344 |
pRightLink->prev = pLeftLink; |
| 345 |
} |
| 346 |
if (pBackend->pLastShownResults == myData.pListing->pEntries) |
| 347 |
myData.pListing->pEntries = pRightLink; |
| 348 |
cd_debug (" => %d elements", g_list_length (myData.pListing->pEntries)); |
| 349 |
|
| 350 |
pBackend->pLastShownResults = NULL; |
| 351 |
pBackend->iNbLastShownResults = 0; |
| 352 |
|
| 353 |
if (myData.pListing->iNbVisibleEntries > 0) |
| 354 |
{ |
| 355 |
if (myData.pListing->iNbVisibleEntries >= myConfig.iNbResultMax) |
| 356 |
cd_do_set_status_printf ("> %d results", myConfig.iNbResultMax); |
| 357 |
else |
| 358 |
cd_do_set_status_printf ("%d %s", myData.pListing->iNbVisibleEntries, myData.pListing->iNbVisibleEntries > 1 ? D_("results") : D_("result")); |
| 359 |
} |
| 360 |
else |
| 361 |
{ |
| 362 |
cd_do_set_status (D_("No result")); |
| 363 |
} |
| 364 |
|
| 365 |
cd_do_rewind_current_entry (); |
| 366 |
myData.pListing->iScrollAnimationCount = 0; |
| 367 |
myData.pListing->fAimedOffset = 0; |
| 368 |
myData.pListing->fPreviousOffset = myData.pListing->fCurrentOffset = 0; |
| 369 |
myData.pListing->sens = 1; |
| 370 |
myData.pListing->iTitleOffset = 0; |
| 371 |
myData.pListing->iTitleWidth = 0; |
| 372 |
} |
| 373 |
|
| 374 |
|
| 375 |
int cd_do_filter_entries (GList *pEntries, gint iNbEntries) |
| 376 |
{ |
| 377 |
cd_debug ("%s (%d)", __func__, iNbEntries); |
| 378 |
CDEntry *pEntry; |
| 379 |
int i, j = 0; |
| 380 |
GList *e; |
| 381 |
gchar *ext, *cHayStack; |
| 382 |
gchar *cPattern = g_ascii_strdown (myData.sCurrentText->str, -1); |
| 383 |
for (e = pEntries, i = 0; e != NULL && i < iNbEntries; e = e->next, i ++) |
| 384 |
{ |
| 385 |
pEntry = e->data; |
| 386 |
if (pEntry->cName == NULL) |
| 387 |
{ |
| 388 |
cd_warning ("l'entree n°%d/%d est vide !", i, iNbEntries); |
| 389 |
continue ; |
| 390 |
} |
| 391 |
if (pEntry->bMainEntry) |
| 392 |
{ |
| 393 |
pEntry->bHidden = FALSE; |
| 394 |
j ++; |
| 395 |
continue ; |
| 396 |
} |
| 397 |
ext = strrchr (pEntry->cName, '.'); |
| 398 |
if (ext) |
| 399 |
ext ++; |
| 400 |
if (myData.iCurrentFilter & DO_MATCH_CASE) |
| 401 |
{ |
| 402 |
cHayStack = pEntry->cName; |
| 403 |
} |
| 404 |
else |
| 405 |
{ |
| 406 |
if (pEntry->cLowerCaseName == NULL) |
| 407 |
pEntry->cLowerCaseName = g_ascii_strdown (pEntry->cName, -1); |
| 408 |
cHayStack = pEntry->cLowerCaseName; |
| 409 |
} |
| 410 |
if (g_strstr_len (cHayStack, -1, cPattern) != NULL && |
| 411 |
(!(myData.iCurrentFilter & DO_TYPE_MUSIC) |
| 412 |
|| (ext |
| 413 |
&& (g_ascii_strcasecmp (ext, "mp3") == 0 |
| 414 |
|| g_ascii_strcasecmp (ext, "ogg") == 0 |
| 415 |
|| g_ascii_strcasecmp (ext, "wav") == 0))) && |
| 416 |
(!(myData.iCurrentFilter & DO_TYPE_IMAGE) |
| 417 |
|| (ext |
| 418 |
&& (g_ascii_strcasecmp (ext, "jpg") == 0 |
| 419 |
|| g_ascii_strcasecmp (ext, "jpeg") == 0 |
| 420 |
|| g_ascii_strcasecmp (ext, "png") == 0))) && |
| 421 |
(!(myData.iCurrentFilter & DO_TYPE_VIDEO) |
| 422 |
|| (ext |
| 423 |
&& (g_ascii_strcasecmp (ext, "avi") == 0 |
| 424 |
|| g_ascii_strcasecmp (ext, "mkv") == 0 |
| 425 |
|| g_ascii_strcasecmp (ext, "ogv") == 0 |
| 426 |
|| g_ascii_strcasecmp (ext, "wmv") == 0 |
| 427 |
|| g_ascii_strcasecmp (ext, "mov") == 0))) && |
| 428 |
(!(myData.iCurrentFilter & DO_TYPE_TEXT) |
| 429 |
|| (ext |
| 430 |
&& (g_ascii_strcasecmp (ext, "txt") == 0 |
| 431 |
|| g_ascii_strcasecmp (ext, "odt") == 0 |
| 432 |
|| g_ascii_strcasecmp (ext, "doc") == 0))) && |
| 433 |
(!(myData.iCurrentFilter & DO_TYPE_HTML) |
| 434 |
|| (ext |
| 435 |
&& (g_ascii_strcasecmp (ext, "html") == 0 |
| 436 |
|| g_ascii_strcasecmp (ext, "htm") == 0))) && |
| 437 |
(!(myData.iCurrentFilter & DO_TYPE_SOURCE) |
| 438 |
|| (ext |
| 439 |
&& (g_ascii_strcasecmp (ext, "c") == 0 |
| 440 |
|| g_ascii_strcasecmp (ext, "h") == 0 |
| 441 |
|| g_ascii_strcasecmp (ext, "cpp") == 0)))) |
| 442 |
{ |
| 443 |
pEntry->bHidden = FALSE; |
| 444 |
j ++; |
| 445 |
} |
| 446 |
else |
| 447 |
{ |
| 448 |
pEntry->bHidden = TRUE; |
| 449 |
} |
| 450 |
} |
| 451 |
g_free (cPattern); |
| 452 |
|
| 453 |
return j; |
| 454 |
} |
| 455 |
|
| 456 |
|
| 457 |
void cd_do_activate_filter_option (int iNumOption) |
| 458 |
{ |
| 459 |
cd_debug ("%s (%d)", __func__, iNumOption); |
| 460 |
int iMaskOption = (1 << iNumOption); |
| 461 |
if (myData.iCurrentFilter & iMaskOption) // on enleve l'option => ca fait (beaucoup) plus de resultats. |
| 462 |
{ |
| 463 |
myData.iCurrentFilter &= (~iMaskOption); |
| 464 |
} |
| 465 |
else // on active l'option => ca filtre les resultats courants. |
| 466 |
{ |
| 467 |
myData.iCurrentFilter |= iMaskOption; |
| 468 |
if (myData.pListing && myData.pListing->pEntries == NULL) // on rajoute une contrainte sur une recherche qui ne fournit aucun resultat => on ignore. |
| 469 |
{ |
| 470 |
cd_debug ("useless\n"); |
| 471 |
return ; |
| 472 |
} |
| 473 |
} |
| 474 |
cd_debug ("myData.iCurrentFilter <- %d", myData.iCurrentFilter); |
| 475 |
|
| 476 |
// on cherche les nouveaux resultats correpondants. |
| 477 |
cd_do_launch_all_backends (); // relance le locate seulement si necessaire. |
| 478 |
} |
| 479 |
|
| 480 |
|
| 481 |
GList* cd_do_list_main_sub_entry (CDEntry *pEntry, int *iNbSubEntries) |
| 482 |
{ |
| 483 |
if (pEntry->pBackend == NULL || pEntry->pBackend->search == NULL) |
| 484 |
return NULL; |
| 485 |
return pEntry->pBackend->search (myData.cSearchText, myData.iCurrentFilter, TRUE, iNbSubEntries); |
| 486 |
} |
| 487 |
|
| 488 |
|
| 489 |
void cd_do_show_current_sub_listing (void) |
| 490 |
{ |
| 491 |
cd_debug ("%s ()", __func__); |
| 492 |
if (myData.pListing->pCurrentEntry == NULL) |
| 493 |
return ; |
| 494 |
if (myData.pListingHistory == NULL) // on sauvegarde le texte de la recherche principale. |
| 495 |
{ |
| 496 |
myData.cSearchText = g_strdup (myData.sCurrentText->str); |
| 497 |
} |
| 498 |
|
| 499 |
// on construit la liste des sous-entrees de l'entree courante. |
| 500 |
CDEntry *pEntry = myData.pListing->pCurrentEntry->data; |
| 501 |
GList *pNewEntries = NULL; |
| 502 |
int iNbNewEntries = 0; |
| 503 |
if (pEntry->list) |
| 504 |
pNewEntries = pEntry->list (pEntry, &iNbNewEntries); |
| 505 |
if (pNewEntries == NULL) |
| 506 |
return ; |
| 507 |
|
| 508 |
// on enleve le listing courant et on le conserve dans l'historique. |
| 509 |
CDListingBackup *pBackup = g_new0 (CDListingBackup, 1); |
| 510 |
pBackup->pEntries = myData.pListing->pEntries; |
| 511 |
pBackup->iNbEntries = myData.pListing->iNbEntries; |
| 512 |
pBackup->pCurrentEntry = myData.pListing->pCurrentEntry; |
| 513 |
|
| 514 |
g_string_assign (myData.sCurrentText, ""); |
| 515 |
myData.iNbValidCaracters = 0; |
| 516 |
//cd_do_delete_invalid_caracters (); |
| 517 |
cd_do_free_char_list (myData.pCharList); |
| 518 |
myData.pCharList = NULL; |
| 519 |
myData.iTextWidth = 0; |
| 520 |
myData.iTextHeight = 0; |
| 521 |
cairo_dock_redraw_container (CAIRO_CONTAINER (g_pMainDock)); |
| 522 |
|
| 523 |
myData.pListingHistory = g_list_prepend (myData.pListingHistory, pBackup); |
| 524 |
|
| 525 |
myData.pListing->pEntries = NULL; |
| 526 |
myData.pListing->iNbEntries = 0; |
| 527 |
myData.pListing->iNbVisibleEntries = 0; |
| 528 |
myData.pListing->pCurrentEntry = NULL; |
| 529 |
myData.pListing->iAppearanceAnimationCount = 0; |
| 530 |
myData.pListing->iCurrentEntryAnimationCount = 0; |
| 531 |
myData.pListing->iScrollAnimationCount = 0; |
| 532 |
myData.pListing->fAimedOffset = myData.pListing->fPreviousOffset = myData.pListing->fCurrentOffset = 0; |
| 533 |
|
| 534 |
// on montre les nouveaux resultats. |
| 535 |
cd_do_load_entries_into_listing (pNewEntries, iNbNewEntries); |
| 536 |
} |
| 537 |
|
| 538 |
void cd_do_show_previous_listing (void) |
| 539 |
{ |
| 540 |
cd_debug ("%s ()", __func__); |
| 541 |
if (myData.pListingHistory == NULL) // on n'est pas dans un sous-listing. |
| 542 |
return ; |
| 543 |
|
| 544 |
// on recupere le precedent sous-listing. |
| 545 |
CDListingBackup *pBackup = myData.pListingHistory->data; |
| 546 |
myData.pListingHistory = g_list_delete_link (myData.pListingHistory, myData.pListingHistory); |
| 547 |
|
| 548 |
// on enleve le sous-listing courant. |
| 549 |
g_list_foreach (myData.pListing->pEntries, (GFunc)cd_do_free_entry, NULL); |
| 550 |
g_list_free (myData.pListing->pEntries); |
| 551 |
myData.pListing->pEntries = NULL; |
| 552 |
myData.pListing->iNbEntries = 0; |
| 553 |
myData.pListing->pCurrentEntry = NULL; |
| 554 |
myData.pListing->iAppearanceAnimationCount = 0; |
| 555 |
myData.pListing->iCurrentEntryAnimationCount = 0; |
| 556 |
myData.pListing->iScrollAnimationCount = 0; |
| 557 |
myData.pListing->fAimedOffset = myData.pListing->fPreviousOffset = myData.pListing->fCurrentOffset = 0; |
| 558 |
|
| 559 |
// on charge le nouveau sous-listing. |
| 560 |
cd_do_load_entries_into_listing (pBackup->pEntries, pBackup->iNbEntries); // les entrees du backup appartiennent desormais au listing. |
| 561 |
g_free (pBackup); |
| 562 |
|
| 563 |
if (myData.pListingHistory == NULL) // retour a la recherche principale. |
| 564 |
{ |
| 565 |
cd_do_free_char_list (myData.pCharList); |
| 566 |
myData.pCharList = NULL; |
| 567 |
myData.iTextWidth = 0; |
| 568 |
myData.iTextHeight = 0; |
| 569 |
myData.iNbValidCaracters = 0; |
| 570 |
|
| 571 |
g_string_assign (myData.sCurrentText, myData.cSearchText); |
| 572 |
g_free (myData.cSearchText); |
| 573 |
myData.cSearchText = NULL; |
| 574 |
|
| 575 |
cd_do_load_pending_caracters (); |
| 576 |
cd_do_launch_appearance_animation (); |
| 577 |
myData.iNbValidCaracters = myData.sCurrentText->len; |
| 578 |
} |
| 579 |
} |
| 580 |
|
| 581 |
|
| 582 |
void cd_do_filter_current_listing (void) |
| 583 |
{ |
| 584 |
cd_debug ("%s ()", __func__); |
| 585 |
if (myData.pListing == NULL || myData.pListing->pEntries == NULL) |
| 586 |
return ; |
| 587 |
|
| 588 |
myData.pListing->iNbVisibleEntries = cd_do_filter_entries (myData.pListing->pEntries, myData.pListing->iNbEntries); |
| 589 |
|
| 590 |
cd_do_fill_listing_entries (myData.pListing); // on reprend a 0. |
| 591 |
|
| 592 |
cd_do_rewind_current_entry (); |
| 593 |
|
| 594 |
myData.pListing->iScrollAnimationCount = 0; |
| 595 |
myData.pListing->fAimedOffset = 0; |
| 596 |
myData.pListing->fPreviousOffset = myData.pListing->fCurrentOffset = 0; |
| 597 |
myData.pListing->sens = 1; |
| 598 |
myData.pListing->iTitleOffset = 0; |
| 599 |
myData.pListing->iTitleWidth = 0; |
| 600 |
cairo_dock_redraw_container (CAIRO_CONTAINER (myData.pListing)); |
| 601 |
} |