Exemple #1
0
/*! \brief Add symbol-generating Scheme procedures to the library.
 *  \par Function Description
 *  Adds a source to the library based on Scheme procedures.  See page
 *  \ref libscms for more information. Two procedures are required: \a
 *  listfunc must return a Scheme list of symbol names, and \a getfunc
 *  must return a string containing symbol data when passed a symbol
 *  name.
 *
 *  \param listfunc A Scheme function returning a list of symbols.
 *  \param getfunc  A Scheme function returning symbol data.
 *  \param name     A descriptive name for the component source.
 *
 *  \return         The new CLibSource.
 */
const CLibSource *s_clib_add_scm (SCM listfunc, SCM getfunc, const gchar *name)
{
  CLibSource *source;
  gchar *realname;

  if (name == NULL) {
    s_log_message (_("Cannot add library: name not specified."));
    return NULL;
  }

  realname = uniquify_source_name (name);

  if (scm_is_false (scm_procedure_p (listfunc))
      && scm_is_false (scm_procedure_p (getfunc))) {
    s_log_message (_("Cannot add Scheme-library [%1$s]: callbacks must be closures."),
                   realname);
    return NULL;
  }

  source = g_new0 (CLibSource, 1);
  source->type = CLIB_SCM;
  source->name = realname;
  source->list_fn = scm_gc_protect_object (listfunc);
  source->get_fn = scm_gc_protect_object (getfunc);

  refresh_scm (source);

  clib_sources = g_list_prepend (clib_sources, source);

  return source;
}
Exemple #2
0
static AvahiWatch *
watch_new (const AvahiPoll *api, int fd, AvahiWatchEvent events,
	   AvahiWatchCallback callback, void *userdata)
{
  AvahiWatch *watch;
  AvahiGuilePoll *guile_poll;

  guile_poll = (AvahiGuilePoll *) api->userdata;

  watch = scm_malloc (sizeof (*watch));
  watch->fd = fd;
  watch->dead = 0;
  watch->events = events;
  watch->callback = callback;
  watch->userdata = userdata;
  watch->guile_poll = guile_poll;
  watch->stuff = SCM_BOOL_F;

  watch->watch_smob = scm_from_avahi_watch (watch);
  watch->watch_smob = scm_gc_protect_object (watch->watch_smob);

  (void) scm_call_3 (guile_poll->new_watch, watch->watch_smob,
		     scm_from_int (fd),
		     scm_from_avahi_watch_events (events));

  return (watch);
}
Exemple #3
0
/*! \brief Allocate a cache entry for Scheme values.
 * \par Function Description
 * Allocate and return a new cache entry for the Scheme value \a smob,
 * which is protected from garbage collection until the cache entry is
 * destroyed with smob_cache_entry_destroy().
 *
 * \param smob Scheme value to be cached.
 * \return a newly allocated cache entry structure.
 */
static SmobCacheEntry *
smob_cache_entry_new (SCM smob)
{
  SmobCacheEntry *entry = g_slice_new (SmobCacheEntry);
  entry->smob = scm_gc_protect_object (smob);
  return entry;
}
Exemple #4
0
static AvahiTimeout *
timeout_new (const AvahiPoll *api, const struct timeval *tv,
	     AvahiTimeoutCallback callback, void *userdata)
{
  SCM sec, nsec;
  AvahiTimeout *timeout;
  AvahiGuilePoll *guile_poll;

  guile_poll = (AvahiGuilePoll *) api->userdata;

  timeout = scm_malloc (sizeof (*timeout));
  timeout->dead = 0;
  timeout->enabled = (tv != NULL);
  timeout->callback = callback;
  timeout->userdata = userdata;
  timeout->guile_poll = guile_poll;
  timeout->stuff = SCM_BOOL_F;

  timeout->timeout_smob = scm_from_avahi_timeout (timeout);
  timeout->timeout_smob = scm_gc_protect_object (timeout->timeout_smob);

  if (tv != NULL)
    {
      timeout->expiry = *tv;
      sec = scm_from_long (tv->tv_sec);
      nsec = scm_from_long (tv->tv_usec * 1000L);
    }
  else
    sec = nsec = SCM_BOOL_F;

  (void) scm_call_3 (guile_poll->new_timeout,
		     timeout->timeout_smob, sec, nsec);

  return (timeout);
}
static gboolean
gnc_create_extension_info (SCM extension)
{
    ExtensionInfo *ext_info;
    gchar *typeStr, *tmp;
    gchar* name;
    gchar* guid;

    ext_info = g_new0(ExtensionInfo, 1);
    ext_info->extension = extension;
    gnc_extension_path(extension, &ext_info->path);
    if (!gnc_extension_type( extension, &ext_info->type ))
    {
        /* Can't parse the type passed to us.  Bail now. */
        g_free(ext_info);
        return FALSE;
    }

    /* Get all the pieces */
    name = gnc_extension_name(extension);
    guid = gnc_extension_guid(extension);
    ext_info->ae.label = g_strdup(gettext(name));
    ext_info->ae.name = gnc_ext_gen_action_name(guid);
    ext_info->ae.tooltip = gnc_extension_documentation(extension);
    ext_info->ae.stock_id = NULL;
    ext_info->ae.accelerator = NULL;
    ext_info->ae.callback = NULL;
    g_free(name);
    g_free(guid);

    tmp = g_strdup_printf("%s/%s", ext_info->path, ext_info->ae.label);
    ext_info->sort_key = g_utf8_collate_key(tmp, -1);
    g_free(tmp);

    switch (ext_info->type)
    {
    case GTK_UI_MANAGER_MENU:
        typeStr = "menu";
        break;
    case GTK_UI_MANAGER_MENUITEM:
        typeStr = "menuitem";
        break;
    default:
        typeStr = "unk";
        break;
    }
    ext_info->typeStr = typeStr;

    DEBUG( "extension: %s/%s [%s] tip [%s] type %s\n",
           ext_info->path, ext_info->ae.label, ext_info->ae.name,
           ext_info->ae.tooltip, ext_info->typeStr );

    scm_gc_protect_object(extension);

    /* need to append so we can run them in order */
    extension_list = g_slist_append(extension_list, ext_info);

    return TRUE;
}
Exemple #6
0
static SCM device_change(SCM obj) {
	if (device_change_handler != SCM_BOOL_F)
		scm_gc_unprotect_object(device_change_handler);
	if (obj != SCM_BOOL_F)
		scm_gc_protect_object(obj);
	device_change_handler = obj;
	return SCM_UNSPECIFIED;
	}
Exemple #7
0
SCM __api_build_projectile_prototype(SCM name, SCM speed, SCM w, SCM h, SCM longevity, SCM dmg)
{
	char *s = scm_to_locale_string(name);
	projectile *p = build_projectile_prototype(s, scm_to_double(speed), scm_to_int(w), scm_to_int(h), scm_to_int(longevity), scm_to_int(dmg));
	free(s);
	SCM ret = scm_new_smob(__api_projectile_tag, (unsigned long) p);
	scm_gc_protect_object(ret);
	return ret;
}
Exemple #8
0
SCM __api_make_projectile(SCM name, SCM x, SCM y, SCM rotation, SCM spawned_by)
{
	char *s = scm_to_locale_string(name);
	item *sb = (item *) SCM_SMOB_DATA(spawned_by);
	projectile *p = make_projectile(s, scm_to_double(x), scm_to_double(y), scm_to_double(rotation), sb);
	free(s);
	SCM ret = scm_new_smob(__api_projectile_tag, (unsigned long) p);
	scm_gc_protect_object(ret);
	return ret;
}
Exemple #9
0
SCM __api_make_fx(SCM type, SCM col, SCM x, SCM y, SCM dim, SCM radius, SCM speed)
{
	color c = *((color *) SCM_SMOB_DATA(col));
	SCM ret = scm_new_smob(__api_effect_tag,
			(unsigned long) make_fx(scm_to_int(type), c,
				scm_to_double(x), scm_to_double(y), scm_to_int(dim),
				scm_to_int(radius), scm_to_double(speed)));
	scm_gc_protect_object(ret);
	return ret;
}
Exemple #10
0
static SCM guileAddPropertyListener(SCM element, SCM keySymbol, SCM callback)
{
  char* key = scm_to_utf8_string(scm_symbol_to_string(keySymbol));
  guihckElementId listenerId = guihckStackGetElement(threadLocalContext.ctx);
  guihckPropertyListenerId id = guihckElementAddListener(threadLocalContext.ctx, listenerId, scm_to_uint64(element), key,
                                                         guilePropertyListenerCallback, callback, guilePropertyListenerFreeCallback);
  scm_gc_protect_object(callback);
  free(key);
  return scm_from_uint64(id);
}
Exemple #11
0
gint gnc_report_add(SCM report)
{
    SCM get_id = scm_c_eval_string("gnc:report-id");
    SCM value;
    gint id, *key;

    gnc_report_init_table();

    value = scm_call_1(get_id, report);
    if (scm_is_number(value))
    {
        id = scm_num2int(value, SCM_ARG1, G_STRFUNC);
        if (!g_hash_table_lookup(reports, &id))
        {
            key = g_new(gint, 1);
            *key = id;
            g_hash_table_insert(reports, key, (gpointer)report);
            scm_gc_protect_object(report);
            return id;
        }
        g_warning("Report specified id of %d is already is use. "
                  "Using generated id.", id);
    }

    id = report_next_serial_id++;
    while (id < G_MAXINT)
    {
        if (!g_hash_table_lookup(reports, &id))
        {
            key = g_new(gint, 1);
            *key = id;
            g_hash_table_insert(reports, key, (gpointer)report);
            scm_gc_protect_object(report);
            return id;
        }
        id = report_next_serial_id++;
    }

    g_warning("Unable to add report to table. %d reports in use.", G_MAXINT);
    report_next_serial_id = G_MAXINT;
    return G_MAXINT;
}
Exemple #12
0
static void *
arscm_object_data_init (struct gdbarch *gdbarch)
{
  SCM arch_scm = arscm_make_arch_smob (gdbarch);

  /* This object lasts the duration of the GDB session, so there is no
     call to scm_gc_unprotect_object for it.  */
  scm_gc_protect_object (arch_scm);

  return (void *) arch_scm;
}
static void
gnc_column_view_edit_size_cb(GtkButton * button, gpointer user_data)
{
    gnc_column_view_edit * r = user_data;
    GtkWidget * rowspin;
    GtkWidget * colspin;
    GtkWidget * dlg;
    GladeXML *xml;
    SCM current;
    int length;
    int dlg_ret;

    xml = gnc_glade_xml_new ("report.glade", "Edit Report Size");
    dlg = glade_xml_get_widget (xml, "Edit Report Size");

    /* get the spinner widgets */
    rowspin = glade_xml_get_widget (xml, "row_spin");
    colspin = glade_xml_get_widget (xml, "col_spin");

    length = scm_ilength(r->contents_list);
    if (length > r->contents_selected)
    {
        current = scm_list_ref(r->contents_list,
                               scm_int2num(r->contents_selected));
        gtk_spin_button_set_value(GTK_SPIN_BUTTON(colspin),
                                  (float)scm_num2int(SCM_CADR(current),
                                          SCM_ARG1, G_STRFUNC));
        gtk_spin_button_set_value(GTK_SPIN_BUTTON(rowspin),
                                  (float)scm_num2int(SCM_CADDR(current),
                                          SCM_ARG1, G_STRFUNC));

        dlg_ret = gtk_dialog_run(GTK_DIALOG(dlg));
        gtk_widget_hide(dlg);

        if (dlg_ret == GTK_RESPONSE_OK)
        {
            current = SCM_LIST4(SCM_CAR(current),
                                scm_int2num(gtk_spin_button_get_value_as_int
                                            (GTK_SPIN_BUTTON(colspin))),
                                scm_int2num(gtk_spin_button_get_value_as_int
                                            (GTK_SPIN_BUTTON(rowspin))),
                                SCM_BOOL_F);
            scm_gc_unprotect_object(r->contents_list);
            r->contents_list = scm_list_set_x(r->contents_list,
                                              scm_int2num(r->contents_selected),
                                              current);
            scm_gc_protect_object(r->contents_list);
            gnc_options_dialog_changed (r->optwin);
            update_display_lists(r);
        }
        gtk_widget_destroy(dlg);
    }
}
SCMFunctor& 
SCMFunctor::operator= (const SCMFunctor& hook)
{
  if (this != &hook)
    {
      scm_gc_unprotect_object(func);

      func = hook.func;

      scm_gc_protect_object(func);
    }
  return *this;
}
static void
bpscm_attach_scm_to_breakpoint (struct breakpoint *bp, SCM containing_scm)
{
  breakpoint_smob *bp_smob;

  bp_smob = (breakpoint_smob *) SCM_SMOB_DATA (containing_scm);
  bp_smob->number = bp->number;
  bp_smob->bp = bp;
  bp_smob->containing_scm = containing_scm;
  bp_smob->bp->scm_bp_object = bp_smob;

  /* The owner of this breakpoint is not in GC-controlled memory, so we need
     to protect it from GC until the breakpoint is deleted.  */
  scm_gc_protect_object (containing_scm);
}
Exemple #16
0
/*! \todo Finish function documentation!!!
 *  \brief
 *  \par Function Description
 *
 */
int s_menu_add_entry(char *new_menu, SCM menu_items) 
{
  if (new_menu == NULL) {
    return(-1); 
  }

  if (menu_index >= MAX_MENUS) {
    return(-1); 
  }

  menu[menu_index].menu_name = g_strdup (new_menu);
  scm_gc_protect_object (menu_items);
  menu[menu_index].menu_items = menu_items;
  menu_index++;
  
  return(menu_index);
}
static void
gnc_column_view_edit_remove_cb(GtkButton * button, gpointer user_data)
{
    gnc_column_view_edit * r = user_data;
    SCM newlist = SCM_EOL;
    SCM oldlist = r->contents_list;
    int count;
    int oldlength;

    if (scm_is_list(r->contents_list))
    {
        oldlength = scm_ilength(r->contents_list);
        if (oldlength > r->contents_selected)
        {
            for (count = 0; count < r->contents_selected; count++)
            {
                newlist = scm_cons(SCM_CAR(oldlist), newlist);
                oldlist = SCM_CDR(oldlist);
            }
            if (count <= oldlength)
            {
                newlist = scm_append(scm_listify(scm_reverse(newlist), SCM_CDR(oldlist), SCM_UNDEFINED));
            }
        }

        if (r->contents_selected > 0 && oldlength == r->contents_selected + 1)
        {
            r->contents_selected --;
        }

        scm_gc_unprotect_object(r->contents_list);
        r->contents_list = newlist;
        scm_gc_protect_object(r->contents_list);

        gnc_column_view_set_option(r->odb, "__general", "report-list",
                                   r->contents_list);

        gnc_options_dialog_changed (r->optwin);
    }

    update_display_lists(r);
}
Exemple #18
0
void
gnc_hook_add_scm_dangler (const gchar *name, SCM proc)
{
    GncHook *gnc_hook;
    GHook *hook;
    GncScmDangler *scm;

    ENTER("list %s, proc ???", name);
    gnc_hook = gnc_hook_lookup(name);
    g_return_if_fail(gnc_hook != NULL);
    scm = g_new0(GncScmDangler, 1);
    scm_gc_protect_object(proc);
    scm->proc = proc;
    hook = g_hook_alloc(gnc_hook->scm_danglers);
    hook->func = call_scm_hook;
    hook->data = scm;
    hook->destroy = delete_scm_hook;
    g_hook_append(gnc_hook->scm_danglers, hook);
    LEAVE("");
}
Exemple #19
0
void init_cache(void) {
	make_node_tag = scm_make_smob_type("make-node", sizeof(MAKE_NODE));
	scm_set_smob_free(make_node_tag, free_node);
	scm_set_smob_mark(make_node_tag, mark_node);
	deflate_tag = scm_make_smob_type("gzip-blob", sizeof(DEFLATE_BLOB));
	sessions_db = scm_from_locale_string("sessions");
	scm_gc_protect_object(sessions_db);
	scm_permanent_object(file_sym = scm_from_utf8_symbol("file"));
	scm_permanent_object(data_sym = scm_from_utf8_symbol("data"));
	scm_permanent_object(stamp_sym = scm_from_utf8_symbol("stamp"));
	scm_c_define_gsubr("make-doc", 2, 0, 0, make_doc);
	scm_c_define_gsubr("touch-doc", 1, 0, 1, touch_node);
	scm_c_define_gsubr("fetch-doc", 1, 0, 1, fetch_node);
	scm_c_define_gsubr("touched-doc?", 1, 0, 0, touched_node);
	scm_c_define_gsubr("gzip", 1, 0, 0, gzip);
	scm_c_define_gsubr("zdeflate", 1, 0, 0, zdeflate);
	scm_c_define_gsubr("zdeflate-size", 1, 0, 0, deflate_size);
	scm_c_define_gsubr("zdeflate?", 1, 0, 0, is_gzip);
	scm_c_define_gsubr("zinflate", 1, 0, 0, gunzip);
	log_msg("zlib version %s\n", zlibVersion());
	}
static ss_info *
gnc_style_sheet_dialog_create(StyleSheetDialog * ss,
                              gchar *name,
                              SCM sheet_info,
                              GtkTreeRowReference *row_ref)
{
    SCM get_options = scm_c_eval_string("gnc:html-style-sheet-options");

    SCM            scm_options = scm_call_1(get_options, sheet_info);
    ss_info        * ssinfo = g_new0(ss_info, 1);
    GtkWidget      * window;
    gchar          * title;

    title = g_strdup_printf(_("HTML Style Sheet Properties: %s"), name);
    ssinfo->odialog = gnc_options_dialog_new(title);
    ssinfo->odb     = gnc_option_db_new(scm_options);
    ssinfo->stylesheet = sheet_info;
    ssinfo->row_ref    = row_ref;
    g_free(title);

    scm_gc_protect_object(ssinfo->stylesheet);
    g_object_ref(gnc_options_dialog_widget(ssinfo->odialog));

    gnc_options_dialog_build_contents(ssinfo->odialog,
                                      ssinfo->odb);
    gnc_options_dialog_set_apply_cb(ssinfo->odialog,
                                    gnc_style_sheet_options_apply_cb,
                                    ssinfo);
    gnc_options_dialog_set_close_cb(ssinfo->odialog,
                                    gnc_style_sheet_options_close_cb,
                                    ssinfo);
    window = gnc_options_dialog_widget(ssinfo->odialog);
    gtk_window_set_transient_for(GTK_WINDOW(window),
                                 GTK_WINDOW(gnc_style_sheet_dialog->toplevel));
    gtk_window_set_destroy_with_parent(GTK_WINDOW(window), TRUE);
    gtk_window_present(GTK_WINDOW(window));

    return(ssinfo);
}
/************************************************************
 *               Style Sheet Selection Dialog               *
 ************************************************************/
static void
gnc_style_sheet_select_dialog_add_one(StyleSheetDialog * ss,
                                      SCM sheet_info,
                                      gboolean select)
{
    SCM get_name, scm_name;
    const gchar *c_name;
    char * str;
    GtkTreeSelection *selection;
    GtkTreeIter iter;

    get_name = scm_c_eval_string("gnc:html-style-sheet-name");
    scm_name = scm_call_1(get_name, sheet_info);
    scm_dynwind_begin (0); 
    str = scm_to_locale_string (scm_name);
    c_name = g_strdup (str);
    scm_dynwind_free (str); 
    scm_dynwind_end (); 
    if (!c_name)
        return;

    /* add the column name */
    scm_gc_protect_object(sheet_info);
    gtk_list_store_append (ss->list_store, &iter);
    gtk_list_store_set (ss->list_store, &iter,
                        /* Translate the displayed name */
                        COLUMN_NAME, _(c_name),
                        COLUMN_STYLESHEET, sheet_info,
                        -1);
    /* The translation of the name fortunately doesn't affect the
     * lookup because that is done through the sheet_info argument. */

    if (select)
    {
        selection = gtk_tree_view_get_selection (ss->list_view);
        gtk_tree_selection_select_iter (selection, &iter);
    }
}
static void
gnc_edit_column_view_move_up_cb(GtkButton * button, gpointer user_data)
{
    gnc_column_view_edit * r = user_data;
    SCM oldlist = r->contents_list;
    SCM newlist = SCM_EOL;
    SCM temp;
    int oldlength;
    int count;

    oldlength = scm_ilength(r->contents_list);
    if ((r->contents_selected > 0) && (oldlength > r->contents_selected))
    {
        for (count = 1; count < r->contents_selected; count++)
        {
            newlist = scm_cons(SCM_CAR(oldlist), newlist);
            oldlist = SCM_CDR(oldlist);
        }
        temp = SCM_CAR(oldlist);
        oldlist = SCM_CDR(oldlist);
        newlist = scm_cons(temp, scm_cons(SCM_CAR(oldlist), newlist));
        newlist = scm_append(scm_listify(scm_reverse(newlist), SCM_CDR(oldlist), SCM_UNDEFINED));

        scm_gc_unprotect_object(r->contents_list);
        r->contents_list = newlist;
        scm_gc_protect_object(r->contents_list);

        r->contents_selected = r->contents_selected - 1;

        gnc_column_view_set_option(r->odb, "__general", "report-list",
                                   r->contents_list);

        gnc_options_dialog_changed (r->optwin);

        update_display_lists(r);
    }
}
Exemple #23
0
static void sched_at_c(utime_t usec, SCM action, SCM tag) {
	SCHED_EVENT *event;
	SCHED_EVENT *node, *prev;
	if (usec < now_usec()) { // can't schedule in the past
		return;
		}
	event = grab_node();
	event->clock = usec;
	event->state = STATE_PENDING;
	if (tag == SCM_UNDEFINED) event->tag = NULL;
	else event->tag = scm_to_locale_string(tag);
	scm_gc_protect_object(event->action = action);
	pthread_mutex_lock(&qmutex);
	node = queue;
	prev = NULL;
	while (node != NULL) {
		if (node->clock >= event->clock) {
			event->link = node;
			if (prev == NULL) queue = event;
			else prev->link = event;
			break;
			}
		prev = node;
		node = node->link;
		}
	if (event->link == NULL) {
		if (prev == NULL) queue = event;
		else prev->link = event;
		}
	pthread_mutex_unlock(&qmutex);
	if (pthread_mutex_trylock(&qmutex) == 0) {
		pthread_cond_signal(&qcondvar);
		pthread_mutex_unlock(&qmutex);
		}
	return;
	}
Exemple #24
0
/*! \brief Parse gschem command-line options.
 * \par Function Description
 * Parse command line options, displaying usage message or version
 * information as required.
 *
 * \param argc Number of command-line arguments.
 * \param argv Array of command-line arguments.
 * \return index into \a argv of first non-option argument.
 */
int
parse_commandline(int argc, char *argv[])
{
  int ch;
  SCM sym_cons = scm_from_utf8_symbol ("cons");
  SCM sym_set_x = scm_from_utf8_symbol ("set!");
  SCM sym_load_path = scm_from_utf8_symbol ("%load-path");
  SCM sym_begin = scm_from_utf8_symbol ("begin");
  SCM sym_load = scm_from_utf8_symbol ("load");
  SCM sym_eval_string = scm_from_utf8_symbol ("eval-string");

#ifdef HAVE_GETOPT_LONG
  while ((ch = getopt_long (argc, argv, GETOPT_OPTIONS, long_options, NULL)) != -1) {
#else
  while ((ch = getopt (argc, argv, GETOPT_OPTIONS)) != -1) {
#endif
    switch (ch) {
      case 'v':
        verbose_mode = TRUE;
        break;

      case 'q':
        quiet_mode = TRUE;
        break;

      case 's':
        /* Argument is filename of a Scheme script to be run on gschem
         * load.  Add the necessary expression to be evaluated after
         * loading. */
        s_post_load_expr =
          scm_cons (scm_list_2 (sym_load,
                                scm_from_locale_string (optarg)),
                    s_post_load_expr);
        break;

      case 'c':
        /* Argument is a Scheme expression to be evaluated on gschem
         * load.  Add the necessary expression to be evaluated after
         * loading. */
        s_post_load_expr =
          scm_cons (scm_list_2 (sym_eval_string,
                                scm_from_locale_string (optarg)),
                    s_post_load_expr);
        break;

      case 'o':
        output_filename_s = scm_from_locale_string (optarg);
        break;

      case 'p':
        auto_place_mode = TRUE;
        break;

      case 'L':
        /* Argument is a directory to add to the Scheme load path.
         * Add the necessary expression to be evaluated before rc file
         * loading. */
        s_pre_load_expr =
          scm_cons (scm_list_3 (sym_set_x,
                                sym_load_path,
                                scm_list_3 (sym_cons,
                                            scm_from_locale_string (optarg),
                                            sym_load_path)),
                    s_pre_load_expr);
        break;

      case 'h':
        usage(argv[0]);
        break;

      case 'V':
        version ();
        break;

      case '?':
#ifndef HAVE_GETOPT_LONG
        if ((optopt != ':') && (strchr (GETOPT_OPTIONS, optopt) != NULL)) {
          fprintf (stderr,
                   "ERROR: -%c option requires an argument.\n\n",
                   optopt);
        } else if (isprint (optopt)) {
          fprintf (stderr, "ERROR: Unknown option -%c.\n\n", optopt);
        } else {
          fprintf (stderr, "ERROR: Unknown option character `\\x%x'.\n\n",
                   optopt);
        }
#endif
        fprintf (stderr, "\nRun `%s --help' for more information.\n", argv[0]);
        exit (1);
        break;
      default:
        g_assert_not_reached ();
    }
  }

  if (quiet_mode) {
    verbose_mode = FALSE;
  }

  /* Make sure Scheme expressions can be passed straight to eval */
  s_pre_load_expr = scm_cons (sym_begin,
                              scm_reverse_x (s_pre_load_expr, SCM_UNDEFINED));
  scm_gc_protect_object (s_pre_load_expr);
  s_post_load_expr = scm_cons (sym_begin,
                               scm_reverse_x (s_post_load_expr, SCM_UNDEFINED));
  scm_gc_protect_object (s_post_load_expr);
  return(optind);
}
SCMFunctor::SCMFunctor(const SCMFunctor& hook)
{
  func = hook.func;

  scm_gc_protect_object(func);
}
SCMFunctor::SCMFunctor(SCM arg_func)
{
  func = arg_func;
  scm_gc_protect_object(func);
}
Exemple #27
0
/****************************************************************
 * qif_account_picker_dialog
 *
 * Select an account from the ones that the engine knows about,
 * plus those that will be created by the QIF import.  If the
 * user clicks OK, map_entry is changed and TRUE is returned.
 * If the clicks Cancel instead, FALSE is returned. Modal.
 ****************************************************************/
gboolean
qif_account_picker_dialog(QIFImportWindow * qif_wind, SCM map_entry)
{
    QIFAccountPickerDialog * wind;
    SCM gnc_name     = scm_c_eval_string("qif-map-entry:gnc-name");
    SCM set_gnc_name = scm_c_eval_string("qif-map-entry:set-gnc-name!");
    SCM orig_acct    = scm_call_1(gnc_name, map_entry);
    int response;
    GtkBuilder *builder;
    GtkWidget *button;

    wind = g_new0(QIFAccountPickerDialog, 1);

    /* Save the map entry. */
    wind->map_entry = map_entry;
    scm_gc_protect_object(wind->map_entry);

    /* Set the initial account to be selected. */
    if (scm_is_string(orig_acct))
        wind->selected_name = gnc_scm_to_utf8_string (orig_acct);

    builder = gtk_builder_new();
    gnc_builder_add_from_file (builder, "dialog-account-picker.glade", "QIF Import Account Picker");

    /* Connect all the signals */
    gtk_builder_connect_signals (builder, wind);

    wind->dialog     = GTK_WIDGET(gtk_builder_get_object (builder, "QIF Import Account Picker"));
    wind->treeview   = GTK_TREE_VIEW(gtk_builder_get_object (builder, "account_tree"));
    wind->qif_wind   = qif_wind;

    {
        GtkTreeStore *store;
        GtkCellRenderer *renderer;
        GtkTreeViewColumn *column;
        GtkTreeSelection *selection;

        store = gtk_tree_store_new(NUM_ACCOUNT_COLS, G_TYPE_STRING, G_TYPE_STRING,
                                   G_TYPE_BOOLEAN);
        gtk_tree_view_set_model(wind->treeview, GTK_TREE_MODEL(store));
        g_object_unref(store);

        renderer = gtk_cell_renderer_text_new();
        column = gtk_tree_view_column_new_with_attributes(_("Account"),
                 renderer,
                 "text",
                 ACCOUNT_COL_NAME,
                 NULL);
        g_object_set(column, "expand", TRUE, NULL);
        gtk_tree_view_append_column(wind->treeview, column);

        renderer = gtk_cell_renderer_toggle_new();
        g_object_set(renderer, "activatable", FALSE, NULL);
        column = gtk_tree_view_column_new_with_attributes(_("New?"),
                 renderer,
                 "active",
                 ACCOUNT_COL_CHECK,
                 NULL);
        gtk_tree_view_append_column(wind->treeview, column);

        selection = gtk_tree_view_get_selection(wind->treeview);
        g_signal_connect(selection, "changed",
                         G_CALLBACK(gnc_ui_qif_account_picker_changed_cb), wind);
        g_signal_connect(wind->treeview, "row-activated",
                         G_CALLBACK(gnc_ui_qif_account_picker_row_activated_cb),
                         wind);
    }

    g_signal_connect_after(wind->dialog, "map",
                           G_CALLBACK(gnc_ui_qif_account_picker_map_cb),
                           wind);

    button =  GTK_WIDGET(gtk_builder_get_object (builder, "newbutton"));
    gtk_button_set_use_stock(GTK_BUTTON(button), TRUE);

    /* this is to get the checkmarks set up right.. it will get called
     * again after the window is mapped. */
    build_acct_tree(wind, wind->qif_wind);

    do
    {
        response = gtk_dialog_run(GTK_DIALOG(wind->dialog));
    }
    while (response == GNC_RESPONSE_NEW);
    gtk_widget_destroy(wind->dialog);
    g_object_unref(G_OBJECT(builder));

    scm_gc_unprotect_object(wind->map_entry);
    g_free(wind->selected_name);
    g_free(wind);

    if (response == GTK_RESPONSE_OK)
        return TRUE;

    /* Restore the original mapping. */
    scm_call_2(set_gnc_name, map_entry, orig_acct);

    return FALSE;
}
static void
update_display_lists(gnc_column_view_edit * view)
{
    SCM   get_names = scm_c_eval_string("gnc:all-report-template-names");
    SCM   template_menu_name = scm_c_eval_string("gnc:report-template-menu-name/report-guid");
    SCM   report_menu_name = scm_c_eval_string("gnc:report-menu-name");
    SCM   names = scm_call_0(get_names);
    SCM   contents =
        gnc_option_db_lookup_option(view->odb, "__general", "report-list",
                                    SCM_BOOL_F);
    SCM   this_report;
    SCM   selection;
    const gchar *name;
    int   row, i, id;
    GtkListStore *store;
    GtkTreeIter iter;
    GtkTreePath *path;
    GtkTreeSelection *tree_selection;


    /* Update the list of available reports (left selection box). */
    row = view->available_selected;

    if (scm_is_list(view->available_list) && !scm_is_null (view->available_list))
    {
        row = MIN (row, scm_ilength (view->available_list) - 1);
        selection = scm_list_ref (view->available_list, scm_int2num (row));
    }
    else
    {
        selection = SCM_UNDEFINED;
    }

    scm_gc_unprotect_object(view->available_list);
    view->available_list = names;
    scm_gc_protect_object(view->available_list);

    store = GTK_LIST_STORE(gtk_tree_view_get_model(view->available));
    gtk_list_store_clear(store);

    if (scm_is_list(names))
    {
        for (i = 0; !scm_is_null(names); names = SCM_CDR(names), i++)
        {
            char * str;

            if (scm_is_equal (SCM_CAR(names), selection))
                row = i;
            scm_dynwind_begin (0); 
            str = scm_to_locale_string (scm_call_2(template_menu_name, SCM_CAR(names),
                                          SCM_BOOL_F));
            name = _(g_strdup (str));
            scm_dynwind_free (str); 
            scm_dynwind_end (); 
            gtk_list_store_append(store, &iter);
            gtk_list_store_set(store, &iter,
                               AVAILABLE_COL_NAME, name,
                               AVAILABLE_COL_ROW, i,
                               -1);
        }

    }

    tree_selection = gtk_tree_view_get_selection(view->available);
    path = gtk_tree_path_new_from_indices(row, -1);
    gtk_tree_selection_select_path(tree_selection, path);
    gtk_tree_path_free(path);


    /* Update the list of selected reports (right selection box). */
    row = view->contents_selected;

    if (scm_is_list(view->contents_list) && !scm_is_null (view->contents_list))
    {
        row = MIN (row, scm_ilength (view->contents_list) - 1);
        selection = scm_list_ref (view->contents_list, scm_int2num (row));
    }
    else
    {
        selection = SCM_UNDEFINED;
    }

    scm_gc_unprotect_object(view->contents_list);
    view->contents_list = contents;
    scm_gc_protect_object(view->contents_list);

    store = GTK_LIST_STORE(gtk_tree_view_get_model(view->contents));
    gtk_list_store_clear(store);
    if (scm_is_list(contents))
    {
        for (i = 0; !scm_is_null(contents); contents = SCM_CDR(contents), i++)
        {
            char * str;

            if (scm_is_equal (SCM_CAR(contents), selection))
                row = i;

            id = scm_num2int(SCM_CAAR(contents), SCM_ARG1, G_STRFUNC);
            this_report = gnc_report_find(id);
            scm_dynwind_begin (0); 
            str = scm_to_locale_string (scm_call_1(report_menu_name, this_report));
            name = _(g_strdup (str));
            scm_dynwind_free (str); 
            scm_dynwind_end (); 

            gtk_list_store_append(store, &iter);
            gtk_list_store_set
            (store, &iter,
             CONTENTS_COL_NAME, name,
             CONTENTS_COL_ROW, i,
             CONTENTS_COL_REPORT_COLS, scm_num2int(SCM_CADR(SCM_CAR(contents)),
                                                   SCM_ARG1, G_STRFUNC),
             CONTENTS_COL_REPORT_ROWS, scm_num2int(SCM_CADDR(SCM_CAR(contents)),
                                                   SCM_ARG1, G_STRFUNC),
             -1);
        }
    }

    tree_selection = gtk_tree_view_get_selection(view->contents);
    path = gtk_tree_path_new_from_indices(row, -1);
    gtk_tree_selection_select_path(tree_selection, path);
    //  gtk_tree_view_scroll_to_cell(view->contents, path, NULL, TRUE, 0.5, 0.0);
    gtk_tree_path_free(path);
}
GtkWidget *
gnc_column_view_edit_options(SCM options, SCM view)
{
    SCM get_editor = scm_c_eval_string("gnc:report-editor-widget");
    SCM ptr;
    GtkWidget * editor;
    GtkListStore *store;
    GtkCellRenderer *renderer;
    GtkTreeViewColumn *column;
    GtkTreeSelection *selection;

    ptr = scm_call_1(get_editor, view);
    if (ptr != SCM_BOOL_F)
    {
#define FUNC_NAME "gtk_window_present"
        GtkWindow * w = SWIG_MustGetPtr(ptr, SWIG_TypeQuery("_p_GtkWidget"), 1, 0);
        gtk_window_present(w);
#undef FUNC_NAME
        return NULL;
    }
    else
    {
        gnc_column_view_edit * r = g_new0(gnc_column_view_edit, 1);
        GladeXML *xml;

        r->optwin = gnc_options_dialog_new(NULL);

        /* Hide the generic dialog page list. */
        {
            GtkWidget *dialog, *page_list;

            dialog = gnc_options_dialog_widget(r->optwin);
            page_list = gnc_glade_lookup_widget (dialog, "page_list");
            gtk_widget_hide(page_list);
        }

        xml = gnc_glade_xml_new ("report.glade", "view_contents_table");

        glade_xml_signal_connect_data
        (xml, "gnc_column_view_edit_add_cb",
         G_CALLBACK (gnc_column_view_edit_add_cb), r);

        glade_xml_signal_connect_data
        (xml, "gnc_column_view_edit_remove_cb",
         G_CALLBACK (gnc_column_view_edit_remove_cb), r);

        glade_xml_signal_connect_data
        (xml, "gnc_edit_column_view_move_up_cb",
         G_CALLBACK (gnc_edit_column_view_move_up_cb), r);

        glade_xml_signal_connect_data
        (xml, "gnc_edit_column_view_move_down_cb",
         G_CALLBACK (gnc_edit_column_view_move_down_cb), r);

        glade_xml_signal_connect_data
        (xml, "gnc_column_view_edit_size_cb",
         G_CALLBACK (gnc_column_view_edit_size_cb), r);

        editor       = glade_xml_get_widget (xml, "view_contents_table");
        r->available = GTK_TREE_VIEW (glade_xml_get_widget (xml, "available_view"));
        r->contents  = GTK_TREE_VIEW (glade_xml_get_widget (xml, "contents_view"));
        r->options   = options;
        r->view      = view;
        r->available_selected = 0;
        r->available_list = SCM_EOL;
        r->contents_selected = 0;
        r->contents_list = SCM_EOL;
        r->odb       = gnc_option_db_new(r->options);

        gnc_options_dialog_build_contents(r->optwin, r->odb);

        gtk_notebook_append_page(GTK_NOTEBOOK(gnc_options_dialog_notebook
                                              (r->optwin)),
                                 editor,
                                 gtk_label_new(_("Contents")));

        scm_gc_protect_object(r->options);
        scm_gc_protect_object(r->view);
        scm_gc_protect_object(r->available_list);
        scm_gc_protect_object(r->contents_list);

        /* Build the 'available' view */
        store = gtk_list_store_new (NUM_AVAILABLE_COLS, G_TYPE_STRING, G_TYPE_INT);
        gtk_tree_view_set_model(r->available, GTK_TREE_MODEL(store));
        gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(store), AVAILABLE_COL_NAME, GTK_SORT_ASCENDING);
        g_object_unref(store);

        renderer = gtk_cell_renderer_text_new();
        column = gtk_tree_view_column_new_with_attributes("", renderer,
                 "text", AVAILABLE_COL_NAME,
                 NULL);
        gtk_tree_view_append_column(r->available, column);

        selection = gtk_tree_view_get_selection(r->available);
        g_signal_connect(selection, "changed",
                         G_CALLBACK(gnc_column_view_select_avail_cb), r);

        /* Build the 'contents' view */
        store = gtk_list_store_new (NUM_CONTENTS_COLS, G_TYPE_STRING, G_TYPE_INT,
                                    G_TYPE_INT, G_TYPE_INT);
        gtk_tree_view_set_model(r->contents, GTK_TREE_MODEL(store));
        g_object_unref(store);

        renderer = gtk_cell_renderer_text_new();
        column = gtk_tree_view_column_new_with_attributes(_("Report"), renderer,
                 "text", CONTENTS_COL_NAME,
                 NULL);
        gtk_tree_view_append_column(r->contents, column);

        renderer = gtk_cell_renderer_text_new();
        column = gtk_tree_view_column_new_with_attributes(_("Rows"), renderer,
                 "text", CONTENTS_COL_REPORT_ROWS,
                 NULL);
        gtk_tree_view_append_column(r->contents, column);

        renderer = gtk_cell_renderer_text_new();
        column = gtk_tree_view_column_new_with_attributes(_("Cols"), renderer,
                 "text", CONTENTS_COL_REPORT_COLS,
                 NULL);
        gtk_tree_view_append_column(r->contents, column);

        selection = gtk_tree_view_get_selection(r->contents);
        g_signal_connect(selection, "changed",
                         G_CALLBACK(gnc_column_view_select_contents_cb), r);

        update_display_lists(r);

        gnc_options_dialog_set_apply_cb(r->optwin,
                                        gnc_column_view_edit_apply_cb, r);
        gnc_options_dialog_set_close_cb(r->optwin,
                                        gnc_column_view_edit_close_cb, r);

        gtk_widget_show(gnc_options_dialog_widget(r->optwin));
        return gnc_options_dialog_widget(r->optwin);
    }
}
static void
gnc_column_view_edit_add_cb(GtkButton * button, gpointer user_data)
{
    gnc_column_view_edit * r = user_data;
    SCM make_report = scm_c_eval_string("gnc:make-report");
    SCM mark_report = scm_c_eval_string("gnc:report-set-needs-save?!");
    SCM template_name;
    SCM new_report;
    SCM newlist = SCM_EOL;
    SCM oldlist = r->contents_list;
    int count;
    int oldlength, id;

    if (scm_is_list(r->available_list) &&
            (scm_ilength(r->available_list) > r->available_selected))
    {
        template_name = scm_list_ref(r->available_list,
                                     scm_int2num(r->available_selected));
        new_report = scm_call_1(make_report, template_name);
        id = scm_num2int(new_report, SCM_ARG1, G_STRFUNC);
        scm_call_2(mark_report, gnc_report_find(id), SCM_BOOL_T);
        oldlength = scm_ilength(r->contents_list);

        if (oldlength > r->contents_selected)
        {
            for (count = 0; count < r->contents_selected; count++)
            {
                newlist = scm_cons(SCM_CAR(oldlist), newlist);
                oldlist = SCM_CDR(oldlist);
            }
            newlist = scm_append
                      (scm_listify(scm_reverse(scm_cons(SCM_LIST4(new_report,
                                               scm_int2num(1),
                                               scm_int2num(1),
                                               SCM_BOOL_F),
                                               newlist)),
                                   oldlist,
                                   SCM_UNDEFINED));
        }
        else
        {
            newlist = scm_append
                      (scm_listify(oldlist,
                                   SCM_LIST1(SCM_LIST4(new_report,
                                             scm_int2num(1),
                                             scm_int2num(1),
                                             SCM_BOOL_F)),
                                   SCM_UNDEFINED));
            r->contents_selected = oldlength;
        }

        scm_gc_unprotect_object(r->contents_list);
        r->contents_list = newlist;
        scm_gc_protect_object(r->contents_list);

        gnc_column_view_set_option(r->odb, "__general", "report-list",
                                   r->contents_list);
        gnc_options_dialog_changed (r->optwin);
    }

    update_display_lists(r);
}