Rockbox open source high quality audio player as a Music Player Daemon
mpris rockbox mpd libadwaita audio rust zig deno
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

openplugins -- import and export thru settings save / restore settings

saves openplugin entries to the config file for later import to the database

lang_english_to_id() allows entries to be transfered between builds

Change-Id: I47e01c5f75f8b0e69c203828e21759ef24bf125d

+105 -4
+83
apps/open_plugin.c
··· 27 27 #include "splash.h" 28 28 #include "lang.h" 29 29 #include "filetypes.h" 30 + #include "language.h" /*lang_english_to_id*/ 30 31 31 32 /* Define LOGF_ENABLE to enable logf output in this file */ 32 33 /*#define LOGF_ENABLE*/ ··· 518 519 op_entry->lang_id = LANG_PREVIOUS_SCREEN; 519 520 } 520 521 op_update_dat(op_entry, true); 522 + } 523 + 524 + static bool op_entry_read(int fd, int selected_item, off_t data_sz, struct open_plugin_entry_t *op_entry) 525 + { 526 + op_clear_entry(op_entry); 527 + return ((selected_item >= 0) && (fd >= 0) && 528 + (lseek(fd, selected_item * op_entry_sz, SEEK_SET) >= 0) && 529 + (read(fd, op_entry, data_sz) == data_sz) && op_entry_checksum(op_entry) > 0); 530 + } 531 + 532 + void open_plugin_import(char *strdat) 533 + { 534 + /* Note: Destroys strdat */ 535 + char *vect[5]; 536 + /* expected openplugin strdat: "englishid", "name", "path", "param" */ 537 + 538 + if (split_string(strdat, ',', vect, 5) == 4) 539 + { 540 + /* Space for 5 values so we will fail if excess arguments or too few */ 541 + for(int i = 0; i < 4; i++) 542 + { 543 + vect[i] = skip_whitespace(vect[i]); 544 + int eos = ((int)strlen(vect[i]))-2; 545 + /* Failure if string is not quoted */ 546 + if (vect[i][0] != '"' || eos < 0 || vect[i][eos + 1] != '"') 547 + { 548 + logf("%s[%d] error: quoted string expected\n", __func__, i); 549 + return; 550 + } 551 + vect[i]++; /* skip first " */ 552 + vect[i][eos] = '\0'; /* skip other " */ 553 + } 554 + char *key = vect[1]; 555 + int lang_id = lang_english_to_id(vect[0]); 556 + if (lang_id >= 0) 557 + key = ID2P(lang_id); 558 + /* if key exists it will be overwritten */ 559 + open_plugin_add_path(key, vect[2], vect[3]); 560 + return; 561 + } 562 + logf("%s error: importing entries", __func__); 563 + } 564 + 565 + void open_plugin_export(int cfg_fd) 566 + { 567 + /* NOTE: assumes cfg_fd is valid */ 568 + char *lang_name; 569 + int fd; 570 + int index = 0; 571 + 572 + struct open_plugin_entry_t *op_entry = open_plugin_get_entry(); 573 + /* if another entry is loaded; flush it to disk before we destroy it */ 574 + op_update_dat(op_entry, true); 575 + 576 + fd = open(OPEN_PLUGIN_DAT, O_RDONLY, 0666); 577 + 578 + if (fd < 0) 579 + { 580 + logf("%s error: opening %s", __func__, OPEN_PLUGIN_DAT); 581 + return; /* OPEN_PLUGIN_NOT_FOUND */ 582 + } 583 + while (op_entry_read(fd, index++, op_entry_sz, op_entry)) 584 + { 585 + /* don't save the LANG_OPEN_PLUGIN entry -- it is for internal use */ 586 + if (op_entry->lang_id == LANG_OPEN_PLUGIN) 587 + { 588 + continue; 589 + } 590 + if (op_entry->lang_id >=0) 591 + lang_name = P2STR(ID2P(op_entry->lang_id)); 592 + else 593 + lang_name = "[USER]"; /* needs to be an invalid lang string */ 594 + 595 + fdprintf(cfg_fd,"%s: \"%s\", \"%s\", \"%s\", \"%s\"\n", 596 + "openplugin", lang_name, op_entry->name, op_entry->path, op_entry->param); 597 + 598 + logf("openplugin[%d]: \"%s\", \"%s\", \"%s\", \"%s\"\n lang id: %d hash: %x, csum: %x\n", 599 + index, lang_name, op_entry->name, op_entry->path, op_entry->param, 600 + op_entry->lang_id, op_entry->hash, op_entry->checksum); 601 + } 602 + close(fd); 603 + logf("%s exported %d entries", __func__, index); 521 604 } 522 605 523 606 #endif /* ndef __PCTOOL__ */
+2
apps/open_plugin.h
··· 84 84 void open_plugin_browse(const char *key); 85 85 int open_plugin_run(const char *key); 86 86 void open_plugin_cache_flush(void); /* flush to disk */ 87 + void open_plugin_import(char *strdat); 88 + void open_plugin_export(int cfg_fd); 87 89 #endif 88 90 89 91 #endif /*ndef __PCTOOL__ */
+19 -3
apps/settings.c
··· 293 293 return true; 294 294 } 295 295 296 - void string_to_cfg(const char *name, char* value, bool *theme_changed) 296 + bool string_to_cfg(const char *name, char* value, bool *theme_changed) 297 297 { 298 298 const struct settings_list *setting = find_setting_by_cfgname(name); 299 299 if (!setting) 300 - return; 300 + return false; 301 301 302 302 uint32_t flags = setting->flags; 303 303 ··· 366 366 { 367 367 logf("Error: %s: Not Found! [%s]\r\n", 368 368 setting->cfg_name, value); 369 + return false; 369 370 } 370 371 } 371 372 break; ··· 394 395 break; 395 396 } 396 397 } 398 + return true; 397 399 } 398 400 399 401 bool settings_load_config(const char* file, bool apply) ··· 412 414 char *name, *value; 413 415 if (!settings_parseline(line, &name, &value)) 414 416 continue; 415 - string_to_cfg(name, value, &theme_changed); 417 + 418 + if (!string_to_cfg(name, value, &theme_changed)) 419 + { 420 + /* if we are here then name was not a valid setting */ 421 + if (!strcmp(name, "openplugin")) 422 + { 423 + open_plugin_import(value); 424 + } 425 + } 416 426 } /* while(...) */ 417 427 418 428 close(fd); ··· 630 640 631 641 fdprintf(fd,"%s: %s\r\n",setting->cfg_name,value); 632 642 } /* for(...) */ 643 + 644 + if (options == SETTINGS_SAVE_ALL) 645 + { 646 + /* add openplugin entries to the open settings file */ 647 + open_plugin_export(fd); 648 + } 633 649 close(fd); 634 650 return true; 635 651 }
+1 -1
apps/settings.h
··· 308 308 bool cfg_int_to_string(const struct settings_list *setting, int val, char* buf, int buf_len); 309 309 bool cfg_string_to_int(const struct settings_list *setting, int* out, const char* str); 310 310 void cfg_to_string(const struct settings_list *setting, char* buf, int buf_len); 311 - void string_to_cfg(const char *name, char* value, bool *theme_changed); 311 + bool string_to_cfg(const char *name, char* value, bool *theme_changed); 312 312 313 313 bool copy_filename_setting(char *buf, size_t buflen, const char *input, 314 314 const struct filename_setting *fs);