Permalink
Browse files

Sort images based on original timestamp instead of title

  • Loading branch information...
1 parent dc578a1 commit 5a9338aeb0867b6d90ccf116bf2e4bc84f8122b1 @andoma committed with Andreas Öman May 15, 2012
View
@@ -1174,7 +1174,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, PROP_NF_AUTODESTROY);
+ PROP_NF_AUTODESTROY);
prop_set_int(prop_create(model, "canFilter"), 1);
prop_nf_release(pnf);
@@ -1199,7 +1199,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, PROP_NF_AUTODESTROY);
+ PROP_NF_AUTODESTROY);
prop_set_int(prop_create(model, "canFilter"), 1);
prop_nf_release(pnf);
View
@@ -124,8 +124,9 @@ search_open(prop_t *page, const char *url0)
pnf = prop_nf_create(prop_create(model, "nodes"),
prop_create(source, "nodes"),
- NULL, "node.metadata.title",
- PROP_NF_AUTODESTROY);
+ NULL, PROP_NF_AUTODESTROY);
+
+ prop_nf_sort(pnf, "node.metadata.title", 0);
prop_nf_pred_int_add(pnf, "node.entries",
PROP_NF_CMP_EQ, 0, NULL,
@@ -1341,7 +1341,7 @@ bh_create(spotify_page_t *sp, const char *playme)
prop_set_string(sp->sp_type, "directory");
bh->sp = sp;
- pnf = prop_nf_create(sp->sp_nodes, sp->sp_items, sp->sp_filter, NULL,
+ pnf = prop_nf_create(sp->sp_nodes, sp->sp_items, sp->sp_filter,
PROP_NF_AUTODESTROY);
prop_set_int(sp->sp_canFilter, 1);
prop_nf_release(pnf);
@@ -1582,7 +1582,7 @@ spotify_open_rootlist(spotify_page_t *sp, int flat)
pnf = prop_nf_create(sp->sp_nodes,
flat ? current_user_rootlist->plc_root_flat :
current_user_rootlist->plc_root_tree,
- sp->sp_filter, NULL, PROP_NF_AUTODESTROY);
+ sp->sp_filter, PROP_NF_AUTODESTROY);
prop_set_int(sp->sp_canFilter, 1);
prop_nf_release(pnf);
}
@@ -2911,8 +2911,10 @@ pl_create(sp_playlist *plist, const char *name,
struct prop_nf *pnf;
pnf = prop_nf_create(nodes, pl->pl_prop_tracks, filter,
- pl->pl_flags & PL_SORT_ON_TIME ? "node.metadata.timestamp" : NULL,
- PROP_NF_AUTODESTROY | PROP_NF_SORT_DESC);
+ PROP_NF_AUTODESTROY);
+
+ if(pl->pl_flags & PL_SORT_ON_TIME)
+ prop_nf_sort(pnf, "node.metadata.timestamp", 1);
prop_nf_pred_int_add(pnf, "node.metadata.available",
PROP_NF_CMP_EQ, 0, NULL,
@@ -3480,7 +3482,7 @@ plc_for_user(sp_session *sess, spotify_page_t *sp, const char *username)
prop_link(_p("Spotify playlists"), sp->sp_title);
pnf = prop_nf_create(sp->sp_nodes, sp->sp_items,
- sp->sp_filter, NULL, PROP_NF_AUTODESTROY);
+ sp->sp_filter, PROP_NF_AUTODESTROY);
prop_set_int(sp->sp_canFilter, 1);
prop_nf_release(pnf);
}
@@ -599,8 +599,10 @@ fa_scanner(const char *url, time_t url_mtime,
pnf = prop_nf_create(prop_create(model, "nodes"),
source,
prop_create(model, "filter"),
- "node.metadata.title", PROP_NF_AUTODESTROY);
+ PROP_NF_AUTODESTROY);
+ prop_nf_sort(pnf, "node.metadata.title", 0);
+
prop_nf_pred_str_add(pnf, "node.type",
PROP_NF_CMP_EQ, "unknown", NULL,
PROP_NF_MODE_EXCLUDE);
@@ -609,11 +611,9 @@ fa_scanner(const char *url, time_t url_mtime,
PROP_NF_CMP_EQ, 1, NULL,
PROP_NF_MODE_EXCLUDE);
- prop_nf_release(pnf);
-
prop_set_int(prop_create(model, "canFilter"), 1);
- decorated_browse_create(model);
+ decorated_browse_create(model, pnf);
s->s_url = strdup(url);
s->s_mtime = url_mtime;
View
@@ -551,7 +551,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, PROP_NF_AUTODESTROY);
+ PROP_NF_AUTODESTROY);
prop_set_int(prop_create(model, "canFilter"), 1);
@@ -60,6 +60,8 @@ typedef struct deco_browse {
int db_pending_flags;
#define DB_PENDING_ALBUM_ANALYSIS 0x1
+ struct prop_nf *db_pnf;
+
} deco_browse_t;
@@ -187,6 +189,7 @@ type_analysis(deco_browse_t *db)
{
if(db->db_types[CONTENT_IMAGE] * 4 > db->db_total * 3) {
prop_set_string(db->db_prop_contents, "images");
+ prop_nf_sort(db->db_pnf, "node.metadata.timestamp", 0);
return;
}
}
@@ -617,6 +620,7 @@ deco_browse_clear(deco_browse_t *db)
static void
deco_browse_destroy(deco_browse_t *db)
{
+ prop_nf_release(db->db_pnf);
deco_browse_clear(db);
prop_unsubscribe(db->db_sub);
prop_ref_dec(db->db_prop_contents);
@@ -690,7 +694,7 @@ deco_browse_node_cb(void *opaque, prop_event_t event, ...)
*
*/
void
-decorated_browse_create(prop_t *model)
+decorated_browse_create(prop_t *model, struct prop_nf *pnf)
{
prop_t *src = prop_create(model, "source");
@@ -705,9 +709,10 @@ decorated_browse_create(prop_t *model)
NULL);
if(db->db_sub == NULL) {
+ prop_nf_release(pnf);
free(db);
} else {
-
+ db->db_pnf = pnf;
LIST_INSERT_HEAD(&deco_browses, db, db_link);
db->db_prop_model = prop_ref_inc(model);
db->db_prop_contents = prop_ref_inc(prop_create(model, "contents"));
View
@@ -23,6 +23,7 @@
struct prop;
struct prop_vec;
+struct prop_nf;
typedef struct metadata_lazy_prop metadata_lazy_prop_t;
/**
@@ -218,7 +219,7 @@ metadata_t *metadb_get_videoinfo(void *db, const char *url);
void decoration_init(void);
-void decorated_browse_create(struct prop *model);
+void decorated_browse_create(struct prop *model, struct prop_nf *pnf);
void metadata_init(void);
View
@@ -402,9 +402,10 @@ get_nodes_for_plugins(prop_t *page, const char *title, int only_installed)
pnf = prop_nf_create(prop_create(model, "nodes"),
source,
prop_create(model, "filter"),
- "node.metadata.title",
PROP_NF_AUTODESTROY);
+ prop_nf_sort(pnf, "node.metadata.title", 0);
+
if(only_installed) {
prop_nf_pred_int_add(pnf, "node.metadata.installed",
PROP_NF_CMP_EQ, 0, NULL,
View
@@ -37,13 +37,15 @@ TAILQ_HEAD(nfnode_queue, nfnode);
LIST_HEAD(nfn_pred_list, nfn_pred);
LIST_HEAD(prop_nf_pred_list, prop_nf_pred);
+/**
+ *
+ */
typedef struct nfn_pred {
LIST_ENTRY(nfn_pred) nfnp_link;
prop_sub_t *nfnp_sub;
struct prop_nf_pred *nfnp_conf;
struct nfnode *nfnp_nfn;
char nfnp_set;
-
} nfn_pred_t;
@@ -123,7 +125,7 @@ typedef struct prop_nf {
int pos_valid;
- char **defsortpath;
+ char *sortkey;
struct prop_nf_pred_list preds;
@@ -287,6 +289,9 @@ nf_insert_node(prop_nf_t *nf, nfnode_t *nfn)
if(nfn->sortkey_type == SORTKEY_NONE) {
b = TAILQ_NEXT(nfn, in_link);
+
+ while(b != NULL && b->inserted == 0)
+ b = TAILQ_NEXT(b, in_link);
if(b != NULL) {
TAILQ_INSERT_BEFORE(b, nfn, out_link);
@@ -323,7 +328,7 @@ nf_update_egress(prop_nf_t *nf, nfnode_t *nfn)
int en = 1;
// If sorting is enabled but this node don't have a key, hide it
- if(nf->defsortpath != NULL && nfn->sortkey_type == SORTKEY_NONE)
+ if(nf->sortkey != NULL && nfn->sortkey_type == SORTKEY_NONE)
en = 0;
// Check filtering
@@ -537,14 +542,12 @@ nf_set_sortkey(void *opaque, prop_event_t event, ...)
static void
nf_update_order(prop_nf_t *nf, nfnode_t *nfn)
{
- char **p = nf->defsortpath;
-
if(nfn->sortsub) {
prop_unsubscribe0(nfn->sortsub);
nfn->sortsub = NULL;
}
- if(p == NULL) {
+ if(nf->sortkey == NULL) {
if(nfn->sortkey_type == SORTKEY_RSTR)
rstr_release(nfn->sortkey_rstr);
@@ -558,7 +561,7 @@ nf_update_order(prop_nf_t *nf, nfnode_t *nfn)
PROP_SUB_DIRECT_UPDATE,
PROP_TAG_CALLBACK, nf_set_sortkey, nfn,
PROP_TAG_NAMED_ROOT, nfn->in, "node",
- PROP_TAG_NAME_VECTOR, p,
+ PROP_TAG_NAMESTR, nf->sortkey,
NULL);
}
}
@@ -769,8 +772,8 @@ prop_nf_release0(struct prop_nf *pnf)
if(pnf->filtersub != NULL)
prop_unsubscribe0(pnf->filtersub);
- if(pnf->defsortpath)
- strvec_free(pnf->defsortpath);
+ if(pnf->sortkey)
+ free(pnf->sortkey);
free(pnf->filter);
@@ -943,8 +946,7 @@ nf_set_filter(void *opaque, const char *str)
*
*/
struct prop_nf *
-prop_nf_create(prop_t *dst, prop_t *src, prop_t *filter,
- const char *defsortpath, int flags)
+prop_nf_create(prop_t *dst, prop_t *src, prop_t *filter, int flags)
{
prop_nf_t *nf = calloc(1, sizeof(prop_nf_t));
@@ -955,9 +957,6 @@ prop_nf_create(prop_t *dst, prop_t *src, prop_t *filter,
nf->dst = flags & PROP_NF_TAKE_DST_OWNERSHIP ? dst : prop_xref_addref(dst);
nf->src = src;
- nf->defsortpath = defsortpath ? strvec_split(defsortpath, '.') : NULL;
- nf->sortorder = flags & PROP_NF_SORT_DESC ? -1 : 1;
-
hts_mutex_lock(&prop_mutex);
if(filter != NULL)
@@ -1086,3 +1085,37 @@ prop_nf_pred_int_add(struct prop_nf *nf,
prop_nf_pred_add(nf, path, cf, enable, mode, pnp);
hts_mutex_unlock(&prop_mutex);
}
+
+
+/**
+ *
+ */
+void
+prop_nf_sort(struct prop_nf *nf, const char *path, int desc)
+{
+ nfnode_t *nfn;
+
+ hts_mutex_lock(&prop_mutex);
+
+ if(nf->sortkey) {
+ if(path && !strcmp(path, nf->sortkey))
+ goto done;
+ free(nf->sortkey);
+ } else {
+ if(path == NULL)
+ goto done;
+ }
+
+ if(path) {
+ nf->sortkey = strdup(path);
+ nf->sortorder = desc ? -1 : 1;
+ } else {
+ nf->sortkey = NULL;
+ nf->sortorder = 0;
+ }
+
+ TAILQ_FOREACH(nfn, &nf->in, in_link)
+ nf_update_order(nf, nfn);
+ done:
+ hts_mutex_unlock(&prop_mutex);
+}
@@ -36,7 +36,6 @@ typedef enum {
#define PROP_NF_TAKE_DST_OWNERSHIP 0x1
#define PROP_NF_AUTODESTROY 0x2
-#define PROP_NF_SORT_DESC 0x4
void prop_nf_pred_str_add(struct prop_nf *nf,
const char *path, prop_nf_cmp_t cf,
@@ -49,9 +48,10 @@ void prop_nf_pred_int_add(struct prop_nf *nf,
prop_nf_mode_t mode);
struct prop_nf *prop_nf_create(prop_t *dst, prop_t *src,
- prop_t *filter, const char *defsortpath,
- int flags);
+ prop_t *filter, int flags);
void prop_nf_release(struct prop_nf *nf);
+void prop_nf_sort(struct prop_nf *nf, const char *path, int desc);
+
#endif // PROP_NODEFILTER_H__
View
@@ -66,7 +66,7 @@ service_init(void)
all_services = prop_create_root(NULL);
pnf = prop_nf_create(prop_create(prop_get_global(), "sources"), all_services,
- NULL, NULL, 0);
+ NULL, 0);
prop_nf_pred_int_add(pnf, "node.enabled",
PROP_NF_CMP_EQ, 0, NULL,
View
@@ -619,10 +619,10 @@ settings_init(void)
settings_nodes = prop_create_root(NULL);
s1 = prop_create_root(NULL);
- prop_nf_create(s1,
- settings_nodes, NULL, "node.metadata.title",
- PROP_NF_AUTODESTROY);
+ struct prop_nf *pnf;
+ pnf = prop_nf_create(s1, settings_nodes, NULL, PROP_NF_AUTODESTROY);
+ prop_nf_sort(pnf, "node.metadata.title", 0);
settings_apps = prop_create_root(NULL);
settings_sd = prop_create_root(NULL);
@@ -4403,9 +4403,10 @@ glwf_propSorter(glw_view_eval_context_t *ec, struct token *self,
eval_push(ec, r);
self->t_extra = prop_nf_create(r->t_prop, a->t_prop, NULL,
- rstr_get(b->t_rstring),
PROP_NF_TAKE_DST_OWNERSHIP);
+ prop_nf_sort(self->t_extra, rstr_get(b->t_rstring), 0);
+
argc -= 2;
argv += 2;
for(; argc >= 4; argc -= 4, argv += 4) {
View
@@ -604,7 +604,7 @@ browse_directory(upnp_browse_t *ub)
prop_set_string(ub->ub_type, "directory");
- pnf = prop_nf_create(ub->ub_nodes, ub->ub_items, ub->ub_filter, NULL,
+ pnf = prop_nf_create(ub->ub_nodes, ub->ub_items, ub->ub_filter,
PROP_NF_AUTODESTROY);
prop_set_int(ub->ub_canFilter, 1);
prop_nf_release(pnf);

0 comments on commit 5a9338a

Please sign in to comment.