Re: [Vala] Chain up base constructor troubles with C code...

2012-05-28 Thread Axel FILMORE

On 28/05/2012 06:52, PCMan wrote:

It looks like you're using libfm/libfmgtk from pcmanfm project. :-)
For performance reasons, in libfm we did not utilize gobject
properties most of the time since we do not need this feature.
So g_object_new with constructor properties won't work.
Just replicating what are done by the C constructor works in this case.


It works, that's fabulous, I'm still missing a few things about
GObject in general, I started GTK+ and Vala in January, I'm a bit new.

I really like Vala, to create some GUI that's fabulous.

On other points, I'm sending you a more detailed reply, I've done a lot 
of experiments indeed.


:)


--
Axel FILMORE
##
https://github.com/afilmore
##
 Vala - Compiler For The GObject Type System
https://live.gnome.org/Vala
##
___
vala-list mailing list
vala-list@gnome.org
https://mail.gnome.org/mailman/listinfo/vala-list


Re: [Vala] Chain up base constructor troubles with C code...

2012-05-27 Thread PCMan
It looks like you're using libfm/libfmgtk from pcmanfm project. :-)
For performance reasons, in libfm we did not utilize gobject
properties most of the time since we do not need this feature.
So g_object_new with constructor properties won't work.
Just replicating what are done by the C constructor works in this case.

Besides, I need to inform you that recently we changed some APIs in
libfm and libfm-gtk.
To simplify things, some APIs you may use are removed, such as
fm_folder_view_chdir().
Please take a look at libfm/src/demo/main-win.c to see how to use the new APIs.

Now this is the standard way to make a FmFolderView showing a specified folder.
1. Load the folder content with FmFolder, fm_folder_get(path);
2. Create a FmFolderModel for the FmFolder so it can be viewed.
3. Set the FmFolderModel to FmFolderView.

It might takes more lines of code, but things actually became more
flexible and cleaner.
If you want to monitor the changes of the folder, connect to FmFolder
signals directly.
1. "start-loading" signal and "finish-loading" signals tell you when a
folder is being loaded and when it's finished.
  fm_folder_reload() triggers these signals as well.
2. "fs-info" signal is for filesystem information.
3. "unmount" signal tells you that a folder is unmoted.

The new way looks more complicated initially, but soon you'll find it
more reasonable and less error-prone.

Besides, did you write your own libfm.vapi file? We have one in
libfm/src/vapi, too.
The one we have is not completed and it's a good idea for us to use
one single libfm.vap.
Maybe we can merge our vapi files?

On Sun, May 27, 2012 at 7:51 PM, Axel FILMORE  wrote:
> Hi there,
>
> to avoid some nasty duplicated code I try to use inheritance with a base
> abstract class and derived views.
>
> I need to create a terminal view and a folder view, while it works fine with
> my terminal view which is written in Vala, I've some troubles with the
> folder view which is C code. :(
>
> I have the following :
>
> namespace Manager {
>
>    public class FolderView : Fm.FolderView, BaseView {
>
>        construct {
>            base.new (Fm.FolderViewMode.LIST_VIEW);
>            //Object ();
>            //base (Fm.FolderViewMode.LIST_VIEW);
>        }
>
>        public FolderView () {
>            //Object (mode: Fm.FolderViewMode.LIST_VIEW);
>            //base (Fm.FolderViewMode.LIST_VIEW);
>
>            base.new (Fm.FolderViewMode.LIST_VIEW);
>        }
>    }
> }
>
> I tried a few things without much success, the problem is that the base
> object doesn't seem to be created.
>
> BaseView is an abstract class in Vala and Fm.FolderView is my base object in
> C, the one that gives my some troubles. :-P
>
> In my Vapi file for the base object, I have :
>
> [CCode (cheader_filename = "gtk/fm-folder-view.h")]
> public class FolderView : Gtk.ScrolledWindow,
>                          Atk.Implementor,
>                          Gtk.Buildable {
>
>        public Fm.FolderViewMode   mode;
>
>        [CCode (has_construct_function = false,
>                cname = "fm_folder_view_new",
>                type = "GtkWidget*")]
>
>        public FolderView (int mode);
>
> }
>
>
> The problem is that the new function (fm_folder_view_new) is not called from
> Vala code.
>
> I tried to use "Object (mode: Fm.FolderViewMode.LIST_VIEW);"
> but "mode" is not a property and it fails.
>
> Is there a way so that when doing var = new Manager.FolderView ();
> the base function "fm_folder_view_new" is called ?
>
> Thanks. :)
>
>
> --
> Axel FILMORE
> ##
>        https://github.com/afilmore
> ##
>  Vala - Compiler For The GObject Type System
>        https://live.gnome.org/Vala
> ##
> ___
> vala-list mailing list
> vala-list@gnome.org
> https://mail.gnome.org/mailman/listinfo/vala-list
___
vala-list mailing list
vala-list@gnome.org
https://mail.gnome.org/mailman/listinfo/vala-list


Re: [Vala] Chain up base constructor troubles with C code...

2012-05-27 Thread Axel FILMORE

On 27/05/2012 17:54, Kerrick Staley wrote:

Axel,
I believe that when you're inheriting from a C class in Vala code,
calling the base class's constructor is not supported [1]. Instead, just
replicate the original constructor's functionality at the beginning of
your derived class's constructor:

public class FolderView : Fm.FolderView, BaseView
{
 public FolderView()
 {
 // initialize Fm.FolderView's properties
fmFoldViewProp1 = "foo";
...
 // do FolderView-specific initialization
foldViewProp1 = "bar";
 }
}


It works just great, this is what I have :

public class FolderView : Fm.FolderView, BaseView {

public FolderView (Gtk.Notebook parent, string directory) {

// Object (); // not needed :)
base.set_mode (Fm.FolderViewMode.LIST_VIEW);
base.small_icon_size =  16;
base.big_icon_size =36;
base.single_click = false;
}
}

I first tried to call Object () but you are absolutely correct,
just setting the properties works as expected. Marvelous. :-P

So, here's the result.

The Folder View :
http://pix.toile-libre.org/upload/original/1338136960.png

The Terminal :
http://pix.toile-libre.org/upload/original/1338137023.png

Great information, thanks a lot, I'm not very familiar with GObject yet 
and I often have that kind of troubles with derived classes.


Thank you, best regards.

:)



--
Axel FILMORE
##
https://github.com/afilmore
##
 Vala - Compiler For The GObject Type System
https://live.gnome.org/Vala
##
___
vala-list mailing list
vala-list@gnome.org
https://mail.gnome.org/mailman/listinfo/vala-list


Re: [Vala] Chain up base constructor troubles with C code...

2012-05-27 Thread Kerrick Staley
Axel,
I believe that when you're inheriting from a C class in Vala code, calling
the base class's constructor is not supported [1]. Instead, just replicate
the original constructor's functionality at the beginning of your derived
class's constructor:

public class FolderView : Fm.FolderView, BaseView
{
public FolderView()
{
// initialize Fm.FolderView's properties
   fmFoldViewProp1 = "foo";
   ...
// do FolderView-specific initialization
   foldViewProp1 = "bar";
}
}

- Kerrick

[1]
As far as I understand it, this is because the C constructors
(e.g. fm_folder_view_new) do two logically separate things:
1) allocate memory for the new object
2) initialize the fields comprising that memory
Since (in general) a derived object occupies more memory than the
corresponding base object, the base constructor generally doesn't allocate
enough memory at step (1), and so the object returned by the base
constructor is pretty much useless (unless the derived constructor wants to
call realloc, but that would incur a performance penalty). Instead, each
constructor has to duplicate the functionality of its parent constructor.
In Vala, they handled this problem a little more nicely, and so constructor
chaining works as expected, but again this only works if you're inheriting
from a Vala class.
This discussion has more information:
http://osdir.com/ml/vala-list/2009-09/msg00376.html

On Sun, May 27, 2012 at 6:51 AM, Axel FILMORE wrote:

> Hi there,
>
> to avoid some nasty duplicated code I try to use inheritance with a base
> abstract class and derived views.
>
> I need to create a terminal view and a folder view, while it works fine
> with my terminal view which is written in Vala, I've some troubles with the
> folder view which is C code. :(
>
> I have the following :
>
> namespace Manager {
>
>public class FolderView : Fm.FolderView, BaseView {
>
>construct {
>base.new (Fm.FolderViewMode.LIST_VIEW);
>//Object ();
>//base (Fm.FolderViewMode.LIST_VIEW);
>}
>
>public FolderView () {
>//Object (mode: Fm.FolderViewMode.LIST_VIEW);
>//base (Fm.FolderViewMode.LIST_VIEW);
>
>base.new (Fm.FolderViewMode.LIST_VIEW);
>}
>}
> }
>
> I tried a few things without much success, the problem is that the base
> object doesn't seem to be created.
>
> BaseView is an abstract class in Vala and Fm.FolderView is my base object
> in C, the one that gives my some troubles. :-P
>
> In my Vapi file for the base object, I have :
>
> [CCode (cheader_filename = "gtk/fm-folder-view.h")]
> public class FolderView : Gtk.ScrolledWindow,
>  Atk.Implementor,
>  Gtk.Buildable {
>
>public Fm.FolderViewMode   mode;
>
>[CCode (has_construct_function = false,
>cname = "fm_folder_view_new",
>type = "GtkWidget*")]
>
>public FolderView (int mode);
>
> }
>
>
> The problem is that the new function (fm_folder_view_new) is not called
> from Vala code.
>
> I tried to use "Object (mode: Fm.FolderViewMode.LIST_VIEW);"
> but "mode" is not a property and it fails.
>
> Is there a way so that when doing var = new Manager.FolderView ();
> the base function "fm_folder_view_new" is called ?
>
> Thanks. :)
>
>
> --
> Axel FILMORE
> #-**---#
>https://github.com/afilmore
> #-**---#
>  Vala - Compiler For The GObject Type System
>https://live.gnome.org/Vala
> #-**---#
> __**_
> vala-list mailing list
> vala-list@gnome.org
> https://mail.gnome.org/**mailman/listinfo/vala-list
>
___
vala-list mailing list
vala-list@gnome.org
https://mail.gnome.org/mailman/listinfo/vala-list


[Vala] Chain up base constructor troubles with C code...

2012-05-27 Thread Axel FILMORE

Hi there,

to avoid some nasty duplicated code I try to use inheritance with a base 
abstract class and derived views.


I need to create a terminal view and a folder view, while it works fine 
with my terminal view which is written in Vala, I've some troubles with 
the folder view which is C code. :(


I have the following :

namespace Manager {

public class FolderView : Fm.FolderView, BaseView {

construct {
base.new (Fm.FolderViewMode.LIST_VIEW);
//Object ();
//base (Fm.FolderViewMode.LIST_VIEW);
}

public FolderView () {
//Object (mode: Fm.FolderViewMode.LIST_VIEW);
//base (Fm.FolderViewMode.LIST_VIEW);

base.new (Fm.FolderViewMode.LIST_VIEW);
}
}
}

I tried a few things without much success, the problem is that the base 
object doesn't seem to be created.


BaseView is an abstract class in Vala and Fm.FolderView is my base 
object in C, the one that gives my some troubles. :-P


In my Vapi file for the base object, I have :

[CCode (cheader_filename = "gtk/fm-folder-view.h")]
public class FolderView : Gtk.ScrolledWindow,
  Atk.Implementor,
  Gtk.Buildable {

public Fm.FolderViewMode   mode;

[CCode (has_construct_function = false,
cname = "fm_folder_view_new",
type = "GtkWidget*")]

public FolderView (int mode);

}


The problem is that the new function (fm_folder_view_new) is not called 
from Vala code.


I tried to use "Object (mode: Fm.FolderViewMode.LIST_VIEW);"
but "mode" is not a property and it fails.

Is there a way so that when doing var = new Manager.FolderView ();
the base function "fm_folder_view_new" is called ?

Thanks. :)


--
Axel FILMORE
##
https://github.com/afilmore
##
 Vala - Compiler For The GObject Type System
https://live.gnome.org/Vala
##
___
vala-list mailing list
vala-list@gnome.org
https://mail.gnome.org/mailman/listinfo/vala-list