break out tooltip creation into separate function
This commit is contained in:
parent
855b0deae8
commit
5539346c53
252
src/bin/empc.c
252
src/bin/empc.c
|
@ -400,6 +400,134 @@ ctxpopup_mouse_position(Evas_Object *ctx)
|
|||
evas_object_move(ctxpopup, px, py);
|
||||
}
|
||||
|
||||
static Evas_Object *
|
||||
tooltip_create(Evas_Object *tooltip, Elm_Object_Item *item)
|
||||
{
|
||||
Elm_Object_Item *it;
|
||||
Evas_Object *o, *copy, *ly;
|
||||
const Eina_File *f;
|
||||
Eina_Stringshare *file, *key;
|
||||
Empd_Empdd_Song *so, *soi;
|
||||
char buf[1024];
|
||||
const char *infos;
|
||||
Eina_Bool playing;
|
||||
|
||||
it = elm_genlist_item_parent_get(item);
|
||||
if (!it) it = item;
|
||||
so = elm_object_item_data_get(it);
|
||||
soi = elm_object_item_data_get(item);
|
||||
|
||||
o = elm_object_item_part_content_get(it, EMPC_SWALLOW_ALBUM);
|
||||
if (o)
|
||||
{
|
||||
if (!strcmp(evas_object_type_get(o), "Evas_Object_Box"))
|
||||
o = eina_list_data_get(evas_object_box_children_get(o));
|
||||
if (o)
|
||||
o = evas_object_data_get(o, "__empc_image");
|
||||
}
|
||||
ly = elm_layout_add(tooltip);
|
||||
elm_layout_theme_set(ly, "layout", "empc", "tooltip");
|
||||
|
||||
if (o)
|
||||
{
|
||||
int w, h;
|
||||
|
||||
evas_object_image_mmap_get(o, &f, &key);
|
||||
if (!f)
|
||||
evas_object_image_file_get(o, &file, &key);
|
||||
copy = elm_image_add(tooltip);
|
||||
if (f)
|
||||
elm_image_mmap_set(copy, f, key);
|
||||
else
|
||||
elm_image_file_set(copy, file, key);
|
||||
elm_image_fill_outside_set(copy, EINA_FALSE);
|
||||
elm_image_smooth_set(copy, EINA_FALSE);
|
||||
elm_image_object_size_get(copy, &w, &h);
|
||||
evas_object_size_hint_max_set(copy, w, h);
|
||||
if (w > 256)
|
||||
{
|
||||
h = 256 * h / w;
|
||||
w = 256;
|
||||
}
|
||||
else if (h > 256)
|
||||
{
|
||||
w = 256 * w / h;
|
||||
h = 256;
|
||||
}
|
||||
evas_object_size_hint_min_set(copy, w, h);
|
||||
elm_object_part_content_set(ly, "empc.swallow.icon", copy);
|
||||
}
|
||||
playing = (empd_song_item && (elm_genlist_item_parent_get(empd_song_item) == it));
|
||||
infos = elm_layout_data_get(ly, "empc.infos");
|
||||
if (infos && infos[0])
|
||||
{
|
||||
unsigned int num, i;
|
||||
char **str;
|
||||
|
||||
str = eina_str_split_full(infos, " ", 0, &num);
|
||||
for (i = 0; i < num; i++)
|
||||
{
|
||||
char *itemname = str[i];
|
||||
Evas_Object *name, *value;
|
||||
|
||||
name = elm_label_add(tooltip);
|
||||
elm_object_style_set(name, "tooltip_info");
|
||||
value = elm_label_add(tooltip);
|
||||
elm_object_style_set(value, "tooltip_info_value");
|
||||
if (eina_streq(itemname, "artist"))
|
||||
{
|
||||
elm_object_text_set(name, "Artist:");
|
||||
elm_object_text_set(value, so->artist);
|
||||
}
|
||||
else if (eina_streq(itemname, "album"))
|
||||
{
|
||||
elm_object_text_set(name, "Album:");
|
||||
elm_object_text_set(value, so->album);
|
||||
}
|
||||
else if (eina_streq(itemname, "time"))
|
||||
{
|
||||
elm_object_text_set(name, "Time:");
|
||||
elm_object_text_set(value, elm_object_item_part_text_get(it, EMPC_TEXT_TIME));
|
||||
}
|
||||
else if (eina_streq(itemname, "track"))
|
||||
{
|
||||
if (it == item) //header
|
||||
{
|
||||
elm_layout_signal_emit(ly, "empc,state,header", "empc");
|
||||
elm_object_text_set(name, "Tracks:");
|
||||
snprintf(buf, sizeof(buf), "%u", elm_genlist_item_subitems_count(it));
|
||||
}
|
||||
else
|
||||
{
|
||||
elm_object_text_set(name, "Track:");
|
||||
snprintf(buf, sizeof(buf), "%d/%u", soi->track, elm_genlist_item_subitems_count(it));
|
||||
}
|
||||
elm_object_text_set(value, buf);
|
||||
}
|
||||
else if (eina_streq(itemname, "index"))
|
||||
{
|
||||
elm_object_text_set(name, "Index:");
|
||||
snprintf(buf, sizeof(buf), "%d", soi->song_pos);
|
||||
elm_object_text_set(value, buf);
|
||||
}
|
||||
if (playing)
|
||||
elm_layout_signal_emit(value, "empc,state,playing", "empc");
|
||||
evas_object_show(name);
|
||||
evas_object_show(value);
|
||||
elm_layout_table_pack(ly, "empc.table", name, 0, i, 1, 1);
|
||||
elm_layout_table_pack(ly, "empc.table", value, 1, i, 1, 1);
|
||||
}
|
||||
if (num)
|
||||
free(str[0]);
|
||||
free(str);
|
||||
}
|
||||
|
||||
if (playing)
|
||||
elm_layout_signal_emit(ly, "empc,state,playing", "empc");
|
||||
|
||||
return ly;
|
||||
}
|
||||
|
||||
static void
|
||||
save_image(Eina_Bool force, Evas_Object *img, const char *uri, const char *artist, const char *album, Empc_Module_Metadata_Save_Post_Cb post_cb)
|
||||
{
|
||||
|
@ -1817,129 +1945,7 @@ empc_status(void *d EINA_UNUSED, int t EINA_UNUSED, Empd_Empdd_Status_Data *ev)
|
|||
static Evas_Object *
|
||||
queue_list_item_tooltip_cb(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, Evas_Object *tooltip, void *item)
|
||||
{
|
||||
Elm_Object_Item *it;
|
||||
Evas_Object *o, *copy, *ly;
|
||||
const Eina_File *f;
|
||||
Eina_Stringshare *file, *key;
|
||||
Empd_Empdd_Song *so, *soi;
|
||||
char buf[1024];
|
||||
const char *infos;
|
||||
Eina_Bool playing;
|
||||
|
||||
it = elm_genlist_item_parent_get(item);
|
||||
if (!it) it = item;
|
||||
so = elm_object_item_data_get(it);
|
||||
soi = elm_object_item_data_get(item);
|
||||
|
||||
o = elm_object_item_part_content_get(it, EMPC_SWALLOW_ALBUM);
|
||||
if (o)
|
||||
{
|
||||
if (!strcmp(evas_object_type_get(o), "Evas_Object_Box"))
|
||||
o = eina_list_data_get(evas_object_box_children_get(o));
|
||||
if (o)
|
||||
o = evas_object_data_get(o, "__empc_image");
|
||||
}
|
||||
ly = elm_layout_add(tooltip);
|
||||
elm_layout_theme_set(ly, "layout", "empc", "tooltip");
|
||||
|
||||
if (o)
|
||||
{
|
||||
int w, h;
|
||||
|
||||
evas_object_image_mmap_get(o, &f, &key);
|
||||
if (!f)
|
||||
evas_object_image_file_get(o, &file, &key);
|
||||
copy = elm_image_add(tooltip);
|
||||
if (f)
|
||||
elm_image_mmap_set(copy, f, key);
|
||||
else
|
||||
elm_image_file_set(copy, file, key);
|
||||
elm_image_fill_outside_set(copy, EINA_FALSE);
|
||||
elm_image_smooth_set(copy, EINA_FALSE);
|
||||
elm_image_object_size_get(copy, &w, &h);
|
||||
evas_object_size_hint_max_set(copy, w, h);
|
||||
if (w > 256)
|
||||
{
|
||||
h = 256 * h / w;
|
||||
w = 256;
|
||||
}
|
||||
else if (h > 256)
|
||||
{
|
||||
w = 256 * w / h;
|
||||
h = 256;
|
||||
}
|
||||
evas_object_size_hint_min_set(copy, w, h);
|
||||
elm_object_part_content_set(ly, "empc.swallow.icon", copy);
|
||||
}
|
||||
playing = (empd_song_item && (elm_genlist_item_parent_get(empd_song_item) == it));
|
||||
infos = elm_layout_data_get(ly, "empc.infos");
|
||||
if (infos && infos[0])
|
||||
{
|
||||
unsigned int num, i;
|
||||
char **str;
|
||||
|
||||
str = eina_str_split_full(infos, " ", 0, &num);
|
||||
for (i = 0; i < num; i++)
|
||||
{
|
||||
char *itemname = str[i];
|
||||
Evas_Object *name, *value;
|
||||
|
||||
name = elm_label_add(tooltip);
|
||||
elm_object_style_set(name, "tooltip_info");
|
||||
value = elm_label_add(tooltip);
|
||||
elm_object_style_set(value, "tooltip_info_value");
|
||||
if (eina_streq(itemname, "artist"))
|
||||
{
|
||||
elm_object_text_set(name, "Artist:");
|
||||
elm_object_text_set(value, so->artist);
|
||||
}
|
||||
else if (eina_streq(itemname, "album"))
|
||||
{
|
||||
elm_object_text_set(name, "Album:");
|
||||
elm_object_text_set(value, so->album);
|
||||
}
|
||||
else if (eina_streq(itemname, "time"))
|
||||
{
|
||||
elm_object_text_set(name, "Time:");
|
||||
elm_object_text_set(value, elm_object_item_part_text_get(it, EMPC_TEXT_TIME));
|
||||
}
|
||||
else if (eina_streq(itemname, "track"))
|
||||
{
|
||||
if (it == item) //header
|
||||
{
|
||||
elm_layout_signal_emit(ly, "empc,state,header", "empc");
|
||||
elm_object_text_set(name, "Tracks:");
|
||||
snprintf(buf, sizeof(buf), "%u", elm_genlist_item_subitems_count(it));
|
||||
}
|
||||
else
|
||||
{
|
||||
elm_object_text_set(name, "Track:");
|
||||
snprintf(buf, sizeof(buf), "%d/%u", soi->track, elm_genlist_item_subitems_count(it));
|
||||
}
|
||||
elm_object_text_set(value, buf);
|
||||
}
|
||||
else if (eina_streq(itemname, "index"))
|
||||
{
|
||||
elm_object_text_set(name, "Index:");
|
||||
snprintf(buf, sizeof(buf), "%d", soi->song_pos);
|
||||
elm_object_text_set(value, buf);
|
||||
}
|
||||
if (playing)
|
||||
elm_layout_signal_emit(value, "empc,state,playing", "empc");
|
||||
evas_object_show(name);
|
||||
evas_object_show(value);
|
||||
elm_layout_table_pack(ly, "empc.table", name, 0, i, 1, 1);
|
||||
elm_layout_table_pack(ly, "empc.table", value, 1, i, 1, 1);
|
||||
}
|
||||
if (num)
|
||||
free(str[0]);
|
||||
free(str);
|
||||
}
|
||||
|
||||
if (playing)
|
||||
elm_layout_signal_emit(ly, "empc,state,playing", "empc");
|
||||
|
||||
return ly;
|
||||
return tooltip_create(tooltip, item);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
Loading…
Reference in New Issue