Commit de315aa9 authored by Guillaume Carmel-Archambault's avatar Guillaume Carmel-Archambault
Browse files

GTK Dbus update list of active codecs

parent 08379a37
...@@ -22,6 +22,8 @@ ...@@ -22,6 +22,8 @@
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include "dbus.h"
GQueue * codecQueue = NULL; GQueue * codecQueue = NULL;
gint gint
...@@ -67,11 +69,12 @@ codec_list_add(codec_t * c) ...@@ -67,11 +69,12 @@ codec_list_add(codec_t * c)
void void
codec_set_active(gchar* name) codec_set_active(gchar* name)
{ {
codec_t * c = codec_list_get(name); codec_t * c = codec_list_get(name);
if(c){ if(c)
printf("%s set active/n", c->name); {
c->is_active = TRUE; printf("%s set active\n", c->name);
} c->is_active = TRUE;
}
} }
void void
...@@ -112,6 +115,9 @@ codec_set_prefered_order(guint index) ...@@ -112,6 +115,9 @@ codec_set_prefered_order(guint index)
g_queue_push_head(codecQueue, prefered); g_queue_push_head(codecQueue, prefered);
} }
/**
*
*/
void void
codec_list_move_codec_up(guint index) codec_list_move_codec_up(guint index)
{ {
...@@ -121,13 +127,16 @@ codec_list_move_codec_up(guint index) ...@@ -121,13 +127,16 @@ codec_list_move_codec_up(guint index)
g_queue_push_nth(codecQueue, codec, index-1); g_queue_push_nth(codecQueue, codec, index-1);
} }
// TEMP // DEBUG
int i; int i;
printf("\nCodec list\n"); printf("\nCodec list\n");
for(i=0; i < codecQueue->length; i++) for(i=0; i < codecQueue->length; i++)
printf("%s\n", codec_list_get_nth(i)->name); printf("%s\n", codec_list_get_nth(i)->name);
} }
/**
*
*/
void void
codec_list_move_codec_down(guint index) codec_list_move_codec_down(guint index)
{ {
...@@ -137,9 +146,67 @@ codec_list_move_codec_down(guint index) ...@@ -137,9 +146,67 @@ codec_list_move_codec_down(guint index)
g_queue_push_nth(codecQueue, codec, index+1); g_queue_push_nth(codecQueue, codec, index+1);
} }
// TEMP // PRINT
int i; int i;
printf("\nCodec list\n"); printf("\nCodec list\n");
for(i=0; i < codecQueue->length; i++) for(i=0; i < codecQueue->length; i++)
printf("%s\n", codec_list_get_nth(i)->name); printf("%s\n", codec_list_get_nth(i)->name);
} }
/**
*
*/
void
codec_list_update_to_daemon()
{
// String listing of all codecs payloads
const gchar** codecList;
// Length of the codec list
int length = codecQueue->length;
// Initiate double array char list for one string
codecList = (void*)malloc(sizeof(void*));
// Get all codecs in queue
int i, c = 0;
printf("List of active codecs :");
for(i = 0; i < length; i++)
{
codec_t* currentCodec = codec_list_get_nth(i);
// Assert not null
if(currentCodec)
{
// Save only if active
if(currentCodec->is_active)
{
// Reallocate memory each time more than one active codec is found
if(c!=0)
codecList = (void*)realloc(codecList, (c+1)*sizeof(void*));
// Allocate memory for the payload
*(codecList+c) = (gchar*)malloc(sizeof(gchar*));
char payload[10];
// Put payload string in char array
sprintf(payload, "%d", currentCodec->_payload);
strcpy((char*)*(codecList+c), payload);
g_print(" %s", *(codecList+c));
c++;
}
}
}
// Allocate NULL array at the end for Dbus
codecList = (void*)realloc(codecList, (c+1)*sizeof(void*));
*(codecList+c) = NULL;
printf("\n");
// call dbus function with array of strings
dbus_set_active_codec_list(codecList);
// Delete memory
for(i = 0; i < c; i++) {
free((gchar*)*(codecList+i));
}
free(codecList);
}
...@@ -54,5 +54,6 @@ void codec_set_prefered_order(guint index); ...@@ -54,5 +54,6 @@ void codec_set_prefered_order(guint index);
void codec_list_move_codec_up(guint index); void codec_list_move_codec_up(guint index);
void codec_list_move_codec_down(guint index); void codec_list_move_codec_down(guint index);
void codec_list_update_to_daemon();
#endif #endif
...@@ -298,7 +298,8 @@ codec_active_toggled(GtkCellRendererToggle *renderer, gchar *path, gpointer data ...@@ -298,7 +298,8 @@ codec_active_toggled(GtkCellRendererToggle *renderer, gchar *path, gpointer data
else else
codec_set_inactive(name); codec_set_inactive(name);
// TODO Perpetuate changes to the deamon // Perpetuate changes to the deamon
codec_list_update_to_daemon();
} }
/** /**
...@@ -356,7 +357,8 @@ codec_move(gboolean moveUp, gpointer data) ...@@ -356,7 +357,8 @@ codec_move(gboolean moveUp, gpointer data)
else else
codec_list_move_codec_down(indice); codec_list_move_codec_down(indice);
// TODO Perpetuate changes to the deamon // Perpetuate changes to the deamon
codec_list_update_to_daemon();
} }
/** /**
......
Supports Markdown
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