VirtualBox

Ignore:
Timestamp:
Jul 23, 2020 11:31:53 AM (4 years ago)
Author:
vboxsync
Message:

DnD: Added DnDTransferObjectInit() / DnDTransferObjectInitEx().

Location:
trunk/src/VBox/GuestHost/DragAndDrop
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/GuestHost/DragAndDrop/DnDTransferList.cpp

    r85428 r85429  
    192192                const bool fIsFile = RTFS_IS_FILE(fMode);
    193193
    194                 rc = DnDTransferObjectInit(pObj, fIsFile ? DNDTRANSFEROBJTYPE_FILE : DNDTRANSFEROBJTYPE_DIRECTORY,
    195                                            pList->pszPathRootAbs, &pcszSrcAbs[idxPathToAdd]);
     194                rc = DnDTransferObjectInitEx(pObj, fIsFile ? DNDTRANSFEROBJTYPE_FILE : DNDTRANSFEROBJTYPE_DIRECTORY,
     195                                             pList->pszPathRootAbs, &pcszSrcAbs[idxPathToAdd]);
    196196                if (RT_SUCCESS(rc))
    197197                {
  • trunk/src/VBox/GuestHost/DragAndDrop/DnDTransferObject.cpp

    r85372 r85429  
    4242
    4343/**
     44 * Initializes the object, internal version.
     45 *
     46 * @returns VBox status code.
     47 * @param   pObj                DnD transfer object to initialize.
     48 */
     49static int dndTransferObjectInitInternal(PDNDTRANSFEROBJECT pObj)
     50{
     51    AssertPtrReturn(pObj, VERR_INVALID_POINTER);
     52
     53    pObj->enmType = DNDTRANSFEROBJTYPE_UNKNOWN;
     54    pObj->idxDst  = 0;
     55    pObj->pszPath = NULL;
     56
     57    RT_ZERO(pObj->u);
     58
     59    return VINF_SUCCESS;
     60}
     61
     62/**
     63 * Initializes the object.
     64 *
     65 * @returns VBox status code.
     66 * @param   pObj                DnD transfer object to initialize.
     67 */
     68int DnDTransferObjectInit(PDNDTRANSFEROBJECT pObj)
     69{
     70    return dndTransferObjectInitInternal(pObj);
     71}
     72
     73/**
    4474 * Initializes the object with an expected object type and file path.
    4575 *
     
    5181 *                              Together with \a pcszPathSrcAbs this represents the complete absolute local path.
    5282 */
    53 int DnDTransferObjectInit(PDNDTRANSFEROBJECT pObj, DNDTRANSFEROBJTYPE enmType, const char *pcszPathSrcAbs, const char *pcszPathDst)
     83int DnDTransferObjectInitEx(PDNDTRANSFEROBJECT pObj,
     84                            DNDTRANSFEROBJTYPE enmType, const char *pcszPathSrcAbs, const char *pcszPathDst)
    5485{
    5586    AssertPtrReturn(pObj, VERR_INVALID_POINTER);
     
    5889    AssertPtrReturn(pcszPathDst, VERR_INVALID_POINTER);
    5990
    60     switch (enmType)
    61     {
    62         case DNDTRANSFEROBJTYPE_FILE:
    63         {
    64             pObj->u.File.hFile = NIL_RTFILE;
    65             break;
    66         }
    67 
    68         case DNDTRANSFEROBJTYPE_DIRECTORY:
    69         {
    70             pObj->u.Dir.hDir = NIL_RTDIR;
    71             break;
    72         }
    73 
    74         default:
    75             AssertFailedReturn(VERR_NOT_IMPLEMENTED);
    76             break; /* Never reached */
    77     }
    78 
    79     int rc = DnDPathValidate(pcszPathDst, false /* Does not need to exist */);
    80     if (RT_FAILURE(rc))
    81         return rc;
     91    int rc = dndTransferObjectInitInternal(pObj);
     92    AssertRCReturn(rc, rc);
     93
     94    rc = DnDPathValidate(pcszPathDst, false /* Does not need to exist */);
     95    AssertRCReturn(rc, rc);
    8296
    8397    char szPath[RTPATH_MAX + 1];
  • trunk/src/VBox/GuestHost/DragAndDrop/testcase/tstDnDTransferObject.cpp

    r85382 r85429  
    4848     * Paths handling.
    4949     */
    50     RTTEST_CHECK_RC_OK(hTest, DnDTransferObjectInit(&Obj, DNDTRANSFEROBJTYPE_FILE, "", "/rel/path/to/dst"));
    51     RTTEST_CHECK_RC   (hTest, DnDTransferObjectInit(&Obj, DNDTRANSFEROBJTYPE_FILE, "", "/rel/path/to/dst"), VERR_WRONG_ORDER);
     50    RTTEST_CHECK_RC_OK(hTest, DnDTransferObjectInitEx(&Obj, DNDTRANSFEROBJTYPE_FILE, "", "/rel/path/to/dst"));
     51    RTTEST_CHECK_RC   (hTest, DnDTransferObjectInitEx(&Obj, DNDTRANSFEROBJTYPE_FILE, "", "/rel/path/to/dst"), VERR_WRONG_ORDER);
    5252    DnDTransferObjectReset(&Obj);
    5353
    54     RTTEST_CHECK_RC_OK(hTest, DnDTransferObjectInit(&Obj, DNDTRANSFEROBJTYPE_FILE, "/src/path1", "dst/path2"));
     54    RTTEST_CHECK_RC_OK(hTest, DnDTransferObjectInitEx(&Obj, DNDTRANSFEROBJTYPE_FILE, "/src/path1", "dst/path2"));
    5555    RTTEST_CHECK(hTest, RTStrCmp(DnDTransferObjectGetSourcePath(&Obj), "/src/path1/dst/path2") == 0);
    5656    RTTEST_CHECK(hTest, RTStrCmp(DnDTransferObjectGetDestPath(&Obj), "dst/path2") == 0);
     
    5858                        && RTStrCmp(szBuf, "dst\\path2") == 0);
    5959    DnDTransferObjectReset(&Obj);
    60     RTTEST_CHECK_RC_OK(hTest, DnDTransferObjectInit(&Obj, DNDTRANSFEROBJTYPE_FILE, "", "dst/with/ending/slash/"));
     60    RTTEST_CHECK_RC_OK(hTest, DnDTransferObjectInitEx(&Obj, DNDTRANSFEROBJTYPE_FILE, "", "dst/with/ending/slash/"));
    6161    RTTEST_CHECK(hTest, RTStrCmp(DnDTransferObjectGetDestPath(&Obj), "dst/with/ending/slash/") == 0);
    6262    RTTEST_CHECK(hTest,    DnDTransferObjectGetDestPathEx(&Obj, DNDTRANSFEROBJPATHSTYLE_TRANSPORT, szBuf, sizeof(szBuf)) == VINF_SUCCESS
    6363                        && RTStrCmp(szBuf, "dst/with/ending/slash/") == 0);
    6464    DnDTransferObjectReset(&Obj);
    65     RTTEST_CHECK_RC_OK(hTest, DnDTransferObjectInit(&Obj, DNDTRANSFEROBJTYPE_DIRECTORY, "", "dst/path2"));
     65    RTTEST_CHECK_RC_OK(hTest, DnDTransferObjectInitEx(&Obj, DNDTRANSFEROBJTYPE_DIRECTORY, "", "dst/path2"));
    6666    RTTEST_CHECK(hTest, RTStrCmp(DnDTransferObjectGetSourcePath(&Obj), "dst/path2/") == 0);
    6767    RTTEST_CHECK(hTest, RTStrCmp(DnDTransferObjectGetDestPath(&Obj), "dst/path2/") == 0);
    6868    DnDTransferObjectReset(&Obj);
    69     RTTEST_CHECK_RC_OK(hTest, DnDTransferObjectInit(&Obj, DNDTRANSFEROBJTYPE_DIRECTORY, "", "dst\\to\\path2"));
     69    RTTEST_CHECK_RC_OK(hTest, DnDTransferObjectInitEx(&Obj, DNDTRANSFEROBJTYPE_DIRECTORY, "", "dst\\to\\path2"));
    7070    RTTEST_CHECK(hTest, RTStrCmp(DnDTransferObjectGetSourcePath(&Obj), "dst/to/path2/") == 0);
    7171    RTTEST_CHECK(hTest, RTStrCmp(DnDTransferObjectGetDestPath(&Obj), "dst/to/path2/") == 0);
    7272    DnDTransferObjectReset(&Obj);
    7373    /* Test that the destination does not have a beginning slash. */
    74     RTTEST_CHECK_RC_OK(hTest, DnDTransferObjectInit(&Obj, DNDTRANSFEROBJTYPE_DIRECTORY, "/src/path2", "/dst/to/path2/"));
     74    RTTEST_CHECK_RC_OK(hTest, DnDTransferObjectInitEx(&Obj, DNDTRANSFEROBJTYPE_DIRECTORY, "/src/path2", "/dst/to/path2/"));
    7575    RTTEST_CHECK(hTest, RTStrCmp(DnDTransferObjectGetSourcePath(&Obj), "/src/path2/dst/to/path2/") == 0);
    7676    RTTEST_CHECK(hTest, RTStrCmp(DnDTransferObjectGetDestPath(&Obj), "dst/to/path2/") == 0);
    7777    DnDTransferObjectReset(&Obj);
    78     RTTEST_CHECK_RC_OK(hTest, DnDTransferObjectInit(&Obj, DNDTRANSFEROBJTYPE_DIRECTORY, "/src/path2", "//////dst/to/path2/"));
     78    RTTEST_CHECK_RC_OK(hTest, DnDTransferObjectInitEx(&Obj, DNDTRANSFEROBJTYPE_DIRECTORY, "/src/path2", "//////dst/to/path2/"));
    7979    RTTEST_CHECK(hTest, RTStrCmp(DnDTransferObjectGetDestPath(&Obj), "dst/to/path2/") == 0);
    8080
     
    8383     */
    8484    DnDTransferObjectReset(&Obj);
    85     RTTEST_CHECK(hTest, DnDTransferObjectInit(&Obj, DNDTRANSFEROBJTYPE_DIRECTORY, "/src/path3", "../../dst/path3") == VERR_INVALID_PARAMETER);
    86     RTTEST_CHECK(hTest, DnDTransferObjectInit(&Obj, DNDTRANSFEROBJTYPE_DIRECTORY, "/src/../../path3", "dst/path3") == VERR_INVALID_PARAMETER);
     85    RTTEST_CHECK(hTest, DnDTransferObjectInitEx(&Obj, DNDTRANSFEROBJTYPE_DIRECTORY, "/src/path3", "../../dst/path3") == VERR_INVALID_PARAMETER);
     86    RTTEST_CHECK(hTest, DnDTransferObjectInitEx(&Obj, DNDTRANSFEROBJTYPE_DIRECTORY, "/src/../../path3", "dst/path3") == VERR_INVALID_PARAMETER);
    8787
    8888    /*
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette