* Adium is the legal property of its developers, whose names are listed in the copyright file included * with this source distribution. * This program is free software; you can redistribute it and/or modify it under the terms of the GNU * General Public License as published by the Free Software Foundation; either version 2 of the License, * or (at your option) any later version. * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General * Public License for more details. * You should have received a copy of the GNU General Public License along with this program; if not, * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #import "AILoginController.h" #import "AILoginWindowController.h" #import <AIUtilities/AIDictionaryAdditions.h> #import <AIUtilities/AIFileManagerAdditions.h> #import <AIUtilities/AIEventAdditions.h> #define PATH_USERS @"/Users" //Path of the users folder #define DEFAULT_USER_NAME @"Default" //The default user name @implementation AILoginController if ((self = [super init])) { - (void)controllerDidLoad - (void)controllerWillClose // Prompts for a user, or automatically selects one - (void)requestUserNotifyingTarget:(id)inTarget selector:(SEL)inSelector NSMutableDictionary *loginDict; NSUInteger argumentIndex; NSString *userName = nil; //Retain the target and selector //Open the login preferences loginDict = [NSMutableDictionary dictionaryAtPath:[adium applicationSupportDirectory] withName:LOGIN_PREFERENCES_FILE_NAME create:YES]; //Make sure that atleast 1 login name is available. If not, create the name 'default' if ([[self userArray] count] == 0) { //Create a 'default' user [self addUser:DEFAULT_USER_NAME]; //Set 'default' as the login of choice [loginDict setObject:DEFAULT_USER_NAME forKey:LOGIN_LAST_USER]; [loginDict asyncWriteToPath:[adium applicationSupportDirectory] withName:LOGIN_PREFERENCES_FILE_NAME]; //Retrieve the desired user from the command line if possible arguments = [[NSProcessInfo processInfo] arguments]; if (arguments && ([arguments count] > 1)) { argumentIndex = [arguments indexOfObject:@"--user"]; if ((argumentIndex != NSNotFound) && ([arguments count] > argumentIndex + 1)) { userName = [[[arguments objectAtIndex:argumentIndex+1] copy] autorelease]; If we don't have a userName yet, show the login select window if: - We should always show it - LOGIN_LAST_USER does not indicate a valid user BOOL userRequestedShowWindow = NO; shouldShowWindow = [NSEvent optionKey]; shouldShowWindow = (userRequestedShowWindow = [[loginDict objectForKey:LOGIN_SHOW_WINDOW] boolValue]); /* Support a different default user for 'Debug' builds but not for 'Release-Debug' builds. * The former are for developers, who may want this behavior. * The latter are for beta testers, who are more likely to be just confused (as per #14432). userName = [loginDict objectForKey:LOGIN_LAST_USER_DEBUG]; shouldShowWindow = ((userName = [loginDict objectForKey:LOGIN_LAST_USER]) == nil); loginWindowController = [[AILoginWindowController loginWindowControllerWithOwner:self] retain]; [loginWindowController showWindow:nil]; //If the user always wants to see the window, disable the login timeout if (userRequestedShowWindow) [loginWindowController disableLoginTimeout]; [self loginAsUser:userName]; // Returns the current user's Adium home directory - (NSString *)userDirectory - (NSString *)currentUser // Sets the correct user directory and sends out a login message - (void)loginAsUser:(NSString *)userName NSParameterAssert(userName != nil); if (loginWindowController) { [loginWindowController closeWindow:nil]; [loginWindowController release]; loginWindowController = nil; //Save the user directory currentUser = [userName retain]; userDirectory = [[[[adium applicationSupportDirectory] stringByAppendingPathComponent:PATH_USERS] stringByAppendingPathComponent:userName] retain]; //Tell Adium to complete login [target performSelector:selector]; // Creates and returns a mutable array of the login users NSString *userPath = [[adium applicationSupportDirectory] stringByAppendingPathComponent:PATH_USERS]; NSMutableArray *userArray = [NSMutableArray array]; for (NSString *path in [[NSFileManager defaultManager] contentsOfDirectoryAtPath:userPath error:NULL]) { //Fetch the names of all directories if ([[NSFileManager defaultManager] fileExistsAtPath:[userPath stringByAppendingPathComponent:path] isDirectory:&isDirectory]) { [userArray addObject:[path lastPathComponent]]; - (void)deleteUser:(NSString *)inUserName NSParameterAssert(inUserName != nil); //Create the source and dest paths sourcePath = [[[adium applicationSupportDirectory] stringByAppendingPathComponent:PATH_USERS] stringByAppendingPathComponent:inUserName]; [[NSFileManager defaultManager] trashFileAtPath:sourcePath]; // Add a user with the specified name - (void)addUser:(NSString *)inUserName NSParameterAssert(inUserName != nil); userPath = [[[adium applicationSupportDirectory] stringByAppendingPathComponent:PATH_USERS] stringByAppendingPathComponent:inUserName]; //Create a folder for the new user [[NSFileManager defaultManager] createDirectoryAtPath:userPath withIntermediateDirectories:YES attributes:nil error:NULL]; // Rename an existing user - (void)renameUser:(NSString *)oldName to:(NSString *)newName NSString *sourcePath, *destPath; NSParameterAssert(oldName != nil); NSParameterAssert(newName != nil); //Create the source and dest paths sourcePath = [[[adium applicationSupportDirectory] stringByAppendingPathComponent:PATH_USERS] stringByAppendingPathComponent:oldName]; destPath = [[[adium applicationSupportDirectory] stringByAppendingPathComponent:PATH_USERS] stringByAppendingPathComponent:newName]; //Rename the user's folder (by moving it to a path with a different name) [[NSFileManager defaultManager] moveItemAtPath:sourcePath toPath:destPath error:NULL];