Commit 2f31b315 authored by Ziirish's avatar Ziirish

feature: configurable cover pattern search

parent 9a1c1122
......@@ -87,8 +87,8 @@ STATE=
SYMBOL_COLOR=
#U Search the following files
#{%user% stands for the username\n%home% stands for the user's home directory\n%artist% stands for the artist's name\n%album% stands for the album name}
FILES_LIST=
#{%user% stands for the username\n%home% stands for the user's home directory\n%artist% stands for the artist's name\n%album% stands for the album name}/
FILES_LIST=album;albumart;cover;folder;.cover;.folder;
#tX+[Display Title;gtk-select-color]
frame_title =
......
......@@ -101,7 +101,7 @@ get_amarock_musicData (CidMainContainer **pCid)
run = TRUE;
cid_info ("\nartist : %s\nalbum : %s\ntitle : %s\nsong uri : %s\ncover uri : %s\n",gArtist,gAlbum,gTitle,gPlayingURI,gCoverURI);
cid_info ("\nartist : %s\nalbum : %s\ntitle : %s\nsong uri : %s\ncover uri : %s",gArtist,gAlbum,gTitle,gPlayingURI,gCoverURI);
g_free (gArtist);
g_free (gAlbum);
g_free (gTitle);
......@@ -143,7 +143,7 @@ cid_check_amarok_cover_exists (CidMainContainer **pCid, gchar *cURI)
if (g_strcasecmp(cSplitedURI[0],"nocover")==0)
{
g_free (cRet);
cRet = cid_search_cover (pCid, musicData.playing_artist, musicData.playing_album);
cRet = cid_db_search_cover (pCid, musicData.playing_artist, musicData.playing_album);
if (cRet == NULL)
{
cid->runtime->iCheckIter = 0;
......@@ -166,7 +166,7 @@ cid_amarok_cover(CidMainContainer **pCid)
/* Si Amarok ne joue pas, on affiche l'image par défaut. */
if (!musicData.opening)
{
cid_debug ("Amarok isn't playing\n");
cid_debug ("Amarok isn't playing");
cid_display_image (cid->config->cDefaultImage);
}
else
......
......@@ -360,7 +360,7 @@ _cid_check_and_display (gpointer *pSharedMemory)
cid_display_image(DEFAULT_DOWNLOADED_IMAGE_LOCATION);
gchar *tmp;
tmp = cid_store_cover (pCid,
tmp = cid_db_store_cover (pCid,
DEFAULT_DOWNLOADED_IMAGE_LOCATION,
cArtist,
cAlbum);
......
......@@ -349,6 +349,7 @@ cid_read_key_file (CidMainContainer **pCid, const gchar *f)
cid_free_and_debug_error(&error);
cid->config->t_cCoverPatternList = g_key_file_get_string_list (cid->pKeyFile, "System", "FILES_LIST", &cid->config->iNbPatterns, &error);
cid_free_and_debug_error(&error);
cid->runtime->pCoversList = cid_char_table_to_datatable (cid->config->t_cCoverPatternList, cid->config->iNbPatterns);
// [Options] configuration
cid->config->bHide = CID_CONFIG_GET_BOOLEAN ("Options", "HIDE");
......
......@@ -173,8 +173,8 @@ cid_search_xml_xpath (const char *filename, gchar **cValue, const gchar*xpath, .
}
gchar *
cid_store_cover (CidMainContainer **pCid,const gchar *cCoverPath,
const gchar *cArtist, const gchar *cAlbum)
cid_db_store_cover (CidMainContainer **pCid,const gchar *cCoverPath,
const gchar *cArtist, const gchar *cAlbum)
{
g_return_val_if_fail (cCoverPath != NULL
&& cArtist != NULL
......@@ -238,7 +238,7 @@ cid_store_cover (CidMainContainer **pCid,const gchar *cCoverPath,
}
gchar *
cid_search_cover (CidMainContainer **pCid, const gchar *cArtist, const gchar *cAlbum)
cid_db_search_cover (CidMainContainer **pCid, const gchar *cArtist, const gchar *cAlbum)
{
g_return_val_if_fail (cArtist != NULL && cAlbum != NULL, NULL);
CidMainContainer *cid = *pCid;
......@@ -286,3 +286,9 @@ cid_search_cover (CidMainContainer **pCid, const gchar *cArtist, const gchar *cA
return cCoverPath;
}
gchar *
cid_cover_lookup (const gchar *cDir)
{
return NULL;
}
......@@ -71,7 +71,7 @@ gboolean cid_download_missing_cover (const gchar *cURL/*, const gchar *cDestPath
* @return URI de la pochette apres stockage dans notre
* 'magazin', NULL si stockage impossible.
*/
gchar *cid_store_cover (CidMainContainer **pCid,const gchar *cCoverPath,
gchar *cid_db_store_cover (CidMainContainer **pCid,const gchar *cCoverPath,
const gchar *cArtist, const gchar *cAlbum);
/**
......@@ -81,7 +81,7 @@ gchar *cid_store_cover (CidMainContainer **pCid,const gchar *cCoverPath,
* @param cAlbum nom de l'album.
* @return URI complet de l'image, NULL si non toruve.
*/
gchar *cid_search_cover (CidMainContainer **pCid, const gchar *cArtist,
gchar *cid_db_search_cover (CidMainContainer **pCid, const gchar *cArtist,
const gchar *cAlbum);
G_END_DECLS
......
......@@ -186,7 +186,7 @@ cid_generate_ihm_from_keyfile (GKeyFile *pKeyFile, const gchar *cTitle, GtkWindo
GtkWidget *pOneWidget;
GSList * pSubWidgetList;
GtkWidget *pLabel, *pLabelContainer;
GtkWidget *pVBox, *pHBox, *pSmallVBox, *pEventBox, *pRightHBox;
GtkWidget *pVBox, *pHBox, *pSmallVBox, *pEventBox = NULL, *pRightHBox;
GtkWidget *pEntry;
GtkWidget *pTable;
GtkWidget *pButtonAdd, *pButtonRemove;
......@@ -457,15 +457,21 @@ cid_generate_ihm_from_keyfile (GKeyFile *pKeyFile, const gchar *cTitle, GtkWindo
if (pTipString != NULL)
{
gchar *pTmpTip = g_strdup (dgettext (cGettextDomain, pTipString));
cid_parse_nl (&pTmpTip);
//g_print ("pTmpTip : '%s'\n", pTmpTip);
pEventBox = gtk_event_box_new ();
gtk_container_add (GTK_CONTAINER (pEventBox), pHBox);
gtk_tooltips_set_tip (GTK_TOOLTIPS (pToolTipsGroup),
pEventBox,
pTmpTip,
"pouet");
g_free (pTmpTip);
if (pTmpTip != NULL)
{
cid_parse_nl (&pTmpTip);
if (pTmpTip != NULL)
{
//g_print ("pTmpTip : '%s'\n", pTmpTip);
pEventBox = gtk_event_box_new ();
gtk_container_add (GTK_CONTAINER (pEventBox), pHBox);
gtk_tooltips_set_tip (GTK_TOOLTIPS (pToolTipsGroup),
pEventBox,
pTmpTip,
"pouet");
g_free (pTmpTip);
}
}
} else
pEventBox = NULL;
......
......@@ -228,9 +228,10 @@ getSongInfos(void)
}
else
{
CidDataTable *p_tabFiles = cid_create_datatable(G_TYPE_STRING,"cover","album","albumart",
".folder",".cover","folder","Cover","Folder",
G_TYPE_INVALID);
CidDataTable *p_tabFiles = cid_clone_datatable (cid->runtime->pCoversList);
//cid_create_datatable(G_TYPE_STRING,"cover","album","albumart",
// ".folder",".cover","folder","Cover","Folder",
// G_TYPE_INVALID);
gchar *cSongPath = g_filename_from_uri (musicData.playing_uri, NULL, NULL); // on teste d'abord dans le repertoire de la chanson.
if (cSongPath != NULL)
{
......@@ -262,7 +263,7 @@ getSongInfos(void)
{
gchar *cCoverSave = g_strdup (musicData.playing_cover);
g_free (musicData.playing_cover);
musicData.playing_cover = cid_search_cover (&cid, musicData.playing_artist, musicData.playing_album);
musicData.playing_cover = cid_db_search_cover (&cid, musicData.playing_artist, musicData.playing_album);
if (musicData.playing_cover == NULL)
{
musicData.playing_cover = g_strdup (cCoverSave);
......
......@@ -292,6 +292,9 @@ struct _CidRuntime {
gboolean bPipeRunning;
/// On est connecte au lecteur ?
gboolean bConnected;
/// liste des patterns de pochettes à rechercher
CidDataTable *pCoversList;
};
/// Structure contenant les paramètres de configuration de CID
......
......@@ -1066,22 +1066,6 @@ cid_encrypt_string( const gchar *cDecryptedString, gchar **cEncryptedString )
#endif
}
static gboolean
eval_cb (const GMatchInfo *info,
GString *res,
gpointer data)
{
gchar *match;
gchar *r;
match = g_match_info_fetch (info, 0);
r = g_hash_table_lookup ((GHashTable *)data, match);
g_string_append (res, r);
g_free (match);
return FALSE;
}
static void
cid_proceed_substitute (CidDataCase *pCase, gpointer *pData)
{
......@@ -1158,4 +1142,65 @@ cid_parse_nl (gchar **input)
g_free (output);
}
CidDataTable *
cid_char_table_to_datatable (gchar **table, gint iSize)
{
g_return_val_if_fail (table != NULL,NULL);
gint cpt = 0;
CidDataTable *res = cid_datatable_new();
if (res != 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);
cpt++;
}
}
return res;
}
static void
cid_copy_datacase (CidDataCase *pCase, gpointer *pData)
{
CidDataTable *table = (CidDataTable *)pData[1];
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:
new = NULL;
}
if (new != NULL)
{
cid_datatable_append (&table,new);
}
}
CidDataTable *
cid_clone_datatable (CidDataTable *pSource)
{
CidDataTable *res = cid_datatable_new ();
if (res != NULL)
{
gpointer *data = g_new0 (gpointer,2);
data[0] = GINT_TO_POINTER (0);
data[1] = res;
cid_datatable_foreach (pSource, cid_copy_datacase, data);
g_free (data);
}
return res;
}
......@@ -287,6 +287,22 @@ void cid_free_substitute (CidSubstitute *pSub);
*/
void cid_parse_nl (gchar **input);
/**
* Permet de convertir un tableau de chaînes classic en DataTable.
* @param table tableau de départ.
* @param iSize nombre d'élément à copier (-1 pour tout le tableau).
* @return un DataTable contenant une copie de l'ensemble des élements
* du tableau passé en paramètre.
*/
CidDataTable *cid_char_table_to_datatable (gchar **table, gint iSize);
/**
* Permet de cloner un datatable.
* @param pSource datatable à cloner.
* @return un clone du datatable source.
*/
CidDataTable *cid_clone_datatable (CidDataTable *pSource);
#define BEGIN_FOREACH_DT(dt) \
CidDataTable *p_dt=dt; \
CidDataCase *p_temp=p_dt->head; \
......
......@@ -169,12 +169,21 @@ cid_set_signal_interception (struct sigaction *action)
(*action).sa_handler = cid_intercept_signal;
sigfillset (&((*action).sa_mask));
(*action).sa_flags = 0;
CidDataTable *p_signals = cid_create_datatable(G_TYPE_INT,SIGSEGV,SIGFPE,SIGILL,SIGABRT,SIGINT,SIGTERM,G_TYPE_INVALID);
CidDataTable *p_signals = cid_create_datatable(G_TYPE_INT,
SIGSEGV,
SIGFPE,
SIGILL,
SIGABRT,
SIGINT,
SIGTERM,
G_TYPE_INVALID);
BEGIN_FOREACH_DT(p_signals)
// p_temp est declare par BEGIN_FOREACH_DT
if (sigaction (p_temp->content->iNumber, action, NULL) != 0)
{
cid_error ("Problem while catching signal %d",p_temp->content->iNumber);
cid_error ("Problem while catching signal %d (%s)",
p_temp->content->iNumber,
strsignal(p_temp->content->iNumber));
}
END_FOREACH_DT
}
......@@ -219,8 +228,6 @@ cid_display_init(CidMainContainer **pCid, int *argc, char ***argv)
int
main ( int argc, char **argv )
{
//char **argvBis = malloc(sizeof(argv));
//memcpy(argvBis,argv,sizeof(argv));
struct sigaction action;
......@@ -228,22 +235,6 @@ main ( int argc, char **argv )
cid->config = g_malloc0 (sizeof(*(cid->config)));
cid->runtime = g_malloc0 (sizeof(*(cid->runtime)));
cid->defaut = g_malloc0 (sizeof(*(cid->defaut)));
/// TODO: debug
/*
int argcBis = argc, a=0;
char **argvBis = calloc(argc,sizeof(char));
if (argvBis==NULL)
cid_exit(&cid,CID_EXIT_ERROR,"Error while copying args");
for (;a<argc;a++)
{
argvBis[a] = realloc (argvBis[a],strlen(argv[a])*sizeof(char));
if (argvBis[a]!=NULL)
strcpy(argvBis[a],argv[a]);
else
cid_exit(&cid,CID_EXIT_ERROR,"Error while copying args");
}
*/
curl_global_init(CURL_GLOBAL_ALL);
......@@ -282,9 +273,7 @@ main ( int argc, char **argv )
gdk_threads_init();
// La on lance la boucle GTK
//cid_display_init (&cid,&argc,&argvBis);
cid_display_init (&cid,0,NULL);
//free (argvBis);
cid_display_init (&cid,&argc,&argv);
// Si on est ici, c'est qu'on a coupé la boucle GTK
// Du coup, on en profite pour faire un peu de ménage
......@@ -353,6 +342,7 @@ main ( int argc, char **argv )
g_free (tmp);
}
*/
fprintf (stdout,"Bye !\n");
return ret;
......
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