Exemple #1
0
    gnc_prefs_set_bool(GNC_PREFS_GROUP, GNC_PREF_SHOW_TIPS, active);
}


/***********************************/
/*     Tip of the Day Parser       */
/***********************************/
static gboolean
gnc_totd_initialize (void)
{
    gchar *filename, *contents, *new;
    gsize length;
    GError *error;

    /* Find the file */
    filename = gnc_filepath_locate_data_file("tip_of_the_day.list");
    if (!filename)
        return FALSE;

    /* Read it */
    if (!g_file_get_contents(filename, &contents, &length, &error))
    {
        printf("Unable to read file: %s\n", error->message);
        g_error_free(error);
        g_free(filename);
        return FALSE;
    }
    g_free(filename);

    /* Split into multiple strings. Due to the nature of the
     * tip list file, this can contain empty strings */
Exemple #2
0
static gboolean
gnc_totd_initialize (void)
{
    gchar *filename, *contents, *new_str;
    gsize length;
    GError *error;

    /* Find the file */
    filename = gnc_filepath_locate_data_file("tip_of_the_day.list");
    if (!filename)
        return FALSE;

    /* Read it */
    if (!g_file_get_contents(filename, &contents, &length, &error))
    {
        printf("Unable to read file: %s\n", error->message);
        g_error_free(error);
        g_free(filename);
        return FALSE;
    }
    g_free(filename);

    /* Split into multiple strings. Due to the nature of the
     * tip list file, this can contain empty strings */
    tip_list = g_strsplit(contents, "\n", 0);
    g_free(contents);
    contents = NULL;

    /* Remove the empty strings */
    for (tip_count = 0; tip_list[tip_count] != NULL; tip_count++)
    {
        if (*tip_list[tip_count]!='\0')
        {
            g_strstrip(tip_list[tip_count]);
            if (!contents)
                contents = g_strdup (tip_list[tip_count]);
            else
            {
                new_str = g_strjoin ("\n", contents, tip_list[tip_count], NULL);
                g_free (contents);
                contents = new_str;
            }
        }
    }

    /* Split cleaned up contents into multiple strings again */
    g_strfreev (tip_list);
    tip_list = g_strsplit(contents, "\n", 0);

    /* Convert any escaped characters while counting the strings */
    for (tip_count = 0; tip_list[tip_count] != NULL; tip_count++)
    {
        new_str = g_strcompress(tip_list[tip_count]);
        g_free(tip_list[tip_count]);
        tip_list[tip_count] = new_str;
    }


    /* Don't continue when no tips were found, to prevent
     * gnc_new_tip_number doesn't handle that case (it would try to
     * display the terminating NULL). There's nothing to show
     * anyway...*/
    if (tip_count == 0)
    {
        PWARN("No tips found - Tips of the day window won't be displayed.");
        return FALSE;
    }

    return TRUE;
}