xref: /haiku/src/apps/deskbar/DeskbarUtils.cpp (revision 323b65468e5836bb27a5e373b14027d902349437)
1*323b6546SOliver Tappe /*
2*323b6546SOliver Tappe Open Tracker License
3*323b6546SOliver Tappe 
4*323b6546SOliver Tappe Terms and Conditions
5*323b6546SOliver Tappe 
6*323b6546SOliver Tappe Copyright (c) 1991-2000, Be Incorporated. All rights reserved.
7*323b6546SOliver Tappe 
8*323b6546SOliver Tappe Permission is hereby granted, free of charge, to any person obtaining a copy of
9*323b6546SOliver Tappe this software and associated documentation files (the "Software"), to deal in
10*323b6546SOliver Tappe the Software without restriction, including without limitation the rights to
11*323b6546SOliver Tappe use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
12*323b6546SOliver Tappe of the Software, and to permit persons to whom the Software is furnished to do
13*323b6546SOliver Tappe so, subject to the following conditions:
14*323b6546SOliver Tappe 
15*323b6546SOliver Tappe The above copyright notice and this permission notice applies to all licensees
16*323b6546SOliver Tappe and shall be included in all copies or substantial portions of the Software.
17*323b6546SOliver Tappe 
18*323b6546SOliver Tappe THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19*323b6546SOliver Tappe IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF TITLE, MERCHANTABILITY,
20*323b6546SOliver Tappe FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21*323b6546SOliver Tappe BE INCORPORATED BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22*323b6546SOliver Tappe AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION
23*323b6546SOliver Tappe WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24*323b6546SOliver Tappe 
25*323b6546SOliver Tappe Except as contained in this notice, the name of Be Incorporated shall not be
26*323b6546SOliver Tappe used in advertising or otherwise to promote the sale, use or other dealings in
27*323b6546SOliver Tappe this Software without prior written authorization from Be Incorporated.
28*323b6546SOliver Tappe 
29*323b6546SOliver Tappe Tracker(TM), Be(R), BeOS(R), and BeIA(TM) are trademarks or registered
30*323b6546SOliver Tappe trademarks of Be Incorporated in the United States and other countries. Other
31*323b6546SOliver Tappe brand product names are registered trademarks or trademarks of their respective
32*323b6546SOliver Tappe holders.
33*323b6546SOliver Tappe All rights reserved.
34*323b6546SOliver Tappe */
35*323b6546SOliver Tappe 
36*323b6546SOliver Tappe #include <stdio.h>
37*323b6546SOliver Tappe #include <stdlib.h>
38*323b6546SOliver Tappe #include <string.h>
39*323b6546SOliver Tappe 
40*323b6546SOliver Tappe #include <Debug.h>
41*323b6546SOliver Tappe #include <Window.h>
42*323b6546SOliver Tappe #include <AppFileInfo.h>
43*323b6546SOliver Tappe #include <Directory.h>
44*323b6546SOliver Tappe #include <FilePanel.h>
45*323b6546SOliver Tappe #include <FindDirectory.h>
46*323b6546SOliver Tappe #include <List.h>
47*323b6546SOliver Tappe #include <Mime.h>
48*323b6546SOliver Tappe #include <NodeInfo.h>
49*323b6546SOliver Tappe #include <Path.h>
50*323b6546SOliver Tappe #include <Screen.h>
51*323b6546SOliver Tappe #include <SymLink.h>
52*323b6546SOliver Tappe 
53*323b6546SOliver Tappe #include "BarMenuBar.h"
54*323b6546SOliver Tappe #include "DeskbarUtils.h"
55*323b6546SOliver Tappe #include "ExpandoMenuBar.h"
56*323b6546SOliver Tappe 
57*323b6546SOliver Tappe void
58*323b6546SOliver Tappe AddRefsToDeskbarMenu(const BMessage* m, entry_ref* subdirectory)
59*323b6546SOliver Tappe {
60*323b6546SOliver Tappe 	if (m) {
61*323b6546SOliver Tappe 		int32 count = 0;
62*323b6546SOliver Tappe 		uint32 type = 0;
63*323b6546SOliver Tappe 		entry_ref ref;
64*323b6546SOliver Tappe 
65*323b6546SOliver Tappe 		m->GetInfo("refs", &type, &count);
66*323b6546SOliver Tappe 		if (count <= 0)
67*323b6546SOliver Tappe 			return;
68*323b6546SOliver Tappe 
69*323b6546SOliver Tappe 		BPath path;
70*323b6546SOliver Tappe 		BSymLink link;
71*323b6546SOliver Tappe 		BDirectory dir;
72*323b6546SOliver Tappe 		if (subdirectory) {
73*323b6546SOliver Tappe 			ref = *subdirectory;
74*323b6546SOliver Tappe 			BEntry entry(&ref);
75*323b6546SOliver Tappe 			if (entry.Exists()) {
76*323b6546SOliver Tappe 				// if the ref is a file get the parent and convert it to a ref
77*323b6546SOliver Tappe 				if (entry.IsFile()) {
78*323b6546SOliver Tappe 					BEntry parent;
79*323b6546SOliver Tappe 					entry.GetParent(&parent);
80*323b6546SOliver Tappe 					parent.GetRef(&ref);
81*323b6546SOliver Tappe 				}
82*323b6546SOliver Tappe 			} else
83*323b6546SOliver Tappe 				return;
84*323b6546SOliver Tappe 
85*323b6546SOliver Tappe 			dir.SetTo(&ref);
86*323b6546SOliver Tappe 		} else {
87*323b6546SOliver Tappe 			if (find_directory(B_USER_DESKBAR_DIRECTORY, &path) == B_OK)
88*323b6546SOliver Tappe 				dir.SetTo(path.Path());
89*323b6546SOliver Tappe 			else
90*323b6546SOliver Tappe 				return;
91*323b6546SOliver Tappe 		}
92*323b6546SOliver Tappe 
93*323b6546SOliver Tappe 		for (long i = 0; i < count; i++) {
94*323b6546SOliver Tappe 			if (m->FindRef("refs", i, &ref) == B_NO_ERROR) {
95*323b6546SOliver Tappe 				BEntry entry(&ref);
96*323b6546SOliver Tappe 				entry.GetPath(&path);
97*323b6546SOliver Tappe 
98*323b6546SOliver Tappe 				dir.CreateSymLink(ref.name, path.Path(), &link);
99*323b6546SOliver Tappe 			}
100*323b6546SOliver Tappe 		}
101*323b6546SOliver Tappe 	}
102*323b6546SOliver Tappe }
103*323b6546SOliver Tappe 
104