c-hartmann / back-in-time-helper

0 stars 2 forks source link

Support for KDE 6 ? #2

Closed RandomLegend closed 7 months ago

RandomLegend commented 7 months ago

Hey, are there any plans to make this usable under KDE 6 ?

I upgraded and the helper doesn't find any snapshots even if i manually backed up a folder within the last snapshot from it's own menu.

RandomLegend commented 7 months ago

I've dug a little bit deeper but i am by no means a coder / dev...

so what i've found first was that in row 33 of the back-in-time-helper.desktop entry in ~/.local/share/kio/servicemenus there is a X_RefreshFromSnapshotsListAndActions; listed but it's not defined later in there.

After removing that i can see in the console output that it actually progresses.

Manually copying a location and replacing the %f in the target="%f" section at the beginning of the bash commands and running that modified command manually actually works perfectly fine.

So my guess is that Dolphin changed the expression on how you actually grab the selected file / folder.

RandomLegend commented 7 months ago

Looking at other working service menus i found that %U is a working expression for getting the path of a file but replacing %f with %U for the target doesn't work for me... also replacing all $target variables with %U doesn't work.

RandomLegend commented 7 months ago

Alright, with the help of ChatGPT i found a workaround. I don't know why but dolphin from KDE 6 apparantly doesn't like the way this command is written... what i've done is putting it into a .sh file somewhere else and simply calling the .sh file from the .desktop entry

The restore_snapshot.sh file looks like this:

#!/bin/bash

target="$1"
snapshots_path="$(backintime --quiet snapshots-path)"
radiolist_options=""

# Normalize the target path to ensure consistency in checks
normalized_target=$(readlink -f "$target")

# Construct radiolist options
snapshots=($(backintime --quiet snapshots-list | tail -5 | sort -r))
for ssid in "${snapshots[@]}"; do
    snapshot_dir="${snapshots_path}/$ssid/backup/${normalized_target}"

    if [ -d "$snapshot_dir" ]; then
        formatted_date="${ssid:0:4}-${ssid:4:2}-${ssid:6:2}_${ssid:9:2}:${ssid:11:2}:${ssid:13:2}"
        radiolist_options+=" \"$ssid\" \"$formatted_date\" \"off\""
    else
        echo "Directory not found in snapshot: $snapshot_dir" >> /home/frank-garuda/Scripts/SystemStuff/backintime_helper/debug.log
    fi
done

# Check if options were constructed
if [ -z "$radiolist_options" ]; then
    echo "No snapshots available that contain the directory: $normalized_target" >> /home/frank-garuda/Scripts/SystemStuff/backintime_helper/debug.log
    kdialog --error "No snapshots available that contain the directory: $normalized_target"
    exit 1
fi

# Display radiolist dialog
ssid=$(kdialog --radiolist "Select Snapshot" $radiolist_options)

# Exit if Cancel button is pressed (empty $ssid)
if [ -z "$ssid" ]; then
    echo "Snapshot selection canceled by user." >> /home/frank-garuda/Scripts/SystemStuff/backintime_helper/debug.log
    exit 0
fi

# Clean up ssid, remove any extraneous quotes if present
clean_ssid=$(echo $ssid | tr -d '"')

# Debug output
echo "Selected SSID: $clean_ssid" >> /home/frank-garuda/Scripts/SystemStuff/backintime_helper/debug.log

# Restore from selected snapshot
if test -n "$clean_ssid"; then
    restore_output=$(backintime restore "$normalized_target" "" "$clean_ssid" 2>&1)
    echo "Restore output: $restore_output" >> /home/frank-garuda/Scripts/SystemStuff/backintime_helper/debug.log

    if echo "$restore_output" | grep -q "No such file or directory"; then
        kdialog --error "Failed: No such file or directory in the selected snapshot."
    else
        kdialog --msgbox "Restore completed successfully."
    fi
else
    echo "No valid snapshot selected" >> /home/frank-garuda/Scripts/SystemStuff/backintime_helper/debug.log
    kdialog --error "No valid snapshot selected or operation was cancelled."
fi

And my .desktop entry for the service menu now looks like this:

[Desktop Entry]
Type=Service
X-KDE-ServiceTypes=KonqPopupMenu/Plugin
X-KDE-Priority=TopLevel
X-KDE-Submenu=Back In Time ...
MimeType=all/all;
Icon=document-save-all
TryExec=backintime
Actions=C_RestoreFromSnapshotSelectable;

[Desktop Action C_RestoreFromSnapshotSelectable]
Name=Restore from Snapshot (selectable)
Icon=document-save-all
Exec=/home/frank-garuda/Scripts/SystemStuff/backintime_helper/restore_snapshot.sh %f

I removed the other options because i always want to use only selectable restore.

Obviously you have to change all the paths from /home/frank-garuda/ etc. if you want to use this.

With this it works. Sad that this got abandonded by the creator.

c-hartmann commented 7 months ago

hi there,

first i have to apologize - i was busy with private things. so far i've setup a plasma 6 enviroment with kde neon and it worked as expected without any functional regression. there are regressions on the dispensable X_RefreshFromSnapshotsListAndActions (see Issue #4). that one was luckily ignored in Plasma 5.

there is another regression on my system: the entries in the content submenu are not ordered as programme, but just alphabetically (see Isssue #5)

when it comes to the %f, %F, %u, or %U references .. %f is for single local files, %F for a list of local files, whereas %u and %U allow references to URL based files. imho there is no need for URL based addresses when backing up local files.

new Issue #6 addresses the single v. multiple selected files isssue. (currently Plasma call the helper multiple times, when the user selected multiple files)

some of my service menus extension use external scripts, but in general i tend to believe, internal scripts are way more easily to handle when it comes to installation via GUI.

said all that...

can you please describe your local environment, so i can try to recreate it here in a VM? (Distro, Versions)

thx a lot

RandomLegend commented 7 months ago

I'm sorry - my last statement came over kinda passive-aggressive. I 100% understand that no one has time for every little project. No worries!

Regarding the % references, i just spurted out what i found online. As i said, i am no developer, i don't know the specifics for all this.

I am happy with the workaround i constructed with the help of GPT. It does Error handling a little bit better (not telling me Oooops when i click cancel in the selection menu) and it gives me feedback when the restore is done.

Maybe there is something in that script i provided that you want to use in future iterations, feel free to do so!

My environment is:

Garuda Linux Hyprland KDE 6 as the framework for Dolphin etc.

c-hartmann commented 7 months ago

you're welcome

Garuda was my first best guess ;)

In my minimal test bed, restore from backup works as expected.

Seems we have to dig deeper into the this rabbit hole

Screenshot_20240504_165729

Screenshot_20240504_170252