Exemplo n.º 1
0
/***********************************************************************
 *  This function should be called to change the tip number.  It
 *  handles clamping the number to the range of tips available, saving
 *  the number in the preferences database, and updating the dialog window
 *  with the text of the newly selected tip.
 *
 *  @param Tip of the day structure. This points to the dialog and
 *  the GtkTextView widget that holds the text of the tip.
 *
 *  @param offset Which tip to show.  If the value is zero then the
 *  current tip will be shown.  If the value is negative the previous
 *  tip will be shown.  If the value is positive the next tip will be
 *  shown.
 ************************************************************************/
static void
gnc_new_tip_number (TotdDialog *totd_dialog, gint offset)
{

    gchar **tip_components;
    gchar *tip;

    ENTER("TotdDialog %p, offset %d", totd_dialog, offset);
    current_tip_number += offset;
    DEBUG("clamp %d to '0 <= x < %d'", current_tip_number, tip_count);
    if (current_tip_number < 0)
        current_tip_number = tip_count - 1;
    if (current_tip_number >= tip_count)
        current_tip_number = 0;
    gnc_prefs_set_int(GNC_PREFS_GROUP, GNC_PREF_CURRENT_TIP, current_tip_number);

    /* A tip consists of a translatable string, which might contain a %s
     * placeholder, optionally followed by a | and a (non-translated)
     * string to put in the placeholder. For example:
     *
     *  Welcome to GnuCash version %s|2.4
     */
    tip_components = g_strsplit(tip_list[current_tip_number], "|", 0);
    /* If the tip is empty, g_strisplit will return an empty list. This
     * shouldn't normally happen, but make sure we don't crash just in
     * case */
    if (tip_components[0] == NULL)
    {
        tip = g_strdup("");
    }
    else
    {
        /* Use printf to do the substitution. Note that if there is no |
         * in the tip, tip_components[1] will be the terminating NULL,
         * so this will never cause an out-of-bounds array access.
         */
        tip = g_strdup_printf( _(tip_components[0]), tip_components[1]);
    }

    g_strfreev(tip_components);
    gtk_text_buffer_set_text(gtk_text_view_get_buffer(GTK_TEXT_VIEW(totd_dialog->textview)),
                             tip, -1);
    g_free(tip);
    LEAVE("");
}
Exemplo n.º 2
0
gint
gnc_dialog_run (GtkDialog *dialog, const gchar *pref_name)
{
    GtkWidget *perm, *temp;
    gboolean ask = TRUE;
    gint response;

    /* Does the user want to see this question? If not, return the
     * previous answer. */
    response = gnc_prefs_get_int(GNC_PREFS_GROUP_WARNINGS_PERM, pref_name);
    if (response != 0)
        return response;
    response = gnc_prefs_get_int(GNC_PREFS_GROUP_WARNINGS_TEMP, pref_name);
    if (response != 0)
        return response;

    /* Add in the checkboxes to find out if the answer should be remembered. */
#if 0
    if (GTK_IS_MESSAGE_DIALOG(dialog))
    {
        GtkMessageType type;
        g_object_get(dialog, "message-type", &type, (gchar*)NULL);
        ask = (type == GTK_MESSAGE_QUESTION);
    }
    else
    {
        ask = FALSE;
    }
#endif
    perm = gtk_check_button_new_with_mnemonic
           (ask
            ? _("Remember and don't _ask me again.")
            : _("Don't _tell me again."));
    temp = gtk_check_button_new_with_mnemonic
           (ask
            ? _("Remember and don't ask me again this _session.")
            : _("Don't tell me again this _session."));
    gtk_widget_show(perm);
    gtk_widget_show(temp);
    gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (dialog)), perm, TRUE, TRUE, 0);
    gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (dialog)), temp, TRUE, TRUE, 0);
    g_signal_connect(perm, "clicked", G_CALLBACK(gnc_perm_button_cb), temp);

    /* OK. Present the dialog. */
    response = gtk_dialog_run(dialog);
    if ((response == GTK_RESPONSE_NONE) || (response == GTK_RESPONSE_DELETE_EVENT))
    {
        return GTK_RESPONSE_CANCEL;
    }

    if (response != GTK_RESPONSE_CANCEL)
    {
        /* Save the answer? */
        if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(perm)))
        {
            gnc_prefs_set_int(GNC_PREFS_GROUP_WARNINGS_PERM, pref_name, response);
        }
        else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(temp)))
        {
            gnc_prefs_set_int(GNC_PREFS_GROUP_WARNINGS_TEMP, pref_name, response);
        }
    }
    return response;
}