Initial import of Scalos. To decrease size I have
[AROS-Contrib.git] / scalos / main / OpenDrawerByName.c
blobb1675c0936e6b52f308d81996dfeeab2c8122955
1 // OpenDrawerByName.c
2 // $Date$
3 // $Revision$
6 #include <exec/types.h>
7 #include <exec/memory.h>
8 #include <workbench/icon.h>
9 #include <workbench/workbench.h>
11 #define __USE_SYSBASE
13 #include <proto/exec.h>
14 #include <proto/dos.h>
15 #include <proto/icon.h>
16 #include <proto/intuition.h>
17 #include <proto/iconobject.h>
18 #include <proto/utility.h>
19 #include "debug.h"
20 #include <proto/scalos.h>
22 #include <clib/alib_protos.h>
24 #include <defs.h>
25 #include <datatypes/iconobject.h>
26 #include <scalos/scalos.h>
28 #include <stdlib.h>
29 #include <stdio.h>
30 #include <stdarg.h>
31 #include <string.h>
33 #include <defs.h>
35 #include "scalos_structures.h"
36 #include "functions.h"
37 #include "Variables.h"
39 //-------------------------------------------------------------------------
41 static Object *ReadIconObject(CONST_STRPTR Path);
42 static Object *ReadIconObject_NoFail(CONST_STRPTR Path);
44 //-------------------------------------------------------------------------
46 struct ScaWindowStruct *OpenDrawerByName(CONST_STRPTR Path, struct TagItem *TagList)
48 struct ScaWindowStruct *Result = NULL;
49 Object *iconObj;
50 Object *AllocIconObj = NULL;
51 struct SM_StartWindow *StartWindowMsg = NULL;
53 d1(KPrintF("%s/%s/%ld: Path=<%s>\n", __FILE__, __FUNC__, __LINE__, Path));
55 do {
56 // special treatment for Volumes/Devices : look for "VOLNAME:disk.info"
57 size_t len = strlen(Path);
59 if (':' == Path[len - 1])
61 d1(KPrintF("%s/%s/%ld: open device window Path=<%s>\n", __FILE__, __FUNC__, __LINE__, Path));
62 SCA_OpenIconWindowTags(
63 SCA_Path, (ULONG) Path,
64 SCA_CheckOverlappingIcons, CurrentPrefs.pref_CheckOverlappingIcons,
65 TAG_MORE, (ULONG) TagList,
66 TAG_END
69 else
71 iconObj = AllocIconObj = ReadIconObject(Path);
73 d1(KPrintF("%s/%s/%ld: iconObj=%08lx Path=<%s>\n", __FILE__, __FUNC__, __LINE__, iconObj, Path));
75 if (NULL == iconObj)
77 iconObj = AllocIconObj = ReadIconObject_NoFail(Path);
79 if (NULL == iconObj)
80 break;
82 SetAttrs(iconObj,
83 IDTA_Flags, DDFLAGS_SHOWALL,
84 TAG_END);
87 d1(KPrintF("%s/%s/%ld: iconObj=%08lx\n", __FILE__, __FUNC__, __LINE__, iconObj));
89 if (NULL == iconObj)
90 break;
92 d1(KPrintF("%s/%s/%ld: iconObj=%08lx\n", __FILE__, __FUNC__, __LINE__, iconObj));
94 SCA_OpenIconWindowTags(
95 SCA_CheckOverlappingIcons, CurrentPrefs.pref_CheckOverlappingIcons,
96 SCA_IconObject, (ULONG) iconObj,
97 SCA_WindowStruct, (ULONG) &Result,
98 TAG_MORE, (ULONG) TagList,
99 TAG_END
102 } while (0);
104 if (StartWindowMsg)
105 SCA_FreeMessage(&StartWindowMsg->ScalosMessage);
106 if (AllocIconObj)
107 DisposeIconObject(AllocIconObj);
109 d1(KPrintF("%s/%s/%ld: Result=%08lx\n", __FILE__, __FUNC__, __LINE__, Result));
111 return Result;
115 static Object *ReadIconObject(CONST_STRPTR Path)
117 Object *iconObj;
118 STRPTR FullPath;
120 FullPath = AllocPathBuffer();
121 if (FullPath)
123 // change path names like "Download:" to a fully qualified name
124 BPTR doLock = Lock((STRPTR) Path, ACCESS_READ);
126 d1(kprintf("%s/%s/%ld doLock=%08lx\n", __FILE__, __FUNC__, __LINE__, doLock));
128 if (doLock)
130 if (NameFromLock(doLock, FullPath, Max_PathLen))
131 Path = FullPath;
133 UnLock(doLock);
137 d1(kprintf("%s/%s/%ld Path=<%s>\n", __FILE__, __FUNC__, __LINE__, Path));
139 iconObj = ReadIconObject_NoFail(Path);
141 if (FullPath)
142 FreePathBuffer(FullPath);
144 return iconObj;
148 static Object *ReadIconObject_NoFail(CONST_STRPTR Path)
150 Object *iconObj;
152 iconObj = NewIconObject(Path, NULL);
153 if (NULL == iconObj)
155 struct WBArg OriginalLocation;
156 BPTR dirLock;
157 BPTR parentLock = (BPTR)NULL;
159 d1(kprintf("%s/%s/%ld Path=<%s>\n", __FILE__, __FUNC__, __LINE__, Path));
161 do {
162 dirLock = Lock(Path, ACCESS_READ);
163 d1(kprintf("%s/%s/%ld dirLock=%08lx\n", __FILE__, __FUNC__, __LINE__, dirLock));
164 if ((BPTR)NULL == dirLock)
165 break;
167 parentLock = ParentDir(dirLock);
168 d1(kprintf("%s/%s/%ld parentLock=%08lx\n", __FILE__, __FUNC__, __LINE__, parentLock));
169 if (parentLock)
171 OriginalLocation.wa_Lock = parentLock;
172 OriginalLocation.wa_Name = (STRPTR) FilePart(Path);
174 else
176 OriginalLocation.wa_Lock = (BPTR)NULL;
177 OriginalLocation.wa_Name = (STRPTR) Path;
180 d1(kprintf("%s/%s/%ld wa_Lock=%08lx wa_Name=<%s>\n", __FILE__, __FUNC__, __LINE__, OriginalLocation.wa_Lock, OriginalLocation.wa_Name));
182 iconObj = GetDefIconObjectTags(WBDRAWER,
183 IDTA_IconLocation, (ULONG) &OriginalLocation,
184 DTA_Name, (ULONG) Path,
185 TAG_END);
187 d1(kprintf("%s/%s/%ld iconObj=%08lx\n", __FILE__, __FUNC__, __LINE__, iconObj));
188 } while (0);
190 if (parentLock)
191 UnLock(parentLock);
192 if (dirLock)
193 UnLock(dirLock);
196 return iconObj;