Ignore:
Timestamp:
Mar 10, 2007, 12:11:43 PM (18 years ago)
Author:
cinc
Message:

Implemented methods to add/remove objects to/from folders (and folder windows).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/desktop/class_c/wpfolder.c

    r241 r244  
    7777#include "nomdraginfo.h"
    7878
     79/*
     80  This struct is associated with the key in the contents tree of the
     81  folder.
     82 */
    7983typedef struct _FLDRGTREEVALUE
    8084{
    8185  PGTree pGTree;
    8286  WPObject* wpObject;
    83   gchar* chrKey;
     87  gchar* chrKey; /* <-- is this really needed? */
    8488}FLDRGTREEVALUE, *PFLDRGTREEVALUE;
    8589
     
    9599};
    96100
     101/*************** Local vars ************************************/
     102
     103/* This ID is used as a namespace */
     104static 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*/
    97113static GtkListStore * fldr_CreateStore (void)
    98114{
     
    104120                              G_TYPE_STRING,
    105121                              GDK_TYPE_PIXBUF);
    106   // g_message("%s: store: %x", __FUNCTION__, (UINT) store);
    107122  return store;
    108123}
    109124
    110 /*************** Local vars ************************************/
    111 
    112 /* This ID is used as a namespace */
    113 static nomId WPFolderNomId;
    114 
    115 /***************************************************************/
     125
    116126/*
    117127  The folder is already populated, that means the internal folder list
     
    122132gboolean fillStoreTraverseFunc(gpointer pKey, gpointer pTraverseValue, gpointer pData)
    123133{
    124   GtkTreeIter iter;
     134  WPFolder* wpFolder=(PWPFolder)pData;
    125135  PFLDRGTREEVALUE pValue=pTraverseValue;
    126   gchar * display_name;
    127   GtkListStore *store=(GtkListStore *)pData;
    128   WPObject* wpObject;
    129    
    130   //  g_message("In %s with %s %x", __FUNCTION__, (char*)pKey, (UINT)pValue->wpObject);
    131 
    132 #warning !!!!! Use Title here !!!!!
    133   display_name=g_strdup(pKey); /* New string necessary? */ 
    134 
    135   wpObject=pValue->wpObject;
    136  
    137   if(nomIsObj(wpObject)){
    138 #if 0
    139     g_message("%d %s : %s, %s",
    140               __LINE__, __FUNCTION__, (char*)pKey,
    141               NOMPath_queryCString(WPFolder_wpQueryFileName(wpFolder, TRUE, NULLHANDLE), NULLHANDLE));
    142 #endif
    143    
    144     gtk_list_store_append (store, &iter);
    145    
    146     gtk_list_store_set (store, &iter,
    147                         COL_OBJECT_PTR, wpObject,
    148                         COL_PATH, "",
    149                         COL_DISPLAY_NAME, display_name,
    150                         COL_PIXBUF, _wpQueryIcon(wpObject, NULLHANDLE),
    151                         -1);
    152   }
    153   return FALSE; /* Traverse every item */
    154 }
     136
     137  WPFolder_wpAddToStore(wpFolder, pValue->wpObject,
     138                        NULLHANDLE);
     139  return FALSE;
     140}
     141
    155142
    156143static gboolean
    157 fldr_fillStore (WPFolder* nomSelf, GtkListStore *store, const gchar* gchrPath)
     144fldr_fillStore (WPFolder* nomSelf, GtkListStore *store)
    158145{
    159146  WPFolderData* nomThis=WPFolderGetData(nomSelf);
    160147
    161148  /* First clear the store */
    162   gtk_list_store_clear (store);
    163 
    164   g_tree_foreach(_fldrObjects, (GTraverseFunc) fillStoreTraverseFunc, 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);
    165154
    166155  return TRUE;
     
    168157
    169158
     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 */
    170169NOM_Scope gulong NOMLINK impl_WPFolder_wpAddToContent(WPFolder* nomSelf, const PWPObject wpObject,
    171170                                                      const CORBA_char * chrFileName, CORBA_Environment *ev)
     
    177176  pValue->pGTree=_fldrObjects;
    178177  pValue->wpObject=wpObject;
    179   pValue->chrKey=g_strdup(chrFileName);
     178  pValue->chrKey=NOMPath_copyCString( WPFileSystem_wpQueryFileName(wpObject, FALSE, NULLHANDLE)
     179                                      , NULLHANDLE);
    180180
    181181  g_tree_insert(_fldrObjects, pValue->chrKey, pValue);
    182182
    183 #if 0
    184   PFLDRGTREEKEY pKey;
    185   pKey=(PFLDRGTREEKEY)NOMMalloc(sizeof(FLDRGTREEKEY));
    186   pKey->pGTree=_fldrObjects;
    187   pKey->chrKey=chrFileName;
    188   g_tree_insert(_fldrObjects, pKey, wpObject);
    189 #endif
    190 
    191183  return 0;
    192184}
    193185
     186
     187static gboolean fldrPrintListFunc(gpointer key, gpointer pValue, gpointer data)
     188{
     189
     190  g_message("%s: key %x (%s), value %x, data %d", __FUNCTION__, key, key, pValue, data);
     191  return FALSE;
     192}
     193
     194static void fldrPrintContentsList(GTree* fldrObjects)
     195{
     196  g_tree_foreach(fldrObjects, (GTraverseFunc) fldrPrintListFunc, (gpointer)123);
     197}
     198
     199
    194200NOM_Scope PWPObject NOMLINK impl_WPFolder_wpQueryContent(WPFolder* nomSelf, CORBA_Environment *ev)
    195201{
    196 /* WPFolderData* nomThis=WPFolderGetData(nomSelf); */
     202  WPFolderData* nomThis=WPFolderGetData(nomSelf);
     203
     204  fldrPrintContentsList(_fldrObjects);
    197205
    198206  return NULLHANDLE;
     207}
     208
     209NOM_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(wpObject, FALSE, NULLHANDLE),
     221                                                  NULLHANDLE));
     222
     223
     224  return TRUE;
     225}
     226
     227
     228NOM_Scope PUSEITEM NOMLINK impl_WPFolder_wpAddToStore(WPFolder* nomSelf, const PWPObject wpObject,
     229                                                              CORBA_Environment *ev)
     230{
     231  WPFolderData* nomThis=WPFolderGetData(nomSelf);
     232  PUSEITEM pui;
     233  ULONG ulError;
     234  GtkTreeIter iter;
     235  gchar * display_name;
     236
     237  if(!nomIsObj(wpObject))
     238    return NULLHANDLE;
     239
     240  if(!_pListStore)
     241    return NULLHANDLE;
     242
     243#warning !!!!! Use Title here? !!!!!
     244  display_name=NOMPath_copyCString(WPFileSystem_wpQueryFileName(wpObject, FALSE, NULLHANDLE),
     245                                   NULLHANDLE);/* Do we need a copy here? */
     246
     247  gtk_list_store_append (_pListStore, &iter);
     248  gtk_list_store_set (_pListStore, &iter,
     249                      COL_OBJECT_PTR, wpObject,
     250                      COL_PATH, "",
     251                      COL_DISPLAY_NAME, display_name,
     252                      COL_PIXBUF, _wpQueryIcon(wpObject, NULLHANDLE),
     253                      -1);
     254
     255  /* Insert a STOREITEM into the objects inuse inuse list to track in which stores
     256     the object lives. This item is later used when an object must be removed from
     257     a folder window. */
     258  pui=(PUSEITEM)_wpAllocMem(wpObject, sizeof(USEITEM)+sizeof(STOREITEM), &ulError, NULLHANDLE);
     259  /* Fill the structures */
     260  pui->type=(gulong)USAGE_STORE;
     261  pui->wpObject=(PWPObject)wpObject;
     262  pui++;
     263  ((STOREITEM*)pui)->treeIter=iter;
     264  ((STOREITEM*)pui)->pListStore=_pListStore;
     265  pui--;
     266  /* Object list not the one of the folder */
     267  WPObject_wpAddToObjUseList(wpObject, pui, NULLHANDLE);
     268
     269  return pui;
     270}
     271
     272
     273NOM_Scope PUSEITEM NOMLINK impl_WPFolder_wpDeleteFromStore(WPFolder* nomSelf, const PWPObject wpObject,
     274                                                           CORBA_Environment *ev)
     275{
     276  WPFolderData* nomThis=WPFolderGetData(nomSelf);
     277  PUSEITEM pui;
     278
     279  /* Remove the object from the folder window. That means from the store. */
     280  if(_pListStore)
     281    {
     282      /* Each object which is added to a store */
     283      pui=_wpFindUseItem(wpObject, USAGE_STORE,
     284                         NULLHANDLE, NULLHANDLE);
     285      while(pui){
     286        GtkTreeIter iter;
     287        pui++;
     288        iter=((STOREITEM*)pui)->treeIter;
     289        if(((STOREITEM*)pui)->pListStore==_pListStore)
     290          {
     291            pui--;
     292            gtk_list_store_remove( _pListStore, &iter);
     293            _wpDeleteFromObjUseList(wpObject, pui, NULLHANDLE);
     294            //_wpFreeMem(wpObject, pui, NULLHANDLE);
     295            break;
     296          }
     297        pui--;
     298        pui=_wpFindUseItem(wpObject, USAGE_STORE,
     299                           pui, NULLHANDLE);
     300      }
     301    }
     302  return pui;
    199303}
    200304
     
    210314  const gchar* gchrPath;
    211315  PNOMPath fldrPath;
    212 
    213   //  g_log("WPFolder", G_LOG_LEVEL_DEBUG, "%s: Populating %s (0x%x)\n", __FUNCTION__, pszPath, (UINT)nomSelf);
    214316
    215317  /* Already populated? */
     
    236338          WPObject* wpObject;
    237339
     340          /* Filenames are in a special encoding with GLib */
    238341          path = g_build_filename (gchrPath, gchrCurrentEntry, NULL);
    239342
     343          /* The name to show to the user */
    240344          display_name = g_filename_to_utf8 (gchrCurrentEntry, -1, NULL, NULL, NULL);
    241345
     
    251355          if(nomIsObj((PNOMObject)wpObject))
    252356            {
     357              /* First ref living as long as the folder is awake */
    253358              WPObject_wpLockObject(wpObject, NULLHANDLE);
    254359              WPObject_wpSetTitleFromCString(wpObject, display_name, NULLHANDLE);
     
    281386/*
    282387  This will change when NOMFolderWindow is migrated to WPFolderWindow.
     388 
     389  This delete handler is called when the folder window is closed. It removes
     390  the view item from the folders inuse list.
    283391 */
    284392static
     
    301409  /* Remove the open folder view from the inuse list */
    302410  WPObject_wpDeleteFromObjUseList(wpObject, pUseItem, NULLHANDLE);
     411
     412  _wpFreeMem(wpObject, pUseItem, NULLHANDLE);
    303413
    304414  return FALSE; /* Let other handlers run */
     
    331441            WPFolderWindow * wpFldrWindow;
    332442            gchar* pszPath;
    333             PPRIVFOLDERDATA priv;
    334             GtkListStore* gStore;
     443            //    PPRIVFOLDERDATA priv;
     444            //    GtkListStore* gStore;
    335445            GtkIconView*  gtkIconView;
    336446
    337447            pszPath=NOMPath_queryCString(_wpQueryFileName(nomSelf, TRUE, NULLHANDLE), NULLHANDLE);
    338448            g_message("%d %s, %s", __LINE__, __FUNCTION__, pszPath);
     449            /* Create the internal list of objects and make all these objects awake */
    339450            WPFolder_wpPopulate(nomSelf, 0L, pszPath, FALSE,  NULLHANDLE);
    340451           
    341            
     452            /* The folder window holding the objects */
    342453            wpFldrWindow=WPFolder_wpCreateFolderWindow(nomSelf, NULLHANDLE);
    343454           
    344             /* Insert it into inuse list */
     455            /* Insert it into inuse list... */
    345456            pui=(PUSEITEM)WPFolder_wpAllocMem(nomSelf, sizeof(USEITEM)+sizeof(VIEWITEM), &ulError, NULLHANDLE);
    346457            /* Fill the structures */
     
    352463            ((VIEWITEM*)pui)->nameSpaceId=WPFolderNomId;
    353464            pui--;
    354 
    355465            /* Make sure the view item is removed when the window is closed */
    356             g_signal_connect(G_OBJECT(NOMWindow_queryWindowHandle((NOMWindow*)wpFldrWindow, NULLHANDLE)),"delete-event",
     466            g_signal_connect(G_OBJECT(NOMWindow_queryWindowHandle((NOMWindow*)wpFldrWindow, NULLHANDLE)),
     467                             "delete-event",
    357468                             G_CALLBACK(tempWPWindowDeleteHandler), (gpointer) pui);
    358469            WPFolder_wpAddToObjUseList(nomSelf, pui, NULLHANDLE);
    359            
     470
     471#if 0           
    360472            /* Now create a folder store and insert icons into the window */
    361473            priv=_privFolderData;
    362             gStore=priv->gstoreFldContents;
    363            
     474            gStore=priv->gstoreFldContents;           
    364475            if(!gStore)
    365476              {
     
    375486                  return FALSE;
    376487              }
    377 
    378488            gtkIconView=WPFolderWindow_wpQueryContainerHandle(wpFldrWindow, NULLHANDLE);
    379 
    380489            gtk_icon_view_set_model(GTK_ICON_VIEW (gtkIconView),
    381490                                    GTK_TREE_MODEL (priv->gstoreFldContents));
     491#endif
     492            if(!_pListStore)
     493              {
     494               
     495                if(( _pListStore=fldr_CreateStore())==NULLHANDLE){
     496                  g_warning("%s: Can't create store.", __FUNCTION__);
     497                  return FALSE;
     498                }
     499                /* Fill our store */
     500                fldr_fillStore(nomSelf, _pListStore);
     501              }
     502
     503            gtkIconView=WPFolderWindow_wpQueryContainerHandle(wpFldrWindow, NULLHANDLE);
     504           
     505            gtk_icon_view_set_model(GTK_ICON_VIEW (gtkIconView),
     506                                    GTK_TREE_MODEL (_pListStore));           
    382507
    383508            /* We now set which model columns that correspond to the text
     
    641766  /* This balanced binary tree holds the objects in this folder. We create a tree
    642767     which may be searched using the name of the file/directory */
    643   //_fldrObjects=g_tree_new((GCompareFunc)strcmp);
    644   _fldrObjects=g_tree_new_full((GCompareFunc)strcmp, nomSelf, NULL,
     768  _fldrObjects=g_tree_new_full((GCompareDataFunc)strcmp, nomSelf, NULL,
    645769                               (GDestroyNotify) fldrCatchDuplicates);
    646770}
     
    668792    return 0;
    669793
     794  /* That's the action the user selected by pressing a key during drop */
    670795  gda=NOMDragInfo_queryChosenDropAction(nomDragInfo, NULLHANDLE);
    671796
     
    693818            break;
    694819          }
     820          /* Copy shouldn't be default I guess... */
    695821        default:
    696822          {
Note: See TracChangeset for help on using the changeset viewer.