/* * The main file opening function. Checks that the file isn't already open, * and if not, opens it in a new tab. */ gboolean gtr_open (GFile * location, GtrWindow * window, GError ** error) { GtrHeader *header; GtrPo *po; GtrTab *tab; GList *current; GtrView *active_view; const gchar *project_id; /* * If the filename can't be opened, pass the error back to the caller * to handle. */ po = gtr_po_new (); gtr_po_parse (po, location, error); if ((*error != NULL) && (((GError *) * error)->code != GTR_PO_ERROR_RECOVERY)) return FALSE; header = gtr_po_get_header (po); project_id = gtr_header_get_prj_id_version (header); /* * If not a crash/temporary file, add to the history. */ _gtr_recent_add (window, location, (gchar *)project_id); /* * Create a page to add to our list of open files */ tab = gtr_window_create_tab (window, po); gtr_window_set_active_tab (window, GTK_WIDGET (tab)); /* * Show the current message. */ current = gtr_po_get_current_message (po); gtr_tab_message_go_to (tab, current->data, FALSE, GTR_TAB_MOVE_NONE); /* * Grab the focus */ active_view = gtr_tab_get_active_view (tab); gtk_widget_grab_focus (GTK_WIDGET (active_view)); gtr_statusbar_update_progress_bar (GTR_STATUSBAR (gtr_window_get_statusbar (window)), (gdouble) gtr_po_get_translated_count (po), (gdouble) gtr_po_get_messages_count (po)); return TRUE; }
/** * gtr_po_save_file: * @po: a #GtrPo * @error: a GError to manage the exceptions * * It saves the po file and if there are any problem it stores the error * in @error. **/ void gtr_po_save_file (GtrPo * po, GError ** error) { struct po_xerror_handler handler; gchar *filename; gchar *msg_error; GtrHeader *header; GtrPoPrivate *priv = gtr_po_get_instance_private (po); /* * Initialice the handler error. */ handler.xerror = &on_gettext_po_xerror; handler.xerror2 = &on_gettext_po_xerror2; filename = g_file_get_path (priv->location); if (g_str_has_suffix (filename, ".pot")) { // Remove suffix filename[strlen (filename) - 4] = '\0'; g_set_error (error, GTR_PO_ERROR, GTR_PO_ERROR_FILENAME, _("You are saving a file with a .pot extension.\n" "Pot files are generated by the compilation process.\n" "Your file should likely be named “%s.po”."), filename); g_free (filename); return; } if (is_read_only (filename)) { g_set_error (error, GTR_PO_ERROR, GTR_PO_ERROR_READONLY, _("The file %s is read-only, and can not be overwritten"), filename); g_free (filename); return; } /* Save header fields into msg */ header = gtr_po_get_header (po); gtr_header_update_header (header); /* * Check if the file is right */ msg_error = gtr_po_check_po_file (po); if (msg_error != NULL) { g_set_error (error, GTR_PO_ERROR, GTR_PO_ERROR_GETTEXT, _("There is an error in the PO file: %s"), msg_error); g_free (msg_error); g_free (filename); return; } if (!po_file_write (gtr_po_get_po_file (po), filename, &handler)) { g_set_error (error, GTR_PO_ERROR, GTR_PO_ERROR_FILENAME, _("There was an error writing the PO file: %s"), message_error); g_free (message_error); g_free (filename); return; } g_free (filename); /* If we are here everything is ok and we can set the state as saved */ gtr_po_set_state (po, GTR_PO_STATE_SAVED); /* * If the warn if fuzzy option is enabled we have to show an error */ /*if (gtr_prefs_manager_get_warn_if_fuzzy () && priv->fuzzy) { g_set_error (error, GTR_PO_ERROR, GTR_PO_ERROR_OTHER, ngettext ("File %s\ncontains %d fuzzy message", "File %s\ncontains %d fuzzy messages", priv->fuzzy), priv->fuzzy); } */ }