As suggested by Rene and Jerome, switch to BDirectory::Contains(),

which is way cleaner.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@39806 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Philippe Houdoin 2010-12-10 15:48:05 +00:00
parent 784263e28a
commit fda6d9ab6f
3 changed files with 26 additions and 36 deletions

View File

@ -158,14 +158,14 @@ class TrashMonitor : public BHandler {
}
if (opcode == B_ENTRY_MOVED) {
entry_ref entry;
entry_ref ref;
const char* name;
msg->FindInt64("to directory", &entry.directory);
msg->FindInt32("device", &entry.device);
msg->FindInt64("to directory", &ref.directory);
msg->FindInt32("device", &ref.device);
msg->FindString("name", &name);
entry.set_name(name);
ref.set_name(name);
BNode node(&entry);
BNode node(&ref);
int32 chain;
// check it's a mail
@ -179,7 +179,7 @@ class TrashMonitor : public BHandler {
// check if it was moved to trash
bool moved_to_trash = false;
BPath trashPath;
BPath entryPath(&entry);
BEntry entry(&ref);
BVolumeRoster volumes;
BVolume volume;
while (volumes.GetNextVolume(&volume) == B_OK) {
@ -189,8 +189,8 @@ class TrashMonitor : public BHandler {
continue;
}
if (strncmp(entryPath.Path(), trashPath.Path(),
strlen(trashPath.Path())) == 0) {
BDirectory trash(trashPath.Path());
if (trash.Contains(&entry)) {
moved_to_trash = true;
break;
}

View File

@ -126,22 +126,17 @@ void DeskbarView::AttachedToWindow()
}
bool DeskbarView::_EntryInTrash(const entry_ref* entry)
bool DeskbarView::_EntryInTrash(const entry_ref* ref)
{
BPath trashPath;
BPath entryPath(entry);
BVolume volume(entry->device);
if (volume.InitCheck() == B_OK
&& find_directory(B_TRASH_DIRECTORY, &trashPath, false,
&volume) == B_OK) {
char path[PATH_MAX];
strncpy(path, trashPath.Path(), sizeof(path));
strncat(path, "/", sizeof(path));
if (strncmp(entryPath.Path(), path, strlen(path)) == 0)
return true;
}
BEntry entry(ref);
BVolume volume(ref->device);
BPath path;
if (volume.InitCheck() != B_OK
|| find_directory(B_TRASH_DIRECTORY, &path, false, &volume) != B_OK)
return false;
return false;
BDirectory trash(path.Path());
return trash.Contains(&entry);
}

View File

@ -14,6 +14,7 @@
#include <Button.h>
#include <ChainRunner.h>
#include <Deskbar.h>
#include <Directory.h>
#include <File.h>
#include <FindDirectory.h>
#include <fs_index.h>
@ -633,22 +634,16 @@ bool
MailDaemonApp::_IsEntryInTrash(BEntry& entry)
{
entry_ref ref;
entry.GetRef(&ref);
BPath trashPath;
BPath entryPath(&entry);
BVolume volume(ref.device);
if (volume.InitCheck() == B_OK
&& find_directory(B_TRASH_DIRECTORY, &trashPath,
false, &volume) == B_OK) {
char path[PATH_MAX];
strncpy(path, trashPath.Path(), sizeof(path));
strncat(path, "/", sizeof(path));
if (strncmp(entryPath.Path(), path, strlen(path)) == 0)
return true;
}
return false;
BVolume volume(ref.device);
BPath path;
if (volume.InitCheck() != B_OK
|| find_directory(B_TRASH_DIRECTORY, &path, false, &volume) != B_OK)
return false;
BDirectory trash(path.Path());
return trash.Contains(&entry);
}