Introducing a private method for launching a Tracker addon as a stand-alone application. Updated TextSearch to use it. Matthijs Hollemans license is MIT. Not important for alphabranch.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@32842 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
b1c06fc64a
commit
c5d2ebc76a
70
headers/private/shared/TrackerAddOnAppLaunch.h
Normal file
70
headers/private/shared/TrackerAddOnAppLaunch.h
Normal file
@ -0,0 +1,70 @@
|
||||
/*
|
||||
* Copyright 2009 Jonas Sundström, jonas@kirilla.com
|
||||
* Copyright 1998-2007 Matthijs Hollemans
|
||||
* All rights reserved. Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef _TRACKER_ADDON_APP_LAUNCH_H
|
||||
#define _TRACKER_ADDON_APP_LAUNCH_H
|
||||
|
||||
|
||||
#include <Entry.h>
|
||||
#include <image.h>
|
||||
#include <Roster.h>
|
||||
#include <TrackerAddOn.h>
|
||||
|
||||
|
||||
void
|
||||
process_refs(entry_ref directory, BMessage* refs, void* reserved)
|
||||
{
|
||||
// When this header file is included by an application it becomes
|
||||
// ready to be used as a Tracker add-on. This function will launch
|
||||
// the application with the entry_refs given by Tracker to the addon.
|
||||
|
||||
// The "directory" entry_ref holds the entry_ref of the folder from where
|
||||
// the addon was launched. If launched from a query it's probably invalid.
|
||||
// The "refs" BMessage is a standard B_REFS_RECEIVED message whose
|
||||
// "refs" array contains the entry_refs of the selected files.
|
||||
// The last argument, "reserved", is currently unused.
|
||||
|
||||
refs->AddRef("dir_ref", &directory);
|
||||
// The folder's entry_ref might be useful to some applications.
|
||||
// We include it by a different name than the other entry_refs.
|
||||
// It could be useful to know if an application got its refs as a
|
||||
// Tracker addon. A B_REFS_RECEIVED message with a "dir_ref"
|
||||
// provides such a hint.
|
||||
|
||||
// get the path of the Tracker add-on
|
||||
image_info image;
|
||||
int32 cookie = 0;
|
||||
status_t status = get_next_image_info(0, &cookie, &image);
|
||||
|
||||
while (status == B_OK) {
|
||||
if (((char*)process_refs >= (char*)image.text
|
||||
&& (char*)process_refs <= (char*)image.text + image.text_size)
|
||||
|| ((char*)process_refs >= (char*)image.data
|
||||
&& (char*)process_refs <= (char*)image.data + image.data_size))
|
||||
break;
|
||||
|
||||
status = get_next_image_info(0, &cookie, &image);
|
||||
}
|
||||
|
||||
entry_ref addonRef;
|
||||
if (get_ref_for_path(image.name, &addonRef) != B_OK)
|
||||
return;
|
||||
|
||||
if (be_roster->Launch(&addonRef, refs) != B_OK) {
|
||||
|
||||
// If launching by entry_ref fails it's probably futile to
|
||||
// launch by signature this way, but we can try anyway.
|
||||
|
||||
app_info appInfo;
|
||||
if (be_roster->GetAppInfo(&addonRef, &appInfo) != B_OK)
|
||||
return;
|
||||
|
||||
be_roster->Launch(appInfo.signature, refs);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif // _TRACKER_ADDON_APP_LAUNCH_H
|
||||
|
@ -1,34 +1,11 @@
|
||||
/*
|
||||
* Copyright (c) 1998-2007 Matthijs Hollemans
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
* All rights reserved. Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
// NOTE: This code is the same in DiskUsge. Maybe it could be made
|
||||
// into some kind of common base class?
|
||||
|
||||
#include "GrepApp.h"
|
||||
|
||||
#include <AppFileInfo.h>
|
||||
#include <Entry.h>
|
||||
#include <Roster.h>
|
||||
#include <TrackerAddOn.h>
|
||||
#include <TrackerAddOnAppLaunch.h>
|
||||
|
||||
#include "GlobalDefs.h"
|
||||
|
||||
@ -41,48 +18,3 @@ main()
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
process_refs(entry_ref dirRef, BMessage *message, void* /*reserved*/)
|
||||
{
|
||||
// Tracker calls this function when the user invokes the add-on.
|
||||
// "dir_ref" contains the entry_ref of the current directory.
|
||||
// "message" is a standard B_REFS_RECEIVED BMessage whose "refs"
|
||||
// array contains the entry_refs of the selected files. The last
|
||||
// argument, "reserved", is currently unused.
|
||||
|
||||
// This version of TextSearch is a Tracker add-on, but primarily
|
||||
// it is a stand-alone application. The add-on launches the app
|
||||
// on the set of files you had selected in Tracker. That way you
|
||||
// get the benefits of the Tracker add-on with the benefits of the
|
||||
// stand-alone application.
|
||||
|
||||
message->AddRef("dir_ref", &dirRef);
|
||||
|
||||
// get the path of the Tracker add-on
|
||||
image_info image;
|
||||
int32 cookie = 0;
|
||||
status_t status = get_next_image_info(0, &cookie, &image);
|
||||
|
||||
while (status == B_OK) {
|
||||
if (((char*)process_refs >= (char*)image.text
|
||||
&& (char*)process_refs <= (char*)image.text + image.text_size)
|
||||
|| ((char*)process_refs >= (char*)image.data
|
||||
&& (char*)process_refs <= (char*)image.data + image.data_size))
|
||||
break;
|
||||
|
||||
status = get_next_image_info(0, &cookie, &image);
|
||||
}
|
||||
|
||||
entry_ref addonRef;
|
||||
|
||||
if (get_ref_for_path(image.name, &addonRef) == B_OK) {
|
||||
// It's better to launch the application by its entry
|
||||
// than by its application signature. There may be
|
||||
// multiple instances and we would not be certain
|
||||
// that the desired one is launched - the one which was
|
||||
// loaded into Tracker and whose process_refs() was called.
|
||||
be_roster->Launch(&addonRef, message);
|
||||
} else
|
||||
be_roster->Launch(APP_SIGNATURE, message);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user