This forum has been archived. All content is frozen. Please use KDE Discuss instead.

KXMLGUIMainWindow and xmlui.rc file

Tags: None
(comma "," separated)
xyfix
Registered Member
Posts
110
Karma
0

KXMLGUIMainWindow and xmlui.rc file

Wed Jan 06, 2010 4:23 pm
So I derived my AppMainWindow from KParts::MainWindow and put setXMLFile( xmlfile ) in the constructor of my AppMainWindow. On the same level ( thus were the app runs ) Just for testing purposes I have a ui.rc file with the content:
Code: Select all
<!DOCTYPE kpartgui SYSTEM "kpartgui.dtd">
<kpartgui name="Konqueror" version="1">
  <MenuBar>
   <Menu name="file"><Text>&amp;File</Text>
    <Action name="find"/>
    <Separator/>
    <Action name="print"/>
    <Separator/>
    <Action name="close"/>
   </Menu>
   <Menu name="edit"><Text>&amp;Edit</Text>
    <Action name="cut"/>
    <Action name="copy"/>
    <Action name="paste"/>
    <Action name="trash"/>
    <Action name="del"/>
    <Separator/>
    <Merge/>
    <Separator/>
   </Menu>
   <Merge/>
  </MenuBar>
  <ToolBar fullWidth="true" name="mainToolBar"><Text>Main</Text>
   <Action name="cut"/>
   <Action name="copy"/>
   <Action name="paste"/>
   <Action name="print"/>
   <Separator/>
   <Merge/>
   <Separator/>
   <Action name="animated_logo"/>
  </ToolBar>
  <ToolBar name="locationToolBar"><Text>Location</Text>
   <Action name="toolbar_url_combo"/>
  </ToolBar>

</kpartgui>


but nothing happens.When debugging I can see that the code line is hit. What am I doing wrong?
User avatar
bcooksley
Administrator
Posts
19765
Karma
87
OS
Do you create the actions and add them to the action collection?

Code: Select all
KStandardAction::copy( this, SLOT(), actionCollection );


Code: Select all
KAction * action = actionCollection()->addAction("copy");
action->setText( i18n("Copy") );


KDE Sysadmin
[img]content/bcooksley_sig.png[/img]
xyfix
Registered Member
Posts
110
Karma
0
I already had actions in my original QMainWindow but they were QActions. Do I need to transform them into KStandardActions?
User avatar
bcooksley
Administrator
Posts
19765
Karma
87
OS
It depends on what they do.

The direct conversion is to KAction, which is what the second code snippet does. KAction adds a few things including KDE Shortcut infrastructure support to QAction.

KStandardAction is what allows KDE applications to share actions which feel and look the exact same between each other.
KStandardAction methods all return a KAction.


KDE Sysadmin
[img]content/bcooksley_sig.png[/img]
xyfix
Registered Member
Posts
110
Karma
0
I had actions like open, close, import, export and many others defined already in my app. Can I use these actions or do I need to use KActions and KMenu instead of QAction and QMenu.
xyfix
Registered Member
Posts
110
Karma
0
Still testing and trying to get familiar with kpart and the ui xml technique but no luck. My application mainwindow is derived from KParts::MainWindow and in this class I create a KAction ("testprint", this ) and inside the constructior of this class I do a setXMLFile with a file in the same directory.
Code: Select all
<!DOCTYPE kpartgui>
<kpartgui name="JustTest" version="1">
  <MenuBar>
   <Menu name="File"><Text>&amp;File</Text>
    <Action name="testprint"/>
   </Menu>
  </MenuBar>
  <ToolBar fullWidth="true" name="mainToolBar"><Text>Main</Text>
   <Action name="testprint"/>
   <Separator/>
  </ToolBar>
</kpartgui>

Anyone got an idea on what I forgot?
xyfix
Registered Member
Posts
110
Karma
0
I tried the full path to the ui.rc file and put a createGUI(0L) after the setXMLFile(). This results in another Help menu item in my menu bar besides the one I already got of my app. The new Help menu displays the KDE help. So can I conclude that my mainwindow is kpart aware? and why is the ui.rc file not read ( checked the name and path a 1000 times).
User avatar
bcooksley
Administrator
Posts
19765
Karma
87
OS
In order to be found, ui.rc files need to be named <app name>ui.rc and installed to $(kde4-config --install data)/<appname>

If you do not want to install it to a system wide path, you will need to make some changes to your environment.
Add the following to your ~/.bashrc:

Code: Select all
export KDEDIR=$(kde4-config --prefix)
export KDEDIRS=$KDEDIR:$HOME/kde4-local-prefix


You can then install your application to $HOME/kde4-local-prefix after logging out and back in again.

The advantage of XMLGUI is that you do not need to create the menus manually as it will do it for you.
You only need to convert your QAction's to KAction's, and add them to the action collection for it to work.


KDE Sysadmin
[img]content/bcooksley_sig.png[/img]
xyfix
Registered Member
Posts
110
Karma
0
Super..this works, a huge THANK YOU bcooksley ;-D .
I can see a test KAction in the file menubar item. Now I need to transform all my current QActions into KAction and put it in the XML file and my QMenu into KMenu. What's with the Help menubar item, can I get rid of it? as much as I like KDE, I've already got one and I don't need another Help in my app.
Another question: currently my app also runs on Windows, I assume it will keep running after the XML transition with the necessary libraries and files that I need to include in my app...right?
Now up to the real reason why I made my app kpart aware: the integration of kword/part. In a QMenu item "Reporting" I have a QAction "Add Report", this action brings the app in a reporting mode (just shows a few default tabs on the screen) and adds a new one with a QTextEdit object in this last tab. In the new situation I want it to put the kword/part in this tab. Any one any ideas?
User avatar
bcooksley
Administrator
Posts
19765
Karma
87
OS
You do not need QMenu's when working with XMLGUI, since it creates them for you, so you can delete them.

simply call setHelpMenuEnabled( false ); to disable the KDE help menu in your KXMLGUIWindow subclass.
This needs to be done before any createGUI() or setupGUI() calls.


KDE Sysadmin
[img]content/bcooksley_sig.png[/img]
xyfix
Registered Member
Posts
110
Karma
0
But ofcourse, I forgot that bcooksley. I don't need any addMenu's anymore since the XMLGUI is taking care of that for me.But can you please give some comments on the other questions in my previous posting?
xyfix
Registered Member
Posts
110
Karma
0
bcooksley gave me a suggestion about the ui.rc file that should be found if I export KDEDIR and KDEDIRS, but unfortunately it didn't work. I exported these environment variables in my .bashrc and then sourced this file and checked wether the variables have the right value in my shell and the started the app but it still says that it can't find the file myappui.rc even though it's on the same level as the application. The application is installed in /development/myapp and this directory is thus also added to KDEDIRS while the DKEDIR has a value $( kde4-config --prefix ) and that is /usr.
User avatar
bcooksley
Administrator
Posts
19765
Karma
87
OS
What build system are you using? CMake can make handling where to install KDE related files much easier.


KDE Sysadmin
[img]content/bcooksley_sig.png[/img]
xyfix
Registered Member
Posts
110
Karma
0
actually my application makes use of project files (.pro) thus qmake. This makes Makefiles which are handled by GNUMake.
I hope this helps.
User avatar
bcooksley
Administrator
Posts
19765
Karma
87
OS
You should install the *ui.rc file to $prefix/share/apps/<your app name>/
Not sure how this is handled in QMake.

Some distributions alter it to need for it to be installed in $prefix/share/kde4/apps/<your app name> instead however.


KDE Sysadmin
[img]content/bcooksley_sig.png[/img]


Bookmarks



Who is online

Registered users: bancha, Bing [Bot], Evergrowing, Google [Bot], lockheed, mesutakcan