Changeset 186 for trunk/desktop/class_c/wpfolder.c
- Timestamp:
- Jan 13, 2007, 12:36:01 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/desktop/class_c/wpfolder.c
r183 r186 48 48 #include "gtk/gtk.h" 49 49 50 #warning !!!!! nomIsObj() must be globaly defined !!!!!51 #define nomIsObj(a) ((a)!= 0)52 53 50 typedef struct _PRIVFOLDERDATA 54 51 { … … 56 53 GtkWidget *gtkIconView; 57 54 }PRIVFOLDERDATA, *PPRIVFOLDERDATA; 55 56 typedef struct _FLDRGTREEKEY 57 { 58 PGTree pGTree; 59 gchar* chrKey; 60 }FLDRGTREEKEY, *PFLDRGTREEKEY; 58 61 59 62 /* Gui stuff */ … … 69 72 #include "helper.h" 70 73 74 typedef struct _FLDRGTREEVALUE 75 { 76 PGTree pGTree; 77 WPObject* wpObject; 78 const gchar* chrKey; 79 }FLDRGTREEVALUE, *PFLDRGTREEVALUE; 71 80 72 81 … … 92 101 GDK_TYPE_PIXBUF, 93 102 G_TYPE_BOOLEAN); 94 g_message("%s: store: %x", __FUNCTION__, store);103 g_message("%s: store: %x", __FUNCTION__, (UINT) store); 95 104 return store; 96 105 } 97 106 107 #if 0 98 108 static BOOL 99 109 fldr_fillStore (GtkListStore *store, const gchar* gchrPath) … … 132 142 133 143 wpFolder=WPFolderNew(); 134 if(nomIsObj( wpFolder))144 if(nomIsObj((PNOMObject)wpFolder)) 135 145 { 136 146 gtk_list_store_append (store, &iter); … … 153 163 wpDataFile=WPDataFileNew(); 154 164 155 if(nomIsObj( wpDataFile))165 if(nomIsObj((PNOMObject)wpDataFile)) 156 166 { 157 167 gtk_list_store_append (store, &iter); … … 177 187 return TRUE; 178 188 } 179 180 189 /* pszPath contains the fully qualified path (checked with WPS) */ 181 190 NOM_Scope CORBA_boolean NOMLINK impl_WPFolder_wpPopulate(WPFolder* nomSelf, const CORBA_unsigned_long ulReserved, … … 197 206 /* Already populated? */ 198 207 if(fFoldersOnly && 199 (_wpQueryFldrFlags( somSelf) & (FOI_POPULATEDWITHFOLDERS | FOI_POPULATEDWITHALL)))208 (_wpQueryFldrFlags(nomSelf) & (FOI_POPULATEDWITHFOLDERS | FOI_POPULATEDWITHALL))) 200 209 return TRUE; 201 else if(_wpQueryFldrFlags( somSelf) & FOI_POPULATEDWITHALL)210 else if(_wpQueryFldrFlags(nomSelf) & FOI_POPULATEDWITHALL) 202 211 return TRUE; 203 212 #endif … … 233 242 return FALSE; 234 243 } 244 /* Insert an object into the folders object list */ 245 void tst_insertObject(WPFolder* nomSelf, WPObject* wpObject, gchar* chrName) 246 { 247 WPFolderData* nomThis=WPFolderGetData(nomSelf); 248 249 g_tree_insert(_fldrObjects, chrName, wpObject); 250 } 251 #endif 252 253 static 254 gboolean fillStoreTraverseFunc(gpointer pKey, gpointer pTraverseValue, gpointer pData) 255 { 256 GtkTreeIter iter; 257 PFLDRGTREEVALUE pValue=pTraverseValue; 258 gchar * display_name; 259 GtkListStore *store=(GtkListStore *)pData; 260 261 g_message("In %s with %s %x", __FUNCTION__, (char*)pKey, (UINT)pValue->wpObject); 262 263 #warning !!!!! Use Title here !!!!! 264 display_name=pKey; 265 266 267 if(!strcmp("WPDataFile", pValue->wpObject->mtab->nomClassName)){ 268 WPDataFile* wpDataFile; 269 270 wpDataFile=(WPDataFile*)pValue->wpObject; 271 272 if(nomIsObj((PNOMObject)wpDataFile)) 273 { 274 gtk_list_store_append (store, &iter); 275 276 #warning !!!! some problems with icon handling here !!!! 277 //nomPrintf("Icon ptr: %x\n", _wpQueryIcon((WPObject*)wpDataFile, NULLHANDLE)); 278 gtk_list_store_set (store, &iter, 279 COL_OBJECT_PTR, wpDataFile, 280 COL_PATH, "", 281 COL_DISPLAY_NAME, display_name, 282 COL_IS_DIRECTORY, FALSE, 283 COL_PIXBUF, _wpQueryIcon((WPObject*)wpDataFile, NULLHANDLE), //file_pixbuf, 284 -1); 285 } 286 } 287 else{ 288 WPFolder* wpFolder; 289 290 wpFolder=(WPFolder*)pValue->wpObject; 291 292 if(nomIsObj((NOMObject*)wpFolder)){ 293 294 g_message("%d %s : %s, %s", 295 __LINE__, __FUNCTION__, (char*)pKey, 296 NOMPath_queryCString(WPFolder_wpQueryFileName(wpFolder, TRUE, NULLHANDLE), NULLHANDLE)); 297 298 299 gtk_list_store_append (store, &iter); 300 301 gtk_list_store_set (store, &iter, 302 COL_OBJECT_PTR, wpFolder, 303 COL_PATH, "", 304 COL_DISPLAY_NAME, display_name, 305 COL_IS_DIRECTORY, TRUE, 306 COL_PIXBUF, _wpQueryIcon((WPObject*)wpFolder, NULLHANDLE), //folder_pixbuf , 307 -1); 308 } 309 } 310 311 return FALSE; /* Traverse every item */ 312 } 313 314 static gboolean 315 fldr_fillStore (WPFolder* nomSelf, GtkListStore *store, const gchar* gchrPath) 316 { 317 WPFolderData* nomThis=WPFolderGetData(nomSelf); 318 319 nomPrintf("In %s: %s\n", __FUNCTION__, gchrPath); 320 321 /* First clear the store */ 322 gtk_list_store_clear (store); 323 324 g_tree_foreach(_fldrObjects, (GTraverseFunc) fillStoreTraverseFunc, store); 325 326 return TRUE; 327 } 328 329 330 NOM_Scope gulong NOMLINK impl_WPFolder_wpAddToContent(WPFolder* nomSelf, const PWPObject wpObject, 331 const CORBA_char * chrFileName, CORBA_Environment *ev) 332 { 333 WPFolderData* nomThis=WPFolderGetData(nomSelf); 334 PFLDRGTREEVALUE pValue; 335 336 pValue=(PFLDRGTREEVALUE)NOMMalloc(sizeof(FLDRGTREEVALUE)); 337 pValue->pGTree=_fldrObjects; 338 pValue->wpObject=wpObject; 339 pValue->chrKey=chrFileName; 340 g_tree_insert(_fldrObjects, chrFileName, pValue); 341 342 #if 0 343 PFLDRGTREEKEY pKey; 344 pKey=(PFLDRGTREEKEY)NOMMalloc(sizeof(FLDRGTREEKEY)); 345 pKey->pGTree=_fldrObjects; 346 pKey->chrKey=chrFileName; 347 g_tree_insert(_fldrObjects, pKey, wpObject); 348 #endif 349 350 return 0; 351 } 352 353 NOM_Scope PWPObject NOMLINK impl_WPFolder_wpQueryContent(WPFolder* nomSelf, CORBA_Environment *ev) 354 { 355 /* WPFolderData* nomThis=WPFolderGetData(nomSelf); */ 356 PWPObject nomRetval; 357 358 return nomRetval; 359 } 360 361 362 /* pszPath contains the fully qualified path (checked with WPS) */ 363 NOM_Scope CORBA_boolean NOMLINK impl_WPFolder_wpPopulate(WPFolder* nomSelf, const CORBA_unsigned_long ulReserved, 364 const CORBA_char * pszPath, const CORBA_boolean fFoldersOnly, 365 CORBA_Environment *ev) 366 { 367 /* WPFolderData* nomThis=WPFolderGetData(nomSelf); */ 368 GDir *gDir; 369 const gchar *gchrCurrentEntry; 370 const gchar* gchrPath; 371 PNOMPath fldrPath; 372 373 g_log("WPFolder", G_LOG_LEVEL_DEBUG, "%s: Populating %s (0x%x)\n", __FUNCTION__, pszPath, (UINT)nomSelf); 374 375 /* Already populated? */ 376 if(fFoldersOnly && 377 (_wpQueryFldrFlags(nomSelf, NULLHANDLE) & (FOI_POPULATEDWITHFOLDERS | FOI_POPULATEDWITHALL))) 378 return TRUE; 379 else if(_wpQueryFldrFlags(nomSelf, NULLHANDLE) & FOI_POPULATEDWITHALL) 380 return TRUE; 381 382 /* Go through the directory and extract all the file 383 * information */ 384 fldrPath=WPFolder_wpQueryFileName(nomSelf, TRUE, NULLHANDLE); 385 gchrPath=NOMPath_queryCString(fldrPath, NULLHANDLE); 386 gDir = g_dir_open(gchrPath, 0, NULL); 387 if (!gDir) 388 return FALSE; 389 390 while ((gchrCurrentEntry = g_dir_read_name (gDir))!= NULL) 391 { 392 gchar *path, *display_name; 393 394 if (gchrCurrentEntry[0] != '\0') 395 { 396 WPObject* wpObject; 397 398 path = g_build_filename (gchrPath, gchrCurrentEntry, NULL); 399 400 display_name = g_filename_to_utf8 (gchrCurrentEntry, -1, NULL, NULL, NULL); 401 402 if(g_file_test (path, G_FILE_TEST_IS_DIR)) 403 wpObject=(WPObject*)WPFolderNew(); /* It's a folder */ 404 else{ 405 if(!fFoldersOnly) 406 wpObject=(WPObject*)WPDataFileNew(); /* It's a file */ 407 else 408 wpObject=NULLHANDLE; 409 } 410 if(nomIsObj((PNOMObject)wpObject)) 411 { 412 WPObject_wpSetTitleFromCString(wpObject, display_name, NULLHANDLE); 413 WPFileSystem_tstSetFullPath((WPFileSystem*)wpObject, gchrCurrentEntry, NULLHANDLE); 414 WPFileSystem_wpSetFolder(wpObject, nomSelf, NULLHANDLE); 415 g_message("%d %s : %s (%x) , %s", 416 __LINE__, __FUNCTION__, gchrCurrentEntry, (UINT)wpObject, 417 NOMPath_queryCString(WPFolder_wpQueryFileName(wpObject, TRUE, NULLHANDLE), NULLHANDLE)); 418 419 /* insert into contents list */ 420 WPFolder_wpAddToContent(nomSelf, wpObject, g_strdup(gchrCurrentEntry), NULLHANDLE); 421 }/* if(nomIsObj(wpObject)) */ 422 g_free (path); 423 g_free (display_name); 424 }/* if (gchrCurrentEntry[0] != '\0') */ 425 }/* while */ 426 g_dir_close(gDir); 427 428 if(fFoldersOnly) 429 _wpSetFldrFlags(nomSelf, FOI_POPULATEDWITHFOLDERS, FOI_POPULATEDWITHFOLDERS, NULLHANDLE); 430 else 431 _wpSetFldrFlags(nomSelf, FOI_POPULATEDWITHFOLDERS| FOI_POPULATEDWITHALL, 432 FOI_POPULATEDWITHFOLDERS| FOI_POPULATEDWITHALL, NULLHANDLE); 433 434 return TRUE; 435 } 436 437 438 /* 439 This will change when NOMFolderWindow is migrated to WPFolderWindow. 440 */ 441 static 442 gboolean tempWPWindowDeleteHandler(GtkWidget* gtkWidget, GdkEvent* gdkEvent, gpointer pData) 443 { 444 WPObject* wpObject; 445 NOMFolderWindow* wpWindow; 446 447 PUSEITEM pUseItem=(PUSEITEM) pData; 448 449 /* This is also in the use item */ 450 wpWindow=(NOMFolderWindow*)g_object_get_data(G_OBJECT(gtkWidget), NOMOBJECT_KEY_STRING); 451 452 g_return_val_if_fail(NULLHANDLE!=wpWindow, FALSE); 453 454 /* This call will be different when using WPFolderWindow */ 455 //wpObject=NOMFolderWindow_wpQueryWPFolderObject(wpWindow, NULLHANDLE); 456 wpObject=pUseItem->wpObject; 457 g_return_val_if_fail(NULLHANDLE!=wpObject, FALSE); 458 459 WPObject_wpSaveDeferred(wpObject, NULLHANDLE); 460 461 WPObject_wpDeleteFromObjUseList(wpObject, pUseItem, NULLHANDLE); 462 463 return FALSE; /* Let other handlers run */ 464 } 465 235 466 236 467 NOM_Scope gpointer NOMLINK impl_WPFolder_wpOpen(WPFolder* nomSelf, const PNOMFolderWindow nomFolder, … … 238 469 CORBA_Environment *ev) 239 470 { 240 /* WPFolderData* nomThis=WPFolderGetData(nomSelf); */ 241 471 WPFolderData* nomThis=WPFolderGetData(nomSelf); 472 g_message("%d %s", __LINE__, __FUNCTION__); 242 473 switch(ulView) 243 474 { … … 245 476 case OPEN_DEFAULT: 246 477 { 247 static NOMFolderWindow * nomFldrWindow; 248 478 PUSEITEM pui; 479 ULONG ulError; 480 NOMFolderWindow * nomFldrWindow; 481 gchar* pszPath; 482 PPRIVFOLDERDATA priv; 483 GtkListStore* gStore; 484 485 pszPath=NOMPath_queryCString(WPFolder_wpQueryFileName(nomSelf, TRUE, NULLHANDLE), NULLHANDLE); 486 g_message("%d %s, %s", __LINE__, __FUNCTION__, pszPath); 487 WPFolder_wpPopulate(nomSelf, 0L, pszPath, FALSE, NULLHANDLE); 488 489 490 nomFldrWindow=WPFolder_wpCreateFolderWindow(nomSelf, ev); 491 #warning !!!!! There is WPWindow now. Use that for any WPS windows, Then this call must be changed 492 NOMFolderWindow_setWPFolderObject(nomFldrWindow, nomSelf, NULLHANDLE); 493 494 /* Insert it into inuse list */ 495 pui=(PUSEITEM)WPFolder_wpAllocMem(nomSelf, sizeof(USEITEM)+sizeof(VIEWITEM), &ulError, ev); 496 /* Fill the structures */ 497 pui->type=(gulong)USAGE_OPENVIEW; 498 pui->wpObject=(PWPObject)nomSelf; 499 pui++; 500 ((VIEWITEM*)pui)->ulView=VIEW_CONTENTS; 501 ((VIEWITEM*)pui)->nomWindow=(NOMWindow*)nomFldrWindow; 502 pui--; 249 503 #warning !!!!! Folder window must be inserted into inuse list !!!!! 250 nomFldrWindow=WPFolder_wpCreateFolderWindow(nomSelf, ev); 251 NOMFolderWindow_setWPFolderObject(nomFldrWindow, nomSelf, ev); 252 253 #warning !!!!! Path taken from a test location !!!!! 254 WPFolder_wpPopulate(nomSelf, 0L, NOMPath_queryCString(WPFolder_wpQueryFileName(nomSelf, TRUE, ev) , ev), FALSE, ev); 255 break; 256 257 #if 0 258 char path[CCHMAXPATH]; 259 ULONG ulSize; 504 /* Make sure the view item is removed when the window is closed */ 505 g_signal_connect(G_OBJECT(NOMWindow_queryWindowHandle((NOMWindow*)nomFldrWindow, NULLHANDLE)),"delete-event", 506 G_CALLBACK(tempWPWindowDeleteHandler), (gpointer) pui); 507 WPFolder_wpAddToObjUseList(nomSelf, pui, NULLHANDLE); 508 509 /* Now create a folder store and insert icons into the window */ 510 priv=_privFolderData; 511 gStore=priv->gstoreFldContents; 512 513 if(!gStore) 514 { 515 /* Create a store holding the folder contents */ 516 gStore=fldr_CreateStore(); 517 g_return_val_if_fail(gStore!=NULLHANDLE, FALSE); 518 priv->gstoreFldContents=gStore; 519 } 520 521 /* Fill our store */ 522 if(gStore) 523 fldr_fillStore(nomSelf, gStore, pszPath); 524 else 525 return FALSE; 260 526 261 /* Get full path of folder */ 262 ulSize=sizeof(path); 527 gtk_icon_view_set_model(GTK_ICON_VIEW (priv->gtkIconView), GTK_TREE_MODEL (priv->gstoreFldContents)); 263 528 264 if(!_wpQueryRealName(somSelf, path, &ulSize, TRUE)) 265 return NULLHANDLE; /* Error */ 529 /* We now set which model columns that correspond to the text 530 * and pixbuf of each item 531 */ 532 gtk_icon_view_set_text_column (GTK_ICON_VIEW (priv->gtkIconView), COL_DISPLAY_NAME); 533 gtk_icon_view_set_pixbuf_column (GTK_ICON_VIEW (priv->gtkIconView), COL_PIXBUF); 534 gtk_icon_view_set_item_width (GTK_ICON_VIEW (priv->gtkIconView), 100); 266 535 267 nomPrintf("%s: opening %s\n", __FUNCTION__, path);536 g_object_unref (gStore); 268 537 269 /* Create folder window */ 270 hwndFolder=fldr_createFolderWindow(somSelf, path); 271 272 if(!hwndFolder) 273 return NULLHANDLE; 274 275 /* populate the folder */ 276 _wpPopulate(somSelf, 0, path, FALSE); /* Contents or details. Tree isn't supported yet */ 277 278 break; 279 #endif 538 return nomFldrWindow; 280 539 }/* default */ 281 540 default: … … 308 567 } 309 568 569 static void 570 itemActivated (GtkIconView *widget, 571 GtkTreePath *treePath, 572 gpointer user_data) 573 { 574 PNOMFolderWindow pWindow; 575 576 pWindow=(NOMFolderWindow*)user_data; 577 578 if(NULL!=treePath) 579 { 580 GtkTreeIter iter; 581 GtkTreeModel* model; 582 WPObject *wpObject; 583 584 /* Click on an icon */ 585 model=gtk_icon_view_get_model(GTK_ICON_VIEW(widget)); 586 gtk_tree_model_get_iter(model , &iter, treePath); 587 588 gtk_tree_model_get(model, &iter, 589 0, &wpObject, 590 -1); 591 g_message("%s: %s", __FUNCTION__, wpObject->mtab->nomClassName); 592 WPObject_wpOpen(wpObject, pWindow, OPEN_CONTENTS, NULL, NULL); 593 } 594 } 595 310 596 /* 311 597 This method creates the folder window it doesn't query any files or creates … … 325 611 priv->gtkIconView=NOMFolderWindow_queryContainerHandle(nomFldrWindow, ev); 326 612 613 /* Connect to the "item_activated" signal */ 614 g_signal_connect (priv->gtkIconView, "item-activated", 615 G_CALLBACK (itemActivated), nomSelf); 616 617 gtk_window_set_title (GTK_WINDOW (NOMFolderWindow_queryWindowHandle(nomFldrWindow, NULLHANDLE)), 618 NOMString_queryCString(WPFolder_wpQueryTitle(nomSelf, NULLHANDLE), NULLHANDLE)); 327 619 /* Show the new window */ 328 620 NOMFolderWindow_show(nomFldrWindow, ev); … … 331 623 } 332 624 625 NOM_Scope gulong NOMLINK impl_WPFolder_wpQueryFldrFlags(WPFolder* nomSelf, CORBA_Environment *ev) 626 { 627 WPFolderData* nomThis=WPFolderGetData(nomSelf); 628 629 return g_atomic_int_get(&_ulFldrFlags); 630 } 631 632 NOM_Scope CORBA_boolean NOMLINK impl_WPFolder_wpSetFldrFlags(WPFolder* nomSelf, const gulong ulFlags, 633 const gulong ulMask, CORBA_Environment *ev) 634 { 635 WPFolderData* nomThis=WPFolderGetData(nomSelf); 636 637 WPFolder_wpRequestObjectMutexSem(nomSelf, 0,ev); 638 639 _ulFldrFlags=(_ulFldrFlags & ~ulMask)| ulFlags; 640 641 WPFolder_wpReleaseObjectMutexSem(nomSelf,ev); 642 643 return TRUE; 644 } 645 646 #if 0 647 static gint fldrCompareObjects(gconstpointer a, gconstpointer b, gpointer pUserData) 648 { 649 return strcmp(((PFLDRGTREEKEY)a)->chrKey, ((PFLDRGTREEKEY)b)->chrKey); 650 } 651 #endif 652 653 static void fldrCatchDuplicates(gpointer pOrgValue) 654 { 655 PFLDRGTREEVALUE pValue; 656 PFLDRGTREEVALUE pValueRemove; 657 658 pValue=(PFLDRGTREEVALUE)pOrgValue; 659 660 g_message("%d %s: value (object): %x %s", __LINE__, __FUNCTION__, (UINT)pValue->wpObject, pValue->chrKey); 661 662 #warning !!!!! Duplicate handling is still kind of broken !!!!! 663 /* 664 When we end here another object with the same key was inserted. This may be due to populating 665 all when we first just populated with folders. ATM we just remove the accidently inserted 666 second data and reinsert the original data (which may be already used by now). The wrong data 667 must be freed here later. 668 We should check the lock counter if we really dealing with wrong insertion here before freeing. 669 This way we might use this func also for freeing when normally removing objects. 670 */ 671 /* Remove the wrong data */ 672 pValueRemove=(PFLDRGTREEVALUE)g_tree_lookup(pValue->pGTree, pValue->chrKey); 673 g_tree_steal(pValue->pGTree, pValue->chrKey); /* This does not free the stuff in this func */ 674 /* Reinsert the old one */ 675 g_tree_insert(pValue->pGTree, pValue->chrKey, pValue); 676 } 677 333 678 NOM_Scope void NOMLINK impl_WPFolder_wpInitData(WPFolder* nomSelf, CORBA_Environment *ev) 334 679 { … … 340 685 nomPrintf(" Entering %s with nomSelf: 0x%x. nomSelf is: %s.\n", 341 686 __FUNCTION__, nomSelf , nomSelf->mtab->nomClassName); 342 _privFolderData=_wpAllocMem((WPObject*)nomSelf, sizeof(PRIVFOLDERDATA), (CORBA_unsigned_long*)&ulErr, NULLHANDLE); 343 } 344 345 346 687 _privFolderData=_wpAllocMem((WPObject*)nomSelf, sizeof(PRIVFOLDERDATA),&ulErr, NULLHANDLE); 688 689 /* This balanced binary tree holds the objects in this folder. We create a tree 690 which may be searched using the name of the file/directory */ 691 //_fldrObjects=g_tree_new((GCompareFunc)strcmp); 692 _fldrObjects=g_tree_new_full((GCompareFunc)strcmp, nomSelf, NULL, (GDestroyNotify) fldrCatchDuplicates); 693 } 694 695 696
Note:
See TracChangeset
for help on using the changeset viewer.