1 | /* ***** BEGIN LICENSE BLOCK *****
|
---|
2 | * Version: CDDL 1.0/LGPL 2.1
|
---|
3 | *
|
---|
4 | * The contents of this file are subject to the COMMON DEVELOPMENT AND
|
---|
5 | * DISTRIBUTION LICENSE (CDDL) Version 1.0 (the "License"); you may not use
|
---|
6 | * this file except in compliance with the License. You may obtain a copy of
|
---|
7 | * the License at http://www.sun.com/cddl/
|
---|
8 | *
|
---|
9 | * Software distributed under the License is distributed on an "AS IS" basis,
|
---|
10 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
---|
11 | * for the specific language governing rights and limitations under the
|
---|
12 | * License.
|
---|
13 | *
|
---|
14 | * The Original Code is "NOM" Netlabs Object Model
|
---|
15 | *
|
---|
16 | * The Initial Developer of the Original Code is
|
---|
17 | * netlabs.org: Chris Wohlgemuth <cinc-ml@netlabs.org>.
|
---|
18 | * Portions created by the Initial Developer are Copyright (C) 2005-2007
|
---|
19 | * the Initial Developer. All Rights Reserved.
|
---|
20 | *
|
---|
21 | * Contributor(s):
|
---|
22 | *
|
---|
23 | * Alternatively, the contents of this file may be used under the terms of
|
---|
24 | * the GNU Lesser General Public License Version 2.1 (the "LGPL"), in which
|
---|
25 | * case the provisions of the LGPL are applicable instead of those above. If
|
---|
26 | * you wish to allow use of your version of this file only under the terms of
|
---|
27 | * the LGPL, and not to allow others to use your version of this file under
|
---|
28 | * the terms of the CDDL, indicate your decision by deleting the provisions
|
---|
29 | * above and replace them with the notice and other provisions required by the
|
---|
30 | * LGPL. If you do not delete the provisions above, a recipient may use your
|
---|
31 | * version of this file under the terms of any one of the CDDL or the LGPL.
|
---|
32 | *
|
---|
33 | * ***** END LICENSE BLOCK ***** */
|
---|
34 | /*
|
---|
35 | * And remember, phase 3 is near...
|
---|
36 | */
|
---|
37 | #ifndef NOM_WPFolder_IMPLEMENTATION_FILE
|
---|
38 | #define NOM_WPFolder_IMPLEMENTATION_FILE
|
---|
39 | #endif
|
---|
40 |
|
---|
41 | #define INCL_DOS
|
---|
42 | #include <os2.h>
|
---|
43 |
|
---|
44 | #include "nom.h"
|
---|
45 | #include <nomtk.h>
|
---|
46 |
|
---|
47 | #include <string.h>
|
---|
48 | #include "gtk/gtk.h"
|
---|
49 |
|
---|
50 | typedef struct _PRIVFOLDERDATA
|
---|
51 | {
|
---|
52 | GtkListStore *gstoreFldContents;
|
---|
53 | GtkWidget *gtkIconView;
|
---|
54 | }PRIVFOLDERDATA, *PPRIVFOLDERDATA;
|
---|
55 |
|
---|
56 | typedef struct _FLDRGTREEKEY
|
---|
57 | {
|
---|
58 | PGTree pGTree;
|
---|
59 | gchar* chrKey;
|
---|
60 | }FLDRGTREEKEY, *PFLDRGTREEKEY;
|
---|
61 |
|
---|
62 | /* Gui stuff */
|
---|
63 | #include "nomguitk.h"
|
---|
64 | #include "nomwindow.h"
|
---|
65 | #include "desktoptypes.h"
|
---|
66 |
|
---|
67 | #include "wpnotebook.h"
|
---|
68 | #include "wpfolderwindow.h"
|
---|
69 | #include "m_wpfolder.h"
|
---|
70 | #include "wpfolder.ih"
|
---|
71 |
|
---|
72 | #include "wpdatafile.h"
|
---|
73 | #include "desktop.h"
|
---|
74 | #include "helper.h"
|
---|
75 | #include "exception.h"
|
---|
76 |
|
---|
77 | #include "nomdraginfo.h"
|
---|
78 |
|
---|
79 | /*
|
---|
80 | This struct is associated with the key in the contents tree of the
|
---|
81 | folder.
|
---|
82 | */
|
---|
83 | typedef struct _FLDRGTREEVALUE
|
---|
84 | {
|
---|
85 | PGTree pGTree;
|
---|
86 | WPObject* wpObject;
|
---|
87 | gchar* chrKey; /* <-- is this really needed? */
|
---|
88 | }FLDRGTREEVALUE, *PFLDRGTREEVALUE;
|
---|
89 |
|
---|
90 |
|
---|
91 | /* Enum for the folder store */
|
---|
92 | enum
|
---|
93 | {
|
---|
94 | COL_OBJECT_PTR,
|
---|
95 | COL_PATH,
|
---|
96 | COL_DISPLAY_NAME,
|
---|
97 | COL_PIXBUF,
|
---|
98 | NUM_COLS
|
---|
99 | };
|
---|
100 |
|
---|
101 | /*************** Local vars ************************************/
|
---|
102 |
|
---|
103 | /* This ID is used as a namespace */
|
---|
104 | static nomId WPFolderNomId;
|
---|
105 |
|
---|
106 | /***************************************************************/
|
---|
107 |
|
---|
108 |
|
---|
109 | /*
|
---|
110 | Private function to create the store with the data for displaying
|
---|
111 | objects in the icon view.
|
---|
112 | */
|
---|
113 | static GtkListStore * fldr_CreateStore (void)
|
---|
114 | {
|
---|
115 | GtkListStore *store;
|
---|
116 |
|
---|
117 | store = gtk_list_store_new (NUM_COLS,
|
---|
118 | G_TYPE_POINTER,
|
---|
119 | G_TYPE_STRING,
|
---|
120 | G_TYPE_STRING,
|
---|
121 | GDK_TYPE_PIXBUF);
|
---|
122 | return store;
|
---|
123 | }
|
---|
124 |
|
---|
125 |
|
---|
126 | /*
|
---|
127 | The folder is already populated, that means the internal folder list
|
---|
128 | is filled with all the objects in the folder. We traverse that list
|
---|
129 | and fill the store utilisized by the icon view with the objects.
|
---|
130 | */
|
---|
131 | static
|
---|
132 | gboolean fillStoreTraverseFunc(gpointer pKey, gpointer pTraverseValue, gpointer pData)
|
---|
133 | {
|
---|
134 | WPFolder* wpFolder=(PWPFolder)pData;
|
---|
135 | PFLDRGTREEVALUE pValue=pTraverseValue;
|
---|
136 |
|
---|
137 | WPFolder_wpAddToStore(wpFolder, pValue->wpObject,
|
---|
138 | NULLHANDLE);
|
---|
139 | return FALSE;
|
---|
140 | }
|
---|
141 |
|
---|
142 |
|
---|
143 | static gboolean
|
---|
144 | fldr_fillStore (WPFolder* nomSelf, GtkListStore *store)
|
---|
145 | {
|
---|
146 | WPFolderData* nomThis=WPFolderGetData(nomSelf);
|
---|
147 |
|
---|
148 | /* First clear the store */
|
---|
149 | if(_pListStore)
|
---|
150 | gtk_list_store_clear (_pListStore);
|
---|
151 |
|
---|
152 | /* Go over all objects in the folder */
|
---|
153 | g_tree_foreach(_fldrObjects, (GTraverseFunc) fillStoreTraverseFunc, nomSelf);
|
---|
154 |
|
---|
155 | return TRUE;
|
---|
156 | }
|
---|
157 |
|
---|
158 |
|
---|
159 | /**
|
---|
160 | Implementation for method wpAddToContent().
|
---|
161 |
|
---|
162 | Each folder has a balanced binary tree (GTree) holding all the objects in it.
|
---|
163 | The key one may use to search the tree is the name of an object. The associated
|
---|
164 | data is a struct holding some more info e.g. the GTree* pointer.
|
---|
165 | Using the name as the key allows to quickly check for duplicates.
|
---|
166 |
|
---|
167 | \sa wpAddToContent()
|
---|
168 | */
|
---|
169 | NOM_Scope gulong NOMLINK impl_WPFolder_wpAddToContent(WPFolder* nomSelf, const PWPObject wpObject,
|
---|
170 | CORBA_Environment *ev)
|
---|
171 | {
|
---|
172 | WPFolderData* nomThis=WPFolderGetData(nomSelf);
|
---|
173 | PFLDRGTREEVALUE pValue;
|
---|
174 |
|
---|
175 | pValue=(PFLDRGTREEVALUE)NOMMalloc(sizeof(FLDRGTREEVALUE));
|
---|
176 | pValue->pGTree=_fldrObjects;
|
---|
177 | pValue->wpObject=wpObject;
|
---|
178 | pValue->chrKey=NOMPath_copyCString( WPFileSystem_wpQueryFileName((WPFileSystem*)wpObject, FALSE, NULLHANDLE)
|
---|
179 | , NULLHANDLE);
|
---|
180 |
|
---|
181 | g_tree_insert(_fldrObjects, pValue->chrKey, pValue);
|
---|
182 |
|
---|
183 | return 0;
|
---|
184 | }
|
---|
185 |
|
---|
186 |
|
---|
187 | static gboolean fldrPrintListFunc(gpointer key, gpointer pValue, gpointer data)
|
---|
188 | {
|
---|
189 |
|
---|
190 | g_message("%s: key %p (%s), value %p, data %d", __FUNCTION__, key, (char*)key, pValue, (int)data);
|
---|
191 | return FALSE;
|
---|
192 | }
|
---|
193 |
|
---|
194 | static void fldrPrintContentsList(GTree* fldrObjects)
|
---|
195 | {
|
---|
196 | g_tree_foreach(fldrObjects, (GTraverseFunc) fldrPrintListFunc, (gpointer)123);
|
---|
197 | }
|
---|
198 |
|
---|
199 |
|
---|
200 | NOM_Scope PWPObject NOMLINK impl_WPFolder_wpQueryContent(WPFolder* nomSelf, CORBA_Environment *ev)
|
---|
201 | {
|
---|
202 | WPFolderData* nomThis=WPFolderGetData(nomSelf);
|
---|
203 |
|
---|
204 | fldrPrintContentsList(_fldrObjects);
|
---|
205 |
|
---|
206 | return NULLHANDLE;
|
---|
207 | }
|
---|
208 |
|
---|
209 | NOM_Scope CORBA_boolean NOMLINK impl_WPFolder_wpDeleteFromContent(WPFolder* nomSelf,
|
---|
210 | const PWPObject wpObject,
|
---|
211 | CORBA_Environment *ev)
|
---|
212 | {
|
---|
213 | WPFolderData* nomThis=WPFolderGetData(nomSelf);
|
---|
214 |
|
---|
215 | /* The destroy function isn't called here. That doesn't matter because the GC
|
---|
216 | will delete our data struct. If we ever have some stuff in the struct which
|
---|
217 | needs freeing we have to think again because the destroy function used by
|
---|
218 | g_tree_remove() will reinsert any object coming by so g_tree_remove() can't
|
---|
219 | be used. */
|
---|
220 | g_tree_steal(_fldrObjects, NOMPath_queryCString(WPFileSystem_wpQueryFileName((WPFileSystem*)wpObject,
|
---|
221 | FALSE, NULLHANDLE),
|
---|
222 | NULLHANDLE));
|
---|
223 | return TRUE;
|
---|
224 | }
|
---|
225 |
|
---|
226 |
|
---|
227 | NOM_Scope PUSEITEM NOMLINK impl_WPFolder_wpAddToStore(WPFolder* nomSelf, const PWPObject wpObject,
|
---|
228 | CORBA_Environment *ev)
|
---|
229 | {
|
---|
230 | WPFolderData* nomThis=WPFolderGetData(nomSelf);
|
---|
231 | PUSEITEM pui;
|
---|
232 | ULONG ulError;
|
---|
233 | GtkTreeIter iter;
|
---|
234 | gchar * display_name;
|
---|
235 |
|
---|
236 | if(!nomIsObj(wpObject))
|
---|
237 | return NULLHANDLE;
|
---|
238 |
|
---|
239 | if(!_pListStore)
|
---|
240 | return NULLHANDLE;
|
---|
241 |
|
---|
242 | #warning !!!!! Use Title here? !!!!!
|
---|
243 | display_name=NOMPath_copyCString(WPFileSystem_wpQueryFileName((WPFileSystem*)wpObject, FALSE, NULLHANDLE),
|
---|
244 | NULLHANDLE);/* Do we need a copy here? */
|
---|
245 |
|
---|
246 | gtk_list_store_append (_pListStore, &iter);
|
---|
247 | gtk_list_store_set (_pListStore, &iter,
|
---|
248 | COL_OBJECT_PTR, wpObject,
|
---|
249 | COL_PATH, "",
|
---|
250 | COL_DISPLAY_NAME, display_name,
|
---|
251 | COL_PIXBUF, _wpQueryIcon(wpObject, NULLHANDLE),
|
---|
252 | -1);
|
---|
253 |
|
---|
254 | /* Insert a STOREITEM into the objects inuse inuse list to track in which stores
|
---|
255 | the object lives. This item is later used when an object must be removed from
|
---|
256 | a folder window. */
|
---|
257 | pui=(PUSEITEM)_wpAllocMem(wpObject, sizeof(USEITEM)+sizeof(STOREITEM), &ulError, NULLHANDLE);
|
---|
258 | /* Fill the structures */
|
---|
259 | pui->type=(gulong)USAGE_STORE;
|
---|
260 | pui->wpObject=(PWPObject)wpObject;
|
---|
261 | pui++;
|
---|
262 | ((STOREITEM*)pui)->treeIter=iter;
|
---|
263 | ((STOREITEM*)pui)->pListStore=_pListStore;
|
---|
264 | pui--;
|
---|
265 | /* Object list not the one of the folder */
|
---|
266 | WPObject_wpAddToObjUseList(wpObject, pui, NULLHANDLE);
|
---|
267 |
|
---|
268 | return pui;
|
---|
269 | }
|
---|
270 |
|
---|
271 |
|
---|
272 | NOM_Scope PUSEITEM NOMLINK impl_WPFolder_wpDeleteFromStore(WPFolder* nomSelf, const PWPObject wpObject,
|
---|
273 | CORBA_Environment *ev)
|
---|
274 | {
|
---|
275 | WPFolderData* nomThis=WPFolderGetData(nomSelf);
|
---|
276 | PUSEITEM pui;
|
---|
277 |
|
---|
278 | /* Remove the object from the folder window. That means from the store. */
|
---|
279 | if(_pListStore)
|
---|
280 | {
|
---|
281 | /* Find the correct STOREITEM for this folder */
|
---|
282 | pui=_wpFindUseItem(wpObject, USAGE_STORE,
|
---|
283 | NULLHANDLE, NULLHANDLE);
|
---|
284 | while(pui){
|
---|
285 | GtkTreeIter iter;
|
---|
286 | pui++;
|
---|
287 | iter=((STOREITEM*)pui)->treeIter;
|
---|
288 | if(((STOREITEM*)pui)->pListStore==_pListStore)
|
---|
289 | {
|
---|
290 | pui--;
|
---|
291 | gtk_list_store_remove( _pListStore, &iter);
|
---|
292 | _wpDeleteFromObjUseList(wpObject, pui, NULLHANDLE);
|
---|
293 | //_wpFreeMem(wpObject, pui, NULLHANDLE);
|
---|
294 | break;
|
---|
295 | }
|
---|
296 | pui--;
|
---|
297 | pui=_wpFindUseItem(wpObject, USAGE_STORE, pui, NULLHANDLE);
|
---|
298 | }
|
---|
299 | }
|
---|
300 | return pui;
|
---|
301 | }
|
---|
302 |
|
---|
303 |
|
---|
304 | /* pszPath contains the fully qualified path (checked with WPS) */
|
---|
305 | NOM_Scope CORBA_boolean NOMLINK impl_WPFolder_wpPopulate(WPFolder* nomSelf, const CORBA_unsigned_long ulReserved,
|
---|
306 | const CORBA_char * pszPath, const CORBA_boolean fFoldersOnly,
|
---|
307 | CORBA_Environment *ev)
|
---|
308 | {
|
---|
309 | /* WPFolderData* nomThis=WPFolderGetData(nomSelf); */
|
---|
310 | GDir *gDir;
|
---|
311 | const gchar *gchrCurrentEntry;
|
---|
312 | const gchar* gchrPath;
|
---|
313 | PNOMPath fldrPath;
|
---|
314 |
|
---|
315 | /* Already populated? */
|
---|
316 | if(fFoldersOnly &&
|
---|
317 | (_wpQueryFldrFlags(nomSelf, NULLHANDLE) & (FOI_POPULATEDWITHFOLDERS | FOI_POPULATEDWITHALL)))
|
---|
318 | return TRUE;
|
---|
319 | else if(_wpQueryFldrFlags(nomSelf, NULLHANDLE) & FOI_POPULATEDWITHALL)
|
---|
320 | return TRUE;
|
---|
321 |
|
---|
322 |
|
---|
323 | /* Go through the directory and extract all the file
|
---|
324 | * information */
|
---|
325 | fldrPath=WPFolder_wpQueryFileName(nomSelf, TRUE, NULLHANDLE);
|
---|
326 | gchrPath=NOMPath_queryCString(fldrPath, NULLHANDLE);
|
---|
327 | gDir = g_dir_open(gchrPath, 0, NULL);
|
---|
328 | if (!gDir)
|
---|
329 | return FALSE;
|
---|
330 |
|
---|
331 | while ((gchrCurrentEntry = g_dir_read_name (gDir))!= NULL)
|
---|
332 | {
|
---|
333 | gchar *path, *display_name;
|
---|
334 |
|
---|
335 | if (gchrCurrentEntry[0] != '\0')
|
---|
336 | {
|
---|
337 | WPObject* wpObject;
|
---|
338 |
|
---|
339 | /* Filenames are in a special encoding with GLib */
|
---|
340 | path = g_build_filename (gchrPath, gchrCurrentEntry, NULL);
|
---|
341 |
|
---|
342 | /* The name to show to the user */
|
---|
343 | display_name = g_filename_to_utf8 (gchrCurrentEntry, -1, NULL, NULL, NULL);
|
---|
344 |
|
---|
345 | if(g_file_test (path, G_FILE_TEST_IS_DIR))
|
---|
346 | wpObject=(WPObject*)WPFolderNew(); /* It's a folder */
|
---|
347 | else{
|
---|
348 | if(!fFoldersOnly)
|
---|
349 | wpObject=(WPObject*)WPDataFileNew(); /* It's a file */
|
---|
350 | else
|
---|
351 | wpObject=NULLHANDLE;
|
---|
352 | }
|
---|
353 |
|
---|
354 | if(nomIsObj((PNOMObject)wpObject))
|
---|
355 | {
|
---|
356 | /* First ref living as long as the folder is awake */
|
---|
357 | WPObject_wpLockObject(wpObject, NULLHANDLE);
|
---|
358 | WPObject_wpSetTitleFromCString(wpObject, display_name, NULLHANDLE);
|
---|
359 | WPFileSystem_tstSetFullPath((WPFileSystem*)wpObject, gchrCurrentEntry, NULLHANDLE);
|
---|
360 | WPFileSystem_wpSetFolder(wpObject, nomSelf, NULLHANDLE);
|
---|
361 | #if 0
|
---|
362 | g_message("%d %s : %s (%x) , %s",
|
---|
363 | __LINE__, __FUNCTION__, gchrCurrentEntry, (UINT)wpObject,
|
---|
364 | NOMPath_queryCString(WPFolder_wpQueryFileName(wpObject, TRUE, NULLHANDLE), NULLHANDLE));
|
---|
365 | #endif
|
---|
366 | /* insert into contents list */
|
---|
367 | WPFolder_wpAddToContent(nomSelf, wpObject, NULLHANDLE);
|
---|
368 | }/* if(nomIsObj(wpObject)) */
|
---|
369 | g_free (path);
|
---|
370 | g_free (display_name);
|
---|
371 | }/* if (gchrCurrentEntry[0] != '\0') */
|
---|
372 | }/* while */
|
---|
373 | g_dir_close(gDir);
|
---|
374 |
|
---|
375 | if(fFoldersOnly)
|
---|
376 | _wpSetFldrFlags(nomSelf, FOI_POPULATEDWITHFOLDERS, FOI_POPULATEDWITHFOLDERS, NULLHANDLE);
|
---|
377 | else
|
---|
378 | _wpSetFldrFlags(nomSelf, FOI_POPULATEDWITHFOLDERS| FOI_POPULATEDWITHALL,
|
---|
379 | FOI_POPULATEDWITHFOLDERS| FOI_POPULATEDWITHALL, NULLHANDLE);
|
---|
380 |
|
---|
381 | return TRUE;
|
---|
382 | }
|
---|
383 |
|
---|
384 |
|
---|
385 | /*
|
---|
386 | This will change when NOMFolderWindow is migrated to WPFolderWindow.
|
---|
387 |
|
---|
388 | This delete handler is called when the folder window is closed. It removes
|
---|
389 | the view item from the folders inuse list.
|
---|
390 | */
|
---|
391 | static
|
---|
392 | gboolean tempWPWindowDeleteHandler(GtkWidget* gtkWidget, GdkEvent* gdkEvent, gpointer pData)
|
---|
393 | {
|
---|
394 | WPObject* wpObject;
|
---|
395 | WPFolderWindow* wpWindow;
|
---|
396 |
|
---|
397 | PUSEITEM pUseItem=(PUSEITEM) pData;
|
---|
398 |
|
---|
399 | /* This is also in the use item */
|
---|
400 | wpWindow=(WPFolderWindow*)g_object_get_data(G_OBJECT(gtkWidget), NOMOBJECT_KEY_STRING);
|
---|
401 |
|
---|
402 | g_return_val_if_fail(NULLHANDLE!=wpWindow, FALSE);
|
---|
403 |
|
---|
404 | wpObject=pUseItem->wpObject;
|
---|
405 | g_return_val_if_fail(NULLHANDLE!=wpObject, FALSE);
|
---|
406 |
|
---|
407 | WPObject_wpSaveDeferred(wpObject, NULLHANDLE);
|
---|
408 | /* Remove the open folder view from the inuse list */
|
---|
409 | WPObject_wpDeleteFromObjUseList(wpObject, pUseItem, NULLHANDLE);
|
---|
410 |
|
---|
411 | _wpFreeMem(wpObject, pUseItem, NULLHANDLE);
|
---|
412 |
|
---|
413 | return FALSE; /* Let other handlers run */
|
---|
414 | }
|
---|
415 |
|
---|
416 |
|
---|
417 | NOM_Scope gpointer NOMLINK impl_WPFolder_wpOpen(WPFolder* nomSelf, const PWPFolderWindow nomFolder,
|
---|
418 | const gulong ulView, const nomId nameSpaceId,
|
---|
419 | const gpointer pParam, CORBA_Environment *ev)
|
---|
420 | {
|
---|
421 | WPFolderData* nomThis=WPFolderGetData(nomSelf);
|
---|
422 | nomId nSpaceId=nameSpaceId;
|
---|
423 | gulong ulV=ulView;
|
---|
424 |
|
---|
425 | // g_message("In %s: %d %d %d", __FUNCTION__, WPFolderNomId, nameSpaceId, ulView);
|
---|
426 |
|
---|
427 | /* Special parameter representing a double click or "I just don't know" ;-) */
|
---|
428 | if(OPEN_DEFAULT==ulView)
|
---|
429 | ulV=WPFolder_wpQueryDefaultView(nomSelf, &nSpaceId, NULLHANDLE);
|
---|
430 |
|
---|
431 | /* We only handle items with in own name space */
|
---|
432 | if(WPFolderNomId==nSpaceId)
|
---|
433 | {
|
---|
434 | switch(ulV)
|
---|
435 | {
|
---|
436 | case OPEN_CONTENTS:
|
---|
437 | {
|
---|
438 | PUSEITEM pui;
|
---|
439 | ULONG ulError;
|
---|
440 | WPFolderWindow * wpFldrWindow;
|
---|
441 | gchar* pszPath;
|
---|
442 | // PPRIVFOLDERDATA priv;
|
---|
443 | // GtkListStore* gStore;
|
---|
444 | GtkIconView* gtkIconView;
|
---|
445 |
|
---|
446 | pszPath=NOMPath_queryCString(_wpQueryFileName(nomSelf, TRUE, NULLHANDLE), NULLHANDLE);
|
---|
447 | g_message("%d %s, %s", __LINE__, __FUNCTION__, pszPath);
|
---|
448 | /* Create the internal list of objects and make all these objects awake */
|
---|
449 | WPFolder_wpPopulate(nomSelf, 0L, pszPath, FALSE, NULLHANDLE);
|
---|
450 |
|
---|
451 | /* The folder window holding the objects */
|
---|
452 | wpFldrWindow=WPFolder_wpCreateFolderWindow(nomSelf, NULLHANDLE);
|
---|
453 |
|
---|
454 | /* Insert it into inuse list... */
|
---|
455 | pui=(PUSEITEM)WPFolder_wpAllocMem(nomSelf, sizeof(USEITEM)+sizeof(VIEWITEM), &ulError, NULLHANDLE);
|
---|
456 | /* Fill the structures */
|
---|
457 | pui->type=(gulong)USAGE_OPENVIEW;
|
---|
458 | pui->wpObject=(PWPObject)nomSelf;
|
---|
459 | pui++;
|
---|
460 | ((VIEWITEM*)pui)->ulView=OPEN_CONTENTS;
|
---|
461 | ((VIEWITEM*)pui)->nomWindow=(NOMWindow*)wpFldrWindow;
|
---|
462 | ((VIEWITEM*)pui)->nameSpaceId=WPFolderNomId;
|
---|
463 | pui--;
|
---|
464 | /* Make sure the view item is removed when the window is closed */
|
---|
465 | g_signal_connect(G_OBJECT(NOMWindow_queryWindowHandle((NOMWindow*)wpFldrWindow, NULLHANDLE)),
|
---|
466 | "delete-event",
|
---|
467 | G_CALLBACK(tempWPWindowDeleteHandler), (gpointer) pui);
|
---|
468 | WPFolder_wpAddToObjUseList(nomSelf, pui, NULLHANDLE);
|
---|
469 |
|
---|
470 | #if 0
|
---|
471 | /* Now create a folder store and insert icons into the window */
|
---|
472 | priv=_privFolderData;
|
---|
473 | gStore=priv->gstoreFldContents;
|
---|
474 | if(!gStore)
|
---|
475 | {
|
---|
476 | /* Create a store holding the folder contents */
|
---|
477 | gStore=fldr_CreateStore();
|
---|
478 | g_return_val_if_fail(gStore!=NULLHANDLE, FALSE);
|
---|
479 | priv->gstoreFldContents=gStore;
|
---|
480 |
|
---|
481 | /* Fill our store */
|
---|
482 | if(gStore)
|
---|
483 | fldr_fillStore(nomSelf, gStore, pszPath);
|
---|
484 | else
|
---|
485 | return FALSE;
|
---|
486 | }
|
---|
487 | gtkIconView=WPFolderWindow_wpQueryContainerHandle(wpFldrWindow, NULLHANDLE);
|
---|
488 | gtk_icon_view_set_model(GTK_ICON_VIEW (gtkIconView),
|
---|
489 | GTK_TREE_MODEL (priv->gstoreFldContents));
|
---|
490 | #endif
|
---|
491 | if(!_pListStore)
|
---|
492 | {
|
---|
493 |
|
---|
494 | if(( _pListStore=fldr_CreateStore())==NULLHANDLE){
|
---|
495 | g_warning("%s: Can't create store.", __FUNCTION__);
|
---|
496 | return FALSE;
|
---|
497 | }
|
---|
498 | /* Fill our store */
|
---|
499 | fldr_fillStore(nomSelf, _pListStore);
|
---|
500 | }
|
---|
501 |
|
---|
502 | gtkIconView=(GtkIconView*)WPFolderWindow_wpQueryContainerHandle(wpFldrWindow, NULLHANDLE);
|
---|
503 |
|
---|
504 | gtk_icon_view_set_model(GTK_ICON_VIEW (gtkIconView),
|
---|
505 | GTK_TREE_MODEL (_pListStore));
|
---|
506 |
|
---|
507 | /* We now set which model columns that correspond to the text
|
---|
508 | * and pixbuf of each item
|
---|
509 | */
|
---|
510 | gtk_icon_view_set_text_column (GTK_ICON_VIEW (gtkIconView), COL_DISPLAY_NAME);
|
---|
511 | gtk_icon_view_set_pixbuf_column (GTK_ICON_VIEW (gtkIconView), COL_PIXBUF);
|
---|
512 | gtk_icon_view_set_item_width (GTK_ICON_VIEW (gtkIconView), 100);
|
---|
513 |
|
---|
514 | // g_object_unref (gStore);
|
---|
515 |
|
---|
516 | return wpFldrWindow;
|
---|
517 | }/* default */
|
---|
518 | default:
|
---|
519 | break;
|
---|
520 | }/* switch */
|
---|
521 | }
|
---|
522 |
|
---|
523 | return WPFolder_wpOpen_parent(nomSelf, nomFolder, ulView, nameSpaceId, pParam, ev);
|
---|
524 | }
|
---|
525 |
|
---|
526 | NOM_Scope gpointer NOMLINK impl_WPFolder_wpQueryIcon(WPFolder* nomSelf, CORBA_Environment *ev)
|
---|
527 | {
|
---|
528 |
|
---|
529 | return M_WPFolder_wpclsQueryIcon( _nomGetClass((NOMObject*)nomSelf, NULLHANDLE), NULLHANDLE);
|
---|
530 |
|
---|
531 | #if 0
|
---|
532 | static const gchar *gchrIconName=NULLHANDLE;
|
---|
533 | static gpointer ptrIcon=NULLHANDLE;
|
---|
534 | GError *error=NULL;
|
---|
535 |
|
---|
536 | /* WPFolderData* nomThis=WPFolderGetData(nomSelf); */
|
---|
537 |
|
---|
538 | /* Load default wpObject icon */
|
---|
539 | if(!gchrIconName){
|
---|
540 | gchrIconName=g_build_filename(priv_getIconDir(), WPFOLDER_ICON_FILE, NULL);
|
---|
541 |
|
---|
542 | g_return_val_if_fail(g_file_test (gchrIconName, G_FILE_TEST_EXISTS), NULLHANDLE);
|
---|
543 | nomPrintf("IconFile: %s\n", gchrIconName);
|
---|
544 | // _hPointerCls = (HPOINTER)gdk_pixbuf_new_from_file (gchrIconName, &error);
|
---|
545 | ptrIcon=gdk_pixbuf_new_from_file (gchrIconName, &error);
|
---|
546 | }
|
---|
547 | return ptrIcon;
|
---|
548 |
|
---|
549 | /* WPFolder_wpQueryIcon_parent(nomSelf, ev); */
|
---|
550 | #endif
|
---|
551 | }
|
---|
552 |
|
---|
553 | NOM_Scope gulong NOMLINK impl_WPFolder_wpQueryDefaultView(WPFolder* nomSelf, const pnomId pNameSpaceId,
|
---|
554 | CORBA_Environment *ev)
|
---|
555 | {
|
---|
556 | *pNameSpaceId=WPFolderNomId;
|
---|
557 | return OPEN_CONTENTS;
|
---|
558 | }
|
---|
559 |
|
---|
560 |
|
---|
561 | static void
|
---|
562 | itemActivated (GtkIconView *widget,
|
---|
563 | GtkTreePath *treePath,
|
---|
564 | gpointer user_data)
|
---|
565 | {
|
---|
566 | PWPFolderWindow pWindow;
|
---|
567 |
|
---|
568 | pWindow=(WPFolderWindow*)user_data;
|
---|
569 |
|
---|
570 | if(NULL!=treePath)
|
---|
571 | {
|
---|
572 | GtkTreeIter iter;
|
---|
573 | GtkTreeModel* model;
|
---|
574 | WPObject *wpObject;
|
---|
575 |
|
---|
576 | /* Click on an icon */
|
---|
577 | model=gtk_icon_view_get_model(GTK_ICON_VIEW(widget));
|
---|
578 | gtk_tree_model_get_iter(model , &iter, treePath);
|
---|
579 |
|
---|
580 | gtk_tree_model_get(model, &iter,
|
---|
581 | 0, &wpObject,
|
---|
582 | -1);
|
---|
583 | g_message("%s: %s", __FUNCTION__, wpObject->mtab->nomClassName);
|
---|
584 | /* WPObject_wpOpen(wpObject, pWindow, OPEN_CONTENTS, NULL, NULL); */
|
---|
585 | TRY(FLDR_ITEMACTIVATED) {
|
---|
586 | WPObject_wpViewObject(wpObject, pWindow, OPEN_DEFAULT, 0, NULLHANDLE, NULL);
|
---|
587 | }
|
---|
588 | CATCH{
|
---|
589 | LOUD;
|
---|
590 | g_message("Line %d: Trap in %s", __LINE__, __FUNCTION__);
|
---|
591 | }END_CATCH(FLDR_ITEMACTIVATED);
|
---|
592 | }
|
---|
593 | }
|
---|
594 |
|
---|
595 |
|
---|
596 | #if 0
|
---|
597 | /**
|
---|
598 | Get the WPFolder object from a container widget (icon view). If the object can't be queried
|
---|
599 | NULL is returned.
|
---|
600 | Note that this function checks if the pointer points to a NOMObject so a call to
|
---|
601 | nomIsObj() is not necessary.
|
---|
602 | */
|
---|
603 | static PWPFolder fldrQueryWPFolderFromContainer(GtkWidget * wgtThis)
|
---|
604 | {
|
---|
605 | GtkWidget* wgtToplevel;
|
---|
606 | PWPFolder wpFolder;
|
---|
607 |
|
---|
608 | if((wgtToplevel=gtk_widget_get_toplevel(wgtThis))==NULLHANDLE)
|
---|
609 | return NULLHANDLE;
|
---|
610 |
|
---|
611 | if(!GTK_WIDGET_TOPLEVEL(wgtToplevel))
|
---|
612 | return NULLHANDLE;
|
---|
613 |
|
---|
614 | wpFolder=(PWPFolder) g_object_get_data(G_OBJECT(wgtToplevel), NOMOBJECT_KEY_STRING);
|
---|
615 | if(nomIsObj(wpFolder))
|
---|
616 | return wpFolder;
|
---|
617 |
|
---|
618 | return NULLHANDLE;
|
---|
619 | }
|
---|
620 | #endif
|
---|
621 |
|
---|
622 |
|
---|
623 | /**
|
---|
624 | This method creates the folder window it doesn't query any files or creates
|
---|
625 | models and stuff.
|
---|
626 | */
|
---|
627 | NOM_Scope PWPFolderWindow NOMLINK impl_WPFolder_wpCreateFolderWindow(WPFolder* nomSelf, CORBA_Environment *ev)
|
---|
628 | {
|
---|
629 | WPFolderWindow * wpFldrWindow;
|
---|
630 | PPRIVFOLDERDATA priv;
|
---|
631 | WPFolderData *nomThis = WPFolderGetData(nomSelf);
|
---|
632 |
|
---|
633 | priv=(PPRIVFOLDERDATA)_privFolderData;
|
---|
634 |
|
---|
635 | wpFldrWindow=WPFolderWindowNew();
|
---|
636 |
|
---|
637 | /* Save a pointer to the desktop folder object */
|
---|
638 | WPFolderWindow_wpSetObject(wpFldrWindow, (WPObject*)nomSelf, NULLHANDLE);
|
---|
639 |
|
---|
640 | /* Connect to the "item_activated" signal */
|
---|
641 | g_signal_connect (WPFolderWindow_wpQueryContainerHandle(wpFldrWindow, NULLHANDLE), "item-activated",
|
---|
642 | G_CALLBACK (itemActivated), nomSelf);
|
---|
643 |
|
---|
644 | WPFolderWindow_wpSetWindowTitle(wpFldrWindow, WPFolder_wpQueryTitle(nomSelf, NULLHANDLE), NULLHANDLE);
|
---|
645 |
|
---|
646 | /* Show the new window */
|
---|
647 | WPFolderWindow_show(wpFldrWindow, ev);
|
---|
648 |
|
---|
649 | return wpFldrWindow;
|
---|
650 | }
|
---|
651 |
|
---|
652 |
|
---|
653 | NOM_Scope gulong NOMLINK impl_WPFolder_wpQueryFldrFlags(WPFolder* nomSelf, CORBA_Environment *ev)
|
---|
654 | {
|
---|
655 | WPFolderData* nomThis=WPFolderGetData(nomSelf);
|
---|
656 |
|
---|
657 | return g_atomic_int_get(&_ulFldrFlags);
|
---|
658 | }
|
---|
659 |
|
---|
660 |
|
---|
661 | NOM_Scope CORBA_boolean NOMLINK impl_WPFolder_wpSetFldrFlags(WPFolder* nomSelf, const gulong ulFlags,
|
---|
662 | const gulong ulMask, CORBA_Environment *ev)
|
---|
663 | {
|
---|
664 | WPFolderData* nomThis=WPFolderGetData(nomSelf);
|
---|
665 |
|
---|
666 | g_message("Calling %s", __FUNCTION__);
|
---|
667 | WPFolder_wpRequestObjectMutexSem(nomSelf, 0,ev);
|
---|
668 |
|
---|
669 | _ulFldrFlags=(_ulFldrFlags & ~ulMask)| ulFlags;
|
---|
670 |
|
---|
671 | WPFolder_wpReleaseObjectMutexSem(nomSelf,ev);
|
---|
672 |
|
---|
673 | return TRUE;
|
---|
674 | }
|
---|
675 |
|
---|
676 |
|
---|
677 | /* FIXME: type and name of containerHandle is wrong */
|
---|
678 | NOM_Scope gulong NOMLINK impl_WPFolder_wpDragOver(WPFolder* nomSelf, const gpointer containerHandle,
|
---|
679 | const gpointer pDragInfo, CORBA_Environment *ev)
|
---|
680 | {
|
---|
681 | /* WPFolderData* nomThis=WPFolderGetData(nomSelf); */
|
---|
682 | gulong ulNumItems, ulLoop;
|
---|
683 | NOMDragInfo* nomDragInfo=(NOMDragInfo*)pDragInfo;
|
---|
684 |
|
---|
685 | if(!nomIsObj(nomDragInfo))
|
---|
686 | return DOR_NODROP;
|
---|
687 |
|
---|
688 | ulNumItems=NOMDragInfo_queryNumDragItems(nomDragInfo, NULLHANDLE);
|
---|
689 |
|
---|
690 | /* No items? */
|
---|
691 | if(0==ulNumItems)
|
---|
692 | return DOR_NODROP;
|
---|
693 |
|
---|
694 | for(ulLoop=0; ulLoop<ulNumItems; ulLoop++)
|
---|
695 | {
|
---|
696 | /* We only accept desktop objects for now */
|
---|
697 | if(!NOMDragInfo_queryIsItemWPObject(nomDragInfo, ulLoop, NULLHANDLE))
|
---|
698 | return DOR_NODROP;
|
---|
699 | /* No dropping on the source folder for now */
|
---|
700 | if(nomSelf==(WPFolder*)
|
---|
701 | NOMDragInfo_querySourceWPObject(nomDragInfo, ulLoop, NULLHANDLE))
|
---|
702 | return DOR_NODROP;
|
---|
703 | /* No dropping on itself */
|
---|
704 | if(nomSelf==(WPFolder*)
|
---|
705 | NOMDragInfo_queryWPObjectFromItemList(nomDragInfo, ulLoop, NULLHANDLE))
|
---|
706 | return DOR_NODROP;
|
---|
707 | }
|
---|
708 |
|
---|
709 | return GDK_ACTION_MOVE;
|
---|
710 |
|
---|
711 | #if 0
|
---|
712 | WPFolder_wpDragOver_parent(nomSelf, ev);
|
---|
713 | #endif
|
---|
714 | }
|
---|
715 |
|
---|
716 |
|
---|
717 | #if 0
|
---|
718 | static gint fldrCompareObjects(gconstpointer a, gconstpointer b, gpointer pUserData)
|
---|
719 | {
|
---|
720 | return strcmp(((PFLDRGTREEKEY)a)->chrKey, ((PFLDRGTREEKEY)b)->chrKey);
|
---|
721 | }
|
---|
722 | #endif
|
---|
723 |
|
---|
724 | static void fldrCatchDuplicates(gpointer pOrgValue)
|
---|
725 | {
|
---|
726 | PFLDRGTREEVALUE pValue;
|
---|
727 | PFLDRGTREEVALUE pValueRemove;
|
---|
728 |
|
---|
729 | pValue=(PFLDRGTREEVALUE)pOrgValue;
|
---|
730 |
|
---|
731 | g_message("%d %s: value (object): %x %s", __LINE__, __FUNCTION__, (UINT)pValue->wpObject, pValue->chrKey);
|
---|
732 |
|
---|
733 | #warning !!!!! Duplicate handling is still kind of broken !!!!!
|
---|
734 | /*
|
---|
735 | When we end here another object with the same key was inserted. This may be due to populating
|
---|
736 | all when we first just populated with folders. ATM we just remove the accidently inserted
|
---|
737 | second data and reinsert the original data (which may be already used by now). The wrong data
|
---|
738 | must be freed here later.
|
---|
739 | We should check the lock counter if we really dealing with wrong insertion here before freeing.
|
---|
740 | This way we might use this func also for freeing when normally removing objects.
|
---|
741 | */
|
---|
742 | /* Remove the wrong data */
|
---|
743 | pValueRemove=(PFLDRGTREEVALUE)g_tree_lookup(pValue->pGTree, pValue->chrKey);
|
---|
744 | g_tree_steal(pValue->pGTree, pValue->chrKey); /* This does not free the stuff in this func */
|
---|
745 | /* Reinsert the old one */
|
---|
746 | g_tree_insert(pValue->pGTree, pValue->chrKey, pValue);
|
---|
747 | }
|
---|
748 |
|
---|
749 |
|
---|
750 | NOM_Scope void NOMLINK impl_WPFolder_wpInitData(WPFolder* nomSelf, CORBA_Environment *ev)
|
---|
751 | {
|
---|
752 | gulong ulErr;
|
---|
753 | WPFolderData* nomThis=WPFolderGetData(nomSelf);
|
---|
754 |
|
---|
755 | WPFolder_wpInitData_parent((WPObject*)nomSelf, ev);
|
---|
756 |
|
---|
757 | /* Get our unique class ID. We need it for example when inserting menu items to
|
---|
758 | specify the namespace. We query it here because getting a GQuark from a string
|
---|
759 | is rather time consuming. The result is saved in a var for later use. */
|
---|
760 | WPFolderNomId=nomIdFromString("WPFolder");//g_quark_from_string("WPFolder");
|
---|
761 |
|
---|
762 | nomPrintf(" Entering %s with nomSelf: 0x%x. nomSelf is: %s.\n",
|
---|
763 | __FUNCTION__, nomSelf , nomSelf->mtab->nomClassName);
|
---|
764 | _privFolderData=_wpAllocMem((WPObject*)nomSelf, sizeof(PRIVFOLDERDATA),&ulErr, NULLHANDLE);
|
---|
765 |
|
---|
766 | /* This balanced binary tree holds the objects in this folder. We create a tree
|
---|
767 | which may be searched using the name of the file/directory */
|
---|
768 | _fldrObjects=g_tree_new_full((GCompareDataFunc)strcmp, nomSelf, NULL,
|
---|
769 | (GDestroyNotify) fldrCatchDuplicates);
|
---|
770 | }
|
---|
771 |
|
---|
772 | NOM_Scope gulong NOMLINK impl_WPFolder_wpDrop(WPFolder* nomSelf,
|
---|
773 | const gpointer containerHandle,
|
---|
774 | const gpointer pDragInfo,
|
---|
775 | CORBA_Environment *ev)
|
---|
776 | {
|
---|
777 | /* WPFolderData* nomThis=WPFolderGetData(nomSelf); */
|
---|
778 | gulong ulNumItems, ulLoop;
|
---|
779 | GdkDragAction gda;
|
---|
780 |
|
---|
781 | NOMDragInfo* nomDragInfo=(NOMDragInfo*)pDragInfo;
|
---|
782 |
|
---|
783 | g_message("%s", __FUNCTION__);
|
---|
784 |
|
---|
785 | if(!nomIsObj(nomDragInfo))
|
---|
786 | return 0;
|
---|
787 |
|
---|
788 | ulNumItems=NOMDragInfo_queryNumDragItems(nomDragInfo, NULLHANDLE);
|
---|
789 |
|
---|
790 | /* No items? */
|
---|
791 | if(0==ulNumItems)
|
---|
792 | return 0;
|
---|
793 |
|
---|
794 | /* That's the action the user selected by pressing a key during drop */
|
---|
795 | gda=NOMDragInfo_queryChosenDropAction(nomDragInfo, NULLHANDLE);
|
---|
796 |
|
---|
797 | for(ulLoop=0; ulLoop<ulNumItems; ulLoop++)
|
---|
798 | {
|
---|
799 | WPObject* wpObject;
|
---|
800 |
|
---|
801 | wpObject=NOMDragInfo_querySourceWPObject(nomDragInfo, ulLoop, NULLHANDLE);
|
---|
802 | g_message("Source folder is: %s",
|
---|
803 | NOMPath_queryCString(WPFolder_wpQueryFileName(wpObject, TRUE, NULLHANDLE),
|
---|
804 | NULLHANDLE));
|
---|
805 | wpObject=NOMDragInfo_queryWPObjectFromItemList(nomDragInfo, ulLoop, NULLHANDLE);
|
---|
806 | g_message("Dropped object is: %s",
|
---|
807 | NOMPath_queryCString(WPFolder_wpQueryFileName(wpObject, TRUE, NULLHANDLE),
|
---|
808 | NULLHANDLE));
|
---|
809 |
|
---|
810 | g_message("%s: drop action: %d", __FUNCTION__, gda);
|
---|
811 |
|
---|
812 | wpObject=NOMDragInfo_queryWPObjectFromItemList(nomDragInfo, ulLoop, NULLHANDLE);
|
---|
813 | switch(gda)
|
---|
814 | {
|
---|
815 | case GDK_ACTION_MOVE:
|
---|
816 | {
|
---|
817 | WPObject_wpMoveObject(wpObject, nomSelf, NULLHANDLE);
|
---|
818 | break;
|
---|
819 | }
|
---|
820 | /* Copy shouldn't be default I guess... */
|
---|
821 | default:
|
---|
822 | {
|
---|
823 | WPObject_wpCopyObject(wpObject, nomSelf, FALSE, NULLHANDLE);
|
---|
824 | break;
|
---|
825 | }
|
---|
826 | }
|
---|
827 | }
|
---|
828 |
|
---|
829 |
|
---|
830 |
|
---|
831 | #if 0
|
---|
832 | WPFolder_wpDrop_parent(nomSelf, ev);
|
---|
833 | #endif
|
---|
834 | return 0;
|
---|
835 | }
|
---|
836 |
|
---|
837 |
|
---|
838 |
|
---|
839 |
|
---|
840 |
|
---|
841 |
|
---|
842 |
|
---|