maps.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /* $Id: maps.c,v 1.10 2001/04/20 09:47:49 kilobug Exp $ */
  2. #include "mclient.h"
  3. int map_sort(GtkCList *clist, gconstpointer ptr1, gconstpointer ptr2)
  4. {
  5. int i = 0;
  6. switch (clist->sort_column)
  7. {
  8. case 0: case 1: case 3:
  9. return clist_compare_str(clist, ptr1, ptr2);
  10. case 2:
  11. return clist_compare_float(clist, ptr1, ptr2);
  12. case 4:
  13. i = clist_compare_float(clist, ptr1, ptr2);
  14. if (i == 0)
  15. i = clist_compare_str(clist, ptr1, ptr2);
  16. return i;
  17. }
  18. return 0;
  19. }
  20. static char *map_owner(const char *val, void *data)
  21. {
  22. int i;
  23. i = atoi(val);
  24. if (i < 0)
  25. return g_strdup("Prologin");
  26. else
  27. return mysql_get_str(gl_config->mysql,
  28. "SELECT pseudo FROM Bitmaps WHERE id=%d", i);
  29. }
  30. static GdkColor *map_color(const sql_list_t *l, int id, void *data)
  31. {
  32. GdkColor *col = NULL;
  33. int auteur;
  34. auteur = mysql_get_int(gl_config->mysql,
  35. "SELECT auteur FROM Maps WHERE id=%d", id);
  36. if ((auteur == -1) || (mysql_get_int(gl_config->mysql,
  37. "SELECT staff FROM Bitmaps "
  38. "WHERE id=%d", auteur)))
  39. {
  40. col = g_malloc(sizeof(*col));
  41. gdk_color_parse("blue", col);
  42. }
  43. else
  44. if (auteur == getuid())
  45. {
  46. col = g_malloc(sizeof(*col));
  47. gdk_color_parse("#009000", col);
  48. }
  49. if (col != NULL)
  50. gdk_color_alloc(gdk_colormap_get_system(), col);
  51. return col;
  52. }
  53. void map_refresh(GtkWidget *wid, void *data)
  54. {
  55. static sql_list_t *lst = NULL;
  56. char *buf;
  57. if (lst == NULL)
  58. {
  59. buf = g_malloc(MYSQL_BUFFER_SIZE);
  60. g_snprintf(buf, MYSQL_BUFFER_SIZE,
  61. "SELECT id, nom, descr, joueurs, auteur, taille "
  62. "FROM Maps "
  63. "WHERE (actif) "
  64. " AND ((public) OR (auteur = %d) OR (%d = 1))",
  65. getuid(), gl_config->staff);
  66. lst = mysql_list_make(buf, 6, GTK_CLIST(gl_config->mapl),
  67. 4, map_owner, g_free, NULL, -1);
  68. mysql_list_set_color_func(lst, map_color, NULL);
  69. }
  70. mysql_list_refresh(lst, NULL);
  71. }
  72. void map_add(GtkWidget *wid, void *data)
  73. {
  74. gtk_widget_show(gl_config->mapa->widget);
  75. }
  76. void map_remove(GtkWidget *wid, void *data)
  77. {
  78. mysql_list_remove("Maps", GTK_CLIST(gl_config->mapl), map_refresh);
  79. }
  80. void map_edit(GtkWidget *wid, void *data)
  81. {
  82. mysql_list_edit("Modification d'une carte", GTK_CLIST(gl_config->mapl),
  83. gl_config->mapa, map_refresh);
  84. }