Skip to content

Commit

Permalink
prop: Add a property grouper than can group child property tree based…
Browse files Browse the repository at this point in the history
… on a node path

glw: Add $clone.* property namespace that is local to each clone
glw: Add propGrouper() and propSorter() GLW methods
service: Remove the fixed set of service type and sorting, grouping, etc of service from service core
glw: Let home.view group and sort services by itself
  • Loading branch information
andoma committed Dec 11, 2010
1 parent 44eb7ad commit 7143b89
Show file tree
Hide file tree
Showing 27 changed files with 728 additions and 289 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ SRCS += src/main.c \
src/prop/prop_nodefilter.c \
src/prop/prop_tags.c \
src/prop/prop_vector.c \
src/prop/prop_grouper.c \

ifeq ($(PLATFORM), linux)
SRCS += src/arch/linux.c
Expand Down
63 changes: 21 additions & 42 deletions glwthemes/mono/pages/home.view
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@ $page.glw.title = "Home";

#define COL() {[0.45, 0.45, 0.5]}

#define SERVICE_TYPE_LISTER(TITLE, NODES, HIDDEN, ICON, COLOR, P1) {
#define SERVICE_TYPE_LISTER(TITLE, NODES, ICON, COLOR) {
widget(container_y, {
.align = center;
(P1) = isFocused();
$clone.focus = isFocused();
.width = $ui.fontsize * 10;
.hidden = HIDDEN;
widget(image, {
.color = select(P1, [1.0, 1.0, 1.0], COLOR);
.color = select($clone.focus, [1.0, 1.0, 1.0], COLOR);
.shadow = true;
.source = ICON;
.height = $ui.fontsize * 4;
Expand All @@ -22,7 +21,7 @@ $page.glw.title = "Home";

widget(list_y, {
.height = 128;
cloner(NODES, backdrop, {
cloner(propSorter(NODES, "node.title"), backdrop, {

PLATE_GFX();

Expand All @@ -41,16 +40,6 @@ $page.glw.title = "Home";
.caption = $self.title;
.color = select(isFocused(), [1.0, 1.0, 1.0], COLOR);
});
/*
widget(icon, {
.align = right;
.shadow = true;
.source = $self.icon;
.sizeBias = -4;
.hqScaling = true;
.alpha = select(isFocused(), 1.0, 0.2);
});
*/
});
});
});
Expand Down Expand Up @@ -108,33 +97,23 @@ widget(container_y, {

widget(container_x, {
.align = center;

SERVICE_TYPE_LISTER("Music", $global.services.music.nodes,
!count($global.services.music.nodes),
"theme:https://icons/mediasources/music.png",
PLATE_COLOR_AUDIO(), $view.musicFocused);


SERVICE_TYPE_LISTER("Video", $global.services.video.nodes,
!count($global.services.video.nodes),
"theme:https://icons/mediasources/movies.png",
PLATE_COLOR_VIDEO(), $view.videoFocused);

SERVICE_TYPE_LISTER("TV", $global.services.tv.nodes,
!count($global.services.tv.nodes),
"theme:https://icons/mediasources/tv.png",
PLATE_COLOR_TV(), $view.tvFocused);

SERVICE_TYPE_LISTER("Photos", $global.services.image.nodes,
!count($global.services.image.nodes),
"theme:https://icons/mediasources/pictures.png",
PLATE_COLOR_IMAGE(), $view.photosFocused);

SERVICE_TYPE_LISTER("Other", $global.services.other.nodes,
!count($global.services.other.nodes),
"theme:https://icons/mediasources/other.png",
PLATE_COLOR_OTHER(), $view.otherFocused);
});
cloner(propSorter(propGrouper($global.sources, "node.type"), "node.name"),
container_z, {
SERVICE_TYPE_LISTER($self.name, $self.nodes,
"theme:https://icons/mediasources/" +
translate($self.name, "other.png",
"music", "music.png",
"video", "movies.png",
"tv", "tv.png",
"photos", "pictures.png"),

translate($self.name, PLATE_COLOR_OTHER(),
"music", PLATE_COLOR_AUDIO(),
"video", PLATE_COLOR_VIDEO(),
"tv", PLATE_COLOR_TV(),
"photos", PLATE_COLOR_IMAGE()));
});
});

HORIZONTAL_SEPARATOR();

Expand Down
4 changes: 2 additions & 2 deletions src/backend/dvd/linux_dvd.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,14 @@ set_status(disc_scanner_t *ds, disc_status_t status, const char *title)
case DISC_AUDIO:
snprintf(buf, sizeof(buf), "Audio CD");
snprintf(url, sizeof(url), "audiocd:%s", ds->ds_dev);
ds->ds_svc = service_create(buf, url, SVC_TYPE_MUSIC, NULL, 0);
ds->ds_svc = service_create(buf, url, "music", NULL, 0);
break;

case DISC_ISOFS:
snprintf(buf, sizeof(buf), "DVD: %s", title);
snprintf(url, sizeof(url), "dvd:%s", ds->ds_dev);

ds->ds_svc = service_create(buf, url, SVC_TYPE_VIDEO, NULL, 0);
ds->ds_svc = service_create(buf, url, "video", NULL, 0);
break;

case DISC_UNKNOWN_TYPE:
Expand Down
4 changes: 2 additions & 2 deletions src/backend/htsp/htsp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1120,7 +1120,7 @@ make_model(prop_t *parent, const char *title, prop_t *nodes)
pnf = prop_nf_create(prop_create(model, "nodes"),
nodes,
prop_create(model, "filter"),
NULL);
NULL, PROP_NF_AUTODESTROY);
prop_set_int(prop_create(model, "canFilter"), 1);

prop_nf_release(pnf);
Expand All @@ -1145,7 +1145,7 @@ make_model2(prop_t *parent, prop_t *sourcemodel)
pnf = prop_nf_create(prop_create(model, "nodes"),
prop_create(sourcemodel, "nodes"),
prop_create(model, "filter"),
NULL);
NULL, PROP_NF_AUTODESTROY);
prop_set_int(prop_create(model, "canFilter"), 1);

prop_nf_release(pnf);
Expand Down
3 changes: 2 additions & 1 deletion src/backend/search.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ search_open(prop_t *page, const char *url0)

pnf = prop_nf_create(prop_create(model, "nodes"),
prop_create(source, "nodes"),
NULL, "node.metadata.title");
NULL, "node.metadata.title",
PROP_NF_AUTODESTROY);

prop_nf_pred_int_add(pnf, "node.entries",
PROP_NF_CMP_EQ, 0, NULL,
Expand Down
12 changes: 3 additions & 9 deletions src/bookmarks.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,7 @@ static void
set_type(void *opaque, const char *str)
{
bookmark_t *bm = opaque;
service_type_t type = service_str2type(str);
if(type == -1)
type = SVC_TYPE_OTHER;
service_set_type(bm->bm_service, type);
service_set_type(bm->bm_service, str);
bookmark_save();
}

Expand All @@ -150,20 +147,17 @@ bookmark_add_prop(prop_t *parent, const char *name, const char *value,
*
*/
static void
bookmark_add(const char *title, const char *url, const char *svctype)
bookmark_add(const char *title, const char *url, const char *type)
{
bookmark_t *bm = calloc(1, sizeof(bookmark_t));
prop_t *p = prop_create(NULL, NULL);
prop_t *src = prop_create(p, "model");
service_type_t type = service_str2type(svctype);
if(type == -1)
type = SVC_TYPE_OTHER;

prop_set_string(prop_create(src, "type"), "bookmark");

bm->bm_title_sub = bookmark_add_prop(src, "title", title, bm, set_title);
bm->bm_url_sub = bookmark_add_prop(src, "url", url, bm, set_url);
bm->bm_type_sub = bookmark_add_prop(src, "svctype", svctype, bm, set_type);
bm->bm_type_sub = bookmark_add_prop(src, "svctype", type, bm, set_type);

bm->bm_service = service_create(title, url, type, NULL, 1);

Expand Down
2 changes: 1 addition & 1 deletion src/fileaccess/fa_scanner.c
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,7 @@ fa_scanner(const char *url, prop_t *model, const char *playme)
prop_nf_release(prop_nf_create(prop_create(model, "nodes"),
source,
prop_create(model, "filter"),
"node.filename"));
"node.filename", PROP_NF_AUTODESTROY));

prop_set_int(prop_create(model, "canFilter"), 1);

Expand Down
2 changes: 1 addition & 1 deletion src/js/js_page.c
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ init_model_props(js_model_t *jm, prop_t *model)
pnf = prop_nf_create(prop_create(model, "nodes"),
jm->jm_nodes,
prop_create(model, "filter"),
NULL);
NULL, PROP_NF_AUTODESTROY);

prop_set_int(prop_create(model, "canFilter"), 1);

Expand Down
2 changes: 1 addition & 1 deletion src/js/js_service.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ js_createService(JSContext *cx, JSObject *obj, uintN argc,
&title, &url, &type, &icon))
return JS_FALSE;

s = service_create(title, url, service_str2type(type), icon, 0);
s = service_create(title, url, type, icon, 0);
robj = JS_NewObjectWithGivenProto(cx, &service_class, NULL, NULL);
JS_SetPrivate(cx, robj, s);
*rval = OBJECT_TO_JSVAL(robj);
Expand Down
7 changes: 5 additions & 2 deletions src/prop/prop.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ void prop_init(void);
#define PROP_SUB_EXPEDITE 0x20
#define PROP_SUB_MULTI 0x40
#define PROP_SUB_INTERNAL 0x80
#define PROP_SUB_NOLOCK 0x100
#define PROP_SUB_DONTLOCK 0x100

enum {
PROP_TAG_END = 0,
Expand Down Expand Up @@ -362,11 +362,14 @@ void prop_tag_set(prop_t *p, void *key, void *value);

void *prop_tag_clear(prop_t *p, void *key);

/* DEBUGish */
const char *propname(prop_t *p);

void prop_print_tree(prop_t *p, int followlinks);

void prop_test(void);

#ifdef PROP_DEBUG
extern int prop_trace;
#endif

#endif /* PROP_H__ */
72 changes: 46 additions & 26 deletions src/prop/prop_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
#include "misc/string.h"
#include "event.h"

#ifdef PROP_DEBUG
int prop_trace;
#endif

hts_mutex_t prop_mutex;
hts_mutex_t prop_tag_mutex;
static prop_t *prop_global;
Expand Down Expand Up @@ -972,7 +976,6 @@ prop_build_notify_child(prop_sub_t *s, prop_t *p, prop_event_t event,
if(direct || s->hps_flags & PROP_SUB_INTERNAL) {
prop_callback_t *cb = s->hps_callback;
prop_trampoline_t *pt = s->hps_trampoline;

if(pt != NULL)
pt(s, event, p, flags);
else
Expand Down Expand Up @@ -1463,6 +1466,20 @@ prop_destroy0(prop_t *p)
prop_t *c, *next, *parent;
prop_sub_t *s;

#ifdef PROP_DEBUG
if(prop_trace) {
int csubs = 0, psubs = 0;
LIST_FOREACH(s, &p->hp_canonical_subscriptions, hps_canonical_prop_link)
csubs++;
LIST_FOREACH(s, &p->hp_value_subscriptions, hps_value_prop_link)
psubs++;

printf("Entering prop_destroy0(%s) [type=%d, refcnt=%d, xref=%d, csubs=%d, psubs=%d]\n",
propname(p), p->hp_type, p->hp_refcount, p->hp_xref,
csubs, psubs);
}
#endif

if(p->hp_type == PROP_ZOMBIE)
return 0;

Expand Down Expand Up @@ -1524,6 +1541,12 @@ prop_destroy0(prop_t *p)
if(p->hp_originator != NULL)
prop_remove_from_originator(p);

#ifdef PROP_DEBUG
if(prop_trace)
printf("Leaving prop_destroy0(%s) parent=%p\n", propname(p),
p->hp_parent);
#endif

if(p->hp_parent != NULL) {
prop_notify_child(p, p->hp_parent, PROP_DEL_CHILD, NULL, 0);
parent = p->hp_parent;
Expand Down Expand Up @@ -1857,7 +1880,7 @@ prop_subscribe(int flags, ...)
struct prop_root_list proproots;
void *cb = NULL;
prop_trampoline_t *trampoline = NULL;
int dolock = !(flags & PROP_SUB_NOLOCK);
int dolock = !(flags & PROP_SUB_DONTLOCK);

va_list ap;
va_start(ap, flags);
Expand Down Expand Up @@ -2155,38 +2178,19 @@ prop_set_epilogue(prop_sub_t *skipme, prop_t *p, const char *origin)
}



/**
*
*/
void
prop_set_string_ex(prop_t *p, prop_sub_t *skipme, const char *str,
prop_str_type_t type)
prop_set_string_exl(prop_t *p, prop_sub_t *skipme, const char *str,
prop_str_type_t type)
{
if(p == NULL)
return;

if(str == NULL) {
prop_set_void_ex(p, skipme);
return;
}

hts_mutex_lock(&prop_mutex);

if(p->hp_type == PROP_ZOMBIE) {
hts_mutex_unlock(&prop_mutex);
if(p->hp_type == PROP_ZOMBIE)
return;
}

if(p->hp_type != PROP_STRING) {

if(prop_clean(p)) {
hts_mutex_unlock(&prop_mutex);
if(prop_clean(p))
return;
}

} else if(!strcmp(rstr_get(p->hp_rstring), str)) {
hts_mutex_unlock(&prop_mutex);
return;
} else {
rstr_release(p->hp_rstring);
Expand All @@ -2196,8 +2200,24 @@ prop_set_string_ex(prop_t *p, prop_sub_t *skipme, const char *str,
p->hp_type = PROP_STRING;

p->hp_rstrtype = type;
prop_notify_value(p, skipme, "prop_set_string()");
}

prop_set_epilogue(skipme, p, "prop_set_string()");
/**
*
*/
void
prop_set_string_ex(prop_t *p, prop_sub_t *skipme, const char *str,
prop_str_type_t type)
{
if(str == NULL) {
prop_set_void_ex(p, skipme);
return;
}

hts_mutex_lock(&prop_mutex);
prop_set_string_exl(p, skipme, str, type);
hts_mutex_unlock(&prop_mutex);
}


Expand Down
Loading

0 comments on commit 7143b89

Please sign in to comment.