Advertisement
adrek14

moc 2.5.0-beta1 rev 2526 ratings patch

Mar 5th, 2013
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 24.17 KB | None | 0 0
  1. diff -rup moc-2.5.0-beta1-clean2526//common.c moc-2.5.0-beta1-ratings/common.c
  2. --- moc-2.5.0-beta1-clean2526//common.c 2013-03-05 15:09:53.000000000 +0100
  3. +++ moc-2.5.0-beta1-ratings/common.c    2013-03-05 16:13:07.000000000 +0100
  4. @@ -266,3 +266,39 @@ const char *get_home ()
  5.  
  6.     return home;
  7.  }
  8. +
  9. +/* Convert rating to text format. Rating must be scaled to 0-255. */
  10. +void rating_to_str (char *buff, const int rating)
  11. +{
  12. +   assert (rating >= 0 && rating <= 255);
  13. +
  14. +   const char empty_star[] = " ";
  15. +   const char filled_star[] = { 0xe2, 0x98, 0x85, '\0' }; // unicode 0x2606
  16. +   const char * stars[5];
  17. +   int star_num = 0;
  18. +   int space_num = 0;
  19. +  
  20. +   // Intervals taken from Banshee (said to provide good compatibility).
  21. +   if (rating == 0)
  22. +       star_num = 0;
  23. +   else if (rating <= 63)
  24. +       star_num = 1;
  25. +   else if (rating <= 127)
  26. +       star_num = 2;
  27. +   else if (rating <= 191)
  28. +       star_num = 3;
  29. +   else if (rating <= 254)
  30. +       star_num = 4;
  31. +   else
  32. +       star_num = 5;
  33. +   space_num = 5 - star_num;
  34. +  
  35. +   int i = 0;
  36. +   while (star_num--)
  37. +       stars[i++] = filled_star;
  38. +   while (space_num--)
  39. +       stars[i++] = empty_star;
  40. +
  41. +   snprintf(buff, 16, "%s%s%s%s%s", stars[0], stars[1], stars[2],
  42. +           stars[3], stars[4]);
  43. +}
  44. diff -rup moc-2.5.0-beta1-clean2526//common.h moc-2.5.0-beta1-ratings/common.h
  45. --- moc-2.5.0-beta1-clean2526//common.h 2013-03-05 15:09:53.000000000 +0100
  46. +++ moc-2.5.0-beta1-ratings/common.h    2013-03-05 16:13:23.000000000 +0100
  47. @@ -118,6 +118,7 @@ bool is_valid_symbol (const char *candid
  48.  char *create_file_name (const char *file);
  49.  void sec_to_min (char *buff, const int seconds);
  50.  const char *get_home ();
  51. +void rating_to_str (char *buff, const int rating);
  52.  
  53.  #ifdef __cplusplus
  54.  }
  55. diff -rup moc-2.5.0-beta1-clean2526//decoder_plugins/aac/aac.c moc-2.5.0-beta1-ratings/decoder_plugins/aac/aac.c
  56. --- moc-2.5.0-beta1-clean2526//decoder_plugins/aac/aac.c    2013-03-05 15:09:53.000000000 +0100
  57. +++ moc-2.5.0-beta1-ratings/decoder_plugins/aac/aac.c   2013-03-05 20:58:40.000000000 +0100
  58. @@ -373,12 +373,24 @@ static char *get_tag (struct id3_tag *ta
  59.     return comm;
  60.  }
  61.  
  62. +int get_tag_rating (struct id3_tag *tag)
  63. +{
  64. +   struct id3_frame *frame;
  65. +   union id3_field *field;
  66. +
  67. +   frame = id3_tag_findframe (tag, "POPM", 0);
  68. +   if (frame && frame->nfields >= 2)
  69. +       return (int)id3_field_getint(&frame->fields[1]);
  70. +   else
  71. +       return 0;
  72. +}
  73. +
  74.  /* Fill info structure with data from aac comments */
  75.  static void aac_info (const char *file_name,
  76.         struct file_tags *info,
  77.         const int tags_sel)
  78.  {
  79. -   if (tags_sel & TAGS_COMMENTS) {
  80. +   if ((tags_sel & TAGS_COMMENTS) || (tags_sel & TAGS_RATING)) {
  81.         struct id3_tag *tag;
  82.         struct id3_file *id3file;
  83.         char *track = NULL;
  84. @@ -387,7 +399,8 @@ static void aac_info (const char *file_n
  85.         if (!id3file)
  86.             return;
  87.         tag = id3_file_tag (id3file);
  88. -       if (tag) {
  89. +
  90. +       if (tag && (tags_sel & TAGS_COMMENTS)) {
  91.             info->artist = get_tag (tag, ID3_FRAME_ARTIST);
  92.             info->title = get_tag (tag, ID3_FRAME_TITLE);
  93.             info->album = get_tag (tag, ID3_FRAME_ALBUM);
  94. @@ -402,6 +415,9 @@ static void aac_info (const char *file_n
  95.                 free (track);
  96.             }
  97.         }
  98. +       if (tag && (tags_sel & TAGS_RATING))
  99. +           info->rating = get_tag_rating (tag);
  100. +
  101.         id3_file_close (id3file);
  102.     }
  103.  
  104. diff -rup moc-2.5.0-beta1-clean2526//decoder_plugins/flac/flac.c moc-2.5.0-beta1-ratings/decoder_plugins/flac/flac.c
  105. --- moc-2.5.0-beta1-clean2526//decoder_plugins/flac/flac.c  2013-03-05 15:09:53.000000000 +0100
  106. +++ moc-2.5.0-beta1-ratings/decoder_plugins/flac/flac.c 2013-03-05 16:22:09.000000000 +0100
  107. @@ -423,7 +423,7 @@ static void flac_close (void *void_data)
  108.  }
  109.  
  110.  static void fill_tag (FLAC__StreamMetadata_VorbisComment_Entry *comm,
  111. -       struct file_tags *tags)
  112. +       struct file_tags *tags, const bool get_rating)
  113.  {
  114.     char *name, *value;
  115.     FLAC__byte *eq;
  116. @@ -457,14 +457,18 @@ static void fill_tag (FLAC__StreamMetada
  117.             || !strcasecmp(name, "track")) {
  118.         tags->track = atoi (value);
  119.         free (value);
  120. -   }
  121. -   else
  122. +   } else if (get_rating && !strncasecmp(name, "rating:",
  123. +           strlen("rating:"))) {
  124. +       tags->rating = (int)(255 * atof(value));
  125. +       free (value);
  126. +   } else
  127.         free (value);
  128.  
  129.     free (name);
  130.  }
  131.  
  132. -static void get_vorbiscomments (const char *filename, struct file_tags *tags)
  133. +static void get_vorbiscomments (const char *filename, struct file_tags *tags,
  134. +       const bool get_rating)
  135.  {
  136.     FLAC__Metadata_SimpleIterator *iterator
  137.         = FLAC__metadata_simple_iterator_new();
  138. @@ -497,7 +501,7 @@ static void get_vorbiscomments (const ch
  139.                     = &block->data.vorbis_comment;
  140.  
  141.                 for (i = 0; i < vc->num_comments; i++)
  142. -                   fill_tag (&vc->comments[i], tags);
  143. +                   fill_tag (&vc->comments[i], tags, get_rating);
  144.  
  145.                 FLAC__metadata_object_delete (block);
  146.                 got_vorbis_comments = true;
  147. @@ -522,7 +526,7 @@ static void flac_info (const char *file_
  148.     }
  149.  
  150.     if (tags_sel & TAGS_COMMENTS)
  151. -       get_vorbiscomments (file_name, info);
  152. +       get_vorbiscomments (file_name, info, tags_sel & TAGS_RATING);
  153.  }
  154.  
  155.  static int flac_seek (void *void_data, int sec)
  156. diff -rup moc-2.5.0-beta1-clean2526//decoder_plugins/mp3/mp3.c moc-2.5.0-beta1-ratings/decoder_plugins/mp3/mp3.c
  157. --- moc-2.5.0-beta1-clean2526//decoder_plugins/mp3/mp3.c    2013-03-05 15:09:53.000000000 +0100
  158. +++ moc-2.5.0-beta1-ratings/decoder_plugins/mp3/mp3.c   2013-03-05 20:58:22.000000000 +0100
  159. @@ -184,6 +184,18 @@ static char *get_tag (struct id3_tag *ta
  160.     return comm;
  161.  }
  162.  
  163. +int get_tag_rating (struct id3_tag *tag)
  164. +{
  165. +   struct id3_frame *frame;
  166. +   union id3_field *field;
  167. +
  168. +   frame = id3_tag_findframe (tag, "POPM", 0);
  169. +   if (frame && frame->nfields >= 2)
  170. +       return (int)id3_field_getint(&frame->fields[1]);
  171. +   else
  172. +       return 0;
  173. +}
  174. +
  175.  static int count_time_internal (struct mp3_data *data)
  176.  {
  177.     struct xing xing;
  178. @@ -453,7 +465,7 @@ static void mp3_info (const char *file_n
  179.         const int tags_sel)
  180.  {
  181.  
  182. -   if (tags_sel & TAGS_COMMENTS) {
  183. +   if ((tags_sel & TAGS_COMMENTS) || (tags_sel & TAGS_RATING)) {
  184.         struct id3_tag *tag;
  185.         struct id3_file *id3file;
  186.         char *track = NULL;
  187. @@ -462,7 +474,8 @@ static void mp3_info (const char *file_n
  188.         if (!id3file)
  189.             return;
  190.         tag = id3_file_tag (id3file);
  191. -       if (tag) {
  192. +
  193. +       if (tag && (tags_sel & TAGS_COMMENTS)) {
  194.             info->artist = get_tag (tag, ID3_FRAME_ARTIST);
  195.             info->title = get_tag (tag, ID3_FRAME_TITLE);
  196.             info->album = get_tag (tag, ID3_FRAME_ALBUM);
  197. @@ -477,6 +490,9 @@ static void mp3_info (const char *file_n
  198.                 free (track);
  199.             }
  200.         }
  201. +       if (tag && (tags_sel & TAGS_RATING))
  202. +           info->rating = get_tag_rating (tag);
  203. +
  204.         id3_file_close (id3file);
  205.     }
  206.  
  207. diff -rup moc-2.5.0-beta1-clean2526//decoder_plugins/vorbis/vorbis.c moc-2.5.0-beta1-ratings/decoder_plugins/vorbis/vorbis.c
  208. --- moc-2.5.0-beta1-clean2526//decoder_plugins/vorbis/vorbis.c  2013-03-05 15:09:53.000000000 +0100
  209. +++ moc-2.5.0-beta1-ratings/decoder_plugins/vorbis/vorbis.c 2013-03-05 16:36:03.000000000 +0100
  210. @@ -68,9 +68,11 @@ struct vorbis_data
  211.     struct file_tags *tags;
  212.  };
  213.  
  214. -static void get_comment_tags (OggVorbis_File *vf, struct file_tags *info)
  215. +static void get_comment_tags (OggVorbis_File *vf, struct file_tags *info,
  216. +       const bool get_rating)
  217.  {
  218.     int i;
  219. +   char * rating_str = 0;
  220.     vorbis_comment *comments;
  221.  
  222.     comments = ov_comment (vf, -1);
  223. @@ -98,6 +100,10 @@ static void get_comment_tags (OggVorbis_
  224.                     "track=", strlen ("track=")))
  225.             info->track = atoi (comments->user_comments[i]
  226.                     + strlen ("track="));
  227. +       else if (get_rating && !strncasecmp(comments->user_comments[i],
  228. +                   "rating:", strlen ("rating:")) &&
  229. +               (rating_str = strchr(comments->user_comments[i], '=')))
  230. +           info->rating = (int)(255 * atof(rating_str + 1));
  231.     }
  232.  }
  233.  
  234. @@ -168,7 +174,7 @@ static void vorbis_tags (const char *fil
  235.     }
  236.  
  237.     if (tags_sel & TAGS_COMMENTS)
  238. -       get_comment_tags (&vf, info);
  239. +       get_comment_tags (&vf, info, tags_sel & TAGS_RATING);
  240.  
  241.     if (tags_sel & TAGS_TIME) {
  242.         int64_t vorbis_time;
  243. @@ -254,7 +260,7 @@ static void vorbis_open_stream_internal
  244.         if (duration >= 0)
  245.             data->duration = duration / time_scaler;
  246.         data->ok = 1;
  247. -       get_comment_tags (&data->vf, data->tags);
  248. +       get_comment_tags (&data->vf, data->tags, true);
  249.     }
  250.  }
  251.  
  252. @@ -364,7 +370,7 @@ static int vorbis_decode (void *prv_data
  253.             data->tags_change = 1;
  254.             tags_free (data->tags);
  255.             data->tags = tags_new ();
  256. -           get_comment_tags (&data->vf, data->tags);
  257. +           get_comment_tags (&data->vf, data->tags, true);
  258.         }
  259.  
  260.         info = ov_info (&data->vf, -1);
  261. diff -rup moc-2.5.0-beta1-clean2526//interface.c moc-2.5.0-beta1-ratings/interface.c
  262. --- moc-2.5.0-beta1-clean2526//interface.c  2013-03-05 15:09:53.000000000 +0100
  263. +++ moc-2.5.0-beta1-ratings/interface.c 2013-03-05 16:27:14.000000000 +0100
  264. @@ -553,8 +553,12 @@ static int get_tags_setting ()
  265.  {
  266.     int needed_tags = 0;
  267.  
  268. -   if (options_get_int("ReadTags"))
  269. +   if (options_get_int("ReadTags")) {
  270.         needed_tags |= TAGS_COMMENTS;
  271. +
  272. +       if (options_get_int("ShowRating"))
  273. +           needed_tags |= TAGS_RATING;
  274. +    }
  275.     if (!strcasecmp(options_get_str("ShowTime"), "yes"))
  276.         needed_tags |= TAGS_TIME;
  277.  
  278. @@ -857,8 +861,13 @@ static void event_plist_add (const struc
  279.         int i;
  280.  
  281.         if (options_get_int("ReadTags")
  282. -               && (!item->tags || !item->tags->title))
  283. +               && (!item->tags || !item->tags->title)) {
  284.             needed_tags |= TAGS_COMMENTS;
  285. +
  286. +           if (options_get_int("ShowRating")
  287. +                   && (!item->tags || item->tags->rating == -1))
  288. +               needed_tags |= TAGS_RATING;
  289. +       }
  290.         if (!strcasecmp(options_get_str("ShowTime"), "yes")
  291.                 && (!item->tags || item->tags->time == -1))
  292.             needed_tags |= TAGS_TIME;
  293. diff -rup moc-2.5.0-beta1-clean2526//interface_elements.c moc-2.5.0-beta1-ratings/interface_elements.c
  294. --- moc-2.5.0-beta1-clean2526//interface_elements.c 2013-03-05 15:09:53.000000000 +0100
  295. +++ moc-2.5.0-beta1-ratings/interface_elements.c    2013-03-05 16:36:15.000000000 +0100
  296. @@ -802,6 +802,8 @@ static void side_menu_init (struct side_
  297.                 options_get_int("ShowFormat"));
  298.         menu_set_show_time (m->menu.list.main,
  299.                 strcasecmp(options_get_str("ShowTime"), "no"));
  300. +       menu_set_show_rating (m->menu.list.main,
  301. +               options_get_int("ReadTags") && options_get_int("ShowRating"));
  302.         menu_set_info_attr_normal (m->menu.list.main,
  303.                 get_color(CLR_MENU_ITEM_INFO));
  304.         menu_set_info_attr_sel (m->menu.list.main,
  305. @@ -1078,6 +1080,13 @@ static int add_to_menu (struct menu *men
  306.         menu_item_set_time (added, time_str);
  307.     }
  308.  
  309. +   if (item->tags && item->tags->rating != -1) {
  310. +       char rating_str[16];
  311. +
  312. +       rating_to_str (rating_str, item->tags->rating);
  313. +       menu_item_set_rating (added, rating_str);
  314. +   }
  315. +
  316.     menu_item_set_attr_normal (added, get_color(CLR_MENU_ITEM_FILE));
  317.     menu_item_set_attr_sel (added, get_color(CLR_MENU_ITEM_FILE_SELECTED));
  318.     menu_item_set_attr_marked (added, get_color(CLR_MENU_ITEM_FILE_MARKED));
  319. @@ -1111,6 +1120,8 @@ static void side_menu_clear (struct side
  320.     menu_set_show_format (m->menu.list.main, options_get_int("ShowFormat"));
  321.     menu_set_show_time (m->menu.list.main,
  322.             strcasecmp(options_get_str("ShowTime"), "no"));
  323. +   menu_set_show_rating (m->menu.list.main,
  324. +           options_get_int("ReadTags") && options_get_int("ShowRating"));
  325.     menu_set_info_attr_normal (m->menu.list.main, get_color(CLR_MENU_ITEM_INFO));
  326.     menu_set_info_attr_sel (m->menu.list.main, get_color(CLR_MENU_ITEM_INFO_SELECTED));
  327.     menu_set_info_attr_marked (m->menu.list.main, get_color(CLR_MENU_ITEM_INFO_MARKED));
  328. @@ -1433,6 +1444,15 @@ static void update_menu_item (struct men
  329.     else
  330.         menu_item_set_time (mi, "");
  331.  
  332. +   if (item->tags && item->tags->rating != -1) {
  333. +       char rating_str[16];
  334. +
  335. +       rating_to_str (rating_str, item->tags->rating);
  336. +       menu_item_set_rating (mi, rating_str);
  337. +   }
  338. +   else
  339. +       menu_item_set_rating (mi, "");
  340. +
  341.     made_from_tags = (options_get_bool ("ReadTags") && item->title_tags);
  342.  
  343.     if (made_from_tags)
  344. diff -rup moc-2.5.0-beta1-clean2526//menu.c moc-2.5.0-beta1-ratings/menu.c
  345. --- moc-2.5.0-beta1-clean2526//menu.c   2013-03-05 15:09:53.000000000 +0100
  346. +++ moc-2.5.0-beta1-ratings/menu.c  2013-03-05 16:44:20.000000000 +0100
  347. @@ -125,15 +125,56 @@ static void draw_item (const struct menu
  348.         xwaddstr (menu->win, "]");
  349.     }
  350.  
  351. -   if (menu->show_time && menu->show_format
  352. -           && (*mi->time || *mi->format))
  353. -       xwprintw (menu->win, "[%5s|%3s]",
  354. -               mi->time ? mi->time : "  ",
  355. -               mi->format);
  356. -   else if (menu->show_time && mi->time[0])
  357. -       xwprintw (menu->win, "[%5s]", mi->time);
  358. -   else if (menu->show_format && mi->format[0])
  359. -       xwprintw (menu->win, "[%3s]", mi->format);
  360. +   int show_details_num = 0;
  361. +   show_details_num += (int)(menu->show_time != 0);
  362. +   show_details_num += (int)(menu->show_format != 0);
  363. +   show_details_num += (int)(menu->show_rating != 0);
  364. +
  365. +   bool show_details = (show_details_num > 0)
  366. +           && (*mi->rating != 0 || *mi->time || *mi->format);
  367. +
  368. +   if (show_details) {
  369. +       int separators = show_details_num - 1;
  370. +
  371. +       xwprintw (menu->win, "[");
  372. +
  373. +       if (menu->show_rating) {
  374. +
  375. +           /* Change the rating theme.
  376. +              TODO: Define new attrs for rating stars? */
  377. +           if (mi == menu->marked)
  378. +               wattrset (menu->win, mi->attr_marked);
  379. +           else
  380. +               wattrset (menu->win, mi->attr_normal);
  381. +
  382. +           wattroff (menu->win, A_BOLD); /* Some chars cannot be bold. */
  383. +
  384. +           xwprintw (menu->win, "%5s",
  385. +                   *mi->rating != 0 ? mi->rating : "     ");
  386. +
  387. +           /* Restore the theme. */
  388. +           if (draw_selected && mi == menu->selected && mi == menu->marked)
  389. +               wattrset (menu->win, menu->info_attr_sel_marked);
  390. +           else if (draw_selected && mi == menu->selected)
  391. +               wattrset (menu->win, menu->info_attr_sel);
  392. +           else if (mi == menu->marked)
  393. +               wattrset (menu->win, menu->info_attr_marked);
  394. +           else
  395. +               wattrset (menu->win, menu->info_attr_normal);
  396. +
  397. +           if (separators--)
  398. +               xwprintw(menu->win, "|");
  399. +       }
  400. +       if (menu->show_time) {
  401. +           xwprintw (menu->win, "%5s", mi->time ? mi->time : "  ");
  402. +           if (separators--)
  403. +               xwprintw(menu->win, "|");
  404. +       }
  405. +       if (menu->show_format && *mi->format)
  406. +           xwprintw (menu->win, "%3s", mi->format);
  407. +
  408. +       xwprintw (menu->win, "]");
  409. +   }
  410.  }
  411.  
  412.  void menu_draw (const struct menu *menu, const int active)
  413. @@ -142,6 +183,7 @@ void menu_draw (const struct menu *menu,
  414.     int title_width;
  415.     int info_pos;
  416.     int number_space = 0;
  417. +   int show_details_num = 0;
  418.  
  419.     assert (menu != NULL);
  420.  
  421. @@ -157,16 +199,22 @@ void menu_draw (const struct menu *menu,
  422.     else
  423.         number_space = 0;
  424.  
  425. -   if (menu->show_time || menu->show_format) {
  426. +   show_details_num += (int)(menu->show_time != 0);
  427. +   show_details_num += (int)(menu->show_format != 0);
  428. +   show_details_num += (int)(menu->show_rating != 0);
  429. +   if (show_details_num > 0) {
  430. +
  431.         title_width = menu->width - 2; /* -2 for brackets */
  432. +
  433. +       if (menu->show_rating)
  434. +           title_width -= 5; /* 5 rating stars */
  435.         if (menu->show_time)
  436.             title_width -= 5; /* 00:00 */
  437.         if (menu->show_format)
  438.             title_width -= 3; /* MP3 */
  439. -       if (menu->show_time && menu->show_format)
  440. -           title_width--; /* for | */
  441. -       info_pos = title_width;
  442. -   }
  443. +       title_width -= show_details_num - 1; /* for | */
  444. +       info_pos = title_width;
  445. +   }
  446.     else {
  447.         title_width = menu->width;
  448.         info_pos = title_width;
  449. @@ -234,6 +282,7 @@ struct menu *menu_new (WINDOW *win, cons
  450.     menu->marked = NULL;
  451.     menu->show_time = 0;
  452.     menu->show_format = 0;
  453. +   menu->show_rating = 0;
  454.     menu->info_attr_normal = A_NORMAL;
  455.     menu->info_attr_sel = A_NORMAL;
  456.     menu->info_attr_marked = A_NORMAL;
  457. @@ -268,6 +317,7 @@ struct menu_item *menu_add (struct menu
  458.  
  459.     mi->time[0] = 0;
  460.     mi->format[0] = 0;
  461. +   mi->rating[0] = 0;
  462.     mi->queue_pos = 0;
  463.  
  464.     mi->next = NULL;
  465. @@ -308,6 +358,7 @@ static struct menu_item *menu_add_from_i
  466.  
  467.     strncpy(new->time, mi->time, FILE_TIME_STR_SZ);
  468.     strncpy(new->format, mi->format, FILE_FORMAT_SZ);
  469. +   strncpy(new->rating, mi->rating, FILE_RATING_SZ);
  470.  
  471.     return new;
  472.  }
  473. @@ -562,6 +613,7 @@ struct menu *menu_filter_pattern (const
  474.             menu->height);
  475.     menu_set_show_time (new, menu->show_time);
  476.     menu_set_show_format (new, menu->show_format);
  477. +   menu_set_show_rating (new, menu->show_rating);
  478.     menu_set_info_attr_normal (new, menu->info_attr_normal);
  479.     menu_set_info_attr_sel (new, menu->info_attr_sel);
  480.     menu_set_info_attr_marked (new, menu->info_attr_marked);
  481. @@ -626,6 +678,15 @@ void menu_item_set_format (struct menu_i
  482.             == 0);
  483.  }
  484.  
  485. +void menu_item_set_rating (struct menu_item *mi, const char *rating)
  486. +{
  487. +   assert (mi != NULL);
  488. +
  489. +   mi->rating[sizeof(mi->rating)-1] = 0;
  490. +   strncpy (mi->rating, rating, sizeof(mi->rating));
  491. +   assert (mi->rating[sizeof(mi->rating)-1] == 0);
  492. +}
  493. +
  494.  void menu_item_set_queue_pos (struct menu_item *mi, const int pos)
  495.  {
  496.     assert (mi != NULL);
  497. @@ -647,6 +708,13 @@ void menu_set_show_format (struct menu *
  498.     menu->show_format = t;
  499.  }
  500.  
  501. +void menu_set_show_rating (struct menu *menu, const int t)
  502. +{
  503. +   assert (menu != NULL);
  504. +
  505. +   menu->show_rating = t;
  506. +}
  507. +
  508.  void menu_set_info_attr_normal (struct menu *menu, const int attr)
  509.  {
  510.     assert (menu != NULL);
  511. diff -rup moc-2.5.0-beta1-clean2526//menu.h moc-2.5.0-beta1-ratings/menu.h
  512. --- moc-2.5.0-beta1-clean2526//menu.h   2013-03-05 15:09:53.000000000 +0100
  513. +++ moc-2.5.0-beta1-ratings/menu.h  2013-03-05 16:11:37.000000000 +0100
  514. @@ -34,6 +34,7 @@ enum menu_align
  515.  
  516.  #define FILE_TIME_STR_SZ        6
  517.  #define FILE_FORMAT_SZ          4
  518. +#define FILE_RATING_SZ         16
  519.  
  520.  struct menu_item
  521.  {
  522. @@ -54,6 +55,7 @@ struct menu_item
  523.     /* Additional information shown: */
  524.     char time[FILE_TIME_STR_SZ];        /* File time string */
  525.     char format[FILE_FORMAT_SZ];        /* File format */
  526. +   char rating[FILE_RATING_SZ];        /* Rating */
  527.     int queue_pos;              /* Position in the queue */
  528.  
  529.     struct menu_item *next;
  530. @@ -80,6 +82,7 @@ struct menu
  531.     /* Flags for displaying information about the file. */
  532.     int show_time;
  533.     int show_format;
  534. +   int show_rating;
  535.  
  536.     int info_attr_normal;   /* attributes for information about the file */
  537.     int info_attr_sel;
  538. @@ -110,6 +113,7 @@ void menu_item_set_attr_marked (struct m
  539.  
  540.  void menu_item_set_time (struct menu_item *mi, const char *time);
  541.  void menu_item_set_format (struct menu_item *mi, const char *format);
  542. +void menu_item_set_rating (struct menu_item *mi, const char *rating);
  543.  void menu_item_set_queue_pos (struct menu_item *mi, const int pos);
  544.  
  545.  void menu_free (struct menu *menu);
  546. @@ -126,6 +130,7 @@ void menu_unmark_item (struct menu *menu
  547.  struct menu *menu_filter_pattern (const struct menu *menu, const char *pattern);
  548.  void menu_set_show_time (struct menu *menu, const int t);
  549.  void menu_set_show_format (struct menu *menu, const int t);
  550. +void menu_set_show_rating (struct menu *menu, const int t);
  551.  void menu_set_info_attr_normal (struct menu *menu, const int attr);
  552.  void menu_set_info_attr_sel (struct menu *menu, const int attr);
  553.  void menu_set_info_attr_marked (struct menu *menu, const int attr);
  554. diff -rup moc-2.5.0-beta1-clean2526//options.c moc-2.5.0-beta1-ratings/options.c
  555. --- moc-2.5.0-beta1-clean2526//options.c    2013-03-05 15:09:53.000000000 +0100
  556. +++ moc-2.5.0-beta1-ratings/options.c   2013-03-05 15:57:02.000000000 +0100
  557. @@ -602,6 +602,7 @@ void options_init ()
  558.     add_bool ("ShowFormat", true);
  559.     add_symb ("ShowTime", "IfAvailable",
  560.                      CHECK_SYMBOL(3), "yes", "no", "IfAvailable");
  561. +   add_bool ("ShowRating", true);
  562.     add_bool ("ShowTimePercent", false);
  563.  
  564.     add_list ("XTerms", "xterm:"
  565. diff -rup moc-2.5.0-beta1-clean2526//playlist.c moc-2.5.0-beta1-ratings/playlist.c
  566. --- moc-2.5.0-beta1-clean2526//playlist.c   2013-03-05 15:09:53.000000000 +0100
  567. +++ moc-2.5.0-beta1-ratings/playlist.c  2013-03-05 15:56:30.000000000 +0100
  568. @@ -67,6 +67,7 @@ void tags_clear (struct file_tags *tags)
  569.     tags->album = NULL;
  570.     tags->track = -1;
  571.     tags->time = -1;
  572. +   tags->rating = -1;
  573.  }
  574.  
  575.  /* Copy the tags data from src to dst freeing old fields if necessary. */
  576. @@ -86,6 +87,7 @@ void tags_copy (struct file_tags *dst, c
  577.  
  578.     dst->track = src->track;
  579.     dst->time = src->time;
  580. +   dst->rating = src->rating;
  581.     dst->filled = src->filled;
  582.  }
  583.  
  584. @@ -99,6 +101,7 @@ struct file_tags *tags_new ()
  585.     tags->album = NULL;
  586.     tags->track = -1;
  587.     tags->time = -1;
  588. +   tags->rating = -1;
  589.     tags->filled = 0;
  590.  
  591.     return tags;
  592. diff -rup moc-2.5.0-beta1-clean2526//playlist_file.c moc-2.5.0-beta1-ratings/playlist_file.c
  593. --- moc-2.5.0-beta1-clean2526//playlist_file.c  2013-03-05 15:09:53.000000000 +0100
  594. +++ moc-2.5.0-beta1-ratings/playlist_file.c 2013-03-05 15:55:28.000000000 +0100
  595. @@ -355,6 +355,7 @@ static int plist_load_pls (struct plist
  596.                     plist->items[last_added].tags->time = time;
  597.                     plist->items[last_added].tags->filled |= TAGS_TIME;
  598.                 }
  599. +               plist->items[last_added].tags->rating = -1;
  600.             }
  601.         }
  602.  
  603. diff -rup moc-2.5.0-beta1-clean2526//playlist.h moc-2.5.0-beta1-ratings/playlist.h
  604. --- moc-2.5.0-beta1-clean2526//playlist.h   2013-03-05 15:09:53.000000000 +0100
  605. +++ moc-2.5.0-beta1-ratings/playlist.h  2013-03-05 15:55:06.000000000 +0100
  606. @@ -20,7 +20,8 @@ typedef int plist_t_item_ix;
  607.  enum tags_select
  608.  {
  609.     TAGS_COMMENTS   = 0x01, /* artist, title, etc. */
  610. -   TAGS_TIME   = 0x02 /* time of the file. */
  611. +   TAGS_TIME   = 0x02, /* time of the file. */
  612. +   TAGS_RATING = 0x04 /* rating */
  613.  };
  614.  
  615.  struct file_tags
  616. @@ -30,6 +31,7 @@ struct file_tags
  617.     char *album;
  618.     int track;
  619.     int time;
  620. +   int rating;
  621.     int filled; /* Which tags are filled: TAGS_COMMENTS, TAGS_TIME. */
  622.  };
  623.  
  624. diff -rup moc-2.5.0-beta1-clean2526//protocol.c moc-2.5.0-beta1-ratings/protocol.c
  625. --- moc-2.5.0-beta1-clean2526//protocol.c   2013-03-05 15:09:53.000000000 +0100
  626. +++ moc-2.5.0-beta1-ratings/protocol.c  2013-03-05 15:53:47.000000000 +0100
  627. @@ -283,6 +283,7 @@ void packet_buf_add_tags (struct packet_
  628.         packet_buf_add_str (b, tags->album ? tags->album : "");
  629.         packet_buf_add_int (b, tags->track);
  630.         packet_buf_add_int (b, tags->filled & TAGS_TIME ? tags->time : -1);
  631. +       packet_buf_add_int (b, tags->filled & TAGS_RATING ? tags->rating : -1);
  632.         packet_buf_add_int (b, tags->filled);
  633.     }
  634.     else {
  635. @@ -293,6 +294,7 @@ void packet_buf_add_tags (struct packet_
  636.         packet_buf_add_str (b, ""); /* album */
  637.         packet_buf_add_int (b, -1); /* track */
  638.         packet_buf_add_int (b, -1); /* time */
  639. +       packet_buf_add_int (b, -1); /* rating */
  640.         packet_buf_add_int (b, 0); /* filled */
  641.     }
  642.  }
  643. @@ -383,6 +385,12 @@ struct file_tags *recv_tags (int sock)
  644.         tags_free (tags);
  645.         return NULL;
  646.     }
  647. +
  648. +   if (!get_int(sock, &tags->rating)) {
  649. +       logit ("Error while receiving 'rating'");
  650. +       tags_free (tags);
  651. +       return NULL;
  652. +   }
  653.  
  654.     if (!get_int(sock, &tags->filled)) {
  655.         logit ("Error while receiving 'filled'");
  656. diff -rup moc-2.5.0-beta1-clean2526//server.c moc-2.5.0-beta1-ratings/server.c
  657. --- moc-2.5.0-beta1-clean2526//server.c 2013-03-05 15:09:53.000000000 +0100
  658. +++ moc-2.5.0-beta1-ratings/server.c    2013-03-05 15:52:49.000000000 +0100
  659. @@ -462,7 +462,7 @@ static void on_song_change ()
  660.     }
  661.  
  662.     curr_tags = tags_cache_get_immediate (&tags_cache, curr_file,
  663. -                                         TAGS_COMMENTS | TAGS_TIME);
  664. +                                         TAGS_COMMENTS | TAGS_TIME | TAGS_RATING);
  665.     arg_list = lists_strs_new (lists_strs_size (on_song_change));
  666.     for (ix = 0; ix < lists_strs_size (on_song_change); ix += 1) {
  667.         char *arg, *str;
  668. diff -rup moc-2.5.0-beta1-clean2526//tags_cache.c moc-2.5.0-beta1-ratings/tags_cache.c
  669. --- moc-2.5.0-beta1-clean2526//tags_cache.c 2013-03-05 15:09:53.000000000 +0100
  670. +++ moc-2.5.0-beta1-ratings/tags_cache.c    2013-03-05 15:52:15.000000000 +0100
  671. @@ -217,7 +217,8 @@ static char *cache_record_serialize (con
  672.         + album_len
  673.         + title_len
  674.         + sizeof(rec->tags->track)
  675. -       + sizeof(rec->tags->time);
  676. +       + sizeof(rec->tags->time)
  677. +       + sizeof(rec->tags->rating);
  678.  
  679.     buf = p = (char *)xmalloc (*len);
  680.  
  681. @@ -254,6 +255,9 @@ static char *cache_record_serialize (con
  682.     memcpy (p, &rec->tags->time, sizeof(rec->tags->time));
  683.     p += sizeof(rec->tags->time);
  684.  
  685. +   memcpy (p, &rec->tags->rating, sizeof(rec->tags->rating));
  686. +   p += sizeof(rec->tags->rating);
  687. +
  688.     return buf;
  689.  }
  690.  #endif
  691. @@ -302,6 +306,7 @@ static int cache_record_deserialize (str
  692.         extract_str (rec->tags->title);
  693.         extract_num (rec->tags->track);
  694.         extract_num (rec->tags->time);
  695. +       extract_num (rec->tags->rating);
  696.  
  697.         if (rec->tags->title)
  698.             rec->tags->filled |= TAGS_COMMENTS;
  699. @@ -318,6 +323,9 @@ static int cache_record_deserialize (str
  700.  
  701.         if (rec->tags->time >= 0)
  702.             rec->tags->filled |= TAGS_TIME;
  703. +
  704. +       if (rec->tags->rating >= 0)
  705. +           rec->tags->filled |= TAGS_RATING;
  706.     }
  707.  
  708.     return 1;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement