X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=src%2Fmain.c;h=4ff98dbc132934dd90c84df332f9b73528c93bdb;hb=64fbee630efe4a6a731bcc7b68855d933946b050;hp=125ebb60901f435b521384ebab86caf3a5244c5c;hpb=5fd40eddc39c912a04cdea83b57c0655cee6bd1d;p=xournal.git diff --git a/src/main.c b/src/main.c index 125ebb6..4ff98db 100644 --- a/src/main.c +++ b/src/main.c @@ -26,20 +26,24 @@ struct BgPdf bgpdf; // the PDF loader stuff struct UIData ui; // the user interface data struct UndoItem *undo, *redo; // the undo and redo stacks +double DEFAULT_ZOOM; + void hide_unimplemented(void) { gtk_widget_hide(GET_COMPONENT("filePrintOptions")); gtk_widget_hide(GET_COMPONENT("journalFlatten")); gtk_widget_hide(GET_COMPONENT("papercolorOther")); - gtk_widget_hide(GET_COMPONENT("journalApplyAllPages")); gtk_widget_hide(GET_COMPONENT("toolsText")); gtk_widget_hide(GET_COMPONENT("buttonText")); + gtk_widget_hide(GET_COMPONENT("button2Text")); + gtk_widget_hide(GET_COMPONENT("button3Text")); gtk_widget_hide(GET_COMPONENT("toolsSelectRegion")); gtk_widget_hide(GET_COMPONENT("buttonSelectRegion")); + gtk_widget_hide(GET_COMPONENT("button2SelectRegion")); + gtk_widget_hide(GET_COMPONENT("button3SelectRegion")); gtk_widget_hide(GET_COMPONENT("colorOther")); gtk_widget_hide(GET_COMPONENT("toolsTextFont")); gtk_widget_hide(GET_COMPONENT("toolsDefaultText")); - gtk_widget_hide(GET_COMPONENT("optionsSavePreferences")); gtk_widget_hide(GET_COMPONENT("helpIndex")); } @@ -49,30 +53,30 @@ void init_stuff (int argc, char *argv[]) GList *dev_list; GdkDevice *device; GdkScreen *screen; - int i; + int i, j; struct Brush *b; - gboolean can_xinput; + gboolean can_xinput, success; + gchar *tmppath, *tmpfn; + + // create some data structures needed to populate the preferences + ui.default_page.bg = g_new(struct Background, 1); + + // initialize config file names + tmppath = g_build_filename(g_get_home_dir(), CONFIG_DIR, NULL); + mkdir(tmppath, 0700); // safer (MRU data may be confidential) + ui.mrufile = g_build_filename(tmppath, MRU_FILE, NULL); + ui.configfile = g_build_filename(tmppath, CONFIG_FILE, NULL); + g_free(tmppath); + + // initialize preferences + init_config_default(); + load_config_from_file(); // we need an empty canvas prior to creating the journal structures canvas = GNOME_CANVAS (gnome_canvas_new_aa ()); // initialize data - // TODO: load this from a preferences file - - ui.default_page.height = 792.0; - ui.default_page.width = 612.0; - ui.default_page.bg = g_new(struct Background, 1); - ui.default_page.bg->type = BG_SOLID; - ui.default_page.bg->color_no = COLOR_WHITE; - ui.default_page.bg->color_rgba = predef_bgcolors_rgba[COLOR_WHITE]; - ui.default_page.bg->ruling = RULING_LINED; ui.default_page.bg->canvas_item = NULL; - - ui.zoom = DEFAULT_ZOOM; - ui.view_continuous = TRUE; - ui.fullscreen = FALSE; - - ui.allow_xinput = TRUE; ui.layerbox_length = 0; if (argc > 2 || (argc == 2 && argv[1][0] == '-')) { @@ -84,47 +88,51 @@ void init_stuff (int argc, char *argv[]) undo = NULL; redo = NULL; journal.pages = NULL; bgpdf.status = STATUS_NOT_INIT; - - if (argc == 1) new_journal(); - else if (!open_journal(argv[1])) { - new_journal(); - w = gtk_message_dialog_new(GTK_WINDOW (winMain), GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, "Error opening file '%s'", argv[1]); - gtk_dialog_run(GTK_DIALOG(w)); - gtk_widget_destroy(w); - } + + new_journal(); ui.cur_item_type = ITEM_NONE; ui.cur_item = NULL; ui.cur_path.coords = NULL; ui.cur_path_storage_alloc = 0; ui.cur_path.ref_count = 1; - ui.toolno = TOOL_PEN; - ui.cur_brush = ui.brushes + TOOL_PEN; - ui.ruler = FALSE; + ui.selection = NULL; ui.cursor = NULL; - ui.brushes[TOOL_PEN].color_no = COLOR_BLACK; - ui.brushes[TOOL_ERASER].color_no = COLOR_WHITE; - ui.brushes[TOOL_HIGHLIGHTER].color_no = COLOR_YELLOW; - for (i=0; i < NUM_STROKE_TOOLS; i++) { - b = ui.brushes + i; - b->tool_type = i; - b->color_rgba = predef_colors_rgba[b->color_no]; - if (i == TOOL_HIGHLIGHTER) { - b->color_rgba &= HILITER_ALPHA_MASK; + ui.cur_brush = &(ui.brushes[0][ui.toolno[0]]); + for (j=0; j<=NUM_BUTTONS; j++) + for (i=0; i < NUM_STROKE_TOOLS; i++) { + b = &(ui.brushes[j][i]); + b->tool_type = i; + b->color_rgba = predef_colors_rgba[b->color_no]; + if (i == TOOL_HIGHLIGHTER) { + b->color_rgba &= HILITER_ALPHA_MASK; + } + b->thickness = predef_thickness[i][b->thickness_no]; } - b->thickness_no = THICKNESS_MEDIUM; - b->thickness = predef_thickness[i][b->thickness_no]; - b->tool_options = 0; - g_memmove(ui.default_brushes+i, ui.brushes+i, sizeof(struct Brush)); - } + for (i=0; istep_increment = 30; - gtk_layout_get_vadjustment(GTK_LAYOUT (canvas))->step_increment = 30; + gtk_layout_get_hadjustment(GTK_LAYOUT (canvas))->step_increment = ui.scrollbar_step_increment; + gtk_layout_get_vadjustment(GTK_LAYOUT (canvas))->step_increment = ui.scrollbar_step_increment; // set up the page size and canvas size update_page_stuff(); @@ -168,13 +176,11 @@ void init_stuff (int argc, char *argv[]) ui.screen_width = gdk_screen_get_width(screen); ui.screen_height = gdk_screen_get_height(screen); - ui.saved_toolno = -1; - can_xinput = FALSE; dev_list = gdk_devices_list(); while (dev_list != NULL) { device = (GdkDevice *)dev_list->data; - if (device->source == GDK_SOURCE_PEN || device->source == GDK_SOURCE_ERASER) { + if (device != gdk_device_get_core_pointer()) { /* get around a GDK bug: map the valuator range CORRECTLY to [0,1] */ #if ENABLE_XINPUT_BUGFIX gdk_device_set_axis_use(device, 0, GDK_AXIS_IGNORE); @@ -189,9 +195,6 @@ void init_stuff (int argc, char *argv[]) gtk_widget_set_sensitive(GET_COMPONENT("optionsUseXInput"), FALSE); ui.use_xinput = ui.allow_xinput && can_xinput; - ui.antialias_bg = TRUE; - ui.emulate_eraser = FALSE; - ui.progressive_bg = TRUE; gtk_check_menu_item_set_active( GTK_CHECK_MENU_ITEM(GET_COMPONENT("optionsUseXInput")), ui.use_xinput); @@ -200,12 +203,49 @@ void init_stuff (int argc, char *argv[]) gtk_check_menu_item_set_active( GTK_CHECK_MENU_ITEM(GET_COMPONENT("optionsProgressiveBG")), ui.progressive_bg); gtk_check_menu_item_set_active( - GTK_CHECK_MENU_ITEM(GET_COMPONENT("optionsEmulateEraser")), ui.emulate_eraser); + GTK_CHECK_MENU_ITEM(GET_COMPONENT("optionsPrintRuling")), ui.print_ruling); hide_unimplemented(); + + /* config file only works with glib 2.6 */ + if (glib_minor_version<6) { + gtk_widget_hide(GET_COMPONENT("optionsSavePreferences")); + } update_undo_redo_enabled(); update_copy_paste_enabled(); + update_vbox_order(ui.vertical_order[ui.fullscreen?1:0]); + + // show everything... + + gtk_widget_show (winMain); + update_cursor(); + + // load the MRU + + init_mru(); + + // and finally, open a file specified on the command line + // (moved here because display parameters weren't initialized yet...) + + if (argc == 1) return; + set_cursor_busy(TRUE); + if (g_path_is_absolute(argv[1])) + tmpfn = g_strdup(argv[1]); + else { + tmppath = g_get_current_dir(); + tmpfn = g_build_filename(tmppath, argv[1], NULL); + g_free(tmppath); + } + success = open_journal(tmpfn); + g_free(tmpfn); + set_cursor_busy(FALSE); + if (!success) { + w = gtk_message_dialog_new(GTK_WINDOW (winMain), GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, "Error opening file '%s'", argv[1]); + gtk_dialog_run(GTK_DIALOG(w)); + gtk_widget_destroy(w); + } } @@ -236,14 +276,14 @@ main (int argc, char *argv[]) winMain = create_winMain (); init_stuff (argc, argv); + gtk_window_set_icon(GTK_WINDOW(winMain), create_pixbuf("xournal.png")); - gtk_widget_show (winMain); - update_cursor(); - gtk_main (); if (bgpdf.status != STATUS_NOT_INIT) shutdown_bgpdf(); if (bgpdf.status != STATUS_NOT_INIT) end_bgpdf_shutdown(); + + save_mru_list(); return 0; }