<commit_before>/**
 * @file   gui-prefs.c
 * @brief
 *
 * Copyright (C) 2010-2011 Gummi-Dev Team <<EMAIL>>
 * All Rights reserved.
 *
 * Permission is hereby granted, free of charge, to any person
 * obtaining a copy of this software and associated documentation
 * files (the "Software"), to deal in the Software without
 * restriction, including without limitation the rights to use,
 * copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following
 * conditions:
 *
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * OTHER DEALINGS IN THE SOFTWARE.
 */

#include "gui-prefs.h"

#include <stdlib.h>
#include <string.h>

#include <glib.h>
#include <gtk/gtk.h>

#include "constants.h"
#include "configfile.h"
#include "environment.h"
#include "gui/gui-main.h"
#include "latex.h"
#include "utils.h"

#include "compile/rubber.h"
#include "compile/latexmk.h"
#include "compile/texlive.h"


/* TODO: needs mayor cleanup */

extern GummiGui* gui;
extern Gummi* gummi;

static void set_all_tab_settings (GuPrefsGui* prefs);
static void set_tab_view_settings (GuPrefsGui* prefs);
static void set_tab_editor_settings (GuPrefsGui* prefs);
static void set_tab_fontcolor_settings (GuPrefsGui* prefs);
static void set_tab_defaulttext_settings (GuPrefsGui* prefs);
static void set_tab_compilation_settings (GuPrefsGui* prefs);
static void set_tab_preview_settings (GuPrefsGui* prefs);
static void set_tab_miscellaneous_settings (GuPrefsGui* prefs);


GuPrefsGui* prefsgui_init (GtkWindow* mainwindow) {
    GuPrefsGui* p = g_new0 (GuPrefsGui, 1);
    GtkBuilder* builder = gtk_builder_new ();
    gchar* ui = g_build_filename (DATADIR, "ui", "prefs.glade", NULL);
    gtk_builder_add_from_file (builder, ui, NULL);
    gtk_builder_set_translation_domain (builder, PACKAGE);
    g_free (ui);

    p->prefwindow =
        GTK_WIDGET (gtk_builder_get_object (builder, "prefwindow"));
    p->notebook =
        GTK_NOTEBOOK (gtk_builder_get_object (builder, "notebook1"));
    p->textwrap_button =
        GTK_CHECK_BUTTON (gtk_builder_get_object (builder, "textwrapping"));
    p->wordwrap_button =
        GTK_CHECK_BUTTON (gtk_builder_get_object (builder, "wordwrapping"));
    p->line_numbers =
        GTK_CHECK_BUTTON (gtk_builder_get_object (builder, "line_numbers")); 
    p->highlighting =
        GTK_CHECK_BUTTON (gtk_builder_get_object (builder, "highlighting")); 
    p->tabwidth =
        GTK_SPIN_BUTTON (gtk_builder_get_object (builder, "tabwidth"));
    p->spaces_instof_tabs =
        GTK_CHECK_BUTTON(gtk_builder_get_object(builder, "spaces_instof_tabs"));
    p->autoindentation =
        GTK_CHECK_BUTTON (gtk_builder_get_object (builder, "autoindentation"));
    p->autosaving =
        GTK_CHECK_BUTTON (gtk_builder_get_object (builder, "autosaving")); 
    p->compile_status =
        GTK_CHECK_BUTTON (gtk_builder_get_object (builder, "compile_status")); 
    p->autosave_timer =
        GTK_SPIN_BUTTON (gtk_builder_get_object (builder, "autosave_timer"));
    p->combo_languages =
        GTK_COMBO_BOX (gtk_builder_get_object (builder, "combo_languages"));
    p->list_languages =
        GTK_LIST_STORE (gtk_builder_get_object (builder, "list_languages"));
    p->styleschemes_treeview =
        GTK_TREE_VIEW(gtk_builder_get_object(builder, "styleschemes_treeview"));
    p->list_styleschemes =
        GTK_LIST_STORE (gtk_builder_get_object (builder, "list_styleschemes"));
    p->default_text =
        GTK_TEXT_VIEW (gtk_builder_get_object (builder, "default_text"));
    p->default_buffer = 
        gtk_text_view_get_buffer (p->default_text);
    p->editor_font =
        GTK_FONT_BUTTON (gtk_builder_get_object (builder, "editor_font"));
    p->compile_scheme =
        GTK_COMBO_BOX (gtk_builder_get_object (builder, "combo_compilescheme"));
    p->compile_timer =
        GTK_SPIN_BUTTON (gtk_builder_get_object (builder, "compile_timer"));
    p->autoexport =
        GTK_CHECK_BUTTON (gtk_builder_get_object (builder, "auto_export"));
        
    p->typ_pdflatex =
        GTK_TOGGLE_BUTTON (gtk_builder_get_object (builder, "typ_pdflatex"));
    p->typ_xelatex =
        GTK_TOGGLE_BUTTON (gtk_builder_get_object (builder, "typ_xelatex"));
    p->typ_rubber =
        GTK_TOGGLE_BUTTON (gtk_builder_get_object (builder, "typ_rubber"));
    p->typ_latexmk =
        GTK_TOGGLE_BUTTON (gtk_builder_get_object (builder, "typ_latexmk"));

    p->method_texpdf =
        GTK_TOGGLE_BUTTON (gtk_builder_get_object (builder, "method_texpdf"));
    p->method_texdvipdf =
        GTK_TOGGLE_BUTTON (gtk_builder_get_object (builder, "method_texdvipdf"));
    p->method_texdvipspdf =
        GTK_TOGGLE_BUTTON (gtk_builder_get_object (builder, "method_texdvipspdf"));
        
    p->opt_shellescape = 
        GTK_TOGGLE_BUTTON (gtk_builder_get_object (builder, "opt_shellescape"));
    p->opt_synctex = 
        GTK_TOGGLE_BUTTON (gtk_builder_get_object (builder, "opt_synctex"));
        
    p->combo_animated_scroll =
        GTK_COMBO_BOX (gtk_builder_get_object (builder, "combo_animated_scroll"));
    p->spin_cache_size =
        GTK_SPIN_BUTTON (gtk_builder_get_object (builder, "spin_cache_size"));
        
    p->view_box = GTK_VBOX (gtk_builder_get_object (builder, "view_box"));
    p->editor_box = GTK_HBOX (gtk_builder_get_object (builder, "editor_box"));
    p->compile_box = GTK_HBOX (gtk_builder_get_object (builder, "compile_box"));

    gtk_window_set_transient_for (GTK_WINDOW (p->prefwindow), mainwindow);

#ifdef USE_GTKSPELL
    /* list available languages */
    gchar* ptr = 0;

    Tuple2 pret = utils_popen_r ("enchant-lsmod -list-dicts");

    ptr = strtok ((gchar*)pret.second, " \n");
    while (ptr) {
        GtkTreeIter iter;
        if (ptr[0] != '(') {
            gtk_list_store_append (p->list_languages, &iter);
            gtk_list_store_set (p->list_languages, &iter, 0, ptr, -1);
        }
        ptr = strtok (NULL, " \n");
    }
    gtk_combo_box_set_active (p->combo_languages, 0);
    g_free ((gchar*)pret.second);
#else
    /* desensitise gtkspell related GUI elements if not used */
    GtkWidget* box = GTK_WIDGET (
		gtk_builder_get_object (builder, "box_spellcheck"));
    gtk_widget_set_sensitive (box, FALSE);
#endif
    GList* schemes = editor_list_style_scheme_sorted ();
    GList* schemes_iter = schemes;
    gchar* desc = NULL;
    GtkTreeIter iter;
    while (schemes_iter) {
        desc = g_markup_printf_escaped ("<b>%s</b> - %s",<commit_msg>rewrite of gtkspell language list for win32 compatibility<commit_after>/**
 * @file   gui-prefs.c
 * @brief
 *
 * Copyright (C) 2010-2011 Gummi-Dev Team <<EMAIL>>
 * All Rights reserved.
 *
 * Permission is hereby granted, free of charge, to any person
 * obtaining a copy of this software and associated documentation
 * files (the "Software"), to deal in the Software without
 * restriction, including without limitation the rights to use,
 * copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following
 * conditions:
 *
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * OTHER DEALINGS IN THE SOFTWARE.
 */

#include "gui-prefs.h"

#include <stdlib.h>
#include <string.h>

#include <glib.h>
#include <gtk/gtk.h>

#include "constants.h"
#include "configfile.h"
#include "environment.h"
#include "gui/gui-main.h"
#include "latex.h"
#include "utils.h"

#include "compile/rubber.h"
#include "compile/latexmk.h"
#include "compile/texlive.h"


/* TODO: needs mayor cleanup */

extern GummiGui* gui;
extern Gummi* gummi;

static void set_all_tab_settings (GuPrefsGui* prefs);
static void set_tab_view_settings (GuPrefsGui* prefs);
static void set_tab_editor_settings (GuPrefsGui* prefs);
static void set_tab_fontcolor_settings (GuPrefsGui* prefs);
static void set_tab_defaulttext_settings (GuPrefsGui* prefs);
static void set_tab_compilation_settings (GuPrefsGui* prefs);
static void set_tab_preview_settings (GuPrefsGui* prefs);
static void set_tab_miscellaneous_settings (GuPrefsGui* prefs);


GuPrefsGui* prefsgui_init (GtkWindow* mainwindow) {
    GuPrefsGui* p = g_new0 (GuPrefsGui, 1);
    GtkBuilder* builder = gtk_builder_new ();
    gchar* ui = g_build_filename (DATADIR, "ui", "prefs.glade", NULL);
    gtk_builder_add_from_file (builder, ui, NULL);
    gtk_builder_set_translation_domain (builder, PACKAGE);
    g_free (ui);

    p->prefwindow =
        GTK_WIDGET (gtk_builder_get_object (builder, "prefwindow"));
    p->notebook =
        GTK_NOTEBOOK (gtk_builder_get_object (builder, "notebook1"));
    p->textwrap_button =
        GTK_CHECK_BUTTON (gtk_builder_get_object (builder, "textwrapping"));
    p->wordwrap_button =
        GTK_CHECK_BUTTON (gtk_builder_get_object (builder, "wordwrapping"));
    p->line_numbers =
        GTK_CHECK_BUTTON (gtk_builder_get_object (builder, "line_numbers")); 
    p->highlighting =
        GTK_CHECK_BUTTON (gtk_builder_get_object (builder, "highlighting")); 
    p->tabwidth =
        GTK_SPIN_BUTTON (gtk_builder_get_object (builder, "tabwidth"));
    p->spaces_instof_tabs =
        GTK_CHECK_BUTTON(gtk_builder_get_object(builder, "spaces_instof_tabs"));
    p->autoindentation =
        GTK_CHECK_BUTTON (gtk_builder_get_object (builder, "autoindentation"));
    p->autosaving =
        GTK_CHECK_BUTTON (gtk_builder_get_object (builder, "autosaving")); 
    p->compile_status =
        GTK_CHECK_BUTTON (gtk_builder_get_object (builder, "compile_status")); 
    p->autosave_timer =
        GTK_SPIN_BUTTON (gtk_builder_get_object (builder, "autosave_timer"));
    p->combo_languages =
        GTK_COMBO_BOX (gtk_builder_get_object (builder, "combo_languages"));
    p->list_languages =
        GTK_LIST_STORE (gtk_builder_get_object (builder, "list_languages"));
    p->styleschemes_treeview =
        GTK_TREE_VIEW(gtk_builder_get_object(builder, "styleschemes_treeview"));
    p->list_styleschemes =
        GTK_LIST_STORE (gtk_builder_get_object (builder, "list_styleschemes"));
    p->default_text =
        GTK_TEXT_VIEW (gtk_builder_get_object (builder, "default_text"));
    p->default_buffer = 
        gtk_text_view_get_buffer (p->default_text);
    p->editor_font =
        GTK_FONT_BUTTON (gtk_builder_get_object (builder, "editor_font"));
    p->compile_scheme =
        GTK_COMBO_BOX (gtk_builder_get_object (builder, "combo_compilescheme"));
    p->compile_timer =
        GTK_SPIN_BUTTON (gtk_builder_get_object (builder, "compile_timer"));
    p->autoexport =
        GTK_CHECK_BUTTON (gtk_builder_get_object (builder, "auto_export"));
        
    p->typ_pdflatex =
        GTK_TOGGLE_BUTTON (gtk_builder_get_object (builder, "typ_pdflatex"));
    p->typ_xelatex =
        GTK_TOGGLE_BUTTON (gtk_builder_get_object (builder, "typ_xelatex"));
    p->typ_rubber =
        GTK_TOGGLE_BUTTON (gtk_builder_get_object (builder, "typ_rubber"));
    p->typ_latexmk =
        GTK_TOGGLE_BUTTON (gtk_builder_get_object (builder, "typ_latexmk"));

    p->method_texpdf =
        GTK_TOGGLE_BUTTON (gtk_builder_get_object (builder, "method_texpdf"));
    p->method_texdvipdf =
        GTK_TOGGLE_BUTTON (gtk_builder_get_object (builder, "method_texdvipdf"));
    p->method_texdvipspdf =
        GTK_TOGGLE_BUTTON (gtk_builder_get_object (builder, "method_texdvipspdf"));
        
    p->opt_shellescape = 
        GTK_TOGGLE_BUTTON (gtk_builder_get_object (builder, "opt_shellescape"));
    p->opt_synctex = 
        GTK_TOGGLE_BUTTON (gtk_builder_get_object (builder, "opt_synctex"));
        
    p->combo_animated_scroll =
        GTK_COMBO_BOX (gtk_builder_get_object (builder, "combo_animated_scroll"));
    p->spin_cache_size =
        GTK_SPIN_BUTTON (gtk_builder_get_object (builder, "spin_cache_size"));
        
    p->view_box = GTK_VBOX (gtk_builder_get_object (builder, "view_box"));
    p->editor_box = GTK_HBOX (gtk_builder_get_object (builder, "editor_box"));
    p->compile_box = GTK_HBOX (gtk_builder_get_object (builder, "compile_box"));

    gtk_window_set_transient_for (GTK_WINDOW (p->prefwindow), mainwindow);

#ifdef USE_GTKSPELL
    /* list available languages */

    Tuple2 pret = utils_popen_r ("enchant-lsmod -list-dicts");
    int i;

    gchar** output = g_strsplit((gchar*)pret.second, "\n", BUFSIZ);
    gchar** elems = NULL;
    
    for(i = 0; output[i] != NULL; i++) {
        GtkTreeIter iter;
        elems = g_strsplit (output[i], " ", BUFSIZ);
        if (elems[0] != NULL) {
            gtk_list_store_append (p->list_languages, &iter);
            gtk_list_store_set (p->list_languages, &iter, 0, elems[0], -1);
        }
    }
    g_strfreev(output);
    g_strfreev(elems);

    gtk_combo_box_set_active (p->combo_languages, 0);
    g_free ((gchar*)pret.second);
#else
    /* desensitise gtkspell related GUI elements if not used */
    GtkWidget* box = GTK_WIDGET (
		gtk_builder_get_object (builder, "box_spellcheck"));
    gtk_widget_set_sensitive (box, FALSE);
#endif
    GList* schemes = editor_list_style_scheme_sorted ();
    GList* schemes_iter = schemes;
    gchar* desc = NULL;
    GtkTreeIter iter;
    while (schemes_iter) {
        desc = g_markup_printf_escaped ("<b>%s</b> - %s",
{'fraction_non_alphanumeric': 0.10710055048428681, 'fraction_numerical': 0.0025782175458156226, 'mean_word_length': 4.153321364452424, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 101, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7178790', 'n_tokens_mistral': 5034, 'n_tokens_neox': 4885, 'n_words': 1087}