mountvolume: open mounted images/volumes in Tracker.

* This can be done from the command line using the new "-open" option.
* When the application is invoked via Tracker, ie. by double clicking
  on an image, then it's being used implicitly.
This commit is contained in:
Axel Dörfler
2013-03-10 22:28:23 +01:00
parent e43a7e3db6
commit 77dfc67033
2 changed files with 40 additions and 7 deletions
+1 -1
View File
@@ -6,7 +6,7 @@ SetSubDirSupportedPlatformsBeOSCompatible ;
AddSubDirSupportedPlatforms libbe_test ; AddSubDirSupportedPlatforms libbe_test ;
UsePrivateHeaders app interface shared storage support usb ; UsePrivateHeaders app interface shared storage support tracker usb ;
UsePrivateSystemHeaders ; UsePrivateSystemHeaders ;
SubDirHdrs $(HAIKU_TOP) src add-ons kernel file_cache ; SubDirHdrs $(HAIKU_TOP) src add-ons kernel file_cache ;
UseLibraryHeaders ncurses ; UseLibraryHeaders ncurses ;
+39 -6
View File
@@ -1,6 +1,6 @@
/* /*
* Copyright 2005-2007 Ingo Weinhold, [email protected] * Copyright 2005-2007 Ingo Weinhold, [email protected]
* Copyright 2005-2009 Axel Dörfler, [email protected] * Copyright 2005-2013 Axel Dörfler, [email protected]
* Copyright 2009 Jonas Sundström, [email protected] * Copyright 2009 Jonas Sundström, [email protected]
* *
* All rights reserved. Distributed under the terms of the MIT License. * All rights reserved. Distributed under the terms of the MIT License.
@@ -27,6 +27,9 @@
#include <DiskDeviceList.h> #include <DiskDeviceList.h>
#include <Partition.h> #include <Partition.h>
#include <tracker_private.h>
using std::set; using std::set;
using std::string; using std::string;
@@ -56,6 +59,7 @@ static const char* kUsage =
" -alldos - mount all mountable DOS volumes\n" " -alldos - mount all mountable DOS volumes\n"
" -ro, -readonly - mount volumes read-only\n" " -ro, -readonly - mount volumes read-only\n"
" -u, -unmount <volume> - unmount the volume with the name <volume>\n" " -u, -unmount <volume> - unmount the volume with the name <volume>\n"
" -open - opens the mounted volumes in Tracker\n"
"\n" "\n"
"[info]\n" "[info]\n"
" -p, -l - list all mounted and mountable volumes\n" " -p, -l - list all mounted and mountable volumes\n"
@@ -116,6 +120,25 @@ size_string(int64 size)
} }
static status_t
open_in_tracker(BPartition* partition)
{
BPath mountPoint;
status_t status = partition->GetMountPoint(&mountPoint);
if (status != B_OK)
return status;
entry_ref ref;
status = get_ref_for_path(mountPoint.Path(), &ref);
if (status != B_OK)
return status;
BMessage refs(B_REFS_RECEIVED);
refs.AddRef("refs", &ref);
return BMessenger(kTrackerSignature).SendMessage(&refs);
}
// #pragma mark - // #pragma mark -
@@ -127,7 +150,8 @@ struct MountVisitor : public BDiskDeviceVisitor {
mountBFS(false), mountBFS(false),
mountHFS(false), mountHFS(false),
mountDOS(false), mountDOS(false),
readOnly(false) readOnly(false),
openInTracker(false)
{ {
} }
@@ -184,7 +208,7 @@ struct MountVisitor : public BDiskDeviceVisitor {
// mount/unmount // mount/unmount
if (mount) { if (mount) {
status_t error = partition->Mount(NULL, status_t error = partition->Mount(NULL,
(readOnly ? B_MOUNT_READ_ONLY : 0)); readOnly ? B_MOUNT_READ_ONLY : 0);
if (!silent) { if (!silent) {
if (error >= B_OK) { if (error >= B_OK) {
BPath mountPoint; BPath mountPoint;
@@ -196,6 +220,8 @@ struct MountVisitor : public BDiskDeviceVisitor {
name, strerror(error)); name, strerror(error));
} }
} }
if (openInTracker && error == B_OK)
open_in_tracker(partition);
} else if (unmount) { } else if (unmount) {
status_t error = partition->Unmount(); status_t error = partition->Unmount();
if (!silent) { if (!silent) {
@@ -219,9 +245,10 @@ struct MountVisitor : public BDiskDeviceVisitor {
bool mountHFS; bool mountHFS;
bool mountDOS; bool mountDOS;
bool readOnly; bool readOnly;
bool openInTracker;
}; };
// PrintPartitionsVisitor
struct PrintPartitionsVisitor : public BDiskDeviceVisitor { struct PrintPartitionsVisitor : public BDiskDeviceVisitor {
PrintPartitionsVisitor() PrintPartitionsVisitor()
: listMountablePartitions(false), : listMountablePartitions(false),
@@ -330,9 +357,10 @@ MountVolume::RefsReceived(BMessage* message)
entry_ref ref; entry_ref ref;
BPath path; BPath path;
int32 argc = refCount + 1; int32 argc = refCount + 2;
char** argv = new char*[argc + 1]; char** argv = new char*[argc + 1];
argv[0] = strdup(kAppName); argv[0] = strdup(kAppName);
argv[1] = strdup("-open");
for (int32 i = 0; i < refCount; i++) { for (int32 i = 0; i < refCount; i++) {
message->FindRef("refs", i, &ref); message->FindRef("refs", i, &ref);
@@ -341,7 +369,7 @@ MountVolume::RefsReceived(BMessage* message)
fprintf(stderr, "Failed to get a path (%s) from entry (%s): %s\n", fprintf(stderr, "Failed to get a path (%s) from entry (%s): %s\n",
path.Path(), ref.name, strerror(status)); path.Path(), ref.name, strerror(status));
} }
argv[1 + i] = strdup(path.Path()); argv[2 + i] = strdup(path.Path());
} }
argv[argc] = NULL; argv[argc] = NULL;
@@ -385,6 +413,8 @@ MountVolume::ArgvReceived(int32 argc, char** argv)
if (argi >= argc) if (argi >= argc)
print_usage_and_exit(true); print_usage_and_exit(true);
mountVisitor.toUnmount.insert(argv[argi]); mountVisitor.toUnmount.insert(argv[argi]);
} else if (strcmp(arg, "-open") == 0) {
mountVisitor.openInTracker = true;
} else if (strcmp(arg, "-p") == 0 || strcmp(arg, "-l") == 0) { } else if (strcmp(arg, "-p") == 0 || strcmp(arg, "-l") == 0) {
printPartitionsVisitor.listMountablePartitions = true; printPartitionsVisitor.listMountablePartitions = true;
} else if (strcmp(arg, "-lh") == 0) { } else if (strcmp(arg, "-lh") == 0) {
@@ -461,6 +491,9 @@ MountVolume::ArgvReceived(int32 argc, char** argv)
} }
} }
if (status >= B_OK) { if (status >= B_OK) {
if (mountVisitor.openInTracker)
open_in_tracker(partition);
// remove from list // remove from list
mountVisitor.toMount.erase(name); mountVisitor.toMount.erase(name);
} else if (id >= 0) } else if (id >= 0)