Commit fa64a147 authored by Ziirish's avatar Ziirish

new datatables features to improve local cover lookup

parent 7ae38b1e
......@@ -284,10 +284,10 @@ _cid_about (GtkMenuItem *pMenuItem, gpointer *data)
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_INFO,
GTK_BUTTONS_CLOSE,
"\nConky Images Display (2008-2010)\n version %s",CID_VERSION);
"\nConky Images Display (2008-2011)\n version %s",CID_VERSION);
#if GTK_MINOR_VERSION >= 12
GtkWidget *pLink = gtk_link_button_new_with_label (CID_WEBSITE, "Conky Images Display (2008-2010)\n version "CID_VERSION);
GtkWidget *pLink = gtk_link_button_new_with_label (CID_WEBSITE, "Conky Images Display (2008-2011)\n version "CID_VERSION);
gtk_container_add (GTK_CONTAINER (GTK_DIALOG(pDialog)->vbox), pLink);
//gtk_link_button_set_uri_hook ((GtkLinkButtonUriFunc) _cid_web_button_clicked, NULL, NULL);
#endif
......
......@@ -257,7 +257,7 @@ cid_db_store_cover (CidMainContainer **pCid,
md5);
cid_file_copy (cCoverPath, cDestFile);
cid_file_remove (cCoverPath);
g_key_file_set_value (pKeyFile, "DB", cKey, md5);
g_key_file_set_value (pKeyFile, DB_GROUP_DOWNLOAD, cKey, md5);
cid_write_keys_to_file (pKeyFile, cDBFile);
g_key_file_free (pKeyFile);
g_free (cKey);
......@@ -300,7 +300,7 @@ cid_db_search_cover (CidMainContainer **pCid,
return NULL;
}
gchar *cVal = g_key_file_get_value (pKeyFile, "DB", cKey, &error);
gchar *cVal = g_key_file_get_value (pKeyFile, DB_GROUP_DOWNLOAD, cKey, &error);
if (error != NULL)
{
cid_warning ("%s",error->message);
......@@ -339,6 +339,7 @@ cid_cover_lookup (CidMainContainer **pCid,
else
cRes = g_strdup_printf ("%s/%s.jpg", cDir, file);
cid_debug (" test de %s\n", cRes);
g_free (file);
if (g_file_test (cRes, G_FILE_TEST_EXISTS))
{
return cRes;
......
......@@ -34,7 +34,9 @@ G_BEGIN_DECLS
#define TEST_XML "../data/test.xml"
#define CID_COVER_DB "cover.db"
#define CID_COVER_DB "cover.db"
#define DB_GROUP_DOWNLOAD "DB"
#define DB_GROUP_LOCAL "LOCAL"
/**
......
......@@ -219,15 +219,56 @@ cid_free_datacontent_full (CidDataContent *pContent, gpointer *pData)
}
void
cid_free_datatable (CidDataTable **p_list)
cid_free_datatable (CidDataTable *p_list)
{
if (p_list != NULL)
{
cid_datatable_foreach(p_list,(CidDataAction) cid_free_datacase_full, NULL);
}
}
void
cid_clear_datatable (CidDataTable *p_list)
{
if (*p_list != NULL)
{
cid_datatable_foreach(*p_list,(CidDataAction) cid_free_datacase_full, NULL);
cid_free_datatable (*p_list);
g_free(*p_list), *p_list = NULL;
}
}
static CidDataCase *
cid_clone_datacase (const CidDataCase *pCase)
{
CidDataCase *res = cid_datacase_new ();
if (res != NULL)
{
CidDataContent *ori = pCase->content;
CidDataContent *new;
switch (ori->type)
{
case G_TYPE_INT:
new = cid_datacontent_new_int (GINT_TO_POINTER(pCase->content->iNumber));
break;
case G_TYPE_BOOLEAN:
new = cid_datacontent_new_boolean (GINT_TO_POINTER(ori->booleen));
break;
case G_TYPE_STRING:
new = cid_datacontent_new_string (ori->string);
break;
case CID_TYPE_SUBSTITUTE:
new = cid_datacontent_new_substitute (cid_new_substitute (ori->sub->regex,ori->sub->replacement));
break;
default:
return NULL;
}
res->content = new;
res->next = pCase->next;
res->prev = pCase->prev;
}
return res;
}
void
cid_datatable_foreach (CidDataTable *p_list, CidDataAction func, gpointer *pData)
{
......@@ -244,11 +285,10 @@ cid_datatable_foreach (CidDataTable *p_list, CidDataAction func, gpointer *pData
while (p_temp != NULL)
{
pData[0] = GINT_TO_POINTER(cpt);
CidDataCase *p_del = g_malloc0(sizeof(*p_temp));
memcpy(p_del,p_temp,sizeof(*p_temp));
CidDataCase *p_del = cid_clone_datacase (p_temp);
func (p_temp, pData);
p_temp = p_del->next;
g_free(p_del);
cid_free_datacase (p_del);
cpt++;
}
if (bCreateData)
......@@ -472,7 +512,7 @@ cid_char_table_to_datatable (gchar **table, gint iSize)
CidDataTable *res = cid_datatable_new();
if (res != NULL)
{
while ((iSize == -1 ? table[cpt] != NULL : cpt<iSize) && table[cpt] != NULL)
while (iSize == -1 ? table[cpt] != NULL : (cpt<iSize && table[cpt] != NULL))
{
CidDataContent *tmp = cid_datacontent_new(G_TYPE_STRING, table[cpt]);
cid_datatable_append(&res,tmp);
......@@ -482,6 +522,31 @@ cid_char_table_to_datatable (gchar **table, gint iSize)
return res;
}
gchar **
cid_datatable_to_char_table (CidDataTable *pTable, gint *iSize)
{
g_return_val_if_fail (pTable != NULL, NULL);
size_t size = cid_datatable_length (pTable);
gchar **res = g_malloc0_n (size,sizeof(gchar *));
gint cpt = 0;
if (res != NULL)
{
BEGIN_FOREACH_DT (pTable)
g_free (res[cpt]);
res[cpt] = g_strdup (p_temp->content->string);
cpt++;
END_FOREACH_DT_NF
*iSize = cpt;
}
else
{
*iSize = -1;
}
return res;
}
static void
cid_copy_datacase (CidDataCase *pCase, gpointer *pData)
{
......
......@@ -221,6 +221,15 @@ void cid_free_datacontent_full (CidDataContent *pContent, gpointer *pData);
*/
CidDataTable *cid_char_table_to_datatable (gchar **table, gint iSize);
/**
* Permet de convertir un DataTable en tableau de chaînes.
* @param pTable table à convertir.
* @param iSize pointeur retournant le nombre d'éléments.
* @return un tableau de chaînes de caractères contenant une copie de
* l'ensemble des chaînes de la table.
*/
gchar **cid_datatable_to_char_table (CidDataTable *pTable, gint *iSize);
/**
* Permet de cloner un datatable.
* @param pSource datatable à cloner.
......
......@@ -12,6 +12,7 @@
#include "cid-md5.h"
#include "cid-constantes.h"
#include "cid-config.h"
#include "cid-string-utilities.h"
gboolean
cid_file_copy (const gchar *cSrc, const gchar *cDst)
......@@ -190,8 +191,21 @@ cid_file_check (const gchar *f)
}
gboolean
cid_file_lookup (const gchar *cFileName)
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)
{
cid_warning ("%s", error->message);
g_clear_error (&error);
return FALSE;
}
return FALSE;
}
......@@ -243,6 +243,11 @@ struct _CidRuntime {
/// liste des patterns de pochettes à rechercher
CidDataTable *pCoversList;
/// liste des images trouvées
CidDataTable *pImagesList;
/// Répertoire dans lequel on recherche des pochettes
GDir *pLookupDirectory;
};
/// Structure contenant les paramètres de configuration de CID
......
......@@ -118,6 +118,12 @@ cid_free_main_structure (CidMainContainer *pCid)
pCid->config->cConfFile = NULL;
pCid->config->cVerbosity = NULL;
cid_free_datatable (&pCid->runtime->pCoversList);
cid_free_datatable (&pCid->runtime->pImagesList);
if (pCid->runtime->pLookupDirectory)
g_dir_close (pCid->runtime->pLookupDirectory);
g_free (pCid);
pCid = NULL;
}
......
......@@ -214,7 +214,6 @@ cid_display_init(CidMainContainer **pCid, int *argc, char ***argv)
int
main ( int argc, char **argv )
{
struct sigaction action;
cid = g_malloc0 (sizeof(*cid));
......@@ -326,6 +325,26 @@ main ( int argc, char **argv )
fprintf (stdout,"after: '%s'\n",init);
g_free (init);
*/
/*
gint size, i = 0;
gchar **test;
CidDataTable *table = cid_char_table_to_datatable (argv, -1);
cid_datatable_foreach (table, cid_datacase_print, NULL);
test = cid_datatable_to_char_table (table, &size);
//g_print ("size: %d | argc: %d\n", size, argc);
for (;i < size; i++)
{
//g_print ("test[%d]: %s\n",i,test[i]);
g_free (test[i]);
}
g_free (test);
cid_free_datatable (&table);
*/
fprintf (stdout,"Bye !\n");
......
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