Interfaces


#1

Hi everyone!

Since I’ve switched to Linux I’ve been looking for a way to write
applications
again. On Windows I used Delphi. I looked at its Linux counterpart Kylix
and
didnt like it at all. Especially, I wanted to write KDE applications
which
just wasnt possible. So I looked at other KDE bindings. I tried C++ but
all
that time for compiling and confusing Makefiles and type definitions
wasnt
really for me either. Now with Ruby and Korundum I think I’ve finally
found
my new language. Its amazing how fast you get things done. My first
application should contain a konsole part. I’ve looked up in the KDE
docs
and found the snippet below. I tried to translate it to ruby.
This worked great for the part until setCentralWidget.
I’m now having a real Terminal inside my application with just a few
lines
of code. Amazing. Unfortuately I cant do anything with it right now.
In order to communicate it seems that I need a so-called
Terminalnterface.
In C++ this is done by using a type-cast / qt_cast. Calling the qt_cast
method
from my KParts::Part object just yields a “*void not supported as return
value” message in Ruby. If I just try to call showShellInDir on my
object it
doesnt work of course because its not a method of KPart. I’m puzzled
right
now. Can this be done at all in Ruby (perhaps by calling “extend” or
whatever)?

Thanks in advance for any help here!

Ranjan

======

// fetch the Library…
KLibFactory* factory = KLibLoader::self()->factory( “libkonsolepart”
);
if ( factory == 0L )
{
// inform the user that he should install konsole…
return;
};
// fetch the part…
KParts::Part* p = static_castKParts::Part*(
factory->create( this, “tralala”, “QObject”,
“KParts::ReadOnlyPart” ) );
assert( p );
setCentralWidget( p->widget() );

// cast the part to the TerminalInterface…
TerminalInterface* t =
static_cast<TerminalInterface*>( p->qt_cast( “TerminalInterface” ) );
if( ! t )
{
// This probably happens because the konsole that is installed
// comes from before KDE 3.2 , and the TerminalInterface is not
// available… What you can do here is either inform the user
// that he needs a more recent konsole, or try to deliver the
// functionality in some other way…
return;
};
// now use the interface in all sorts of ways, e.g.
// t->showShellInDir( QDir::home().path() );
// or:
// QStrList l;
// l.append( “python” );
// t->startProgram( QString::fromUtf8( “/usr/bin/python” ), l);
// or connect to one of the signals. Connect to the Part object,
// not to the TerminalInterface, since the latter is no QObject,
// and as such cannot have signals…:
// connect( p, SIGNAL( processExited( int ) ),
// this, SLOT( shellExited( int ) ) );
// etc.