예제 #1
0
JBoolean
JGetTempDirectory
	(
	JString* tempDir
	)
{
	// inside function to keep gcc 3.3.3 (cygwin) happy
	static JBoolean theTempPathInitFlag = kJFalse;
	static JString theTempPath;

	if (!theTempPathInitFlag)
		{
		char* path = getenv("TMPDIR");
		if (!JStringEmpty(path) && JDirectoryWritable(path))
			{
			theTempPath = path;
			}
		else if (P_tmpdir != NULL && JDirectoryWritable(P_tmpdir))
			{
			theTempPath = P_tmpdir;
			}
		else
			{
			theTempPath = "/tmp/";
			}

		JAppendDirSeparator(&theTempPath);
		theTempPathInitFlag = kJTrue;
		}

	*tempDir = theTempPath;
	return kJTrue;
}
JColorIndex
JXPathInput::GetTextColor
	(
	const JCharacter*	path,
	const JCharacter*	base,
	const JBoolean		requireWrite,
	const JColormap*	colormap
	)
{
	if (JStringEmpty(path))
		{
		return colormap->GetBlackColor();
		}

	JString fullPath;
	if ((JIsAbsolutePath(path) || !JStringEmpty(base)) &&
		JConvertToAbsolutePath(path, base, &fullPath) &&
		JDirectoryReadable(fullPath) &&
		JCanEnterDirectory(fullPath) &&
		(!requireWrite || JDirectoryWritable(fullPath)))
		{
		return colormap->GetBlackColor();
		}
	else
		{
		return colormap->GetRedColor();
		}
}
예제 #3
0
JXImage*
SyGGetDirectorySmallIcon
	(
	const JCharacter* path
	)
{
	JMountType type;
	JXImage* image;
	if ((SyGGetApplication())->IsMountPoint(path, &type) &&
		SyGGetMountPointSmallIcon(type, &image))
		{
		return image;
		}
	else if (SyGIsTrashDirectory(path))
		{
		return SyGGetTrashSmallIcon();
		}
	else if (!JFSFileTreeNode::CanHaveChildren(path))
		{
		return SyGGetLockedFolderSmallIcon();
		}
	else if (!JDirectoryWritable(path))
		{
		return SyGGetReadOnlyFolderSmallIcon();
		}
	else
		{
		return SyGGetFolderSmallIcon();
		}
}
JBoolean
JDirInfo::Update
	(
	const JBoolean force
	)
{
	ACE_stat info;
	if (force ||
		ACE_OS::lstat(*itsCWD, &info) != 0 ||
		ACE_OS::stat(*itsCWD, &info) != 0  ||
		itsModTime != (time_t) info.st_mtime)
		{
		ForceUpdate();
		return kJTrue;
		}
	else if (itsStatusTime != (time_t) info.st_ctime &&
			 JDirectoryReadable(*itsCWD))
		{
		itsStatusTime     = info.st_ctime;
		itsIsWritableFlag = JDirectoryWritable(*itsCWD);
		Broadcast(PermissionsChanged());
		return kJTrue;
		}
	else if (itsStatusTime != (time_t) info.st_ctime)
		{
		ForceUpdate();
		return kJTrue;
		}
	else
		{
		return kJFalse;
		}
}
예제 #5
0
JXImage*
JXCurrentPathMenu::GetIcon
	(
	const JCharacter* path
	)
	const
{
	return (JDirectoryWritable(path) ? itsFolderIcon : itsReadOnlyFolderIcon);
}
JError
JDirInfo::BuildInfo()
{
	if (!JDirectoryReadable(*itsCWD))
		{
		return JAccessDenied(*itsCWD);
		}

	const JString origDir = JGetCurrentDirectory();

	JError err = JChangeDirectory(*itsCWD);
	if (!err.OK())
		{
		return err;
		}

	// clear old information

	itsDirEntries->CleanOut();

	// update instance variables

	JStripTrailingDirSeparator(itsCWD);		// keep Windows happy

	ACE_stat stbuf;
	ACE_OS::stat(*itsCWD, &stbuf);
	itsIsValidFlag    = kJTrue;
	itsIsWritableFlag = JDirectoryWritable(*itsCWD);
	itsModTime        = stbuf.st_mtime;
	itsStatusTime     = stbuf.st_ctime;

	JAppendDirSeparator(itsCWD);

	// process files in the directory

	JLatentPG pg(itsContentRegex == NULL ? 100 : 10);
	if (itsPG != NULL)
		{
		pg.SetPG(itsPG, kJFalse);
		}
	pg.VariableLengthProcessBeginning("Scanning directory...", kJTrue, kJFalse);

	BuildInfo1(pg);

	pg.ProcessFinished();

	err = JChangeDirectory(origDir);
	assert_ok( err );

	ApplyFilters(kJFalse);
	return JNoError();
}
JBoolean
JXPathInput::GetPath
	(
	JString* path
	)
	const
{
	const JString& text = GetText();
	return JI2B(!text.IsEmpty() &&
				(JIsAbsolutePath(text) || HasBasePath()) &&
				JConvertToAbsolutePath(text, itsBasePath, path) &&
				JDirectoryExists(*path) &&
				JDirectoryReadable(*path) &&
				JCanEnterDirectory(*path) &&
				(!itsRequireWriteFlag || JDirectoryWritable(*path)));
}
JFSBindingList*
JFSBindingList::Create
	(
	const JCharacter** needUserCheck
	)
{
	JString signalFileName, path, name;
	if (JExpandHomeDirShortcut(kSignalFileName, &signalFileName))
		{
		JSplitPathAndName(signalFileName, &path, &name);
		if ((JCreateDirectory(path, 0700)).OK() && JDirectoryWritable(path))
			{
			JFSBindingList* list = new JFSBindingList(signalFileName, needUserCheck);
			assert( list != NULL );
			return list;
			}
		}

	JFSBindingList* list = new JFSBindingList("", needUserCheck);
	assert( list != NULL );
	return list;
}
예제 #9
0
JIndex
SyGGetMountPointLargeIcon
	(
	const JCharacter*	path,
	SyGFileTreeList*	fileList,
	JXPM*				plainIcon,
	JXPM*				selectedIcon
	)
{
	JMountType type;
	const JBoolean isMP = theApplication->IsMountPoint(path, &type);

	if (!isMP)
		{
		JBoolean writable, isTop;
		JString device, fsTypeString;
		JFileSystemType fsType;
		if (JIsMounted(path, &writable, &isTop, &device, &fsType, &fsTypeString))
			{
			type = JGetUserMountPointType(path, device, fsTypeString);
			}
		else
			{
			type = kJHardDisk;
			}
		}

	const JBoolean writable = JDirectoryWritable(path);

	JString dir;
	if (JGetHomeDirectory(&dir) && JSameDirEntry(dir, path))
		{
		*plainIcon    = syg_home_folder_large;
		*selectedIcon = syg_home_folder_selected_large;
		return 1;
		}
	else if (SyGIsTrashDirectory(path))
		{
		(fileList->GetSyGFileTree())->Update();
		if (fileList->IsEmpty())
			{
			*plainIcon    = jx_trash_can_empty_large;
			*selectedIcon = jx_trash_can_empty_selected_large;
			return 2;
			}
		else
			{
			*plainIcon    = jx_trash_can_full_large;
			*selectedIcon = jx_trash_can_full_selected_large;
			return 3;
			}
		}
	else if (!isMP && type == kJFloppyDisk && !writable)
		{
		*plainIcon    = syg_floppy_folder_read_only_large;
		*selectedIcon = syg_floppy_folder_read_only_large;
		return 4;
		}
	else if (!isMP && type == kJFloppyDisk)
		{
		*plainIcon    = syg_floppy_folder_large;
		*selectedIcon = syg_floppy_folder_large;
		return 5;
		}
	else if (!isMP && type == kJCDROM && !writable)
		{
		*plainIcon    = syg_cdrom_folder_read_only_large;
		*selectedIcon = syg_cdrom_folder_read_only_large;
		return 4;
		}
	else if (!isMP && type == kJCDROM)
		{
		*plainIcon    = syg_cdrom_folder_large;
		*selectedIcon = syg_cdrom_folder_large;
		return 5;
		}
	else if (!isMP && !writable)
		{
		*plainIcon    = jx_folder_read_only_large;
		*selectedIcon = jx_folder_read_only_selected_large;
		return 6;
		}
	else if (!isMP)
		{
		*plainIcon    = jx_folder_large;
		*selectedIcon = jx_folder_selected_large;
		return 7;
		}
	else if (type == kJFloppyDisk)
		{
		*plainIcon    = jx_floppy_disk_large;
		*selectedIcon = jx_floppy_disk_selected_large;
		return 8;
		}
	else if (type == kJCDROM)
		{
		*plainIcon    = jx_cdrom_disk_large;
		*selectedIcon = jx_cdrom_disk_selected_large;
		return 9;
		}
	else
		{
		*plainIcon    = jx_hard_disk_large;
		*selectedIcon = jx_hard_disk_selected_large;
		return 11;
		}
}
예제 #10
0
JBoolean
JXPathInput::InputValid()
{
	if (itsAllowInvalidPathFlag)
		{
		return kJTrue;
		}
	else if (!JXInputField::InputValid())
		{
		return kJFalse;
		}

	const JString& text = GetText();
	if (text.IsEmpty())		// paranoia -- JXInputField should have reported
		{
		return !IsRequired();
		}

	JString path;
	if (JIsRelativePath(text) && !HasBasePath())
		{
		(JGetUserNotification())->ReportError(JGetString(kNoRelPathID));
		RecalcAll(kJTrue);
		return kJFalse;
		}
	if (!JConvertToAbsolutePath(text, itsBasePath, &path))
		{
		(JGetUserNotification())->ReportError(JGetString(kInvalidPathID));
		RecalcAll(kJTrue);
		return kJFalse;
		}

	const JString currDir = JGetCurrentDirectory();
	const JError err      = JChangeDirectory(path);
	JChangeDirectory(currDir);

	if (err.OK())
		{
		if (!JDirectoryReadable(path))
			{
			(JGetUserNotification())->ReportError(JGetString(kUnreadableID));
			RecalcAll(kJTrue);
			return kJFalse;
			}
		else if (itsRequireWriteFlag && !JDirectoryWritable(path))
			{
			(JGetUserNotification())->ReportError(JGetString(kUnwritableID));
			RecalcAll(kJTrue);
			return kJFalse;
			}
		else
			{
			return kJTrue;
			}
		}

	const JCharacter* errID;
	if (err == kJAccessDenied)
		{
		errID = kAccessDeniedID;
		}
	else if (err == kJBadPath)
		{
		errID = kBadPathID;
		}
	else if (err == kJComponentNotDirectory)
		{
		errID = kCompNotDirID;
		}
	else
		{
		errID = kInvalidDirID;
		}

	(JGetUserNotification())->ReportError(JGetString(errID));
	RecalcAll(kJTrue);
	return kJFalse;
}
JBoolean
JXSaveFileDialog::OKToDeactivate()
{
	if (!JXCSFDialogBase::OKToDeactivate())
		{
		return kJFalse;
		}
	else if (Cancelled())
		{
		return kJTrue;
		}

	JXPathInput* pathInput = GetPathInput();
	if (pathInput->HasFocus())
		{
		GoToItsPath();
		return kJFalse;
		}

	JXInputField* filterInput = GetFilterInput();
	if (filterInput->HasFocus())
		{
		AdjustFilter();
		return kJFalse;
		}

	JXDirTable* fileBrowser = GetFileBrowser();
	if (fileBrowser->HasFocus() && fileBrowser->GoToSelectedDirectory())
		{
		return kJFalse;
		}

	const JString& fileName = itsFileNameInput->GetText();
	if (fileName.IsEmpty())
		{
		(JGetUserNotification())->ReportError("You need to enter a file name.");
		return kJFalse;
		}

	const JString& path     = GetPath();
	const JString fullName  = path + fileName;

	const JBoolean fileExists = JFileExists(fullName);

	if (JDirectoryExists(fullName))
		{
		(JGetUserNotification())->ReportError(
			"This name is already used for a directory.");
		return kJFalse;
		}
	else if (!JDirectoryWritable(path) && !fileExists)
		{
		(JGetUserNotification())->ReportError(
			"You are not allowed to write to this directory.");
		return kJFalse;
		}
	else if (!fileExists)
		{
		*itsFileName = fileName;
		return kJTrue;
		}
	else if (!JFileWritable(fullName))
		{
		(JGetUserNotification())->ReportError(
			"You are not allowed to write to this file.");
		return kJFalse;
		}
	else if ((JGetUserNotification())->AskUserNo("That file already exists.  Replace it?"))
		{
		*itsFileName = fileName;
		return kJTrue;
		}
	else
		{
		return kJFalse;
		}
}
예제 #12
0
JString
JGetClosestDirectory
	(
	const JCharacter*	origDirName,
	const JBoolean		requireWrite,
	const JCharacter*	basePath
	)
{
	assert( !JStringEmpty(origDirName) );

	JString workingDir;
	if (!JStringEmpty(basePath))
		{
		workingDir = basePath;
		JAppendDirSeparator(&workingDir);
		}
	else
		{
		workingDir = JGetCurrentDirectory();
		}

	JString dirName = origDirName;
	JString homeDir;
	JSize homeLength;
	if (origDirName[0] == '~' &&
		!JExpandHomeDirShortcut(origDirName, &dirName, &homeDir, &homeLength))
		{
		return JGetRootDirectory();
		}
	else if (JIsRelativePath(origDirName))
		{
		dirName.Prepend(workingDir);
		}

	assert( !JIsRelativePath(dirName) );

	JString newDir, junkName;
	while (!JDirectoryExists(dirName)   ||
		   !JCanEnterDirectory(dirName) ||
		   !JDirectoryReadable(dirName) ||
		   (requireWrite && !JDirectoryWritable(dirName)))
		{
		JStripTrailingDirSeparator(&dirName);
		if (JIsRootDirectory(dirName))
			{
			break;
			}
		JSplitPathAndName(dirName, &newDir, &junkName);
		dirName = newDir;
		}

	// convert back to partial path, if possible

	if (origDirName[0] == '~' &&
		dirName.BeginsWith(homeDir))
		{
		dirName.ReplaceSubstring(1, homeDir.GetLength(), origDirName, homeLength);
		}
	else if (JIsRelativePath(origDirName) &&
			 dirName.GetLength() > workingDir.GetLength() &&
			 dirName.BeginsWith(workingDir))
		{
		dirName.RemoveSubstring(1, workingDir.GetLength());
		}

	return dirName;
}
JBoolean
CBFileNameDisplay::InputValid()
{
	const JString& text = GetText();
	if (itsUnfocusAction == kCancel)
		{
		return kJTrue;
		}
	else if (text.IsEmpty())
		{
		(JGetUserNotification())->ReportError(JGetString(kEmptyErrorID));
		return kJFalse;
		}
	else if (text.EndsWith(ACE_DIRECTORY_SEPARATOR_STR))
		{
		(JGetUserNotification())->ReportError(JGetString(kNoFileNameID));
		return kJFalse;
		}
	else if (JIsRelativePath(text))
		{
		return kJTrue;	// open Choose File dialog
		}

	JString path, fullPath, name;
	JSplitPathAndName(text, &path, &name);
	if (!JExpandHomeDirShortcut(path, &fullPath))
		{
		return kJFalse;
		}

	const JString fullName = JCombinePathAndName(fullPath, name);
	JBoolean onDisk;
	const JString origFullName = itsDoc->GetFullName(&onDisk);
	if (onDisk && JSameDirEntry(origFullName, fullName))
		{
		itsUnfocusAction = kCancel;
		return kJTrue;
		}

	if (JFileExists(fullName))
		{
		const JCharacter* map[] =
			{
			"f", text
			};
		const JString msg = JGetString(kOKToReplaceID, map, sizeof(map));
		if (!(JGetUserNotification())->AskUserNo(msg))
			{
			return kJFalse;
			}
		}

	if (!JDirectoryExists(fullPath))
		{
		const JError err = JCreateDirectory(fullPath);
		if (!err.OK())
			{
			err.ReportIfError();
			return kJFalse;
			}
		}
	else if (!JDirectoryWritable(fullPath))
		{
		const JError err = JAccessDenied(fullPath);
		err.ReportIfError();
		return kJFalse;
		}

	if (itsUnfocusAction == kRename)
		{
		const JError err = JRenameVCS(origFullName, fullName);
		err.ReportIfError();
		return err.OK();
		}
	else
		{
		return kJTrue;
		}
}