Zip-O-Matic: Fix and enable _SelectInTracker().
Based on a code example from humdinger.
This commit is contained in:
@@ -23,6 +23,8 @@
|
|||||||
#include <Path.h>
|
#include <Path.h>
|
||||||
#include <Volume.h>
|
#include <Volume.h>
|
||||||
|
|
||||||
|
#include <private/tracker/tracker_private.h>
|
||||||
|
|
||||||
#include "ZipOMaticMisc.h"
|
#include "ZipOMaticMisc.h"
|
||||||
#include "ZipOMaticWindow.h"
|
#include "ZipOMaticWindow.h"
|
||||||
|
|
||||||
@@ -211,7 +213,7 @@ ZipperThread::ThreadShutdown()
|
|||||||
close(fStdOut);
|
close(fStdOut);
|
||||||
close(fStdErr);
|
close(fStdErr);
|
||||||
|
|
||||||
// _SelectInTracker();
|
_SelectInTracker();
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
@@ -410,10 +412,8 @@ ZipperThread::WaitOnExternalZip()
|
|||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
ZipperThread::_SelectInTracker(int32 tryNumber)
|
ZipperThread::_SelectInTracker()
|
||||||
{
|
{
|
||||||
// work in progress - unreliable - not ready to be used
|
|
||||||
|
|
||||||
entry_ref parentRef;
|
entry_ref parentRef;
|
||||||
BEntry entry(&fOutputEntryRef);
|
BEntry entry(&fOutputEntryRef);
|
||||||
|
|
||||||
@@ -423,108 +423,24 @@ ZipperThread::_SelectInTracker(int32 tryNumber)
|
|||||||
entry.GetParent(&entry);
|
entry.GetParent(&entry);
|
||||||
entry.GetRef(&parentRef);
|
entry.GetRef(&parentRef);
|
||||||
|
|
||||||
BMessenger trackerMessenger("application/x-vnd.Be-TRAK");
|
BMessenger trackerMessenger(kTrackerSignature);
|
||||||
if (!trackerMessenger.IsValid())
|
if (!trackerMessenger.IsValid())
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
|
|
||||||
BMessage request;
|
BMessage request, reply;
|
||||||
BMessage reply;
|
request.what = B_REFS_RECEIVED;
|
||||||
status_t status;
|
request.AddRef("refs", &parentRef);
|
||||||
|
status_t status = trackerMessenger.SendMessage(&request, &reply);
|
||||||
if (tryNumber == 0) {
|
|
||||||
request.MakeEmpty();
|
|
||||||
request.what = B_REFS_RECEIVED;
|
|
||||||
request.AddRef("refs", &parentRef);
|
|
||||||
trackerMessenger.SendMessage(&request, &reply);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (tryNumber > 20)
|
|
||||||
return B_ERROR;
|
|
||||||
|
|
||||||
snooze(200000);
|
|
||||||
|
|
||||||
// find out the number of Tracker windows
|
|
||||||
request.MakeEmpty();
|
|
||||||
request.what = B_COUNT_PROPERTIES;
|
|
||||||
request.AddSpecifier("Window");
|
|
||||||
reply.MakeEmpty();
|
|
||||||
|
|
||||||
status = trackerMessenger.SendMessage(&request, &reply);
|
|
||||||
if (status != B_OK)
|
if (status != B_OK)
|
||||||
return status;
|
return status;
|
||||||
|
|
||||||
int32 windowCount;
|
// Wait 0.3 seconds to give Tracker time to populate.
|
||||||
status = reply.FindInt32("result", &windowCount);
|
snooze(300000);
|
||||||
if (status != B_OK)
|
|
||||||
return status;
|
|
||||||
|
|
||||||
// find a likely parent window
|
|
||||||
bool foundWindow = false;
|
|
||||||
int32 index = 0;
|
|
||||||
for (; index < windowCount; index++) {
|
|
||||||
request.MakeEmpty();
|
|
||||||
request.what = B_GET_PROPERTY;
|
|
||||||
request.AddSpecifier("Path");
|
|
||||||
request.AddSpecifier("Poses");
|
|
||||||
request.AddSpecifier("Window", index);
|
|
||||||
reply.MakeEmpty();
|
|
||||||
|
|
||||||
status = trackerMessenger.SendMessage(&request, &reply);
|
|
||||||
if (status != B_OK)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
entry_ref windowRef;
|
|
||||||
status = reply.FindRef("result", &windowRef);
|
|
||||||
if (status != B_OK)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (windowRef == parentRef) {
|
|
||||||
foundWindow = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!foundWindow)
|
|
||||||
return _SelectInTracker(tryNumber + 1);
|
|
||||||
|
|
||||||
// find entry_ref in window - a newly opened window might
|
|
||||||
// be filling and the entry_ref perhaps not there yet?
|
|
||||||
request.MakeEmpty();
|
request.MakeEmpty();
|
||||||
request.what = B_GET_PROPERTY;
|
request.what = BPrivate::kSelect;
|
||||||
request.AddSpecifier("Entry");
|
request.AddRef("refs", &fOutputEntryRef);
|
||||||
request.AddSpecifier("Poses");
|
|
||||||
request.AddSpecifier("Window", index);
|
|
||||||
reply.MakeEmpty();
|
reply.MakeEmpty();
|
||||||
|
return trackerMessenger.SendMessage(&request, &reply);
|
||||||
status = trackerMessenger.SendMessage(&request, &reply);
|
|
||||||
if (status != B_OK)
|
|
||||||
return _SelectInTracker(tryNumber + 1);
|
|
||||||
|
|
||||||
bool foundRef = false;
|
|
||||||
entry_ref ref;
|
|
||||||
for (int32 m = 0;; m++) {
|
|
||||||
status = reply.FindRef("result", m, &ref);
|
|
||||||
if (status != B_OK)
|
|
||||||
break;
|
|
||||||
if (ref == fOutputEntryRef)
|
|
||||||
foundRef = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// if entry_ref not found in window, start over
|
|
||||||
if (!foundRef)
|
|
||||||
return _SelectInTracker(tryNumber + 1);
|
|
||||||
|
|
||||||
// select archive file in Tracker window
|
|
||||||
request.MakeEmpty();
|
|
||||||
request.what = B_SET_PROPERTY;
|
|
||||||
request.AddRef("data", &fOutputEntryRef);
|
|
||||||
request.AddSpecifier("Selection");
|
|
||||||
request.AddSpecifier("Poses");
|
|
||||||
request.AddSpecifier("Window", index);
|
|
||||||
reply.MakeEmpty();
|
|
||||||
|
|
||||||
status = trackerMessenger.SendMessage(&request, &reply);
|
|
||||||
|
|
||||||
return status;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ private:
|
|||||||
const char* name = NULL,
|
const char* name = NULL,
|
||||||
const char* value = NULL);
|
const char* value = NULL);
|
||||||
|
|
||||||
status_t _SelectInTracker(int32 tryNumber = 0);
|
status_t _SelectInTracker();
|
||||||
|
|
||||||
BMessenger fWindowMessenger;
|
BMessenger fWindowMessenger;
|
||||||
thread_id fZipProcess;
|
thread_id fZipProcess;
|
||||||
|
|||||||
Reference in New Issue
Block a user