tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / svl / source / misc / filenotation.cxx
blobf1ef595570ea0349decb73f5a80150fcf77073c0
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 <svl/filenotation.hxx>
21 #include <osl/file.h>
22 #include <osl/diagnose.h>
23 #include <tools/urlobj.hxx>
25 namespace svt
28 OFileNotation::OFileNotation( const OUString& _rUrlOrPath )
30 construct( _rUrlOrPath );
33 OFileNotation::OFileNotation( const OUString& _rUrlOrPath, NOTATION _eInputNotation )
35 if ( _eInputNotation == N_URL )
37 INetURLObject aParser( _rUrlOrPath );
38 if ( aParser.GetProtocol() == INetProtocol::File )
39 implInitWithURLNotation( _rUrlOrPath );
40 else
41 m_sSystem = m_sFileURL = _rUrlOrPath;
43 else
44 implInitWithSystemNotation( _rUrlOrPath );
47 bool OFileNotation::implInitWithSystemNotation( const OUString& _rSystemPath )
49 bool bSuccess = false;
51 m_sSystem = _rSystemPath;
52 if ( ( osl_File_E_None != osl_getFileURLFromSystemPath( m_sSystem.pData, &m_sFileURL.pData ) )
53 && ( m_sFileURL.isEmpty() )
56 if ( !_rSystemPath.isEmpty() )
58 INetURLObject aSmartParser;
59 aSmartParser.SetSmartProtocol( INetProtocol::File );
60 if ( aSmartParser.SetSmartURL( _rSystemPath ) )
62 m_sFileURL = aSmartParser.GetMainURL( INetURLObject::DecodeMechanism::NONE );
63 osl_getSystemPathFromFileURL( m_sFileURL.pData, &m_sSystem.pData );
64 bSuccess = true;
68 else
69 bSuccess = true;
70 return bSuccess;
73 void OFileNotation::implInitWithURLNotation( const OUString& _rURL )
75 m_sFileURL = _rURL;
76 osl_getSystemPathFromFileURL( _rURL.pData, &m_sSystem.pData );
79 void OFileNotation::construct( const OUString& _rUrlOrPath )
81 bool bSuccess = false;
82 // URL notation?
83 INetURLObject aParser( _rUrlOrPath );
84 switch ( aParser.GetProtocol() )
86 case INetProtocol::File:
87 // file URL
88 implInitWithURLNotation( _rUrlOrPath );
89 bSuccess = true;
90 break;
92 case INetProtocol::NotValid:
93 // assume system notation
94 bSuccess = implInitWithSystemNotation( _rUrlOrPath );
95 break;
97 default:
98 // it's a known scheme, but no file-URL -> assume that both the URL representation and the
99 // system representation are the URL itself
100 m_sSystem = m_sFileURL = _rUrlOrPath;
101 bSuccess = true;
102 break;
105 OSL_ENSURE( bSuccess, "OFileNotation::OFileNotation: could not detect the format!" );
108 const OUString & OFileNotation::get(NOTATION _eOutputNotation) const
110 switch (_eOutputNotation)
112 case N_SYSTEM: return m_sSystem;
113 case N_URL: return m_sFileURL;
116 OSL_FAIL("OFileNotation::get: invalid enum value!");
117 return EMPTY_OUSTRING;
120 } // namespace svt
122 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */