Re: NSOpenPanel limited to the Home folder ?
Re: NSOpenPanel limited to the Home folder ?
- Subject: Re: NSOpenPanel limited to the Home folder ?
- From: Stéphane Sudre <email@hidden>
- Date: Tue, 8 Jul 2003 15:22:39 +0200
On mardi, juil 8, 2003, at 14:14 Europe/Paris, Jirome Foucher wrote:
Hi all,
For a kiosk browser I'd like to display an open sheet, but limited to
the Home folder of the user.
The user can navigate inside the Home's content, including inside the
Documents, Music... folders, but cannot go back to /Users or /
I've tried to chroot("/Users/myname") before creating the NSOpenPanel,
but that doesn't work.
Any idea ?
One idea.
Pro:
it looks like to be working like you want it to.
Cons:
The code needs to be improved if the user can select a directory.
The user can see a bit of the file hierarchy before $HOME but can't
select any other path.
------8<-------------8<-------------8<-------------8<-------------
8<-------------8<-------------
/* MainController */
#import <Cocoa/Cocoa.h>
@interface MainController : NSObject
{
IBOutlet id IBwindow_;
}
- (IBAction)showOpenPanel:(id)sender;
- (void)sheetOpenDidEnd:(NSOpenPanel *)sheet returnCode:(int)returnCode
contextInfo:(void *)contextInfo;
@end
-----8<-------------8<-------------8<-------------8<-------------
8<-------------
#import "MainController.h"
@implementation MainController
- (IBAction)showOpenPanel:(id)sender
{
NSOpenPanel *tPanel = [NSOpenPanel openPanel];
[tPanel setDelegate:self];
[tPanel beginSheetForDirectory:NSHomeDirectory()
file:nil
types:nil
modalForWindow:IBwindow_
modalDelegate:self
didEndSelector:@selector(sheetOpenDidEnd:returnCode:contextInfo:)
contextInfo:nil];
}
- (BOOL)panel:(id)sender shouldShowFilename:(NSString *)filename
{
NSArray * fileComponent;
NSArray * homeComponent;
int i,tFileCount,tHomeCount;
fileComponent=[filename pathComponents];
homeComponent=[NSHomeDirectory() pathComponents];
tFileCount=[fileComponent count];
tHomeCount=[homeComponent count];
for(i=0;i<tFileCount && i<tHomeCount;i++)
{
if ([[fileComponent objectAtIndex:i]
isEqualToString:[homeComponent objectAtIndex:i]]==NO)
{
return NO;
}
}
return YES;
}
- (void)sheetOpenDidEnd:(NSOpenPanel *)sheet returnCode:(int)returnCode
contextInfo:(void *)contextInfo
{
if (returnCode == NSOKButton)
{
NSLog([[sheet filenames] description]);
}
}
@end
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.