31#include <com/sun/star/beans/IllegalTypeException.hpp>
32#include <com/sun/star/beans/PropertyValue.hpp>
33#include <com/sun/star/beans/PropertyAttribute.hpp>
34#include <com/sun/star/beans/XPropertySetInfo.hpp>
35#include <com/sun/star/io/IOException.hpp>
36#include <com/sun/star/io/XActiveDataSink.hpp>
37#include <com/sun/star/io/XOutputStream.hpp>
38#include <com/sun/star/lang/IllegalAccessException.hpp>
39#include <com/sun/star/lang/IllegalArgumentException.hpp>
40#include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
41#include <com/sun/star/ucb/ContentInfoAttribute.hpp>
42#include <com/sun/star/ucb/InsertCommandArgument.hpp>
43#include <com/sun/star/ucb/InteractiveAugmentedIOException.hpp>
44#include <com/sun/star/ucb/InteractiveNetworkGeneralException.hpp>
45#include <com/sun/star/ucb/InteractiveNetworkResolveNameException.hpp>
46#include <com/sun/star/ucb/NameClashException.hpp>
47#include <com/sun/star/ucb/OpenMode.hpp>
48#include <com/sun/star/ucb/XCommandInfo.hpp>
49#include <com/sun/star/ucb/MissingInputStreamException.hpp>
50#include <com/sun/star/ucb/UnsupportedCommandException.hpp>
51#include <com/sun/star/ucb/UnsupportedDataSinkException.hpp>
52#include <com/sun/star/ucb/UnsupportedOpenModeException.hpp>
53#include <com/sun/star/ucb/XDynamicResultSet.hpp>
54#include <com/sun/star/ucb/XContentCreator.hpp>
76 const css::uno::Reference< css::uno::XComponentContext >& rxContext,
78 const css::uno::Reference< css::ucb::XContentIdentifier >& Identifier)
79 : ContentImplHelper( rxContext, pProvider,
Identifier ),
80 m_pProvider( pProvider ), mpFile (nullptr), mpInfo( nullptr ), mbTransient(false)
86 const css::uno::Reference< css::uno::XComponentContext >& rxContext,
88 const css::uno::Reference< css::ucb::XContentIdentifier >& Identifier,
90 : ContentImplHelper( rxContext, pProvider,
Identifier ),
91 m_pProvider( pProvider ), mpFile (nullptr), mpInfo( nullptr ), mbTransient(true)
94 mpInfo = g_file_info_new();
95 g_file_info_set_file_type(
mpInfo, bIsFolder ? G_FILE_TYPE_DIRECTORY : G_FILE_TYPE_REGULAR);
107 if (GFile* pFile = g_file_get_parent(
getGFile()))
109 char* pPath = g_file_get_uri(pFile);
110 g_object_unref(pFile);
111 sURL = OUString::createFromAscii(pPath);
126 return isFolder(css::uno::Reference< css::ucb::XCommandEnvironment >())
131#define EXCEPT(aExcept) \
133 if (bThrow) throw aExcept;\
137css::uno::Any
convertToException(GError *pError,
const css::uno::Reference< css::uno::XInterface >& rContext,
bool bThrow)
141 gint eCode = pError->code;
142 OUString
sMessage(pError->message, strlen(pError->message), RTL_TEXTENCODING_UTF8);
143 g_error_free(pError);
147 css::uno::Sequence< css::uno::Any > aArgs{ css::uno::Any(
sName) };
151 case G_IO_ERROR_FAILED:
152 { css::io::IOException aExcept(
sMessage, rContext);
155 case G_IO_ERROR_NOT_MOUNTED:
156 { css::ucb::InteractiveAugmentedIOException aExcept(
sMessage, rContext,
157 css::task::InteractionClassification_ERROR, css::ucb::IOErrorCode_NOT_EXISTING_PATH, aArgs);
160 case G_IO_ERROR_NOT_FOUND:
161 { css::ucb::InteractiveAugmentedIOException aExcept(
sMessage, rContext,
162 css::task::InteractionClassification_ERROR, css::ucb::IOErrorCode_NOT_EXISTING, aArgs);
165 case G_IO_ERROR_EXISTS:
166 { css::ucb::NameClashException aExcept(
sMessage, rContext,
167 css::task::InteractionClassification_ERROR,
sName);
170 case G_IO_ERROR_INVALID_ARGUMENT:
171 { css::lang::IllegalArgumentException aExcept(
sMessage, rContext, -1 );
174 case G_IO_ERROR_PERMISSION_DENIED:
175 { css::ucb::InteractiveAugmentedIOException aExcept(
sMessage, rContext,
176 css::task::InteractionClassification_ERROR, css::ucb::IOErrorCode_ACCESS_DENIED, aArgs);
179 case G_IO_ERROR_IS_DIRECTORY:
180 { css::ucb::InteractiveAugmentedIOException aExcept(
sMessage, rContext,
181 css::task::InteractionClassification_ERROR, css::ucb::IOErrorCode_NO_FILE, aArgs);
184 case G_IO_ERROR_NOT_REGULAR_FILE:
185 { css::ucb::InteractiveAugmentedIOException aExcept(
sMessage, rContext,
186 css::task::InteractionClassification_ERROR, css::ucb::IOErrorCode_NO_FILE, aArgs);
189 case G_IO_ERROR_NOT_DIRECTORY:
190 { css::ucb::InteractiveAugmentedIOException aExcept(
sMessage, rContext,
191 css::task::InteractionClassification_ERROR, css::ucb::IOErrorCode_NO_DIRECTORY, aArgs);
194 case G_IO_ERROR_FILENAME_TOO_LONG:
195 { css::ucb::InteractiveAugmentedIOException aExcept(
sMessage, rContext,
196 css::task::InteractionClassification_ERROR, css::ucb::IOErrorCode_NAME_TOO_LONG, aArgs);
199 case G_IO_ERROR_FAILED_HANDLED:
202 case G_IO_ERROR_PENDING:
203 { css::ucb::InteractiveAugmentedIOException aExcept(
sMessage, rContext,
204 css::task::InteractionClassification_ERROR, css::ucb::IOErrorCode_PENDING, aArgs);
207 case G_IO_ERROR_CLOSED:
208 case G_IO_ERROR_CANCELLED:
209 case G_IO_ERROR_TOO_MANY_LINKS:
210 case G_IO_ERROR_WRONG_ETAG:
211 { css::ucb::InteractiveAugmentedIOException aExcept(
sMessage, rContext,
212 css::task::InteractionClassification_ERROR, css::ucb::IOErrorCode_GENERAL, aArgs);
215 case G_IO_ERROR_NOT_SUPPORTED:
216 case G_IO_ERROR_CANT_CREATE_BACKUP:
217 case G_IO_ERROR_WOULD_MERGE:
218 { css::ucb::InteractiveAugmentedIOException aExcept(
sMessage, rContext,
219 css::task::InteractionClassification_ERROR, css::ucb::IOErrorCode_NOT_SUPPORTED, aArgs);
222 case G_IO_ERROR_NO_SPACE:
223 { css::ucb::InteractiveAugmentedIOException aExcept(
sMessage, rContext,
224 css::task::InteractionClassification_ERROR, css::ucb::IOErrorCode_OUT_OF_DISK_SPACE, aArgs);
227 case G_IO_ERROR_INVALID_FILENAME:
228 { css::ucb::InteractiveAugmentedIOException aExcept(
sMessage, rContext,
229 css::task::InteractionClassification_ERROR, css::ucb::IOErrorCode_INVALID_CHARACTER, aArgs);
232 case G_IO_ERROR_READ_ONLY:
233 { css::ucb::InteractiveAugmentedIOException aExcept(
sMessage, rContext,
234 css::task::InteractionClassification_ERROR, css::ucb::IOErrorCode_WRITE_PROTECTED, aArgs);
237 case G_IO_ERROR_TIMED_OUT:
238 { css::ucb::InteractiveAugmentedIOException aExcept(
sMessage, rContext,
239 css::task::InteractionClassification_ERROR, css::ucb::IOErrorCode_DEVICE_NOT_READY, aArgs);
242 case G_IO_ERROR_WOULD_RECURSE:
243 { css::ucb::InteractiveAugmentedIOException aExcept(
sMessage, rContext,
244 css::task::InteractionClassification_ERROR, css::ucb::IOErrorCode_RECURSIVE, aArgs);
247 case G_IO_ERROR_BUSY:
248 case G_IO_ERROR_WOULD_BLOCK:
249 { css::ucb::InteractiveAugmentedIOException aExcept(
sMessage, rContext,
250 css::task::InteractionClassification_ERROR, css::ucb::IOErrorCode_LOCKING_VIOLATION, aArgs);
253 case G_IO_ERROR_HOST_NOT_FOUND:
254 { css::ucb::InteractiveNetworkResolveNameException aExcept(
sMessage, rContext,
255 css::task::InteractionClassification_ERROR, OUString());
259 case G_IO_ERROR_ALREADY_MOUNTED:
260 case G_IO_ERROR_NOT_EMPTY:
261 case G_IO_ERROR_NOT_SYMBOLIC_LINK:
262 case G_IO_ERROR_NOT_MOUNTABLE_FILE:
263 { css::ucb::InteractiveNetworkGeneralException aExcept(
sMessage, rContext,
264 css::task::InteractionClassification_ERROR);
277 catch (
const css::io::IOException&)
281 catch (
const css::uno::RuntimeException&)
285 catch (
const css::uno::Exception& e)
288 throw css::lang::WrappedTargetRuntimeException(
289 "wrapped Exception " + e.Message,
290 css::uno::Reference<css::uno::XInterface>(),
a);
304 return css::uno::Any( css::lang::IllegalArgumentException(
305 "Wrong argument type!",
315 GMountOperation *mpAuthentication;
317 static void Completed(GObject *source, GAsyncResult *res, gpointer user_data);
319 explicit MountOperation(
const css::uno::Reference< css::ucb::XCommandEnvironment >& xEnv);
321 GError *Mount(GFile *pFile);
326MountOperation::MountOperation(
const css::uno::Reference< css::ucb::XCommandEnvironment >& xEnv) : mpError(nullptr)
329 mContext.reset(g_main_context_new());
330 mpLoop = g_main_loop_new(mContext.get(), FALSE);
331 g_main_context_push_thread_default(mContext.get());
335void MountOperation::Completed(GObject *source, GAsyncResult *res, gpointer user_data)
337 MountOperation *pThis =
static_cast<MountOperation*
>(user_data);
338 g_file_mount_enclosing_volume_finish(G_FILE(source), res, &(pThis->mpError));
339 g_main_loop_quit(pThis->mpLoop);
342GError *MountOperation::Mount(GFile *pFile)
344 g_file_mount_enclosing_volume(pFile, G_MOUNT_MOUNT_NONE, mpAuthentication,
nullptr, MountOperation::Completed,
this);
354 g_main_loop_run(mpLoop);
358 g_main_loop_run(mpLoop);
364MountOperation::~MountOperation()
366 g_object_unref(mpAuthentication);
367 g_main_context_pop_thread_default(mContext.get());
368 g_main_loop_unref(mpLoop);
373 GError *
err =
nullptr;
375 for (
bool retried =
false;; retried =
true) {
376 mpInfo = g_file_query_info(
377 getGFile(),
"*", G_FILE_QUERY_INFO_NONE,
nullptr, &
err);
381 assert(
err !=
nullptr);
382 if (
err->code != G_IO_ERROR_NOT_MOUNTED || retried) {
387 "G_IO_ERROR_NOT_MOUNTED \"" <<
err->message
388 <<
"\", trying to mount");
391 if (
err !=
nullptr) {
396 if (ppError !=
nullptr) {
398 }
else if (
err !=
nullptr) {
401 "ignoring GError \"" <<
err->message <<
"\" for <"
418 return pInfo && (g_file_info_get_file_type(pInfo) == G_FILE_TYPE_DIRECTORY);
430 if ( osl_getDateTimeFromTimeValue( &tv, &dt ) )
431 return css::util::DateTime( 0, dt.Seconds, dt.Minutes, dt.Hours,
432 dt.Day, dt.Month, dt.Year,
false);
434 return css::util::DateTime();
438 const css::uno::Sequence< css::beans::Property >& rProperties,
439 const css::uno::Reference< css::ucb::XCommandEnvironment >& xEnv )
443 GFileInfo *pInfo =
nullptr;
444 for(
const css::beans::Property& rProp : rProperties )
446 if ( rProp.Name ==
"IsDocument" )
449 if (pInfo !=
nullptr && g_file_info_has_attribute(pInfo, G_FILE_ATTRIBUTE_STANDARD_TYPE))
450 xRow->appendBoolean( rProp, ( g_file_info_get_file_type( pInfo ) == G_FILE_TYPE_REGULAR ||
451 g_file_info_get_file_type( pInfo ) == G_FILE_TYPE_UNKNOWN ) );
453 xRow->appendVoid( rProp );
455 else if ( rProp.Name ==
"IsFolder" )
458 if (pInfo !=
nullptr && g_file_info_has_attribute( pInfo, G_FILE_ATTRIBUTE_STANDARD_TYPE) )
459 xRow->appendBoolean( rProp, ( g_file_info_get_file_type( pInfo ) == G_FILE_TYPE_DIRECTORY ));
461 xRow->appendVoid( rProp );
463 else if ( rProp.Name ==
"Title" )
466 if (pInfo !=
nullptr && g_file_info_has_attribute(pInfo, G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME))
468 const char *
pName = g_file_info_get_display_name(pInfo);
469 xRow->appendString( rProp, OUString(
pName, strlen(
pName), RTL_TEXTENCODING_UTF8) );
472 xRow->appendVoid(rProp);
474 else if ( rProp.Name ==
"IsReadOnly" )
477 if (pInfo !=
nullptr && g_file_info_has_attribute( pInfo, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE ) )
478 xRow->appendBoolean( rProp, !g_file_info_get_attribute_boolean( pInfo, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE) );
480 xRow->appendVoid( rProp );
482 else if ( rProp.Name ==
"DateCreated" )
485 if (pInfo !=
nullptr && g_file_info_has_attribute( pInfo, G_FILE_ATTRIBUTE_TIME_CREATED ) )
486 xRow->appendTimestamp( rProp,
getDateFromUnix(g_file_info_get_attribute_uint64(pInfo, G_FILE_ATTRIBUTE_TIME_CREATED)) );
488 xRow->appendVoid( rProp );
490 else if ( rProp.Name ==
"DateModified" )
493 if (pInfo !=
nullptr && g_file_info_has_attribute( pInfo, G_FILE_ATTRIBUTE_TIME_CHANGED ) )
494 xRow->appendTimestamp( rProp,
getDateFromUnix(g_file_info_get_attribute_uint64(pInfo, G_FILE_ATTRIBUTE_TIME_CHANGED)) );
496 xRow->appendVoid( rProp );
498 else if ( rProp.Name ==
"Size" )
501 if (pInfo !=
nullptr && g_file_info_has_attribute( pInfo, G_FILE_ATTRIBUTE_STANDARD_SIZE) )
502 xRow->appendLong( rProp, ( g_file_info_get_size( pInfo ) ));
504 xRow->appendVoid( rProp );
506 else if ( rProp.Name ==
"IsVolume" )
509 xRow->appendBoolean( rProp,
false );
511 else if ( rProp.Name ==
"IsCompactDisc" )
514 if (pInfo !=
nullptr && g_file_info_has_attribute( pInfo, G_FILE_ATTRIBUTE_MOUNTABLE_CAN_EJECT ) )
515 xRow->appendBoolean( rProp, g_file_info_get_attribute_boolean(pInfo, G_FILE_ATTRIBUTE_MOUNTABLE_CAN_EJECT) );
517 xRow->appendVoid( rProp );
519 else if ( rProp.Name ==
"IsRemoveable" )
522 if (pInfo !=
nullptr && g_file_info_has_attribute( pInfo, G_FILE_ATTRIBUTE_MOUNTABLE_CAN_UNMOUNT ) )
523 xRow->appendBoolean( rProp, g_file_info_get_attribute_boolean(pInfo, G_FILE_ATTRIBUTE_MOUNTABLE_CAN_UNMOUNT ) );
525 xRow->appendVoid( rProp );
527 else if ( rProp.Name ==
"IsFloppy" )
529 xRow->appendBoolean( rProp,
false );
531 else if ( rProp.Name ==
"IsHidden" )
534 if (pInfo !=
nullptr && g_file_info_has_attribute( pInfo, G_FILE_ATTRIBUTE_STANDARD_IS_HIDDEN) )
535 xRow->appendBoolean( rProp, ( g_file_info_get_is_hidden ( pInfo ) ) );
537 xRow->appendVoid( rProp );
539 else if ( rProp.Name ==
"CreatableContentsInfo" )
547 "Looking for unsupported property " << rProp.Name);
548 xRow->appendVoid(rProp);
555static css::lang::IllegalAccessException
558 return css::lang::IllegalAccessException (
"Property is read-only!", rContext );
568 m_xProvider->queryExistingContents( aAllContents );
571 sal_Int32 nURLPos =
aURL.lastIndexOf(
'/' );
573 if ( nURLPos != (
aURL.getLength() - 1 ) )
576 sal_Int32 nLen =
aURL.getLength();
578 for (
const auto& rContent : aAllContents )
581 OUString aChildURL = xChild->getIdentifier()->getContentIdentifier();
584 if ( ( aChildURL.getLength() > nLen ) && aChildURL.startsWith(
aURL ) )
586 sal_Int32
nPos = aChildURL.indexOf(
'/', nLen );
588 if ( (
nPos == -1 ) || (
nPos == ( aChildURL.getLength() - 1 ) ) )
591 rChildren.emplace_back(
static_cast< ::
gio::Content *
>(xChild.get() ) );
602 css::uno::Reference< css::ucb::XContent > xThis =
this;
619 for (
const auto& rChild : aChildren )
624 css::uno::Reference< css::ucb::XContentIdentifier > xOldChildId = xChild->getIdentifier();
625 OUString aOldChildURL = xOldChildId->getContentIdentifier();
626 OUString aNewChildURL = aOldChildURL.replaceAt(
627 0, aOldURL.getLength(), xNewId->getContentIdentifier() );
629 css::uno::Reference< css::ucb::XContentIdentifier > xNewChildId
630 = new ::ucbhelper::ContentIdentifier( aNewChildURL );
632 if ( !xChild->exchangeIdentity( xNewChildId ) )
642 css::uno::Reference<css::ucb::XCommandEnvironment>
const & env, GFileInfo ** info,
bool fail)
644 assert(info !=
nullptr);
645 if (*info !=
nullptr)
648 GError *
err =
nullptr;
654 else if (
err !=
nullptr)
661 const css::uno::Sequence< css::beans::PropertyValue >& rValues,
662 const css::uno::Reference< css::ucb::XCommandEnvironment >& xEnv )
664 GError *pError=
nullptr;
665 GFileInfo *pNewInfo=
nullptr;
668 pNewInfo = g_file_info_dup(pInfo);
676 g_error_free(pError);
677 pNewInfo = g_file_info_new();
681 sal_Int32
nCount = rValues.getLength();
683 css::beans::PropertyChangeEvent
aEvent;
684 aEvent.Source = getXWeak();
686 aEvent.PropertyHandle = -1;
688 sal_Int32 nChanged = 0, nTitlePos = -1;
690 css::uno::Sequence< css::beans::PropertyChangeEvent > aChanges(
nCount);
691 auto aChangesRange = asNonConstRange(aChanges);
693 css::uno::Sequence< css::uno::Any > aRet(
nCount );
694 auto aRetRange = asNonConstRange(aRet);
695 const css::beans::PropertyValue*
pValues = rValues.getConstArray();
698 const css::beans::PropertyValue& rValue =
pValues[
n ];
699 SAL_INFO(
"ucb.ucp.gio",
"Set prop '" << rValue.Name <<
"'");
700 if ( rValue.Name ==
"ContentType" ||
701 rValue.Name ==
"MediaType" ||
702 rValue.Name ==
"IsDocument" ||
703 rValue.Name ==
"IsFolder" ||
704 rValue.Name ==
"Size" ||
705 rValue.Name ==
"CreatableContentsInfo" )
709 else if ( rValue.Name ==
"Title" )
711 if (!( rValue.Value >>= aNewTitle ))
713 aRetRange[
n ] <<= css::beans::IllegalTypeException
714 (
"Property value has wrong type!",
719 if ( aNewTitle.isEmpty() )
721 aRetRange[
n ] <<= css::lang::IllegalArgumentException
722 (
"Empty title not allowed!",
729 const char *
newName = sNewTitle.getStr();
730 const char *oldName = g_file_info_get_name( pInfo);
736 aEvent.PropertyName =
"Title";
738 aEvent.OldValue <<= OUString(oldName, strlen(oldName), RTL_TEXTENCODING_UTF8);
739 aEvent.NewValue <<= aNewTitle;
740 aChangesRange[ nChanged ] =
aEvent;
741 nTitlePos = nChanged++;
743 g_file_info_set_name(pNewInfo,
newName);
748 SAL_WARN(
"ucb.ucp.gio",
"Unknown property " << rValue.Name);
760 for (sal_Int32
i = 0;
i < nChanged; ++
i)
770 if (!aNewURL.isEmpty() && aNewURL[aNewURL.getLength() - 1] !=
'/')
772 aNewURL += aNewTitle;
774 css::uno::Reference< css::ucb::XContentIdentifier > xNewId
775 = new ::ucbhelper::ContentIdentifier( aNewURL );
779 aRetRange[ nTitlePos ] <<= css::uno::Exception
780 (
"Exchange failed!",
793 g_file_info_copy_into(pNewInfo,
mpInfo);
794 g_object_unref(pNewInfo);
808 aChanges.realloc( nChanged );
813 g_object_unref(pNewInfo);
824 if(!g_file_set_attributes_from_info(pFile, pNewInfo, G_FILE_QUERY_INFO_NONE,
nullptr,
nullptr))
832 const css::uno::Reference< css::io::XOutputStream >& xOut )
836 g_return_if_fail( xIn.is() && xOut.is() );
839 xOut->writeBytes( theData );
849 css::uno::Reference< css::io::XOutputStream > xOut(
xSink, css::uno::UNO_QUERY );
850 css::uno::Reference< css::io::XActiveDataSink > xDataSink(
xSink, css::uno::UNO_QUERY );
852 if ( !xOut.is() && !xDataSink.is() )
855 GError *pError=
nullptr;
856 GFileInputStream *pStream = g_file_read(
getGFile(),
nullptr, &pError);
860 css::uno::Reference< css::io::XInputStream > xIn(
862 new ::gio::InputStream(pStream),
m_xContext));
867 if ( xDataSink.is() )
868 xDataSink->setInputStream( xIn );
873css::uno::Any
Content::open(
const css::ucb::OpenCommandArgument2 & rOpenCommand,
874 const css::uno::Reference< css::ucb::XCommandEnvironment > & xEnv )
878 if (!g_file_query_exists(
getGFile(),
nullptr))
880 css::uno::Sequence< css::uno::Any > aArgs{ css::uno::Any(
883 css::ucb::InteractiveAugmentedIOException(OUString(), getXWeak(),
884 css::task::InteractionClassification_ERROR,
885 bIsFolder ? css::ucb::IOErrorCode_NOT_EXISTING_PATH : css::ucb::IOErrorCode_NOT_EXISTING, aArgs)
894 ( rOpenCommand.Mode == css::ucb::OpenMode::ALL ) ||
895 ( rOpenCommand.Mode == css::ucb::OpenMode::FOLDERS ) ||
896 ( rOpenCommand.Mode == css::ucb::OpenMode::DOCUMENTS )
899 if ( bOpenFolder && bIsFolder )
901 css::uno::Reference< css::ucb::XDynamicResultSet > xSet
905 else if ( rOpenCommand.Sink.is() )
908 ( rOpenCommand.Mode == css::ucb::OpenMode::DOCUMENT_SHARE_DENY_NONE ) ||
909 ( rOpenCommand.Mode == css::ucb::OpenMode::DOCUMENT_SHARE_DENY_WRITE )
913 css::uno::Any ( css::ucb::UnsupportedOpenModeException
914 ( OUString(), getXWeak(),
915 sal_Int16( rOpenCommand.Mode ) ) ),
919 if ( !
feedSink( rOpenCommand.Sink ) )
924 SAL_WARN(
"ucb.ucp.gio",
"Failed to load data from '" <<
m_xIdentifier->getContentIdentifier() <<
"'");
927 css::uno::Any (css::ucb::UnsupportedDataSinkException
928 ( OUString(), getXWeak(),
929 rOpenCommand.Sink ) ),
934 SAL_INFO(
"ucb.ucp.gio",
"Open falling through ...");
939 const css::ucb::Command& aCommand,
941 const css::uno::Reference< css::ucb::XCommandEnvironment >& xEnv )
946 if (
aCommand.Name ==
"getPropertyValues" )
948 css::uno::Sequence< css::beans::Property >
Properties;
953 else if (
aCommand.Name ==
"getPropertySetInfo" )
955 else if (
aCommand.Name ==
"getCommandInfo" )
959 css::ucb::OpenCommandArgument2 aOpenCommand;
960 if ( !(
aCommand.Argument >>= aOpenCommand ) )
962 aRet =
open( aOpenCommand, xEnv );
964 else if (
aCommand.Name ==
"transfer" )
966 css::ucb::TransferInfo transferArgs;
967 if ( !(
aCommand.Argument >>= transferArgs ) )
971 else if (
aCommand.Name ==
"setPropertyValues" )
973 css::uno::Sequence< css::beans::PropertyValue >
aProperties;
978 else if (
aCommand.Name ==
"createNewContent"
981 css::ucb::ContentInfo arg;
982 if ( !(
aCommand.Argument >>= arg ) )
986 else if (
aCommand.Name ==
"insert" )
988 css::ucb::InsertCommandArgument arg;
989 if ( !(
aCommand.Argument >>= arg ) )
991 insert( arg.Data, arg.ReplaceExisting, xEnv );
993 else if (
aCommand.Name ==
"delete" )
995 bool bDeletePhysical =
false;
996 aCommand.Argument >>= bDeletePhysical;
1000 if (!bDeletePhysical && !g_file_trash(
getGFile(),
nullptr,
nullptr))
1001 bDeletePhysical =
true;
1003 if (bDeletePhysical)
1005 GError *pError =
nullptr;
1006 if (!g_file_delete(
getGFile(),
nullptr, &pError))
1017 ( css::uno::Any( css::ucb::UnsupportedCommandException
1028 css::uno::Reference< css::ucb::XContent > xThis =
this;
1035 for (
auto& rChild : aChildren )
1037 rChild->destroy( bDeletePhysical );
1042 bool bReplaceExisting,
const css::uno::Reference< css::ucb::XCommandEnvironment > &xEnv )
1044 GError *pError =
nullptr;
1048 g_file_info_has_attribute(pInfo, G_FILE_ATTRIBUTE_STANDARD_TYPE) &&
1049 g_file_info_get_file_type(pInfo) == G_FILE_TYPE_DIRECTORY )
1051 SAL_INFO(
"ucb.ucp.gio",
"Make directory");
1052 if( !g_file_make_directory(
getGFile(),
nullptr, &pError))
1057 if ( !xInputStream.is() )
1060 ( css::ucb::MissingInputStreamException
1061 ( OUString(), getXWeak() ) ),
1065 GFileOutputStream* pOutStream =
nullptr;
1066 if ( bReplaceExisting )
1068 if (!(pOutStream = g_file_replace(
getGFile(),
nullptr,
false, G_FILE_CREATE_PRIVATE,
nullptr, &pError)))
1073 if (!(pOutStream = g_file_create (
getGFile(), G_FILE_CREATE_PRIVATE,
nullptr, &pError)))
1077 css::uno::Reference < css::io::XOutputStream > xOutput = new ::gio::OutputStream(pOutStream);
1088 static_cast<GFileCopyFlags
>(G_FILE_COPY_OVERWRITE|G_FILE_COPY_TARGET_DEFAULT_PERMS);
1090void Content::transfer(
const css::ucb::TransferInfo& aTransferInfo,
const css::uno::Reference< css::ucb::XCommandEnvironment >& xEnv )
1093 if (!sDest.endsWith(
"/")) {
1096 if (!aTransferInfo.NewTitle.isEmpty())
1098 sDest += rtl::Uri::encode( aTransferInfo.NewTitle,
1099 rtl_UriCharClassPchar,
1100 rtl_UriEncodeIgnoreEscapes,
1101 RTL_TEXTENCODING_UTF8 );
1104 sDest += OUString::createFromAscii(g_file_get_basename(
getGFile()));
1106 GFile *pDest = g_file_new_for_uri(
OUStringToOString(sDest, RTL_TEXTENCODING_UTF8).getStr());
1107 GFile *pSource = g_file_new_for_uri(
OUStringToOString(aTransferInfo.SourceURL, RTL_TEXTENCODING_UTF8).getStr());
1109 bool bSuccess =
false;
1110 GError *pError =
nullptr;
1111 if (aTransferInfo.MoveData)
1112 bSuccess = g_file_move(pSource, pDest, G_FILE_COPY_OVERWRITE,
nullptr,
nullptr,
nullptr, &pError);
1115 g_object_unref(pSource);
1116 g_object_unref(pDest);
1120 "transfer <" << aTransferInfo.SourceURL <<
"> to <" << sDest <<
"> (MoveData = "
1121 <<
int(aTransferInfo.MoveData) <<
") failed with \"" << pError->message <<
"\"");
1127 const css::uno::Reference< css::ucb::XCommandEnvironment >& xEnv)
1133 css::uno::Sequence< css::beans::Property >
props
1140 {
GIO_FILE_TYPE, ( css::ucb::ContentInfoAttribute::INSERT_WITH_INPUTSTREAM | css::ucb::ContentInfoAttribute::KIND_DOCUMENT ),
props },
1155css::uno::Reference< css::ucb::XContent >
1158 bool create_document;
1162 create_document =
true;
1164 create_document =
false;
1167 SAL_WARN(
"ucb.ucp.gio",
"Failed to create new content '" <<
Info.Type <<
"'");
1168 return css::uno::Reference< css::ucb::XContent >();
1171 SAL_INFO(
"ucb.ucp.gio",
"createNewContent (" << create_document <<
")");
1174 if ( (
aURL.lastIndexOf(
'/' ) + 1 ) !=
aURL.getLength() )
1177 name = create_document ?
"[New_Content]" :
"[New_Collection]";
1178 aURL += OUString::createFromAscii(
name );
1180 css::uno::Reference< css::ucb::XContentIdentifier > xId(new ::ucbhelper::ContentIdentifier(
aURL));
1185 }
catch ( css::ucb::ContentCreationException & )
1187 return css::uno::Reference< css::ucb::XContent >();
1193 if (
isFolder( css::uno::Reference< css::ucb::XCommandEnvironment >() ) )
1204 CPPU_TYPE_REF( css::beans::XPropertySetInfoChangeNotifier ),
1207 return s_aFolderCollection.
getTypes();
1220 CPPU_TYPE_REF( css::beans::XPropertySetInfoChangeNotifier ),
1223 return s_aFileCollection.
getTypes();
1228 const css::uno::Reference< css::ucb::XCommandEnvironment > & )
1230 static const css::beans::Property aGenericProperties[] =
1232 css::beans::Property(
"IsDocument",
1234 css::beans::PropertyAttribute::BOUND | css::beans::PropertyAttribute::READONLY ),
1235 css::beans::Property(
"IsFolder",
1237 css::beans::PropertyAttribute::BOUND | css::beans::PropertyAttribute::READONLY ),
1238 css::beans::Property(
"Title",
1240 css::beans::PropertyAttribute::BOUND ),
1241 css::beans::Property(
"IsReadOnly",
1243 css::beans::PropertyAttribute::BOUND | css::beans::PropertyAttribute::READONLY ),
1244 css::beans::Property(
"DateCreated",
1246 css::beans::PropertyAttribute::BOUND | css::beans::PropertyAttribute::READONLY ),
1247 css::beans::Property(
"DateModified",
1249 css::beans::PropertyAttribute::BOUND | css::beans::PropertyAttribute::READONLY ),
1250 css::beans::Property(
"Size",
1252 css::beans::PropertyAttribute::BOUND | css::beans::PropertyAttribute::READONLY ),
1253 css::beans::Property(
"IsVolume",
1255 css::beans::PropertyAttribute::BOUND | css::beans::PropertyAttribute::READONLY ),
1256 css::beans::Property(
"IsCompactDisc",
1258 css::beans::PropertyAttribute::BOUND | css::beans::PropertyAttribute::READONLY ),
1259 css::beans::Property(
"IsRemoveable",
1261 css::beans::PropertyAttribute::BOUND | css::beans::PropertyAttribute::READONLY ),
1262 css::beans::Property(
"IsHidden",
1264 css::beans::PropertyAttribute::BOUND | css::beans::PropertyAttribute::READONLY ),
1265 css::beans::Property(
"CreatableContentsInfo",
1266 -1,
cppu::UnoType<css::uno::Sequence< css::ucb::ContentInfo >>::get(),
1267 css::beans::PropertyAttribute::BOUND | css::beans::PropertyAttribute::READONLY )
1271 return css::uno::Sequence< css::beans::Property > ( aGenericProperties, nProps );
1274css::uno::Sequence< css::ucb::CommandInfo >
Content::getCommands(
const css::uno::Reference< css::ucb::XCommandEnvironment > & xEnv)
1276 static const css::ucb::CommandInfo aCommandInfoTable[] =
1279 css::ucb::CommandInfo
1282 css::ucb::CommandInfo
1283 (
"getPropertySetInfo",
1285 css::ucb::CommandInfo
1286 (
"getPropertyValues",
1287 -1,
cppu::UnoType<css::uno::Sequence< css::beans::Property >>::get() ),
1288 css::ucb::CommandInfo
1289 (
"setPropertyValues",
1290 -1,
cppu::UnoType<css::uno::Sequence< css::beans::PropertyValue >>::get() ),
1293 css::ucb::CommandInfo
1296 css::ucb::CommandInfo
1299 css::ucb::CommandInfo
1304 css::ucb::CommandInfo
1307 css::ucb::CommandInfo
1308 (
"createNewContent",
1313 return css::uno::Sequence< css::ucb::CommandInfo >(aCommandInfoTable,
isFolder(xEnv) ? nProps : nProps - 2);
1320 ContentImplHelper::acquire();
1325 ContentImplHelper::release();
1330 css::uno::Any aRet =
cppu::queryInterface( rType,
static_cast< css::ucb::XContentCreator *
>(
this ) );
1331 return aRet.hasValue() ? aRet : ContentImplHelper::queryInterface(rType);
1336 return "com.sun.star.comp.GIOContent";
1341 css::uno::Sequence<OUString> aSNS {
"com.sun.star.ucb.GIOContent" };
const PropertyValue * pValues
PropertiesInfo aProperties
static SolarMutex * get()
css::uno::Sequence< css::uno::Type > SAL_CALL getTypes()
css::uno::Type const & get()
bool exchangeIdentity(const css::uno::Reference< css::ucb::XContentIdentifier > &xNewId)
bool isFolder(const css::uno::Reference< css::ucb::XCommandEnvironment > &xEnv)
css::uno::Any getBadArgExcept()
void getFileInfo(css::uno::Reference< css::ucb::XCommandEnvironment > const &env, GFileInfo **info, bool fail)
virtual css::uno::Reference< css::ucb::XContent > SAL_CALL createNewContent(const css::ucb::ContentInfo &Info) override
void destroy(bool bDeletePhysical)
virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type &rType) override
css::uno::Any mapGIOError(GError *error)
bool feedSink(const css::uno::Reference< css::uno::XInterface > &aSink)
void insert(const css::uno::Reference< css::io::XInputStream > &xInputStream, bool bReplaceExisting, const css::uno::Reference< css::ucb::XCommandEnvironment > &xEnv)
ContentProvider * m_pProvider
bool doSetFileInfo(GFileInfo *pNewInfo)
css::uno::Sequence< css::uno::Any > setPropertyValues(const css::uno::Sequence< css::beans::PropertyValue > &rValues, const css::uno::Reference< css::ucb::XCommandEnvironment > &xEnv)
virtual void SAL_CALL acquire() noexcept override
virtual css::uno::Sequence< css::beans::Property > getProperties(const css::uno::Reference< css::ucb::XCommandEnvironment > &xEnv) override
css::uno::Any open(const css::ucb::OpenCommandArgument2 &rArg, const css::uno::Reference< css::ucb::XCommandEnvironment > &xEnv)
css::uno::Reference< css::sdbc::XRow > getPropertyValues(const css::uno::Sequence< css::beans::Property > &rProperties, const css::uno::Reference< css::ucb::XCommandEnvironment > &xEnv)
virtual void SAL_CALL abort(sal_Int32 CommandId) override
virtual css::uno::Sequence< css::ucb::CommandInfo > getCommands(const css::uno::Reference< css::ucb::XCommandEnvironment > &xEnv) override
virtual ~Content() override
virtual css::uno::Sequence< css::ucb::ContentInfo > SAL_CALL queryCreatableContentsInfo() override
void transfer(const css::ucb::TransferInfo &rTransferInfo, const css::uno::Reference< css::ucb::XCommandEnvironment > &xEnv)
virtual void SAL_CALL release() noexcept override
virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() override
Content(const css::uno::Reference< css::uno::XComponentContext > &rxContext, ContentProvider *pProvider, const css::uno::Reference< css::ucb::XContentIdentifier > &Identifier)
void queryChildren(ContentRefList &rChildren)
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
GFileInfo * getGFileInfo(const css::uno::Reference< css::ucb::XCommandEnvironment > &xEnv, GError **ppError=nullptr)
virtual OUString SAL_CALL getImplementationName() override
virtual css::uno::Any SAL_CALL execute(const css::ucb::Command &aCommand, sal_Int32 CommandId, const css::uno::Reference< css::ucb::XCommandEnvironment > &Environment) override
static void copyData(const css::uno::Reference< css::io::XInputStream > &xIn, const css::uno::Reference< css::io::XOutputStream > &xOut)
virtual OUString SAL_CALL getContentType() override
virtual OUString getParentURL() override
std::vector< ContentRef > ContentRefList
css::uno::Reference< css::ucb::XCommandInfo > getCommandInfo(const css::uno::Reference< css::ucb::XCommandEnvironment > &xEnv, bool bCache=true)
rtl::Reference< ContentProviderImplHelper > m_xProvider
bool exchange(const css::uno::Reference< css::ucb::XContentIdentifier > &rNewId)
css::uno::Reference< css::beans::XPropertySetInfo > getPropertySetInfo(const css::uno::Reference< css::ucb::XCommandEnvironment > &xEnv, bool bCache=true)
css::uno::Reference< css::ucb::XContentIdentifier > m_xIdentifier
css::uno::Reference< css::uno::XComponentContext > m_xContext
void notifyPropertiesChange(const css::uno::Sequence< css::beans::PropertyChangeEvent > &evt) const
GMountOperation * ooo_mount_operation_new(ucb::ucp::gio::glib::MainContextRef &&context, const css::uno::Reference< css::ucb::XCommandEnvironment > &rEnv)
tools::SvRef< SvBaseLink > xSink
#define SAL_WARN(area, stream)
#define SAL_INFO(area, stream)
#define SAL_N_ELEMENTS(arr)
const css::uno::Reference< css::xml::crypto::XSecurityEnvironment > & env
css::uno::Any SAL_CALL queryInterface(const css::uno::Type &rType, Interface1 *p1)
Any SAL_CALL getCaughtException()
OUString newName(std::u16string_view aNewPrefix, std::u16string_view aOldPrefix, std::u16string_view old_Name)
static css::util::DateTime getDateFromUnix(time_t t)
constexpr OUStringLiteral GIO_FILE_TYPE
const GFileCopyFlags DEFAULT_COPYDATA_FLAGS
static css::lang::IllegalAccessException getReadOnlyException(const css::uno::Reference< css::uno::XInterface > &rContext)
css::uno::Any convertToException(GError *pError, const css::uno::Reference< css::uno::XInterface > &rContext, bool bThrow)
constexpr OUStringLiteral GIO_FOLDER_TYPE
const int TRANSFER_BUFFER_SIZE
XTYPEPROVIDER_COMMON_IMPL(Content)
void convertToIOException(GError *pError, const css::uno::Reference< css::uno::XInterface > &rContext)
OString OUStringToOString(std::u16string_view str, ConnectionSettings const *settings)
std::unique_ptr< GMainContext, detail::MainContextUnref > MainContextRef
std::vector< ContentImplHelperRef > ContentRefList
void cancelCommandExecution(const uno::Any &rException, const uno::Reference< ucb::XCommandEnvironment > &xEnv)