Re: [Vala] Emendo text editor

2013-09-24 Thread simargl
On Mon, Sep 23, 2013 at 8:15 PM, simargl arch...@gmail.com wrote:

 Hi,

 Emendo is a simple text editor with syntax highlighting written in Vala,
 using Gtk+3 and Gtksourceview. If someone is interested source tarball can
 be found here:http://alphaos.tuxfamily.org/forum/viewtopic.php?f=8t=702#p1151

 Presenting this text editor to you is one thing, but more important there
 are two known bugs I am still not able to solve:

 First, before closing program from toolbar or with Ctrl+Q, there is
 source_buffer_check method called (line 700) from action_quit (line 573)
 method, that offers to save changes if source buffer is modified. That
 works fine if program is closing from toolbar button or Ctrl+Q, but when X
 in titlebar is clicked, program first closes then shows that dialog box and
 offers to save changes.

 Second, replace_all method (line 545) works OK, but it is not undoable,
 when undo button from toolbar is clicked, everything from sourcebuffer gets
 deleted.

 Thank you for any help.


Solved not undoable replace_all with adding two lines:

source_buffer.begin_user_action();

and

source_buffer.end_user_action();

..
private void replace_all()
{
  string search_string = replace_search_entry.text;
  string replace_string = replace_entry.text;
  Gtk.TextSearchFlags flags = Gtk.TextSearchFlags.TEXT_ONLY;
  Gtk.TextIter start_iter, match_start, match_end;
  source_buffer.get_start_iter (out start_iter);
  while (start_iter.forward_search (search_string, flags, out
match_start, out match_end, null))
  {
source_buffer.begin_user_action();
source_buffer.@delete (ref match_start, ref match_end);
source_buffer.insert (ref match_start, replace_string,
replace_string.length);
start_iter = match_start;
source_view.scroll_to_iter (start_iter, 0.10, false, 0, 0);
source_buffer.end_user_action();
  }
}

___
vala-list mailing list
vala-list@gnome.org
https://mail.gnome.org/mailman/listinfo/vala-list


[Vala] Soup.Buffer memory

2013-09-24 Thread andrea zambon
I am developing a service http with libsoup, but I have a memory problem.
When you make a request, the service memory increases during transmission
and decreases only after the closure of the service. Another call and will
increase again.
The client is in another machine and the data may be very long (2 GB).
I try to user Soup.MemoryUse.TAKE but I get garbage data.
The Soup.Buffer is not free when sending a new buffer?

Thank you for suggestion.



public static int main(string[] args)
{
Soup.Server server = new Soup.Server (Soup.SERVER_PORT, 12345);
server.add_handler (/data, default_handler);
server.run();
return 0;
}

void default_handler (Soup.Server server, Soup.Message msg, string path,
GLib.HashTable? query, Soup.ClientContext client) {

r = new Reader();

msg.response_headers.set_encoding(Soup.Encoding.EOF);
msg.response_headers.append(Content-Type, text/html );
msg.set_status(Soup.KnownStatusCode.OK);

if (msg.method == GET) {
msg.wrote_headers.connect(write_next_chunk);
msg.wrote_chunk.connect(write_next_chunk);
}
}

public void write_next_chunk(Soup.Message msg){
Soup.Buffer b = r.GetBuffer();
msg.response_body.append_buffer (b);
}


Reader r;

public class Reader {

public Soup.Buffer GetBuffer() {
uint8[] b = {'a','b','c','d','e','f','g','h','i','l' };
return new Soup.Buffer(Soup.MemoryUse.COPY, s.data);
}
}
___
vala-list mailing list
vala-list@gnome.org
https://mail.gnome.org/mailman/listinfo/vala-list


[Vala] How to convert a string to float ?

2013-09-24 Thread raum
Hello,

Just as I said in subject of this mail, I'm trying to convert a string
into a float.

To convert a string to int : int.parse
ok, easy...

Float... ehm.. no atof function, I've seen a lot of things about Value
so I've tried and I've got  GLib-GObject-CRITICAL **:
g_value_set_***...

So how can I convert ?

Sample code :
Value val = Value (typeof (double));
val.set_string(3.4);   //  error
stdout.printf (get_double()\n);
stdout.printf (%f\n, val.get_double());
stdout.printf (get_string()\n);
stdout.printf (%s\n, val.get_string()); // -- error

Value val2 = Value (typeof (string));
val2.set_string(3.4);
stdout.printf (get_double()\n);
stdout.printf (%f\n, val2.get_double()); // -- error
stdout.printf (get_string()\n);
stdout.printf (%s\n, val2.get_string());

OUTPUT :
---
(spawn.exe:4056): GLib-GObject-CRITICAL **: g_value_set_string: assertion
`G_VALUE_HOLDS_STRING (value)' failed
get_double()
0.00
get_string()

(spawn.exe:4056): GLib-GObject-CRITICAL **: g_value_get_string: assertion
`G_VALUE_HOLDS_STRING (value)' failed
(null)
get_double()

(spawn.exe:4056): GLib-GObject-CRITICAL **: g_value_get_double: assertion
`G_VALUE_HOLDS_DOUBLE (value)' failed
0.00
get_string()
3.4
---


Thanks

Regards

Raum
___
vala-list mailing list
vala-list@gnome.org
https://mail.gnome.org/mailman/listinfo/vala-list


Re: [Vala] How to convert a string to float ?

2013-09-24 Thread Al Thomas






 From: r...@no-log.org r...@no-log.org
To: vala-list@gnome.org 
Sent: Tuesday, 24 September 2013, 13:36
Subject: [Vala] How to convert a string to float ?
 

To convert a string to int : int.parse
ok, easy...

Try double.parse()

For more see https://wiki.gnome.org/Vala/Tutorial#Strings

Al
___
vala-list mailing list
vala-list@gnome.org
https://mail.gnome.org/mailman/listinfo/vala-list


[Vala] Extra documentation for vapis on Valadoc

2013-09-24 Thread Steven Oliver
I was looking through Valadoc.org today and came across this entry:

http://valadoc.org/#!api=glib-2.0/GLib.Markup.printf_escaped

My question is how did the extra documentation get there? I looked in the
Glib-2.0 vapi but there's nothing extra there.

https://git.gnome.org/browse/vala/tree/vapi/glib-2.0.vapi#n3553

Steven N. Oliver
___
vala-list mailing list
vala-list@gnome.org
https://mail.gnome.org/mailman/listinfo/vala-list


[Vala] Fw: Extra documentation for vapis on Valadoc

2013-09-24 Thread Al Thomas


From: Steven Oliver oliver.ste...@gmail.com
To: vala-list vala-list@gnome.org 
Sent: Tuesday, 24 September 2013, 19:15
Subject: [Vala] Extra documentation for vapis on Valadoc
 

My
 question is how did the extra documentation get there? I looked in the
Glib-2.0 vapi but there's nothing extra there.


My understanding is Valadoc is not generated from vapi files. 

It has it's own markup style ( see http://valadoc.org/#!wiki=markup ) and 
source code ( see https://gitorious.org/valadoc-org/valadoc-org/ ), but that 
may not be the whole story because the relevant valadoc file I can find ( 
https://gitorious.org/valadoc-org/valadoc-org/source/6c7d58e17a247438337d75bde80737f0e539fa2b:documentation/glib-2.0/glib-2.0.valadoc
 ) doesn't seem to contain the GLib.Markup.printf_escaped function you were 
interested in.

Hope that helps,

Al
___
vala-list mailing list
vala-list@gnome.org
https://mail.gnome.org/mailman/listinfo/vala-list


Re: [Vala] Soup.Buffer memory

2013-09-24 Thread Evan Nemerson
On Tue, 2013-09-24 at 14:24 +0200, andrea zambon wrote:
 I am developing a service http with libsoup, but I have a memory problem.
 When you make a request, the service memory increases during transmission
 and decreases only after the closure of the service. Another call and will
 increase again.

See the API docs for Soup.MessageBody.set_accumulate:
http://valadoc.org/libsoup-2.4/Soup.MessageBody.set_accumulate.html

I have no idea if it will work for encodings other than chunked, but I
don't see a reason why you would want to close the connection after
every request, so why not just use chunked?

 The client is in another machine and the data may be very long (2 GB).
 I try to user Soup.MemoryUse.TAKE but I get garbage data.
 The Soup.Buffer is not free when sending a new buffer?

Using the default Soup.Buffer constructor with Soup.MemoryUse.TAKE is
very difficult to get right.  That flag is telling libsoup:

The caller has allocated the memory for the SoupBuffer's use;
libsoup will assume ownership of it and free it (with g_free())
when it is done with it.

However, Vala isn't actually aware of the interaction between this
parameter and libsoup's memory management.  According to the bindings,
the argument does not transfer ownership, which means Vala will free the
buffer for you, then it is likely to get reallocated somewhere else and
have its contents changed.  Furthermore, when libsoup tries to free it
your program will likely crash.

If you want to transfer ownership, you should use the Soup.Buffer.take
constructor.  By default valac will actually make a copy of the buffer
for you, so if you want to pass along your reference (which will
invalidate your local copy), use the (owned) keyword:

var buffer = new Soup.Buffer.take ((owned) data);

I'm attaching a version of a server I wrote a while back which you may
want to take a look at.  It uses chunked encoding for larger files,
while smaller files are mmaped and use content length encoding.  It's
also pretty good about doing things asynchronously when possible.


-Evan
public class Server : Soup.Server {
  public string directory { get; construct; }

  private const int BUFFER_SIZE = 1024 * 1024;

  private void write_chunk (Soup.Message msg) {
unowned GLib.InputStream stream = msg.get_dataGLib.InputStream (input-stream);
uint8[] buffer = new uint8[BUFFER_SIZE];

stream.read_async.begin (buffer, GLib.Priority.DEFAULT, null, (obj, res) = {
try {
  buffer.length = (int) stream.read_async.end (res);
  if (buffer.length  0) {
msg.response_body.append_take ((owned) buffer);
  } else {
msg.response_body.complete ();
  }
} catch (GLib.Error e) {
  GLib.warning (e.message);
  msg.response_body.complete ();
}

this.unpause_message (msg);
  });
  }

  private async void handle_async (Soup.Server server, Soup.Message msg, string path, GLib.HashTablestring,string? query, Soup.ClientContext client) {
string filename = GLib.Path.build_filename (directory, path);
GLib.File file = GLib.File.new_for_path (filename);
GLib.FileInputStream stream;
uint64 content_length = 0;

this.pause_message (msg);

try {
  GLib.FileInfo info = file.query_info (
string.joinv (,, { GLib.FileAttribute.STANDARD_SIZE,
 GLib.FileAttribute.STANDARD_CONTENT_TYPE }), 0);

  content_length = info.get_attribute_uint64 (GLib.FileAttribute.STANDARD_SIZE);
  msg.response_headers.append (Content-type, info.get_attribute_as_string (GLib.FileAttribute.STANDARD_CONTENT_TYPE));

  stream = yield file.read_async ();
} catch (GLib.Error e) {
  bool e_handled = false;

  if (e is GLib.IOError) {
if (e is GLib.IOError.NOT_FOUND) {
  msg.set_status (Soup.Status.NOT_FOUND);
  e_handled = true;
}
  }

  if (!e_handled) {
msg.set_status (Soup.Status.INTERNAL_SERVER_ERROR);
  }

  msg.response_headers.append (Content-type, text/html);
  string reason = GLib.Markup.escape_text (msg.reason_phrase);
  msg.response_body.append (Soup.MemoryUse.COPY, htmlheadtitle%s/title/headbodyh1%s/h1/body/html\n.printf (reason, reason).data);
  this.unpause_message (msg);

  return;
}

msg.set_status (Soup.Status.OK);

if (content_length  0  content_length  BUFFER_SIZE) {
  try {
GLib.MappedFile mapped = new GLib.MappedFile (filename, false);
unowned uint8[] data = (uint8[]) mapped.get_contents ();
data.length = (int) mapped.get_length ();

msg.response_headers.set_encoding (Soup.Encoding.CONTENT_LENGTH);
msg.response_body.append (Soup.MemoryUse.TEMPORARY, data);
/* This will keep the mapped file alive until the message is
 * destroyed, which allows us to use Soup.MemoryUse.TEMPORARY
 * above and avoid a copy. */