summaryrefslogblamecommitdiff
path: root/src/bin/playbacks_view.c
blob: 43b818abd01a24f3bc3ccf20efa127c24328f7b3 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12

                           
                 


                                     





                               

  

                         

                                    
                                  

 

                                         

                                    



                                                             

 

                                           

                                    

                                                                   
 
            
      


                                                      



                                            

                                                         
      

 

                                           

                                    



                                                                   
               













                                                                

 

                       

                                    
                                                  

 

                                                              
 




















                                               


           
                                                                                

                                     
                                       




                                                                          
                                 

                             
                                




               


                                                
                                 
                                        

                      
 



                                                                     
 

                                             





                                                        
                                 
 
                                                




                                                              
                                 
                                      
                                                    
 
                                            






                                                                 
                                 


                               


                                                   
                                                        



                                                       
                                                             









                                                                  

                                                                        







                                                                         
                                                              



                                                   
                                                     



                                   
                        

                                     
                                                                 
           
                                     




                                                              
                                                              









                                       

                          



                                                 
                                                              






                                                                          
                                           





                                                  








                                                                  





                                                                   


                 




                
#include "playbacks_view.h"

#include <emix.h>

#define PLAYBACKS_KEY "playbacks.key"


struct Playbacks_View
{
   Evas_Object *self;
   Evas_Object *genlist;
   Elm_Genlist_Item_Class *itc;
};

 static void
_disconnected(void *data)
{
   struct Playbacks_View *pv = data;
   elm_genlist_clear(pv->genlist);
}

static void
_sink_input_added(void *data, void *info)
{
   struct Playbacks_View *pv = data;
   Emix_Sink_Input *input = info;

   elm_genlist_item_append(pv->genlist, pv->itc, input, NULL,
                           ELM_GENLIST_ITEM_NONE, NULL, pv);
}

static void
_sink_input_removed(void *data, void *info)
{
   struct Playbacks_View *pv = data;
   Emix_Sink_Input *ev = info;
   Elm_Object_Item *item = elm_genlist_first_item_get(pv->genlist);

   if (item)
     {
        do
          {
             if (ev == elm_object_item_data_get(item))
               {
                  elm_object_item_del(item);
                  break;
               }
          }
        while ((item = elm_genlist_item_next_get(item)));
     }
}

static void
_sink_input_changed(void *data, void *info)
{
   struct Playbacks_View *pv = data;
   Emix_Sink_Input *ev = info;
   Elm_Object_Item *item = elm_genlist_first_item_get(pv->genlist);
   Evas_Object *it;

   while (item)
    {
       if (ev == elm_object_item_data_get(item))
         {
            it = elm_object_item_part_content_get(item, "item");
            if (it)
               elm_slider_value_set(it, ev->volume.volumes[0]);

            it = elm_object_item_part_content_get(item, "mute");
            if (it)
                 elm_check_state_set(it, ev->mute);
            break;
         }
       item = elm_genlist_item_next_get(item);
    }
}

static void
_sink_event(void *data)
{
   struct Playbacks_View *pv = data;
   elm_genlist_realized_items_update(pv->genlist);
}

static void
_events_cb(void *data, enum Emix_Event type, void *event_info)
{
   switch (type)
     {
      case EMIX_SINK_ADDED_EVENT:
      case EMIX_SINK_REMOVED_EVENT:
         _sink_event(data);
         break;
      case EMIX_DISCONNECTED_EVENT:
         _disconnected(data);
         break;
      case EMIX_SINK_INPUT_ADDED_EVENT:
         _sink_input_added(data, event_info);
         break;
      case EMIX_SINK_INPUT_CHANGED_EVENT:
         _sink_input_changed(data, event_info);
         break;
      case EMIX_SINK_INPUT_REMOVED_EVENT:
         _sink_input_removed(data, event_info);
         break;
      default:
         break;
     }
}

static void
_del_cb(void *data EINA_UNUSED, Evas *e EINA_UNUSED, Evas_Object *o EINA_UNUSED,
        void *event_info EINA_UNUSED)
{
   emix_event_callback_del(_events_cb);
}

static char *
_item_text_get(void *data, Evas_Object *obj EINA_UNUSED, const char *part)
{
   Emix_Sink_Input *input = data;

   if (!strcmp(part, "name"))
     return strdup(input->name);

   return NULL;
}

static void
_volume_changed_cb(void *data, Evas_Object *o,
                   void *event_info EINA_UNUSED)
{
   Emix_Sink_Input *input = data;
   double val = elm_slider_value_get(o);
   Emix_Volume volume;
   unsigned int i;

   volume.channel_count = input->volume.channel_count;
   volume.volumes = calloc(input->volume.channel_count, sizeof(int));
   for (i = 0; i < volume.channel_count; i++)
      volume.volumes[i] = val;

   emix_sink_input_volume_set(input, volume);
   free(volume.volumes);
}

static void
_mute_changed_cb(void *data, Evas_Object *o EINA_UNUSED,
                 void *event_info EINA_UNUSED)
{
   Emix_Sink_Input *input = data;

   emix_sink_input_mute_set(input, input->mute);
}

static void
_sink_selected(void *data, Evas_Object *obj, void *event_info)
{
   Emix_Sink_Input *input = data;
   Elm_Object_Item *item = event_info;
   Emix_Sink *sink = elm_object_item_data_get(item);

   emix_sink_input_sink_change(input, sink);
   elm_object_text_set(obj, sink->name);
}

static Evas_Object *
_item_content_get(void *data, Evas_Object *obj, const char *part)
{
   Evas_Object *item = NULL;
   Emix_Sink_Input *input = data;

   if (!strcmp(part, "slider"))
     {
        item = elm_slider_add(obj);
        EINA_SAFETY_ON_NULL_RETURN_VAL(item, NULL);

        elm_slider_step_set(item, 1.0/BASE_VOLUME_STEP);
        elm_slider_unit_format_set(item, "%1.0f");
        elm_slider_indicator_format_set(item, "%1.0f");
        elm_slider_span_size_set(item, 120);
        elm_slider_min_max_set(item, 0.0, 100.0);
        elm_slider_value_set(item, input->volume.volumes[0]);

        evas_object_smart_callback_add(item, "delay,changed",
                                       _volume_changed_cb, input);
     }
   else if (!strcmp(part, "mute"))
     {
        item = elm_check_add(obj);
        EINA_SAFETY_ON_NULL_RETURN_VAL(item, NULL);

        elm_object_style_set(item, "toggle");
        elm_object_translatable_part_text_set(item, "off", N_("Mute"));
        elm_object_translatable_part_text_set(item, "on", N_("Unmute"));

        elm_check_state_set(item, input->mute);
        elm_check_state_pointer_set(item, &input->mute);
        evas_object_smart_callback_add(item, "changed", _mute_changed_cb,
                                       input);
     }
   else if (!strcmp(part, "icon"))
     {
        /*EINA_SAFETY_ON_NULL_RETURN_VAL(input->icon, NULL);*/

        item = elm_icon_add(obj);
        EINA_SAFETY_ON_NULL_RETURN_VAL(item, NULL);

        /*elm_icon_standard_set(item, input->icon);*/
     }
   else if (!strcmp(part, "hover"))
     {
        Eina_List *l;
        Emix_Sink *sink;
        item = elm_hoversel_add(obj);

        EINA_LIST_FOREACH((Eina_List *)emix_sinks_get(), l, sink)
          {
             if (sink == input->sink)
                elm_object_text_set(item, sink->name);
             elm_hoversel_item_add(item, sink->name, NULL,
                                   ELM_ICON_NONE, NULL, sink);
          }
        evas_object_smart_callback_add(item, "selected",
                                       _sink_selected, input);
     }

   return item;
}

Evas_Object *
playbacks_view_add(Evas_Object *parent)
{
   Evas_Object *layout;
   struct Playbacks_View *pv;
   Emix_Sink_Input *input;
   Eina_List *l;

   pv = calloc(1, sizeof(struct Playbacks_View));
   EINA_SAFETY_ON_NULL_RETURN_VAL(pv, NULL);

   layout = emixer_layout_add(parent, "playbacks", "default");
   EINA_SAFETY_ON_NULL_GOTO(layout, err);

   evas_object_event_callback_add(layout, EVAS_CALLBACK_DEL, _del_cb, pv);

   pv->genlist = elm_genlist_add(layout);
   EINA_SAFETY_ON_NULL_GOTO(pv->genlist, err_genlist);

   emix_event_callback_add(_events_cb, pv);

   pv->itc = elm_genlist_item_class_new();
   EINA_SAFETY_ON_NULL_GOTO(pv->itc, err_genlist);
   pv->itc->item_style = "playbacks";
   pv->itc->func.text_get = _item_text_get;
   pv->itc->func.content_get = _item_content_get;

   evas_object_data_set(layout, PLAYBACKS_KEY, pv);
   elm_layout_content_set(layout, "list", pv->genlist);

   evas_object_size_hint_weight_set(pv->genlist, EVAS_HINT_EXPAND,
                                    EVAS_HINT_EXPAND);
   evas_object_size_hint_align_set(pv->genlist, EVAS_HINT_FILL,
                                   EVAS_HINT_FILL);

   EINA_LIST_FOREACH((Eina_List *)emix_sink_inputs_get(), l, input)
     {
        elm_genlist_item_append(pv->genlist, pv->itc, input, NULL,
                                ELM_GENLIST_ITEM_NONE, NULL, pv);
     }

   return layout;

 err_genlist:
   free(layout);
 err:
   free(pv);
   return NULL;
}