mirror of
https://github.com/Ryujinx/GtkSharp.git
synced 2024-09-16 11:34:47 +02:00
2004-12-08 Jeroen Zwartepoorte <jeroen@xs4all.nl>
* sample/Makefile.am: Readded TestVfs.cs back and make it conditional. * sample/TestVfs.cs: New sample contributed by Tamara Roberson. [Fixes #70262] svn path=/trunk/gtk-sharp/; revision=37374
This commit is contained in:
parent
f662bb93a5
commit
aca1b3ce98
@ -1,3 +1,9 @@
|
|||||||
|
2004-12-08 Jeroen Zwartepoorte <jeroen@xs4all.nl>
|
||||||
|
|
||||||
|
* sample/Makefile.am: Readded TestVfs.cs back and make it conditional.
|
||||||
|
* sample/TestVfs.cs: New sample contributed by Tamara Roberson.
|
||||||
|
[Fixes #70262]
|
||||||
|
|
||||||
2004-12-07 Mike Kestner <mkestner@novell.com>
|
2004-12-07 Mike Kestner <mkestner@novell.com>
|
||||||
|
|
||||||
* gtk/glue/style.c : add missing method and prototype. [Fixes #70216]
|
* gtk/glue/style.c : add missing method and prototype. [Fixes #70216]
|
||||||
|
@ -8,6 +8,14 @@ GNOME_TARGETS=
|
|||||||
GNOME_ASSEMBLY=
|
GNOME_ASSEMBLY=
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
if ENABLE_GNOMEVFS
|
||||||
|
GNOMEVFS_TARGETS=testvfs.exe
|
||||||
|
GNOMEVFS_ASSEMBLY=../gnomevfs/gnome-vfs-sharp.dll
|
||||||
|
else
|
||||||
|
GNOMEVFS_TARGETS=
|
||||||
|
GNOMEVFS_ASSEMBLY=
|
||||||
|
endif
|
||||||
|
|
||||||
if ENABLE_GLADE
|
if ENABLE_GLADE
|
||||||
GLADE_TARGETS=glade-viewer.exe glade-test.exe
|
GLADE_TARGETS=glade-viewer.exe glade-test.exe
|
||||||
GLADE_ASSEMBLY=../glade/glade-sharp.dll
|
GLADE_ASSEMBLY=../glade/glade-sharp.dll
|
||||||
@ -24,9 +32,9 @@ VTE_TARGETS=
|
|||||||
VTE_ASSEMBLY=
|
VTE_ASSEMBLY=
|
||||||
endif
|
endif
|
||||||
|
|
||||||
TARGETS = custom-notebook.exe drawing-sample.exe custom-widget.exe custom-cellrenderer.exe gtk-hello-world.exe button.exe calendar.exe subclass.exe menu.exe size.exe scribble.exe scribble-xinput.exe treeviewdemo.exe managedtreeviewdemo.exe testdnd.exe actions.exe $(GNOME_TARGETS) $(GLADE_TARGETS) $(VTE_TARGETS)
|
TARGETS = custom-notebook.exe drawing-sample.exe custom-widget.exe custom-cellrenderer.exe gtk-hello-world.exe button.exe calendar.exe subclass.exe menu.exe size.exe scribble.exe scribble-xinput.exe treeviewdemo.exe managedtreeviewdemo.exe testdnd.exe actions.exe $(GNOMEVFS_TARGETS) $(GNOME_TARGETS) $(GLADE_TARGETS) $(VTE_TARGETS)
|
||||||
|
|
||||||
assemblies=../glib/glib-sharp.dll ../pango/pango-sharp.dll ../atk/atk-sharp.dll ../gdk/gdk-sharp.dll ../gtk/gtk-sharp.dll ../gnomevfs/gnome-vfs-sharp.dll $(GNOME_ASSEMBLY) $(GLADE_ASSEMBLY) $(VTE_ASSEMBLY)
|
assemblies=../glib/glib-sharp.dll ../pango/pango-sharp.dll ../atk/atk-sharp.dll ../gdk/gdk-sharp.dll ../gtk/gtk-sharp.dll $(GNOMEVFS_ASSEMBLY) $(GNOME_ASSEMBLY) $(GLADE_ASSEMBLY) $(VTE_ASSEMBLY)
|
||||||
references=$(addprefix /r:, $(assemblies))
|
references=$(addprefix /r:, $(assemblies))
|
||||||
|
|
||||||
noinst_SCRIPTS = $(TARGETS)
|
noinst_SCRIPTS = $(TARGETS)
|
||||||
@ -104,7 +112,7 @@ actions.exe: $(srcdir)/Actions.cs
|
|||||||
custom-notebook.exe: $(srcdir)/CustomNotebook.cs $(assemblies)
|
custom-notebook.exe: $(srcdir)/CustomNotebook.cs $(assemblies)
|
||||||
$(CSC) /debug /out:custom-notebook.exe $(references) $(srcdir)/CustomNotebook.cs
|
$(CSC) /debug /out:custom-notebook.exe $(references) $(srcdir)/CustomNotebook.cs
|
||||||
|
|
||||||
testvfs.exe: $(srcdir)/TestVfs.cs
|
testvfs.exe: $(srcdir)/TestVfs.cs $(assemblies)
|
||||||
$(CSC) /debug /out:testvfs.exe $(references) $(srcdir)/TestVfs.cs
|
$(CSC) /debug /out:testvfs.exe $(references) $(srcdir)/TestVfs.cs
|
||||||
|
|
||||||
EXTRA_DIST = \
|
EXTRA_DIST = \
|
||||||
|
@ -1,114 +1,211 @@
|
|||||||
//
|
//
|
||||||
// TestVfs.cs: Test gnome-vfs bindings.
|
// TestVfs.cs: Test for Gnome.Vfs bindings.
|
||||||
//
|
//
|
||||||
// Author:
|
// Author:
|
||||||
// Jeroen Zwartepoorte <jeroen@xs4all.nl>
|
// Tamara Roberson (foxxygirltamara@gmail.com)
|
||||||
//
|
//
|
||||||
// (C) Copyright Jeroen Zwartepoorte 2004
|
// (C) 2004 Tamara Roberson
|
||||||
//
|
//
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using GLib;
|
using System.IO;
|
||||||
using Gtk;
|
|
||||||
using Gnome.Vfs;
|
|
||||||
|
|
||||||
public class TestVfs {
|
class FileDialog : Gtk.FileChooserDialog {
|
||||||
static void Main (string[] args)
|
|
||||||
{
|
|
||||||
Application.Init ();
|
|
||||||
|
|
||||||
FileChooserDialog fcd = new FileChooserDialog ("Open File",
|
|
||||||
new Window ("test"),
|
|
||||||
FileChooserAction.Open,
|
|
||||||
"gnome-vfs");
|
|
||||||
fcd.LocalOnly = false;
|
|
||||||
fcd.AddButton (Stock.Cancel, ResponseType.Cancel);
|
|
||||||
fcd.AddButton (Stock.Open, ResponseType.Ok);
|
|
||||||
fcd.DefaultResponse = ResponseType.Ok;
|
|
||||||
int resp = fcd.Run ();
|
|
||||||
fcd.Hide ();
|
|
||||||
|
|
||||||
if (resp != (int)ResponseType.Ok)
|
|
||||||
return;
|
|
||||||
|
|
||||||
Console.WriteLine ("Selected uri = {0}", fcd.Uri);
|
public FileDialog (string title, Gtk.FileChooserAction action)
|
||||||
string mimetype = Mime.GetMimeType (fcd.Uri);
|
: base (title, null, action, "gnome-vfs")
|
||||||
Console.WriteLine ("Mimetype = {0}", mimetype);
|
{
|
||||||
|
this.LocalOnly = false;
|
||||||
|
|
||||||
FileInfoOptions options = FileInfoOptions.Default;
|
this.AddButton (Gtk.Stock.Cancel, Gtk.ResponseType.Cancel);
|
||||||
Gnome.Vfs.FileInfo info = new Gnome.Vfs.FileInfo (fcd.Uri, options);
|
this.AddButton (Gtk.Stock.Open, Gtk.ResponseType.Ok);
|
||||||
Console.WriteLine ("isLocal = " + info.IsLocal);
|
|
||||||
|
|
||||||
#if false
|
this.DefaultResponse = Gtk.ResponseType.Ok;
|
||||||
Gnome.Vfs.Uri uri = new Gnome.Vfs.Uri (fcd.Uri);
|
}
|
||||||
Console.WriteLine (uri.ToString ());
|
|
||||||
|
|
||||||
VfsStream vs = new VfsStream (fcd.Uri, FileMode.OpenOrCreate);
|
|
||||||
UTF8Encoding utf8 = new UTF8Encoding ();
|
|
||||||
byte[] buf = utf8.GetBytes ("Testing 1 2 3, asdjfaskjdhfkajshdf");
|
|
||||||
vs.Write (buf, 0, buf.Length);
|
|
||||||
/*for (int i = 0; i < 200; i++) {
|
|
||||||
int c = vs.ReadByte ();
|
|
||||||
if (c == -1) {
|
|
||||||
Console.WriteLine ("EOF");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
Console.Write ((char)c);
|
|
||||||
}*/
|
|
||||||
vs.Close ();
|
|
||||||
|
|
||||||
//Handle handle = Vfs.Open (fcd.Uri, OpenMode.Read);
|
|
||||||
|
|
||||||
//Vfs.OpenAsync (fcd.Uri, OpenMode.Read, 0, new Gnome.Vfs.AsyncCallback (open_cb));
|
|
||||||
|
|
||||||
/*FilePermission perms = FilePermission.UserRead |
|
|
||||||
FilePermission.UserWrite |
|
|
||||||
FilePermission.GroupRead |
|
|
||||||
FilePermission.OtherRead;
|
|
||||||
Vfs.CreateAsync ("file:///home/jeroen/test.txt", OpenMode.Write,
|
|
||||||
false, perms, 0, new Gnome.Vfs.AsyncCallback (create_cb));*/
|
|
||||||
#endif
|
|
||||||
Application.Run ();
|
|
||||||
}
|
|
||||||
|
|
||||||
static void open_cb (Handle handle, Result result)
|
|
||||||
{
|
|
||||||
Console.WriteLine ("OpenAsync result = {0} ({1})", Vfs.ResultToString (result), result);
|
|
||||||
|
|
||||||
byte[] buffer = new byte[128];
|
public Gnome.Vfs.Uri GetUri ()
|
||||||
Vfs.ReadAsync (handle, out buffer[0], 128, new AsyncReadCallback (read_cb));
|
{
|
||||||
}
|
int resp = this.Run ();
|
||||||
|
|
||||||
static void read_cb (Handle handle, Result result, byte[] buffer, ulong bytes_requested, ulong bytes_read)
|
this.Hide ();
|
||||||
{
|
|
||||||
Console.WriteLine ("ReadAsync result = {0} ({1})", Vfs.ResultToString (result), result);
|
if (resp != (int) Gtk.ResponseType.Ok)
|
||||||
|
throw new Exception ("No File Selected.");
|
||||||
|
|
||||||
if (result == Result.Ok) {
|
return new Gnome.Vfs.Uri (this.Uri);
|
||||||
Console.WriteLine ("bytes_requested = {0}", bytes_requested);
|
}
|
||||||
Console.WriteLine ("bytes_read = {0}", bytes_read);
|
|
||||||
/*Console.WriteLine ("bytes = ");
|
|
||||||
for (int i = 0; i < (int)bytes_read; i++)
|
public static Gnome.Vfs.Uri OpenFile (string title)
|
||||||
Console.Write ("" + (char)buffer[i]);*/
|
{
|
||||||
|
FileDialog fd = new FileDialog (title, Gtk.FileChooserAction.Open);
|
||||||
byte[] buf = new byte[128];
|
return fd.GetUri ();
|
||||||
Vfs.ReadAsync (handle, out buf[0], 128, new AsyncReadCallback (read_cb));
|
}
|
||||||
}
|
|
||||||
}
|
public static Gnome.Vfs.Uri SaveFile(string title)
|
||||||
|
{
|
||||||
static void create_cb (Handle handle, Result result)
|
FileDialog fd = new FileDialog (title, Gtk.FileChooserAction.Save);
|
||||||
{
|
return fd.GetUri ();
|
||||||
Console.WriteLine ("CreateAsync result = {0} ({1})", Vfs.ResultToString (result), result);
|
}
|
||||||
|
}
|
||||||
if (result == Result.Ok) {
|
|
||||||
UTF8Encoding utf8 = new UTF8Encoding ();
|
|
||||||
byte[] buffer = utf8.GetBytes ("Testing 1 2 3 asdlfjalsjdfksjdf \nGustavo Giráldez\n");
|
public class TestVfs
|
||||||
Vfs.WriteAsync (handle, out buffer[0], (uint)buffer.Length, new AsyncWriteCallback (write_cb));
|
{
|
||||||
}
|
public TestVfs ()
|
||||||
}
|
{
|
||||||
|
ShowFileInfo ();
|
||||||
static void write_cb (Handle handle, Result result, byte[] buffer, ulong bytes_requested, ulong bytes_written)
|
WriteFile ();
|
||||||
{
|
ReadFile ();
|
||||||
Console.WriteLine ("WriteAsync result = {0} ({1})", Vfs.ResultToString (result), result);
|
OpenAsync ();
|
||||||
}
|
CreateAsync ();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void ShowFileInfo()
|
||||||
|
{
|
||||||
|
// Ask for a file
|
||||||
|
Gnome.Vfs.Uri uri = FileDialog.OpenFile ("Show File Info");
|
||||||
|
Console.WriteLine ("Selected uri\t= {0}", uri.ToString ());
|
||||||
|
|
||||||
|
// MimeType
|
||||||
|
string mimeType = Gnome.Vfs.MimeType.GetMimeTypeForUri (uri.ToString ());
|
||||||
|
Console.WriteLine ("Mimetype\t= {0}", mimeType);
|
||||||
|
|
||||||
|
// IsLocal
|
||||||
|
Gnome.Vfs.FileInfoOptions options = Gnome.Vfs.FileInfoOptions.Default;
|
||||||
|
Gnome.Vfs.FileInfo info = new Gnome.Vfs.FileInfo (uri.ToString (), options);
|
||||||
|
|
||||||
|
Console.WriteLine ("IsLocal\t\t= {0}", info.IsLocal);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void WriteFile ()
|
||||||
|
{
|
||||||
|
// Ask for a file
|
||||||
|
Gnome.Vfs.Uri uri = FileDialog.SaveFile ("Write to File");
|
||||||
|
|
||||||
|
// Create Stream
|
||||||
|
Gnome.Vfs.VfsStream vs = new Gnome.Vfs.VfsStream (uri.ToString (), FileMode.CreateNew);
|
||||||
|
|
||||||
|
// Write to the file
|
||||||
|
UTF8Encoding utf8 = new UTF8Encoding ();
|
||||||
|
byte [] buf = utf8.GetBytes ("Testing 1 2 3, asdjfaskjdhfkajshdf");
|
||||||
|
vs.Write (buf, 0, buf.Length);
|
||||||
|
|
||||||
|
// Close the file
|
||||||
|
vs.Close();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ReadFile()
|
||||||
|
{
|
||||||
|
// Ask for a file
|
||||||
|
Gnome.Vfs.Uri uri = FileDialog.OpenFile ("Read File");
|
||||||
|
|
||||||
|
// Create Stream
|
||||||
|
Gnome.Vfs.VfsStream vs = new Gnome.Vfs.VfsStream (uri.ToString (), FileMode.Open);
|
||||||
|
|
||||||
|
// Read File byte by byte
|
||||||
|
while (true) {
|
||||||
|
int c = vs.ReadByte ();
|
||||||
|
|
||||||
|
if (c < 0) {
|
||||||
|
Console.WriteLine ("EOF");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
Console.Write ((char) c);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Close File
|
||||||
|
vs.Close ();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OpenAsync ()
|
||||||
|
{
|
||||||
|
// Ask for a file
|
||||||
|
Gnome.Vfs.Uri uri = FileDialog.OpenFile ("Open File Asynchronously");
|
||||||
|
|
||||||
|
// Open the file Asynchronously
|
||||||
|
Gnome.Vfs.AsyncCallback openCallback = new Gnome.Vfs.AsyncCallback (OnUriOpen);
|
||||||
|
Gnome.Vfs.Async.Open (uri.ToString (), Gnome.Vfs.OpenMode.Read, 0, openCallback);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void CreateAsync ()
|
||||||
|
{
|
||||||
|
// Ask for a file
|
||||||
|
Gnome.Vfs.Uri uri = FileDialog.SaveFile ("Create File Asynchronously");
|
||||||
|
|
||||||
|
// Create a file Asynchronously
|
||||||
|
Gnome.Vfs.FilePermissions perms =
|
||||||
|
Gnome.Vfs.FilePermissions.UserRead |
|
||||||
|
Gnome.Vfs.FilePermissions.UserWrite |
|
||||||
|
Gnome.Vfs.FilePermissions.GroupRead |
|
||||||
|
Gnome.Vfs.FilePermissions.OtherRead;
|
||||||
|
|
||||||
|
Gnome.Vfs.AsyncCallback createCallback = new Gnome.Vfs.AsyncCallback (OnUriCreate);
|
||||||
|
Gnome.Vfs.Async.Create (uri, Gnome.Vfs.OpenMode.Write, false, perms, 0, createCallback);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void OnUriOpen (Gnome.Vfs.Handle handle, Gnome.Vfs.Result result)
|
||||||
|
{
|
||||||
|
Console.WriteLine ("Async.Open result\t= {0} ({1})", Gnome.Vfs.Vfs.ResultToString (result), result);
|
||||||
|
|
||||||
|
Gnome.Vfs.AsyncReadCallback readCallback = new Gnome.Vfs.AsyncReadCallback (OnUriRead);
|
||||||
|
|
||||||
|
byte [] buffer = new byte [128];
|
||||||
|
Gnome.Vfs.Async.Read (handle, out buffer [0], 128, readCallback);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void OnUriRead (Gnome.Vfs.Handle handle, Gnome.Vfs.Result result,
|
||||||
|
byte [] buffer, ulong bytesRequested, ulong bytesRead)
|
||||||
|
{
|
||||||
|
Console.WriteLine ("Async.Read result\t= {0} ({1})", Gnome.Vfs.Vfs.ResultToString(result), result);
|
||||||
|
|
||||||
|
if (result != Gnome.Vfs.Result.Ok)
|
||||||
|
return;
|
||||||
|
|
||||||
|
Console.WriteLine ("bytesRequested\t\t= {0}", bytesRequested);
|
||||||
|
Console.WriteLine ("bytesRead\t\t= {0}", bytesRead);
|
||||||
|
|
||||||
|
Console.Write("bytes\t\t\t= ");
|
||||||
|
for (int i = 0; i < (int) bytesRead; i++)
|
||||||
|
Console.Write ((char) buffer [i]);
|
||||||
|
Console.WriteLine ();
|
||||||
|
|
||||||
|
Gnome.Vfs.AsyncReadCallback readCallback = new Gnome.Vfs.AsyncReadCallback (OnUriRead);
|
||||||
|
|
||||||
|
byte [] buf = new byte [128];
|
||||||
|
Gnome.Vfs.Async.Read (handle, out buf [0], 128, readCallback);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OnUriCreate (Gnome.Vfs.Handle handle, Gnome.Vfs.Result result)
|
||||||
|
{
|
||||||
|
Console.WriteLine ("Async.Create result\t= {0} ({1})", Gnome.Vfs.Vfs.ResultToString (result), result);
|
||||||
|
|
||||||
|
if (result != Gnome.Vfs.Result.Ok)
|
||||||
|
return;
|
||||||
|
UTF8Encoding utf8 = new UTF8Encoding ();
|
||||||
|
byte [] buffer = utf8.GetBytes ("Testing 1 2 3 asdlfjalsjdfksjdf \nGustavo Giráldez\n");
|
||||||
|
Gnome.Vfs.AsyncWriteCallback writeCallback = new Gnome.Vfs.AsyncWriteCallback (OnUriWrite);
|
||||||
|
Gnome.Vfs.Async.Write (handle, out buffer [0], (uint) buffer.Length, writeCallback);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void OnUriWrite (Gnome.Vfs.Handle handle, Gnome.Vfs.Result result,
|
||||||
|
byte [] buffer, ulong bytesRequested, ulong bytesWritten)
|
||||||
|
{
|
||||||
|
Console.WriteLine ("Async.Write result\t= {0} ({1})", Gnome.Vfs.Vfs.ResultToString (result), result);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void Main (string [] args)
|
||||||
|
{
|
||||||
|
// Initialize Gtk
|
||||||
|
Gtk.Application.Init ();
|
||||||
|
|
||||||
|
new TestVfs ();
|
||||||
|
|
||||||
|
// Run!
|
||||||
|
Gtk.Application.Run ();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user