void prefs_read_config (GUI *appGUI) { gboolean cfg_file; xmlDocPtr doc; xmlNodePtr node, general_node, calendar_node, tasks_node, contacts_node, notes_node; cfg_file = g_file_test (prefs_get_config_filename (CONFIG_FILENAME, appGUI), G_FILE_TEST_IS_REGULAR); if (cfg_file == TRUE) { doc = xmlParseFile (prefs_get_config_filename (CONFIG_FILENAME, appGUI)); if (doc == NULL) return; node = xmlDocGetRootElement (doc); if (node == NULL) { xmlFreeDoc (doc); return; } if (xmlStrcmp (node->name, (const xmlChar *) CONFIG_NAME)) { xmlFreeDoc (doc); return; } prefs_set_default_values (); node = node->xmlChildrenNode; while (node != NULL) { /*---------------------------------------------------------------------------------------*/ /* general */ if ((!xmlStrcmp (node->name, (const xmlChar *) "general"))) { general_node = node->xmlChildrenNode; while (general_node != NULL) { utl_xml_get_int ("window_x", &config.window_x, general_node); utl_xml_get_int ("window_y", &config.window_y, general_node); utl_xml_get_int ("window_size_x", &config.window_size_x, general_node); utl_xml_get_int ("window_size_y", &config.window_size_y, general_node); utl_xml_get_int ("enable_tooltips", &config.enable_tooltips, general_node); utl_xml_get_int ("latest_tab", &config.latest_tab, general_node); utl_xml_get_int ("tabs_position", &config.tabs_position, general_node); utl_xml_get_int ("remember_latest_tab", &config.remember_latest_tab, general_node); utl_xml_get_int ("save_data_after_modification", &config.save_data_after_modification, general_node); utl_xml_get_int ("default_stock_icons", &config.default_stock_icons, general_node); utl_xml_get_int ("disable_underline_links", &config.disable_underline_links, general_node); utl_xml_get_int ("date_format", &config.date_format, general_node); utl_xml_get_int ("time_format", &config.time_format, general_node); utl_xml_get_int ("enable_systray", &config.enable_systray, general_node); utl_xml_get_int ("start_minimised_in_systray", &config.start_minimised_in_systray, general_node); utl_xml_get_int ("blink_on_events", &config.blink_on_events, general_node); utl_xml_get_int ("ignore_day_note_events", &config.ignore_day_note_events, general_node); utl_xml_get_int ("run_counter", &config.run_counter, general_node); utl_xml_get_int ("lastrun_date", &config.lastrun_date, general_node); utl_xml_get_int ("lastrun_time", &config.lastrun_time, general_node); utl_xml_get_int ("hide_calendar", &config.hide_calendar, general_node); utl_xml_get_int ("hide_tasks", &config.hide_tasks, general_node); utl_xml_get_int ("hide_contacts", &config.hide_contacts, general_node); utl_xml_get_int ("hide_notes", &config.hide_notes, general_node); utl_xml_get_strn ("spell_lang", config.spell_lang, MAXNAME, general_node); utl_xml_get_strn ("web_browser", config.web_browser, MAXHELPERCMD, general_node); utl_xml_get_strn ("email_client", config.email_client, MAXHELPERCMD, general_node); general_node = general_node->next; } } /*---------------------------------------------------------------------------------------*/ /* calendar */ if ((!xmlStrcmp (node->name, (const xmlChar *) "calendar"))) { calendar_node = node->xmlChildrenNode; while (calendar_node != NULL) { utl_xml_get_int ("fy_window_size_x", &config.fy_window_size_x, calendar_node); utl_xml_get_int ("fy_window_size_y", &config.fy_window_size_y, calendar_node); utl_xml_get_int ("fy_simple_view", &config.fy_simple_view, calendar_node); utl_xml_get_int ("fy_alternative_view", &config.fy_alternative_view, calendar_node); utl_xml_get_int ("cb_window_size_x", &config.cb_window_size_x, calendar_node); utl_xml_get_int ("cb_window_size_y", &config.cb_window_size_y, calendar_node); utl_xml_get_int ("ib_window_size_x", &config.ib_window_size_x, calendar_node); utl_xml_get_int ("ib_window_size_y", &config.ib_window_size_y, calendar_node); utl_xml_get_int ("display_options", &config.display_options, calendar_node); utl_xml_get_int ("day_notes_visible", &config.day_notes_visible, calendar_node); utl_xml_get_int ("timeline_start", &config.timeline_start, calendar_node); utl_xml_get_int ("timeline_end", &config.timeline_end, calendar_node); utl_xml_get_int ("timeline_step", &config.timeline_step, calendar_node); utl_xml_get_int ("di_show_current_time", &config.di_show_current_time, calendar_node); utl_xml_get_int ("di_show_day_number", &config.di_show_day_number, calendar_node); utl_xml_get_int ("di_show_current_day_distance", &config.di_show_current_day_distance, calendar_node); utl_xml_get_int ("di_show_marked_days", &config.di_show_marked_days, calendar_node); utl_xml_get_int ("di_show_week_number", &config.di_show_week_number, calendar_node); utl_xml_get_int ("di_show_weekend_days", &config.di_show_weekend_days, calendar_node); utl_xml_get_int ("di_show_day_category", &config.di_show_day_category, calendar_node); utl_xml_get_int ("di_show_moon_phase", &config.di_show_moon_phase, calendar_node); utl_xml_get_int ("di_show_notes", &config.di_show_notes, calendar_node); utl_xml_get_int ("di_show_zodiac_sign", &config.di_show_zodiac_sign, calendar_node); utl_xml_get_int ("cursor_type", &config.cursor_type, calendar_node); utl_xml_get_int ("frame_cursor_thickness", &config.frame_cursor_thickness, calendar_node); utl_xml_get_int ("enable_auxilary_calendars", &config.enable_auxilary_calendars, calendar_node); utl_xml_get_int ("enable_day_mark", &config.enable_day_mark, calendar_node); utl_xml_get_int ("strikethrough_past_notes", &config.strikethrough_past_notes, calendar_node); utl_xml_get_int ("ascending_sorting_in_day_notes_browser", &config.ascending_sorting_in_day_notes_browser, calendar_node); utl_xml_get_int ("auxilary_calendars_state", &config.auxilary_calendars_state, calendar_node); utl_xml_get_int ("day_note_spell_checker", &config.day_note_spell_checker, calendar_node); utl_xml_get_char ("day_note_marker", &config.day_note_marker, calendar_node); utl_xml_get_int ("event_marker_type", &config.event_marker_type, calendar_node); utl_xml_get_int ("today_marker_type", &config.today_marker_type, calendar_node); utl_xml_get_int ("day_notes_browser_filter", &config.day_notes_browser_filter, calendar_node); utl_xml_get_int ("ical_export_pane_pos", &config.ical_export_pane_pos, calendar_node); utl_xml_get_strn ("header_color", config.header_color, MAXCOLORNAME, calendar_node); utl_xml_get_strn ("weekend_color", config.weekend_color, MAXCOLORNAME, calendar_node); utl_xml_get_strn ("selection_color", config.selection_color, MAXCOLORNAME, calendar_node); utl_xml_get_strn ("mark_color", config.mark_color, MAXCOLORNAME, calendar_node); utl_xml_get_strn ("mark_current_day_color", config.mark_current_day_color, MAXCOLORNAME, calendar_node); utl_xml_get_int ("mark_current_day_alpha", &config.mark_current_day_alpha, calendar_node); utl_xml_get_int ("selector_alpha", &config.selector_alpha, calendar_node); utl_xml_get_strn ("day_name_font", config.day_name_font, MAXFONTNAME, calendar_node); utl_xml_get_strn ("calendar_font", config.calendar_font, MAXFONTNAME, calendar_node); utl_xml_get_strn ("notes_font", config.notes_font, MAXFONTNAME, calendar_node); utl_xml_get_strn ("cal_print_month_name_font", config.cal_print_month_name_font, MAXFONTNAME, calendar_node); utl_xml_get_strn ("cal_print_day_name_font", config.cal_print_day_name_font, MAXFONTNAME, calendar_node); utl_xml_get_strn ("cal_print_day_num_font", config.cal_print_day_num_font, MAXFONTNAME, calendar_node); utl_xml_get_strn ("cal_print_event_font", config.cal_print_event_font, MAXFONTNAME, calendar_node); utl_xml_get_int ("cal_print_event_length", &config.cal_print_event_length, calendar_node); utl_xml_get_int ("cal_print_padding", &config.cal_print_padding, calendar_node); utl_xml_get_int ("cal_print_page_orientation", &config.cal_print_page_orientation, calendar_node); utl_xml_get_int ("cal_print_tasks", &config.cal_print_tasks, calendar_node); utl_xml_get_int ("cal_print_birthdays", &config.cal_print_birthdays, calendar_node); utl_xml_get_int ("cal_print_namedays", &config.cal_print_namedays, calendar_node); utl_xml_get_int ("cal_print_day_notes", &config.cal_print_day_notes, calendar_node); utl_xml_get_int ("cal_print_ical", &config.cal_print_ical, calendar_node); calendar_node = calendar_node->next; } } /*---------------------------------------------------------------------------------------*/ /* tasks */ if ((!xmlStrcmp (node->name, (const xmlChar *) "tasks"))) { tasks_node = node->xmlChildrenNode; while (tasks_node != NULL) { utl_xml_get_int ("rules_hint", &config.tasks_rules_hint, tasks_node); utl_xml_get_int ("high_priority_in_bold", &config.tasks_high_in_bold, tasks_node); utl_xml_get_int ("hide_completed", &config.hide_completed, tasks_node); utl_xml_get_int ("delete_completed", &config.delete_completed, tasks_node); utl_xml_get_int ("add_edit", &config.add_edit, tasks_node); utl_xml_get_int ("remember_category", &config.remember_category_in_tasks, tasks_node); utl_xml_get_int ("current_category", &config.current_category_in_tasks, tasks_node); utl_xml_get_int ("pane_pos", &config.tasks_pane_pos, tasks_node); utl_xml_get_int ("tasks_sorting_order", &config.tasks_sorting_order, tasks_node); utl_xml_get_int ("tasks_sorting_mode", &config.tasks_sorting_mode, tasks_node); utl_xml_get_int ("visible_due_date_column", &config.tsk_visible_due_date_column, tasks_node); utl_xml_get_int ("visible_type_column", &config.tsk_visible_type_column, tasks_node); utl_xml_get_int ("visible_priority_column", &config.tsk_visible_priority_column, tasks_node); utl_xml_get_int ("visible_category_column", &config.tsk_visible_category_column, tasks_node); utl_xml_get_int ("tasks_addedit_win_x", &config.tasks_addedit_win_x, tasks_node); utl_xml_get_int ("tasks_addedit_win_y", &config.tasks_addedit_win_y, tasks_node); utl_xml_get_int ("tasks_addedit_win_w", &config.tasks_addedit_win_w, tasks_node); utl_xml_get_int ("tasks_addedit_win_h", &config.tasks_addedit_win_h, tasks_node); utl_xml_get_int ("postpone_time", &config.postpone_time, tasks_node); utl_xml_get_int ("column_idx_0", &config.tasks_column_idx_0, tasks_node); utl_xml_get_int ("column_idx_0_width", &config.tasks_column_idx_0_width, tasks_node); utl_xml_get_int ("column_idx_1", &config.tasks_column_idx_1, tasks_node); utl_xml_get_int ("column_idx_1_width", &config.tasks_column_idx_1_width, tasks_node); utl_xml_get_int ("column_idx_2", &config.tasks_column_idx_2, tasks_node); utl_xml_get_int ("column_idx_2_width", &config.tasks_column_idx_2_width, tasks_node); utl_xml_get_int ("column_idx_3", &config.tasks_column_idx_3, tasks_node); utl_xml_get_int ("column_idx_3_width", &config.tasks_column_idx_3_width, tasks_node); utl_xml_get_int ("column_idx_4", &config.tasks_column_idx_4, tasks_node); utl_xml_get_int ("column_idx_4_width", &config.tasks_column_idx_4_width, tasks_node); utl_xml_get_int ("column_idx_5", &config.tasks_column_idx_5, tasks_node); utl_xml_get_int ("column_idx_5_width", &config.tasks_column_idx_5_width, tasks_node); utl_xml_get_strn ("due_today_color", config.due_today_color, MAXCOLORNAME, tasks_node); utl_xml_get_strn ("due_7days_color", config.due_7days_color, MAXCOLORNAME, tasks_node); utl_xml_get_strn ("past_due_color", config.past_due_color, MAXCOLORNAME, tasks_node); utl_xml_get_strn ("task_info_font", config.task_info_font, MAXFONTNAME, tasks_node); utl_xml_get_strn ("global_notification_command", config.global_notification_command, MAXHELPERCMD, tasks_node); tasks_node = tasks_node->next; } } /*---------------------------------------------------------------------------------------*/ /* contacts */ if ((!xmlStrcmp (node->name, (const xmlChar *) "contacts"))) { contacts_node = node->xmlChildrenNode; while (contacts_node != NULL) { utl_xml_get_int ("find_mode", &config.find_mode, contacts_node); utl_xml_get_int ("show_after_search", &config.show_after_search, contacts_node); utl_xml_get_int ("hide_group_column", &config.hide_group_column, contacts_node); utl_xml_get_int ("pane_pos", &config.contacts_pane_pos, contacts_node); utl_xml_get_int ("rules_hint", &config.contacts_rules_hint, contacts_node); utl_xml_get_int ("photo_width", &config.photo_width, contacts_node); utl_xml_get_int ("visible_age_column", &config.cnt_visible_age_column, contacts_node); utl_xml_get_int ("visible_birthday_date_column", &config.cnt_visible_birthday_date_column, contacts_node); utl_xml_get_int ("visible_zodiac_sign_column", &config.cnt_visible_zodiac_sign_column, contacts_node); utl_xml_get_strn ("contact_tag_color", config.contact_tag_color, MAXCOLORNAME, contacts_node); utl_xml_get_strn ("contact_link_color", config.contact_link_color, MAXCOLORNAME, contacts_node); utl_xml_get_strn ("contact_name_font", config.contact_name_font, MAXFONTNAME, contacts_node); utl_xml_get_strn ("contact_item_font", config.contact_item_font, MAXFONTNAME, contacts_node); utl_xml_get_int ("export_format", &config.export_format, contacts_node); utl_xml_get_strn ("export_fields", config.export_fields, MAXCONTACTFIELDS, contacts_node); utl_xml_get_int ("contacts_sorting_order", &config.contacts_sorting_order, contacts_node); utl_xml_get_int ("contacts_sorting_mode", &config.contacts_sorting_mode, contacts_node); utl_xml_get_int ("contacts_addedit_win_x", &config.contacts_addedit_win_x, contacts_node); utl_xml_get_int ("contacts_addedit_win_y", &config.contacts_addedit_win_y, contacts_node); utl_xml_get_int ("contacts_addedit_win_w", &config.contacts_addedit_win_w, contacts_node); utl_xml_get_int ("contacts_addedit_win_h", &config.contacts_addedit_win_h, contacts_node); utl_xml_get_int ("contacts_export_win_x", &config.contacts_export_win_x, contacts_node); utl_xml_get_int ("contacts_export_win_y", &config.contacts_export_win_y, contacts_node); utl_xml_get_int ("contacts_export_win_w", &config.contacts_export_win_w, contacts_node); utl_xml_get_int ("contacts_export_win_h", &config.contacts_export_win_h, contacts_node); utl_xml_get_int ("contacts_import_sel_win_x", &config.contacts_import_sel_win_x, contacts_node); utl_xml_get_int ("contacts_import_sel_win_y", &config.contacts_import_sel_win_y, contacts_node); utl_xml_get_int ("contacts_import_win_x", &config.contacts_import_win_x, contacts_node); utl_xml_get_int ("contacts_import_win_y", &config.contacts_import_win_y, contacts_node); utl_xml_get_int ("contacts_import_win_w", &config.contacts_import_win_w, contacts_node); utl_xml_get_int ("contacts_import_win_h", &config.contacts_import_win_h, contacts_node); utl_xml_get_int ("contacts_birthdays_win_w", &config.contacts_birthdays_win_w, contacts_node); utl_xml_get_int ("contacts_birthdays_win_h", &config.contacts_birthdays_win_h, contacts_node); utl_xml_get_int ("column_idx_0", &config.contacts_column_idx_0, contacts_node); utl_xml_get_int ("column_idx_0_width", &config.contacts_column_idx_0_width, contacts_node); utl_xml_get_int ("column_idx_1", &config.contacts_column_idx_1, contacts_node); utl_xml_get_int ("column_idx_1_width", &config.contacts_column_idx_1_width, contacts_node); utl_xml_get_int ("column_idx_2", &config.contacts_column_idx_2, contacts_node); utl_xml_get_int ("column_idx_2_width", &config.contacts_column_idx_2_width, contacts_node); utl_xml_get_int ("import_type", &config.import_type, contacts_node); utl_xml_get_int ("import_interface_type", &config.import_interface_type, contacts_node); utl_xml_get_int ("import_bluetooth_channel", &config.import_bluetooth_channel, contacts_node); utl_xml_get_int ("import_usb_interface", &config.import_usb_interface, contacts_node); utl_xml_get_int ("import_binary_xml", &config.import_binary_xml, contacts_node); utl_xml_get_strn ("import_bluetooth_address", config.import_bluetooth_address, MAXADDRESS, contacts_node); contacts_node = contacts_node->next; } } /*---------------------------------------------------------------------------------------*/ /* notes */ if ((!xmlStrcmp (node->name, (const xmlChar *) "notes"))) { notes_node = node->xmlChildrenNode; while (notes_node != NULL) { utl_xml_get_int ("rules_hint", &config.notes_rules_hint, notes_node); utl_xml_get_int ("enc_algorithm", &config.notes_enc_algorithm, notes_node); utl_xml_get_int ("enc_hashing", &config.notes_enc_hashing, notes_node); utl_xml_get_int ("comp_algorithm", &config.notes_comp_algorithm, notes_node); utl_xml_get_int ("comp_ratio", &config.notes_comp_ratio, notes_node); utl_xml_get_int ("sorting_order", &config.notes_sorting_order, notes_node); utl_xml_get_int ("sorting_mode", &config.notes_sorting_mode, notes_node); utl_xml_get_int ("visible_type_column", &config.nte_visible_type_column, notes_node); utl_xml_get_int ("visible_category_column", &config.nte_visible_category_column, notes_node); utl_xml_get_int ("visible_last_changes_column", &config.nte_visible_last_changes_column, notes_node); utl_xml_get_int ("column_idx_0", &config.notes_column_idx_0, notes_node); utl_xml_get_int ("column_idx_0_width", &config.notes_column_idx_0_width, notes_node); utl_xml_get_int ("column_idx_1", &config.notes_column_idx_1, notes_node); utl_xml_get_int ("column_idx_1_width", &config.notes_column_idx_1_width, notes_node); utl_xml_get_int ("column_idx_2", &config.notes_column_idx_2, notes_node); utl_xml_get_int ("column_idx_2_width", &config.notes_column_idx_2_width, notes_node); utl_xml_get_int ("column_idx_3", &config.notes_column_idx_3, notes_node); utl_xml_get_int ("column_idx_3_width", &config.notes_column_idx_3_width, notes_node); utl_xml_get_int ("remember_category", &config.remember_category_in_notes, notes_node); utl_xml_get_int ("current_category", &config.current_category_in_notes, notes_node); utl_xml_get_int ("use_system_date", &config.use_system_date_in_notes, notes_node); utl_xml_get_char ("text_separator", &config.text_separator, notes_node); utl_xml_get_strn ("editor_font", config.notes_editor_font, MAXFONTNAME, notes_node); notes_node = notes_node->next; } } /*---------------------------------------------------------------------------------------*/ node = node->next; } xmlFreeDoc (doc); } else { prefs_set_default_values (); prefs_write_config (appGUI); } }
/* * Given a filename return a filesystem URL. Relative paths are prefixed with * the datafile directory path. */ gchar * data_file_url(const gchar *filename) { gchar *file_path; gchar *uri; /* Absolute path? */ #ifdef G_OS_WIN32 if((strlen(filename) > 2) && (filename[1] == ':')) { file_path = g_strdup(filename); #else if((strlen(filename) > 1) && (filename[0] == '/')) { file_path = g_strdup(filename); #endif } else if(running_in_build_directory()) { file_path = g_strdup_printf("%s/doc/%s", get_datafile_dir(), filename); } else { file_path = g_strdup_printf("%s/%s", get_datafile_dir(), filename); } /* XXX - check, if the file is really existing, otherwise display a simple_dialog about the problem */ /* convert filename to uri */ uri = g_filename_to_uri(file_path, NULL, NULL); g_free(file_path); return uri; } const char * topic_online_url(topic_action_e action) { switch(action) { case(ONLINEPAGE_HOME): return "https://www.wireshark.org"; break; case(ONLINEPAGE_WIKI): return "https://wiki.wireshark.org"; break; case(ONLINEPAGE_DOWNLOAD): return "https://www.wireshark.org/download.html"; break; case(ONLINEPAGE_USERGUIDE): return "https://www.wireshark.org/docs/wsug_html_chunked/"; break; case(ONLINEPAGE_FAQ): return "http://www.wireshark.org/faq.html"; break; case(ONLINEPAGE_ASK): return "https://ask.wireshark.org"; break; case(ONLINEPAGE_SAMPLE_FILES): return "https://wiki.wireshark.org/SampleCaptures"; break; case(ONLINEPAGE_CAPTURE_SETUP): return "https://wiki.wireshark.org/CaptureSetup"; break; case(ONLINEPAGE_NETWORK_MEDIA): return "https://wiki.wireshark.org/CaptureSetup/NetworkMedia"; break; case(ONLINEPAGE_SAMPLE_CAPTURES): return "https://wiki.wireshark.org/SampleCaptures"; break; case(ONLINEPAGE_SECURITY): return "https://wiki.wireshark.org/Security"; break; case(ONLINEPAGE_CHIMNEY): return "https://wiki.wireshark.org/CaptureSetup/Offloading#chimney"; break; default: return NULL; } } /* * Open the help dialog and show a specific HTML help page. */ gchar * user_guide_url(const gchar *page) { GString *url = g_string_new(""); /* * Try to open local .chm file. This is not the most intuitive way to * go about this but it fits in with the rest of the _url functions. */ #ifdef HHC_DIR HWND hw; g_string_printf(url, "%s\\user-guide.chm::/wsug_chm/%s>Wireshark Help", get_datafile_dir(), page); hw = HtmlHelpW(NULL, utf_8to16(url->str), HH_DISPLAY_TOPIC, 0); /* if the .chm file could be opened, stop here */ if(hw != NULL) { g_string_free(url, TRUE /* free_segment */); return NULL; } #endif /* HHC_DIR */ #ifdef DOC_DIR if (g_file_test(DOC_DIR "/guides/wsug_html_chunked", G_FILE_TEST_IS_DIR)) { /* try to open the HTML page from wireshark.org instead */ g_string_printf(url, "file://" DOC_DIR "/guides/wsug_html_chunked/%s", page); } else { #endif /* ifdef DOC_DIR */ /* try to open the HTML page from wireshark.org instead */ g_string_printf(url, "https://www.wireshark.org/docs/wsug_html_chunked/%s", page); #ifdef DOC_DIR } #endif /* ifdef DOC_DIR */ return g_string_free(url, FALSE); }
/* Search the given directory for candidate binaries matching the base binary. * Return a GHashTable of major/minor -> directory pairs */ static GHashTable * get_candidates (const gchar * dir, const gchar * base) { GDir *gdir; GError *error = NULL; const gchar *entry; gchar *path; gchar *suffix, *copy; gchar *pattern; GPatternSpec *spec, *specexe; gchar **dirs; gchar **cur; GHashTable *candidates = NULL; candidates = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); /* compile our pattern specs */ pattern = g_strdup_printf ("%s-*.*", base); spec = g_pattern_spec_new (pattern); g_free (pattern); pattern = g_strdup_printf ("%s-*.*.exe", base); specexe = g_pattern_spec_new (pattern); g_free (pattern); /* get all dirs from the path and prepend with given dir */ if (dir) path = g_strdup_printf ("%s%c%s", dir, G_SEARCHPATH_SEPARATOR, g_getenv ("PATH")); else path = (gchar *) g_getenv ("PATH"); dirs = g_strsplit (path, G_SEARCHPATH_SEPARATOR_S, 0); if (dir) g_free (path); /* check all of these in reverse order by winding to bottom and going up */ cur = &dirs[0]; while (*cur) ++cur; while (cur != &dirs[0]) { --cur; if (!g_file_test (*cur, G_FILE_TEST_EXISTS) || !g_file_test (*cur, G_FILE_TEST_IS_DIR)) { continue; } gdir = g_dir_open (*cur, 0, &error); if (!gdir) { g_warning ("Could not open dir %s: %s", *cur, error->message); g_error_free (error); return NULL; } while ((entry = g_dir_read_name (gdir))) { if (g_pattern_match_string (spec, entry) || g_pattern_match_string (specexe, entry)) { gchar *full; /* is it executable ? */ full = g_build_filename (*cur, entry, NULL); if (!g_file_test (full, G_FILE_TEST_IS_EXECUTABLE)) { g_free (full); continue; } g_free (full); /* strip base and dash from it */ suffix = g_strdup (&(entry[strlen (base) + 1])); copy = g_strdup (suffix); /* strip possible .exe from copy */ if (g_strrstr (copy, ".exe")) g_strrstr (copy, ".exe")[0] = '\0'; /* stricter pattern check: check if it only contains digits or dots */ g_strcanon (copy, "0123456789.", 'X'); if (strstr (copy, "X")) { g_free (suffix); g_free (copy); continue; } g_free (copy); g_hash_table_insert (candidates, suffix, g_strdup (*cur)); } } } g_strfreev (dirs); g_pattern_spec_free (spec); return candidates; }
static gboolean gimp_config_writer_close_file (GimpConfigWriter *writer, GError **error) { g_return_val_if_fail (writer->fd != 0, FALSE); if (! writer->filename) return TRUE; if (writer->error) { close (writer->fd); if (writer->tmpname) g_unlink (writer->tmpname); return FALSE; } #ifdef HAVE_FSYNC /* If the final destination exists, we want to sync the newly written * file to ensure the data is on disk when we rename over the destination. * otherwise if we get a system crash we can lose both the new and the * old file on some filesystems. (I.E. those that don't guarantee the * data is written to the disk before the metadata.) */ if (writer->tmpname && g_file_test (writer->filename, G_FILE_TEST_EXISTS)) { if (fsync (writer->fd) != 0) { g_set_error (error, GIMP_CONFIG_ERROR, GIMP_CONFIG_ERROR_WRITE, _("Error writing to temporary file for '%s': %s\n" "The original file has not been touched."), gimp_filename_to_utf8 (writer->filename), g_strerror (errno)); close (writer->fd); g_unlink (writer->tmpname); return FALSE; } } #endif if (close (writer->fd) != 0) { if (writer->tmpname) { if (g_file_test (writer->filename, G_FILE_TEST_EXISTS)) { g_set_error (error, GIMP_CONFIG_ERROR, GIMP_CONFIG_ERROR_WRITE, _("Error writing to temporary file for '%s': %s\n" "The original file has not been touched."), gimp_filename_to_utf8 (writer->filename), g_strerror (errno)); } else { g_set_error (error, GIMP_CONFIG_ERROR, GIMP_CONFIG_ERROR_WRITE, _("Error writing to temporary file for '%s': %s\n" "No file has been created."), gimp_filename_to_utf8 (writer->filename), g_strerror (errno)); } g_unlink (writer->tmpname); } else { g_set_error (error, GIMP_CONFIG_ERROR, GIMP_CONFIG_ERROR_WRITE, _("Error writing to '%s': %s"), gimp_filename_to_utf8 (writer->filename), g_strerror (errno)); } return FALSE; } if (writer->tmpname) { if (g_rename (writer->tmpname, writer->filename) == -1) { g_set_error (error, GIMP_CONFIG_ERROR, GIMP_CONFIG_ERROR_WRITE, _("Could not create '%s': %s"), gimp_filename_to_utf8 (writer->filename), g_strerror (errno)); g_unlink (writer->tmpname); return FALSE; } } return TRUE; }
static void init (void) { GimpMessageHandlerType old_handler; gimp_plugin_domain_register (PLUGIN_NAME, NULL); setup_debug_mask (); old_handler = gimp_message_get_handler (); if (old_handler == GIMP_CONSOLE) gimp_message_set_handler (GIMP_MESSAGE_BOX); search_path = gimp_gimprc_query (PSPI_PATH_TOKEN); if (search_path == NULL) search_path = g_strdup (""); get_saved_plugin_data (); pspirc_values_modified = FALSE; scan_search_path (); /* Forget those PS plug-ins that weren't around any longer. */ g_hash_table_foreach_remove (plug_in_hash, check_present, NULL); /* Rewrite the pspirc file if necessary */ if (pspirc_values_modified) { gchar *pspirc_name = gimp_personal_rc_file (PSPIRC); gchar *temp_name = g_strconcat (pspirc_name, ".new", NULL); gchar *bak_name = g_strconcat (pspirc_name, ".bak", NULL); FILE *pspirc = fopen (temp_name, "w"); if (pspirc == NULL) g_message (_("Could not open %s for writing"), temp_name); else { PSPI_DEBUG (PSPIRC, g_print ("Saving pspirc file\n")); fprintf (pspirc, "<pspi-settings>\n"); g_hash_table_foreach (plug_in_hash, save_pspirc_entry, pspirc); fprintf (pspirc, "</pspi-settings>\n"); PSPI_DEBUG (PSPIRC, g_print ("\n")); fclose (pspirc); remove (bak_name); if (g_file_test (pspirc_name, G_FILE_TEST_EXISTS) && rename (pspirc_name, bak_name) != 0) g_message (_("Could not rename %s to %s"), pspirc_name, bak_name); else { if (rename (temp_name, pspirc_name) != 0) { g_message (_("Could not rename %s to %s"), temp_name, pspirc_name); if (rename (bak_name, pspirc_name) != 0) g_message (_("Could not rename %s to %s"), bak_name, pspirc_name); } else remove (bak_name); } } g_free (pspirc_name); g_free (temp_name); g_free (bak_name); } if (old_handler == GIMP_CONSOLE) gimp_message_set_handler (GIMP_CONSOLE); }
GtkWidget *create_class_page (void) { #if 1 GtkWidget *vbox; gchar *path; vbox = gtk_vbox_new (FALSE, 0); priv->kb = utt_keyboard_new (); path = g_build_filename (PKGDATADIR, "keyboard_wubi.png", NULL); utt_keyboard_set_image (UTT_KEYBOARD (priv->kb), path); g_free (path); gtk_box_pack_start (GTK_BOX (vbox), priv->kb, FALSE, FALSE, 0); return vbox; #else GtkWidget *vbox; GtkWidget *frame, *hbox, *hbox2, *align; GtkWidget *ch_draw[6]; GtkWidget *kb_draw; cairo_surface_t *kb_image; gint i; gchar *path; vbox = gtk_vbox_new (FALSE, 0); frame = gtk_frame_new (_("Display Zone")); hbox = gtk_hbox_new (FALSE, 0); gtk_container_add (GTK_CONTAINER (frame), hbox); gtk_container_set_border_width (GTK_CONTAINER (frame), 4); gtk_container_set_border_width (GTK_CONTAINER (hbox), 4); gtk_box_pack_start (GTK_BOX (vbox), frame, TRUE, TRUE, 0); /* padding */ hbox2 = gtk_hbox_new (FALSE, 0); gtk_box_pack_start (GTK_BOX (hbox), hbox2, TRUE, TRUE, 0); for (i = 0; i < 6; i++) { ch_draw[i] = gtk_drawing_area_new (); gtk_widget_set_size_request (ch_draw[i], 48, 48); hbox2 = gtk_hbox_new (FALSE, 0); gtk_box_pack_start (GTK_BOX (hbox), hbox2, TRUE, TRUE, 0); align = gtk_alignment_new (0.5, 0.5, 0, 0); gtk_container_add (GTK_CONTAINER (align), ch_draw[i]); gtk_box_pack_start (GTK_BOX (hbox2), align, TRUE, TRUE, 0); } /* padding */ hbox2 = gtk_hbox_new (FALSE, 0); gtk_box_pack_start (GTK_BOX (hbox), hbox2, TRUE, TRUE, 0); kb_draw = gtk_drawing_area_new (); path = g_build_filename (PKGDATADIR, "keyboard_wubi.png", NULL); if (!g_file_test (path, G_FILE_TEST_EXISTS)) { g_error (G_STRLOC ": %s doesn't exists.", path); } kb_image = cairo_image_surface_create_from_png (path); g_free (path); gtk_widget_add_events (kb_draw, GDK_KEY_PRESS_MASK); /* set can focus and grab focus, so we can receive key press event */ gtk_widget_set_can_focus (kb_draw, TRUE); gtk_widget_set_size_request (kb_draw, cairo_image_surface_get_width (kb_image), cairo_image_surface_get_height (kb_image)); align = gtk_alignment_new (0.5, 0.5, 0, 0); gtk_container_add (GTK_CONTAINER (align), kb_draw); gtk_container_set_border_width (GTK_CONTAINER (align), 4); gtk_box_pack_start (GTK_BOX (vbox), align, TRUE, TRUE, 0); return vbox; #endif }
static void set_thumbnail(GtkTreeIter *iter, const gchar * tmp_dir, const gchar *out_full, int is_PolSARpro) { if (g_show_thumbnail_columns && use_thumbnails) { // changed this to always do scaling, no reason not to really // since it is pretty quick int scaling_required = TRUE; char *basename = get_basename(out_full); char *thumbnail_name = MALLOC(sizeof(char)*(strlen(tmp_dir)+strlen(basename)+32)); sprintf(thumbnail_name, "%s%c%s_thumb.png", tmp_dir, DIR_SEPARATOR, basename); // if output was a png image, we will be using that instead // of the "_thumb" file if (!fileExists(thumbnail_name) && strcmp_case(findExt(out_full), ".png") == 0) { strcpy(thumbnail_name, out_full); } GError *err = NULL, *err_big = NULL; GdkPixbuf *pb, *pb_big; if (g_file_test(thumbnail_name, G_FILE_TEST_EXISTS)) { if (scaling_required) { pb = gdk_pixbuf_new_from_file_at_size(thumbnail_name, THUMB_SIZE, THUMB_SIZE, &err); pb_big = gdk_pixbuf_new_from_file_at_size(thumbnail_name, THUMB_SIZE_BIG, THUMB_SIZE_BIG, &err_big); } else { pb_big = gdk_pixbuf_new_from_file(thumbnail_name, &err); pb = gdk_pixbuf_new_from_file_at_size(thumbnail_name, THUMB_SIZE, THUMB_SIZE, &err); } if (!err) { gtk_list_store_set(completed_list_store, iter, COMP_COL_OUTPUT_THUMBNAIL, pb, -1); if (!err_big) { gtk_list_store_set(completed_list_store, iter, COMP_COL_OUTPUT_THUMBNAIL_BIG, pb_big, -1); } else /*{ g_warning("Error loading image '%s': %s\n", thumbnail_name, err_big->message); g_error_free(err_big); }*/ asfPrintWarning("Could not display thumbnail!\n"); } else /*{ g_warning("Error loading image '%s': %s\n", thumbnail_name, err->message); g_error_free(err); }*/ asfPrintWarning("Could not display thumbnail!\n"); } free(thumbnail_name); } }
int qaul_copyDirectory(char* source, char* target) { // g_file_copy: https://developer.gnome.org/gio/stable/GFile.html#g-file-copy // Permissions: http://www.gnu.org/software/libc/manual/html_node/Permission-Bits.html // glib-file-utilities: https://developer.gnome.org/glib/2.37/glib-File-Utilities.html const gchar *fileName; char sourcePath[MAX_PATH_LEN], targetPath[MAX_PATH_LEN]; GFile *sourceFile, *targetFile; GFileEnumerator* enumerator; GFileInfo *fileInfo; GError *error = NULL; printf("qaul_copyDirectory: %s -> %s\n", source, target); // test if source path is a directory if(g_file_test(source, G_FILE_TEST_IS_DIR)) { // check if directory exists & create it otherwise if(!g_file_test(target, G_FILE_TEST_EXISTS) && g_mkdir(target, S_IRUSR|S_IWUSR|S_IXUSR)==-1) { printf("qaul.net home directory %s creation error.\n", target); return 0; } else { // get directories files sourceFile = g_file_new_for_path(source); enumerator = g_file_enumerate_children(sourceFile, "*", G_FILE_QUERY_INFO_NONE, NULL, &error); // loop through the directories files fileInfo = g_file_enumerator_next_file(enumerator, NULL, &error); while(fileInfo != NULL) { // copy regular files if(g_file_info_get_file_type(fileInfo) == G_FILE_TYPE_REGULAR) { // get source file fileName = g_file_info_get_name(fileInfo); sourceFile = g_file_get_child(g_file_enumerator_get_container(enumerator), fileName); // create target path sprintf(targetPath, "%s/%s", target, fileName); targetFile = g_file_new_for_path(targetPath); if(!g_file_copy(sourceFile, targetFile, G_FILE_COPY_OVERWRITE, NULL, NULL, NULL, &error)) { printf("qaul_copyDirectory copy file error: %s\n", (char*)error->message); } } // recursively copy directories else if(g_file_info_get_file_type(fileInfo) == G_FILE_TYPE_DIRECTORY) { fileName = g_file_info_get_name(fileInfo); sprintf(sourcePath, "%s/%s", source, fileName); sprintf(targetPath, "%s/%s", target, fileName); if(!qaul_copyDirectory(sourcePath, targetPath)) printf("qaul_copyDirectory error copying %s -> %s", sourcePath, targetPath); } // free file info g_object_unref(fileInfo); fileInfo = g_file_enumerator_next_file(enumerator, NULL, &error); } } return 1; } else printf("qaul_copyDirectoryRecursively source is not a directory error: %s\n", source); /* else { sourcefile = g_file_new_for_path(source); targetfile = g_file_new_for_path(target); if(!g_file_copy(sourcefile, targetfile, G_FILE_COPY_OVERWRITE, NULL, NULL, NULL, &error)) { printf("qaul_copyDirectory error: %s\n", (char*)error->message); return 0; } } */ return 0; }
int main(int argc, char *argv[]) { char qaulUserPath[MAX_PATH_LEN]; char qaulTmpPath[MAX_PATH_LEN]; char qaulTmpPath2[MAX_PATH_LEN]; qaulConfigureCounter = 0; qaulTimerEvents = 0; qaulTimerSockets = 0; qaulTimerTopology = 0; network_interface_found = 0; // initialize glib types g_type_init(); // set paths sprintf(qaulUserPath, "%s/.qaul", (char*)g_get_home_dir()); printf ("qaul.net home directory is %s\n", qaulUserPath); // create qaul user directory if(!g_file_test(qaulUserPath, G_FILE_TEST_EXISTS)) { // create directory // http://www.gnu.org/software/libc/manual/html_node/Permission-Bits.html if(g_mkdir(qaulUserPath, S_IRUSR|S_IWUSR|S_IXUSR)== -1) printf("qaul.net home directory %s creation error.\n", qaulUserPath); } // check if we have to update sprintf(qaulTmpPath, "%s/%s", qaulUserPath, QAUL_VERSION); if(!g_file_test(qaulTmpPath, G_FILE_TEST_EXISTS)) { printf("Update user folder to qaul.net version %s\n", QAUL_VERSION); // copy www folder sprintf(qaulTmpPath, "%s/www", QAUL_ROOT_PATH); sprintf(qaulTmpPath2, "%s/www", qaulUserPath); if(!qaul_copyDirectory(qaulTmpPath, qaulTmpPath2)) printf("qaul copy directory error. source: %s target: %s\n", qaulTmpPath, qaulTmpPath2); // TODO: update data base // remove old data base if it exists sprintf(qaulTmpPath, "%s/qaullib.db", qaulUserPath); if(g_file_test(qaulTmpPath, G_FILE_TEST_EXISTS)) if(g_remove(qaulTmpPath) == -1) printf("qaul.net database %s removal error\n", qaulTmpPath); // create qaul version file sprintf(qaulTmpPath, "%s/%s", qaulUserPath, QAUL_VERSION); if(!g_file_test(qaulTmpPath, G_FILE_TEST_EXISTS)) if(!g_creat(qaulTmpPath, S_IRUSR|S_IWUSR) == -1) printf("qaul.net version file %s creation error\n", qaulTmpPath); } Qaullib_Init(qaulUserPath); // set configuration Qaullib_SetConf(QAUL_CONF_INTERFACE); // enable debug menu qaul_conf_debug = 1; if(!Qaullib_WebserverStart()) printf("Webserver startup failed\n"); // initialize dbus connection qaul_dbus_init(&network_dbus_connection); // start configuration timer qaulConfigureTimer = g_timeout_add(500, qaul_configure, NULL); // open window gtk_init(&argc,&argv); // Create a window that will contain the browser instance qaulMainWindow = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_default_size(GTK_WINDOW(qaulMainWindow), 400, 592); gtk_window_set_title(GTK_WINDOW(qaulMainWindow), "qaul.net - قول"); sprintf(qaulTmpPath, "%s/app_icon.png", QAUL_ROOT_PATH); gtk_window_set_icon(GTK_WINDOW(qaulMainWindow), create_pixbuf(qaulTmpPath)); // Create a browser instance WebKitWebView *webView = WEBKIT_WEB_VIEW(webkit_web_view_new()); // Create a scrollable area, and put the browser instance into it GtkWidget *scrolledWindow = gtk_scrolled_window_new(NULL, NULL); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledWindow), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); gtk_container_add(GTK_CONTAINER(scrolledWindow), GTK_WIDGET(webView)); // Set up callbacks so that if either the main window or the browser instance is // closed, the program will exit g_signal_connect(qaulMainWindow, "destroy", G_CALLBACK(destroyWindowCb), NULL); g_signal_connect(webView, "close-web-view", G_CALLBACK(closeWebViewCb), qaulMainWindow); // Put the scrollable area into the main window gtk_container_add(GTK_CONTAINER(qaulMainWindow), scrolledWindow); // Load a web page into the browser instance webkit_web_view_load_uri(webView, "http://127.0.0.1:8081/qaul.html"); // Make sure that when the browser area becomes visible, it will get mouse // and keyboard events gtk_widget_grab_focus(GTK_WIDGET(webView)); // Make sure the main window and all its contents are visible gtk_widget_show_all(qaulMainWindow); // Run the main GTK+ event loop gtk_main(); return 0; }
int main(int argc, char *arg[]) { bindtextdomain (GETTEXT_PACKAGE, DARKTABLE_LOCALEDIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); gtk_init (&argc, &arg); // parse command line arguments char *image_filename = NULL; char *xmp_filename = NULL; char *output_filename = NULL; int file_counter = 0; int width = 0, height = 0, bpp = 0; gboolean verbose = FALSE, high_quality = TRUE; int k; for(k=1; k<argc; k++) { if(arg[k][0] == '-') { if(!strcmp(arg[k], "--help")) { usage(arg[0]); exit(1); } else if(!strcmp(arg[k], "--version")) { printf("this is darktable-cli\ncopyright (c) 2012-2014 johannes hanika, tobias ellinghaus\n"); exit(1); } else if(!strcmp(arg[k], "--width")) { k++; width = MAX(atoi(arg[k]), 0); } else if(!strcmp(arg[k], "--height")) { k++; height = MAX(atoi(arg[k]), 0); } else if(!strcmp(arg[k], "--bpp")) { k++; bpp = MAX(atoi(arg[k]), 0); fprintf(stderr, "%s %d\n", _("TODO: sorry, due to API restrictions we currently cannot set the BPP to"), bpp); } else if(!strcmp(arg[k], "--hq")) { k++; gchar *str = g_ascii_strup(arg[k], -1); if(!g_strcmp0(str, "0") || !g_strcmp0(str, "FALSE")) high_quality = FALSE; else if(!g_strcmp0(str, "1") || !g_strcmp0(str, "TRUE")) high_quality = TRUE; else { fprintf(stderr, "%s: %s\n", _("Unknown option for --hq"), arg[k]); usage(arg[0]); exit(1); } g_free(str); } else if(!strcmp(arg[k], "-v") || !strcmp(arg[k], "--verbose")) { verbose = TRUE; } else if(!strcmp(arg[k], "--core")) { // everything from here on should be passed to the core k++; break; } } else { if(file_counter == 0) image_filename = arg[k]; else if(file_counter == 1) xmp_filename = arg[k]; else if(file_counter == 2) output_filename = arg[k]; file_counter++; } } int m_argc = 0; char *m_arg[4 + argc - k]; m_arg[m_argc++] = "darktable-cli"; m_arg[m_argc++] = "--library"; m_arg[m_argc++] = ":memory:"; for(; k < argc; k++) m_arg[m_argc++] = arg[k]; m_arg[m_argc] = NULL; if(file_counter < 2 || file_counter > 3) { usage(arg[0]); exit(1); } else if(file_counter == 2) { // no xmp file given output_filename = xmp_filename; xmp_filename = NULL; } // the output file already exists, so there will be a sequence number added if(g_file_test(output_filename, G_FILE_TEST_EXISTS)) { fprintf(stderr, "%s\n", _("output file already exists, it will get renamed")); } // init dt without gui: if(dt_init(m_argc, m_arg, 0,NULL)) exit(1); dt_film_t film; int id = 0; int filmid = 0; gchar *directory = g_path_get_dirname(image_filename); filmid = dt_film_new(&film, directory); id = dt_image_import(filmid, image_filename, TRUE); if(!id) { fprintf(stderr, _("error: can't open file %s"), image_filename); fprintf(stderr, "\n"); exit(1); } g_free(directory); // attach xmp, if requested: if(xmp_filename) { const dt_image_t *cimg = dt_image_cache_read_get(darktable.image_cache, id); dt_image_t *image = dt_image_cache_write_get(darktable.image_cache, cimg); dt_exif_xmp_read(image, xmp_filename, 1); // don't write new xmp: dt_image_cache_write_release(darktable.image_cache, image, DT_IMAGE_CACHE_RELAXED); dt_image_cache_read_release(darktable.image_cache, image); } // print the history stack if(verbose) { gchar *history = dt_history_get_items_as_string(id); if(history) printf("%s\n", history); else printf("[%s]\n", _("empty history stack")); } // try to find out the export format from the output_filename char *ext = output_filename + strlen(output_filename); while(ext > output_filename && *ext != '.') ext--; *ext = '\0'; ext++; if(!strcmp(ext, "jpg")) ext = "jpeg"; if(!strcmp(ext, "tif")) ext = "tiff"; // init the export data structures dt_imageio_module_format_t *format; dt_imageio_module_storage_t *storage; dt_imageio_module_data_t *sdata, *fdata; storage = dt_imageio_get_storage_by_name("disk"); // only exporting to disk makes sense if(storage == NULL) { fprintf(stderr, "%s\n", _("cannot find disk storage module. please check your installation, something seems to be broken.")); exit(1); } sdata = storage->get_params(storage); if(sdata == NULL) { fprintf(stderr, "%s\n", _("failed to get parameters from storage module, aborting export ...")); exit(1); } // and now for the really ugly hacks. don't tell your children about this one or they won't sleep at night any longer ... g_strlcpy((char*)sdata, output_filename, 1024); // all is good now, the last line didn't happen. format = dt_imageio_get_format_by_name(ext); if(format == NULL) { fprintf(stderr, _("unknown extension '.%s'"), ext); fprintf(stderr, "\n"); exit(1); } fdata = format->get_params(format); if(fdata == NULL) { fprintf(stderr, "%s\n", _("failed to get parameters from format module, aborting export ...")); exit(1); } uint32_t w,h,fw,fh,sw,sh; fw=fh=sw=sh=0; storage->dimension(storage, &sw, &sh); format->dimension(format, &fw, &fh); if( sw==0 || fw==0) w=sw>fw?sw:fw; else w=sw<fw?sw:fw; if( sh==0 || fh==0) h=sh>fh?sh:fh; else h=sh<fh?sh:fh; fdata->max_width = width; fdata->max_height = height; fdata->max_width = (w!=0 && fdata->max_width >w)?w:fdata->max_width; fdata->max_height = (h!=0 && fdata->max_height >h)?h:fdata->max_height; fdata->style[0] = '\0'; if(storage->initialize_store) { GList *single_image= g_list_append(NULL,GINT_TO_POINTER(id)); storage->initialize_store(storage, sdata,format,fdata,&single_image, high_quality); g_list_free(single_image); } //TODO: add a callback to set the bpp without going through the config storage->store(storage, sdata, id, format, fdata, 1, 1, high_quality); // cleanup time if(storage->finalize_store) storage->finalize_store(storage, sdata); storage->free_params(storage, sdata); format->free_params(format, fdata); dt_cleanup(); }
static void _lib_modulelist_populate_callback(gpointer instance, gpointer user_data) { dt_lib_module_t *self = (dt_lib_module_t *)user_data; if(!self || !(self->data)) return; GtkListStore *store; GtkTreeIter iter; GtkWidget *view=GTK_WIDGET(((dt_lib_modulelist_t*)self->data)->tree); GtkCellRenderer *pix_renderer,*fav_renderer,*text_renderer; GtkStyle *style=gtk_widget_get_style(view); store = gtk_list_store_new (NUM_COLS, GDK_TYPE_PIXBUF, G_TYPE_POINTER); gtk_tree_view_set_model (GTK_TREE_VIEW(view), GTK_TREE_MODEL(store)); g_object_unref (store); gtk_tree_sortable_set_sort_func(GTK_TREE_SORTABLE(store), COL_MODULE, _lib_modulelist_gui_sort, NULL, NULL); gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(store), COL_MODULE, GTK_SORT_ASCENDING); pix_renderer = gtk_cell_renderer_pixbuf_new (); g_object_set(pix_renderer,"cell-background-gdk",&style->bg[GTK_STATE_ACTIVE],NULL); fav_renderer = gtk_cell_renderer_pixbuf_new (); cairo_surface_t *fav_cst = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, ICON_SIZE, ICON_SIZE); cairo_t *fav_cr = cairo_create(fav_cst); cairo_set_source_rgb(fav_cr, 0.7,0.7,0.7); dtgtk_cairo_paint_modulegroup_favorites(fav_cr, 0, 0, ICON_SIZE, ICON_SIZE, 0); guchar* data = cairo_image_surface_get_data(fav_cst); dt_draw_cairo_to_gdk_pixbuf(data, ICON_SIZE, ICON_SIZE); ((dt_lib_modulelist_t*)self->data)->fav_pixbuf = gdk_pixbuf_new_from_data(data, GDK_COLORSPACE_RGB, TRUE, 8, ICON_SIZE, ICON_SIZE, cairo_image_surface_get_stride(fav_cst), NULL, NULL); g_object_set(fav_renderer,"cell-background-gdk",&style->bg[GTK_STATE_ACTIVE],NULL); g_object_set(fav_renderer,"width",gdk_pixbuf_get_width(((dt_lib_modulelist_t*)self->data)->fav_pixbuf),NULL); text_renderer = gtk_cell_renderer_text_new (); g_object_set(text_renderer,"cell-background-gdk",&style->bg[GTK_STATE_ACTIVE],NULL); gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(view),FALSE); gtk_tree_view_set_headers_clickable(GTK_TREE_VIEW(view),FALSE); gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(view),FALSE); GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(view)); gtk_tree_selection_set_mode(selection, GTK_SELECTION_NONE); GtkTreeViewColumn *col; col = gtk_tree_view_get_column(GTK_TREE_VIEW(view), 0); if(col) gtk_tree_view_remove_column(GTK_TREE_VIEW(view), col); gtk_tree_view_insert_column_with_data_func (GTK_TREE_VIEW (view), 0, "favorite", fav_renderer, favorite_renderer_function, NULL,NULL); col = gtk_tree_view_get_column(GTK_TREE_VIEW(view), 1); if(col) gtk_tree_view_remove_column(GTK_TREE_VIEW(view), col); gtk_tree_view_insert_column_with_data_func (GTK_TREE_VIEW (view), 1, "image", pix_renderer, image_renderer_function, NULL,NULL); col = gtk_tree_view_get_column(GTK_TREE_VIEW(view), 2); if(col) gtk_tree_view_remove_column(GTK_TREE_VIEW(view), col); gtk_tree_view_insert_column_with_data_func (GTK_TREE_VIEW (view), 2, "name", text_renderer, text_renderer_function, NULL,NULL); /* go thru list of iop modules and add them to the list */ GList *modules = g_list_last(darktable.develop->iop); while(modules) { dt_iop_module_t *module = (dt_iop_module_t *)(modules->data); if(!dt_iop_is_hidden(module) && !(module->flags() & IOP_FLAGS_DEPRECATED) && module->multi_priority==0) { char filename[DT_MAX_PATH_LEN], datadir[DT_MAX_PATH_LEN]; dt_loc_get_datadir(datadir, DT_MAX_PATH_LEN); snprintf(filename, DT_MAX_PATH_LEN, "%s/pixmaps/plugins/darkroom/%s.png", datadir, module->op); if(!g_file_test(filename, G_FILE_TEST_IS_REGULAR)) snprintf(filename, DT_MAX_PATH_LEN, "%s/pixmaps/plugins/darkroom/template.png", datadir); GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file(filename,NULL); gtk_list_store_append (store, &iter); gtk_list_store_set (store, &iter, COL_IMAGE, pixbuf, COL_MODULE,module, -1); g_object_unref (pixbuf); } modules = g_list_previous(modules); } }
GModule* g_module_open (const gchar *file_name, GModuleFlags flags) { GModule *module; gpointer handle = NULL; gchar *name = NULL; SUPPORT_OR_RETURN (NULL); g_static_rec_mutex_lock (&g_module_global_lock); if (G_UNLIKELY (!module_debug_initialized)) _g_module_debug_init (); if (module_debug_flags & G_MODULE_DEBUG_BIND_NOW_MODULES) flags &= ~G_MODULE_BIND_LAZY; if (!file_name) { if (!main_module) { handle = _g_module_self (); if (handle) { main_module = g_new (GModule, 1); main_module->file_name = NULL; #if defined (G_OS_WIN32) && !defined(_WIN64) main_module->cp_file_name = NULL; #endif main_module->handle = handle; main_module->ref_count = 1; main_module->is_resident = TRUE; main_module->unload = NULL; main_module->next = NULL; } } else main_module->ref_count++; g_static_rec_mutex_unlock (&g_module_global_lock); return main_module; } /* we first search the module list by name */ module = g_module_find_by_name (file_name); if (module) { module->ref_count++; g_static_rec_mutex_unlock (&g_module_global_lock); return module; } /* check whether we have a readable file right away */ if (g_file_test (file_name, G_FILE_TEST_IS_REGULAR)) name = g_strdup (file_name); /* try completing file name with standard library suffix */ if (!name) { name = g_strconcat (file_name, "." G_MODULE_SUFFIX, NULL); if (!g_file_test (name, G_FILE_TEST_IS_REGULAR)) { g_free (name); name = NULL; } } /* try completing by appending libtool suffix */ if (!name) { name = g_strconcat (file_name, ".la", NULL); if (!g_file_test (name, G_FILE_TEST_IS_REGULAR)) { g_free (name); name = NULL; } } /* we can't access() the file, lets hope the platform backends finds * it via library paths */ if (!name) { gchar *dot = strrchr (file_name, '.'); gchar *slash = strrchr (file_name, G_DIR_SEPARATOR); /* make sure the name has a suffix */ if (!dot || dot < slash) name = g_strconcat (file_name, "." G_MODULE_SUFFIX, NULL); else name = g_strdup (file_name); } /* ok, try loading the module */ if (name) { /* if it's a libtool archive, figure library file to load */ if (str_check_suffix (name, ".la")) /* libtool archive? */ { gchar *real_name = parse_libtool_archive (name); /* real_name might be NULL, but then module error is already set */ if (real_name) { g_free (name); name = real_name; } } if (name) handle = _g_module_open (name, (flags & G_MODULE_BIND_LAZY) != 0, (flags & G_MODULE_BIND_LOCAL) != 0); } else { gchar *display_file_name = g_filename_display_name (file_name); g_module_set_error_unduped (g_strdup_printf ("unable to access file \"%s\"", display_file_name)); g_free (display_file_name); } g_free (name); if (handle) { gchar *saved_error; GModuleCheckInit check_init; const gchar *check_failed = NULL; /* search the module list by handle, since file names are not unique */ module = g_module_find_by_handle (handle); if (module) { _g_module_close (module->handle, TRUE); module->ref_count++; g_module_set_error (NULL); g_static_rec_mutex_unlock (&g_module_global_lock); return module; } saved_error = g_strdup (g_module_error ()); g_module_set_error (NULL); module = g_new (GModule, 1); module->file_name = g_strdup (file_name); #if defined (G_OS_WIN32) && !defined(_WIN64) module->cp_file_name = g_locale_from_utf8 (file_name, -1, NULL, NULL, NULL); #endif module->handle = handle; module->ref_count = 1; module->is_resident = FALSE; module->unload = NULL; module->next = modules; modules = module; /* check initialization */ if (g_module_symbol (module, "g_module_check_init", (gpointer) &check_init) && check_init != NULL) check_failed = check_init (module); /* we don't call unload() if the initialization check failed. */ if (!check_failed) g_module_symbol (module, "g_module_unload", (gpointer) &module->unload); if (check_failed) { gchar *error; error = g_strconcat ("GModule (", file_name, ") ", "initialization check failed: ", check_failed, NULL); g_module_close (module); module = NULL; g_module_set_error (error); g_free (error); } else g_module_set_error (saved_error); g_free (saved_error); } if (module != NULL && (module_debug_flags & G_MODULE_DEBUG_RESIDENT_MODULES)) g_module_make_resident (module); g_static_rec_mutex_unlock (&g_module_global_lock); return module; }
gboolean lock_port(gchar * name) #endif { #ifndef __WIN32__ gchar *tmpbuf = NULL; gchar *lock = NULL; gchar **vector = NULL; gchar *contents = NULL; GError *err = NULL; guint i = 0; gint pid = 0; /* If no /proc (i.e. os-X), just fake it and return */ if (!g_file_test("/proc",G_FILE_TEST_IS_DIR)) return TRUE; lock = g_strdup_printf("/var/lock/LCK.."); vector = g_strsplit(name,PSEP,-1); for (i=0;i<g_strv_length(vector);i++) { if ((g_ascii_strcasecmp(vector[i],"") == 0) || (g_ascii_strcasecmp(vector[i],"dev") == 0)) continue; lock = g_strconcat(lock,vector[i],NULL); } g_strfreev(vector); if (g_file_test(lock,G_FILE_TEST_IS_REGULAR)) { /* printf("found existing lock!\n");*/ if(g_file_get_contents(lock,&contents,NULL,&err)) { /* printf("read existing lock\n");*/ vector = g_strsplit(g_strchug(contents)," ", -1); /* printf("lock had %i fields\n",g_strv_length(vector));*/ pid = (gint)g_ascii_strtoull(vector[0],NULL,10); /* printf("pid in lock \"%i\"\n",pid);*/ g_free(contents); g_strfreev(vector); tmpbuf = g_strdup_printf("/proc/%i",pid); if (g_file_test(tmpbuf,G_FILE_TEST_IS_DIR)) { /* printf("process active\n");*/ g_free(tmpbuf); g_free(lock); return FALSE; } else g_remove(lock); g_free(tmpbuf); } } contents = g_strdup_printf(" %i",getpid()); if(g_file_set_contents(lock,contents,-1,&err)) { serial_lockfile = g_strdup(lock); g_free(contents); g_free(lock); return TRUE; } else printf("Error setting serial lock %s\n",(gchar *)strerror(errno)); g_free(contents); #endif return TRUE; }
void send_raw_file(GtkAction *action, gpointer data) { GtkWidget *file_select; file_select = gtk_file_chooser_dialog_new(_("Send RAW File"), GTK_WINDOW(Fenetre), GTK_FILE_CHOOSER_ACTION_OPEN, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, NULL); if(fic_defaut != NULL) gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(file_select), fic_defaut); if(gtk_dialog_run(GTK_DIALOG(file_select)) == GTK_RESPONSE_ACCEPT) { gchar *fileName; gchar *msg; fileName = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(file_select)); if(!g_file_test(fileName, G_FILE_TEST_IS_REGULAR)) { msg = g_strdup_printf(_("Error opening file\n")); show_message(msg, MSG_ERR); g_free(msg); g_free(fileName); gtk_widget_destroy(file_select); return; } Fichier = open(fileName, O_RDONLY); if(Fichier != -1) { GtkWidget *Bouton_annuler, *Box; fic_defaut = g_strdup(fileName); msg = g_strdup_printf(_("%s : transfer in progress..."), fileName); gtk_statusbar_push(GTK_STATUSBAR(StatusBar), id, msg); car_written = 0; current_buffer_position = 0; bytes_read = 0; nb_car = lseek(Fichier, 0L, SEEK_END); lseek(Fichier, 0L, SEEK_SET); Window = gtk_dialog_new(); gtk_window_set_title(GTK_WINDOW(Window), msg); g_free(msg); Box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 10); gtk_container_add(GTK_CONTAINER(gtk_dialog_get_content_area(GTK_DIALOG(Window))), Box); ProgressBar = gtk_progress_bar_new(); gtk_box_pack_start(GTK_BOX(Box), ProgressBar, FALSE, FALSE, 5); Bouton_annuler = gtk_button_new_with_label(_("Cancel")); g_signal_connect(GTK_WIDGET(Bouton_annuler), "clicked", G_CALLBACK(close_all), NULL); gtk_container_add(GTK_CONTAINER(gtk_dialog_get_action_area(GTK_DIALOG(Window))), Bouton_annuler); g_signal_connect(GTK_WIDGET(Window), "delete_event", G_CALLBACK(close_all), NULL); gtk_window_set_default_size(GTK_WINDOW(Window), 250, 100); gtk_window_set_modal(GTK_WINDOW(Window), TRUE); gtk_widget_show_all(Window); add_input(); } else { msg = g_strdup_printf(_("Cannot read file %s: %s\n"), fileName, strerror(errno)); show_message(msg, MSG_ERR); g_free(msg); } g_free(fileName); } gtk_widget_destroy(file_select); }
static void GeanyPy_init_manager(const gchar *dir) { PyObject *module, *man, *args; gchar *sys_plugin_dir = NULL; g_return_if_fail(dir != NULL); module = PyImport_ImportModule("geany.manager"); if (module == NULL) { g_warning(_("Failed to import manager module")); return; } man = PyObject_GetAttrString(module, "PluginManager"); Py_DECREF(module); if (man == NULL) { g_warning(_("Failed to retrieve PluginManager from manager module")); return; } #ifdef GEANYPY_WINDOWS { /* Detect the system plugin's dir at runtime on Windows since we * don't really know where Geany is installed. */ gchar *geany_base_dir; geany_base_dir = g_win32_get_package_installation_directory_of_module(NULL); if (geany_base_dir) { sys_plugin_dir = g_build_filename(geany_base_dir, "lib", "geanypy", "plugins", NULL); g_free(geany_base_dir); } if (!g_file_test(sys_plugin_dir, G_FILE_TEST_EXISTS)) { g_warning(_("System plugin directory not found.")); g_free(sys_plugin_dir); sys_plugin_dir = NULL; } } #else sys_plugin_dir = g_strdup(GEANYPY_PLUGIN_DIR); #endif g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, "User plugins: %s", dir); if (sys_plugin_dir) { g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, "System plugins: %s", sys_plugin_dir); args = Py_BuildValue("([s, s])", sys_plugin_dir, dir); g_free(sys_plugin_dir); } else args = Py_BuildValue("([s])", dir); manager = PyObject_CallObject(man, args); if (PyErr_Occurred()) PyErr_Print(); Py_DECREF(man); Py_DECREF(args); if (manager == NULL) { g_warning(_("Unable to instantiate new PluginManager")); return; } }
/*! \todo Finish function description!!! * \brief * \par Function Description * * \param [in] path * \return SCM_BOOL_T on success, SCM_BOOL_F otherwise. */ SCM g_rc_source_library_search(SCM path) { gchar *string; char *temp; GDir *dir; const gchar *entry; SCM_ASSERT (scm_is_string (path), path, SCM_ARG1, "source-library-search"); /* take care of any shell variables */ temp = scm_to_utf8_string (path); string = s_expand_env_variables (temp); free (temp); /* invalid path? */ if (!g_file_test (string, G_FILE_TEST_IS_DIR)) { fprintf (stderr, "Invalid path [%s] passed to source-library-search\n", string); g_free(string); return SCM_BOOL_F; } dir = g_dir_open (string, 0, NULL); if (dir == NULL) { fprintf (stderr, "Invalid path [%s] passed to source-library-search\n", string); g_free(string); return SCM_BOOL_F; } while ((entry = g_dir_read_name (dir))) { /* don't do . and .. and special case font */ if ((g_strcasecmp (entry, ".") != 0) && (g_strcasecmp (entry, "..") != 0) && (g_strcasecmp (entry, "font") != 0)) { gchar *fullpath = g_build_filename (string, entry, NULL); if (g_file_test (fullpath, G_FILE_TEST_IS_DIR)) { if (s_slib_uniq (fullpath)) { if (g_path_is_absolute (fullpath)) { s_slib_add_entry (fullpath); } else { gchar *cwd = g_get_current_dir (); gchar *temp; temp = g_build_filename (cwd, fullpath, NULL); s_slib_add_entry (temp); g_free(temp); g_free(cwd); } } } g_free(fullpath); } } g_free(string); g_dir_close(dir); return SCM_BOOL_T; }
static void GeanyPy_start_interpreter(void) { gchar *init_code; gchar *py_dir = NULL; #ifndef GEANYPY_WINDOWS { /* Prevents a crash in the dynload thingy TODO: is this or the old dlopen version even needed? */ GModule *mod = g_module_open(GEANYPY_PYTHON_LIBRARY, G_MODULE_BIND_LAZY); if (!mod) { g_warning(_("Unable to pre-load Python library: %s."), g_module_error()); return; } g_module_close(mod); } #endif Py_Initialize(); /* Import the C modules */ initapp(); initdialogs(); initdocument(); initeditor(); initencoding(); initfiletypes(); initglog(); inithighlighting(); initmain(); initmsgwin(); initnavqueue(); initprefs(); initproject(); initscintilla(); initsearch(); inittemplates(); initui_utils(); #ifdef GEANYPY_WINDOWS { /* On windows, get path at runtime since we don't really know where * Geany is installed ahead of time. */ gchar *geany_base_dir; geany_base_dir = g_win32_get_package_installation_directory_of_module(NULL); if (geany_base_dir) { py_dir = g_build_filename(geany_base_dir, "lib", "geanypy", NULL); g_free(geany_base_dir); } if (!g_file_test(py_dir, G_FILE_TEST_EXISTS)) { g_critical("The path to the `geany' module was not found: %s", py_dir); g_free(py_dir); py_dir = g_strdup(""); /* will put current dir on path? */ } } #else py_dir = g_strdup(GEANYPY_PYTHON_DIR); #endif /* Adjust Python path to find wrapper package (geany) */ init_code = g_strdup_printf( "import os, sys\n" "path = '%s'.replace('~', os.path.expanduser('~'))\n" "sys.path.append(path)\n" "import geany\n", py_dir); g_free(py_dir); PyRun_SimpleString(init_code); g_free(init_code); }
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 ; }
int main (int argc, char *argv[]) { /* set up i18n */ bindtextdomain (PACKAGE, LOCALEDIR); setlocale (LC_ALL, ""); textdomain (PACKAGE); GError* error = NULL; GOptionContext* context = g_option_context_new ("files"); g_option_context_add_main_entries (context, entries, PACKAGE); g_option_context_parse (context, &argc, &argv, &error); if (error) g_error("%s\n", error->message); /* initialize GTK */ g_thread_init (NULL); gdk_threads_init (); gtk_init (&argc, &argv); GError* ui_error = NULL; GtkBuilder* builder = gtk_builder_new (); gchar* ui = g_build_filename (DATADIR, "ui", "gummi.glade", NULL); // exit program when gummi.glade can not be located: if (!g_file_test (ui, G_FILE_TEST_EXISTS)) { printf("Could not locate Glade interface file at:\n%s\n", ui); return 0; } gtk_builder_add_from_file (builder, ui, &ui_error); if (ui_error) { g_error ("%s\n", ui_error->message); } gtk_builder_set_translation_domain (builder, PACKAGE); g_free (ui); /* Initialize logging */ slog_init (debug); slog (L_INFO, PACKAGE_NAME" version: "PACKAGE_VERSION"\n"); /* Initialize configuration */ gchar* configname = g_build_filename (g_get_user_config_dir (), "gummi", "gummi.cfg", NULL); config_init (configname); config_load (); g_free (configname); /* Initialize signals */ gummi_signals_register (); /* Initialize Classes */ gchar* snippetsname = g_build_filename (g_get_user_config_dir (), "gummi", "snippets.cfg", NULL); // why do we not load this from environment, like gui-main does? -A GuMotion* motion = motion_init (); GuIOFunc* io = iofunctions_init(); GuLatex* latex = latex_init (); GuBiblio* biblio = biblio_init (builder); GuTemplate* templ = template_init (builder); GuTabmanager* tabm = tabmanager_init (); GuProject* proj = project_init (); GuSnippets* snippets = snippets_init (snippetsname); gummi = gummi_init (motion, io, latex, biblio, templ, snippets, tabm, proj); slog (L_DEBUG, "Gummi created!\n"); g_free (snippetsname); /* Initialize GUI */ gui = gui_init (builder); slog_set_gui_parent (gui->mainwindow); slog (L_DEBUG, "GummiGui created!\n"); /* Start compile thread */ if (external_exists (config_get_value("typesetter"))) { typesetter_setup (); motion_start_compile_thread (motion); } else { infoscreengui_enable (gui->infoscreengui, "program_error"); slog (L_ERROR, "Could not locate the typesetter program\n"); } /* Install acceleration group to mainwindow */ gtk_window_add_accel_group (gui->mainwindow, snippets->accel_group); if (argc != 2) tabmanager_create_tab (A_DEFAULT, NULL, NULL); else { if (!g_file_test(argv[1], G_FILE_TEST_EXISTS)) { slog(L_ERROR, "Failed to open file '%s': No such file or " "directory\n", argv[1]); exit(1); } tabmanager_create_tab (A_LOAD, argv[1], NULL); } if (config_get_value ("autosaving")) iofunctions_start_autosave (); gui_main (builder); config_save (); config_clean_up (); return 0; }
void dt_styles_save_to_file(const char *style_name, const char *filedir, gboolean overwrite) { int rc = 0; char stylename[520]; sqlite3_stmt *stmt; // generate filename based on name of style // convert all characters to underscore which are not allowed in filenames char *filename = g_strdup(style_name); snprintf(stylename, sizeof(stylename), "%s/%s.dtstyle", filedir, g_strdelimit(filename, "/<>:\"\\|*?[]", '_')); g_free(filename); // check if file exists if(g_file_test(stylename, G_FILE_TEST_EXISTS) == TRUE) { if(overwrite) { if(unlink(stylename)) { dt_control_log(_("failed to overwrite style file for %s"), style_name); return; } } else { dt_control_log(_("style file for %s exists"), style_name); return; } } if(!dt_styles_exists(style_name)) return; xmlTextWriterPtr writer = xmlNewTextWriterFilename(stylename, 0); if(writer == NULL) { fprintf(stderr, "[dt_styles_save_to_file] Error creating the xml writer\n, path: %s", stylename); return; } rc = xmlTextWriterStartDocument(writer, NULL, "UTF-8", NULL); if(rc < 0) { fprintf(stderr, "[dt_styles_save_to_file]: Error on encoding setting"); return; } xmlTextWriterStartElement(writer, BAD_CAST "darktable_style"); xmlTextWriterWriteAttribute(writer, BAD_CAST "version", BAD_CAST "1.0"); xmlTextWriterStartElement(writer, BAD_CAST "info"); xmlTextWriterWriteFormatElement(writer, BAD_CAST "name", "%s", style_name); xmlTextWriterWriteFormatElement(writer, BAD_CAST "description", "%s", dt_styles_get_description(style_name)); xmlTextWriterEndElement(writer); xmlTextWriterStartElement(writer, BAD_CAST "style"); DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), "select " "num,module,operation,op_params,enabled,blendop_" "params,blendop_version,multi_priority,multi_" "name from style_items where styleid =?1", -1, &stmt, NULL); DT_DEBUG_SQLITE3_BIND_INT(stmt, 1, dt_styles_get_id_by_name(style_name)); while(sqlite3_step(stmt) == SQLITE_ROW) { xmlTextWriterStartElement(writer, BAD_CAST "plugin"); xmlTextWriterWriteFormatElement(writer, BAD_CAST "num", "%d", sqlite3_column_int(stmt, 0)); xmlTextWriterWriteFormatElement(writer, BAD_CAST "module", "%d", sqlite3_column_int(stmt, 1)); xmlTextWriterWriteFormatElement(writer, BAD_CAST "operation", "%s", sqlite3_column_text(stmt, 2)); xmlTextWriterWriteFormatElement(writer, BAD_CAST "op_params", "%s", dt_style_encode(stmt, 3)); xmlTextWriterWriteFormatElement(writer, BAD_CAST "enabled", "%d", sqlite3_column_int(stmt, 4)); xmlTextWriterWriteFormatElement(writer, BAD_CAST "blendop_params", "%s", dt_style_encode(stmt, 5)); xmlTextWriterWriteFormatElement(writer, BAD_CAST "blendop_version", "%d", sqlite3_column_int(stmt, 6)); xmlTextWriterWriteFormatElement(writer, BAD_CAST "multi_priority", "%d", sqlite3_column_int(stmt, 7)); xmlTextWriterWriteFormatElement(writer, BAD_CAST "multi_name", "%s", sqlite3_column_text(stmt, 8)); xmlTextWriterEndElement(writer); } sqlite3_finalize(stmt); xmlTextWriterEndDocument(writer); xmlFreeTextWriter(writer); }
static gboolean confirm_overwrite() { GtkTreeIter iter; gboolean valid; gboolean exist = FALSE; gboolean settings_different = TRUE; Settings * user_settings; user_settings = settings_get_from_gui(); if (settings_on_execute) { settings_different = !settings_equal(user_settings, settings_on_execute); } valid = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(list_store), &iter); while (valid) { gchar *output_file; gchar *status; gboolean done; gtk_tree_model_get (GTK_TREE_MODEL(list_store), &iter, COL_OUTPUT_FILE, &output_file, COL_STATUS, &status, -1); done = strcmp("Done", status) == 0; if ((settings_different || !done) && g_file_test(output_file, G_FILE_TEST_EXISTS)) exist = TRUE; g_free(output_file); g_free(status); if (exist) break; valid = gtk_tree_model_iter_next(GTK_TREE_MODEL(list_store), &iter); } settings_delete(user_settings); if (exist) { GtkWidget * dialog_confirm_overwrite; gint result; dialog_confirm_overwrite = get_widget_checked("dialog_confirm_overwrite"); result = gtk_dialog_run( GTK_DIALOG(dialog_confirm_overwrite) ); gtk_widget_hide( dialog_confirm_overwrite ); switch (result) { default: return FALSE; case GTK_RESPONSE_OK: return TRUE; } } else { /* no need to confirm -- no overwrites */ return TRUE; } }
char *setup_testbed(const char *fkt_name) { #ifndef _WIN32 setuid(65534); #endif char *testbed = g_strdup_printf("%s/testbed.XXXXXX", g_get_tmp_dir()); char *command = NULL, *dirname = NULL; #ifdef _WIN32 if(g_file_test(testbed, G_FILE_TEST_IS_DIR)) destroy_testbed(g_strdup(testbed)); if(g_mkdir(testbed,0777) < 0){ osync_trace(TRACE_INTERNAL, "%s: Cannot create testbed directory %s", __func__, testbed); abort(); } #else /* WIN32 */ if (!mkdtemp(testbed)) abort(); #endif /* WIN32 */ if (fkt_name) { dirname = g_strdup_printf(OPENSYNC_TESTDATA"/%s", fkt_name); if (!g_file_test(dirname, G_FILE_TEST_IS_DIR)) { osync_trace(TRACE_INTERNAL, "%s: Path %s not exist.", __func__, dirname); abort(); } command = g_strdup_printf("cp -R %s/* %s", dirname, testbed); if (osync_system(command)) abort(); g_free(command); /* special handling for the git repo, since git does not * support empty directories, check for a file named * "empty_dirs" and create every subdirectory listed * there that does not begin with a slash (relative dirs only) */ { char *empty_name = NULL; FILE *fh = NULL; empty_name = g_strdup_printf("%s/empty_dirs", dirname); if ((fh = fopen(empty_name, "r"))) { char line[100], *s; while ((s = fgets(line, sizeof(line), fh))) { int len = strlen(s); /* trim newline */ if (len && s[len-1] == '\n') s[len-1] = 0; /* only create relative paths */ if (len && s[0] != '/' && s[0] != '\\' && s[0] != '#') { char *newdir = g_strdup_printf("%s/%s", testbed, s); if (newdir) { g_mkdir_with_parents(newdir, 0755); g_free(newdir); } } } fclose(fh); } g_free(empty_name); } g_free(dirname); } dirname = g_strdup_printf("%s/formats", testbed); if (!g_file_test(dirname, G_FILE_TEST_IS_DIR)) { if (g_mkdir(dirname,0777) < 0) { osync_trace(TRACE_ERROR, "Could not create format direcotry %s", dirname); abort(); } } g_free(dirname); dirname = g_strdup_printf("%s/plugins", testbed); if (!g_file_test(dirname, G_FILE_TEST_IS_DIR)) { if (g_mkdir(dirname,0777) < 0) { osync_trace(TRACE_ERROR, "Could not create plugin direcotry %s", dirname); abort(); } } g_free(dirname); command = g_strdup_printf("cp ./mock-plugin/mock-sync.%s %s/plugins", G_MODULE_SUFFIX, testbed); if (osync_system(command)) abort(); g_free(command); command = g_strdup_printf("cp ./mock-plugin/mock-format.%s %s/formats", G_MODULE_SUFFIX, testbed); if (osync_system(command)) abort(); g_free(command); command = g_strdup_printf("cp -R %s/../../misc/schemas/*.xsd %s", OPENSYNC_TESTDATA, testbed); if (osync_system(command)) abort(); g_free(command); #ifndef _WIN32 /* chmod is useless on windows system */ command = g_strdup_printf("chmod -R 700 %s", testbed); if (osync_system(command)) abort(); g_free(command); #endif olddir = g_get_current_dir(); if (g_chdir(testbed) < 0){ osync_trace(TRACE_ERROR, "Could not chdir to testbed"); abort(); } reset_counters(); osync_trace(TRACE_INTERNAL, "Seting up %s at %s", fkt_name, testbed); /* printf("."); fflush(NULL);*/ reset_env(); return testbed; }
void dt_print_file(const int32_t imgid, const char *filename, const dt_print_info_t *pinfo) { // first for safety check that filename exists and is readable if (!g_file_test(filename, G_FILE_TEST_IS_REGULAR)) { dt_control_log(_("file `%s' to print not found for image %d on `%s'"), filename, imgid, pinfo->printer.name); return; } cups_dest_t *dests; int num_dests = cupsGetDests(&dests); cups_dest_t *dest = cupsGetDest(pinfo->printer.name, NULL, num_dests, dests); cups_option_t *options = NULL; int num_options = 0; for (int j = 0; j < dest->num_options; j ++) if (cupsGetOption(dest->options[j].name, num_options, options) == NULL) num_options = cupsAddOption(dest->options[j].name, dest->options[j].value, num_options, &options); cupsFreeDests(num_dests, dests); // disable cm on CUPS, this is important as dt does the cm if (*pinfo->printer.profile) num_options = cupsAddOption("cm-calibration", "true", num_options, &options); // media to print on num_options = cupsAddOption("media", pinfo->paper.name, num_options, &options); // never print two-side num_options = cupsAddOption("sides", "one-sided", num_options, &options); // and a single image per page num_options = cupsAddOption("number-up", "1", num_options, &options); // if the printer has no hardward margins activate the borderless mode if (pinfo->printer.hw_margin_top == 0 || pinfo->printer.hw_margin_bottom == 0 || pinfo->printer.hw_margin_left == 0 || pinfo->printer.hw_margin_right == 0) { // there is many variant for this parameter num_options = cupsAddOption("StpFullBleed", "true", num_options, &options); num_options = cupsAddOption("STP_FullBleed", "true", num_options, &options); num_options = cupsAddOption("Borderless", "true", num_options, &options); } if (pinfo->page.landscape) num_options = cupsAddOption("landscape", "true", num_options, &options); else num_options = cupsAddOption("landscape", "false", num_options, &options); // print lp options dt_print(DT_DEBUG_PRINT, "[print] printer options (%d)\n", num_options); for (int k=0; k<num_options; k++) dt_print(DT_DEBUG_PRINT, "[print] %s=%s\n", options[k].name, options[k].value); const int job_id = cupsPrintFile(pinfo->printer.name, filename, "darktable", num_options, options); if (job_id == 0) dt_control_log(_("error while printing image %d on `%s'"), imgid, pinfo->printer.name); else dt_control_log(_("printing image %d on `%s'"), imgid, pinfo->printer.name); cupsFreeOptions (num_options, options); }
/** @brief Check if file or directory exists. No check for regular file! * * @param file filename or fullpath of file/directory * @returns TRUE if exists, FALSE otherwise * */ osync_bool osync_testing_file_exists(const char *file) { return g_file_test(file, G_FILE_TEST_EXISTS); }
void FilterImage::render_cairo(FilterSlot &slot) { if (!feImageHref) return; //cairo_surface_t *input = slot.getcairo(_input); // Viewport is filter primitive area (in user coordinates). // Note: viewport calculation in non-trivial. Do not rely // on get_matrix_primitiveunits2pb(). Geom::Rect vp = filter_primitive_area( slot.get_units() ); slot.set_primitive_area(_output, vp); // Needed for tiling double feImageX = vp.min()[Geom::X]; double feImageY = vp.min()[Geom::Y]; double feImageWidth = vp.width(); double feImageHeight = vp.height(); // feImage is suppose to use the same parameters as a normal SVG image. // If a width or height is set to zero, the image is not suppose to be displayed. // This does not seem to be what Firefox or Opera does, nor does the W3C displacement // filter test expect this behavior. If the width and/or height are zero, we use // the width and height of the object bounding box. Geom::Affine m = slot.get_units().get_matrix_user2filterunits().inverse(); Geom::Point bbox_00 = Geom::Point(0,0) * m; Geom::Point bbox_w0 = Geom::Point(1,0) * m; Geom::Point bbox_0h = Geom::Point(0,1) * m; double bbox_width = Geom::distance(bbox_00, bbox_w0); double bbox_height = Geom::distance(bbox_00, bbox_0h); if( feImageWidth == 0 ) feImageWidth = bbox_width; if( feImageHeight == 0 ) feImageHeight = bbox_height; // Internal image, like <use> if (from_element) { if (!SVGElem) return; // TODO: do not recreate the rendering tree every time // TODO: the entire thing is a hack, we should give filter primitives an "update" method // like the one for DrawingItems document->ensureUpToDate(); Drawing drawing; Geom::OptRect optarea = SVGElem->visualBounds(); if (!optarea) return; unsigned const key = SPItem::display_key_new(1); DrawingItem *ai = SVGElem->invoke_show(drawing, key, SP_ITEM_SHOW_DISPLAY); if (!ai) { g_warning("feImage renderer: error creating DrawingItem for SVG Element"); return; } drawing.setRoot(ai); Geom::Rect area = *optarea; Geom::Affine user2pb = slot.get_units().get_matrix_user2pb(); /* FIXME: These variables are currently unused. Why were they calculated? double scaleX = feImageWidth / area.width(); double scaleY = feImageHeight / area.height(); */ Geom::Rect sa = slot.get_slot_area(); cairo_surface_t *out = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, sa.width(), sa.height()); Inkscape::DrawingContext dc(out, sa.min()); dc.transform(user2pb); // we are now in primitive units dc.translate(feImageX, feImageY); // dc.scale(scaleX, scaleY); No scaling should be done Geom::IntRect render_rect = area.roundOutwards(); // dc.translate(render_rect.min()); This seems incorrect // Update to renderable state drawing.update(render_rect); drawing.render(dc, render_rect); SVGElem->invoke_hide(key); // For the moment, we'll assume that any image is in sRGB color space set_cairo_surface_ci(out, SP_CSS_COLOR_INTERPOLATION_SRGB); slot.set(_output, out); cairo_surface_destroy(out); return; } // External image, like <image> if (!image && !broken_ref) { broken_ref = true; /* TODO: If feImageHref is absolute, then use that (preferably handling the * case that it's not a file URI). Otherwise, go up the tree looking * for an xml:base attribute, and use that as the base URI for resolving * the relative feImageHref URI. Otherwise, if document->base is valid, * then use that as the base URI. Otherwise, use feImageHref directly * (i.e. interpreting it as relative to our current working directory). * (See http://www.w3.org/TR/xmlbase/#resolution .) */ gchar *fullname = feImageHref; if ( !g_file_test( fullname, G_FILE_TEST_EXISTS ) ) { // Try to load from relative postion combined with document base if( document ) { fullname = g_build_filename( document->getBase(), feImageHref, NULL ); } } if ( !g_file_test( fullname, G_FILE_TEST_EXISTS ) ) { // Should display Broken Image png. g_warning("FilterImage::render: Can not find: %s", feImageHref ); return; } image = Inkscape::Pixbuf::create_from_file(fullname); if( fullname != feImageHref ) g_free( fullname ); if ( !image ) { g_warning("FilterImage::render: failed to load image: %s", feImageHref); return; } broken_ref = false; } if (broken_ref) { return; } cairo_surface_t *image_surface = image->getSurfaceRaw(); Geom::Rect sa = slot.get_slot_area(); cairo_surface_t *out = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, sa.width(), sa.height()); // For the moment, we'll assume that any image is in sRGB color space // set_cairo_surface_ci(out, SP_CSS_COLOR_INTERPOLATION_SRGB); // This seemed like a sensible thing to do but it breaks filters-displace-01-f.svg cairo_t *ct = cairo_create(out); cairo_translate(ct, -sa.min()[Geom::X], -sa.min()[Geom::Y]); // now ct is in pb coordinates, note the feWidth etc. are in user units ink_cairo_transform(ct, slot.get_units().get_matrix_user2pb()); // now ct is in the coordinates of feImageX etc. // Now that we have the viewport, we must map image inside. // Partially copied from sp-image.cpp. // Do nothing if preserveAspectRatio is "none". if( aspect_align != SP_ASPECT_NONE ) { // Check aspect ratio of image vs. viewport double feAspect = feImageHeight/feImageWidth; double aspect = (double)image->height()/(double)image->width(); bool ratio = (feAspect < aspect); double ax, ay; // Align side switch( aspect_align ) { case SP_ASPECT_XMIN_YMIN: ax = 0.0; ay = 0.0; break; case SP_ASPECT_XMID_YMIN: ax = 0.5; ay = 0.0; break; case SP_ASPECT_XMAX_YMIN: ax = 1.0; ay = 0.0; break; case SP_ASPECT_XMIN_YMID: ax = 0.0; ay = 0.5; break; case SP_ASPECT_XMID_YMID: ax = 0.5; ay = 0.5; break; case SP_ASPECT_XMAX_YMID: ax = 1.0; ay = 0.5; break; case SP_ASPECT_XMIN_YMAX: ax = 0.0; ay = 1.0; break; case SP_ASPECT_XMID_YMAX: ax = 0.5; ay = 1.0; break; case SP_ASPECT_XMAX_YMAX: ax = 1.0; ay = 1.0; break; default: ax = 0.0; ay = 0.0; break; } if( aspect_clip == SP_ASPECT_SLICE ) { // image clipped by viewbox if( ratio ) { // clip top/bottom feImageY -= ay * (feImageWidth * aspect - feImageHeight); feImageHeight = feImageWidth * aspect; } else { // clip sides feImageX -= ax * (feImageHeight / aspect - feImageWidth); feImageWidth = feImageHeight / aspect; } } else { // image fits into viewbox if( ratio ) { // fit to height feImageX += ax * (feImageWidth - feImageHeight / aspect ); feImageWidth = feImageHeight / aspect; } else { // fit to width feImageY += ay * (feImageHeight - feImageWidth * aspect); feImageHeight = feImageWidth * aspect; } } } double scaleX = feImageWidth / image->width(); double scaleY = feImageHeight / image->height(); cairo_translate(ct, feImageX, feImageY); cairo_scale(ct, scaleX, scaleY); cairo_set_source_surface(ct, image_surface, 0, 0); cairo_paint(ct); cairo_destroy(ct); slot.set(_output, out); }
gboolean ots_load_xml_dictionary (OtsArticle * Doc,unsigned const char *name) { xmlDocPtr doc=NULL; xmlNodePtr head=NULL; xmlNodePtr stem=NULL; xmlNodePtr pre=NULL; xmlNodePtr post=NULL; xmlNodePtr syno=NULL; /* synonyms */ xmlNodePtr manual=NULL; /* manual */ xmlNodePtr step1_pre=NULL; /* step1 */ xmlNodePtr step1_post=NULL; /* step1 */ xmlNodePtr parse=NULL; /* parser rules */ xmlNodePtr pbreak=NULL; xmlNodePtr pdbreak=NULL; xmlNodePtr tc_words=NULL; /* term count dictionary */ xmlNodePtr tf_words=NULL; /* term frequency dictionary */ OtsStemRule * rule=Doc->stem; char *local_dict_name; local_dict_name = g_strdup_printf ("%s.xml", name); if (g_file_test(local_dict_name,G_FILE_TEST_EXISTS)) doc = xmlParseFile (local_dict_name); /* it warns to the screen so we cant use it; enable for web services only */ if (doc == NULL) return (FALSE); head = xmlDocGetRootElement (doc); if (head == NULL) { fprintf (stderr, "empty document\n"); xmlFreeDoc (doc); return (FALSE); } if (xmlStrcmp (head->name, (const xmlChar *) "dictionary")) { fprintf (stderr, "%s", head->name); xmlFreeDoc (doc); return (FALSE); } if (head != NULL) stem = head->xmlChildrenNode; while ((stem != NULL) && (xmlStrcmp (stem->name, (const xmlChar *) "stemmer"))) { stem = stem->next; } if (head != NULL) parse = head->xmlChildrenNode; while ((parse != NULL) && (xmlStrcmp (parse->name, (const xmlChar *) "parser"))) { parse = parse->next; } if (head != NULL) tc_words = head->xmlChildrenNode; while ((tc_words != NULL) && (xmlStrcmp (tc_words->name, (const xmlChar *) "grader-tc"))) { tc_words = tc_words->next; } if (head != NULL) tf_words = head->xmlChildrenNode; while ((tf_words != NULL) && (xmlStrcmp (tf_words->name, (const xmlChar *) "grader-tf"))) { tf_words = tf_words->next; } if (stem != NULL) pre = stem->xmlChildrenNode; while ((pre != NULL) && (xmlStrcmp (pre->name, (const xmlChar *) "pre"))) { pre = pre->next; } if (stem != NULL) post = stem->xmlChildrenNode; while ((post != NULL) && (xmlStrcmp (post->name, (const xmlChar *) "post"))) { post = post->next; } if (stem != NULL) syno = stem->xmlChildrenNode; while ((syno != NULL) && (xmlStrcmp (syno->name, (const xmlChar *) "synonyms"))) { syno = syno->next; } if (stem != NULL) manual = stem->xmlChildrenNode; while ((manual != NULL) && (xmlStrcmp (manual->name, (const xmlChar *) "manual"))) { manual = manual->next; } if (stem != NULL) step1_pre = stem->xmlChildrenNode; while ((step1_pre != NULL) && (xmlStrcmp (step1_pre->name, (const xmlChar *) "step1_pre"))) { step1_pre = step1_pre->next; } if (stem != NULL) step1_post = stem->xmlChildrenNode; while ((step1_post != NULL) && (xmlStrcmp (step1_post->name, (const xmlChar *) "step1_post"))) { step1_post = step1_post->next; } if (pre != NULL) pre = pre->xmlChildrenNode; /*point to first word */ while (pre != NULL) { if (0 == xmlStrcmp (pre->name, (const xmlChar *) "rule")) rule->RemovePre = g_list_append (rule->RemovePre, (xmlNodeListGetString (doc, pre->xmlChildrenNode, 1))); pre = pre->next; } if (post != NULL) post = post->xmlChildrenNode; while (post != NULL) { if (0 == xmlStrcmp (post->name, (const xmlChar *) "rule")) rule->RemovePost = g_list_append (rule->RemovePost, (xmlNodeListGetString (doc, post->xmlChildrenNode, 1))); post = post->next; } if (syno != NULL) syno = syno->xmlChildrenNode; while (syno != NULL) { if (0 == xmlStrcmp (syno->name, (const xmlChar *) "rule")) rule->synonyms = g_list_append (rule->synonyms, (xmlNodeListGetString (doc, syno->xmlChildrenNode, 1))); syno = syno->next; } if (manual != NULL) manual = manual->xmlChildrenNode; while (manual != NULL) { if (0 == xmlStrcmp (manual->name, (const xmlChar *) "rule")) rule->manual = g_list_append (rule->manual, (xmlNodeListGetString (doc, manual->xmlChildrenNode, 1))); manual = manual->next; } if (step1_pre != NULL) step1_pre = step1_pre->xmlChildrenNode; while (step1_pre != NULL) { if (0 == xmlStrcmp (step1_pre->name, (const xmlChar *) "rule")) rule->step1_pre = g_list_append (rule->step1_pre, (xmlNodeListGetString (doc, step1_pre->xmlChildrenNode, 1))); step1_pre = step1_pre->next; } if (step1_post != NULL) step1_post = step1_post->xmlChildrenNode; while (step1_post != NULL) { if (0 == xmlStrcmp (step1_post->name, (const xmlChar *) "rule")) rule->step1_post = g_list_append (rule->step1_post, (xmlNodeListGetString (doc, step1_post->xmlChildrenNode, 1))); step1_post = step1_post->next; } if (parse != NULL) pbreak = parse->xmlChildrenNode; while ((pbreak != NULL) && (xmlStrcmp (pbreak->name, (const xmlChar *) "linebreak"))) { pbreak = pbreak->next; } if (parse != NULL) pdbreak = parse->xmlChildrenNode; while ((pdbreak != NULL) && (xmlStrcmp (pdbreak->name, (const xmlChar *) "linedontbreak"))) { pdbreak = pdbreak->next; } /*Parser break*/ if (pbreak != NULL) pbreak = pbreak->xmlChildrenNode; while (pbreak != NULL) { if (0 == xmlStrcmp (pbreak->name, (const xmlChar *) "rule")) rule->ParserBreak = g_list_append (rule->ParserBreak, (xmlNodeListGetString (doc, pbreak->xmlChildrenNode, 1))); pbreak = pbreak->next; } /*Parser Don't break*/ if (pdbreak != NULL) pdbreak = pdbreak->xmlChildrenNode; while (pdbreak != NULL) { if (0 == xmlStrcmp (pdbreak->name, (const xmlChar *) "rule")) rule->ParserDontBreak = g_list_append (rule->ParserDontBreak, (xmlNodeListGetString (doc, pdbreak->xmlChildrenNode, 1))); pdbreak = pdbreak->next; } /*Term Count load dict*/ if (tc_words != NULL) tc_words = tc_words->xmlChildrenNode; while (tc_words != NULL) { if (0 == xmlStrcmp (tc_words->name, (const xmlChar *) "word")) { xmlChar *key; key=xmlNodeListGetString(doc, tc_words->xmlChildrenNode,1); Doc->dict = g_list_append (Doc->dict,(gpointer)ots_new_wordEntery(key)); xmlFree(key); } tc_words = tc_words->next; } /*Term Frequency load dict*/ if (tf_words != NULL) tf_words = tf_words->xmlChildrenNode; while (tf_words != NULL) { if (0 == xmlStrcmp (tf_words->name, (const xmlChar *) "word")) { xmlChar *key; xmlChar *idf_key; key=xmlNodeListGetString(doc, tf_words->xmlChildrenNode,1); idf_key=xmlGetProp(tf_words,"idf"); Doc->tf_terms = g_list_append (Doc->tf_terms,ots_new_OtsWordTF(key,atof(idf_key))); xmlFree(key); xmlFree(idf_key); } tf_words = tf_words->next; } xmlFreeDoc(doc); xmlCleanupParser (); g_free(local_dict_name); return (TRUE); }
static void load_single_dir (GalViewCollection *collection, char *dir, gboolean local) { xmlDoc *doc = NULL; xmlNode *root; xmlNode *child; char *filename = g_build_filename(dir, "galview.xml", NULL); char *default_view; if (g_file_test (filename, G_FILE_TEST_IS_REGULAR)) { #ifdef G_OS_WIN32 gchar *locale_filename = g_win32_locale_filename_from_utf8 (filename); if (locale_filename != NULL) doc = xmlParseFile (locale_filename); g_free (locale_filename); #else doc = xmlParseFile (filename); #endif } if (!doc) { g_free (filename); return; } root = xmlDocGetRootElement(doc); for (child = root->xmlChildrenNode; child; child = child->next) { gchar *id; gboolean found = FALSE; int i; if (!strcmp ((char *)child->name, "text")) continue; id = e_xml_get_string_prop_by_name(child, (const unsigned char *)"id"); for (i = 0; i < collection->view_count; i++) { if (!strcmp(id, collection->view_data[i]->id)) { if (!local) collection->view_data[i]->built_in = TRUE; found = TRUE; break; } } if (!found) { for (i = 0; i < collection->removed_view_count; i++) { if (!strcmp(id, collection->removed_view_data[i]->id)) { if (!local) collection->removed_view_data[i]->built_in = TRUE; found = TRUE; break; } } } if (!found) { GalViewCollectionItem *item = load_single_file (collection, dir, local, child); if (item->filename && *item->filename) { collection->view_data = g_renew(GalViewCollectionItem *, collection->view_data, collection->view_count + 1); collection->view_data[collection->view_count] = item; collection->view_count ++; } else {
void otr_on_connect(ProfAccount *account) { if (jid) { free(jid); } jid = strdup(account->jid); log_info("Loading OTR key for %s", jid); gchar *data_home = xdg_get_data_home(); GString *basedir = g_string_new(data_home); free(data_home); gchar *account_dir = str_replace(jid, "@", "_at_"); g_string_append(basedir, "/profanity/otr/"); g_string_append(basedir, account_dir); g_string_append(basedir, "/"); free(account_dir); if (!mkdir_recursive(basedir->str)) { log_error("Could not create %s for account %s.", basedir->str, jid); cons_show_error("Could not create %s for account %s.", basedir->str, jid); g_string_free(basedir, TRUE); return; } user_state = otrl_userstate_create(); gcry_error_t err = 0; GString *keysfilename = g_string_new(basedir->str); g_string_append(keysfilename, "keys.txt"); if (!g_file_test(keysfilename->str, G_FILE_TEST_IS_REGULAR)) { log_info("No OTR private key file found %s", keysfilename->str); data_loaded = FALSE; } else { log_info("Loading OTR private key %s", keysfilename->str); err = otrl_privkey_read(user_state, keysfilename->str); if (!err == GPG_ERR_NO_ERROR) { log_warning("Failed to read OTR private key file: %s", keysfilename->str); cons_show_error("Failed to read OTR private key file: %s", keysfilename->str); g_string_free(basedir, TRUE); g_string_free(keysfilename, TRUE); return; } OtrlPrivKey* privkey = otrl_privkey_find(user_state, jid, "xmpp"); if (!privkey) { log_warning("No OTR private key found for account \"%s\", protocol \"xmpp\" in file: %s", jid, keysfilename->str); cons_show_error("No OTR private key found for account \"%s\", protocol \"xmpp\" in file: %s", jid, keysfilename->str); g_string_free(basedir, TRUE); g_string_free(keysfilename, TRUE); return; } log_info("Loaded OTR private key"); data_loaded = TRUE; } GString *fpsfilename = g_string_new(basedir->str); g_string_append(fpsfilename, "fingerprints.txt"); if (!g_file_test(fpsfilename->str, G_FILE_TEST_IS_REGULAR)) { log_info("No OTR fingerprints file found %s", fpsfilename->str); data_loaded = FALSE; } else { log_info("Loading OTR fingerprints %s", fpsfilename->str); err = otrl_privkey_read_fingerprints(user_state, fpsfilename->str, NULL, NULL); if (!err == GPG_ERR_NO_ERROR) { log_error("Failed to load OTR fingerprints file: %s", fpsfilename->str); g_string_free(basedir, TRUE); g_string_free(keysfilename, TRUE); g_string_free(fpsfilename, TRUE); return; } else { log_info("Loaded OTR fingerprints"); data_loaded = TRUE; } } if (data_loaded) { cons_show("Loaded OTR private key for %s", jid); } g_string_free(basedir, TRUE); g_string_free(keysfilename, TRUE); g_string_free(fpsfilename, TRUE); return; }
sc_bool sc_fs_storage_initialize(const gchar *path, sc_bool clear) { g_message("Initialize sc-storage from path: %s", path); g_snprintf(segments_path, MAX_PATH_LENGTH, "%s/segments.scdb", path); repo_path = g_strdup(path); g_message("\tFile memory engine: %s", sc_config_fm_engine()); // load engine extension #ifdef __MINGW32__ g_snprintf(fm_engine_module_path, MAX_PATH_LENGTH, "libsc-fm-%s.dll", sc_config_fm_engine()); #elif WIN32 g_snprintf(fm_engine_module_path, MAX_PATH_LENGTH, "sc-fm-%s.dll", sc_config_fm_engine()); #else g_snprintf(fm_engine_module_path, MAX_PATH_LENGTH, "libsc-fm-%s.so", sc_config_fm_engine()); #endif // try to load engine extension fFmEngineInitFunc func; fm_engine_module = g_module_open(fm_engine_module_path, G_MODULE_BIND_LOCAL); // skip non module files if (g_str_has_suffix(fm_engine_module_path, G_MODULE_SUFFIX) == TRUE) { if (fm_engine_module == null_ptr) { g_critical("Can't load module: %s. Error: %s", fm_engine_module_path, g_module_error()); } else { g_message("Initialize file memory engine from: %s", fm_engine_module_path); if (g_module_symbol(fm_engine_module, "initialize", (gpointer*) &func) == FALSE) { g_critical("Can't find 'initialize' symbol in module: %s", fm_engine_module_path); } else { fm_engine = func(repo_path); if (fm_engine == 0) { g_critical("Can't create file memory engine from: %s", fm_engine_module_path); return SC_FALSE; } } } } // clear repository if needs if (clear == SC_TRUE) { g_message("Clear memory"); if (g_file_test(segments_path, G_FILE_TEST_IS_REGULAR) && g_remove(segments_path) != 0) g_error("Can't delete segments file: %s", segments_path); g_message("Clear file memory"); if (sc_fm_clear(fm_engine) != SC_RESULT_OK) { g_critical("Can't clear file memory"); return SC_FALSE; } } return SC_TRUE; }
static void saa_main_window_init (SaaMainWindow * w) { GtkWidget * vbox_win; // Barre de menu ---------------------------------------------------------- GtkWidget *menubar; GtkWidget *image; GtkWidget *mit_fichier; GtkWidget *mit_fichier_menu; GtkWidget *it_charger_xml; GtkWidget *it_enregistrer_xml; GtkWidget *mit_exporter; GtkWidget *mit_exporter_menu; GtkWidget *it_exporter; GtkWidget *it_exporter_rb; GtkWidget *it_sep_fichier; GtkWidget *it_quitter; GtkWidget *mit_aide; GtkWidget *mit_aide_menu; GtkWidget *it_a_propos; GtkWidget *hbox_win; GtkWidget *vbox_prop; // Onglets ---------------------------------------------------------------- GtkWidget *notebook; GtkWidget *label_page1; GtkWidget *page1; GtkWidget *f_uniform; GtkWidget *lbl_uniform; GtkWidget *f_traitement; GtkWidget *lbl_traitement; GtkWidget *label_page2; GtkWidget *page2; GtkWidget *sw; GtkWidget *label_page3; GtkWidget *page3; // Barre d'état ----------------------------------------------------------- GtkWidget *hbox_status; GtkWidget *statusbar; GtkWidget *progressbar; GtkAccelGroup *accel_group; int i; const gchar* const * dirs = g_get_system_data_dirs(); gchar * path; // TODO init_files(); saa_init_files(); g_set_application_name (PACKAGE_NAME); w->icon = NULL; for(i=0; dirs[i] && !w->icon; i++) { path = g_build_filename(dirs[i], "images", "gsolaar-logo.png", NULL); if(g_file_test(path, G_FILE_TEST_EXISTS)) { w->icon = gdk_pixbuf_new_from_file(path, NULL); gtk_window_set_default_icon (w->icon); } g_free(path); } w->visuel = saa_visuel_creer(); accel_group = gtk_accel_group_new (); gtk_window_set_title (GTK_WINDOW (w), "GSolaar"); vbox_win = gtk_vbox_new (FALSE, 0); gtk_widget_show (vbox_win); gtk_container_add (GTK_CONTAINER (w), vbox_win); menubar = gtk_menu_bar_new (); gtk_widget_show (menubar); gtk_box_pack_start (GTK_BOX (vbox_win), menubar, FALSE, FALSE, 0); mit_fichier = gtk_menu_item_new_with_mnemonic(_("_File")); gtk_widget_show (mit_fichier); gtk_container_add (GTK_CONTAINER (menubar), mit_fichier); mit_fichier_menu = gtk_menu_new (); gtk_menu_item_set_submenu (GTK_MENU_ITEM (mit_fichier), mit_fichier_menu); // Chargement ------------------------------------------------------------- it_charger_xml = gtk_image_menu_item_new_from_stock (GTK_STOCK_OPEN, accel_group); gtk_widget_show (it_charger_xml); gtk_container_add (GTK_CONTAINER (mit_fichier_menu), it_charger_xml); // Sauvegarde ------------------------------------------------------------- it_enregistrer_xml = gtk_image_menu_item_new_from_stock (GTK_STOCK_SAVE, accel_group); gtk_widget_show (it_enregistrer_xml); gtk_container_add (GTK_CONTAINER (mit_fichier_menu), it_enregistrer_xml); // Patron ----------------------------------------------------------------- mit_exporter = gtk_image_menu_item_new_with_mnemonic(_("_Export")); gtk_widget_show(mit_exporter); gtk_container_add (GTK_CONTAINER (mit_fichier_menu), mit_exporter); image = gtk_image_new_from_stock (GTK_STOCK_CONVERT, GTK_ICON_SIZE_MENU); gtk_widget_show (image); gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (mit_exporter), image); mit_exporter_menu = gtk_menu_new (); gtk_menu_item_set_submenu (GTK_MENU_ITEM (mit_exporter), mit_exporter_menu); it_exporter = gtk_image_menu_item_new_with_label (_("Pattern ...")); gtk_widget_show (it_exporter); gtk_container_add (GTK_CONTAINER (mit_exporter_menu), it_exporter); it_exporter_rb = gtk_image_menu_item_new_with_label (_("Ruby script for SketchUp ...")); gtk_widget_show (it_exporter_rb); gtk_container_add (GTK_CONTAINER (mit_exporter_menu), it_exporter_rb); //------------------------------------------------------------------------- it_sep_fichier = gtk_menu_item_new (); gtk_widget_show (it_sep_fichier); gtk_container_add (GTK_CONTAINER (mit_fichier_menu), it_sep_fichier); gtk_widget_set_sensitive (it_sep_fichier, FALSE); it_quitter = gtk_image_menu_item_new_from_stock (GTK_STOCK_QUIT, accel_group); gtk_widget_show (it_quitter); gtk_container_add (GTK_CONTAINER (mit_fichier_menu), it_quitter); mit_aide = gtk_menu_item_new_with_mnemonic ("_?"); gtk_widget_show (mit_aide); gtk_container_add (GTK_CONTAINER (menubar), mit_aide); mit_aide_menu = gtk_menu_new (); gtk_menu_item_set_submenu (GTK_MENU_ITEM (mit_aide), mit_aide_menu); it_a_propos = gtk_image_menu_item_new_from_stock ( GTK_STOCK_ABOUT, accel_group); gtk_widget_show (it_a_propos); gtk_container_add (GTK_CONTAINER (mit_aide_menu), it_a_propos); //------------------------------------------------------------------------- hbox_win = gtk_hbox_new (FALSE, 0); gtk_widget_show (hbox_win); gtk_box_pack_start (GTK_BOX (vbox_win), hbox_win, TRUE, TRUE, 0); vbox_prop = gtk_vbox_new (FALSE, 0); gtk_widget_show (vbox_prop); gtk_box_pack_start (GTK_BOX (hbox_win), vbox_prop, TRUE, TRUE, 0); gtk_widget_set_size_request (vbox_prop, 500, 400); // Drawing Area w->area = saa_drawing_area_new_with_visuel (w->visuel); gtk_widget_show (w->area); gtk_box_pack_start (GTK_BOX (vbox_prop), w->area, TRUE, TRUE, 0); gtk_widget_set_size_request (w->area, 600, 400); notebook = gtk_notebook_new(); gtk_widget_show(notebook); gtk_container_set_border_width (GTK_CONTAINER (notebook), 5); gtk_box_pack_start (GTK_BOX (hbox_win), notebook, FALSE, FALSE, 0); label_page1 = gtk_label_new (_("Polyhedron")); gtk_widget_show (label_page1); page1 = gtk_vbox_new (FALSE, 5); gtk_widget_show (page1); gtk_container_set_border_width (GTK_CONTAINER (page1), 5); gtk_notebook_append_page(GTK_NOTEBOOK(notebook), page1, label_page1); f_uniform = gtk_frame_new (NULL); gtk_widget_show (f_uniform); gtk_box_pack_start (GTK_BOX (page1), f_uniform, FALSE, FALSE, 0); gtk_container_set_border_width (GTK_CONTAINER (f_uniform), 5); gtk_frame_set_label_align (GTK_FRAME (f_uniform), 0.5, 0.5); lbl_uniform = gtk_label_new (_("Uniform polyhedra")); gtk_widget_show (lbl_uniform); gtk_frame_set_label_widget (GTK_FRAME (f_uniform), lbl_uniform); gtk_label_set_justify (GTK_LABEL (lbl_uniform), GTK_JUSTIFY_LEFT); // Solid manager w->manager = saa_solid_manager_new_with_visuel(w->visuel); gtk_widget_show(w->manager); gtk_container_add (GTK_CONTAINER (f_uniform), w->manager); f_traitement = gtk_frame_new (NULL); gtk_widget_show (f_traitement); gtk_box_pack_start (GTK_BOX (page1), f_traitement, TRUE, TRUE, 0); gtk_container_set_border_width (GTK_CONTAINER (f_traitement), 5); gtk_frame_set_label_align (GTK_FRAME (f_traitement), 0.5, 0.5); lbl_traitement = gtk_label_new (_("Treatment")); gtk_widget_show (lbl_traitement); gtk_frame_set_label_widget (GTK_FRAME (f_traitement), lbl_traitement); gtk_label_set_justify (GTK_LABEL (lbl_traitement), GTK_JUSTIFY_LEFT); // Solid Handler w->handler = saa_solid_handler_new_with_visuel(w->visuel); gtk_widget_show(w->handler); gtk_container_add (GTK_CONTAINER (f_traitement), w->handler); label_page2 = gtk_label_new (_("Navigation")); gtk_widget_show (label_page2); page2 = gtk_vbox_new (FALSE, 5); gtk_widget_show (page2); gtk_container_set_border_width (GTK_CONTAINER (page2), 5); gtk_notebook_append_page(GTK_NOTEBOOK(notebook), page2, label_page2); sw = gtk_scrolled_window_new (NULL, NULL); gtk_widget_show(sw); gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw), GTK_SHADOW_ETCHED_IN); gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); gtk_box_pack_start (GTK_BOX (page2), sw, TRUE, TRUE, 0); // Treeview navigator w->explorer = saa_tree_view_new_with_visuel(w->visuel); gtk_widget_show(w->explorer); gtk_container_add (GTK_CONTAINER (sw), w->explorer); // TODO a deplacer dans window realize saa_tree_view_update(SAA_TREE_VIEW(w->explorer)); label_page3 = gtk_label_new (_("Display")); gtk_widget_show (label_page3); page3 = gtk_vbox_new (FALSE, 5); gtk_widget_show (page3); gtk_container_set_border_width (GTK_CONTAINER (page3), 5); gtk_notebook_append_page(GTK_NOTEBOOK(notebook), page3, label_page3); // Solid display w->display = saa_solid_display_new_with_visuel(w->visuel); gtk_widget_show (w->display); gtk_box_pack_start(GTK_BOX(page3), w->display, TRUE, TRUE, 0); hbox_status = gtk_hbox_new (FALSE, 0); gtk_widget_show (hbox_status); gtk_box_pack_start (GTK_BOX (vbox_win), hbox_status, FALSE, FALSE, 0); statusbar = gtk_statusbar_new (); gtk_widget_show (statusbar); gtk_box_pack_start (GTK_BOX (hbox_status), statusbar, TRUE, TRUE, 0); progressbar = gtk_progress_bar_new (); gtk_widget_show (progressbar); gtk_box_pack_start (GTK_BOX (hbox_status), progressbar, FALSE, FALSE, 0); g_signal_connect_swapped ((gpointer)w->manager, "solid-changed", G_CALLBACK (saa_tree_view_update), w->explorer); g_signal_connect_swapped ((gpointer)w->manager, "solid-changed", G_CALLBACK (gtk_widget_queue_draw), w->area); g_signal_connect_swapped ((gpointer)w->display, "solid-changed", G_CALLBACK (gtk_widget_queue_draw), w->area); g_signal_connect_swapped ((gpointer)w->handler, "solid-changed", G_CALLBACK (saa_tree_view_update), w->explorer); g_signal_connect_swapped ((gpointer)w->handler, "solid-changed", G_CALLBACK (gtk_widget_queue_draw), w->area); g_signal_connect_swapped ((gpointer)w->area, "vertex-selected", G_CALLBACK (saa_tree_view_select_vertex), w->explorer); g_signal_connect_swapped ((gpointer)w->area, "edge-selected", G_CALLBACK (saa_tree_view_select_edge), w->explorer); g_signal_connect_swapped ((gpointer)w->area, "wing-selected", G_CALLBACK (saa_tree_view_select_wing), w->explorer); g_signal_connect_swapped ((gpointer)w->explorer, "vertex-selected", G_CALLBACK (saa_drawing_area_select_vertex), w->area); g_signal_connect_swapped ((gpointer)w->explorer, "edge-selected", G_CALLBACK (saa_drawing_area_select_edge), w->area); g_signal_connect_swapped ((gpointer)w->explorer, "wing-selected", G_CALLBACK (saa_drawing_area_select_wing), w->area); g_signal_connect_swapped((gpointer)it_charger_xml, "activate", G_CALLBACK (saa_main_window_charger_xml_clicked), w); g_signal_connect_swapped((gpointer)it_enregistrer_xml, "activate", G_CALLBACK (saa_main_window_sauver_xml_activate), w); g_signal_connect_swapped((gpointer)it_exporter, "activate", G_CALLBACK (saa_main_window_exporter_activate), w); g_signal_connect_swapped((gpointer)it_exporter_rb, "activate", G_CALLBACK (saa_main_window_exporter_rb_activate), w); g_signal_connect_swapped ((gpointer)it_quitter, "activate", G_CALLBACK (saa_main_window_quitter_activate), w); g_signal_connect (G_OBJECT(w), "destroy", G_CALLBACK (saa_main_window_quitter_activate), NULL); g_signal_connect_swapped ((gpointer)it_a_propos, "activate", G_CALLBACK (saa_main_window_a_propos_activate), w); gtk_window_add_accel_group (GTK_WINDOW (w), accel_group); }