void prefs_common_write_config(void) { GList *cur; FILE *fp; gchar *path; prefs_write_config(param, "Common", COMMON_RC); path = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, COMMAND_HISTORY, NULL); if ((fp = g_fopen(path, "wb")) == NULL) { FILE_OP_ERROR(path, "fopen"); g_free(path); return; } for (cur = prefs_common.mime_open_cmd_history; cur != NULL; cur = cur->next) { fputs((gchar *)cur->data, fp); fputc('\n', fp); } fclose(fp); g_free(path); }
int main(int argc, char **argv) { GtkWidget *info_dialog; if (argc != 1) { if (argc == 2 && !strncmp(argv[1], "-cal", 4) && strlen(argv[1]) == 4) { calendar_only = TRUE; } else { fprintf(stderr, "OSMO v%s - %s\n", VERSION, _("a handy personal organizer")); fprintf(stderr, "Copyright (c) 2007 Tomasz Maka <*****@*****.**>\n\n"); fprintf(stderr, "%s: %s [%s]\n\n", _("usage"), argv[0], _("options")); fprintf(stderr, "%s:\n", _("options")); fprintf(stderr, " -cal : %s\n", _("show small calendar window")); exit (-1); } } prefs_read_config (); gtk_init (&argc, &argv); if(check_if_app_is_running() == FALSE) { gtk_set_locale(); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); gui_create_window (); gtk_main (); prefs_write_config (); unlink(prefs_get_config_filename (RUN_FLAG_FILE)); } else { sprintf(tmpbuf, _("Another copy of OSMO is already running or it has been stopped uncleanly (in this case please remove '%s' file and try again)."), prefs_get_config_filename (RUN_FLAG_FILE)); info_dialog = gtk_message_dialog_new (GTK_WINDOW_TOPLEVEL, GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, tmpbuf); gtk_window_set_title(GTK_WINDOW(info_dialog), _("Error")); gtk_window_set_position(GTK_WINDOW(info_dialog), GTK_WIN_POS_CENTER); gtk_widget_show (info_dialog); gtk_dialog_run(GTK_DIALOG(info_dialog)); gtk_widget_destroy(info_dialog); } return 0; }
void folder_item_prefs_save_config(FolderItem * item) { gchar * id; tmp_prefs = * item->prefs; id = folder_item_get_identifier(item); if (id == NULL) return; debug_print("saving prefs for %s\n", id); prefs_write_config(param, id, FOLDERITEM_RC); g_free(id); }
static void write_config(void) { debug_print("autoenc: write_config\n"); prefs_write_config(param, "AutoEncrypt", "autoencrc"); }
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); } }
int main(int argc, char **argv) { GUI *appGUI = NULL; CALENDAR *cal = NULL; TASKS *tsk = NULL; CONTACTS *cnt = NULL; NOTES *nte = NULL; OPTIONS *opt = NULL; GtkWidget *info_dialog; gchar tmpbuf[BUFFER_SIZE]; gint response = -1; struct flock *s_lock = NULL; int fhandle; GOptionContext *cmd_context; gboolean cmd_calendar = FALSE; gboolean cmd_check_events = FALSE; gint cmd_check_ndays_events = 0; gchar *cmd_cfg_path = NULL; gboolean cmd_tiny_gui = FALSE; GOptionEntry cmd_options[] = { { "calendar", 'c', 0, G_OPTION_ARG_NONE, &cmd_calendar, N_("Show small calendar window"), NULL }, { "check", 'e', 0, G_OPTION_ARG_NONE, &cmd_check_events, N_("Check for events since last run"), NULL }, { "days", 'd', 0, G_OPTION_ARG_INT, &cmd_check_ndays_events, N_("Number of days to check forward for events (default: 0)"), NULL }, { "config", 's', 0, G_OPTION_ARG_STRING, &cmd_cfg_path, N_("Set absolute path for settings and data files"), "PATH" }, { "tinygui", 't', 0, G_OPTION_ARG_NONE, &cmd_tiny_gui, N_("Modify GUI to use Osmo on low resolutions"), NULL }, { NULL } }; appGUI = g_new0 (GUI, 1); g_return_val_if_fail (appGUI != NULL, -1); cal = g_new0 (CALENDAR, 1); g_return_val_if_fail (cal != NULL, -1); tsk = g_new0 (TASKS, 1); g_return_val_if_fail (tsk != NULL, -1); cnt = g_new0 (CONTACTS, 1); g_return_val_if_fail (cnt != NULL, -1); nte = g_new0 (NOTES, 1); g_return_val_if_fail (nte != NULL, -1); opt = g_new0 (OPTIONS, 1); g_return_val_if_fail (opt != NULL, -1); /* register modules */ appGUI->cal = cal; appGUI->tsk = tsk; appGUI->cnt = cnt; appGUI->nte = nte; appGUI->opt = opt; appGUI->run_date = utl_get_current_julian (); appGUI->run_time = get_seconds_for_today (); appGUI->key_counter = 0; /* default values */ appGUI->hovering_over_link = FALSE; appGUI->hand_cursor = NULL; appGUI->regular_cursor = NULL; appGUI->gui_url_tag = NULL; appGUI->trayicon_popup_menu = NULL; appGUI->calendar_only = FALSE; appGUI->check_events = FALSE; appGUI->tiny_gui = FALSE; appGUI->save_status = 0; appGUI->print_font_size = 10; appGUI->cal->date = g_date_new (); g_return_val_if_fail (appGUI->cal->date != NULL, -1); g_date_set_time_t (appGUI->cal->date, time (NULL)); appGUI->tsk->id_counter = 0; appGUI->tsk->tasks_panel_status = FALSE; appGUI->tsk->tasks_filter_disabled = FALSE; appGUI->tsk->tasks_list_store = NULL; appGUI->tsk->notifications = NULL; appGUI->cnt->photo_image = NULL; appGUI->cnt->contacts_uim_widget = NULL; appGUI->cnt->contacts_panel_status = FALSE; appGUI->cnt->contacts_filter_disabled = TRUE; appGUI->cnt->export_button = NULL; appGUI->cnt->output_file_entry = NULL; appGUI->opt->options_counter = 0; setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); bind_textdomain_codeset (PACKAGE, "UTF-8"); textdomain (PACKAGE); if (argc == 2 && (!strncmp(argv[1], "--help", 6) || (argv[1][0] == '-' && argv[1][1] == '?'))) { fprintf(stderr, "\nOSMO v%s - %s\n", VERSION, _("a handy personal organizer")); fprintf(stderr, "Copyright (c) 2007-2008 Tomasz Maka <*****@*****.**>\n\n"); } cmd_context = g_option_context_new(NULL); g_option_context_add_main_entries(cmd_context, cmd_options, TRANSLATION_DOMAIN); g_option_context_parse(cmd_context, &argc, &argv, NULL); g_option_context_free(cmd_context); appGUI->calendar_only = cmd_calendar; appGUI->check_events = cmd_check_events; appGUI->check_ndays_events = cmd_check_ndays_events; appGUI->config_path = cmd_cfg_path; appGUI->tiny_gui = cmd_tiny_gui; if (prefs_get_config_filename (CONFIG_FILENAME, appGUI) == NULL) { fprintf(stderr, "%s\n", _("ERROR: Cannot create config files")); goto finish; } s_lock = g_new0 (struct flock, 1); s_lock->l_type = F_WRLCK; s_lock->l_whence = SEEK_SET; s_lock->l_start = 0; s_lock->l_len = 0; prefs_read_config (appGUI); close(creat(prefs_get_config_filename (RUN_FLAG_FILE, appGUI), S_IRUSR | S_IWUSR)); /* create lock file */ gtk_init (&argc, &argv); fhandle = open(prefs_get_config_filename (RUN_FLAG_FILE, appGUI), O_RDWR); if (fhandle) { if (fcntl(fhandle, F_SETLK, s_lock) == -1) { close (fhandle); g_snprintf (tmpbuf, BUFFER_SIZE, "%s %s\n\n%s", _("Another copy of OSMO is already running."), _("Simultaneously use two or more copies of OSMO can be a cause of data loss."), _("Do you really want to continue?")); info_dialog = gtk_message_dialog_new_with_markup (GTK_WINDOW_TOPLEVEL, GTK_DIALOG_MODAL, GTK_MESSAGE_WARNING, GTK_BUTTONS_YES_NO, tmpbuf); gtk_window_set_title(GTK_WINDOW(info_dialog), _("Warning")); gtk_window_set_position(GTK_WINDOW(info_dialog), GTK_WIN_POS_CENTER); gtk_widget_show (info_dialog); response = gtk_dialog_run(GTK_DIALOG(info_dialog)); gtk_widget_destroy(info_dialog); if (response == GTK_RESPONSE_NO || response == GTK_RESPONSE_DELETE_EVENT) { goto finish; } } } notify_init("Osmo notification"); if (appGUI->calendar_only != TRUE) { /* setup timer at 1000ms (1s) interval */ g_timeout_add (1000, (GtkFunction) time_handler, appGUI); } config.run_counter++; if (gui_create_window (appGUI) == TRUE) { gtk_main (); } if (appGUI->calendar_only == FALSE) { config.lastrun_date = utl_get_current_julian (); config.lastrun_time = get_seconds_for_today(); } if (appGUI->check_events == FALSE) { prefs_write_config (appGUI); } if (fhandle) { s_lock->l_type = F_UNLCK; fcntl(fhandle, F_SETLK, s_lock); close (fhandle); } finish: g_date_free (appGUI->cal->date); g_free (opt); g_free (nte); g_free (cnt); g_free (tsk); g_free (cal); g_free (appGUI); g_free (s_lock); return 0; }
int main (int argc, char **argv) { struct timeval timer; gchar buffer[PATH_MAX]; GUI *appGUI = NULL; CHART *chr = NULL; STATISTICS *sts = NULL; TEST *tst = NULL; OPTIONS *opt = NULL; #ifdef MAEMO osso_context_t *osso_context = NULL; /* initialize maemo application */ osso_context = osso_initialize(APP_NAME, APP_VER, TRUE, NULL); if (osso_context == NULL) { fprintf (stderr, "osso_initialize failed.\n"); exit (1); } #endif appGUI = g_new0 (GUI, 1); g_return_val_if_fail (appGUI != NULL, -1); chr = g_new0 (CHART, 1); g_return_val_if_fail (chr != NULL, -1); sts = g_new0 (STATISTICS, 1); g_return_val_if_fail (sts != NULL, -1); tst = g_new0 (TEST, 1); g_return_val_if_fail (tst != NULL, -1); opt = g_new0 (OPTIONS, 1); g_return_val_if_fail (opt != NULL, -1); /* register modules */ appGUI->chr = chr; appGUI->sts = sts; appGUI->tst = tst; appGUI->opt = opt; /* default values */ appGUI->old_kana_type = -1; appGUI->chr->chart_window = NULL; appGUI->tst->any_key = FALSE; appGUI->tst->test_state = FALSE; appGUI->sts->active_tab = -1; appGUI->opt->active_tab = -1; /* preferences update */ g_snprintf (buffer, PATH_MAX, "%s%c%s", g_get_home_dir(), G_DIR_SEPARATOR, CONFIG_DIRNAME); if (g_file_test(buffer, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR) != TRUE) { prefs_read_config (CONFIG_FILENAME_OLD, CONFIG_DIRNAME_OLD); prefs_write_config (CONFIG_FILENAME, CONFIG_DIRNAME); if (g_file_test(prefs_get_config_filename (STATS_FILENAME_OLD, CONFIG_DIRNAME_OLD), G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR) == TRUE) { stats_read_list (STATS_FILENAME_OLD, CONFIG_DIRNAME_OLD, appGUI); } stats_write_list (STATS_FILENAME, CONFIG_DIRNAME, appGUI); } prefs_read_config (CONFIG_FILENAME, CONFIG_DIRNAME); stats_read_list (STATS_FILENAME, CONFIG_DIRNAME, appGUI); /* init */ #ifdef MAEMO hildon_gtk_init (&argc, &argv); #else gtk_init (&argc, &argv); #endif setlocale (LC_ALL, ""); #if defined(WIN32) || defined(WIN64) /* Set the locale directory as subdirectory of application path */ char WINLOCALEDIR[MAX_PATH]; strcpy(WINLOCALEDIR, g_path_get_dirname(argv[0])); strcat(WINLOCALEDIR, "\\share\\locale"); bindtextdomain (PACKAGE, WINLOCALEDIR); #else bindtextdomain (PACKAGE, LOCALEDIR); #endif bind_textdomain_codeset (PACKAGE, "UTF-8"); textdomain (PACKAGE); /* set seed */ gettimeofday(&timer, NULL); #if defined(WIN32) || defined(WIN64) srand((long)time(NULL)); #else srand48(timer.tv_usec + getpid()); #endif #ifdef MAEMO show_splash_screen (); #endif gui_create_window (appGUI); gtk_main (); stats_write_list (STATS_FILENAME, CONFIG_DIRNAME, appGUI); stats_free_list (appGUI); prefs_write_config (CONFIG_FILENAME, CONFIG_DIRNAME); g_free (opt); g_free (tst); g_free (sts); g_free (chr); g_free (appGUI); #ifdef MAEMO /* deinitialize OSSO */ osso_deinitialize (osso_context); #endif return 0; }