[Kde-java] Some questions - long - KScribble in java

Richard Dale kde-java@kde.org
Mon, 11 Feb 2002 16:54:52 +0000


On Monday 11 February 2002 9:48 am, KJ P wrote:

> 1)  KScribble uses the following
>
> pFileMenu->insertItem(BarIcon("filenew"), i18n("&New"), ID_FILE_NEW);
> pFileMenu->insertItem(BarIcon("fileopen"), i18n("&Open..."), ID_FILE_OPEN);
>
> I can not find BarIcon.  Is it missing or have I missed something.
I've had a look - and it is missing because it's a function call rather than a 
static method of KIconLoader. So that needs to be fixed up by hand - in java 
the functions at the end of kiconloader.h would appear as KIconLoader static 
methods.

> Also, when looking at KBase.java example it uses KStdAction.  Which is used
> as a standard both or should KStdAction be used?  I guess this is off topic
> for this list but hope to get an answer here.

>From KStdAction.java:

 In general, using standard actions should be a drop in replacement
 for regular actions.  For example, if you previously had:

 <PRE>
 KAction newAct = new KAction(i18n("&New"), QIconSet(BarIcon("filenew")),
                               KStdAccel.key(KStdAccel.New), this,
                               SLOT("fileNew()"), actionCollection());
 </PRE>

 You could drop that and replace it with:

 <PRE>
 KAction newAct = KStdAction.openNew(this, SLOT("fileNew()"),
                                       actionCollection());
 </PRE>

So maybe BarIcon() isn't needed so much anymore.

> 2) Does the i18n not exist for java?  KBase.java uses tr() so instead I
> wrote an i18n method which calls tr() that way I did not have to change all
> the i18n code.  Is the tr() method going to be used instead of the i18n?
Yes, it should be there. I'll add your version if you post it on this list or 
send it to me.

> 3) Could someone give me an example of using the QWhatsThis.  In
> kscribble.cpp it is as follows:
>
> QToolButton *btnwhat = QWhatsThis::whatsThisButton(toolBar());
> QToolTip::add(btnwhat, i18n("What's this...?"));
> toolBar()->insertWidget(ID_HELP_WHATS_THIS, btnwhat->sizeHint().width(),
> btnwhat);
>
> I have tried all sorts of things to get this working but to no avail.
This compiles, but it crashes:

private static final int ID_HELP_WHATS_THIS = 1;
	...

	QToolButton btnwhat = QWhatsThis.whatsThisButton(toolBar());
	QToolTip.add(btnwhat, "What's this...?");
	toolBar().insertWidget(ID_HELP_WHATS_THIS, btnwhat.sizeHint().width(), 
btnwhat);

I'm investigating what's wrong. 

Here is some QWhatsThis() code which works:

    button =
            new QPushButton("Top Level\nWidget",this);
    QWhatsThis.add(button,
        "Button\n\n"
        + "This button is used as the top\n"
        + "level widget for this example. It\n"
        + "is very safe to click the button\n"
        + "because it doesn't do anything.\n");
    setCentralWidget(button);

> 4) While reading options and using the readListEntry for recentFiles I get
> a error linkage not satisfied error.  I have tried both versions of the
> method call for java.
>   // initialize the recent file list
>   config->readListEntry("Recent Files",recentFiles);
>
>   My code (example):
>
>   ArrayList recentFiles = new ArrayList();
>   config.readListEntry("Recent Files",recentFiles);
>
> Sorry I can not give the exact error message as I am writing from memory
> and do not have the code here.  I can of course provide this if needed
> later.
That method needs fixing up by hand. At the moment it is passing the value of 
'recentFiles' to config.readListEntry(), but isn't converting the returned 
value of the list back to java.

On the other hand:

ArrayList recentFiles = config.readListEntry("Recent Files");

A function returning a C++ list would be easier to convert than a void 
procedure.

> 5) When trying to load an image from open file list in kscribbledoc.cpp
>
>   /////////////////////////////////////////////////
>   // TODO: Add your document opening code here
> 	if(!buffer.load( filename, format ))
> 		return false;
> 	size=buffer.size(); /////////////////////////////////////////////////
>
> I tried the buffer.load( filename, format, conv) method.
>
>    format is difined as a char in the C++ library version but in the java
> binding it is a String.  I could not for the life of me get this to work. 
> I finally used !buffer.load( filename ) and it worked perfectly.
>
> My question is is this an error or have I done something wrong?  Probably I
> did something wrong but just had to ask.
It looks like a bug - I'll look into it.

> Sorry for so many newbie quesions.  I have others but I like to dig.
No problem, keep coming up with more feedback like this..

> The KScribble in java works great so far.  There is no difference in look
> and feel nor speed so far.  This is great.
Just slower start up time is the main difference.

> I will post the code for your examples as soon as I get it cleaned up.  I
> have stuff commented out all over the place and the toolbar does not work
> yet I think because of the BarIcon that I mentioned before.
It would be good to add a java KScribble to the kdebindings examples. It's an 
excellent test program - I can just keep fixing the problems you describe 
until we get it fully working.

> I did all of this yesterday (Sunday) while learning the Qt and KDE stuff at
> the same time.  I think this is a testimonial to the java bindings.
Yes, that's encouraging for me too..

-- Richard