Announcement

Collapse
No announcement yet.

Service Menus with Dolphin

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Rog131
    replied
    Magick pile of Polaroids

    With the help of the ImageMagick /1/ the KDE icons can be made from the piles of polaroids.



    The context menu desktop part - $HOME/.local/share/kservices5/ServiceMenus/magickpile.desktop:
    Code:
    [Desktop Entry]
    Type=Service
    Icon=view-list-icons
    X-KDE-ServiceTypes=KonqPopupMenu/Plugin
    MimeType=all/allfiles;
    Actions=magickPile;
    Encoding=UTF-8
    
    [Desktop Action magickPile]
    Name=Magick pile of icons
    Icon=view-list-icons
    Exec=magickpile.pl "%F"


    The thumbnail polaroids are scooped from the thumbnail cache and piled with a short Perl script - magickpile.pl:
    Code:
    #!/usr/bin/perl
    
    # usage: magickpile.pl filelist
    
    use strict;
    use warnings;
    
    # modules
    use Image::Magick;
    use File::Spec;
    use URI::Escape;
    use Digest::MD5 qw(md5_hex);
    
    my $angle;
    my @newIcon;
    
    my $i = 0;
    my $iconResolution = '256x256';
    
    my $cachePath = $ENV{XDG_CACHE_HOME} || ("$ENV{HOME}/.cache");
    my $thumbPath = "$cachePath/thumbnails/large/";
    
    $ARGV[0] =~ s' /' //'g;
    my @fileNames = split(' /', $ARGV[0]);
    my ($volume,$workDir,$file) = File::Spec->splitpath( $fileNames[0] );
    my $iconOut = "$workDir.magickpile.png";
    
    # pile of thumbs
    foreach my $name (@fileNames) {
    $i++;
    my $fullName = "file://" . $name;
    my $escapedName = uri_escape("$fullName", "^A-Öa-ö0-9\-\.,_~/:()&!\@\\[\\]'");
    $escapedName=~ s'\|'%7C'g;
    $escapedName=~ s'%24'$'g;
    $escapedName=~ s'\{'%7B'g;
    $escapedName=~ s'\}'%7D'g;
    my $thumbName = md5_hex("$escapedName") . ".png";
    my $angle = int(rand(30))-15;
    $newIcon[$i] = Image::Magick->new;
    $newIcon[$i]->Read("$thumbPath$thumbName");
    $newIcon[$i]->Polaroid(angle => $angle, gravity => 'center', background => 'transparent');
    $newIcon[$i] = $newIcon[$i]->Montage(geometry=>$iconResolution, background=>'transparent');
    if ($i > 1) { 
    $newIcon[1]->Composite(image=>$newIcon[$i],compose=>'over', gravity=>'center');
    $newIcon[$i]->Set(quality=>100);
    }
    }
    
    $newIcon[1]->Write("$iconOut");
    system ("kwriteconfig5", "--file", "$workDir.directory", "--group", "Desktop Entry", "--key", "Icon", "./.magickpile.png");
    Executable script 'magickpile.pl' is located in the $PATH. The script is using PerlMagick /2/

    Note !

    This script is using 'Correctly encode URL of thumbnails' /3/. It won't work with the older KDE Frameworks (<5.46 ?). At here, now, the KF 5.48.0.

    It is getting the thumbnails from the thumbnail cache. If the thumbnailer /4/ is not caching then it won't work with this type of thumbnails.

    Preview



    Direct: https://youtu.be/-JEfOa8gAWQ

    Links

    1. https://www.imagemagick.org/script/index.php
    2. http://www.imagemagick.org/script/perl-magick.php
    3. https://cgit.kde.org/kio.git/commit/...499eff3b976162
    4. https://api.kde.org/frameworks/kio/h...mbCreator.html
    Last edited by Rog131; Jul 17, 2018, 10:05 AM.

    Leave a comment:


  • Rog131
    replied
    Originally posted by Chipy View Post
    No, it only says :
    What kind of file ?
    What is the extension ?

    I get the error - No plugin specified - When the kioclient5 doesn't link the filename pattern to the correct file type.
    i.e with the 'video.mpeg-4' the thumbnailer can thumbnail it but the kioclient5 command doesn't understand the type.



    Last edited by Rog131; Jul 16, 2018, 10:22 AM.

    Leave a comment:


  • Chipy
    replied
    No, it only says :
    No plugin specified.

    Leave a comment:


  • Rog131
    replied
    Originally posted by Chipy View Post

    ...But I'm only getting an Internal Error and there is no new icon...

    Any further ideas?

    Thank you in advance!
    Chipy
    Hi !

    Do you see something like:

    or something else ?

    In this case the image file has a wrong extension.
    A bug report: Bug 220496 - Preview of pictures when content type does not match extension - https://bugs.kde.org/show_bug.cgi?id=220496

    You could check if there is a wrong extension with the file command:
    Code:
    $ file /media/sda1/GifWallpapers/1358773.jpg
    /media/sda1/GifWallpapers/1358773.jpg: GIF image data, version 89a, 460 x 460

    Leave a comment:


  • Chipy
    replied
    Originally posted by Rog131 View Post
    Hi !

    What is PATH ?: http://www.linfo.org/path_env_var.html

    AskUbuntu - How to add a directory to the PATH?: https://askubuntu.com/questions/6021...ry-to-the-path

    At here the useThisAsIcon.sh is in the $HOME/.bin/:

    as my $PATH includes it.

    The useThisAsIcon.sh is executable:

    so I can execute it when I right click a file:

    The desktop file ($HOME/.local/share/kservices5/ServiceMenus/useThisAsIcon.desktop) has line:

    Code:
    Exec=useThisAsIcon.sh "%f"
    The Exec key: https://standards.freedesktop.org/de...t/ar01s07.html
    Hi Rog131,
    thank you very much for your fast answer!

    I checked with
    Code:
    [FONT=sans-serif]echo $PATH[/FONT]
    and got as result
    Code:
    /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
    So I moved the executable useThisAsIcon.sh to
    Code:
    /usr/local/bin
    , where I also have two other executable files for service menus.

    But I'm only getting an Internal Error and there is no new icon...

    Any further ideas?

    Thank you in advance!
    Chipy

    Leave a comment:


  • Rog131
    replied
    Originally posted by Chipy View Post
    Hi Rog131 & everybody,
    I tried to add this service menu to my Kubuntu 18.04, but I don't understand exactly, where to put the useThisAsIcon.sh and what to do exactly with it.
    What do you mean by:

    Thank you in advance about a timely response!
    Chipy
    Hi !

    What is PATH ?: http://www.linfo.org/path_env_var.html
    PATH is an environmental variable in Linux and other Unix-like operating systems that tells the shell which directories to search for executable files (i.e., ready-to-run programs) in response to commands issued by a user. It increases both the convenience and the safety of such operating systems and is widely considered to be the single most important environmental variable...

    A list of all the current environmental variables and their values for the current user, including all the directories in the PATH variable, can be seen by running the env command without any options or arguments (i.e., input data), i.e.,

    env

    As there can be considerable output, it can be convenient to modify this command so that it displays just the PATH environmental variable and its value. This can be accomplished by using a pipe (represented by the vertical bar character) to transfer the output of env to the grep filter and use PATH as an argument to grep, i.e.,

    env | grep PATH

    Another way to view the contents of just PATH alone is by using the echo command with $PATH as an argument:

    echo $PATH

    echo repeats on the display screen whatever follows it on the command line. The dollar sign immediately preceding PATH tells echo to repeat the value of the variable PATH rather than its name.

    Each user on a system can have a different PATH variable...
    AskUbuntu - How to add a directory to the PATH?: https://askubuntu.com/questions/6021...ry-to-the-path

    At here the useThisAsIcon.sh is in the $HOME/.bin/:



    as my $PATH includes it.

    The useThisAsIcon.sh is executable:



    so I can execute it when I right click a file:



    The desktop file ($HOME/.local/share/kservices5/ServiceMenus/useThisAsIcon.desktop) has line:

    Code:
    Exec=useThisAsIcon.sh "%f"
    The Exec key: https://standards.freedesktop.org/de...t/ar01s07.html

    The Exec key must contain a command line. A command line consists of an executable program optionally followed by one or more arguments. The executable program can either be specified with its full path or with the name of the executable only. If no full path is provided the executable is looked up in the $PATH environment variable used by the desktop environment...
    Last edited by Rog131; Jul 16, 2018, 04:34 AM.

    Leave a comment:


  • Chipy
    replied
    Originally posted by Rog131 View Post
    Linking to Thread: Dolphin folder display, one photo only as thunbnail. - https://www.kubuntuforums.net/showth...bnail?p=408667

    With the KDE Frameworks 5.41.0 (kio) , KDE Applications 17.12.0 (Dolphin), Plasma 5.11.4 (kde-cli-tools).

    Making a desktop file - useThisAsIcon.desktop

    Code:
    [Desktop Entry]
    Type=Service
    Icon=image-x-icon
    X-KDE-ServiceTypes=KonqPopupMenu/Plugin
    MimeType=all/allfiles;
    Actions=thisIcon;
    Encoding=UTF-8
    
    [Desktop Action thisIcon]
    Name=Use this as folder icon
    Icon=image-x-icon
    Exec=useThisAsIcon.sh "%f"
    And a script file - useThisAsIcon.sh:

    Code:
    #!/bin/sh
    # Usage: useThisAsIcon /path/to/file.extension
    
    file=$1
    directory=$(dirname "${file}")
    
    kioclient5 copy "thumbnail://$file" "$directory/.cover.png"
    kwriteconfig5 --file "$directory/.directory" --group 'Desktop Entry' --key Icon ./.cover
    Hi Rog131 & everybody,
    I tried to add this service menu to my Kubuntu 18.04, but I don't understand exactly, where to put the useThisAsIcon.sh and what to do exactly with it.
    What do you mean by:
    In the right place - told by echo $PATH.
    Thank you in advance about a timely response!
    Chipy

    Leave a comment:


  • MoonRise
    replied
    Thanks All!

    Leave a comment:


  • Rog131
    replied
    KDE4 vs KF5

    Paths

    Service menus are looked at...

    Earlier: https://www.kubuntuforums.net/showth...l=1#post367207

    KDE4 - Debian based:

    ~/.kde/share/kde4/services/ServiceMenus/
    and
    /usr/share/kde4/services/ServiceMenus/

    KF5:

    ~/.local/share/kservices5/ServiceMenus/
    and
    /usr/share/kservices5/ServiceMenus/

    A quick test

    with
    $ dolphin -v
    Qt: 4.8.6
    KDE Development Platform: 4.14.2
    Dolphin: 4.14.2
    ~/.kde/share/kde4/services/ServiceMenus/useThisAsIcon.desktop:
    Code:
    [Desktop Entry]
    Type=Service
    Icon=image-x-icon
    X-KDE-ServiceTypes=KonqPopupMenu/Plugin
    MimeType=all/allfiles;
    Actions=thisIcon;
    Encoding=UTF-8
    
    [Desktop Action thisIcon]
    Name=Use this as folder icon
    Icon=image-x-icon
    Exec=useThisAsIcon.sh "%f"
    Executable useThisAsIcon.sh:
    Code:
    #!/bin/sh
    # Usage: useThisAsIcon /path/to/file.extension
    
    file=$1
    directory=$(dirname "${file}")
    
    kioclient copy "thumbnail://$file" "$directory/.cover.png"
    kwriteconfig --file "$directory/.directory" --group 'Desktop Entry' --key Icon ./.cover
    In the right place - told by echo $PATH.

    Seems to work =>



    Notes

    The KDE4 Dolphin is not refreshing the view. The user need to press F5 to reload the folder icons.

    The KDE4 Dolphin/kio is squashing the icons to square. KF5 keep the image proportions.

    Leave a comment:


  • oshunluvr
    replied
    ..and rebooting isn't necessary. At the most closing and re-launching Dolphin, but even that shouldn't be necessary. They should be available immediately.

    Leave a comment:


  • vinnywright
    replied
    Originally posted by MoonRise View Post
    Nice!! Thanks!

    EDIT: Oddly I add that desktop entry to `/.kde/share/kde4/services/ServiceMenus/ but for some reason does not show up even on a reboot. Will play around some, but any feedback?
    are you running plasma5 ?

    try /home/vinny/.local/share/kservices5/ServiceMenus/ ,,,,,,,of corse change "vinny" to your user name and you may half to make the "kservices5" directory .

    VINNY

    Leave a comment:


  • MoonRise
    replied
    Nice!! Thanks!

    EDIT: Oddly I add that desktop entry to `/.kde/share/kde4/services/ServiceMenus/ but for some reason does not show up even on a reboot. Will play around some, but any feedback?
    Last edited by MoonRise; Jan 06, 2018, 08:54 AM.

    Leave a comment:


  • Rog131
    replied
    Use This As Icon

    Linking to Thread: Dolphin folder display, one photo only as thunbnail. - https://www.kubuntuforums.net/showth...bnail?p=408667

    With the KDE Frameworks 5.41.0 (kio) , KDE Applications 17.12.0 (Dolphin), Plasma 5.11.4 (kde-cli-tools).

    Making a desktop file - useThisAsIcon.desktop

    Code:
    [Desktop Entry]
    Type=Service
    Icon=image-x-icon
    X-KDE-ServiceTypes=KonqPopupMenu/Plugin
    MimeType=all/allfiles;
    Actions=thisIcon;
    Encoding=UTF-8
    
    [Desktop Action thisIcon]
    Name=Use this as folder icon
    Icon=image-x-icon
    Exec=useThisAsIcon.sh "%f"


    And a script file - useThisAsIcon.sh:

    Code:
    #!/bin/sh
    # Usage: useThisAsIcon /path/to/file.extension
    
    file=$1
    directory=$(dirname "${file}")
    
    kioclient5 copy "thumbnail://$file" "$directory/.cover.png"
    kwriteconfig5 --file "$directory/.directory" --group 'Desktop Entry' --key Icon ./.cover
    The script file is executing the kio thumbnail and writing the thumbnail to the .cover.png. The script is also writing the icon key to the the KDE .directory file:





    More of the kioclient and the kwriteconfig can be found with the commands:

    Code:
    kioclient --help
    kwriteconfig --help
    With the KDE Frameworks 5 the commands are kioclient5 and the kwriteconfig5.
    Last edited by Rog131; Jan 05, 2018, 01:41 PM.

    Leave a comment:


  • vinnywright
    replied
    Originally posted by chimak111 View Post
    It has a minimal GUI and I'm used to it on my Lubuntu laptop. I'm using the ppa version: https://launchpad.net/~mc3man/+archi..._filter=xenial.

    The one in the standard repos is quite old (and gave me trouble with kwin as well).

    Plus I wanted to make a service menu all of my very own
    O ,,,so you made a service menu to launch mpv on a media file .

    I thought you were still talking about getting the full path and filename of some file to the clipboard.

    VINNY

    Leave a comment:


  • chimak111
    replied
    Originally posted by vinnywright View Post
    ok ,,gota ask ,,,why "mpv" is not that a media player ,,,,I'v never used it .
    VINNY
    It has a minimal GUI and I'm used to it on my Lubuntu laptop. I'm using the ppa version: https://launchpad.net/~mc3man/+archi..._filter=xenial.

    The one in the standard repos is quite old (and gave me trouble with kwin as well).

    Plus I wanted to make a service menu all of my very own

    Leave a comment:

Users Viewing This Topic

Collapse

There are 0 users viewing this topic.

Working...
X