| 1 | # ----------------------------------------------------------------------------- | ||||||||||
| 2 | |||||||||||
| 3 | =encoding utf8 | ||||||||||
| 4 | |||||||||||
| 5 | =head1 NAME | ||||||||||
| 6 | |||||||||||
| 7 | Quiq::Trash - Operationen auf dem Trash von XFCE | ||||||||||
| 8 | |||||||||||
| 9 | =head1 BASE CLASS | ||||||||||
| 10 | |||||||||||
| 11 | L<Quiq::Hash> | ||||||||||
| 12 | |||||||||||
| 13 | =cut | ||||||||||
| 14 | |||||||||||
| 15 | # ----------------------------------------------------------------------------- | ||||||||||
| 16 | |||||||||||
| 17 | package Quiq::Trash; | ||||||||||
| 18 | 2 | ▶ | use base qw/Quiq::Hash/; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 19 | |||||||||||
| 20 | 2 | ▶ | use v5.10; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 21 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 22 | 2 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 23 | |||||||||||
| 24 | 2 | our $VERSION = '1.240'; | |||||||||
| 25 | |||||||||||
| 26 | 2 | ▶ | use Quiq::Path; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 27 | 2 | ▶ | use Quiq::Terminal; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 28 | |||||||||||
| 29 | # ----------------------------------------------------------------------------- | ||||||||||
| 30 | |||||||||||
| 31 | =head1 METHODS | ||||||||||
| 32 | |||||||||||
| 33 | =head2 Konstruktor | ||||||||||
| 34 | |||||||||||
| 35 | =head3 new() - Instantiiere Objekt | ||||||||||
| 36 | |||||||||||
| 37 | =head4 Synopsis | ||||||||||
| 38 | |||||||||||
| 39 | $t = $class->new; | ||||||||||
| 40 | $t = $class->new($trashDir); | ||||||||||
| 41 | |||||||||||
| 42 | =head4 Arguments | ||||||||||
| 43 | |||||||||||
| 44 | =over 4 | ||||||||||
| 45 | |||||||||||
| 46 | =item $trashDir (Default: '~/.local/share/Trash') | ||||||||||
| 47 | |||||||||||
| 48 | Pfad zum Trash. | ||||||||||
| 49 | |||||||||||
| 50 | =back | ||||||||||
| 51 | |||||||||||
| 52 | =head4 Returns | ||||||||||
| 53 | |||||||||||
| 54 | Objekt | ||||||||||
| 55 | |||||||||||
| 56 | =head4 Description | ||||||||||
| 57 | |||||||||||
| 58 | Instantiiere ein Objekt der Klasse und liefere dieses zurück. Weicht | ||||||||||
| 59 | der Trash-Pfad vom Standard-Pfad ab, kann dieser als Parameter | ||||||||||
| 60 | gesetzt werden. | ||||||||||
| 61 | |||||||||||
| 62 | =cut | ||||||||||
| 63 | |||||||||||
| 64 | # ----------------------------------------------------------------------------- | ||||||||||
| 65 | |||||||||||
| 66 | 0 | ▶ | sub new { | ||||||||
|
Subroutine
new: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 67 | 0 | my $class = shift; | |||||||||
| 68 | 0 | ▶ | my $trashDir = @_? shift: '~/.local/share/Trash'; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 69 | |||||||||||
| 70 | 0 | return $class->SUPER::new( | |||||||||
| 71 | trashDir => $trashDir, | ||||||||||
| 72 | ); | ||||||||||
| 73 | } | ||||||||||
| 74 | |||||||||||
| 75 | # ----------------------------------------------------------------------------- | ||||||||||
| 76 | |||||||||||
| 77 | =head2 Objektmethoden | ||||||||||
| 78 | |||||||||||
| 79 | =head3 emptyTrash() - Leere Trash | ||||||||||
| 80 | |||||||||||
| 81 | =head4 Synopsis | ||||||||||
| 82 | |||||||||||
| 83 | $t->emptyTrash; | ||||||||||
| 84 | $t->emptyTrash($ask); | ||||||||||
| 85 | |||||||||||
| 86 | =head4 Arguments | ||||||||||
| 87 | |||||||||||
| 88 | =over 4 | ||||||||||
| 89 | |||||||||||
| 90 | =item $ask (Default: 0) | ||||||||||
| 91 | |||||||||||
| 92 | Stelle Rückfrage an den Benutzer, wenn der Trash nicht leer ist. | ||||||||||
| 93 | |||||||||||
| 94 | =back | ||||||||||
| 95 | |||||||||||
| 96 | =head4 Description | ||||||||||
| 97 | |||||||||||
| 98 | Leere den Trash, d.h. lösche I<alle> Dateien aus C<$trashDir/files> und | ||||||||||
| 99 | C<$trashDir/info>. | ||||||||||
| 100 | |||||||||||
| 101 | =cut | ||||||||||
| 102 | |||||||||||
| 103 | # ----------------------------------------------------------------------------- | ||||||||||
| 104 | |||||||||||
| 105 | 0 | ▶ | sub emptyTrash { | ||||||||
|
Subroutine
emptyTrash: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||
| 106 | 0 | my ($self,$ask) = @_; | |||||||||
| 107 | |||||||||||
| 108 | 0 | my $p = Quiq::Path->new; | |||||||||
| 109 | |||||||||||
| 110 | 0 | my $trashDir = $self->trashDir; | |||||||||
| 111 | 0 | ▶ | if ($ask) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 112 | 0 | my $pathA = $p->find("$trashDir/files",-excludeRoot=>1,-sort=>1); | |||||||||
| 113 | 0 | ▶ | if (@$pathA) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 114 | 0 | say join "\n",@$pathA; | |||||||||
| 115 | 0 | my $answ = Quiq::Terminal->askUser( | |||||||||
| 116 | 'Delete existing trash files?', | ||||||||||
| 117 | -values => 'y/n', | ||||||||||
| 118 | -default => 'y', | ||||||||||
| 119 | ); | ||||||||||
| 120 | 0 | ▶ | if ($answ eq 'n') { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 121 | 0 | return; | |||||||||
| 122 | } | ||||||||||
| 123 | } | ||||||||||
| 124 | } | ||||||||||
| 125 | |||||||||||
| 126 | 0 | $p->deleteContent("$trashDir/files"); | |||||||||
| 127 | 0 | $p->deleteContent("$trashDir/info"); | |||||||||
| 128 | |||||||||||
| 129 | 0 | return; | |||||||||
| 130 | } | ||||||||||
| 131 | |||||||||||
| 132 | # ----------------------------------------------------------------------------- | ||||||||||
| 133 | |||||||||||
| 134 | =head3 files() - Liste der im Trash enthaltenen Dateien | ||||||||||
| 135 | |||||||||||
| 136 | =head4 Synopsis | ||||||||||
| 137 | |||||||||||
| 138 | @files | $fileA = $t->files; | ||||||||||
| 139 | |||||||||||
| 140 | =head4 Returns | ||||||||||
| 141 | |||||||||||
| 142 | Liste von Dateien. Im Skalarkontext eine Referenz auf die Liste. | ||||||||||
| 143 | |||||||||||
| 144 | =head4 Description | ||||||||||
| 145 | |||||||||||
| 146 | Liefere die Liste aller im Trash enthaltene Dateien. | ||||||||||
| 147 | |||||||||||
| 148 | =cut | ||||||||||
| 149 | |||||||||||
| 150 | # ----------------------------------------------------------------------------- | ||||||||||
| 151 | |||||||||||
| 152 | 0 | ▶ | sub files { | ||||||||
|
Subroutine
files: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 153 | 0 | my $self = shift; | |||||||||
| 154 | |||||||||||
| 155 | 0 | my $trashDir = $self->trashDir; | |||||||||
| 156 | 0 | my $fileA = Quiq::Path->find("$trashDir/files",-type=>'f',-sort=>1); | |||||||||
| 157 | |||||||||||
| 158 | 0 | ▶ | return wantarray? @$fileA: $fileA; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 159 | } | ||||||||||
| 160 | |||||||||||
| 161 | # ----------------------------------------------------------------------------- | ||||||||||
| 162 | |||||||||||
| 163 | =head1 VERSION | ||||||||||
| 164 | |||||||||||
| 165 | 1.240 | ||||||||||
| 166 | |||||||||||
| 167 | =head1 AUTHOR | ||||||||||
| 168 | |||||||||||
| 169 | Frank Seitz, L<http://fseitz.de/> | ||||||||||
| 170 | |||||||||||
| 171 | =head1 COPYRIGHT | ||||||||||
| 172 | |||||||||||
| 173 | Copyright (C) 2026 Frank Seitz | ||||||||||
| 174 | |||||||||||
| 175 | =head1 LICENSE | ||||||||||
| 176 | |||||||||||
| 177 | This code is free software; you can redistribute it and/or modify | ||||||||||
| 178 | it under the same terms as Perl itself. | ||||||||||
| 179 | |||||||||||
| 180 | =cut | ||||||||||
| 181 | |||||||||||
| 182 | # ----------------------------------------------------------------------------- | ||||||||||
| 183 | |||||||||||
| 184 | 2 | 1; | |||||||||
| 185 | |||||||||||
| 186 | # eof | ||||||||||