[haiku-commits] r39806 - in haiku/trunk/src: kits/mail servers/mail

  • From: philippe.houdoin@xxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Fri, 10 Dec 2010 16:48:05 +0100 (CET)

Author: phoudoin
Date: 2010-12-10 16:48:05 +0100 (Fri, 10 Dec 2010)
New Revision: 39806
Changeset: http://dev.haiku-os.org/changeset/39806

Modified:
   haiku/trunk/src/kits/mail/MailProtocol.cpp
   haiku/trunk/src/servers/mail/DeskbarView.cpp
   haiku/trunk/src/servers/mail/main.cpp
Log:
As suggested by Rene and Jerome, switch to BDirectory::Contains(),
which is way cleaner.


Modified: haiku/trunk/src/kits/mail/MailProtocol.cpp
===================================================================
--- haiku/trunk/src/kits/mail/MailProtocol.cpp  2010-12-10 15:26:27 UTC (rev 
39805)
+++ haiku/trunk/src/kits/mail/MailProtocol.cpp  2010-12-10 15:48:05 UTC (rev 
39806)
@@ -158,14 +158,14 @@
                        }
 
                        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 @@
                                // 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 @@
                                                continue;
                                        }
 
-                                       if (strncmp(entryPath.Path(), 
trashPath.Path(),
-                                               strlen(trashPath.Path())) == 0) 
{
+                                       BDirectory trash(trashPath.Path());
+                                       if (trash.Contains(&entry)) {
                                                moved_to_trash = true;
                                                break;
                                        }

Modified: haiku/trunk/src/servers/mail/DeskbarView.cpp
===================================================================
--- haiku/trunk/src/servers/mail/DeskbarView.cpp        2010-12-10 15:26:27 UTC 
(rev 39805)
+++ haiku/trunk/src/servers/mail/DeskbarView.cpp        2010-12-10 15:48:05 UTC 
(rev 39806)
@@ -126,22 +126,17 @@
 }
 
 
-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);
 }
 
 

Modified: haiku/trunk/src/servers/mail/main.cpp
===================================================================
--- haiku/trunk/src/servers/mail/main.cpp       2010-12-10 15:26:27 UTC (rev 
39805)
+++ haiku/trunk/src/servers/mail/main.cpp       2010-12-10 15:48:05 UTC (rev 
39806)
@@ -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 @@
 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;
-       }
+       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);
 }
 
 


Other related posts:

  • » [haiku-commits] r39806 - in haiku/trunk/src: kits/mail servers/mail - philippe . houdoin