Diff of /trunk/src/cache.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 138 by harbaum, Tue Oct 20 13:25:04 2009 UTC revision 158 by harbaum, Wed Nov 4 14:54:52 2009 UTC
# Line 22  Line 22 
22    
23  static GtkWidget *cache_description(appdata_t *appdata, cache_t *cache) {  static GtkWidget *cache_description(appdata_t *appdata, cache_t *cache) {
24    return html_view(appdata, cache->long_description,    return html_view(appdata, cache->long_description,
25                     cache->long_is_html, TRUE, cache, NULL);             cache->long_is_html?HTML_HTML:HTML_PLAIN_TEXT, TRUE, cache, NULL);
26  }  }
27    
28  #ifndef USE_MAEMO  // maemos touchscreen doesn't support tooltips  #ifndef USE_MAEMO  // maemos touchscreen doesn't support tooltips
# Line 100  void overview_coordinate_update(cache_co Line 100  void overview_coordinate_update(cache_co
100    gtk_widget_show_all(context->bearing_hbox);    gtk_widget_show_all(context->bearing_hbox);
101  }  }
102    
103    static void gcvote_callback(vote_t *vote, gpointer data) {
104      cache_context_t *context = (cache_context_t*)data;
105    
106      /* no vote returned: request failed, just cleanup */
107      if(!vote) {
108        printf("gcvote callback for failed request\n");
109    
110        gcvote_request_free(context->gcvote_request);
111        context->gcvote_request = NULL;
112        return FALSE;
113      }
114    
115      printf("gcvote callback is being called with a %d/%d\n",
116             vote->quality, vote->votes);
117    
118      /* update/draw the voting */
119      if(!context->quality) {
120    #ifndef USE_MAEMO
121        GtkTooltips *tips = gtk_tooltips_new();
122    #endif
123    
124        GtkWidget *ivbox = gtk_vbox_new(FALSE, 0);
125    
126        char *votes_str = g_strdup_printf(_("Quality (%d %s):"), vote->votes,
127                                          (vote->votes == 1)?_("vote"):_("votes"));
128        context->votes = GTK_LABEL_SMALL(votes_str);
129        gtk_box_pack_start(GTK_BOX(ivbox), context->votes, FALSE, FALSE, 0);
130        g_free(votes_str);
131        context->quality = icon_get_widget(ICON_STARS, (int)(vote->quality*2-2));
132        gtk_box_pack_start(GTK_BOX(ivbox), context->quality,
133                                   FALSE, FALSE, 0);
134    
135        GtkWidget *align = gtk_alignment_new(0.5, 0.5, 0.0, 0.0);
136        gtk_container_add(GTK_CONTAINER(align), ivbox);
137        gtk_box_pack_start_defaults(GTK_BOX(context->ratebox), align);
138    #ifndef USE_MAEMO
139        char *str = g_strdup_printf(_("Quality: %d"), vote->quality);
140        gtk_tooltips_set_tip(tips, ivbox, str, NULL);
141        g_free(str);
142    #endif
143    
144        gtk_widget_show_all(context->ratebox);
145    
146        gcvote_request_free(context->gcvote_request);
147        context->gcvote_request = NULL;
148      }
149    }
150    
151  static GtkWidget *cache_overview(cache_context_t *context) {  static GtkWidget *cache_overview(cache_context_t *context) {
152    GtkWidget *vbox, *ivbox;    GtkWidget *vbox, *ivbox;
153    GtkWidget *table, *tip;    GtkWidget *table, *tip;
# Line 161  static GtkWidget *cache_overview(cache_c Line 209  static GtkWidget *cache_overview(cache_c
209      gtk_table_attach(GTK_TABLE(table), ivbox, 1,2,1,2, FALSE,FALSE,0,0);      gtk_table_attach(GTK_TABLE(table), ivbox, 1,2,1,2, FALSE,FALSE,0,0);
210    }    }
211    
212      /* ----------- vbox containing all ratings ---------- */
213      GtkWidget *ratebox = context->ratebox = gtk_vbox_new(FALSE, 0);
214    
215    /* ----------- box containing difficulty rating ---------- */    /* ----------- box containing difficulty rating ---------- */
216    if(cache->difficulty != 0) {    if(cache->difficulty != 0) {
217      ivbox = gtk_vbox_new(FALSE, 0);      ivbox = gtk_vbox_new(FALSE, 0);
# Line 170  static GtkWidget *cache_overview(cache_c Line 221  static GtkWidget *cache_overview(cache_c
221      gtk_box_pack_start(GTK_BOX(ivbox),      gtk_box_pack_start(GTK_BOX(ivbox),
222                    icon_get_widget(ICON_STARS, (int)(cache->difficulty*2-2)),                    icon_get_widget(ICON_STARS, (int)(cache->difficulty*2-2)),
223                         FALSE, FALSE, 0);                         FALSE, FALSE, 0);
224      gtk_table_attach(GTK_TABLE(table), ivbox, 2,3,0,1,  
225                       GTK_EXPAND | GTK_FILL, 0, GTK_FILL, 0);      GtkWidget *align = gtk_alignment_new(0.5, 0.5, 0.0, 0.0);
226        gtk_container_add(GTK_CONTAINER(align), ivbox);
227        gtk_box_pack_start_defaults(GTK_BOX(ratebox), align);
228  #ifndef USE_MAEMO  #ifndef USE_MAEMO
229      sprintf(str, _("Difficulty: %.1f"), cache->difficulty);      sprintf(str, _("Difficulty: %.1f"), cache->difficulty);
230      gtk_tooltips_set_tip(tips, ivbox, str, NULL);      gtk_tooltips_set_tip(tips, ivbox, str, NULL);
# Line 186  static GtkWidget *cache_overview(cache_c Line 239  static GtkWidget *cache_overview(cache_c
239      gtk_box_pack_start(GTK_BOX(ivbox),      gtk_box_pack_start(GTK_BOX(ivbox),
240                         icon_get_widget(ICON_STARS, (int)(cache->terrain*2-2)),                         icon_get_widget(ICON_STARS, (int)(cache->terrain*2-2)),
241                         FALSE, FALSE, 0);                         FALSE, FALSE, 0);
242      gtk_table_attach(GTK_TABLE(table), ivbox, 2,3,1,2,      GtkWidget *align = gtk_alignment_new(0.5, 0.5, 0.0, 0.0);
243                       GTK_EXPAND | GTK_FILL, 0, GTK_FILL, 0);      gtk_container_add(GTK_CONTAINER(align), ivbox);
244        gtk_box_pack_start_defaults(GTK_BOX(ratebox), align);
245  #ifndef USE_MAEMO  #ifndef USE_MAEMO
246      sprintf(str, _("Terrain: %.1f"), cache->terrain);      sprintf(str, _("Terrain: %.1f"), cache->terrain);
247      gtk_tooltips_set_tip(tips, ivbox, str, NULL);      gtk_tooltips_set_tip(tips, ivbox, str, NULL);
248  #endif  #endif
249    }    }
250    
251      /* --------------------- GCVote ------------------------ */
252      /* gcvote if present and possible */
253    
254      context->gcvote_request =
255        gcvote_request(appdata, gcvote_callback, cache->url, context);
256    
257    #if 0
258      vote_t *vote = gcvote_get(appdata, cache->url);
259      if(vote) {
260        ivbox = gtk_vbox_new(FALSE, 0);
261    
262        char *votes_str = g_strdup_printf(_("Quality (%d %s):"), vote->votes,
263                                          (vote->votes == 1)?_("vote"):_("votes"));
264        gtk_box_pack_start(GTK_BOX(ivbox), GTK_LABEL_SMALL(votes_str),
265                           FALSE, FALSE, 0);
266        g_free(votes_str);
267        gtk_box_pack_start(GTK_BOX(ivbox),
268             icon_get_widget(ICON_STARS, (int)(vote->quality*2-2)), FALSE, FALSE, 0);
269    
270        GtkWidget *align = gtk_alignment_new(0.5, 0.5, 0.0, 0.0);
271        gtk_container_add(GTK_CONTAINER(align), ivbox);
272        gtk_box_pack_start_defaults(GTK_BOX(ratebox), align);
273    #ifndef USE_MAEMO
274        sprintf(str, _("Quality: %d"), vote->quality);
275        gtk_tooltips_set_tip(tips, ivbox, str, NULL);
276    #endif
277    
278        gcvote_free(vote);
279      }
280    #endif
281    
282      gtk_table_attach_defaults(GTK_TABLE(table), ratebox, 2,3,0,2);
283    
284      /* ----------------------------------------------------- */
285    
286    
287    /* ----------------- the two coordinates ----------------- */    /* ----------------- the two coordinates ----------------- */
288    /* ----------------- and the heading/distance ------------ */    /* ----------------- and the heading/distance ------------ */
289    pos_t *refpos = get_pos(appdata);    pos_t *refpos = get_pos(appdata);
# Line 223  static GtkWidget *cache_overview(cache_c Line 313  static GtkWidget *cache_overview(cache_c
313    gtk_box_pack_start(GTK_BOX(vbox), table, 0,0,0);    gtk_box_pack_start(GTK_BOX(vbox), table, 0,0,0);
314    gtk_box_pack_start(GTK_BOX(vbox), gtk_hseparator_new(),FALSE,FALSE,0);    gtk_box_pack_start(GTK_BOX(vbox), gtk_hseparator_new(),FALSE,FALSE,0);
315    
316      /* ----------------------------------------------------- */
317    
318    if(cache->short_description)    if(cache->short_description)
319      gtk_box_pack_start_defaults(GTK_BOX(vbox),      gtk_box_pack_start_defaults(GTK_BOX(vbox),
320          html_view(appdata, cache->short_description,          html_view(appdata, cache->short_description,
321                    cache->short_is_html, TRUE, cache, NULL));            cache->short_is_html?HTML_HTML:HTML_PLAIN_TEXT, TRUE, cache, NULL));
322    
323    return vbox;    return vbox;
324  }  }
# Line 272  static void on_decrypt(GtkWidget *widget Line 364  static void on_decrypt(GtkWidget *widget
364  static GtkWidget *cache_hint(appdata_t *appdata, cache_t *cache) {  static GtkWidget *cache_hint(appdata_t *appdata, cache_t *cache) {
365    /* encrypting/decrypting html is nothing we want to do */    /* encrypting/decrypting html is nothing we want to do */
366    if(cache->hint_is_html)    if(cache->hint_is_html)
367      return html_view(appdata, cache->hint, TRUE, TRUE, NULL, NULL);      return html_view(appdata, cache->hint, HTML_HTML, TRUE, NULL, NULL);
368    
369    /* we can now be sure that we are talking about pain text */    /* we can now be sure that we are talking about pain text */
370    GtkWidget *vbox = gtk_vbox_new(FALSE, 0);    GtkWidget *vbox = gtk_vbox_new(FALSE, 0);
371    
372    char *hint = strdup(cache->hint);    char *hint = strdup(cache->hint);
373    rot13(hint);    rot13(hint);
374    GtkWidget *view = html_view(appdata, hint, FALSE, TRUE, NULL, NULL);    GtkWidget *view =
375        html_view(appdata, hint, HTML_PLAIN_TEXT, TRUE, NULL, NULL);
376    gtk_box_pack_start_defaults(GTK_BOX(vbox), view);    gtk_box_pack_start_defaults(GTK_BOX(vbox), view);
377    free(hint);    free(hint);
378    
# Line 556  static GtkWidget *cache_logs(appdata_t * Line 649  static GtkWidget *cache_logs(appdata_t *
649    
650      if(log->text) {      if(log->text) {
651        gtk_table_attach_defaults(GTK_TABLE(table),        gtk_table_attach_defaults(GTK_TABLE(table),
652                  html_view(appdata, log->text, is_html, FALSE, NULL, NULL),          html_view(appdata, log->text,
653                  0, 3, cnt+3, cnt+4);                    is_html?HTML_HTML:HTML_CUSTOM_MARKUP, FALSE, NULL, NULL),
654                                    0, 3, cnt+3, cnt+4);
655      }      }
656    
657      log = log->next;      log = log->next;
658      cnt+=4;      cnt+=4;
659    }    }

Legend:
Removed from v.138  
changed lines
  Added in v.158