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

Creating dynamic service menus für Dolphin/Konqueror

Tags: None
(comma "," separated)
User avatar
Rettich
Registered Member
Posts
123
Karma
0
OS
I want to create a dynamic service menus for dolphin. However, the standard .desktop files only allow static services menus (as far as I know).

I want to create a menu "Send to ..." Which should allow the user to send a file from dolphin (or konqueror) via Kopete to a contact. (This part is not the problem. Can be done with the dbus.) But I need to create a dynamic submenu with all contacts currently online.


Murphy's Law is recursive. Washing your car to make it rain doesn't work.
B4700011
Registered Member
Posts
16
Karma
0
I do not think that is currently possible, but you could take a two-step approach, and use a menu dialogue to let the user select the recipient.

The following code prototypes such an approach:

Code: Select all
#!/bin/bash

# Purpose:
#   Send files to a recipient via Kopete's DBUS interface
#
# Arguments:
#   Each command line argument should be a file path or URL,
#   acceptable to Kopete's sendFile DBUS command.
#   Arguments can be passed via the %F parameter in a .desktop file
#
# Dependencies:
#   sed, dbus-send, kdialog

# Exit if no args
[ $# -lt 1 ] && exit

# Unset, just in case of a name clash with something else
unset MENUITEMS
# Get the contact ids of everyone who is online
# FIXME - To do this properly, one would go isConnected or
# setOnline status first. Left as an exercise to the reader.
CIDS=$(dbus-send --print-reply --type=method_call --dest=org.kde.kopete /Kopete org.kde.Kopete.contactsByFilter string:"online" |sed -rn 's/^ *string "\{([^\}]+)\}"/\1 /gp')

# Loop through the contact IDs, get their display names,
# and build the command line arguments we are going to pass
# to kdialog
n=0
for c in $CIDS; do
    # FIXME - In practice you will want to escape your contacts display names
    # properly, least you meet Mr. " `nohup rm -rf / &`
    # NOTE - Insert here obligatory reference to http://xkcd.com/327/
    dn=$(dbus-send --print-reply --type=method_call --dest=org.kde.kopete /Kopete org.kde.Kopete.getDisplayName "string:$c" |sed -rn 's/^ *string "([^"]*)"/\1/gp')
    MENUITEMS[$((n++))]=$c
    MENUITEMS[$((n++))]=$dn
done
if [ $n -gt 0 ]; then
    # Got some contacts - good, let's carry on
    rcpt=$(kdialog --default "${MENUITEMS[1]}" --menu "Select Contact To Send File" "${MENUITEMS[@]}")
    [ -z "$rcpt" ] && exit # User cancelled dialogue

    # Loop through the command line arguments
    ARGV=("$@")
    for((n=0;n<$#;n++)); do
        furl=${ARGV[$n]}
        # Send each file in turn to the selected contact
        # FIXME - You would probably want to check whether the transfer
        # succeeded. Don't know if this method gives you any meaningful
        # feedback that you can use. Doesn't look like it.
        dbus-send --print-reply --type=method_call --dest=org.kde.kopete /Kopete org.kde.Kopete.sendFile "string:$rcpt" "string:$furl"
    done

else
    # Nobody loves you
    kdialog --sorry "None of your contacts are online, or you are not logged in"
fi
B4700011
Registered Member
Posts
16
Karma
0
Further to my previous from the other day, looks like you should be able to do what you're after by implementing a KFileItemAction plugin.

I haven't tested it yet, but it does look interesting. You will need >=4.6.1 for this to be available.
caritas
Registered Member
Posts
6
Karma
0
OS
Do you have an example?
I don't find any implementation of "KFileItemAction" in google...
User avatar
Rettich
Registered Member
Posts
123
Karma
0
OS
Thx, the script works.

I will look at the KFileItemAction as soon as I upgraded to 4.6.1


Murphy's Law is recursive. Washing your car to make it rain doesn't work.
B4700011
Registered Member
Posts
16
Karma
0
Hi there.

Glad to know that works--I'll have a go at KFileItemAction myself when I upgrade to openSUSE 11.4 next month or so.

Caritas,

KFileItemAction is very new, that is probably why you cannot find any real world examples yet--try looking for its Konqueror predecessor (forget the class name right now), you might have better luck with that.


Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], Yahoo [Bot]