xref: /haiku/src/apps/deskbar/DeskbarUtils.cpp (revision 06736193497068c34e326be28ae67bbc5d1a154c)
1323b6546SOliver Tappe /*
2323b6546SOliver Tappe Open Tracker License
3323b6546SOliver Tappe 
4323b6546SOliver Tappe Terms and Conditions
5323b6546SOliver Tappe 
6323b6546SOliver Tappe Copyright (c) 1991-2000, Be Incorporated. All rights reserved.
7323b6546SOliver Tappe 
8323b6546SOliver Tappe Permission is hereby granted, free of charge, to any person obtaining a copy of
9323b6546SOliver Tappe this software and associated documentation files (the "Software"), to deal in
10323b6546SOliver Tappe the Software without restriction, including without limitation the rights to
11323b6546SOliver Tappe use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
12323b6546SOliver Tappe of the Software, and to permit persons to whom the Software is furnished to do
13323b6546SOliver Tappe so, subject to the following conditions:
14323b6546SOliver Tappe 
15323b6546SOliver Tappe The above copyright notice and this permission notice applies to all licensees
16323b6546SOliver Tappe and shall be included in all copies or substantial portions of the Software.
17323b6546SOliver Tappe 
18323b6546SOliver Tappe THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19323b6546SOliver Tappe IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF TITLE, MERCHANTABILITY,
20323b6546SOliver Tappe FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21323b6546SOliver Tappe BE INCORPORATED BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22323b6546SOliver Tappe AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION
23323b6546SOliver Tappe WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24323b6546SOliver Tappe 
25323b6546SOliver Tappe Except as contained in this notice, the name of Be Incorporated shall not be
26323b6546SOliver Tappe used in advertising or otherwise to promote the sale, use or other dealings in
27323b6546SOliver Tappe this Software without prior written authorization from Be Incorporated.
28323b6546SOliver Tappe 
29323b6546SOliver Tappe Tracker(TM), Be(R), BeOS(R), and BeIA(TM) are trademarks or registered
30323b6546SOliver Tappe trademarks of Be Incorporated in the United States and other countries. Other
31323b6546SOliver Tappe brand product names are registered trademarks or trademarks of their respective
32323b6546SOliver Tappe holders.
33323b6546SOliver Tappe All rights reserved.
34323b6546SOliver Tappe */
35323b6546SOliver Tappe 
361cd61330SJohn Scipione 
371cd61330SJohn Scipione #include "DeskbarUtils.h"
381cd61330SJohn Scipione 
39323b6546SOliver Tappe #include <stdio.h>
40323b6546SOliver Tappe #include <stdlib.h>
41323b6546SOliver Tappe #include <string.h>
42323b6546SOliver Tappe 
43323b6546SOliver Tappe #include <AppFileInfo.h>
441cd61330SJohn Scipione #include <Debug.h>
45323b6546SOliver Tappe #include <Directory.h>
46323b6546SOliver Tappe #include <FilePanel.h>
47323b6546SOliver Tappe #include <FindDirectory.h>
48323b6546SOliver Tappe #include <List.h>
49323b6546SOliver Tappe #include <Mime.h>
50323b6546SOliver Tappe #include <NodeInfo.h>
51323b6546SOliver Tappe #include <Screen.h>
52323b6546SOliver Tappe #include <SymLink.h>
531cd61330SJohn Scipione #include <Window.h>
54323b6546SOliver Tappe 
55323b6546SOliver Tappe #include "BarMenuBar.h"
56323b6546SOliver Tappe #include "ExpandoMenuBar.h"
57323b6546SOliver Tappe 
58*06736193SJohn Scipione 
59323b6546SOliver Tappe void
60323b6546SOliver Tappe AddRefsToDeskbarMenu(const BMessage* m, entry_ref* subdirectory)
61323b6546SOliver Tappe {
62323b6546SOliver Tappe 	if (m) {
63323b6546SOliver Tappe 		int32 count = 0;
64323b6546SOliver Tappe 		uint32 type = 0;
65323b6546SOliver Tappe 		entry_ref ref;
66323b6546SOliver Tappe 
67323b6546SOliver Tappe 		m->GetInfo("refs", &type, &count);
68323b6546SOliver Tappe 		if (count <= 0)
69323b6546SOliver Tappe 			return;
70323b6546SOliver Tappe 
71323b6546SOliver Tappe 		BPath path;
72323b6546SOliver Tappe 		BSymLink link;
73323b6546SOliver Tappe 		BDirectory dir;
74323b6546SOliver Tappe 		if (subdirectory) {
75323b6546SOliver Tappe 			ref = *subdirectory;
76323b6546SOliver Tappe 			BEntry entry(&ref);
77323b6546SOliver Tappe 			if (entry.Exists()) {
78323b6546SOliver Tappe 				// if the ref is a file get the parent and convert it to a ref
79323b6546SOliver Tappe 				if (entry.IsFile()) {
80323b6546SOliver Tappe 					BEntry parent;
81323b6546SOliver Tappe 					entry.GetParent(&parent);
82323b6546SOliver Tappe 					parent.GetRef(&ref);
83323b6546SOliver Tappe 				}
84323b6546SOliver Tappe 			} else
85323b6546SOliver Tappe 				return;
86323b6546SOliver Tappe 
87323b6546SOliver Tappe 			dir.SetTo(&ref);
88323b6546SOliver Tappe 		} else {
89323b6546SOliver Tappe 			if (find_directory(B_USER_DESKBAR_DIRECTORY, &path) == B_OK)
90323b6546SOliver Tappe 				dir.SetTo(path.Path());
91323b6546SOliver Tappe 			else
92323b6546SOliver Tappe 				return;
93323b6546SOliver Tappe 		}
94323b6546SOliver Tappe 
95323b6546SOliver Tappe 		for (long i = 0; i < count; i++) {
96323b6546SOliver Tappe 			if (m->FindRef("refs", i, &ref) == B_NO_ERROR) {
97323b6546SOliver Tappe 				BEntry entry(&ref);
98323b6546SOliver Tappe 				entry.GetPath(&path);
99323b6546SOliver Tappe 
100323b6546SOliver Tappe 				dir.CreateSymLink(ref.name, path.Path(), &link);
101323b6546SOliver Tappe 			}
102323b6546SOliver Tappe 		}
103323b6546SOliver Tappe 	}
104323b6546SOliver Tappe }
105