diff options
author | Roman Artiukhin <bahusdrive@gmail.com> | 2024-02-04 11:04:23 +0200 |
---|---|---|
committer | Roman Artiukhin <bahusdrive@gmail.com> | 2024-06-24 16:59:14 +0300 |
commit | 5d39d987c0a0687cd3e919c01847172ff5ae8813 (patch) | |
tree | c0f6ded306a60bc1dadf2e089a10a1e23dc9e127 /apps/plugins/playing_time.c | |
parent | 54e2facb8533358e06b2716753e12865c471c2be (diff) | |
download | rockbox-5d39d987c0a0687cd3e919c01847172ff5ae8813.tar.gz rockbox-5d39d987c0a0687cd3e919c01847172ff5ae8813.zip |
plugins: playing time: Show info in 2 lines (header + details)
Improves readability on small screens.
See WPS -> Context Menu -> Current Playlist -> Playing time
Also, Russian translation is adjusted accordingly.
Change-Id: I23662ccb324f07a742179ff274453416bb8eff08
Diffstat (limited to 'apps/plugins/playing_time.c')
-rw-r--r-- | apps/plugins/playing_time.c | 98 |
1 files changed, 72 insertions, 26 deletions
diff --git a/apps/plugins/playing_time.c b/apps/plugins/playing_time.c index 354c5a3e06..1daf70c53e 100644 --- a/apps/plugins/playing_time.c +++ b/apps/plugins/playing_time.c | |||
@@ -31,6 +31,17 @@ const unsigned char * const byte_units[] = | |||
31 | ID2P(LANG_GIBIBYTE) | 31 | ID2P(LANG_GIBIBYTE) |
32 | }; | 32 | }; |
33 | 33 | ||
34 | const int menu_items[] = { | ||
35 | LANG_PLAYTIME_ELAPSED, | ||
36 | LANG_PLAYTIME_REMAINING, | ||
37 | LANG_PLAYTIME_TRK_ELAPSED, | ||
38 | LANG_PLAYTIME_TRK_REMAINING, | ||
39 | LANG_PLAYTIME_TRACK, | ||
40 | LANG_PLAYTIME_STORAGE, | ||
41 | LANG_PLAYTIME_AVG_TRACK_SIZE, | ||
42 | LANG_PLAYTIME_AVG_BITRATE, | ||
43 | }; | ||
44 | |||
34 | const unsigned char * const * const kibyte_units = &byte_units[1]; | 45 | const unsigned char * const * const kibyte_units = &byte_units[1]; |
35 | 46 | ||
36 | enum ePT_SECS { | 47 | enum ePT_SECS { |
@@ -68,6 +79,27 @@ struct playing_time_info { | |||
68 | long kbs[ePT_KBS_COUNT]; | 79 | long kbs[ePT_KBS_COUNT]; |
69 | }; | 80 | }; |
70 | 81 | ||
82 | static char* get_percent_str(long percents) | ||
83 | { | ||
84 | static char val[10]; | ||
85 | rb->snprintf(val, 10, rb->str(LANG_PERCENT_FORMAT), percents); | ||
86 | return val; | ||
87 | } | ||
88 | |||
89 | static inline void prepare_time_string(const char *buf, size_t buffer_len, long elapsed_pct, const char *timestr1, const char *timestr2) | ||
90 | { | ||
91 | if (rb->lang_is_rtl()) | ||
92 | { | ||
93 | rb->snprintf(buf, buffer_len, "%s %s / %s", | ||
94 | get_percent_str(elapsed_pct), timestr2, timestr1); | ||
95 | } | ||
96 | else | ||
97 | { | ||
98 | rb->snprintf(buf, buffer_len, "%s / %s %s", | ||
99 | timestr1, timestr2, get_percent_str(elapsed_pct)); | ||
100 | } | ||
101 | } | ||
102 | |||
71 | /* list callback for playing_time screen */ | 103 | /* list callback for playing_time screen */ |
72 | static const char * playing_time_get_or_speak_info(int selected_item, void * data, | 104 | static const char * playing_time_get_or_speak_info(int selected_item, void * data, |
73 | char *buf, size_t buffer_len, | 105 | char *buf, size_t buffer_len, |
@@ -75,14 +107,22 @@ static const char * playing_time_get_or_speak_info(int selected_item, void * dat | |||
75 | { | 107 | { |
76 | long elapsed_pct; /* percentage of duration elapsed */ | 108 | long elapsed_pct; /* percentage of duration elapsed */ |
77 | struct playing_time_info *pti = (struct playing_time_info *)data; | 109 | struct playing_time_info *pti = (struct playing_time_info *)data; |
78 | switch(selected_item) { | 110 | int info_no = selected_item/2; |
111 | const int menu_name_id = menu_items[info_no]; | ||
112 | |||
113 | if (!(selected_item%2)) | ||
114 | {/* header */ | ||
115 | return rb->str(menu_name_id); | ||
116 | } | ||
117 | |||
118 | switch(info_no) { | ||
79 | case 0: { /* elapsed and total time */ | 119 | case 0: { /* elapsed and total time */ |
80 | char timestr1[25], timestr2[25]; | 120 | char timestr1[25], timestr2[25]; |
81 | rb->format_time_auto(timestr1, sizeof(timestr1), | 121 | rb->format_time_auto(timestr1, sizeof(timestr1), |
82 | pti->secs[ePT_SECS_BEF], UNIT_SEC, false); | 122 | pti->secs[ePT_SECS_BEF], UNIT_SEC, true); |
83 | 123 | ||
84 | rb->format_time_auto(timestr2, sizeof(timestr2), | 124 | rb->format_time_auto(timestr2, sizeof(timestr2), |
85 | pti->secs[ePT_SECS_TTL], UNIT_SEC, false); | 125 | pti->secs[ePT_SECS_TTL], UNIT_SEC, true); |
86 | 126 | ||
87 | if (pti->secs[ePT_SECS_TTL] == 0) | 127 | if (pti->secs[ePT_SECS_TTL] == 0) |
88 | elapsed_pct = 0; | 128 | elapsed_pct = 0; |
@@ -96,11 +136,10 @@ static const char * playing_time_get_or_speak_info(int selected_item, void * dat | |||
96 | elapsed_pct = (pti->secs[ePT_SECS_BEF] >> 7) * 100 | 136 | elapsed_pct = (pti->secs[ePT_SECS_BEF] >> 7) * 100 |
97 | / (pti->secs[ePT_SECS_TTL] >> 7); | 137 | / (pti->secs[ePT_SECS_TTL] >> 7); |
98 | } | 138 | } |
99 | rb->snprintf(buf, buffer_len, rb->str(LANG_PLAYTIME_ELAPSED), | 139 | prepare_time_string(buf, buffer_len, elapsed_pct, timestr1, timestr2); |
100 | timestr1, timestr2, elapsed_pct); | ||
101 | 140 | ||
102 | if (say_it) | 141 | if (say_it) |
103 | rb_talk_ids(false, LANG_PLAYTIME_ELAPSED, | 142 | rb_talk_ids(false, menu_name_id, |
104 | TALK_ID(pti->secs[ePT_SECS_BEF], UNIT_TIME), | 143 | TALK_ID(pti->secs[ePT_SECS_BEF], UNIT_TIME), |
105 | VOICE_OF, | 144 | VOICE_OF, |
106 | TALK_ID(pti->secs[ePT_SECS_TTL], UNIT_TIME), | 145 | TALK_ID(pti->secs[ePT_SECS_TTL], UNIT_TIME), |
@@ -112,10 +151,10 @@ static const char * playing_time_get_or_speak_info(int selected_item, void * dat | |||
112 | char timestr[25]; | 151 | char timestr[25]; |
113 | rb->format_time_auto(timestr, sizeof(timestr), pti->secs[ePT_SECS_AFT], | 152 | rb->format_time_auto(timestr, sizeof(timestr), pti->secs[ePT_SECS_AFT], |
114 | UNIT_SEC, false); | 153 | UNIT_SEC, false); |
115 | rb->snprintf(buf, buffer_len, rb->str(LANG_PLAYTIME_REMAINING), timestr); | 154 | rb->snprintf(buf, buffer_len, "%s", timestr); |
116 | 155 | ||
117 | if (say_it) | 156 | if (say_it) |
118 | rb_talk_ids(false, LANG_PLAYTIME_REMAINING, | 157 | rb_talk_ids(false, menu_name_id, |
119 | TALK_ID(pti->secs[ePT_SECS_AFT], UNIT_TIME)); | 158 | TALK_ID(pti->secs[ePT_SECS_AFT], UNIT_TIME)); |
120 | break; | 159 | break; |
121 | } | 160 | } |
@@ -123,9 +162,9 @@ static const char * playing_time_get_or_speak_info(int selected_item, void * dat | |||
123 | char timestr1[25], timestr2[25]; | 162 | char timestr1[25], timestr2[25]; |
124 | 163 | ||
125 | rb->format_time_auto(timestr1, sizeof(timestr1), pti->trk_secs[ePT_SECS_BEF], | 164 | rb->format_time_auto(timestr1, sizeof(timestr1), pti->trk_secs[ePT_SECS_BEF], |
126 | UNIT_SEC, false); | 165 | UNIT_SEC, true); |
127 | rb->format_time_auto(timestr2, sizeof(timestr2), pti->trk_secs[ePT_SECS_TTL], | 166 | rb->format_time_auto(timestr2, sizeof(timestr2), pti->trk_secs[ePT_SECS_TTL], |
128 | UNIT_SEC, false); | 167 | UNIT_SEC, true); |
129 | 168 | ||
130 | if (pti->trk_secs[ePT_SECS_TTL] == 0) | 169 | if (pti->trk_secs[ePT_SECS_TTL] == 0) |
131 | elapsed_pct = 0; | 170 | elapsed_pct = 0; |
@@ -139,11 +178,10 @@ static const char * playing_time_get_or_speak_info(int selected_item, void * dat | |||
139 | elapsed_pct = (pti->trk_secs[ePT_SECS_BEF] >> 7) * 100 | 178 | elapsed_pct = (pti->trk_secs[ePT_SECS_BEF] >> 7) * 100 |
140 | / (pti->trk_secs[ePT_SECS_TTL] >> 7); | 179 | / (pti->trk_secs[ePT_SECS_TTL] >> 7); |
141 | } | 180 | } |
142 | rb->snprintf(buf, buffer_len, rb->str(LANG_PLAYTIME_TRK_ELAPSED), | 181 | prepare_time_string(buf, buffer_len, elapsed_pct, timestr1, timestr2); |
143 | timestr1, timestr2, elapsed_pct); | ||
144 | 182 | ||
145 | if (say_it) | 183 | if (say_it) |
146 | rb_talk_ids(false, LANG_PLAYTIME_TRK_ELAPSED, | 184 | rb_talk_ids(false, menu_name_id, |
147 | TALK_ID(pti->trk_secs[ePT_SECS_BEF], UNIT_TIME), | 185 | TALK_ID(pti->trk_secs[ePT_SECS_BEF], UNIT_TIME), |
148 | VOICE_OF, | 186 | VOICE_OF, |
149 | TALK_ID(pti->trk_secs[ePT_SECS_TTL], UNIT_TIME), | 187 | TALK_ID(pti->trk_secs[ePT_SECS_TTL], UNIT_TIME), |
@@ -155,21 +193,29 @@ static const char * playing_time_get_or_speak_info(int selected_item, void * dat | |||
155 | char timestr[25]; | 193 | char timestr[25]; |
156 | rb->format_time_auto(timestr, sizeof(timestr), pti->trk_secs[ePT_SECS_AFT], | 194 | rb->format_time_auto(timestr, sizeof(timestr), pti->trk_secs[ePT_SECS_AFT], |
157 | UNIT_SEC, false); | 195 | UNIT_SEC, false); |
158 | rb->snprintf(buf, buffer_len, rb->str(LANG_PLAYTIME_TRK_REMAINING), timestr); | 196 | rb->snprintf(buf, buffer_len, "%s", timestr); |
159 | 197 | ||
160 | if (say_it) | 198 | if (say_it) |
161 | rb_talk_ids(false, LANG_PLAYTIME_TRK_REMAINING, | 199 | rb_talk_ids(false, menu_name_id, |
162 | TALK_ID(pti->trk_secs[ePT_SECS_AFT], UNIT_TIME)); | 200 | TALK_ID(pti->trk_secs[ePT_SECS_AFT], UNIT_TIME)); |
163 | break; | 201 | break; |
164 | } | 202 | } |
165 | case 4: { /* track index */ | 203 | case 4: { /* track index */ |
166 | int track_pct = pti->curr_display_index * 100 / pti->nb_tracks; | 204 | int track_pct = pti->curr_display_index * 100 / pti->nb_tracks; |
167 | 205 | ||
168 | rb->snprintf(buf, buffer_len, rb->str(LANG_PLAYTIME_TRACK), | 206 | if (rb->lang_is_rtl()) |
169 | pti->curr_display_index, pti->nb_tracks, track_pct); | 207 | { |
208 | rb->snprintf(buf, buffer_len, "%s %d / %d", | ||
209 | get_percent_str(track_pct), pti->nb_tracks, pti->curr_display_index); | ||
210 | } | ||
211 | else | ||
212 | { | ||
213 | rb->snprintf(buf, buffer_len, "%d / %d %s", | ||
214 | pti->curr_display_index, pti->nb_tracks, get_percent_str(track_pct)); | ||
215 | } | ||
170 | 216 | ||
171 | if (say_it) | 217 | if (say_it) |
172 | rb_talk_ids(false, LANG_PLAYTIME_TRACK, | 218 | rb_talk_ids(false, menu_name_id, |
173 | TALK_ID(pti->curr_display_index, UNIT_INT), | 219 | TALK_ID(pti->curr_display_index, UNIT_INT), |
174 | VOICE_OF, | 220 | VOICE_OF, |
175 | TALK_ID(pti->nb_tracks, UNIT_INT), | 221 | TALK_ID(pti->nb_tracks, UNIT_INT), |
@@ -185,12 +231,12 @@ static const char * playing_time_get_or_speak_info(int selected_item, void * dat | |||
185 | rb->output_dyn_value(kbstr[i], sizeof(kbstr[i]), | 231 | rb->output_dyn_value(kbstr[i], sizeof(kbstr[i]), |
186 | pti->kbs[i], kibyte_units, 3, true); | 232 | pti->kbs[i], kibyte_units, 3, true); |
187 | } | 233 | } |
188 | rb->snprintf(buf, buffer_len, rb->str(LANG_PLAYTIME_STORAGE), | 234 | rb->snprintf(buf, buffer_len, "%s (%s / %s)", |
189 | kbstr[ePT_KBS_TTL], kbstr[ePT_KBS_BEF],kbstr[ePT_KBS_AFT]); | 235 | kbstr[ePT_KBS_TTL], kbstr[ePT_KBS_BEF],kbstr[ePT_KBS_AFT]); |
190 | 236 | ||
191 | if (say_it) { | 237 | if (say_it) { |
192 | int32_t voice_ids[ePT_KBS_COUNT]; | 238 | int32_t voice_ids[ePT_KBS_COUNT]; |
193 | voice_ids[ePT_KBS_TTL] = LANG_PLAYTIME_STORAGE; | 239 | voice_ids[ePT_KBS_TTL] = menu_name_id; |
194 | voice_ids[ePT_KBS_BEF] = VOICE_PLAYTIME_DONE; | 240 | voice_ids[ePT_KBS_BEF] = VOICE_PLAYTIME_DONE; |
195 | voice_ids[ePT_KBS_AFT] = LANG_PLAYTIME_REMAINING; | 241 | voice_ids[ePT_KBS_AFT] = LANG_PLAYTIME_REMAINING; |
196 | 242 | ||
@@ -205,10 +251,10 @@ static const char * playing_time_get_or_speak_info(int selected_item, void * dat | |||
205 | char str[10]; | 251 | char str[10]; |
206 | long avg_track_size = pti->kbs[ePT_KBS_TTL] / pti->nb_tracks; | 252 | long avg_track_size = pti->kbs[ePT_KBS_TTL] / pti->nb_tracks; |
207 | rb->output_dyn_value(str, sizeof(str), avg_track_size, kibyte_units, 3, true); | 253 | rb->output_dyn_value(str, sizeof(str), avg_track_size, kibyte_units, 3, true); |
208 | rb->snprintf(buf, buffer_len, rb->str(LANG_PLAYTIME_AVG_TRACK_SIZE), str); | 254 | rb->snprintf(buf, buffer_len, "%s", str); |
209 | 255 | ||
210 | if (say_it) { | 256 | if (say_it) { |
211 | rb->talk_id(LANG_PLAYTIME_AVG_TRACK_SIZE, false); | 257 | rb->talk_id(menu_name_id, false); |
212 | rb->output_dyn_value(NULL, 0, avg_track_size, kibyte_units, 3, true); | 258 | rb->output_dyn_value(NULL, 0, avg_track_size, kibyte_units, 3, true); |
213 | } | 259 | } |
214 | break; | 260 | break; |
@@ -217,10 +263,10 @@ static const char * playing_time_get_or_speak_info(int selected_item, void * dat | |||
217 | /* Convert power of 2 kilobytes to power of 10 kilobits */ | 263 | /* Convert power of 2 kilobytes to power of 10 kilobits */ |
218 | long avg_bitrate = (pti->kbs[ePT_KBS_TTL] / pti->secs[ePT_SECS_TTL] | 264 | long avg_bitrate = (pti->kbs[ePT_KBS_TTL] / pti->secs[ePT_SECS_TTL] |
219 | * 1024 * 8 / 1000); | 265 | * 1024 * 8 / 1000); |
220 | rb->snprintf(buf, buffer_len, rb->str(LANG_PLAYTIME_AVG_BITRATE), avg_bitrate); | 266 | rb->snprintf(buf, buffer_len, "%ld kbps", avg_bitrate); |
221 | 267 | ||
222 | if (say_it) | 268 | if (say_it) |
223 | rb_talk_ids(false, LANG_PLAYTIME_AVG_BITRATE, | 269 | rb_talk_ids(false, menu_name_id, |
224 | TALK_ID(avg_bitrate, UNIT_KBIT)); | 270 | TALK_ID(avg_bitrate, UNIT_KBIT)); |
225 | break; | 271 | break; |
226 | } | 272 | } |
@@ -340,10 +386,10 @@ static bool playing_time(void) | |||
340 | struct gui_synclist pt_lists; | 386 | struct gui_synclist pt_lists; |
341 | int key; | 387 | int key; |
342 | 388 | ||
343 | rb->gui_synclist_init(&pt_lists, &playing_time_get_info, &pti, true, 1, NULL); | 389 | rb->gui_synclist_init(&pt_lists, &playing_time_get_info, &pti, true, 2, NULL); |
344 | if (rb->global_settings->talk_menu) | 390 | if (rb->global_settings->talk_menu) |
345 | rb->gui_synclist_set_voice_callback(&pt_lists, playing_time_speak_info); | 391 | rb->gui_synclist_set_voice_callback(&pt_lists, playing_time_speak_info); |
346 | rb->gui_synclist_set_nb_items(&pt_lists, 8); | 392 | rb->gui_synclist_set_nb_items(&pt_lists, 16); |
347 | rb->gui_synclist_set_title(&pt_lists, rb->str(LANG_PLAYING_TIME), NOICON); | 393 | rb->gui_synclist_set_title(&pt_lists, rb->str(LANG_PLAYING_TIME), NOICON); |
348 | rb->gui_synclist_draw(&pt_lists); | 394 | rb->gui_synclist_draw(&pt_lists); |
349 | rb->gui_synclist_speak_item(&pt_lists); | 395 | rb->gui_synclist_speak_item(&pt_lists); |