Diff of /branches/ports/maemo/src/josm_presets.c

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

revision 50 by achadwick, Thu Feb 5 10:34:53 2009 UTC revision 51 by harbaum, Thu Feb 5 20:08:46 2009 UTC
# Line 26  Line 26 
26  #error "Tree not enabled in libxml"  #error "Tree not enabled in libxml"
27  #endif  #endif
28    
29    #ifndef USE_HILDON
30    #include <libgnome/gnome-url.h>
31    #else
32    #include <tablet-browser-interface.h>
33    #endif
34    
35    typedef struct {
36      appdata_t *appdata;
37      char *link;
38    } www_context_t;
39    
40    /* ---------- simple interface to the systems web browser ---------- */
41    static void on_info(GtkWidget *widget, www_context_t *context) {
42    #ifndef USE_HILDON
43      /* taken from gnome-open, part of libgnome */
44      GError *err = NULL;
45      gnome_url_show(context->link, &err);
46    #else
47      osso_rpc_run_with_defaults(context->appdata->osso_context, "osso_browser",
48                                 OSSO_BROWSER_OPEN_NEW_WINDOW_REQ, NULL,
49                                 DBUS_TYPE_STRING, context->link,
50                                 DBUS_TYPE_BOOLEAN, FALSE, DBUS_TYPE_INVALID);
51    #endif
52    }
53    
54  /* --------------------- presets.xml parsing ----------------------- */  /* --------------------- presets.xml parsing ----------------------- */
55    
56  static gboolean xmlGetPropIs(xmlNode *node, char *prop, char *is) {  static gboolean xmlGetPropIs(xmlNode *node, char *prop, char *is) {
# Line 82  char *josm_icon_name_adjust(char *name) Line 107  char *josm_icon_name_adjust(char *name)
107  }  }
108    
109  /* parse children of a given node for into *widget */  /* parse children of a given node for into *widget */
110  static presets_widget_t **parse_widgets(xmlNode *a_node, presets_widget_t **widget) {  static presets_widget_t **parse_widgets(xmlNode *a_node,
111                                            presets_item_t *item,
112                                            presets_widget_t **widget) {
113    xmlNode *cur_node = NULL;    xmlNode *cur_node = NULL;
114    
115    for(cur_node = a_node->children; cur_node; cur_node = cur_node->next) {    for(cur_node = a_node->children; cur_node; cur_node = cur_node->next) {
116      if(cur_node->type == XML_ELEMENT_NODE) {      if(cur_node->type == XML_ELEMENT_NODE) {
117        if(strcasecmp((char*)cur_node->name, "label") == 0) {  
118          if(strcasecmp((char*)cur_node->name, "space") == 0) {
119    
120            /* --------- space widget --------- */
121            /* we are low on screen space on the handhelds, */
122            /* so we just ignore extra spaces */
123    #ifndef USE_HILDON
124            *widget = g_new0(presets_widget_t, 1);
125            (*widget)->type = WIDGET_TYPE_SPACE;
126    #endif
127    
128          } else if(strcasecmp((char*)cur_node->name, "label") == 0) {
129    
130          /* --------- label widget --------- */          /* --------- label widget --------- */
131          *widget = g_new0(presets_widget_t, 1);          *widget = g_new0(presets_widget_t, 1);
# Line 162  static presets_widget_t **parse_widgets( Line 200  static presets_widget_t **parse_widgets(
200          // Could be done as a fold-out box width twisties.          // Could be done as a fold-out box width twisties.
201          // Or maybe as a separate dialog for small screens.          // Or maybe as a separate dialog for small screens.
202          // For now, just recurse and build up our current list.          // For now, just recurse and build up our current list.
203          widget = parse_widgets(cur_node, widget);          widget = parse_widgets(cur_node, item, widget);
204        }        }
205    
206        else if (strcasecmp((char*)cur_node->name, "link") == 0) {        else if (strcasecmp((char*)cur_node->name, "link") == 0) {
207          // silently ignore for now.  
208        }          /* --------- link is not a widget, but a property of item --------- */
209        else          if(!item->link) {
210              item->link = (char*)xmlGetProp(cur_node, BAD_CAST "href");
211            } else
212              printf("ignoring surplus link\n");
213    
214          } else
215          printf("found unhandled annotations/item/%s\n", cur_node->name);          printf("found unhandled annotations/item/%s\n", cur_node->name);
216      }      }
217    }    }
# Line 185  static presets_item_t *parse_item(xmlDoc Line 229  static presets_item_t *parse_item(xmlDoc
229      item->icon = josm_icon_name_adjust(item->icon);      item->icon = josm_icon_name_adjust(item->icon);
230    
231    presets_widget_t **widget = &item->widget;    presets_widget_t **widget = &item->widget;
232    parse_widgets(a_node, widget);    parse_widgets(a_node, item, widget);
233    return item;    return item;
234  }  }
235    
# Line 340  static gint table_expose_event(GtkWidget Line 384  static gint table_expose_event(GtkWidget
384  }  }
385  #endif  #endif
386    
387  static tag_t *presets_item_dialog(GtkWindow *parent,  static tag_t *presets_item_dialog(appdata_t *appdata, GtkWindow *parent,
388                       presets_item_t *item, tag_t *orig_tag) {                       presets_item_t *item, tag_t *orig_tag) {
389      GtkWidget *dialog = NULL;
390    gboolean ok = FALSE;    gboolean ok = FALSE;
391    tag_t *tag = NULL, **ctag = &tag;    tag_t *tag = NULL, **ctag = &tag;
392      www_context_t *www_context = NULL;
393    
394    printf("dialog for item %s\n", item->name);    printf("dialog for item %s\n", item->name);
   GtkWidget *dialog = gtk_dialog_new_with_buttons(  
           item->name, parent, GTK_DIALOG_MODAL,  
           GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,  
           GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,  
           NULL);  
395    
396    /* build dialog from items widget list */    /* build dialog from items widget list */
397    presets_widget_t *widget = item->widget;    presets_widget_t *widget = item->widget;
# Line 373  static tag_t *presets_item_dialog(GtkWin Line 414  static tag_t *presets_item_dialog(GtkWin
414    GtkWidget **gtk_widgets = (GtkWidget**)g_new0(GtkWidget, widget_cnt);    GtkWidget **gtk_widgets = (GtkWidget**)g_new0(GtkWidget, widget_cnt);
415    
416    if(interactive_widget_cnt)  {    if(interactive_widget_cnt)  {
417        dialog = gtk_dialog_new_with_buttons(
418            item->name, parent, GTK_DIALOG_MODAL,
419            GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
420            GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
421            NULL);
422    
423        /* if a web link has been provided for this item install */
424        /* a button for this */
425        if(item->link) {
426          www_context = g_new0(www_context_t, 1);
427          www_context->link = item->link;
428          www_context->appdata = appdata;
429    
430          GtkWidget *button = gtk_dialog_add_button(GTK_DIALOG(dialog), _
431                            ("Info..."), GTK_RESPONSE_HELP);
432          gtk_signal_connect(GTK_OBJECT(button), "clicked",
433                             GTK_SIGNAL_FUNC(on_info), (gpointer)www_context);
434        }
435    
436      /* special handling for the first label/separators */      /* special handling for the first label/separators */
437      guint widget_skip = 0;  // number of initial widgets to skip      guint widget_skip = 0;  // number of initial widgets to skip
438      widget = item->widget;      widget = item->widget;
# Line 385  static tag_t *presets_item_dialog(GtkWin Line 445  static tag_t *presets_item_dialog(GtkWin
445        /* skip all following separators (and keys) */        /* skip all following separators (and keys) */
446        while(widget &&        while(widget &&
447              ((widget->type == WIDGET_TYPE_SEPARATOR) ||              ((widget->type == WIDGET_TYPE_SEPARATOR) ||
448                 (widget->type == WIDGET_TYPE_SPACE) ||
449               (widget->type == WIDGET_TYPE_KEY))) {               (widget->type == WIDGET_TYPE_KEY))) {
450          widget_skip++;   // this widget isn't part of the contents anymore          widget_skip++;   // this widget isn't part of the contents anymore
451          widget = widget->next;          widget = widget->next;
# Line 404  static tag_t *presets_item_dialog(GtkWin Line 465  static tag_t *presets_item_dialog(GtkWin
465          attach_both(table, gtk_hseparator_new(), widget_cnt-widget_skip);          attach_both(table, gtk_hseparator_new(), widget_cnt-widget_skip);
466          break;          break;
467    
468          case WIDGET_TYPE_SPACE:
469            /* space is just an empty label until we find something better */
470            attach_both(table, gtk_label_new(" "), widget_cnt-widget_skip);
471            break;
472    
473        case WIDGET_TYPE_LABEL:        case WIDGET_TYPE_LABEL:
474          attach_both(table, gtk_label_new(widget->text), widget_cnt-widget_skip);          attach_both(table, gtk_label_new(widget->text), widget_cnt-widget_skip);
475          break;          break;
# Line 483  static tag_t *presets_item_dialog(GtkWin Line 549  static tag_t *presets_item_dialog(GtkWin
549  #endif  #endif
550    
551      gtk_widget_show_all(dialog);      gtk_widget_show_all(dialog);
   }  
   
   if(!interactive_widget_cnt ||  
      (GTK_RESPONSE_ACCEPT == gtk_dialog_run(GTK_DIALOG(dialog)))) {  
     ok = TRUE;  
552    
553        /* run gtk_dialog_run, but continue if e.g. the help button was pressed */
554        int result = -1;
555        do
556          result = gtk_dialog_run(GTK_DIALOG(dialog));
557        while((result != GTK_RESPONSE_DELETE_EVENT) &&
558              (result != GTK_RESPONSE_ACCEPT) &&
559              (result != GTK_RESPONSE_REJECT));
560    
561        if(result == GTK_RESPONSE_ACCEPT)
562          ok = TRUE;
563    
564      } else
565        ok = TRUE;
566    
567      if(ok) {
568      /* handle all children of the table */      /* handle all children of the table */
569      widget = item->widget;      widget = item->widget;
570      widget_cnt = 0;      widget_cnt = 0;
# Line 516  static tag_t *presets_item_dialog(GtkWin Line 592  static tag_t *presets_item_dialog(GtkWin
592    
593          ctag = store_value(widget, ctag,          ctag = store_value(widget, ctag,
594                   gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(                   gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(
595                             gtk_widgets[widget_cnt]))?"true":                             gtk_widgets[widget_cnt]))?"yes":
596                      (widget->del_if_empty?NULL:"false"));                      (widget->del_if_empty?NULL:"no"));
597          break;          break;
598    
599        case WIDGET_TYPE_KEY:        case WIDGET_TYPE_KEY:
# Line 544  static tag_t *presets_item_dialog(GtkWin Line 620  static tag_t *presets_item_dialog(GtkWin
620    if(interactive_widget_cnt)    if(interactive_widget_cnt)
621      gtk_widget_destroy(dialog);      gtk_widget_destroy(dialog);
622    
623      if(www_context)
624        g_free(www_context);
625    
626    return tag;    return tag;
627  }  }
628    
# Line 563  cb_menu_item(GtkMenuItem *menu_item, gpo Line 642  cb_menu_item(GtkMenuItem *menu_item, gpo
642    g_assert(item);    g_assert(item);
643    
644    tag_t *tag =    tag_t *tag =
645      presets_item_dialog(GTK_WINDOW(context->tag_context->dialog), item,      presets_item_dialog(context->appdata,
646                            GTK_WINDOW(context->tag_context->dialog), item,
647                          *context->tag_context->tag);                          *context->tag_context->tag);
648    
649    if(tag) {    if(tag) {

Legend:
Removed from v.50  
changed lines
  Added in v.51