Commit aaff648b authored by Ziirish's avatar Ziirish

fixing d&d + bug with rhythmbox while listening a radio

parent c2e8a084
......@@ -20,6 +20,7 @@
#include "cid-constantes.h"
#include "cid-draw.h"
#include "cid-menu-factory.h"
#include "cid-string-utilities.h"
extern CidMainContainer *cid;
//extern gboolean bCurrentlyDownloading, bCurrentlyDownloadingXML, bCurrentlyFocused;
......@@ -160,86 +161,77 @@ on_dragNdrop_data_received (GtkWidget *wgt, GdkDragContext *context, int x, int
GtkSelectionData *seldata, guint info, guint time,
gpointer userdata)
{
gchar *cReceivedData = (gchar *) seldata->data;
g_return_if_fail (cReceivedData != NULL);
int length = strlen (cReceivedData);
if (cReceivedData[length-1] == '\n')
cReceivedData[--length] = '\0'; // on vire le retour chariot final.
if (cReceivedData[length-1] == '\r')
cReceivedData[--length] = '\0';
if ((seldata->length >= 0) && (seldata->format == 8))
{
gchar *cReceivedData = (gchar *) seldata->data;
g_return_if_fail (cReceivedData != NULL);
int length = strlen (cReceivedData);
fprintf (stdout, "before: %s\n", cReceivedData);
CidDataTable *pTab = cid_str_split (cReceivedData, '\n');
gchar **cReceivedDataList = g_strsplit(cReceivedData,"\n",0);
//g_free (cReceivedData);
while (*cReceivedDataList != NULL)
{
gboolean isImage = g_str_has_suffix(*cReceivedDataList,"JPG")
|| g_str_has_suffix(*cReceivedDataList,"jpg")
|| g_str_has_suffix(*cReceivedDataList,"JPEG")
|| g_str_has_suffix(*cReceivedDataList,"jpeg")
|| g_str_has_suffix(*cReceivedDataList,"PNG")
|| g_str_has_suffix(*cReceivedDataList,"png")
|| g_str_has_suffix(*cReceivedDataList,"SVG")
|| g_str_has_suffix(*cReceivedDataList,"svg");
BEGIN_FOREACH_DT (pTab)
gchar *cTmp = p_temp->content->string;
fprintf (stdout, "POUET: '%s' (%s)\n", *cReceivedDataList, isImage ? "TRUE" : "FALSE");
if(isImage)
{
if(musicData.playing_artist != NULL && musicData.playing_album != NULL)
gboolean isImage = cid_str_match (cTmp, "^.+\\.(jpe?g|png|svg)$");
if(isImage)
{
cid_debug("Le fichier est une image");
GString *command = g_string_new ("");
if(strncmp(*cReceivedDataList, "http://", 7) == 0)
if(musicData.playing_artist != NULL && musicData.playing_album != NULL)
{
cid_debug("Le fichier est distant");
g_string_printf (command, "wget -O /tmp/\"%s - %s.jpg\" %s",
musicData.playing_artist,
musicData.playing_album,
*cReceivedDataList);
cid_debug("Le fichier est une image");
GString *command = g_string_new ("");
if(strncmp(cTmp, "http://", 7) == 0)
{
cid_debug("Le fichier est distant");
g_string_printf (command, "wget -O /tmp/\"%s - %s.jpg\" %s",
musicData.playing_artist,
musicData.playing_album,
cTmp);
cid_launch_command (command->str);
g_string_free (command, TRUE);
}
else
{
cid_debug("Le fichier est local");
gchar *cFileSrc = (*cTmp == '/' ? g_strdup(cTmp) : g_filename_from_uri (cTmp, NULL, NULL));
gchar *cFileDst = g_strdup_printf ("/tmp/\"%s - %s.jpg\"",musicData.playing_artist,musicData.
playing_album);
cid_file_copy (cFileSrc,cFileDst);
g_free (cFileSrc);
g_free (cFileDst);
}
gchar *cTmpImagePath = g_strdup_printf("/tmp/%s - %s.jpg",musicData.playing_artist,musicData.
playing_album);
cid_display_image(cTmpImagePath);
cid_animation(cid->config->iAnimationType);
cid_datatable_append (&cid->runtime->pImagesList, cid_datacontent_new_string (cTmpImagePath));
g_free (cTmpImagePath);
}
else
{
cid_debug("Le fichier est local");
gchar *cFileSrc = (**cReceivedDataList == '/' ? g_strdup(*cReceivedDataList) : g_filename_from_uri (*cReceivedDataList, NULL, NULL));
gchar *cFileDst = g_strdup_printf ("/tmp/\"%s - %s.jpg\"",musicData.playing_artist,musicData.playing_album);
cid_file_copy (cFileSrc,cFileDst);
g_free (cFileSrc);
g_free (cFileDst);
gchar *cTmpImagePath = (*cTmp == '/' ? g_strdup(cTmp) : g_filename_from_uri (cTmp, NULL, NULL));
cid_display_image(cTmpImagePath);
cid_animation(cid->config->iAnimationType);
cid_datatable_append (&cid->runtime->pImagesList, cid_datacontent_new_string (cTmpImagePath));
g_free (cTmpImagePath);
}
cid_launch_command (command->str);
g_string_free (command, TRUE);
gchar *cTmpImagePath = g_strdup_printf("/tmp/%s - %s.jpg",musicData.playing_artist,musicData.playing_album);
cid_display_image(cTmpImagePath);
cid_animation(cid->config->iAnimationType);
g_free (cTmpImagePath);
}
else
{
gchar *cTmpImagePath = (**cReceivedDataList == '/' ? g_strdup(*cReceivedDataList) : g_filename_from_uri (*cReceivedDataList, NULL, NULL));
cid_display_image(cTmpImagePath);
cid_animation(cid->config->iAnimationType);
g_free (cTmpImagePath);
cid_debug("On ajoute à la playlist");
if (cid->runtime->pMonitorList->p_fAddToQueue!=NULL)
cid->runtime->pMonitorList->p_fAddToQueue(cTmp);
}
gtk_main_quit ();
gtk_main ();
}
else
{
cid_debug("On ajoute à la playlist");
if (cid->runtime->pMonitorList->p_fAddToQueue!=NULL)
cid->runtime->pMonitorList->p_fAddToQueue(*cReceivedDataList);
}
g_free (*cReceivedDataList);
cReceivedDataList++;
}
END_FOREACH_DT_NF
//g_print("d&d >>> %s\n",cReceivedData);
//system (g_strdup_printf("nautilus %s &",cReceivedData));
//g_strfreev (cReceivedDataList);
g_free (cReceivedData);
context->action = GDK_ACTION_COPY;
gtk_drag_finish (context, TRUE, FALSE, time);
return;
}
gtk_drag_finish (context, FALSE, FALSE, time);
}
......
......@@ -338,7 +338,7 @@ cid_read_key_file (CidMainContainer **pCid, const gchar *f)
cid->config->dGreen = cid->config->pColor->dGreen;
cid->config->dBlue = cid->config->pColor->dBlue;
cid->config->dAlpha = cid->config->pColor->dAlpha;
cid->runtime->dFocusVariation = cid->config->pFlyingColor->dAlpha>cid->config->dAlpha ? +1 : -1;
cid->runtime->dFocusVariation = cid->config->pFlyingColor->dAlpha > cid->config->dAlpha ? +1 : -1;
cid->config->iExtraSize = (cid->config->iHeight + cid->config->iWidth)/20;
cid->config->iPrevNextSize = cid->config->iExtraSize * 2;
cid->config->iPlayPauseSize = cid->config->iExtraSize * 3;
......
......@@ -356,6 +356,7 @@ cid_cover_lookup (CidMainContainer **pCid,
return cRes;
g_free (cRes);
cRes = NULL;
cid->runtime->pImagesList = cid_images_lookup (pCid, cDir);
......
......@@ -229,29 +229,25 @@ cid_create_main_window()
g_signal_connect (G_OBJECT(cid->pWindow), "enter-notify-event", G_CALLBACK(cid_focus), GINT_TO_POINTER(TRUE)); // On passe le curseur sur la fenêtre
g_signal_connect (G_OBJECT(cid->pWindow), "leave-notify-event", G_CALLBACK(cid_focus), GINT_TO_POINTER(FALSE)); // Le curseur quitte la fenêtre
///\_______ TESTING OPTION
if (cid->config->bUnstable)
{
/* On prépare le traitement du d'n'd */
GtkTargetEntry *pTargetEntry = g_new0 (GtkTargetEntry, 6);
pTargetEntry[0].target = "text/*";
pTargetEntry[0].flags = (GtkTargetFlags) 0;
pTargetEntry[0].info = 0;
pTargetEntry[1].target = "text/uri-list";
pTargetEntry[2].target = "text/plain";
pTargetEntry[3].target = "text/plain;charset=UTF-8";
pTargetEntry[4].target = "text/directory";
pTargetEntry[5].target = "text/html";
gtk_drag_dest_set (cid->pWindow,
GTK_DEST_DEFAULT_DROP | GTK_DEST_DEFAULT_MOTION, // GTK_DEST_DEFAULT_HIGHLIGHT ne rend pas joli je trouve.
pTargetEntry,
6,
GDK_ACTION_COPY | GDK_ACTION_MOVE); // le 'GDK_ACTION_MOVE' c'est pour KDE.
g_free (pTargetEntry);
/* On prépare le traitement du d'n'd */
GtkTargetEntry *pTargetEntry = g_new0 (GtkTargetEntry, 6);
pTargetEntry[0].target = "text/*";
pTargetEntry[0].flags = (GtkTargetFlags) 0;
pTargetEntry[0].info = 0;
pTargetEntry[1].target = "text/uri-list";
pTargetEntry[2].target = "text/plain";
pTargetEntry[3].target = "text/plain;charset=UTF-8";
pTargetEntry[4].target = "text/directory";
pTargetEntry[5].target = "text/html";
gtk_drag_dest_set (cid->pWindow,
GTK_DEST_DEFAULT_DROP | GTK_DEST_DEFAULT_MOTION, // GTK_DEST_DEFAULT_HIGHLIGHT ne rend pas joli je trouve.
pTargetEntry,
6,
GDK_ACTION_COPY | GDK_ACTION_MOVE); // le 'GDK_ACTION_MOVE' c'est pour KDE.
g_free (pTargetEntry);
/* traitement du d'n'd */
g_signal_connect (G_OBJECT(cid->pWindow), "drag-data-received", G_CALLBACK(on_dragNdrop_data_received), NULL);
}
/* traitement du d'n'd */
g_signal_connect (G_OBJECT(cid->pWindow), "drag-data-received", G_CALLBACK(on_dragNdrop_data_received), NULL);
/* traitement des clics */
g_signal_connect (G_OBJECT(cid->pWindow), "button-press-event", G_CALLBACK(on_clic), NULL); // Clic de souris
......
......@@ -167,7 +167,8 @@ getSongInfos(void)
G_TYPE_INVALID,
dbus_g_type_get_map("GHashTable",G_TYPE_STRING, G_TYPE_VALUE),
&data_list,
G_TYPE_INVALID)) {
G_TYPE_INVALID))
{
g_free (musicData.playing_artist);
value = (GValue *) g_hash_table_lookup(data_list, "artist");
if (value != NULL && G_VALUE_HOLDS_STRING(value))
......@@ -208,6 +209,7 @@ getSongInfos(void)
value = (GValue *) g_hash_table_lookup(data_list, "rb:coverArt-uri");
g_free (musicData.playing_cover);
musicData.playing_cover = NULL;
if (value != NULL && G_VALUE_HOLDS_STRING(value))
{
GError *erreur = NULL;
......
......@@ -250,3 +250,63 @@ cid_str_match (const gchar *cString, const gchar *cRegex)
{
return g_regex_match_simple (cRegex, cString, G_REGEX_CASELESS, 0);
}
CidDataTable *
cid_str_split (const gchar *cString, const gchar cTokken)
{
CidDataTable *ret = cid_datatable_new ();
gchar *cTmp = g_malloc (256 * sizeof(gchar));
gint cpt = 0, i = 0, nb = 2;
for (; *cString != 0; cString++,cpt++,i++)
{
if (cpt > 10)
{
cTmp = g_realloc (cTmp, nb * 256 * sizeof(gchar));
if (cTmp == NULL)
{
g_free (cTmp);
cid_clear_datatable (&ret);
return NULL;
}
nb++;
cpt = 0;
}
if (*cString == cTokken)
{
if (i > 0)
{
cTmp[i] = '\0';
gchar *cAdd = g_strndup (cTmp, i - 1);
cid_datatable_append (&ret, cid_datacontent_new_string (cAdd));
g_free (cTmp);
g_free (cAdd);
cTmp = g_malloc (256 * sizeof(gchar));
i = -1;
nb = 2;
cpt = -1;
}
continue;
}
cTmp[i] = *cString;
}
if (i > 0)
{
if (cpt > 10)
{
cTmp = g_realloc (cTmp, nb * 256 * sizeof(gchar));
if (cTmp == NULL)
{
g_free (cTmp);
cid_clear_datatable (&ret);
return NULL;
}
}
cTmp[i] = '\0';
gchar *cAdd = g_strndup (cTmp, i - 1);
cid_datatable_append (&ret, cid_datacontent_new_string (cAdd));
g_free (cTmp);
g_free (cAdd);
}
return ret;
}
......@@ -65,5 +65,13 @@ void cid_str_prepare (gchar **cString);
*/
gboolean cid_str_match (const gchar *cString, const gchar *cRegex);
/**
* Permet de splitter une chaine de caractères.
* @param cString la chaîne à splitter.
* @param cTokken le caractère à utiliser pour découper la chaine.
* @return un tableau de chaines de caractères.
*/
CidDataTable *cid_str_split (const gchar *cString, const gchar cTokken);
G_END_DECLS
#endif
......@@ -385,6 +385,11 @@ main ( int argc, char **argv )
cid_clear_datatable (&table);
*/
/*
gchar *cString = "bonjour\ncomment ça va ?";
gchar **cTab = cid_str_split (cString, '\n');
*/
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