xref: /haiku/src/apps/diskusage/DiskUsage.cpp (revision 16d5c24e533eb14b7b8a99ee9f3ec9ba66335b1e)
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 
23 // NOTE: This code is the same in TextSearch. Maybe it could be made
24 // into some kind of common base class?
25 
26 #include "App.h"
27 
28 #include <AppFileInfo.h>
29 #include <Entry.h>
30 #include <Roster.h>
31 #include <TrackerAddOn.h>
32 
33 #include "Common.h"
34 
35 
36 int
37 main()
38 {
39 	App app;
40 	app.Run();
41 	return 0;
42 }
43 
44 
45 void
46 process_refs(entry_ref dirRef, BMessage* message, void* /*reserved*/)
47 {
48 	// Tracker calls this function when the user invokes the add-on.
49 	// "dir_ref" contains the entry_ref of the current directory.
50 	// "message" is a standard B_REFS_RECEIVED BMessage whose "refs"
51 	// array contains the entry_refs of the selected files. The last
52 	// argument, "reserved", is currently unused.
53 
54 	// This version of TrackerGrep is a Tracker add-on, but primarily
55 	// it is a stand-alone application. The add-on launches the app
56 	// on the set of files you had selected in Tracker. That way you
57 	// get the benefits of the Tracker add-on with the benefits of the
58 	// stand-alone application.
59 
60 	if (!message->HasRef("refs"))
61 		message->AddRef("refs", &dirRef);
62 
63 	// get the path of the Tracker add-on
64 	image_info image;
65 	int32 cookie = 0;
66 	status_t status = get_next_image_info(0, &cookie, &image);
67 
68 	while (status == B_OK) {
69 		if (((char*)process_refs >= (char*)image.text
70 				&& (char*)process_refs <= (char*)image.text + image.text_size)
71 			|| ((char*)process_refs >= (char*)image.data
72 				&& (char*)process_refs <= (char*)image.data + image.data_size))
73 			break;
74 
75 		status = get_next_image_info(0, &cookie, &image);
76 	}
77 
78 	entry_ref addonRef;
79 
80 	if (get_ref_for_path(image.name, &addonRef) == B_OK) {
81 		// It's better to launch the application by its entry
82 		// than by its application signature. There may be
83 		// multiple instances and we would not be certain
84 		// that the desired one is launched - the one which was
85 		// loaded into Tracker and whose process_refs() was called.
86 		be_roster->Launch(&addonRef, message);
87 	} else
88 		be_roster->Launch(kAppSignature, message);
89 }
90