champions.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /* $Id: champions.c,v 1.10 2001/05/07 02:41:36 kilobug Exp $ */
  2. #include "mclient.h"
  3. int prg_sort(GtkCList *clist, gconstpointer ptr1, gconstpointer ptr2)
  4. {
  5. switch (clist->sort_column)
  6. {
  7. case 0: case 1: case 4:
  8. return clist_compare_str(clist, ptr1, ptr2);
  9. case 2: case 3:
  10. return clist_compare_float(clist, ptr1, ptr2);
  11. }
  12. return 0;
  13. }
  14. static GdkColor *prg_color(const sql_list_t *l, int id, void *data)
  15. {
  16. GdkColor *col = NULL;
  17. int auteur;
  18. auteur = mysql_get_int(gl_config->mysql,
  19. "SELECT auteur FROM Champions WHERE id=%d", id);
  20. if (auteur == getuid())
  21. {
  22. col = g_malloc(sizeof(*col));
  23. gdk_color_parse("#009000", col);
  24. }
  25. if (col != NULL)
  26. gdk_color_alloc(gdk_colormap_get_system(), col);
  27. return col;
  28. }
  29. void prg_refresh(GtkWidget *wid, void *data)
  30. {
  31. static sql_list_t *lst = NULL;
  32. char *buf;
  33. if (lst == NULL)
  34. {
  35. buf = g_malloc(MYSQL_BUFFER_SIZE);
  36. g_snprintf(buf, MYSQL_BUFFER_SIZE,
  37. "SELECT c.id, c.nom, b.pseudo, c.best, c.score, m.msg "
  38. "FROM Champions c, Bitmaps b, Msg m "
  39. "WHERE (c.auteur = b.id) AND (c.actif) AND (m.id = c.tourn)"
  40. " AND ((c.public) OR (c.auteur = %d) OR (%d = 1))",
  41. getuid(), gl_config->staff);
  42. lst = mysql_list_make(buf, 6, GTK_CLIST(gl_config->prgl), -1);
  43. mysql_list_set_color_func(lst, prg_color, NULL);
  44. }
  45. mysql_list_refresh(lst, NULL);
  46. }
  47. void prg_add(GtkWidget *wid, void *data)
  48. {
  49. gtk_widget_show(gl_config->prga->widget);
  50. }
  51. void prg_remove(GtkWidget *wid, void *data)
  52. {
  53. mysql_list_remove("Champions", GTK_CLIST(gl_config->prgl), prg_refresh);
  54. }
  55. void prg_edit(GtkWidget *wid, void *data)
  56. {
  57. mysql_list_edit("Modification d'un champion", GTK_CLIST(gl_config->prgl),
  58. gl_config->prga, prg_refresh);
  59. }