JBoolean
JXChooseFileDialog::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->GoToSelectedDirectory())
    {
        return kJFalse;
    }

    JPtrArray<JDirEntry> entryList(JPtrArrayT::kDeleteAll);
    if (fileBrowser->GetSelection(&entryList))
    {
        const JSize count = entryList.GetElementCount();
        for (JIndex i=1; i<=count; i++)
        {
            JDirEntry* entry = entryList.NthElement(i);
            entry->ForceUpdate();	// check that link hasn't been broken behind our back
            if (!entry->IsFile())
            {
                (GetDirInfo())->ForceUpdate();
                return kJFalse;
            }
        }
        return kJTrue;
    }
    else
    {
        return kJFalse;
    }
}
Beispiel #2
0
JBoolean
JDirInfo::IsVisible
	(
	const JDirEntry& entry
	)
	const
{
	const JDirEntry::Type type = entry.GetType();
	const JString& name        = entry.GetName();

	if (!itsShowHiddenFlag && name.GetFirstCharacter() == '.' && name != "..")
		{
		return kJFalse;
		}

	if (!itsShowVCSDirsFlag && JIsVCSDirectory(name))
		{
		return kJFalse;
		}

	if (type == JDirEntry::kDir || type == JDirEntry::kDirLink)
		{
		return JI2B(itsShowDirsFlag &&
					(!itsFilterDirsFlag || MatchesNameFilter(entry)) &&
					MatchesDirEntryFilter(entry));
		}
	else if (type == JDirEntry::kFile || type == JDirEntry::kFileLink ||
			 type == JDirEntry::kBrokenLink)
		{
		return JI2B(itsShowFilesFlag &&
					MatchesNameFilter(entry) &&
					MatchesDirEntryFilter(entry));
		}
	else if (type == JDirEntry::kUnknown || type == JDirEntry::kUnknownLink)
		{
		return JI2B(itsShowOthersFlag &&
					MatchesNameFilter(entry) &&
					MatchesDirEntryFilter(entry));
		}
	else if (type == JDirEntry::kDoesNotExist)
		{
		return kJFalse;
		}
	else
		{
		assert( 0 );	// this should never happen
		return kJFalse;
		}
}
JBoolean
JDirInfo::MatchesContentFilter
	(
	const JDirEntry& entry
	)
	const
{
	if (itsContentRegex == NULL || entry.IsDirectory())
		{
		return kJTrue;
		}
	else
		{
		return entry.MatchesContentFilter(*itsContentRegex);
		}
}
GPMProcessEntry::GPMProcessEntry
	(
	JTree*				tree,
	const JDirEntry&	entry
	)
	:
	JNamedTreeNode(tree, "", kJFalse),
	itsLastUTime(0),
	itsLastSTime(0)
{
	itsProcPath = entry.GetFullName();
	itsUID      = entry.GetUserID();
	itsUser     = entry.GetUserName();
	
	JUInt value;
	entry.GetName().ConvertToUInt(&value);
	itsPID = value;
}
JBoolean
JDirInfo::MatchesNameFilter
	(
	const JDirEntry& entry
	)
	const
{
	if (itsNameRegex != NULL)
		{
		const JString& name = entry.GetName();
		JBoolean match      = itsNameRegex->Match(name);
		if (itsInvertNameRegexFlag)
			{
			match = !match;
			}
		return match;
		}
	else
		{
		return kJTrue;
		}
}
JBoolean
MatchesCookie
	(
	const JCharacter*	cookie,
	const JDirEntry&	entry
	)
{
	JString file = entry.GetFullName();
	if (!JFileReadable(file))
		{
		return kJFalse;
		}

	mode_t perms;
	JError err = JGetPermissions(file, &perms);
	if (!err.OK())
		{
		perms = 0600;
		}
	ifstream is(file);
	is >> ws;
	JString line1 = JReadLine(is);
	is.close();
	if (line1 == "")
		{
		return kJTrue;
		}
	JArray<JIndexRange> subList;
	JRegex regex;
	err = regex.SetPattern(cookie);
	JBoolean matched = regex.Match(line1, &subList);
	if (matched)
		{
		return kJTrue;
		}
	return kJFalse;
}
void
GAddressBookMgr::AddAddressBook
	(
	const JCharacter*	name,
	JTree*				tree
	)
{
	if (!JFileExists(name))
		{
		return;
		}
	JDirEntry* dirEntry = new JDirEntry(name);
	assert(dirEntry != NULL);
	JTreeNode* jbase = tree->GetRoot();
	JNamedTreeNode* base = dynamic_cast<JNamedTreeNode*>(jbase);
	assert(base != NULL);
	GAddressBookTreeNode* book = new
		GAddressBookTreeNode(dirEntry, base, dirEntry->GetName());
	assert(book != NULL);
	std::ifstream is(name);
	while (is.good())
		{
		JString line = JReadLine(is);
		GAddressBookEntry* entry = new GAddressBookEntry();
		assert( entry != NULL );

		JString name;
		if (GetNextRecord(line, name, is))
			{
			GetNextRecord(line, entry->fullname, is);
			if (GetNextRecord(line, entry->address, is))
				{
				GetNextRecord(line, entry->fcc, is);
				GetNextRecord(line, entry->comment, is);
				itsAddresses->SetElement(name, entry, JPtrArrayT::kDelete);

				GAddressEntryTreeNode* aEntry =
					new GAddressEntryTreeNode(book, entry->fullname);
				assert(aEntry != NULL);
				GAddressItemTreeNode* item =
					new GAddressItemTreeNode(GAddressItemTreeNode::kName,
											 aEntry, name, kJFalse);
				assert(item != NULL);

				JString address = entry->address;
				if (address.BeginsWith("(") && address.GetLength() > 2)
					{
					address = address.GetSubstring(2, address.GetLength() - 1);
					JPtrArray<JString> list(JPtrArrayT::kForgetAll);
					GParseNameList(address, list);
					const JSize count = list.GetElementCount();
					for (JSize i = count; i >= 1; i--)
						{
						item =
							new GAddressItemTreeNode(GAddressItemTreeNode::kEMail,
													 aEntry, *(list.NthElement(i)), kJFalse);
						assert(item != NULL);
						}
					list.DeleteAll();
					}
				else
					{
					item =
						new GAddressItemTreeNode(GAddressItemTreeNode::kEMail,
												 aEntry, address, kJFalse);
					}

				if (!entry->comment.IsEmpty())
					{
					item =
						new GAddressItemTreeNode(GAddressItemTreeNode::kComment,
												 aEntry, entry->comment, kJFalse);
					assert(item != NULL);
					}

				if (!entry->fcc.IsEmpty())
					{
					item =
						new GAddressItemTreeNode(GAddressItemTreeNode::kFcc,
												 aEntry, entry->fcc, kJFalse);
					assert(item != NULL);
					}

				book->InsertSorted(aEntry);

				continue;
				}
			}
		delete entry;
		}
}