Commit ce7f8281 authored by Ziirish's avatar Ziirish

cid is now able to search images into the song directory

parent 0c660d2b
......@@ -15,6 +15,7 @@
#include "cid-messages.h"
#include "cid-utilities.h"
#include "cid-md5.h"
#include "cid-file-utilities.h"
#include <curl/curl.h>
#include <fcntl.h>
......@@ -330,6 +331,8 @@ cid_cover_lookup (CidMainContainer **pCid,
CidMainContainer *cid = *pCid;
gchar *cRes = NULL;
cid_clear_datatable (&cid->runtime->pImagesList);
BEGIN_FOREACH_DT (cid->runtime->pCoversList)
g_free (cRes);
gchar *file = g_strdup (p_temp->content->string);
......@@ -351,7 +354,20 @@ cid_cover_lookup (CidMainContainer **pCid,
if (cRes != NULL)
return cRes;
g_free (cRes);
cid->runtime->pImagesList = cid_images_lookup (pCid, cDir);
if (cid_datatable_length (cid->runtime->pImagesList) > 0)
{
CidDataCase *p_tmp = cid->runtime->pImagesList->head;
cRes = g_strdup_printf ("%s/%s", cDir, p_tmp->content->string);
}
if (cRes != NULL)
return cRes;
cid->runtime->iCheckIter = 0;
if (musicData.iSidCheckCover != 0)
{
......
......@@ -143,6 +143,8 @@ cid_file_check (const gchar *f)
}
g_free (cDirectory);
/// retro-compatibilité: on déplace les anciens fichiers de conf
/// si existants.
cFileTest = g_strdup_printf("%s/%s",g_getenv("HOME"),OLD_CONFIG_FILE) ;
if (g_file_test (cFileTest, G_FILE_TEST_EXISTS))
{
......@@ -182,6 +184,9 @@ cid_file_check (const gchar *f)
return ret;
}
g_free (cFileTest);
/// Si on a pas trouvé d'ancienne conf, on recopie la conf par
/// défaut.
gchar *cSrc = g_strdup_printf("%s/%s",CID_DATA_DIR,CID_CONFIG_FILE);
cid_debug ("Copying file from %s to %s",cSrc,f);
ret = cid_file_copy (cSrc,f);
......@@ -190,22 +195,38 @@ cid_file_check (const gchar *f)
return ret;
}
gboolean
CidDataTable *
cid_images_lookup (CidMainContainer **pCid, const gchar *cDirName)
{
g_return_val_if_fail (cDirName != NULL, FALSE);
CidMainContainer *cid = *pCid;
GError *error;
if (cid->runtime->pLookupDirectory)
g_dir_close (cid->runtime->pLookupDirectory);
cid->runtime->pLookupDirectory = g_dir_open (cDirName,0,&error);
if (error != NULL)
CidDataTable *ret = cid_datatable_new ();
GError *error = NULL;
if (ret != NULL)
{
cid_warning ("%s", error->message);
g_clear_error (&error);
return FALSE;
cid->runtime->pLookupDirectory = g_dir_open (cDirName,0,&error);
if (error != NULL)
{
cid_warning ("%s", error->message);
g_clear_error (&error);
return FALSE;
}
const gchar *cEntry = NULL;
while ((cEntry = g_dir_read_name (cid->runtime->pLookupDirectory)) != NULL)
{
fprintf(stdout,"Testing file: %s ",cEntry);
if (cid_str_match (cEntry,"\\.(jpg|png|gif|svg)$"))
{
cid_datatable_append (&ret, cid_datacontent_new_string (cEntry));
fprintf(stdout,"[OK]\n");
}
else
{
fprintf(stdout,"[KO]\n");
}
}
g_dir_close (cid->runtime->pLookupDirectory);
}
return FALSE;
return ret;
}
......@@ -52,5 +52,13 @@ gboolean cid_file_check_conf_version (CidMainContainer **pCid, const gchar *f);
*/
gboolean cid_file_move (const gchar *cSrc, const gchar *cDst);
/**
* Retourne la liste de toutes les images d'un dossier.
* @param pCid Structure de configuration.
* @param cDirName Dossier dans lequel il faut chercher les images.
* @return CidDataTable contenant l'ensemble des images.
*/
CidDataTable *cid_images_lookup (CidMainContainer **pCid, const gchar *cDirName);
G_END_DECLS
#endif
......@@ -227,6 +227,7 @@ cid_str_prepare (gchar **cString)
CidDataTable *table = cid_create_datatable (CID_TYPE_SUBSTITUTE,
cid_new_substitute ("\\(.*\\)",""),
cid_new_substitute ("\\[.*\\]",""),
cid_new_substitute ("_"," "),
cid_new_substitute (" +"," "),
cid_new_substitute (" $",""),
G_TYPE_INVALID);
......@@ -238,3 +239,9 @@ cid_str_prepare (gchar **cString)
cid_clear_datatable (&table);
g_free (pData);
}
gboolean
cid_str_match (const gchar *cString, const gchar *cRegex)
{
return g_regex_match_simple (cRegex, cString, G_REGEX_CASELESS, 0);
}
......@@ -57,5 +57,13 @@ void cid_str_replace_all_seq (gchar **string, gchar *seqFrom, gchar *seqTo);
*/
void cid_str_prepare (gchar **cString);
/**
* Permet de tester une expression régulière.
* @param cString la chaîne à tester.
* @param cRegex expression régulière à passer sur la chaîne.
* @return TRUE si on match, FALSE sinon.
*/
gboolean cid_str_match (const gchar *cString, const gchar *cRegex);
G_END_DECLS
#endif
......@@ -206,6 +206,8 @@ struct _CidRuntime {
gint iCursorX;
/// position en y du curseur
gint iCursorY;
/// indice de l'image à utiliser
gint iImageIndex;
/// avancement de l'animation
gdouble dAnimationProgress;
......
......@@ -121,9 +121,6 @@ cid_free_main_structure (CidMainContainer *pCid)
cid_clear_datatable (&pCid->runtime->pCoversList);
cid_clear_datatable (&pCid->runtime->pImagesList);
if (pCid->runtime->pLookupDirectory)
g_dir_close (pCid->runtime->pLookupDirectory);
g_free (pCid);
pCid = NULL;
}
......
......@@ -81,7 +81,7 @@ cid_intercept_signal (int number)
cid_interrupt ();
return;
}
cid_warning ("Attention : cid has crashed (%s).", strsignal(number));
cid_warning ("Attention : cid has crashed (%d).", /*strsignal(*/number);
fflush (stdout);
signal (number, SIG_DFL);
raise (number);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment