Commit 9b33052d authored by Sebastien Granjoux's avatar Sebastien Granjoux

#511589 – Anjuta uses GNOME-VFS

	* plugins/valgrind/vgdefaultview.c,
	plugins/valgrind/plugin.c,
	libanjuta/anjuta-utils.c:
	#511589 – Anjuta uses GNOME-VFS

svn path=/trunk/; revision=4458
parent 2e457703
2008-12-19 Jens Georg <jens@einstein>
reviewed by: Sébastien Granjoux <seb.sfo@free.fr>
* plugins/valgrind/vgdefaultview.c,
plugins/valgrind/plugin.c,
libanjuta/anjuta-utils.c:
#511589 – Anjuta uses GNOME-VFS
2008-12-19 Massimo Cora' <mcora@svn.gnome.org>
* plugins/symbol-db/plugin.c (value_added_current_editor):
......@@ -1077,45 +1077,74 @@ anjuta_util_escape_quotes(const gchar* str)
return buffer;
}
/* FIXME: Use gio instead */
/* Diff the text contained in uri with text. Return true if files
differ, FALSE if they are identical.
FIXME: Find a better algorithm, this seems ineffective */
differ, FALSE if they are identical.*/
gboolean anjuta_util_diff(const gchar* uri, const gchar* text)
{
GnomeVFSFileSize bytes_read;
gchar* file_text;
GnomeVFSFileInfo info;
GnomeVFSHandle* handle = NULL;
gnome_vfs_get_file_info(uri, &info, GNOME_VFS_FILE_INFO_DEFAULT);
if (info.size == 0 && text == NULL)
return FALSE;
else if (info.size == 0 || text == NULL)
GFile *file;
GFileInfo *file_info;
guint64 size;
gchar* file_text = NULL;
gsize bytes_read;
file = g_file_new_for_uri (uri);
file_info = g_file_query_info (file,
G_FILE_ATTRIBUTE_STANDARD_SIZE,
G_FILE_QUERY_INFO_NONE,
NULL,
NULL);
if (file_info == NULL)
{
g_object_unref (file);
return TRUE;
file_text = g_new0(gchar, info.size + 1);
if (gnome_vfs_open(&handle, uri, GNOME_VFS_OPEN_READ != GNOME_VFS_OK))
}
size = g_file_info_get_attribute_uint64(file_info,
G_FILE_ATTRIBUTE_STANDARD_SIZE);
g_object_unref (file_info);
if (size == 0 && text == NULL)
{
g_object_unref (file);
return FALSE;
}
else if (size == 0 || text == NULL)
{
g_object_unref (file);
return TRUE;
if ((gnome_vfs_read(handle, file_text, info.size, &bytes_read) == GNOME_VFS_OK)
&& (bytes_read == info.size))
}
if (!g_file_load_contents(file,
NULL,
&file_text,
&bytes_read,
NULL,
NULL))
{
gnome_vfs_close(handle);
if ((g_utf8_strlen(file_text, -1) == g_utf8_strlen(text, -1))
&& strcmp(file_text, text) == 0)
return FALSE;
g_object_unref (file);
return TRUE;
}
else
g_object_unref (file);
if (bytes_read != size)
{
gnome_vfs_close(handle);
g_free (file_text);
return TRUE;
}
/* according to g_file_load_contents's documentation
* file_text is guaranteed to end with \0.
*/
if (strcmp (file_text, text) == 0)
{
g_free (file_text);
return FALSE;
}
g_free (file_text);
return TRUE;
}
/**
......
......@@ -22,9 +22,7 @@
*/
#include <config.h>
#include <libgnomevfs/gnome-vfs-utils.h>
#include <glib/gi18n.h>
#include <libgnomevfs/gnome-vfs.h>
#include <libgnome/gnome-util.h>
#include <libgnomeui/gnome-about.h>
#include <libanjuta/anjuta-shell.h>
......@@ -79,7 +77,7 @@ project_root_added (AnjutaPlugin *plugin, const gchar *name,
if (root_uri)
{
gchar *root_dir = gnome_vfs_get_local_path_from_uri (root_uri);
gchar *root_dir = anjuta_util_get_local_path_from_uri (root_uri);
if (root_dir)
val_plugin->project_root_uri = g_strdup(root_dir);
else
......@@ -279,8 +277,11 @@ on_menu_run_activate (GtkAction *action, AnjutaValgrindPlugin *plugin)
gchar *program_dir;
SymTab *symtab;
VgToolView *vg_tool_view;
GFile *file;
prgname = gnome_vfs_format_uri_for_display (sel_target);
file = g_file_new_for_uri (sel_target);
prgname = g_file_get_parse_name (file);
g_object_unref (file);
DEBUG_PRINT ("target program selected is %s", prgname);
/* lets set some infos */
......@@ -348,7 +349,7 @@ on_menu_save_log_activate (GtkAction *action, AnjutaValgrindPlugin *plugin)
{
GtkWidget *dialog;
gchar* uri = NULL;
GnomeVFSURI* vfs_uri;
GFile* file;
dialog = gtk_file_chooser_dialog_new (_("Choose file where to save Valgrind log"),
NULL, GTK_FILE_CHOOSER_ACTION_SAVE, GTK_STOCK_SAVE,
......@@ -364,8 +365,8 @@ on_menu_save_log_activate (GtkAction *action, AnjutaValgrindPlugin *plugin)
gtk_widget_destroy(dialog);
vfs_uri = gnome_vfs_uri_new(uri);
if (gnome_vfs_uri_exists (vfs_uri))
file = g_file_new_for_uri (uri);
if (g_file_query_exists (file, NULL))
{
GtkWidget *dialog;
dialog = gtk_message_dialog_new (NULL,
......@@ -392,7 +393,7 @@ on_menu_save_log_activate (GtkAction *action, AnjutaValgrindPlugin *plugin)
}
g_free (uri);
g_free (vfs_uri);
g_object_unref (file);
}
static void
......
......@@ -38,7 +38,6 @@
#include <gconf/gconf-client.h>
#include <glib/gi18n.h>
#include <libgnomevfs/gnome-vfs.h>
#include <libanjuta/anjuta-debug.h>
#include <libanjuta/interfaces/ianjuta-document-manager.h>
......@@ -621,26 +620,42 @@ valgrind_view_save_log (VgToolView *tool, gchar* uri)
VgDefaultView *view = VG_DEFAULT_VIEW (tool);
VgError *err;
GString *str;
GFile *file;
GFileOutputStream *file_output_stream;
int i;
GnomeVFSHandle* handle;
if (uri == NULL)
return -1;
file = g_file_new_for_uri (uri);
file_output_stream = g_file_replace (file,
NULL, /* no etag */
FALSE, /* no backup */
G_FILE_CREATE_NONE,
NULL,
NULL);
g_object_unref (file);
/* Create file */
if (gnome_vfs_create (&handle, uri, GNOME_VFS_OPEN_WRITE, FALSE, 0664) != GNOME_VFS_OK) {
if (file_output_stream == NULL) {
return -1;
}
str = g_string_new ("");
for (i = 0; i < view->errors->len; i++) {
GnomeVFSFileSize written;
gsize written;
err = view->errors->pdata[i];
vg_error_to_string (err, str);
if (gnome_vfs_write (handle, str->str, str->len, &written) != GNOME_VFS_OK) {
written = g_output_stream_write (
G_OUTPUT_STREAM(file_output_stream),
str->str,
str->len,
NULL,
NULL);
if (written == -1) {
g_string_free (str, TRUE);
return -1;
}
......@@ -648,8 +663,8 @@ valgrind_view_save_log (VgToolView *tool, gchar* uri)
}
g_string_free (str, TRUE);
gnome_vfs_close (handle);
g_output_stream_close (G_OUTPUT_STREAM(file_output_stream),
NULL, NULL);
return 0;
}
......@@ -669,7 +684,7 @@ valgrind_view_load_log (VgToolView *tool, VgActions *actions, gchar* uri)
int fd;
gchar *filename;
filename = gnome_vfs_get_local_path_from_uri (uri);
filename = anjuta_util_get_local_path_from_uri (uri);
if ((fd = open (filename, O_RDONLY)) != -1) {
vg_tool_view_connect (tool, fd);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment