Created
January 25, 2011 23:41
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/gmusicbrowser.pl b/gmusicbrowser.pl | |
index 032e597..1df52e3 100755 | |
--- a/gmusicbrowser.pl | |
+++ b/gmusicbrowser.pl | |
@@ -757,6 +757,7 @@ our ($RandomMode,$SortFields,$ListMode); | |
our ($SongID,$prevID,$Recent,$RecentPos,$Queue); our $QueueAction=''; | |
our ($Position,$ChangedID,$ChangedPos,@NextSongs,$NextFileToPlay); | |
our ($MainWindow,$FullscreenWindow); my $OptionsDialog; | |
+my @UnmountedFolders; | |
my $TrayIcon; | |
my %Editing; #used to keep track of opened song properties dialog and lyrics dialog | |
our $PlayTime; | |
@@ -4757,10 +4758,12 @@ sub SongsRemove | |
} | |
sub UpdateMasterFilter | |
{ SongAdd_now(); #flush waiting list | |
+ @UnmountedFolders=(); | |
my @diff; | |
$diff[$_]=1 for @$Library; | |
- my $mfilter= $Options{MasterFilterOn} && $Options{MasterFilter} || ''; | |
- my $newlist= Filter->newadd(TRUE,'missing:e:0', $mfilter)->filter_all; | |
+ my $mfilter= $Options{MasterFilterOn} && $Options{MasterFilter} || undef; | |
+ my $unmounted= $Options{ExcludeUnmounted} && UnmountedFolders() || undef; | |
+ my $newlist= Filter->newadd(TRUE,'missing:e:0', $mfilter, $unmounted)->filter_all; | |
$diff[$_]+=2 for @$newlist; | |
my @toadd= grep $diff[$_]==2, @$newlist; | |
my @toremove= grep $diff[$_] && $diff[$_]==1, 0..$#diff; | |
@@ -4769,6 +4772,7 @@ sub UpdateMasterFilter | |
$Library->Replace($newlist); | |
HasChanged(SongsRemoved=> \@toremove); | |
HasChanged(SongsAdded=> \@toadd); | |
+ HasChanged('MasterFilter'); | |
} | |
@@ -5917,6 +5921,8 @@ sub PrefLibrary | |
my $masterfilter= FilterCombo->new( $Options{MasterFilter}, sub { $Options{MasterFilter}=$_[1]; UpdateMasterFilter(); } ); | |
my $masterfiltercheck= NewPrefCheckButton( MasterFilterOn=> _"Use a master filter", widget=>$masterfilter, cb=>\&UpdateMasterFilter, horizontal=>1 ); | |
+ my $exclude_unmounted= NewPrefCheckButton( ExcludeUnmounted=> _"Exclude unmounted folders from the library", tip => UnmountedFolders_desc(), cb=> \&UpdateMasterFilter ); | |
+ Watch( $exclude_unmounted, MasterFilter => sub { $_[0]->set_tooltip_text( UnmountedFolders_desc() ); } ); | |
my $librarysize= Label::Preview->new( | |
event => 'SongsRemoved SongsAdded', | |
preview=> sub | |
@@ -5935,6 +5941,7 @@ sub PrefLibrary | |
$table, | |
$autoremove, | |
$masterfiltercheck, | |
+ $exclude_unmounted, | |
$librarysize, | |
); | |
return $vbox; | |
@@ -5963,6 +5970,35 @@ sub AddPath | |
HasChanged(options=>'LibraryPath') if $changed; | |
} | |
+sub Read_fstab_mtab | |
+{ my $file=shift; | |
+ open my($fh),'<',$file or do {warn "Can't open $file\n"; return}; | |
+ my @found; | |
+ while (<$fh>) | |
+ { next if m/^\s*#/; | |
+ next unless m/\s*\S+\s+(\/\S+)/; | |
+ my $f=$1; | |
+ $f=~s#\\040# #g; #unescape spaces | |
+ $f=~s#//+#/#g; | |
+ $f=~s#/+$##; | |
+ push @found,$f; | |
+ } | |
+ return @found; | |
+} | |
+ | |
+sub UnmountedFolders | |
+{ my %folder; | |
+ $folder{$_}=1 for Read_fstab_mtab('/etc/fstab'); | |
+ delete $folder{$_} for Read_fstab_mtab('/etc/mtab'); | |
+ @UnmountedFolders= keys %folder; | |
+ Filter->newadd(TRUE, map("-path:i:$_", @UnmountedFolders)); | |
+} | |
+sub UnmountedFolders_desc | |
+{ @UnmountedFolders=() unless $Options{ExcludeUnmounted}; | |
+ return @UnmountedFolders ? join("\n", _"Excluded folders :", map( filename_to_utf8displayname($_), @UnmountedFolders)) : | |
+ _"No excluded folders"; | |
+} | |
+ | |
sub ToggleLabel #maybe do the toggle in SetLabels #FIXME | |
{ my ($label,$ID,$on)=@_; | |
return unless defined $ID && defined $label; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment