diff --git a/FSNode/FSNodeRepIcons.m b/FSNode/FSNodeRepIcons.m index 58256c9d..f94c1cdf 100644 --- a/FSNode/FSNodeRepIcons.m +++ b/FSNode/FSNodeRepIcons.m @@ -1,6 +1,6 @@ /* FSNodeRepIcons.m * - * Copyright (C) 2005-2016 Free Software Foundation, Inc. + * Copyright (C) 2005-2018 Free Software Foundation, Inc. * * Author: Enrico Sersale * Riccardo Mottola @@ -135,8 +135,7 @@ static unsigned char darkerLUT[256] = { { key = nodepath; } - else if (([node isMountPoint] && [volumes containsObject: nodepath]) - || [volumes containsObject: nodepath]) + else if ([node isMountPoint] || [volumes containsObject: nodepath]) { key = @"disk"; baseIcon = hardDiskIcon; @@ -358,8 +357,7 @@ static unsigned char darkerLUT[256] = { icon = [self darkerIcon: [self iconOfSize: size forNode: node]]; } } else { - if (([node isMountPoint] && [volumes containsObject: [node path]]) - || [volumes containsObject: [node path]]) { + if ([node isMountPoint] || [volumes containsObject: [node path]]) { icon = [self darkerIcon: hardDiskIcon]; } else { icon = [self darkerIcon: [self iconOfSize: size forNode: node]]; diff --git a/GWorkspace/Desktop/GWDesktopManager.h b/GWorkspace/Desktop/GWDesktopManager.h index d270345e..fe25ce42 100644 --- a/GWorkspace/Desktop/GWDesktopManager.h +++ b/GWorkspace/Desktop/GWDesktopManager.h @@ -1,6 +1,6 @@ /* GWDesktopManager.h * - * Copyright (C) 2005-2016 Free Software Foundation, Inc. + * Copyright (C) 2005-2018 Free Software Foundation, Inc. * * Author: Enrico Sersale * Date: January 2005 @@ -186,7 +186,7 @@ typedef enum DockPosition { @interface MPointWatcher : NSObject { - NSMutableArray *volinfo; + NSArray *mountedRemovableVolumes; NSTimer *timer; BOOL active; GWDesktopManager *manager; diff --git a/GWorkspace/Desktop/GWDesktopManager.m b/GWorkspace/Desktop/GWDesktopManager.m index 498f5abd..f8bb5f90 100644 --- a/GWorkspace/Desktop/GWDesktopManager.m +++ b/GWorkspace/Desktop/GWDesktopManager.m @@ -1,8 +1,10 @@ /* GWDesktopManager.m * - * Copyright (C) 2005-2016 Free Software Foundation, Inc. + * Copyright (C) 2005-2018 Free Software Foundation, Inc. + * + * Authors: Enrico Sersale + * Riccardo Mottola * - * Author: Enrico Sersale * Date: January 2005 * * This file is part of the GNUstep GWorkspace application @@ -866,97 +868,84 @@ static GWDesktopManager *desktopManager = nil; - (void)dealloc { - if (timer && [timer isValid]) { - [timer invalidate]; - } - RELEASE (volinfo); - [super dealloc]; + if (timer && [timer isValid]) + { + [timer invalidate]; + } + + RELEASE (mountedRemovableVolumes); + [super dealloc]; } - (id)initForManager:(GWDesktopManager *)mngr { self = [super init]; - if (self) { - manager = mngr; - volinfo = [NSMutableArray new]; - active = NO; - fm = [NSFileManager defaultManager]; - - timer = [NSTimer scheduledTimerWithTimeInterval: 1.0 - target: self - selector: @selector(watchMountPoints:) - userInfo: nil - repeats: YES]; - } + if (self) + { + manager = mngr; + active = NO; + fm = [NSFileManager defaultManager]; + + timer = [NSTimer scheduledTimerWithTimeInterval: 1.5 + target: self + selector: @selector(watchMountPoints:) + userInfo: nil + repeats: YES]; + } return self; } - (void)startWatching { - NSSet *volumes = [[FSNodeRep sharedInstance] volumes]; - NSEnumerator *enumerator = [volumes objectEnumerator]; - NSString *path; - - [volinfo removeAllObjects]; - - while ((path = [enumerator nextObject])) { - NSDictionary *attributes = [fm fileAttributesAtPath: path traverseLink: NO]; - - if (attributes) { - NSDate *moddate = [attributes fileModificationDate]; - NSMutableDictionary *dict = [NSMutableDictionary dictionary]; - - [dict setObject: path forKey: @"path"]; - [dict setObject: moddate forKey: @"moddate"]; - - [volinfo addObject: dict]; - } - } - + [mountedRemovableVolumes release]; + mountedRemovableVolumes = [[NSWorkspace sharedWorkspace] mountedRemovableMedia]; + [mountedRemovableVolumes retain]; active = YES; } - (void)stopWatching { active = NO; - [volinfo removeAllObjects]; + [mountedRemovableVolumes release]; + mountedRemovableVolumes = nil; } - (void)watchMountPoints:(id)sender { - if (active) { - int count = [volinfo count]; - BOOL changed = NO; - NSUInteger i; - - for (i = 0; i < count; i++) { - NSMutableDictionary *dict = [volinfo objectAtIndex: i]; - NSString *path = [dict objectForKey: @"path"]; - NSDate *moddate = [dict objectForKey: @"moddate"]; - NSDictionary *attributes = [fm fileAttributesAtPath: path traverseLink: NO]; - - if (attributes) { - NSDate *lastmod = [attributes fileModificationDate]; - - if ([moddate isEqualToDate: lastmod] == NO) { - [dict setObject: lastmod forKey: @"moddate"]; - changed = YES; - } - - } else { - [volinfo removeObjectAtIndex: i]; - count--; - i--; - changed = YES; - } - } - - if (changed) { - [manager mountedVolumesDidChange]; + if (active) + { + BOOL removed = NO; + BOOL added = NO; + NSUInteger i; + NSArray *newVolumes = [[NSWorkspace sharedWorkspace] mountedRemovableMedia]; + + for (i = 0; i < [mountedRemovableVolumes count]; i++) + { + NSString *vol; + + vol = [mountedRemovableVolumes objectAtIndex:i]; + if (![newVolumes containsObject:vol]) + removed |= YES; + } + + for (i = 0; i < [newVolumes count]; i++) + { + NSString *vol; + + vol = [newVolumes objectAtIndex:i]; + if (![mountedRemovableVolumes containsObject:vol]) + added |= YES; + } + + if (added || removed) + [manager mountedVolumesDidChange]; + + [mountedRemovableVolumes release]; + mountedRemovableVolumes = newVolumes; + [mountedRemovableVolumes retain]; } - } } @end diff --git a/GWorkspace/Desktop/GWDesktopView.m b/GWorkspace/Desktop/GWDesktopView.m index 402e948c..597a0440 100644 --- a/GWorkspace/Desktop/GWDesktopView.m +++ b/GWorkspace/Desktop/GWDesktopView.m @@ -159,9 +159,6 @@ if ([mountedVolumes isEqual: rvpaths] == NO) { NSUInteger count = [icons count]; int i; - - [mountedVolumes removeAllObjects]; - [mountedVolumes addObjectsFromArray: rvpaths]; for (i = 0; i < count; i++) { FSNIcon *icon = [icons objectAtIndex: i]; @@ -173,14 +170,15 @@ } } + [mountedVolumes removeAllObjects]; + [mountedVolumes addObjectsFromArray: rvpaths]; + for (i = 0; i < [mountedVolumes count]; i++) { NSString *vpath = [mountedVolumes objectAtIndex: i]; if ([vpath isEqual: path_separator()] == NO) { - FSNode *vnode = [FSNode nodeWithPath: vpath]; - [vnode setMountPoint: YES]; - [self addRepForSubnode: vnode]; + [self newVolumeMountedAtPath:vpath]; } }