示例#1
0
static GtkWidget *
make_menu (GNCSearchCoreType *fe)
{
    GNCSearchAccount *fi = (GNCSearchAccount *)fe;
    GNCSearchAccountPrivate *priv;
    GtkComboBox *combo;
    int initial = 0;

    combo = GTK_COMBO_BOX(gnc_combo_box_new_search());

    priv = _PRIVATE(fi);
    if (priv->match_all)
    {
        gnc_combo_box_search_add(combo, _("matches all accounts"), QOF_GUID_MATCH_ALL);
        initial = QOF_GUID_MATCH_ALL;
    }
    else
    {
        gnc_combo_box_search_add(combo, _("matches any account"), QOF_GUID_MATCH_ANY);
        gnc_combo_box_search_add(combo, _("matches no accounts"), QOF_GUID_MATCH_NONE);
        initial = QOF_GUID_MATCH_ANY;
    }

    gnc_combo_box_search_changed(combo, &fi->how);
    gnc_combo_box_search_set_active(combo, fi->how ? fi->how : initial);

    return GTK_WIDGET(combo);
}
/* The user clicked on the button.  Pop up the selection window */
static void
search_cb(GtkButton * button, gpointer user_data)
{
    GNCGeneralSearch *gsl = user_data;
    GNCGeneralSearchPrivate *priv;
    GNCSearchWindow *sw;

    priv = _PRIVATE(gsl);
    if (priv->sw)
    {
        gnc_search_dialog_raise (priv->sw);
        return;
    }

    sw = (priv->search_cb)(gsl->selected_item, priv->user_data);

    /* NULL means nothing to 'select' */
    if (sw == NULL)
        return;

    /* Ok, save this search window and setup callbacks */
    priv->sw = sw;

    /* Catch when the search dialog closes */
    gnc_search_dialog_connect_on_close (sw, G_CALLBACK (on_close_cb),
                                        gsl);

    /* Catch the selection */
    gnc_search_dialog_set_select_cb (sw, new_item_selected_cb,
                                     gsl, gsl->allow_clear);

}
/**
 * gnc_general_search_new:
 *
 * Creates a new GNCGeneralSearch widget which can be used to provide
 * an easy way to choose selections.
 *
 * @param type The type of object that this widget will be used for.
 * This parameter is a QofIdTypeConst.
 * @param label The label for the GtkButton child widget.
 * @param text_editable switch to enable or disable direct text entry
 * @param search_cb The callback function to use when an object has been
 * selected in the search dialog. This dialog is created when clicking on
 * the GtkButton child widget.
 * @param user_data Generic pointer to context relevant data that can be
 * used by callback functions later on. At present, depending on the context
 * this can be a QofBook, a GncISI structure or a InvoiceWindow structure.
 * @param book Pointer to the QofBook for this search widget. This is used for
 * the autocompletion in the text entry widget.
 *
 * @return a GNCGeneralSearch widget.
 */
GtkWidget *
gnc_general_search_new (QofIdTypeConst type,
                        const char    *label,
                        gboolean       text_editable,
                        GNCSearchCB    search_cb,
                        gpointer       user_data,
                        QofBook       *book)
{
    GNCGeneralSearch *gsl;
    GNCGeneralSearchPrivate *priv;
    const QofParam *get_guid;

    g_return_val_if_fail (type && label && search_cb, NULL);

    get_guid = qof_class_get_parameter (type, QOF_PARAM_GUID);
    g_return_val_if_fail (get_guid, NULL);

    gsl = g_object_new (GNC_TYPE_GENERAL_SEARCH, NULL);

    create_children (gsl, label, text_editable, type, book);

    priv = _PRIVATE(gsl);
    priv->type = type;
    priv->search_cb = search_cb;
    priv->user_data = user_data;
    priv->get_guid = get_guid;
    priv->component_id =
        gnc_register_gui_component (GNCGENERALSEARCH_CLASS,
                                    refresh_handler, NULL, gsl);

    return GTK_WIDGET (gsl);
}
/**
 * gnc_general_search_set_selected:
 * @gsl: the general selection widget
 * @selection: the selection to point to
 *
 * Sets the selection value of the widget to a particular pointer.
 *
 * Returns nothing.
 */
void
gnc_general_search_set_selected (GNCGeneralSearch *gsl, gpointer selection)
{
    GNCGeneralSearchPrivate *priv;

    g_return_if_fail(gsl != NULL);
    g_return_if_fail(GNC_IS_GENERAL_SEARCH(gsl));

    priv = _PRIVATE(gsl);
    if (selection != gsl->selected_item)
    {
        gsl->selected_item = selection;
        g_signal_emit(gsl,
                      general_search_signals[SELECTION_CHANGED], 0);
    }
    reset_selection_text (gsl);

    gnc_gui_component_clear_watches (priv->component_id);

    if (selection)
    {
        const QofParam *get_guid = priv->get_guid;
        priv->guid = * ((GncGUID *)(get_guid->param_getfcn
                                    (gsl->selected_item, get_guid)));
        gnc_gui_component_watch_entity
        (priv->component_id, &(priv->guid),
         QOF_EVENT_MODIFY | QOF_EVENT_DESTROY);
    }
    else
        priv->guid = *guid_null ();
}
static void
gnc_general_search_destroy (GtkObject *object)
{
    GNCGeneralSearch *gsl;
    GNCGeneralSearchPrivate *priv;

    g_return_if_fail (object != NULL);
    g_return_if_fail (GNC_IS_GENERAL_SEARCH (object));

    gsl = GNC_GENERAL_SEARCH (object);

    gsl->entry = NULL;
    gsl->button = NULL;

    priv = _PRIVATE(gsl);
    /* Clear the callbacks */
    if (priv->sw)
    {
        gnc_search_dialog_set_select_cb (priv->sw, NULL, NULL, FALSE);
        gnc_search_dialog_disconnect (priv->sw, gsl);
        priv->sw = NULL;
    }
    if (priv->component_id)
    {
        /* Unregister ourselves */
        gnc_unregister_gui_component (priv->component_id);
        priv->component_id = 0;
    }

    if (GTK_OBJECT_CLASS (parent_class)->destroy)
        GTK_OBJECT_CLASS (parent_class)->destroy (object);
}
示例#6
0
static GtkWidget *
gncs_get_widget (GNCSearchCoreType *fe)
{
    GtkWidget *entry, *toggle, *menu, *box;
    GNCSearchString *fi = (GNCSearchString *)fe;
    GNCSearchStringPrivate *priv;

    g_return_val_if_fail (fi, NULL);
    g_return_val_if_fail (IS_GNCSEARCH_STRING (fi), NULL);

    priv = _PRIVATE(fi);
    box = gtk_hbox_new (FALSE, 3);

    /* Build and connect the option menu */
    menu = make_menu (fe);
    gtk_box_pack_start (GTK_BOX (box), menu, FALSE, FALSE, 3);

    /* Build and connect the entry window */
    entry = gtk_entry_new ();
    if (fi->value)
        gtk_entry_set_text (GTK_ENTRY (entry), fi->value);
    g_signal_connect (G_OBJECT (entry), "changed", G_CALLBACK (entry_changed), fe);
    gtk_box_pack_start (GTK_BOX (box), entry, FALSE, FALSE, 3);
    priv->entry = entry;

    /* Build and connect the case-sensitive check button; defaults to off */
    toggle = gtk_check_button_new_with_label (_("Match case"));
    g_signal_connect (G_OBJECT(toggle), "toggled", G_CALLBACK (toggle_changed), fe);
    gtk_box_pack_start (GTK_BOX (box), toggle, FALSE, FALSE, 3);

    /* And return the box */
    return box;
}
示例#7
0
static GNCSearchCoreType *gncs_clone(GNCSearchCoreType *fe)
{
    GNCSearchAccount *se, *fse = (GNCSearchAccount *)fe;
    GNCSearchAccountPrivate *se_priv, *fse_priv;

    g_return_val_if_fail (fse, NULL);
    g_return_val_if_fail (IS_GNCSEARCH_ACCOUNT (fse), NULL);
    fse_priv = _PRIVATE(fse);

    se = gnc_search_account_new ();
    se_priv = _PRIVATE(se);
    se->how = fse->how;
    se_priv->match_all = fse_priv->match_all;
    se_priv->selected_accounts = g_list_copy (fse_priv->selected_accounts);

    return (GNCSearchCoreType *)se;
}
/* The search dialog has closed; let's forget about her */
static int
on_close_cb (GtkDialog *dialog, gpointer user_data)
{
    GNCGeneralSearch *gsl = user_data;
    GNCGeneralSearchPrivate *priv;

    priv = _PRIVATE(gsl);
    priv->sw = NULL;
    return FALSE;
}
示例#9
0
static char *
describe_button (GNCSearchAccount *fi)
{
    GNCSearchAccountPrivate *priv;

    priv = _PRIVATE(fi);
    if (priv->selected_accounts)
        return (_("Selected Accounts"));
    return (_("Choose Accounts"));
}
示例#10
0
static void
camel_stream_filter_init (CamelStreamFilter *obj)
{
	struct _CamelStreamFilterPrivate *p;

	_PRIVATE(obj) = p = g_malloc0(sizeof(*p));
	p->realbuffer = g_malloc(READ_SIZE + READ_PAD);
	p->buffer = p->realbuffer + READ_PAD;
	p->last_was_read = TRUE;
	p->flushed = FALSE;
}
示例#11
0
/**
 * gnc_search_account_matchall_new:
 *
 * Create a new GNCSearchAccount object.
 *
 * Return value: A new #GNCSearchAccount object.
 **/
GNCSearchAccount *
gnc_search_account_matchall_new (void)
{
    GNCSearchAccount *o;
    GNCSearchAccountPrivate *priv;

    o = g_object_new(GNC_TYPE_SEARCH_ACCOUNT, NULL);
    priv = _PRIVATE(o);
    priv->match_all = TRUE;
    o->how = QOF_GUID_MATCH_ALL;
    return o;
}
示例#12
0
static void
editable_enters (GNCSearchCoreType *fe)
{
    GNCSearchString *fi = (GNCSearchString *)fe;
    GNCSearchStringPrivate *priv;

    g_return_if_fail (fi);
    g_return_if_fail (IS_GNCSEARCH_STRING (fi));

    priv = _PRIVATE(fi);
    if (priv->entry)
        gtk_entry_set_activates_default(GTK_ENTRY (priv->entry), TRUE);
}
示例#13
0
static void
grab_focus (GNCSearchCoreType *fe)
{
    GNCSearchString *fi = (GNCSearchString *)fe;
    GNCSearchStringPrivate *priv;

    g_return_if_fail (fi);
    g_return_if_fail (IS_GNCSEARCH_STRING (fi));

    priv = _PRIVATE(fi);
    if (priv->entry)
        gtk_widget_grab_focus (priv->entry);
}
示例#14
0
/* The "selection" contents have changed.  Change the text. */
static void
reset_selection_text (GNCGeneralSearch *gsl)
{
    GNCGeneralSearchPrivate *priv;
    const char *text;

    priv = _PRIVATE(gsl);
    if (gsl->selected_item == NULL)
        text = "";
    else
        text = qof_object_printable (priv->type, gsl->selected_item);

    gtk_entry_set_text(GTK_ENTRY(gsl->entry), text);
}
示例#15
0
static void
camel_stream_filter_finalize(CamelObject *o)
{
	CamelStreamFilter *filter = (CamelStreamFilter *)o;
	struct _CamelStreamFilterPrivate *p = _PRIVATE(filter);
	struct _filter *fn, *f;

	f = p->filters;
	while (f) {
		fn = f->next;
		camel_object_unref((CamelObject *)f->filter);
		g_free(f);
		f = fn;
	}
	g_free(p->realbuffer);
	g_free(p);
	camel_object_unref((CamelObject *)filter->source);
}
示例#16
0
/* We've got a refresh event */
static void
refresh_handler (GHashTable *changes, gpointer data)
{
    GNCGeneralSearch *gsl = data;
    GNCGeneralSearchPrivate *priv;
    const EventInfo *info;

    priv = _PRIVATE(gsl);
    if (changes)
    {
        info = gnc_gui_get_entity_events (changes, &priv->guid);
        if (info)
        {
            if (info->event_mask & QOF_EVENT_DESTROY)
                gsl->selected_item = NULL;
            reset_selection_text (gsl);
        }
    }
}
示例#17
0
static QofQueryPredData* gncs_get_predicate (GNCSearchCoreType *fe)
{
    GNCSearchAccountPrivate *priv;
    GNCSearchAccount *fi = (GNCSearchAccount *)fe;
    GList *l = NULL, *node;

    g_return_val_if_fail (fi, NULL);
    g_return_val_if_fail (IS_GNCSEARCH_ACCOUNT (fi), NULL);

    priv = _PRIVATE(fi);
    for (node = priv->selected_accounts; node; node = node->next)
    {
        Account *acc = node->data;
        const GncGUID *guid = xaccAccountGetGUID (acc);
        l = g_list_prepend (l, (gpointer)guid);
    }
    l = g_list_reverse (l);

    return qof_query_guid_predicate (fi->how, l);
}
示例#18
0
static void
ecp_set_target (EConfig *ec, EConfigTarget *t)
{
	struct _ECalConfigPrivate *p = _PRIVATE(ec);

	((EConfigClass *)ecp_parent_class)->set_target(ec, t);

	if (t) {
		switch (t->type) {
		case EC_CONFIG_TARGET_SOURCE: {
			ECalConfigTargetSource *s = (ECalConfigTargetSource *)t;

			p->source_changed_id = g_signal_connect (s->source, "changed", G_CALLBACK (ecp_source_changed), ec);
			break; }
		case EC_CONFIG_TARGET_PREFS: {
			/* ECalConfigTargetPrefs *s = (ECalConfigTargetPrefs *)t; */
			break; }
		}
	}
}
示例#19
0
static gboolean
gncs_validate (GNCSearchCoreType *fe)
{
    GNCSearchAccount *fi = (GNCSearchAccount *)fe;
    GNCSearchAccountPrivate *priv;
    gboolean valid = TRUE;

    g_return_val_if_fail (fi, FALSE);
    g_return_val_if_fail (IS_GNCSEARCH_ACCOUNT (fi), FALSE);

    priv = _PRIVATE(fi);
    if (priv->selected_accounts == NULL && fi->how )
    {
        valid = FALSE;
        gnc_error_dialog (NULL, "%s", _("You have not selected any accounts"));
    }

    /* XXX */

    return valid;
}
static void
camel_store_summary_finalise (CamelObject *obj)
{
	struct _CamelStoreSummaryPrivate *p;
	CamelStoreSummary *s = (CamelStoreSummary *)obj;

	p = _PRIVATE(obj);

	camel_store_summary_clear(s);
	g_ptr_array_free(s->folders, TRUE);
	g_hash_table_destroy(s->folders_path);

	g_free(s->summary_path);

	if (s->store_info_chunks)
		e_memchunk_destroy(s->store_info_chunks);

	g_mutex_free(p->summary_lock);
	g_mutex_free(p->io_lock);
	g_mutex_free(p->alloc_lock);
	g_mutex_free(p->ref_lock);

	g_free(p);
}
示例#21
0
static void
ecp_target_free (EConfig *ec, EConfigTarget *t)
{
	struct _ECalConfigPrivate *p = _PRIVATE (ec);

	if (ec->target == t) {
		switch (t->type) {
		case EC_CONFIG_TARGET_SOURCE: {
			ECalConfigTargetSource *s = (ECalConfigTargetSource *)t;

			if (p->source_changed_id) {
				g_signal_handler_disconnect (s->source, p->source_changed_id);
				p->source_changed_id = 0;
			}
			break; }
		case EC_CONFIG_TARGET_PREFS: {
			/* ECalConfigTargetPrefs *s = (ECalConfigTargetPrefs *)t; */
			break; }
		}
	}

	switch (t->type) {
	case EC_CONFIG_TARGET_SOURCE: {
		ECalConfigTargetSource *s = (ECalConfigTargetSource *)t;
		if (s->source)
			g_object_unref (s->source);
		break; }
	case EC_CONFIG_TARGET_PREFS: {
		ECalConfigTargetPrefs *s = (ECalConfigTargetPrefs *)t;
		if (s->gconf)
			g_object_unref (s->gconf);
		break; }
	}

	((EConfigClass *) ecp_parent_class)->target_free (ec, t);
}
static void
camel_store_summary_init (CamelStoreSummary *s)
{
	struct _CamelStoreSummaryPrivate *p;

	p = _PRIVATE(s) = g_malloc0(sizeof(*p));

	s->store_info_size = sizeof(CamelStoreInfo);

	s->store_info_chunks = NULL;

	s->version = CAMEL_STORE_SUMMARY_VERSION;
	s->flags = 0;
	s->count = 0;
	s->time = 0;

	s->folders = g_ptr_array_new();
	s->folders_path = g_hash_table_new(g_str_hash, g_str_equal);

	p->summary_lock = g_mutex_new();
	p->io_lock = g_mutex_new();
	p->alloc_lock = g_mutex_new();
	p->ref_lock = g_mutex_new();
}
示例#23
0
/**  The focus left the general search edit widget, so reset the widget to
 *   its last known good value.  If the widget value contained a valid
 *   value then this is a noop.  Otherwise the widget will be reset
 *   to the last user selected value.  This latter state will occur
 *   if the user has typed characters directly into the widget but not
 *   selected a completion.
 *
 *   @param entry The entry widget in which the user is typing.
 *
 *   @param event Unused.
 *
 *   @param gsl A pointer to a general search widget. */
static gboolean
gnc_gsl_focus_out_cb (GtkEntry         *entry,
                      GdkEventFocus    *event,
                      GNCGeneralSearch *gsl)
{
    const gchar	*text;
    GtkEntryCompletion *completion;
    GtkTreeModel *model;
    GtkTreeIter iter;
    gchar *lc_text, *tree_string, *lc_tree_string;
    gboolean match, valid_iter;
    QofObject *qofobject;
    gpointer selected_item = NULL;

    /* Attempt to match the current text to a qofobject. */
    completion = gtk_entry_get_completion(entry);
    model = gtk_entry_completion_get_model(completion);

    /* Return if completion tree is empty */
    valid_iter = gtk_tree_model_get_iter_first(model, &iter);
    if (!valid_iter)
        return FALSE;

    text = gtk_entry_get_text(entry);
    lc_text = g_utf8_strdown(text, -1);

    /* The last, valid selected entry can match the entered text
     * No need to search further in that case */
    if (gsl->selected_item)
    {
        GNCGeneralSearchPrivate *	priv;

        priv = _PRIVATE(gsl);
        tree_string = g_strdup(qof_object_printable(priv->type, gsl->selected_item));
        lc_tree_string = g_utf8_strdown(tree_string, -1);
        match = g_utf8_collate(lc_text, lc_tree_string) == 0;
        g_free(tree_string);
        g_free(lc_tree_string);
        if (match)
            selected_item = gsl->selected_item;
    }

    /* Otherwise, find a match in the completion list */
    while (valid_iter && !selected_item)
    {
        gtk_tree_model_get(model, &iter, GSL_COLUMN_TEXT, &tree_string, -1);
        lc_tree_string = g_utf8_strdown(tree_string, -1);
        match = g_utf8_collate(lc_text, lc_tree_string) == 0;
        g_free(tree_string);
        g_free(lc_tree_string);
        if (match)
        {
            gtk_tree_model_get(model, &iter, GSL_COLUMN_QOFOBJECT, &qofobject, -1);
            selected_item = qofobject;
        }
        else
            valid_iter = gtk_tree_model_iter_next(model, &iter);
    }

    g_free(lc_text);
    gnc_general_search_set_selected (gsl, selected_item);
    return FALSE;
}
示例#24
0
static void
button_clicked (GtkButton *button, GNCSearchAccount *fi)
{
    GNCSearchAccountPrivate *priv;
    GtkDialog *dialog;
    GtkWidget *account_tree;
    GtkWidget *accounts_scroller;
    GtkWidget *label;
    char *desc;
    GtkTreeSelection *selection;

    /* Create the account tree */
    account_tree = GTK_WIDGET(gnc_tree_view_account_new (FALSE));
    gtk_tree_view_set_headers_visible (GTK_TREE_VIEW(account_tree), FALSE);
    selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(account_tree));
    gtk_tree_selection_set_mode (selection, GTK_SELECTION_MULTIPLE);

    /* Select the currently-selected accounts */
    priv = _PRIVATE(fi);
    if (priv->selected_accounts)
        gnc_tree_view_account_set_selected_accounts (GNC_TREE_VIEW_ACCOUNT(account_tree),
                priv->selected_accounts, FALSE);

    /* Create the account scroller and put the tree in it */
    accounts_scroller = gtk_scrolled_window_new (NULL, NULL);
    gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW(accounts_scroller),
                                    GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
    gtk_container_add(GTK_CONTAINER(accounts_scroller), account_tree);
    gtk_widget_set_size_request(GTK_WIDGET(accounts_scroller), 300, 300);

    /* Create the label */
    label = gtk_label_new (_("Select Accounts to Match"));

    /* Create the dialog */
    dialog =
        GTK_DIALOG(gtk_dialog_new_with_buttons(_("Select the Accounts to Compare"),
                   NULL,
                   0,
                   _("_Cancel"), GTK_RESPONSE_CANCEL,
                   _("_OK"), GTK_RESPONSE_OK,
                   NULL));

    /* Put the dialog together */
    gtk_box_pack_start ((GtkBox *) gtk_dialog_get_content_area (dialog), label,
                        FALSE, FALSE, 3);
    gtk_box_pack_start ((GtkBox *) gtk_dialog_get_content_area (dialog), accounts_scroller,
                        TRUE, TRUE, 3);

    gtk_widget_show_all (GTK_WIDGET (dialog));

    /* Now run the dialog */
    if (gtk_dialog_run (dialog) == GTK_RESPONSE_OK)
    {
        if (priv->selected_accounts)
            g_list_free (priv->selected_accounts);

        priv->selected_accounts =
            gnc_tree_view_account_get_selected_accounts (GNC_TREE_VIEW_ACCOUNT (account_tree));

        desc = describe_button (fi);
        gtk_label_set_text (GTK_LABEL (gtk_bin_get_child (GTK_BIN (button))), desc);
    }

    gtk_widget_destroy (GTK_WIDGET (dialog));
}