xref: /haiku/src/apps/deskbar/DeskbarUtils.cpp (revision 1501d1d619d9a4afe90516d1949a12614de91a44)
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 
5706736193SJohn Scipione 
58*26ea7066SIngo Weinhold const char* const kDeskbarMenuEntriesFileName = "menu_entries";
59*26ea7066SIngo Weinhold 
60*26ea7066SIngo Weinhold static const char* const kDeskbarDirectoryName = "deskbar";
61*26ea7066SIngo Weinhold 
62*26ea7066SIngo Weinhold 
63323b6546SOliver Tappe void
AddRefsToDeskbarMenu(const BMessage * m,entry_ref * subdirectory)64323b6546SOliver Tappe AddRefsToDeskbarMenu(const BMessage* m, entry_ref* subdirectory)
65323b6546SOliver Tappe {
66323b6546SOliver Tappe 	if (m) {
67323b6546SOliver Tappe 		int32 count = 0;
68323b6546SOliver Tappe 		uint32 type = 0;
69323b6546SOliver Tappe 		entry_ref ref;
70323b6546SOliver Tappe 
71323b6546SOliver Tappe 		m->GetInfo("refs", &type, &count);
72323b6546SOliver Tappe 		if (count <= 0)
73323b6546SOliver Tappe 			return;
74323b6546SOliver Tappe 
75323b6546SOliver Tappe 		BPath path;
76323b6546SOliver Tappe 		BSymLink link;
77323b6546SOliver Tappe 		BDirectory dir;
78323b6546SOliver Tappe 		if (subdirectory) {
79323b6546SOliver Tappe 			ref = *subdirectory;
80323b6546SOliver Tappe 			BEntry entry(&ref);
81323b6546SOliver Tappe 			if (entry.Exists()) {
82323b6546SOliver Tappe 				// if the ref is a file get the parent and convert it to a ref
83323b6546SOliver Tappe 				if (entry.IsFile()) {
84323b6546SOliver Tappe 					BEntry parent;
85323b6546SOliver Tappe 					entry.GetParent(&parent);
86323b6546SOliver Tappe 					parent.GetRef(&ref);
87323b6546SOliver Tappe 				}
88323b6546SOliver Tappe 			} else
89323b6546SOliver Tappe 				return;
90323b6546SOliver Tappe 
91323b6546SOliver Tappe 			dir.SetTo(&ref);
92323b6546SOliver Tappe 		} else {
93323b6546SOliver Tappe 			if (find_directory(B_USER_DESKBAR_DIRECTORY, &path) == B_OK)
94323b6546SOliver Tappe 				dir.SetTo(path.Path());
95323b6546SOliver Tappe 			else
96323b6546SOliver Tappe 				return;
97323b6546SOliver Tappe 		}
98323b6546SOliver Tappe 
99323b6546SOliver Tappe 		for (long i = 0; i < count; i++) {
100323b6546SOliver Tappe 			if (m->FindRef("refs", i, &ref) == B_NO_ERROR) {
101323b6546SOliver Tappe 				BEntry entry(&ref);
102323b6546SOliver Tappe 				entry.GetPath(&path);
103323b6546SOliver Tappe 
104323b6546SOliver Tappe 				dir.CreateSymLink(ref.name, path.Path(), &link);
105323b6546SOliver Tappe 			}
106323b6546SOliver Tappe 		}
107323b6546SOliver Tappe 	}
108323b6546SOliver Tappe }
109*26ea7066SIngo Weinhold 
110*26ea7066SIngo Weinhold 
111*26ea7066SIngo Weinhold status_t
GetDeskbarSettingsDirectory(BPath & _path,bool create)112*26ea7066SIngo Weinhold GetDeskbarSettingsDirectory(BPath& _path, bool create)
113*26ea7066SIngo Weinhold {
114*26ea7066SIngo Weinhold 	status_t error = find_directory(B_USER_SETTINGS_DIRECTORY, &_path, create);
115*26ea7066SIngo Weinhold 	if (error != B_OK)
116*26ea7066SIngo Weinhold 		return error;
117*26ea7066SIngo Weinhold 
118*26ea7066SIngo Weinhold 	error = _path.Append(kDeskbarDirectoryName);
119*26ea7066SIngo Weinhold 	if (error != B_OK)
120*26ea7066SIngo Weinhold 		return error;
121*26ea7066SIngo Weinhold 
122*26ea7066SIngo Weinhold 	return create ? create_directory(_path.Path(), 0755) : error;
123*26ea7066SIngo Weinhold }
124*26ea7066SIngo Weinhold 
125*26ea7066SIngo Weinhold 
126*26ea7066SIngo Weinhold status_t
GetDeskbarDataDirectory(BPath & _path)127*26ea7066SIngo Weinhold GetDeskbarDataDirectory(BPath& _path)
128*26ea7066SIngo Weinhold {
129*26ea7066SIngo Weinhold 	status_t error = find_directory(B_SYSTEM_DATA_DIRECTORY, &_path, false);
130*26ea7066SIngo Weinhold 	if (error != B_OK)
131*26ea7066SIngo Weinhold 		return error;
132*26ea7066SIngo Weinhold 
133*26ea7066SIngo Weinhold 	return _path.Append(kDeskbarDirectoryName);
134*26ea7066SIngo Weinhold }
135