Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix more internationalization issues, fixes #3202
  • Loading branch information
perexg committed Oct 23, 2015
1 parent 94342c9 commit e434119
Show file tree
Hide file tree
Showing 13 changed files with 62 additions and 30 deletions.
2 changes: 1 addition & 1 deletion src/api/api_service.c
Expand Up @@ -90,7 +90,7 @@ api_mapper_status
void
api_service_mapper_notify ( void )
{
notify_by_msg("servicemapper", api_mapper_status_msg());
notify_by_msg("servicemapper", api_mapper_status_msg(), 0);
}

static htsmsg_t *
Expand Down
2 changes: 1 addition & 1 deletion src/api/api_status.c
Expand Up @@ -71,7 +71,7 @@ api_status_subscriptions
c = 0;
pthread_mutex_lock(&global_lock);
LIST_FOREACH(ths, &subscriptions, ths_global_link) {
e = subscription_create_msg(ths);
e = subscription_create_msg(ths, perm->aa_lang_ui);
htsmsg_add_msg(l, NULL, e);
c++;
}
Expand Down
11 changes: 6 additions & 5 deletions src/config.c
Expand Up @@ -1821,21 +1821,22 @@ config_class_info_area_set ( void *o, const void *v )
}

static void
config_class_info_area_list1 ( htsmsg_t *m, const char *key, const char *val )
config_class_info_area_list1 ( htsmsg_t *m, const char *key,
const char *val, const char *lang )
{
htsmsg_t *e = htsmsg_create_map();
htsmsg_add_str(e, "key", key);
htsmsg_add_str(e, "val", val);
htsmsg_add_str(e, "val", tvh_gettext_lang(lang, val));
htsmsg_add_msg(m, NULL, e);
}

static htsmsg_t *
config_class_info_area_list ( void *o, const char *lang )
{
htsmsg_t *m = htsmsg_create_list();
config_class_info_area_list1(m, "login", N_("Login/Logout"));
config_class_info_area_list1(m, "storage", N_("Storage space"));
config_class_info_area_list1(m, "time", N_("Time"));
config_class_info_area_list1(m, "login", N_("Login/Logout"), lang);
config_class_info_area_list1(m, "storage", N_("Storage space"), lang);
config_class_info_area_list1(m, "time", N_("Time"), lang);
return m;
}

Expand Down
2 changes: 1 addition & 1 deletion src/dvr/dvr_rec.c
Expand Up @@ -1334,7 +1334,7 @@ dvr_get_disk_space_tcb(void *opaque, int dearmed)
htsmsg_add_s64(m, "totaldiskspace", dvr_btotal);
pthread_mutex_unlock(&dvr_disk_space_mutex);

notify_by_msg("diskspaceUpdate", m);
notify_by_msg("diskspaceUpdate", m, 0);
}

free(opaque);
Expand Down
2 changes: 1 addition & 1 deletion src/idnode.c
Expand Up @@ -1613,7 +1613,7 @@ idnode_notify_title_changed (void *in, const char *lang)
htsmsg_t *m = htsmsg_create_map();
htsmsg_add_str(m, "uuid", idnode_uuid_as_sstr(in));
htsmsg_add_str(m, "text", idnode_get_title(in, lang));
notify_by_msg("title", m);
notify_by_msg("title", m, 0);
idnode_notify_changed(in);
}

Expand Down
2 changes: 1 addition & 1 deletion src/input/mpegts/mpegts_input.c
Expand Up @@ -1594,7 +1594,7 @@ mpegts_input_status_timer ( void *p )
mpegts_input_stream_status(mmi, &st);
e = tvh_input_stream_create_msg(&st);
htsmsg_add_u32(e, "update", 1);
notify_by_msg("input_status", e);
notify_by_msg("input_status", e, 0);
subs += st.subs_count;
tvh_input_stream_destroy(&st);
}
Expand Down
8 changes: 4 additions & 4 deletions src/notify.c
Expand Up @@ -33,10 +33,10 @@ static pthread_t notify_tid;
static void* notify_thread(void* p);

void
notify_by_msg(const char *class, htsmsg_t *m)
notify_by_msg(const char *class, htsmsg_t *m, int rewrite)
{
htsmsg_add_str(m, "notificationClass", class);
comet_mailbox_add_message(m, 0);
comet_mailbox_add_message(m, 0, rewrite);
htsmsg_destroy(m);
}

Expand All @@ -46,7 +46,7 @@ notify_reload(const char *class)
{
htsmsg_t *m = htsmsg_create_map();
htsmsg_add_u32(m, "reload", 1);
notify_by_msg(class, m);
notify_by_msg(class, m, 0);
}

void
Expand Down Expand Up @@ -103,7 +103,7 @@ notify_thread ( void *p )
pthread_mutex_lock(&global_lock);

HTSMSG_FOREACH(f, q)
notify_by_msg(f->hmf_name, htsmsg_detach_submsg(f));
notify_by_msg(f->hmf_name, htsmsg_detach_submsg(f), 0);

/* Finished */
pthread_mutex_unlock(&global_lock);
Expand Down
4 changes: 3 additions & 1 deletion src/notify.h
Expand Up @@ -21,7 +21,9 @@

#include "htsmsg.h"

void notify_by_msg(const char *class, htsmsg_t *m);
#define NOTIFY_REWRITE_SUBSCRIPTIONS 1

void notify_by_msg(const char *class, htsmsg_t *m, int rewrite);

void notify_reload(const char *class);

Expand Down
16 changes: 8 additions & 8 deletions src/subscriptions.c
Expand Up @@ -847,7 +847,7 @@ static gtimer_t subscription_status_timer;
* Serialize info about subscription
*/
htsmsg_t *
subscription_create_msg(th_subscription_t *s)
subscription_create_msg(th_subscription_t *s, const char *lang)
{
htsmsg_t *m = htsmsg_create_map();
descramble_info_t *di;
Expand All @@ -860,24 +860,24 @@ subscription_create_msg(th_subscription_t *s)
const char *state;
switch(s->ths_state) {
default:
state = "Idle";
state = N_("Idle");
break;

case SUBSCRIPTION_TESTING_SERVICE:
state = "Testing";
state = N_("Testing");
break;

case SUBSCRIPTION_GOT_SERVICE:
state = "Running";
state = N_("Running");
break;

case SUBSCRIPTION_BAD_SERVICE:
state = "Bad";
state = N_("Bad");
break;
}


htsmsg_add_str(m, "state", state);
htsmsg_add_str(m, "state", lang ? tvh_gettext_lang(lang, state) : state);

if(s->ths_hostname != NULL)
htsmsg_add_str(m, "hostname", s->ths_hostname);
Expand Down Expand Up @@ -939,9 +939,9 @@ subscription_status_callback ( void *p )
s->ths_bytes_out_avg = (int)(out_curr - out_prev);
s->ths_total_bytes_out_prev = s->ths_total_bytes_out;

htsmsg_t *m = subscription_create_msg(s);
htsmsg_t *m = subscription_create_msg(s, NULL);
htsmsg_add_u32(m, "updateEntry", 1);
notify_by_msg("subscriptions", m);
notify_by_msg("subscriptions", m, NOTIFY_REWRITE_SUBSCRIPTIONS);
count++;
}
if (old_count != count) {
Expand Down
2 changes: 1 addition & 1 deletion src/subscriptions.h
Expand Up @@ -215,6 +215,6 @@ static inline int subscriptions_active(void)
{ return LIST_FIRST(&subscriptions) != NULL; }

struct htsmsg;
struct htsmsg *subscription_create_msg(th_subscription_t *s);
struct htsmsg *subscription_create_msg(th_subscription_t *s, const char *lang);

#endif /* SUBSCRIPTIONS_H */
2 changes: 1 addition & 1 deletion src/tvhlog.c
Expand Up @@ -178,7 +178,7 @@ tvhlog_process
snprintf(buf, sizeof(buf), "%s %s", t, msg->msg);
htsmsg_add_str(m, "notificationClass", "logmessage");
htsmsg_add_str(m, "logtxt", buf);
comet_mailbox_add_message(m, msg->severity >= LOG_DEBUG);
comet_mailbox_add_message(m, msg->severity >= LOG_DEBUG, 0);
htsmsg_destroy(m);
}

Expand Down
37 changes: 33 additions & 4 deletions src/webui/comet.c
Expand Up @@ -35,6 +35,7 @@
#include "dvr/dvr.h"
#include "webui/webui.h"
#include "access.h"
#include "notify.h"
#include "tcp.h"

static pthread_mutex_t comet_mutex = PTHREAD_MUTEX_INITIALIZER;
Expand All @@ -54,6 +55,7 @@ int comet_running;

typedef struct comet_mailbox {
char *cmb_boxid; /* SHA-1 hash */
char *cmb_lang; /* UI language */
htsmsg_t *cmb_messages; /* A vector */
time_t cmb_last_used;
LIST_ENTRY(comet_mailbox) cmb_link;
Expand All @@ -74,6 +76,7 @@ cmb_destroy(comet_mailbox_t *cmb)

LIST_REMOVE(cmb, cmb_link);

free(cmb->cmb_lang);
free(cmb->cmb_boxid);
free(cmb);
}
Expand Down Expand Up @@ -103,7 +106,7 @@ comet_flush(void)
*
*/
static comet_mailbox_t *
comet_mailbox_create(void)
comet_mailbox_create(const char *lang)
{
comet_mailbox_t *cmb = calloc(1, sizeof(comet_mailbox_t));

Expand All @@ -127,6 +130,7 @@ comet_mailbox_create(void)
id[40] = 0;

cmb->cmb_boxid = strdup(id);
cmb->cmb_lang = lang ? strdup(lang) : NULL;
time(&cmb->cmb_last_used);
mailbox_tally++;

Expand Down Expand Up @@ -234,7 +238,7 @@ comet_mailbox_poll(http_connection_t *hc, const char *remain, void *opaque)
break;

if(cmb == NULL) {
cmb = comet_mailbox_create();
cmb = comet_mailbox_create(hc->hc_access->aa_lang_ui);
comet_access_update(hc, cmb);
comet_serverIpPort(hc, cmb);
}
Expand Down Expand Up @@ -332,13 +336,35 @@ comet_done(void)
pthread_mutex_unlock(&comet_mutex);
}

/**
*
*/
static void
comet_mailbox_rewrite_str(htsmsg_t *m, const char *key, const char *lang)
{
const char *s = htsmsg_get_str(m, key);
if (s)
htsmsg_set_str(m, key, tvh_gettext_lang(lang, s));
}

static void
comet_mailbox_rewrite_msg(int rewrite, htsmsg_t *m, const char *lang)
{
switch (rewrite) {
case NOTIFY_REWRITE_SUBSCRIPTIONS:
comet_mailbox_rewrite_str(m, "state", lang);
break;
}
}

/**
*
*/
void
comet_mailbox_add_message(htsmsg_t *m, int isdebug)
comet_mailbox_add_message(htsmsg_t *m, int isdebug, int rewrite)
{
comet_mailbox_t *cmb;
htsmsg_t *e;

pthread_mutex_lock(&comet_mutex);

Expand All @@ -350,7 +376,10 @@ comet_mailbox_add_message(htsmsg_t *m, int isdebug)

if(cmb->cmb_messages == NULL)
cmb->cmb_messages = htsmsg_create_list();
htsmsg_add_msg(cmb->cmb_messages, NULL, htsmsg_copy(m));
e = htsmsg_copy(m);
if (cmb->cmb_lang && rewrite)
comet_mailbox_rewrite_msg(rewrite, e, cmb->cmb_lang);
htsmsg_add_msg(cmb->cmb_messages, NULL, e);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/webui/webui.h
Expand Up @@ -49,7 +49,7 @@ void comet_init(void);

void comet_done(void);

void comet_mailbox_add_message(htsmsg_t *m, int isdebug);
void comet_mailbox_add_message(htsmsg_t *m, int isdebug, int rewrite);

void comet_flush(void);

Expand Down

0 comments on commit e434119

Please sign in to comment.