예제 #1
0
static void timestamp_edited(GtkCellRendererText *renderer, gchar *path_string, gchar *new_timestamp, struct commodity_register *commodity_register) {
    struct tm tm;
    int increment=0;
    gchar *quote_guid = get_string_column_via_path_string(gtk_tree_view_get_model(COMMODITY_REGISTER_CORE.view),
                                                          path_string,
                                                          STORE_GUID);

    if (is_integer(new_timestamp, &increment))
        timestamp_edited_process_increment(commodity_register, quote_guid, increment);
    else if (strlen(new_timestamp) == 1) {
        /* Support some of the Gnucash timestamp manipulation keys */
        if (new_timestamp[0] == '=')
            timestamp_edited_process_increment(commodity_register, quote_guid, 1);
        else if (new_timestamp[0] == '-')
            timestamp_edited_process_increment(commodity_register, quote_guid, -1);
        else if (new_timestamp[0] == '+')
            timestamp_edited_process_increment(commodity_register, quote_guid, 7);
        else if (new_timestamp[0] == '_')
            timestamp_edited_process_increment(commodity_register, quote_guid, -7);
        else if (new_timestamp[0] == 't') {
            static sqlite3_stmt *query = NULL;
            PREPARE_QUERY_ONCE(db, "update prices set timestamp = datetime('now', 'localtime') where guid = :guid", query);
            timestamp_edited_run_query(commodity_register, query, quote_guid);
        } else if (new_timestamp[0] == 'm') {
            static sqlite3_stmt *query = NULL;
            /* Start of current month */
            PREPARE_QUERY_ONCE(db, "update prices set timestamp = datetime(timestamp, 'start of month') where guid = ?1", query);
            timestamp_edited_run_query(commodity_register, query, quote_guid);
        } else if (new_timestamp[0] == 'h') {
            static sqlite3_stmt *query = NULL;
            /* End of current month */
            PREPARE_QUERY_ONCE(db, "update prices set timestamp = datetime(timestamp, 'start of month', '31 days', 'start of month', '-1 days') where guid = ?1", query);
            timestamp_edited_run_query(commodity_register, query, quote_guid);
        } else
            display_message_dialog(DATE_ERROR_MESSAGE, GTK_MESSAGE_WARNING, NULL);
    }
    /* Did the user provide a timestamp? */
    else if ((strptime(new_timestamp, "%Y-%m-%d", &tm) != (char *) NULL)) {
        static sqlite3_stmt *query = NULL;
        PREPARE_QUERY_ONCE(db, "update prices set timestamp = ?1 where guid = ?2", query);
        BIND_TEXT(query, 1, new_timestamp);
        BIND_TEXT(query, 2, quote_guid);
        run_dm_query(query);
        refresh_commodity_register(commodity_register);
    } else
        display_message_dialog(DATE_ERROR_MESSAGE, GTK_MESSAGE_WARNING, NULL);

    /* and clean up */
    g_free(quote_guid);
}
예제 #2
0
void GUI::launch_documentation_html(void) {

  /** Launch the HTML-Documentation file to display it to the user through the GUI. **/

  GError *error = NULL ;

  char *doc_realpath = realpath(PATH_TO_DOCUMENTATION, NULL) ;

  gchar *doc_uri = g_filename_to_uri(doc_realpath, NULL, NULL);

  gtk_show_uri(NULL, doc_uri, GDK_CURRENT_TIME, &error);

  g_free(doc_uri) ;
  free(doc_realpath) ;

  #ifdef DEBUG
  // This call make crash the application, i don't know why. Not really needed, so we process only if DEBUG define.
  if (error != NULL) {

    string msg =  "Cannot display README:\n\n" ;

    msg += error->message ;

    display_message_dialog("Error README displaying !", msg.c_str() ) ;

  }
  #endif

    
  return ;

}
예제 #3
0
static void display_calendar_for_selected_row(struct commodity_register *commodity_register) {
    if (gtk_tree_selection_count_selected_rows(COMMODITY_REGISTER_CORE.selection)  == 1) {
        GtkTreeIter iter;
        GtkTreeModel *model;

        if (gtk_tree_selection_get_selected(COMMODITY_REGISTER_CORE.selection, &model, &iter)) {
            gchar *current_timestamp = get_string_column_via_iter(model, &iter, STORE_TIMESTAMP), *new_date;
            gchar current_date[DATE_SIZE];

            strncpy(current_date, current_timestamp, DATE_SIZE-1);
            current_date[DATE_SIZE-1] = NULL_CHARACTER;

            new_date = display_calendar(current_date, GTK_WIDGET(COMMODITY_REGISTER_CORE.window));
            /* Did we get a date back? */
            if (new_date != NULL) {
                gchar *path_string = gtk_tree_model_get_string_from_iter(model, &iter);
                gchar *new_time_stamp = g_strdup_printf("%s 00:00:00", new_date);
                timestamp_edited(GTK_CELL_RENDERER_TEXT(commodity_register->timestamp_renderer), path_string, new_time_stamp, commodity_register);
                g_free(path_string);
                g_free(new_date);
                g_free(new_time_stamp);
            }
        } else {
            fprintf(stderr, "mouse_button_pressed: gtk_tree_selection_get_selected failed\n");
            exit(EXIT_FAILURE);
        }
    } else
        display_message_dialog("Improper selection", GTK_MESSAGE_WARNING, COMMODITY_REGISTER_CORE.window);
}
예제 #4
0
void launch_readme_html(GtkWidget *widget, gpointer user_data) {

  /** Launch the README file to display it to the user through the GUI. **/

  GError *error = NULL ;

  char *readme_realpath = realpath(PATH_TO_README, NULL) ;

  gchar *readme_uri = g_filename_to_uri(readme_realpath, NULL, NULL);

  gtk_show_uri(NULL, readme_uri, GDK_CURRENT_TIME, &error);

  g_free(readme_uri) ;
  free(readme_realpath) ;

  #ifdef DEBUG
  // This call make crash the application, i don't know why. Not really needed, so we process only if DEBUG define.
  if (error != NULL) {

    string msg =  "Cannot display README:\n\n" ;

    msg += error->message ;

    display_message_dialog("Error README displaying !", msg.c_str() ) ;

  }
  #endif


  return ;

}
예제 #5
0
static gchar *get_selected_quote_guid(struct commodity_register *commodity_register) {
    if (gtk_tree_selection_count_selected_rows(COMMODITY_REGISTER_CORE.selection)  == 1) {
        GtkTreeIter iter;
        GtkTreeModel *model = gtk_tree_view_get_model(COMMODITY_REGISTER_CORE.view);

        if (! gtk_tree_selection_get_selected(COMMODITY_REGISTER_CORE.selection, &model, &iter)) {
            fprintf(stderr, "get_selected_quote_guid: gtk_tree_selection_get_selected failed\n");
            exit(EXIT_FAILURE);
        }
        return (get_string_column_via_iter(model, &iter,
                                           STORE_GUID));
    } else {
        display_message_dialog("Improper selection", GTK_MESSAGE_WARNING, COMMODITY_REGISTER_CORE.window);
        return NULL;
    }
}
예제 #6
0
void configure_program_dialog(GtkWidget *widget, gpointer user_data) {

  /** Program configuration dailog window. **/

  #ifdef DEBUG
  DEBUG_FUNC_MARK
  #endif

  GtkWidget *configure_dialog = gtk_dialog_new() ;



  gtk_window_set_icon_from_file(GTK_WINDOW(configure_dialog), PATH_TO_PRG_WIN_ICON, NULL) ;
  gtk_window_set_title(GTK_WINDOW(configure_dialog), "Configure program") ;
  gtk_window_set_position(GTK_WINDOW(configure_dialog), GTK_WIN_POS_CENTER_ALWAYS) ;
  gtk_window_set_resizable(GTK_WINDOW(configure_dialog), FALSE);
  gtk_widget_set_size_request(configure_dialog,-1,-1) ;
  gtk_window_set_modal(GTK_WINDOW(configure_dialog), FALSE) ;
  gtk_window_set_destroy_with_parent(GTK_WINDOW(configure_dialog), TRUE) ;
  gtk_window_set_decorated(GTK_WINDOW(configure_dialog), TRUE) ;

  gtk_window_set_type_hint(GTK_WINDOW(configure_dialog), GDK_WINDOW_TYPE_HINT_NORMAL) ;
  gtk_window_set_transient_for(GTK_WINDOW(configure_dialog), GTK_WINDOW(gui->window)) ;

  gtk_container_set_border_width(GTK_CONTAINER(configure_dialog), 12) ;


  #define DIALOG_DEFAULT_SPACE 12


  /** ***** [START] Icon set choice [START] ***** **/

  GtkWidget *icon_set_choice_frame = gtk_frame_new(" Icon set ") ;


  GtkWidget *icon_set_choice_hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0) ;

  gtk_container_set_border_width(GTK_CONTAINER(icon_set_choice_hbox), DIALOG_DEFAULT_SPACE) ;

  gtk_box_set_spacing(GTK_BOX(icon_set_choice_hbox), DIALOG_DEFAULT_SPACE) ;

  gtk_box_set_homogeneous(GTK_BOX(icon_set_choice_hbox), TRUE) ;


  GtkWidget *radiobutton_icons_high_contrast = gtk_radio_button_new_with_label(NULL, " HighContrast") ;

  GtkWidget *image_icons_high_contrast       ;

  GtkWidget *radiobutton_icons_oxygen        = gtk_radio_button_new_with_label(gtk_radio_button_get_group(GTK_RADIO_BUTTON(radiobutton_icons_high_contrast)), " Oxygen") ;

  GtkWidget *image_icons_oxygen              ;


  gtk_widget_set_tooltip_markup(radiobutton_icons_high_contrast, "Set the <b>HighContrast</b> theme icon set.\nThis will update the interface.\nBut you must press the <b>Apply</b> button to store your configuration.") ;
  gtk_widget_set_tooltip_markup(radiobutton_icons_oxygen,        "Set the <b>Oxygen</b> theme icon set.\nThis will update the interface.\nBut you must press the <b>Apply</b> button to store your configuration.") ;

  gtk_toggle_button_set_mode(GTK_TOGGLE_BUTTON(radiobutton_icons_high_contrast), FALSE) ;
  gtk_toggle_button_set_mode(GTK_TOGGLE_BUTTON(radiobutton_icons_oxygen),        FALSE) ;


  if (settings.icon_set_oxygen) {

    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(radiobutton_icons_oxygen), TRUE) ;

    image_icons_high_contrast = gtk_image_new_from_file( PATH_TO_HIGH_CONTRAST_BUTTON_ICONS  "face-angry.png")     ;

    image_icons_oxygen        = gtk_image_new_from_file( PATH_TO_OXYGEN_BUTTON_ICONS         "face-smile-big.png") ;

  }
  else {

    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(radiobutton_icons_high_contrast), TRUE) ;

    image_icons_high_contrast = gtk_image_new_from_file( PATH_TO_HIGH_CONTRAST_BUTTON_ICONS  "face-smile-big.png") ;

    image_icons_oxygen        = gtk_image_new_from_file( PATH_TO_OXYGEN_BUTTON_ICONS         "face-angry.png")     ;

  }


  gtk_button_set_image(GTK_BUTTON(radiobutton_icons_high_contrast), image_icons_high_contrast) ;

  gtk_button_set_always_show_image(GTK_BUTTON(radiobutton_icons_high_contrast), TRUE) ;

  gtk_button_set_image(GTK_BUTTON(radiobutton_icons_oxygen), image_icons_oxygen) ;

  gtk_button_set_always_show_image(GTK_BUTTON(radiobutton_icons_oxygen), TRUE)   ;





  gtk_box_pack_start(GTK_BOX(icon_set_choice_hbox), radiobutton_icons_high_contrast, TRUE,  TRUE, 0) ;
  gtk_box_pack_start(GTK_BOX(icon_set_choice_hbox), radiobutton_icons_oxygen,        TRUE,  TRUE, 0) ;

  gtk_container_add(GTK_CONTAINER(icon_set_choice_frame), icon_set_choice_hbox) ;

  /** ***** [END] Icon set choice [END] ***** **/



  /** ***** [START] Playing settings [START] ***** **/

  GtkWidget *playing_settings_frame = gtk_frame_new(" Player settings ") ;


  GtkWidget *playing_settings_vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0) ;

  gtk_container_set_border_width(GTK_CONTAINER(playing_settings_vbox), DIALOG_DEFAULT_SPACE) ;



  GtkWidget *playing_settings_repeat_all = gtk_check_button_new_with_label(" Repeat all mode. ") ;

  gtk_widget_set_tooltip_markup(playing_settings_repeat_all, "Enable the <b>repeat all</b> feature.\nThis will update the player settings.\nBut you must press the <b>Apply</b> button to store your configuration.") ;

  gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(playing_settings_repeat_all), is_repeat_all) ;



  GtkWidget *playing_settings_shuffle = gtk_check_button_new_with_label(" Shuffle mode. ") ;

  gtk_widget_set_tooltip_markup(playing_settings_shuffle, "Enable the <b>shuffle</b> feature.\nThis will update the player settings.\nBut you must press the <b>Apply</b> button to store your configuration.") ;

  gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(playing_settings_shuffle), is_shuffle ) ;

  GtkWidget *playing_settings_volume_hbox  = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0) ;



  GtkWidget *playing_settings_volume_label_hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0) ;

  GtkWidget *playing_settings_volume_image      = gtk_image_new_from_file( (settings.path_to_button_icons + "audio-volume-medium.png").c_str() ) ;

  GtkWidget *playing_settings_volume_label      = gtk_label_new(" Default Volume:") ;

  gtk_box_pack_start(GTK_BOX(playing_settings_volume_label_hbox), playing_settings_volume_image, FALSE, FALSE, 0) ;
  gtk_box_pack_start(GTK_BOX(playing_settings_volume_label_hbox), playing_settings_volume_label, FALSE, FALSE, 0) ;


  GtkWidget *playing_settings_volume_scale = gtk_scale_new_with_range(GTK_ORIENTATION_HORIZONTAL, 0.0, 100.0, 1.0) ;



  gtk_widget_set_tooltip_markup(playing_settings_volume_scale, "Set the <b>default player volume</b> at start.\nThis will <b>not</b> update the player settings.\nYou must press the <b>Apply</b> button to store your configuration.") ;

  gtk_range_set_value(GTK_RANGE(playing_settings_volume_scale), settings.volume) ;

  gtk_scale_set_draw_value(GTK_SCALE(playing_settings_volume_scale), TRUE) ;
  gtk_scale_set_has_origin(GTK_SCALE(playing_settings_volume_scale), TRUE) ;

  gtk_scale_set_value_pos(GTK_SCALE(playing_settings_volume_scale), GTK_POS_TOP) ;

  gtk_scale_add_mark(GTK_SCALE(playing_settings_volume_scale), 50.0, GTK_POS_TOP, NULL) ;



  gtk_box_pack_start(GTK_BOX(playing_settings_volume_hbox), playing_settings_volume_label_hbox, FALSE,  FALSE, 0) ;
  gtk_box_pack_start(GTK_BOX(playing_settings_volume_hbox), playing_settings_volume_scale,      TRUE,   TRUE,  0) ;



  gtk_box_pack_start(GTK_BOX(playing_settings_vbox), playing_settings_repeat_all,               FALSE, FALSE, 0)   ;
  gtk_box_pack_start(GTK_BOX(playing_settings_vbox), playing_settings_shuffle,                  FALSE, FALSE, 0)   ;
  gtk_box_pack_start(GTK_BOX(playing_settings_vbox), playing_settings_volume_hbox,              FALSE, FALSE, 0)   ;

  gtk_container_add(GTK_CONTAINER(playing_settings_frame), playing_settings_vbox) ;

  /** ***** [END] Playing settings [END] ***** **/



  /** ***** [START] Interface size setting [START] ***** **/

  GtkWidget *interface_size_frame = gtk_frame_new(" Interface size ") ;

  GtkWidget *interface_size_hbox  = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0) ;

  gtk_container_set_border_width(GTK_CONTAINER(interface_size_hbox), DIALOG_DEFAULT_SPACE) ;

  GtkWidget *interface_size_radiobutton_little = gtk_radio_button_new_with_label(NULL, " Little") ;
  GtkWidget *interface_size_radiobutton_middle = gtk_radio_button_new_with_label(gtk_radio_button_get_group(GTK_RADIO_BUTTON(interface_size_radiobutton_little)), " Medium") ;
  GtkWidget *interface_size_radiobutton_big    = gtk_radio_button_new_with_label(gtk_radio_button_get_group(GTK_RADIO_BUTTON(interface_size_radiobutton_little)), "  Big  ") ;

  GtkWidget *interface_size_little_image       = gtk_image_new_from_file((settings.path_to_button_icons + "interface-little.png").c_str() ) ;
  GtkWidget *interface_size_middle_image       = gtk_image_new_from_file((settings.path_to_button_icons + "interface-middle.png").c_str() ) ;
  GtkWidget *interface_size_big_image          = gtk_image_new_from_file((settings.path_to_button_icons + "interface-big.png").c_str()    ) ;

  gtk_widget_set_tooltip_markup(interface_size_radiobutton_little, "Set the <b>interface size</b> on <b>little</b>.\nThis will update the interface.\nBut you must press the <b>Apply</b> button to store your configuration.") ;
  gtk_widget_set_tooltip_markup(interface_size_radiobutton_middle, "Set the <b>interface size</b> on <b>middle</b>.\nThis will update the interface.\nBut you must press the <b>Apply</b> button to store your configuration.") ;
  gtk_widget_set_tooltip_markup(interface_size_radiobutton_big,    "Set the <b>interface size</b> on <b>big</b>.\nThis will update the interface.\nBut you must press the <b>Apply</b> button to store your configuration.")    ;

  gtk_button_set_image(GTK_BUTTON(interface_size_radiobutton_little), interface_size_little_image) ;
  gtk_button_set_image(GTK_BUTTON(interface_size_radiobutton_middle), interface_size_middle_image) ;
  gtk_button_set_image(GTK_BUTTON(interface_size_radiobutton_big),    interface_size_big_image   ) ;

  gtk_button_set_always_show_image(GTK_BUTTON(interface_size_radiobutton_little), TRUE) ;
  gtk_button_set_always_show_image(GTK_BUTTON(interface_size_radiobutton_middle), TRUE) ;
  gtk_button_set_always_show_image(GTK_BUTTON(interface_size_radiobutton_big),    TRUE) ;

  gtk_toggle_button_set_mode(GTK_TOGGLE_BUTTON(interface_size_radiobutton_little), FALSE) ;
  gtk_toggle_button_set_mode(GTK_TOGGLE_BUTTON(interface_size_radiobutton_middle), FALSE) ;
  gtk_toggle_button_set_mode(GTK_TOGGLE_BUTTON(interface_size_radiobutton_big),    FALSE) ;


  switch (settings.image_resized_size) {

    case IMAGE_RESIZED_SIZE_LITTLE :

      gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(interface_size_radiobutton_little), TRUE) ;
      break ;

    case IMAGE_RESIZED_SIZE_MIDDLE :

      gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(interface_size_radiobutton_middle), TRUE) ;
      break ;

    case IMAGE_RESIZED_SIZE_BIG :

      gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(interface_size_radiobutton_big),    TRUE) ;
      break ;

    default :
      break ;
  }


  gtk_box_pack_start(GTK_BOX(interface_size_hbox), interface_size_radiobutton_little, TRUE, TRUE, 0) ;
  gtk_box_pack_start(GTK_BOX(interface_size_hbox), interface_size_radiobutton_middle, TRUE, TRUE, 0) ;
  gtk_box_pack_start(GTK_BOX(interface_size_hbox), interface_size_radiobutton_big,    TRUE, TRUE, 0) ;

  gtk_box_set_homogeneous(GTK_BOX(interface_size_hbox), TRUE) ;

  gtk_box_set_spacing(GTK_BOX(interface_size_hbox), DIALOG_DEFAULT_SPACE) ;

  gtk_container_add(GTK_CONTAINER(interface_size_frame), interface_size_hbox) ;

  /** ***** [END] Interface size setting [END] ***** **/



  /** ***** [START] Music folder setting [START] ***** **/

  GtkWidget *folder_selecting_frame = gtk_frame_new(" Music folder ") ;

  GtkWidget *folder_selecting_box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0) ;

  gtk_container_set_border_width(GTK_CONTAINER(folder_selecting_box), DIALOG_DEFAULT_SPACE) ;


  GtkWidget *folder_selecting_button = gtk_file_chooser_button_new("Set the Music folder to open per default.", GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER) ;

  gtk_widget_set_tooltip_markup(folder_selecting_button, "Set the folder to open per default: your <b>default music folder</b>.\n<i>The default folder from the folder selector</i>.\nSet it simply to your <b>Music folder</b>.\nChanges are immediatly applied.\nBut you must press the <b>Apply</b> button to store your configuration.") ;

  gtk_file_chooser_button_set_title(GTK_FILE_CHOOSER_BUTTON(folder_selecting_button), "Set the Music folder to open per default.") ;

  const char *user_music_folder = g_get_user_special_dir(G_USER_DIRECTORY_MUSIC) ;

  gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(folder_selecting_button), (g_file_test(settings.path_to_music_folder.c_str(), G_FILE_TEST_IS_DIR)) ? settings.path_to_music_folder.c_str() : (user_music_folder != NULL) ? user_music_folder : g_get_home_dir()  ) ;


  gtk_box_pack_start(GTK_BOX(folder_selecting_box), folder_selecting_button,  TRUE, TRUE, 0)   ;

  gtk_container_add(GTK_CONTAINER(folder_selecting_frame), folder_selecting_box) ;

  /** ***** [END] Music folder setting [END] ***** **/



  /** ***** [START] Dialog main content box [START] ***** **/

  GtkWidget *content_area = gtk_dialog_get_content_area( GTK_DIALOG(configure_dialog) ) ;

  gtk_box_pack_start(GTK_BOX(content_area), icon_set_choice_frame,  FALSE, FALSE, 0) ;
  gtk_box_pack_start(GTK_BOX(content_area), playing_settings_frame, FALSE, FALSE, 0) ;
  gtk_box_pack_start(GTK_BOX(content_area), interface_size_frame,   FALSE, FALSE, 0) ;
  gtk_box_pack_start(GTK_BOX(content_area), folder_selecting_frame, FALSE, FALSE, 0) ;

  gtk_box_set_spacing(GTK_BOX(content_area), DIALOG_DEFAULT_SPACE) ;

  /** ***** [END] Dialog main content box [END] ***** **/



  /** ***** [START] Dialog action buttons [START] ***** **/

  GtkWidget *button_close = gtk_button_new_with_label("Close") ; // gtk_dialog_add_button(GTK_DIALOG(configure_dialog), "Cancel", GTK_RESPONSE_CANCEL) ;

  GtkWidget *image_close  = gtk_image_new_from_file((settings.path_to_button_icons + "dialog-close.png").c_str()) ;

  gtk_widget_set_tooltip_markup(button_close, "<b>Close</b> the configuration window and don't store any setting.") ;

  gtk_button_set_image(GTK_BUTTON(button_close), image_close) ;

  gtk_button_set_always_show_image(GTK_BUTTON(button_close), TRUE) ;


  GtkWidget *button_ok = gtk_button_new_with_label("Apply") ; // gtk_dialog_add_button(GTK_DIALOG(configure_dialog), "Apply", GTK_RESPONSE_APPLY) ;

  GtkWidget *image_ok  = gtk_image_new_from_file((settings.path_to_button_icons + "dialog-ok.png").c_str()) ;

  gtk_widget_set_tooltip_markup(button_ok, "<b>Register</b> all the settings as <i>your default configuration</i> at start.") ;

  gtk_button_set_image(GTK_BUTTON(button_ok), image_ok) ;

  gtk_button_set_always_show_image(GTK_BUTTON(button_ok), TRUE) ;


  gtk_dialog_add_action_widget(GTK_DIALOG(configure_dialog), button_close, GTK_RESPONSE_CLOSE) ;

  gtk_dialog_add_action_widget(GTK_DIALOG(configure_dialog), button_ok,     GTK_RESPONSE_APPLY)  ;

  GtkWidget *action_area = gtk_dialog_get_action_area(GTK_DIALOG(configure_dialog)) ;

  gtk_container_set_border_width(GTK_CONTAINER(action_area), 0) ;

  gtk_button_box_set_layout(GTK_BUTTON_BOX(action_area), GTK_BUTTONBOX_EDGE) ;

  /** ***** [END] Dialog action buttons [END] ***** **/



  Radio_Config high_contrast_radiobutton ;

  high_contrast_radiobutton.button  = radiobutton_icons_high_contrast ;
  high_contrast_radiobutton.image   = image_icons_high_contrast       ;

  high_contrast_radiobutton.volume  = playing_settings_volume_image       ;
  high_contrast_radiobutton.cancel  = image_close    ;
  high_contrast_radiobutton.apply   = image_ok       ;

  high_contrast_radiobutton.little  = interface_size_little_image ;
  high_contrast_radiobutton.middle  = interface_size_middle_image ;
  high_contrast_radiobutton.big     = interface_size_big_image    ;


  Radio_Config oxygen_radiobutton ;

  oxygen_radiobutton.button  = radiobutton_icons_oxygen ;
  oxygen_radiobutton.image   = image_icons_oxygen       ;

  oxygen_radiobutton.volume  = playing_settings_volume_image       ;
  oxygen_radiobutton.cancel  = image_close    ;
  oxygen_radiobutton.apply   = image_ok       ;

  oxygen_radiobutton.little  = interface_size_little_image ;
  oxygen_radiobutton.middle  = interface_size_middle_image ;
  oxygen_radiobutton.big     = interface_size_big_image    ;

  g_signal_connect(G_OBJECT(radiobutton_icons_high_contrast), "clicked", G_CALLBACK(configure_high_contrast_radiobutton), &high_contrast_radiobutton) ;
  g_signal_connect(G_OBJECT(radiobutton_icons_oxygen),        "clicked", G_CALLBACK(configure_oxygen_radiobutton),        &oxygen_radiobutton       ) ;


  int little = -1 ;
  int middle =  0 ;
  int big    =  1 ;

  g_signal_connect(G_OBJECT(interface_size_radiobutton_little), "clicked",       G_CALLBACK(reconfigure_interface_size), &little) ;
  g_signal_connect(G_OBJECT(interface_size_radiobutton_middle), "clicked",       G_CALLBACK(reconfigure_interface_size), &middle) ;
  g_signal_connect(G_OBJECT(interface_size_radiobutton_big),    "clicked",       G_CALLBACK(reconfigure_interface_size), &big)    ;


  g_signal_connect(G_OBJECT(playing_settings_repeat_all),       "toggled",       G_CALLBACK(repeat_all_feature_set),     NULL)    ;
  g_signal_connect(G_OBJECT(playing_settings_shuffle),          "toggled",       G_CALLBACK(shuffle_feature_set),        NULL)    ;
  g_signal_connect(G_OBJECT(playing_settings_volume_scale),     "value-changed", G_CALLBACK(get_volume),                 NULL)    ;
  g_signal_connect(G_OBJECT(folder_selecting_button),           "file-set",      G_CALLBACK(set_default_folder),         NULL)    ;


  gtk_widget_show_all(configure_dialog) ;



  int response = gtk_dialog_run(GTK_DIALOG(configure_dialog))  ;

  switch (response) {

    case GTK_RESPONSE_APPLY :

      {

        GKeyFile *conf_file = g_key_file_new() ;

        GError *error = NULL ;

        settings.is_repeat_all = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(playing_settings_repeat_all)) ;

        settings.is_shuffle       = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(playing_settings_shuffle))    ;



        // Set configuration settings to configuration file buffer.
        g_key_file_set_string(conf_file,   "Config",  "Buttons_Icons_Path",   settings.path_to_button_icons.c_str()) ;

        g_key_file_set_string(conf_file,   "Config",  "Menu_Icons_Path",      settings.path_to_menu_icons.c_str())   ;

        g_key_file_set_string(conf_file,   "Config",  "Music_Folder",         settings.path_to_music_folder.c_str())   ;

        g_key_file_set_boolean(conf_file,  "Config",  "Is_Oxygen",            settings.icon_set_oxygen) ;
        g_key_file_set_boolean(conf_file,  "Config",  "Repeat_all",           settings.is_repeat_all)  ;
        g_key_file_set_boolean(conf_file,  "Config",  "Shuffle",              settings.is_shuffle) ;

        g_key_file_set_double(conf_file,   "Config",  "Volume",               settings.volume) ;

        g_key_file_set_uint64(conf_file,   "Config",  "Buttons_space",        settings.space_buttons) ;

        g_key_file_set_uint64(conf_file,   "Config",  "Display_Size",         settings.display_size) ;

        g_key_file_set_uint64(conf_file,   "Config",  "Image_Resizing",       settings.image_resized_size) ;

        g_key_file_set_string(conf_file,   "Config",  "Sized_Default_Image",  settings.path_to_default_image.c_str())   ;

        // Write to configuration file
        g_key_file_save_to_file(conf_file, PATH_TO_CONF_FILE, &error);

        // Setting global variables.
        cover_image    = settings.path_to_default_image ;
        current_folder = settings.path_to_music_folder ;

        if ( error != NULL ) {

          display_message_dialog("Error store configuration !", "Cannot store the configuration.") ;

          #ifdef DEBUG
          fprintf(stdout,"\n%s: Error store configuratiom settings.\n", prgname.c_str() )    ; fflush(stdout) ;
          #endif
        }
        else { // Success
          #ifdef DEBUG
          fprintf(stdout,"\n%s: Success store configuratiom settings.\n", prgname.c_str() )  ;
          #endif
        }

      }

      break ;

    case GTK_RESPONSE_CLOSE :
      // Do nothing.
      break ;
  }

  gtk_widget_destroy(configure_dialog) ;

  return ;

}
예제 #7
0
void save_all_file(GtkWidget *button, gpointer user_data) {
  /** All files saving callback. **/

  #ifdef DEBUG
    DEBUG_FUNC_MARK
  #endif

  gint number_of_pages = gtk_notebook_get_n_pages(GTK_NOTEBOOK(gui->editor_notebook)) ;

  int c ;
  for (c=0 ; c < number_of_pages ; c++) {
    /** We iterate over every notebook page. **/

    GtkWidget *notebook_page = gtk_notebook_get_nth_page(GTK_NOTEBOOK(gui->editor_notebook), c) ;
    GtkWidget *notebook_tab  = gtk_notebook_get_tab_label(GTK_NOTEBOOK(gui->editor_notebook), notebook_page);

    /** The tab contains an mimetype icon, the filename and the page closing button. **/
    GList *tab_compound_list = gtk_container_get_children(GTK_CONTAINER(notebook_tab)) ;

    tab_compound_list = g_list_first(tab_compound_list) ;

    while (tab_compound_list->data != NULL) {

      if  (g_object_get_data(G_OBJECT(tab_compound_list->data), "tab_filename_widget")) {
        /** We get the filename tab label. **/

        const char *tab_label = gtk_label_get_text(GTK_LABEL(tab_compound_list->data)) ;

        if (tab_label[0] == '*' && g_strcmp0(tab_label,"*New") != 0) {
          /** Check if the file is modified (marked with an'*') and is not the default "New" named file. **/

          GtkWidget     *current_textview        = gtk_bin_get_child(GTK_BIN(notebook_page)) ;
          GtkTextBuffer *current_buffer          = gtk_text_view_get_buffer(GTK_TEXT_VIEW(current_textview)) ;

          gpointer filepath = g_object_get_data(G_OBJECT(current_buffer), "filepath") ;

          if (filepath != NULL) {

            /** Getting current editor content **/
            GtkTextIter iter_start, iter_end ;
            GError *error=NULL               ;

            gtk_text_buffer_get_start_iter(current_buffer, &iter_start);
            gtk_text_buffer_get_end_iter(current_buffer,   &iter_end);

            gchar *file_content = gtk_text_buffer_get_text(current_buffer, &iter_start, &iter_end, FALSE);

            char *back_up_filepath = NULL ;

            if (settings.backup_file) {
              /** backup creation by renaming the ancient (last saved) file (content) by adding an '~' the backup files suffix. **/

              back_up_filepath = g_strdup_printf("%s~", (char *) filepath) ;
              rename(filepath,back_up_filepath) ;

            }

            if ( ! g_file_set_contents(filepath, file_content, -1, &error) ) {
                /** The content saving has failed **/
                rename(back_up_filepath, filepath) ; /** We must reset the renaming because else we lost the correct filename in this error case. **/
  
                char *msg = g_strdup_printf( _("Failed to save file:\n%s"), (gchar *) filepath) ;
  
                display_message_dialog( _("Cannot save file !!!"), msg, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE) ;
  
                free(msg) ;
  
            }

            g_free(file_content)   ;
            g_free(back_up_filepath) ;

            /** setting the base filename in the bottom bar. **/
            gtk_label_set_text(GTK_LABEL(tab_compound_list->data), g_path_get_basename(filepath)) ;

            /** We mark the TextBuffer as not modified since last saving operation. **/
            gtk_text_buffer_set_modified(current_buffer, FALSE) ;

            if (settings.rm_trailing_spaces) {
              /** Deleting trailing spaces. **/

              char *trailing_spaces_deleting ;
              trailing_spaces_deleting = g_strdup_printf("sed -i 's/[[:space:]]$//' '%s'", (char *) filepath) ;
              int ret ;
              if ((ret = system(trailing_spaces_deleting)) == -1) {
                g_warning(_("Removing trailing space failure:\n%s\n"), trailing_spaces_deleting) ;
              }
              free(trailing_spaces_deleting) ;
            }

            #ifdef RELOADING_FUNC
            /** Update Last modification timestamp. **/
            File_Editor *file_editor = (File_Editor *) g_object_get_data(G_OBJECT(current_textview), "file_editor") ;
            g_stat(filepath, &file_editor->file_info) ;
            #endif

          }
        }
        break ;
      }

      tab_compound_list = tab_compound_list->next ;
    }


  }

  return ;
}
예제 #8
0
void save_file(GtkButton *button) {
  /** Save editor content as the stored filename. **/

  #ifdef DEBUG
    DEBUG_FUNC_MARK
  #endif


  /** Retrieve the stored filepath: **/
  gpointer filepath = g_object_get_data(G_OBJECT(current_editor.current_buffer), "filepath") ;

  char *cmp_filepath = g_strdup_printf("%s/New", (char *) g_get_home_dir()) ;
  if ( g_strcmp0(filepath,cmp_filepath) == 0) {
    /** File is the start file **/

    free(cmp_filepath) ;
    save_as_file(NULL) ;
    return ;
  }

  free(cmp_filepath) ;


  /** Getting current editor content **/
  GtkTextIter iter_start, iter_end ;
  GError *error=NULL               ;

  gtk_text_buffer_get_start_iter(current_editor.current_buffer,&iter_start);
  gtk_text_buffer_get_end_iter(current_editor.current_buffer,&iter_end);

  gchar *file_content = gtk_text_buffer_get_text(current_editor.current_buffer, &iter_start, &iter_end, FALSE);


  char *back_up_filepath = NULL ;

  if (settings.backup_file) {
    /** backup creation by renaming the ancient (last saved) file (content) by adding an '~' the backup files suffix. **/

    back_up_filepath = g_strdup_printf("%s~",(char *) filepath) ;
    rename(filepath,back_up_filepath) ;

  }

  if ( ! g_file_set_contents(filepath, file_content, -1, &error) ) {
    /** Failed to save editor content as file, display an error message and return. **/


    rename(back_up_filepath, filepath) ; /** We must reset the renaming because else we lost the correct filename in this error case. **/
    free(back_up_filepath) ;

    char *msg = g_strdup_printf(_("Failed to save file:\n%s"), (char *) filepath) ;

    display_message_dialog(_("Cannot save file !!!"), msg, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE) ;

    free(msg) ;

    return ;
  }

  free(back_up_filepath) ;


  /** Update the notebook label tab **/
  GtkWidget *notebook_tab = gtk_notebook_get_tab_label(GTK_NOTEBOOK(gui->editor_notebook), current_editor.current_notebook_page);

  /** The tab contains an mimetype icon, the filename and the page closing button. **/
  GList *tab_compound_list = gtk_container_get_children(GTK_CONTAINER(notebook_tab)) ;

  tab_compound_list = g_list_first(tab_compound_list) ;

  while (tab_compound_list->data != NULL) {
      /** We iterate over the notebook tab component to find the filename label.**/

      if  (g_object_get_data(G_OBJECT(tab_compound_list->data), "tab_filename_widget")) {
        /** We reset the filename without the asterix ('*'). **/
        gtk_label_set_text(GTK_LABEL(tab_compound_list->data), g_path_get_basename(filepath)) ;
        break ;
      }

      tab_compound_list = tab_compound_list->next ;
  }


  /** We mark the TextBuffer as not modified since last saving operation. **/
  gtk_text_buffer_set_modified(current_editor.current_buffer, FALSE) ;


  /** setting the base filename in the bottom bar. **/
  gtk_label_set_text(GTK_LABEL(gui->bottom_bar->filename_label), g_path_get_basename(filepath)) ;
 
  File_Editor *file_editor = (File_Editor *) g_object_get_data(G_OBJECT(current_editor.current_textview), "file_editor") ;
 
  gtk_notebook_set_menu_label_text(GTK_NOTEBOOK(gui->editor_notebook), file_editor->scrolled_window, g_path_get_basename(filepath) ) ;
 
  g_free(file_content) ;


  if (settings.rm_trailing_spaces) {
    /** Deleting trailing spaces. **/
    char *trailing_spaces_deleting ;
    trailing_spaces_deleting = g_strdup_printf("sed -i 's/[[:space:]]$//' '%s'", (char *) filepath) ;
    int ret ;
    if ((ret = system(trailing_spaces_deleting)) == -1) {
      g_warning( _("Removing trailing space failure:\n%s\n"), trailing_spaces_deleting) ;
    }
    free(trailing_spaces_deleting) ;
  }

  #ifdef RELOADING_FUNC
  /** Update Last modification timestamp. **/
  File_Editor *file_editor = (File_Editor *) g_object_get_data(G_OBJECT(current_editor.current_textview), "file_editor") ;
  g_stat(filepath, &file_editor->file_info) ;
  #endif

  return ;

}
예제 #9
0
void save_as_file(GtkButton *button) {
  /** Save the current editor content as the choosen file. **/

  #ifdef DEBUG
    DEBUG_FUNC_MARK
  #endif





  GtkWidget *file_chooser = gtk_file_chooser_dialog_new( _("Save as file"),
                                                        GTK_WINDOW(gui->main_window),
                                                        GTK_FILE_CHOOSER_ACTION_SAVE,
                                                        _("Cancel"),  GTK_RESPONSE_CANCEL,
                                                        _("Save as"), GTK_RESPONSE_ACCEPT,
                                                        NULL) ;


  /** Retrieve the stored filepath: **/
  gpointer stored_filepath = g_object_get_data(G_OBJECT(current_editor.current_buffer), "filepath") ;

  /** Storing last opened file folder. **/
  if (open_file_dirname != NULL) {
    g_free(open_file_dirname) ;
  }
  open_file_dirname = g_strdup(g_path_get_dirname(stored_filepath)) ;

  gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(file_chooser), open_file_dirname );

  gint res;

  GtkFileChooser *chooser;
  chooser = GTK_FILE_CHOOSER(file_chooser);


  gtk_file_chooser_set_do_overwrite_confirmation(chooser, TRUE);

  res = gtk_dialog_run(GTK_DIALOG(file_chooser)) ;

  if (res == GTK_RESPONSE_ACCEPT) {

    char *filepath ;
    filepath = gtk_file_chooser_get_filename(chooser);

    /** Getting current editor content **/
    GtkTextIter iter_start, iter_end  ;
    GError *error = NULL              ;

    gtk_text_buffer_get_start_iter(current_editor.current_buffer, &iter_start);
    gtk_text_buffer_get_end_iter(current_editor.current_buffer,   &iter_end);

    gchar *file_content = gtk_text_buffer_get_text(current_editor.current_buffer, &iter_start, &iter_end, FALSE) ;


    if (! g_file_set_contents(filepath, file_content, -1, &error) ) {
      /** Failed to save editor content as file, display an error message and return. **/

      char *msg = g_strdup_printf(_("Failed to save file:\n%s"), filepath) ;

      display_message_dialog(_("Cannot save file !!!"), msg, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE) ;

      free(msg) ;

      return ;

    }

    /** Mark the TextBuffer as not modfied. **/
    gtk_text_buffer_set_modified(current_editor.current_buffer, FALSE) ;

    /** Only useful if the content type has changed like a new file saved as a *.c file. **/
    GtkSourceLanguage        *source_language         = NULL ;
    GtkSourceLanguageManager *source_language_manager = gtk_source_language_manager_get_default();

    gboolean result_uncertain ;
    gchar *content_type ;

    content_type = g_content_type_guess( g_path_get_basename(filepath), (const guchar *) file_content, strlen(file_content), &result_uncertain) ;

    if (content_type && source_language_manager) {

      source_language = gtk_source_language_manager_guess_language(source_language_manager, g_path_get_basename(filepath), content_type);

      if (source_language) {

        set_syntax_highlight_radio(gtk_source_language_get_id(source_language)) ;

        gtk_source_buffer_set_language(GTK_SOURCE_BUFFER(current_editor.current_buffer), source_language) ;

        g_object_set_data(G_OBJECT(current_editor.current_textview), "lang_id", (char *) gtk_source_language_get_id(source_language)) ;
      }

      g_free(content_type) ;
    }



    /** Update the notebook label tab **/
    GtkWidget *notebook_tab = gtk_notebook_get_tab_label(GTK_NOTEBOOK(gui->editor_notebook), current_editor.current_notebook_page);

    /** The tab contains an mimetype icon, the filename and the page closing button. **/
    GList *tab_compound_list = gtk_container_get_children(GTK_CONTAINER(notebook_tab)) ;

    tab_compound_list = g_list_first(tab_compound_list) ;

    while (tab_compound_list->data != NULL) {
        /** We iterate over the notebook tab component **/
        if  (g_object_get_data(G_OBJECT(tab_compound_list->data), "tab_filename_widget")) {
          /** Set the new filename in the tab. **/
          gtk_label_set_text(GTK_LABEL(tab_compound_list->data), g_path_get_basename(filepath)) ;
        }

        if  (g_object_get_data(G_OBJECT(tab_compound_list->data), "tab_icon") && source_language) {


          uint8_t c ;
          for ( c=0 ; ; c++) {
    
              if (gtk_source_language_get_mime_types(source_language) == NULL) {
     
                break ;
              }
    
              char *mimetype = gtk_source_language_get_mime_types(source_language)[c] ;

              if (mimetype == NULL) {
                  /** don't find an specific mimetype for this new file extension use default icon. **/
                  g_object_set(G_OBJECT(tab_compound_list->data),"file", PATH_TO_MIMETYPE_ICON "unknown.png", NULL) ;
                  break ;
              }

              /** We search for an image filename ending with the corresponding mimetype: **/
              char *ptr = strchr(mimetype, '/') ;

              if (ptr != NULL) {

                /** Simply pointer arithmetic to exchange the '/' (used in mimetypes) and the '-' (used in the images names) character **/
                mimetype[ptr - mimetype] = '-' ;


                gchar *filepath = g_strdup_printf("%s%s.png", PATH_TO_MIMETYPE_ICON, mimetype) ;

                if ( g_file_test(filepath, G_FILE_TEST_EXISTS) ) {
                  /** We found an corresponding image for this mimetype. **/
                  g_object_set(G_OBJECT(tab_compound_list->data),"file", filepath, NULL) ;
                  free(filepath) ;
                  break ;
                }

                free(filepath) ;

              }

          }
        }

        if (tab_compound_list->next == NULL) {
          break ;
        }

        tab_compound_list = tab_compound_list->next ;
    }

    g_free(file_content)   ;

    /** Storing filepath for further saving operations. **/
    g_object_set_data(G_OBJECT(current_editor.current_buffer), "filepath", filepath) ;

    /** setting the base filename in the bottom bar. **/
    gtk_label_set_text(GTK_LABEL(gui->bottom_bar->filename_label), g_path_get_basename(filepath)) ;


    if (settings.rm_trailing_spaces) {
      /** Deleting trailing spaces. **/
      char *trailing_spaces_deleting ;
      trailing_spaces_deleting = g_strdup_printf("sed -i 's/[[:space:]]$//' '%s'", (char *) filepath) ;
      int ret ;
      if ((ret = system(trailing_spaces_deleting)) == -1) {
        g_warning( _("Removing trailing space failure:\n%s\n"), trailing_spaces_deleting) ;
      }

      free(trailing_spaces_deleting) ;
    }
   
    File_Editor *file_editor = (File_Editor *) g_object_get_data(G_OBJECT(current_editor.current_textview), "file_editor") ;
   
    gtk_notebook_set_menu_label_text(GTK_NOTEBOOK(gui->editor_notebook), file_editor->scrolled_window, g_path_get_basename(filepath) ) ;
   
    #ifdef RELOADING_FUNC
    /** Update Last modification timestamp. **/
    File_Editor *file_editor = (File_Editor *) g_object_get_data(G_OBJECT(current_editor.current_textview), "file_editor") ;
    g_stat(filepath, &file_editor->file_info) ;
    #endif
   
   

  }

  /** @NOTE: the filepath must not be free because it is set as data from the file_editor->buffer for further use. **/

  gtk_widget_destroy(file_chooser);
}