1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "sal/log.hxx"
21 #include "CFStringUtilities.hxx"
23 rtl::OUString CFStringToOUString(const CFStringRef sOrig) {
24 //DBG_PRINT_ENTRY("CFStringUtilities", __func__, "sOrig", sOrig);
27 return rtl::OUString();
31 CFIndex nFileNameLength = CFStringGetLength(sOrig);
32 //SAL_INFO("fpicker.aqua","FH: string length: " << (int)(nFileNameLength));
33 UniChar unichars[nFileNameLength+1];
34 //'close' the string buffer correctly
35 unichars[nFileNameLength] = '\0';
37 CFStringGetCharacters (sOrig, CFRangeMake(0,nFileNameLength), unichars);
39 //we no longer need the original string
42 //DBG_PRINT_EXIT("CFStringUtilities", __func__, unichars);
44 return rtl::OUString(unichars);
47 CFStringRef CFStringCreateWithOUString(const rtl::OUString& aString) {
48 //DBG_PRINT_ENTRY("CFStringUtilities", __func__);
50 CFStringRef ref = CFStringCreateWithCharacters(kCFAllocatorDefault, aString.getStr(), aString.getLength());
52 //DBG_PRINT_EXIT("CFStringUtilities", __func__, ref);
57 rtl::OUString FSRefToOUString(FSRef const & fsRef, InfoType info)
59 //DBG_PRINT_ENTRY("CFStringUtilities", __func__);
61 SAL_WNODEPRECATED_DECLARATIONS_PUSH //TODO: 10.9 CFURLCreateFromFSRef
62 CFURLRef aUrlRef = CFURLCreateFromFSRef(NULL, &fsRef);
63 SAL_WNODEPRECATED_DECLARATIONS_POP
65 rtl::OUString sResult = CFURLRefToOUString(aUrlRef, info);
67 //we no longer need the CFURLRef
70 //DBG_PRINT_EXIT("CFStringUtilities", __func__, OUStringToOString(sResult, RTL_TEXTENCODING_UTF8).getStr());
75 rtl::OUString CFURLRefToOUString(CFURLRef aUrlRef, InfoType info)
77 //DBG_PRINT_ENTRY("CFStringUtilities", __func__);
79 CFStringRef sURLString = NULL;
83 SAL_INFO("fpicker.aqua","Extracting the full path of an item");
84 sURLString = CFURLGetString(aUrlRef);
89 SAL_INFO("fpicker.aqua","Extracting the file name of an item");
90 CFStringRef fullString = CFURLGetString(aUrlRef);
91 CFURLRef dirRef = CFURLCreateCopyDeletingLastPathComponent(NULL,aUrlRef);
92 CFIndex dirLength = CFStringGetLength(CFURLGetString(dirRef));
94 CFIndex fullLength = CFStringGetLength(fullString);
95 CFRange substringRange = CFRangeMake(dirLength, fullLength - dirLength);
96 sURLString = CFStringCreateWithSubstring(NULL, fullString, substringRange);
99 case PATHWITHOUTLASTCOMPONENT:
101 SAL_INFO("fpicker.aqua","Extracting the last but one component of an item's path");
102 CFURLRef directoryRef = CFURLCreateCopyDeletingLastPathComponent(NULL,aUrlRef);
103 sURLString = CFURLGetString(directoryRef);
104 CFRetain(sURLString);
105 CFRelease(directoryRef);
112 rtl::OUString sResult = CFStringToOUString(sURLString);
114 CFRelease(sURLString);
116 //DBG_PRINT_EXIT("CFStringUtilities", __func__, OUStringToOString(sResult, RTL_TEXTENCODING_UTF8).getStr());
121 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */