xref: /haiku/src/apps/text_search/TextSearch.cpp (revision f75a7bf508f3156d63a14f8fd77c5e0ca4d08c42)
1 /*
2  * Copyright (c) 1998-2007 Matthijs Hollemans
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20  * DEALINGS IN THE SOFTWARE.
21  */
22 #include "GrepApp.h"
23 
24 #include <AppFileInfo.h>
25 #include <Entry.h>
26 #include <Roster.h>
27 #include <TrackerAddOn.h>
28 
29 #include "GlobalDefs.h"
30 
31 
32 int
33 main()
34 {
35 	GrepApp app;
36 	app.Run();
37 	return 0;
38 }
39 
40 
41 void
42 process_refs(entry_ref dirRef, BMessage *message, void* /*reserved*/)
43 {
44 	// Tracker calls this function when the user invokes the add-on.
45 	// "dir_ref" contains the entry_ref of the current directory.
46 	// "message" is a standard B_REFS_RECEIVED BMessage whose "refs"
47 	// array contains the entry_refs of the selected files. The last
48 	// argument, "reserved", is currently unused.
49 
50 	// This version of TrackerGrep is a Tracker add-on, but primarily
51 	// it is a stand-alone application. The add-on launches the app
52 	// on the set of files you had selected in Tracker. That way you
53 	// get the benefits of the Tracker add-on with the benefits of the
54 	// stand-alone application.
55 
56 	message->AddRef("dir_ref", &dirRef);
57 
58 	// get the path of the Tracker add-on
59 	image_info image;
60 	int32 cookie = 0;
61 	status_t status = B_OK;
62 
63 	status = get_next_image_info(0, &cookie, &image);
64 
65 	while (status == B_OK) {
66 		if (((char*)process_refs >= (char*)image.text
67 				&& (char*)process_refs <= (char*)image.text + image.text_size)
68 			|| ((char*)process_refs >= (char*)image.data
69 				&& (char*)process_refs <= (char*)image.data + image.data_size))
70 			break;
71 
72 		status = get_next_image_info(0, &cookie, &image);
73 	}
74 
75 	entry_ref addonRef;
76 
77 	if (get_ref_for_path(image.name, &addonRef) == B_OK) {
78 		// It's better to launch the application by its entry
79 		// than by its application signature. There may be
80 		// multiple instances and we would not be certain
81 		// that the desired one is launched - the one which was
82 		// loaded into Tracker and whose process_refs() was called.
83 		be_roster->Launch(&addonRef, message);
84 	} else
85 		be_roster->Launch(APP_SIGNATURE, message);
86 }
87