Next Previous Table of Contents

p6 is a very simple application that just shows a list with bookmarks.
require 'Korundum'
class BookMarkList < KDE::ListView
k_dcop 'void add( QString )'
def initialize()
super(nil, "Bookmarks")
addColumn( i18n("My Bookmarks") )
end
def add( s )
insertItem( KDE::ListViewItem.new( self , s ) )
end
end
about = KDE::AboutData.new("p6", "Tutorial - p6", "0.1")
KDE::CmdLineArgs.init(ARGV, about)
a = KDE::UniqueApplication.new()
mylist = BookMarkList.new
mylist.resize( 300, 200 )
a.mainWidget = mylist
mylist.show
a.exec
Instead of using a KDE::MainWindow, to emphasize source clarity over user interface design, we will use a KDE::ListView item directly.
With KDE::ListView you can create a widget with a list of items (also with different columns to show different properties of each item). It's also possible (and fast) to create a tree of items to better organize things. In this little example, we will just use it as a single column list view with ordering capabilities (that's why we aren't using a KDE::ListBox which would fit our needs as well and with a simpler API).
class BookMarkList < KDE::ListView
Note that the classname is the name with which DCOP
will know this object, so that remote calls to one of its methods should
be made using BookMarkList as object name.
k_dcop 'void add( QString )'
Using the special k_dcop tag, we define the methods that others will be
able to remotely call using DCOP, in this case, add.
addColumn( i18n("My Bookmarks") )
We add a column (there should be at least one to make the Qt::ListView usable).
insertItem( KDE::ListViewItem.new( self , s ) )
Finally, the add method, takes the String parameter, constructs
a KDE::ListViewItem with it and adds the item to the KDE::ListView.
Perhaps you wonder why there isn't a simpler way to insert a String in a KDE::ListView. The reason is simple: A KDE::ListView object can hold much more complex items than simple strings, for example, you can have multiple columns, and multiple columns where some of them are Qt::Pixmap objects (ie images), etc.
This is the script:
#!/usr/bin/bash dcop p6 BookMarkList add "http://www.kde.org"
That's it!
You can use the kdcop app to browse DCOP interfaces. Start kdcop from the command line and you should see 'p6' listed along with the other apps. Click to open it and look in the BookMarkList interface for the void add(QString) method. Select the add() method, run the Execute menu command and kdcop will prompt you for a string to type as a URL to send to p6.
We have now finished examining p6. Let's see what we can do next.
Next Previous Table of Contents