LibreOffice Module ucb (master)  1
gio_content.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
20 #include <sal/config.h>
21 
22 #include <utility>
23 
24 #include <string.h>
25 #include <sys/types.h>
26 #include <sal/macros.h>
27 #include <osl/time.h>
28 #include <sal/log.hxx>
29 
30 #include <com/sun/star/beans/IllegalTypeException.hpp>
31 #include <com/sun/star/beans/PropertyValue.hpp>
32 #include <com/sun/star/beans/PropertyAttribute.hpp>
33 #include <com/sun/star/beans/XPropertySetInfo.hpp>
34 #include <com/sun/star/io/IOException.hpp>
35 #include <com/sun/star/io/XActiveDataSink.hpp>
36 #include <com/sun/star/io/XOutputStream.hpp>
37 #include <com/sun/star/lang/IllegalAccessException.hpp>
38 #include <com/sun/star/lang/IllegalArgumentException.hpp>
39 #include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
40 #include <com/sun/star/ucb/ContentInfoAttribute.hpp>
41 #include <com/sun/star/ucb/InsertCommandArgument.hpp>
42 #include <com/sun/star/ucb/InteractiveAugmentedIOException.hpp>
43 #include <com/sun/star/ucb/InteractiveNetworkGeneralException.hpp>
44 #include <com/sun/star/ucb/InteractiveNetworkResolveNameException.hpp>
45 #include <com/sun/star/ucb/NameClashException.hpp>
46 #include <com/sun/star/ucb/OpenMode.hpp>
47 #include <com/sun/star/ucb/XCommandInfo.hpp>
48 #include <com/sun/star/ucb/MissingInputStreamException.hpp>
49 #include <com/sun/star/ucb/UnsupportedCommandException.hpp>
50 #include <com/sun/star/ucb/UnsupportedDataSinkException.hpp>
51 #include <com/sun/star/ucb/UnsupportedOpenModeException.hpp>
52 #include <com/sun/star/ucb/XDynamicResultSet.hpp>
53 #include <com/sun/star/ucb/XContentCreator.hpp>
54 
56 #include <cppuhelper/exc_hlp.hxx>
61 #include <ucbhelper/macros.hxx>
62 #include <vcl/svapp.hxx>
63 
64 #include "gio_content.hxx"
65 #include "gio_provider.hxx"
66 #include "gio_resultset.hxx"
67 #include "gio_inputstream.hxx"
68 #include "gio_outputstream.hxx"
69 #include "gio_mount.hxx"
70 
71 namespace gio
72 {
73 
75  const css::uno::Reference< css::uno::XComponentContext >& rxContext,
76  ContentProvider* pProvider,
77  const css::uno::Reference< css::ucb::XContentIdentifier >& Identifier)
78  : ContentImplHelper( rxContext, pProvider, Identifier ),
79  m_pProvider( pProvider ), mpFile (nullptr), mpInfo( nullptr ), mbTransient(false)
80 {
81  SAL_INFO("ucb.ucp.gio", "New Content ('" << m_xIdentifier->getContentIdentifier() << "')");
82 }
83 
85  const css::uno::Reference< css::uno::XComponentContext >& rxContext,
86  ContentProvider* pProvider,
87  const css::uno::Reference< css::ucb::XContentIdentifier >& Identifier,
88  bool bIsFolder)
89  : ContentImplHelper( rxContext, pProvider, Identifier ),
90  m_pProvider( pProvider ), mpFile (nullptr), mpInfo( nullptr ), mbTransient(true)
91 {
92  SAL_INFO("ucb.ucp.gio", "Create Content ('" << m_xIdentifier->getContentIdentifier() << "')");
93  mpInfo = g_file_info_new();
94  g_file_info_set_file_type(mpInfo, bIsFolder ? G_FILE_TYPE_DIRECTORY : G_FILE_TYPE_REGULAR);
95 }
96 
98 {
99  if (mpInfo) g_object_unref(mpInfo);
100  if (mpFile) g_object_unref(mpFile);
101 }
102 
104 {
105  OUString sURL;
106  if (GFile* pFile = g_file_get_parent(getGFile()))
107  {
108  char* pPath = g_file_get_uri(pFile);
109  g_object_unref(pFile);
110  sURL = OUString::createFromAscii(pPath);
111  g_free(pPath);
112  }
113  return sURL;
114 }
115 
116 void SAL_CALL Content::abort( sal_Int32 /*CommandId*/ )
117 {
118  //TODO
119  //stick a map from each CommandId to a new GCancellable and propagate
120  //it throughout the g_file_* calls
121 }
122 
123 OUString SAL_CALL Content::getContentType()
124 {
125  return isFolder(css::uno::Reference< css::ucb::XCommandEnvironment >())
126  ? OUString( GIO_FOLDER_TYPE )
127  : OUString( GIO_FILE_TYPE );
128 }
129 
130 #define EXCEPT(aExcept) \
131 do { \
132  if (bThrow) throw aExcept;\
133  aRet <<= aExcept;\
134 } while(false)
135 
136 css::uno::Any convertToException(GError *pError, const css::uno::Reference< css::uno::XInterface >& rContext, bool bThrow)
137 {
138  css::uno::Any aRet;
139 
140  gint eCode = pError->code;
141  OUString sMessage(pError->message, strlen(pError->message), RTL_TEXTENCODING_UTF8);
142  g_error_free(pError);
143 
144  OUString sName;
145 
146  css::uno::Sequence< css::uno::Any > aArgs( 1 );
147  aArgs[ 0 ] <<= sName;
148 
149  switch (eCode)
150  {
151  case G_IO_ERROR_FAILED:
152  { css::io::IOException aExcept(sMessage, rContext);
153  EXCEPT(aExcept); }
154  break;
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);
158  EXCEPT(aExcept); }
159  break;
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);
163  EXCEPT(aExcept); }
164  break;
165  case G_IO_ERROR_EXISTS:
166  { css::ucb::NameClashException aExcept(sMessage, rContext,
167  css::task::InteractionClassification_ERROR, sName);
168  EXCEPT(aExcept); }
169  break;
170  case G_IO_ERROR_INVALID_ARGUMENT:
171  { css::lang::IllegalArgumentException aExcept(sMessage, rContext, -1 );
172  EXCEPT(aExcept); }
173  break;
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);
177  EXCEPT(aExcept); }
178  break;
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);
182  EXCEPT(aExcept); }
183  break;
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);
187  EXCEPT(aExcept); }
188  break;
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);
192  EXCEPT(aExcept); }
193  break;
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);
197  EXCEPT(aExcept); }
198  break;
199  case G_IO_ERROR_PENDING:
200  { css::ucb::InteractiveAugmentedIOException aExcept(sMessage, rContext,
201  css::task::InteractionClassification_ERROR, css::ucb::IOErrorCode_PENDING, aArgs);
202  EXCEPT(aExcept); }
203  break;
204  case G_IO_ERROR_CLOSED:
205  case G_IO_ERROR_CANCELLED:
206  case G_IO_ERROR_TOO_MANY_LINKS:
207  case G_IO_ERROR_WRONG_ETAG:
208  { css::ucb::InteractiveAugmentedIOException aExcept(sMessage, rContext,
209  css::task::InteractionClassification_ERROR, css::ucb::IOErrorCode_GENERAL, aArgs);
210  EXCEPT(aExcept); }
211  break;
212  case G_IO_ERROR_NOT_SUPPORTED:
213  case G_IO_ERROR_CANT_CREATE_BACKUP:
214  case G_IO_ERROR_WOULD_MERGE:
215  { css::ucb::InteractiveAugmentedIOException aExcept(sMessage, rContext,
216  css::task::InteractionClassification_ERROR, css::ucb::IOErrorCode_NOT_SUPPORTED, aArgs);
217  EXCEPT(aExcept); }
218  break;
219  case G_IO_ERROR_NO_SPACE:
220  { css::ucb::InteractiveAugmentedIOException aExcept(sMessage, rContext,
221  css::task::InteractionClassification_ERROR, css::ucb::IOErrorCode_OUT_OF_DISK_SPACE, aArgs);
222  EXCEPT(aExcept); }
223  break;
224  case G_IO_ERROR_INVALID_FILENAME:
225  { css::ucb::InteractiveAugmentedIOException aExcept(sMessage, rContext,
226  css::task::InteractionClassification_ERROR, css::ucb::IOErrorCode_INVALID_CHARACTER, aArgs);
227  EXCEPT(aExcept); }
228  break;
229  case G_IO_ERROR_READ_ONLY:
230  { css::ucb::InteractiveAugmentedIOException aExcept(sMessage, rContext,
231  css::task::InteractionClassification_ERROR, css::ucb::IOErrorCode_WRITE_PROTECTED, aArgs);
232  EXCEPT(aExcept); }
233  break;
234  case G_IO_ERROR_TIMED_OUT:
235  { css::ucb::InteractiveAugmentedIOException aExcept(sMessage, rContext,
236  css::task::InteractionClassification_ERROR, css::ucb::IOErrorCode_DEVICE_NOT_READY, aArgs);
237  EXCEPT(aExcept); }
238  break;
239  case G_IO_ERROR_WOULD_RECURSE:
240  { css::ucb::InteractiveAugmentedIOException aExcept(sMessage, rContext,
241  css::task::InteractionClassification_ERROR, css::ucb::IOErrorCode_RECURSIVE, aArgs);
242  EXCEPT(aExcept); }
243  break;
244  case G_IO_ERROR_BUSY:
245  case G_IO_ERROR_WOULD_BLOCK:
246  { css::ucb::InteractiveAugmentedIOException aExcept(sMessage, rContext,
247  css::task::InteractionClassification_ERROR, css::ucb::IOErrorCode_LOCKING_VIOLATION, aArgs);
248  EXCEPT(aExcept); }
249  break;
250  case G_IO_ERROR_HOST_NOT_FOUND:
251  { css::ucb::InteractiveNetworkResolveNameException aExcept(sMessage, rContext,
252  css::task::InteractionClassification_ERROR, OUString());
253  EXCEPT(aExcept);}
254  break;
255  default:
256  case G_IO_ERROR_ALREADY_MOUNTED:
257  case G_IO_ERROR_NOT_EMPTY:
258  case G_IO_ERROR_NOT_SYMBOLIC_LINK:
259  case G_IO_ERROR_NOT_MOUNTABLE_FILE:
260  case G_IO_ERROR_FAILED_HANDLED:
261  { css::ucb::InteractiveNetworkGeneralException aExcept(sMessage, rContext,
262  css::task::InteractionClassification_ERROR);
263  EXCEPT(aExcept);}
264  break;
265  }
266  return aRet;
267 }
268 
269 void convertToIOException(GError *pError, const css::uno::Reference< css::uno::XInterface >& rContext)
270 {
271  try
272  {
273  convertToException(pError, rContext);
274  }
275  catch (const css::io::IOException&)
276  {
277  throw;
278  }
279  catch (const css::uno::RuntimeException&)
280  {
281  throw;
282  }
283  catch (const css::uno::Exception& e)
284  {
285  css::uno::Any a(cppu::getCaughtException());
286  throw css::lang::WrappedTargetRuntimeException(
287  "wrapped Exception " + e.Message,
288  css::uno::Reference<css::uno::XInterface>(), a);
289  }
290 }
291 
292 css::uno::Any Content::mapGIOError( GError *pError )
293 {
294  if (!pError)
295  return getBadArgExcept();
296 
297  return convertToException(pError, static_cast< cppu::OWeakObject * >(this), false);
298 }
299 
301 {
302  return css::uno::makeAny( css::lang::IllegalArgumentException(
303  "Wrong argument type!",
304  static_cast< cppu::OWeakObject * >( this ), -1) );
305 }
306 
308 {
310  GMainLoop *mpLoop;
311  GMountOperation *mpAuthentication;
312  GError *mpError;
313  static void Completed(GObject *source, GAsyncResult *res, gpointer user_data);
314 public:
315  explicit MountOperation(const css::uno::Reference< css::ucb::XCommandEnvironment >& xEnv);
316  ~MountOperation();
317  GError *Mount(GFile *pFile);
318 };
319 
320 MountOperation::MountOperation(const css::uno::Reference< css::ucb::XCommandEnvironment >& xEnv) : mpError(nullptr)
321 {
322  ucb::ucp::gio::glib::MainContextRef oldContext(g_main_context_ref_thread_default());
323  mContext.reset(g_main_context_new());
324  mpLoop = g_main_loop_new(mContext.get(), FALSE);
325  g_main_context_push_thread_default(mContext.get());
326  mpAuthentication = ooo_mount_operation_new(std::move(oldContext), xEnv);
327 }
328 
329 void MountOperation::Completed(GObject *source, GAsyncResult *res, gpointer user_data)
330 {
331  MountOperation *pThis = static_cast<MountOperation*>(user_data);
332  g_file_mount_enclosing_volume_finish(G_FILE(source), res, &(pThis->mpError));
333  g_main_loop_quit(pThis->mpLoop);
334 }
335 
336 GError *MountOperation::Mount(GFile *pFile)
337 {
338  g_file_mount_enclosing_volume(pFile, G_MOUNT_MOUNT_NONE, mpAuthentication, nullptr, MountOperation::Completed, this);
339  {
340  //HACK: At least the gdk_threads_set_lock_functions(GdkThreadsEnter,
341  // GdkThreadsLeave) call in vcl/unx/gtk/app/gtkinst.cxx will lead to
342  // GdkThreadsLeave unlock the SolarMutex down to zero at the end of
343  // g_main_loop_run, so we need ~SolarMutexReleaser to raise it back to
344  // the original value again:
345  if (comphelper::SolarMutex::get()->IsCurrentThread())
346  {
347  SolarMutexReleaser rel;
348  g_main_loop_run(mpLoop);
349  }
350  else
351  {
352  g_main_loop_run(mpLoop);
353  }
354  }
355  return mpError;
356 }
357 
359 {
360  g_object_unref(mpAuthentication);
361  g_main_context_pop_thread_default(mContext.get());
362  g_main_loop_unref(mpLoop);
363 }
364 
365 GFileInfo* Content::getGFileInfo(const css::uno::Reference< css::ucb::XCommandEnvironment >& xEnv, GError **ppError)
366 {
367  GError * err = nullptr;
368  if (mpInfo == nullptr && !mbTransient) {
369  for (bool retried = false;; retried = true) {
370  mpInfo = g_file_query_info(
371  getGFile(), "*", G_FILE_QUERY_INFO_NONE, nullptr, &err);
372  if (mpInfo != nullptr) {
373  break;
374  }
375  assert(err != nullptr);
376  if (err->code != G_IO_ERROR_NOT_MOUNTED || retried) {
377  break;
378  }
379  SAL_INFO(
380  "ucb.ucp.gio",
381  "G_IO_ERROR_NOT_MOUNTED \"" << err->message
382  << "\", trying to mount");
383  g_error_free(err);
384  err = MountOperation(xEnv).Mount(getGFile());
385  if (err != nullptr) {
386  break;
387  }
388  }
389  }
390  if (ppError != nullptr) {
391  *ppError = err;
392  } else if (err != nullptr) {
393  SAL_WARN(
394  "ucb.ucp.gio",
395  "ignoring GError \"" << err->message << "\" for <"
396  << m_xIdentifier->getContentIdentifier() << ">");
397  g_error_free(err);
398  }
399  return mpInfo;
400 }
401 
403 {
404  if (!mpFile)
405  mpFile = g_file_new_for_uri(OUStringToOString(m_xIdentifier->getContentIdentifier(), RTL_TEXTENCODING_UTF8).getStr());
406  return mpFile;
407 }
408 
409 bool Content::isFolder(const css::uno::Reference< css::ucb::XCommandEnvironment >& xEnv)
410 {
411  GFileInfo *pInfo = getGFileInfo(xEnv);
412  return pInfo && (g_file_info_get_file_type(pInfo) == G_FILE_TYPE_DIRECTORY);
413 }
414 
415 static css::util::DateTime getDateFromUnix (time_t t)
416 {
417  TimeValue tv;
418  tv.Nanosec = 0;
419  tv.Seconds = t;
420  oslDateTime dt;
421 
422  if ( osl_getDateTimeFromTimeValue( &tv, &dt ) )
423  return css::util::DateTime( 0, dt.Seconds, dt.Minutes, dt.Hours,
424  dt.Day, dt.Month, dt.Year, false);
425  else
426  return css::util::DateTime();
427 }
428 
429 css::uno::Reference< css::sdbc::XRow > Content::getPropertyValues(
430  const css::uno::Sequence< css::beans::Property >& rProperties,
431  const css::uno::Reference< css::ucb::XCommandEnvironment >& xEnv )
432 {
433  rtl::Reference< ::ucbhelper::PropertyValueSet > xRow = new ::ucbhelper::PropertyValueSet( m_xContext );
434 
435  GFileInfo *pInfo = nullptr;
436  for( const css::beans::Property& rProp : rProperties )
437  {
438  if ( rProp.Name == "IsDocument" )
439  {
440  getFileInfo(xEnv, &pInfo, true);
441  if (pInfo != nullptr && g_file_info_has_attribute(pInfo, G_FILE_ATTRIBUTE_STANDARD_TYPE))
442  xRow->appendBoolean( rProp, ( g_file_info_get_file_type( pInfo ) == G_FILE_TYPE_REGULAR ||
443  g_file_info_get_file_type( pInfo ) == G_FILE_TYPE_UNKNOWN ) );
444  else
445  xRow->appendVoid( rProp );
446  }
447  else if ( rProp.Name == "IsFolder" )
448  {
449  getFileInfo(xEnv, &pInfo, true);
450  if (pInfo != nullptr && g_file_info_has_attribute( pInfo, G_FILE_ATTRIBUTE_STANDARD_TYPE) )
451  xRow->appendBoolean( rProp, ( g_file_info_get_file_type( pInfo ) == G_FILE_TYPE_DIRECTORY ));
452  else
453  xRow->appendVoid( rProp );
454  }
455  else if ( rProp.Name == "Title" )
456  {
457  getFileInfo(xEnv, &pInfo, false);
458  if (pInfo != nullptr && g_file_info_has_attribute(pInfo, G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME))
459  {
460  const char *pName = g_file_info_get_display_name(pInfo);
461  xRow->appendString( rProp, OUString(pName, strlen(pName), RTL_TEXTENCODING_UTF8) );
462  }
463  else
464  xRow->appendVoid(rProp);
465  }
466  else if ( rProp.Name == "IsReadOnly" )
467  {
468  getFileInfo(xEnv, &pInfo, true);
469  if (pInfo != nullptr && g_file_info_has_attribute( pInfo, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE ) )
470  xRow->appendBoolean( rProp, !g_file_info_get_attribute_boolean( pInfo, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE) );
471  else
472  xRow->appendVoid( rProp );
473  }
474  else if ( rProp.Name == "DateCreated" )
475  {
476  getFileInfo(xEnv, &pInfo, true);
477  if (pInfo != nullptr && g_file_info_has_attribute( pInfo, G_FILE_ATTRIBUTE_TIME_CREATED ) )
478  xRow->appendTimestamp( rProp, getDateFromUnix(g_file_info_get_attribute_uint64(pInfo, G_FILE_ATTRIBUTE_TIME_CREATED)) );
479  else
480  xRow->appendVoid( rProp );
481  }
482  else if ( rProp.Name == "DateModified" )
483  {
484  getFileInfo(xEnv, &pInfo, true);
485  if (pInfo != nullptr && g_file_info_has_attribute( pInfo, G_FILE_ATTRIBUTE_TIME_CHANGED ) )
486  xRow->appendTimestamp( rProp, getDateFromUnix(g_file_info_get_attribute_uint64(pInfo, G_FILE_ATTRIBUTE_TIME_CHANGED)) );
487  else
488  xRow->appendVoid( rProp );
489  }
490  else if ( rProp.Name == "Size" )
491  {
492  getFileInfo(xEnv, &pInfo, true);
493  if (pInfo != nullptr && g_file_info_has_attribute( pInfo, G_FILE_ATTRIBUTE_STANDARD_SIZE) )
494  xRow->appendLong( rProp, ( g_file_info_get_size( pInfo ) ));
495  else
496  xRow->appendVoid( rProp );
497  }
498  else if ( rProp.Name == "IsVolume" )
499  {
500  //What do we use this for ?
501  xRow->appendBoolean( rProp, false );
502  }
503  else if ( rProp.Name == "IsCompactDisc" )
504  {
505  getFileInfo(xEnv, &pInfo, true);
506  if (pInfo != nullptr && g_file_info_has_attribute( pInfo, G_FILE_ATTRIBUTE_MOUNTABLE_CAN_EJECT ) )
507  xRow->appendBoolean( rProp, g_file_info_get_attribute_boolean(pInfo, G_FILE_ATTRIBUTE_MOUNTABLE_CAN_EJECT) );
508  else
509  xRow->appendVoid( rProp );
510  }
511  else if ( rProp.Name == "IsRemoveable" )
512  {
513  getFileInfo(xEnv, &pInfo, true);
514  if (pInfo != nullptr && g_file_info_has_attribute( pInfo, G_FILE_ATTRIBUTE_MOUNTABLE_CAN_UNMOUNT ) )
515  xRow->appendBoolean( rProp, g_file_info_get_attribute_boolean(pInfo, G_FILE_ATTRIBUTE_MOUNTABLE_CAN_UNMOUNT ) );
516  else
517  xRow->appendVoid( rProp );
518  }
519  else if ( rProp.Name == "IsFloppy" )
520  {
521  xRow->appendBoolean( rProp, false );
522  }
523  else if ( rProp.Name == "IsHidden" )
524  {
525  getFileInfo(xEnv, &pInfo, true);
526  if (pInfo != nullptr && g_file_info_has_attribute( pInfo, G_FILE_ATTRIBUTE_STANDARD_IS_HIDDEN) )
527  xRow->appendBoolean( rProp, ( g_file_info_get_is_hidden ( pInfo ) ) );
528  else
529  xRow->appendVoid( rProp );
530  }
531  else if ( rProp.Name == "CreatableContentsInfo" )
532  {
533  xRow->appendObject( rProp, css::uno::makeAny( queryCreatableContentsInfo( xEnv ) ) );
534  }
535  else
536  {
537  SAL_WARN(
538  "ucb.ucp.gio",
539  "Looking for unsupported property " << rProp.Name);
540  }
541  }
542 
543  return css::uno::Reference< css::sdbc::XRow >( xRow.get() );
544 }
545 
546 static css::lang::IllegalAccessException
547 getReadOnlyException( const css::uno::Reference< css::uno::XInterface >& rContext )
548 {
549  return css::lang::IllegalAccessException ("Property is read-only!", rContext );
550 }
551 
553 {
554  // Obtain a list with a snapshot of all currently instantiated contents
555  // from provider and extract the contents which are direct children
556  // of this content.
557 
558  ucbhelper::ContentRefList aAllContents;
559  m_xProvider->queryExistingContents( aAllContents );
560 
561  OUString aURL = m_xIdentifier->getContentIdentifier();
562  sal_Int32 nURLPos = aURL.lastIndexOf( '/' );
563 
564  if ( nURLPos != ( aURL.getLength() - 1 ) )
565  aURL += "/";
566 
567  sal_Int32 nLen = aURL.getLength();
568 
569  for ( const auto& rContent : aAllContents )
570  {
571  ucbhelper::ContentImplHelperRef xChild = rContent;
572  OUString aChildURL = xChild->getIdentifier()->getContentIdentifier();
573 
574  // Is aURL a prefix of aChildURL?
575  if ( ( aChildURL.getLength() > nLen ) && aChildURL.startsWith( aURL ) )
576  {
577  sal_Int32 nPos = aChildURL.indexOf( '/', nLen );
578 
579  if ( ( nPos == -1 ) || ( nPos == ( aChildURL.getLength() - 1 ) ) )
580  {
581  // No further slashes / only a final slash. It's a child!
582  rChildren.emplace_back(static_cast< ::gio::Content * >(xChild.get() ) );
583  }
584  }
585  }
586 }
587 
588 bool Content::exchangeIdentity( const css::uno::Reference< css::ucb::XContentIdentifier >& xNewId )
589 {
590  if ( !xNewId.is() )
591  return false;
592 
593  css::uno::Reference< css::ucb::XContent > xThis = this;
594 
595  if ( mbTransient )
596  {
597  m_xIdentifier = xNewId;
598  return false;
599  }
600 
601  OUString aOldURL = m_xIdentifier->getContentIdentifier();
602 
603  // Exchange own identitity.
604  if ( exchange( xNewId ) )
605  {
606  // Process instantiated children...
607  ContentRefList aChildren;
608  queryChildren( aChildren );
609 
610  for ( const auto& rChild : aChildren )
611  {
612  ContentRef xChild = rChild;
613 
614  // Create new content identifier for the child...
615  css::uno::Reference< css::ucb::XContentIdentifier > xOldChildId = xChild->getIdentifier();
616  OUString aOldChildURL = xOldChildId->getContentIdentifier();
617  OUString aNewChildURL = aOldChildURL.replaceAt(
618  0, aOldURL.getLength(), xNewId->getContentIdentifier() );
619 
620  css::uno::Reference< css::ucb::XContentIdentifier > xNewChildId
621  = new ::ucbhelper::ContentIdentifier( aNewChildURL );
622 
623  if ( !xChild->exchangeIdentity( xNewChildId ) )
624  return false;
625  }
626  return true;
627  }
628 
629  return false;
630 }
631 
633  css::uno::Reference<css::ucb::XCommandEnvironment> const & env, GFileInfo ** info, bool fail)
634 {
635  assert(info != nullptr);
636  if (*info == nullptr)
637  {
638  GError * err = nullptr;
639  *info = getGFileInfo(env, &err);
640  if (*info == nullptr && !mbTransient && fail)
641  {
643  }
644  else if (err != nullptr)
645  {
646  g_error_free(err);
647  }
648  }
649 }
650 
651 css::uno::Sequence< css::uno::Any > Content::setPropertyValues(
652  const css::uno::Sequence< css::beans::PropertyValue >& rValues,
653  const css::uno::Reference< css::ucb::XCommandEnvironment >& xEnv )
654 {
655  GError *pError=nullptr;
656  GFileInfo *pNewInfo=nullptr;
657  GFileInfo *pInfo = getGFileInfo(xEnv, &pError);
658  if (pInfo)
659  pNewInfo = g_file_info_dup(pInfo);
660  else
661  {
662  if (!mbTransient)
664  else
665  {
666  if (pError)
667  g_error_free(pError);
668  pNewInfo = g_file_info_new();
669  }
670  }
671 
672  sal_Int32 nCount = rValues.getLength();
673 
674  css::beans::PropertyChangeEvent aEvent;
675  aEvent.Source = static_cast< cppu::OWeakObject * >( this );
676  aEvent.Further = false;
677  aEvent.PropertyHandle = -1;
678 
679  sal_Int32 nChanged = 0, nTitlePos = -1;
680  const char *newName = nullptr;
681  css::uno::Sequence< css::beans::PropertyChangeEvent > aChanges(nCount);
682 
683  css::uno::Sequence< css::uno::Any > aRet( nCount );
684  const css::beans::PropertyValue* pValues = rValues.getConstArray();
685  for ( sal_Int32 n = 0; n < nCount; ++n )
686  {
687  const css::beans::PropertyValue& rValue = pValues[ n ];
688  SAL_INFO("ucb.ucp.gio", "Set prop '" << rValue.Name << "'");
689  if ( rValue.Name == "ContentType" ||
690  rValue.Name == "MediaType" ||
691  rValue.Name == "IsDocument" ||
692  rValue.Name == "IsFolder" ||
693  rValue.Name == "Size" ||
694  rValue.Name == "CreatableContentsInfo" )
695  {
696  aRet[ n ] <<= getReadOnlyException( static_cast< cppu::OWeakObject * >(this) );
697  }
698  else if ( rValue.Name == "Title" )
699  {
700  OUString aNewTitle;
701  if (!( rValue.Value >>= aNewTitle ))
702  {
703  aRet[ n ] <<= css::beans::IllegalTypeException
704  ( "Property value has wrong type!",
705  static_cast< cppu::OWeakObject * >( this ) );
706  continue;
707  }
708 
709  if ( aNewTitle.getLength() <= 0 )
710  {
711  aRet[ n ] <<= css::lang::IllegalArgumentException
712  ( "Empty title not allowed!",
713  static_cast< cppu::OWeakObject * >( this ), -1 );
714  continue;
715 
716  }
717 
718  OString sNewTitle = OUStringToOString(aNewTitle, RTL_TEXTENCODING_UTF8);
719  newName = sNewTitle.getStr();
720  const char *oldName = g_file_info_get_name( pInfo);
721 
722  if (!newName || !oldName || strcmp(newName, oldName))
723  {
724  SAL_INFO("ucb.ucp.gio", "Set new name to '" << newName << "'");
725 
726  aEvent.PropertyName = "Title";
727  if (oldName)
728  aEvent.OldValue <<= OUString(oldName, strlen(oldName), RTL_TEXTENCODING_UTF8);
729  aEvent.NewValue <<= aNewTitle;
730  aChanges.getArray()[ nChanged ] = aEvent;
731  nTitlePos = nChanged++;
732 
733  g_file_info_set_name(pNewInfo, newName);
734  }
735  }
736  else
737  {
738  SAL_WARN("ucb.ucp.gio", "Unknown property " << rValue.Name);
739  aRet[ n ] <<= getReadOnlyException( static_cast< cppu::OWeakObject * >(this) );
740  //TODO
741  }
742  }
743 
744  if (nChanged)
745  {
746  bool bOk = true;
747  if (!mbTransient)
748  {
749  if ((bOk = doSetFileInfo(pNewInfo)))
750  {
751  for (sal_Int32 i = 0; i < nChanged; ++i)
752  aRet[ i ] = getBadArgExcept();
753  }
754  }
755 
756  if (bOk)
757  {
758  if (nTitlePos > -1)
759  {
760  OUString aNewURL = getParentURL() +
761  OUString( newName, strlen(newName), RTL_TEXTENCODING_UTF8 );
762  css::uno::Reference< css::ucb::XContentIdentifier > xNewId
763  = new ::ucbhelper::ContentIdentifier( aNewURL );
764 
765  if (!exchangeIdentity( xNewId ) )
766  {
767  aRet[ nTitlePos ] <<= css::uno::Exception
768  ( "Exchange failed!",
769  static_cast< cppu::OWeakObject * >( this ) );
770  }
771  }
772 
773  if (!mbTransient) //Discard and refetch
774  {
775  g_object_unref(mpInfo);
776  mpInfo = nullptr;
777  }
778 
779  if (mpInfo)
780  {
781  g_file_info_copy_into(pNewInfo, mpInfo);
782  g_object_unref(pNewInfo);
783  }
784  else
785  mpInfo = pNewInfo;
786 
787  if (mpFile) //Discard and refetch
788  {
789  g_object_unref(mpFile);
790  mpFile = nullptr;
791  }
792  }
793 
794  aChanges.realloc( nChanged );
795  notifyPropertiesChange( aChanges );
796  }
797 
798  return aRet;
799 }
800 
801 bool Content::doSetFileInfo(GFileInfo *pNewInfo)
802 {
803  g_assert (!mbTransient);
804 
805  bool bOk = true;
806  GFile *pFile = getGFile();
807  if(!g_file_set_attributes_from_info(pFile, pNewInfo, G_FILE_QUERY_INFO_NONE, nullptr, nullptr))
808  bOk = false;
809  return bOk;
810 }
811 
812 const int TRANSFER_BUFFER_SIZE = 65536;
813 
814 void Content::copyData( const css::uno::Reference< css::io::XInputStream >& xIn,
815  const css::uno::Reference< css::io::XOutputStream >& xOut )
816 {
817  css::uno::Sequence< sal_Int8 > theData( TRANSFER_BUFFER_SIZE );
818 
819  g_return_if_fail( xIn.is() && xOut.is() );
820 
821  while ( xIn->readBytes( theData, TRANSFER_BUFFER_SIZE ) > 0 )
822  xOut->writeBytes( theData );
823 
824  xOut->closeOutput();
825 }
826 
827 bool Content::feedSink( const css::uno::Reference< css::uno::XInterface >& xSink )
828 {
829  if ( !xSink.is() )
830  return false;
831 
832  css::uno::Reference< css::io::XOutputStream > xOut(xSink, css::uno::UNO_QUERY );
833  css::uno::Reference< css::io::XActiveDataSink > xDataSink(xSink, css::uno::UNO_QUERY );
834 
835  if ( !xOut.is() && !xDataSink.is() )
836  return false;
837 
838  GError *pError=nullptr;
839  GFileInputStream *pStream = g_file_read(getGFile(), nullptr, &pError);
840  if (!pStream)
841  convertToException(pError, static_cast< cppu::OWeakObject * >(this));
842 
843  css::uno::Reference< css::io::XInputStream > xIn(
845  new ::gio::InputStream(pStream), m_xContext));
846 
847  if ( xOut.is() )
848  copyData( xIn, xOut );
849 
850  if ( xDataSink.is() )
851  xDataSink->setInputStream( xIn );
852 
853  return true;
854 }
855 
856 css::uno::Any Content::open(const css::ucb::OpenCommandArgument2 & rOpenCommand,
857  const css::uno::Reference< css::ucb::XCommandEnvironment > & xEnv )
858 {
859  bool bIsFolder = isFolder(xEnv);
860 
861  if (!g_file_query_exists(getGFile(), nullptr))
862  {
863  css::uno::Sequence< css::uno::Any > aArgs( 1 );
864  aArgs[ 0 ] <<= m_xIdentifier->getContentIdentifier();
865  css::uno::Any aErr = css::uno::makeAny(
866  css::ucb::InteractiveAugmentedIOException(OUString(), static_cast< cppu::OWeakObject * >( this ),
867  css::task::InteractionClassification_ERROR,
868  bIsFolder ? css::ucb::IOErrorCode_NOT_EXISTING_PATH : css::ucb::IOErrorCode_NOT_EXISTING, aArgs)
869  );
870 
872  }
873 
874  css::uno::Any aRet;
875 
876  bool bOpenFolder = (
877  ( rOpenCommand.Mode == css::ucb::OpenMode::ALL ) ||
878  ( rOpenCommand.Mode == css::ucb::OpenMode::FOLDERS ) ||
879  ( rOpenCommand.Mode == css::ucb::OpenMode::DOCUMENTS )
880  );
881 
882  if ( bOpenFolder && bIsFolder )
883  {
884  css::uno::Reference< css::ucb::XDynamicResultSet > xSet
885  = new DynamicResultSet( m_xContext, this, rOpenCommand, xEnv );
886  aRet <<= xSet;
887  }
888  else if ( rOpenCommand.Sink.is() )
889  {
890  if (
891  ( rOpenCommand.Mode == css::ucb::OpenMode::DOCUMENT_SHARE_DENY_NONE ) ||
892  ( rOpenCommand.Mode == css::ucb::OpenMode::DOCUMENT_SHARE_DENY_WRITE )
893  )
894  {
896  css::uno::makeAny ( css::ucb::UnsupportedOpenModeException
897  ( OUString(), static_cast< cppu::OWeakObject * >( this ),
898  sal_Int16( rOpenCommand.Mode ) ) ),
899  xEnv );
900  }
901 
902  if ( !feedSink( rOpenCommand.Sink ) )
903  {
904  // Note: rOpenCommand.Sink may contain an XStream
905  // implementation. Support for this type of
906  // sink is optional...
907  SAL_WARN("ucb.ucp.gio", "Failed to load data from '" << m_xIdentifier->getContentIdentifier() << "'");
908 
910  css::uno::makeAny (css::ucb::UnsupportedDataSinkException
911  ( OUString(), static_cast< cppu::OWeakObject * >( this ),
912  rOpenCommand.Sink ) ),
913  xEnv );
914  }
915  }
916  else
917  SAL_INFO("ucb.ucp.gio", "Open falling through ...");
918  return aRet;
919 }
920 
921 css::uno::Any SAL_CALL Content::execute(
922  const css::ucb::Command& aCommand,
923  sal_Int32 /*CommandId*/,
924  const css::uno::Reference< css::ucb::XCommandEnvironment >& xEnv )
925 {
926  SAL_INFO("ucb.ucp.gio", "Content::execute " << aCommand.Name);
927  css::uno::Any aRet;
928 
929  if ( aCommand.Name == "getPropertyValues" )
930  {
931  css::uno::Sequence< css::beans::Property > Properties;
932  if ( !( aCommand.Argument >>= Properties ) )
934  aRet <<= getPropertyValues( Properties, xEnv );
935  }
936  else if ( aCommand.Name == "getPropertySetInfo" )
937  aRet <<= getPropertySetInfo( xEnv, false );
938  else if ( aCommand.Name == "getCommandInfo" )
939  aRet <<= getCommandInfo( xEnv, false );
940  else if ( aCommand.Name == "open" )
941  {
942  css::ucb::OpenCommandArgument2 aOpenCommand;
943  if ( !( aCommand.Argument >>= aOpenCommand ) )
945  aRet = open( aOpenCommand, xEnv );
946  }
947  else if ( aCommand.Name == "transfer" )
948  {
949  css::ucb::TransferInfo transferArgs;
950  if ( !( aCommand.Argument >>= transferArgs ) )
952  transfer( transferArgs, xEnv );
953  }
954  else if ( aCommand.Name == "setPropertyValues" )
955  {
956  css::uno::Sequence< css::beans::PropertyValue > aProperties;
957  if ( !( aCommand.Argument >>= aProperties ) || !aProperties.hasElements() )
959  aRet <<= setPropertyValues( aProperties, xEnv );
960  }
961  else if (aCommand.Name == "createNewContent"
962  && isFolder( xEnv ) )
963  {
964  css::ucb::ContentInfo arg;
965  if ( !( aCommand.Argument >>= arg ) )
967  aRet <<= createNewContent( arg );
968  }
969  else if ( aCommand.Name == "insert" )
970  {
971  css::ucb::InsertCommandArgument arg;
972  if ( !( aCommand.Argument >>= arg ) )
974  insert( arg.Data, arg.ReplaceExisting, xEnv );
975  }
976  else if ( aCommand.Name == "delete" )
977  {
978  bool bDeletePhysical = false;
979  aCommand.Argument >>= bDeletePhysical;
980 
981  //If no delete physical, try and trashcan it, if that doesn't work go
982  //ahead and try and delete it anyway
983  if (!bDeletePhysical && !g_file_trash(getGFile(), nullptr, nullptr))
984  bDeletePhysical = true;
985 
986  if (bDeletePhysical)
987  {
988  GError *pError = nullptr;
989  if (!g_file_delete( getGFile(), nullptr, &pError))
991  }
992 
993  destroy( bDeletePhysical );
994  }
995  else
996  {
997  SAL_WARN("ucb.ucp.gio", "Unknown command " << aCommand.Name);
998 
1000  ( css::uno::makeAny( css::ucb::UnsupportedCommandException
1001  ( OUString(),
1002  static_cast< cppu::OWeakObject * >( this ) ) ),
1003  xEnv );
1004  }
1005 
1006  return aRet;
1007 }
1008 
1009 void Content::destroy( bool bDeletePhysical )
1010 {
1011  css::uno::Reference< css::ucb::XContent > xThis = this;
1012 
1013  deleted();
1014 
1016  queryChildren( aChildren );
1017 
1018  for ( auto& rChild : aChildren )
1019  {
1020  rChild->destroy( bDeletePhysical );
1021  }
1022 }
1023 
1024 void Content::insert(const css::uno::Reference< css::io::XInputStream > &xInputStream,
1025  bool bReplaceExisting, const css::uno::Reference< css::ucb::XCommandEnvironment > &xEnv )
1026 {
1027  GError *pError = nullptr;
1028  GFileInfo *pInfo = getGFileInfo(xEnv);
1029 
1030  if ( pInfo &&
1031  g_file_info_has_attribute(pInfo, G_FILE_ATTRIBUTE_STANDARD_TYPE) &&
1032  g_file_info_get_file_type(pInfo) == G_FILE_TYPE_DIRECTORY )
1033  {
1034  SAL_INFO("ucb.ucp.gio", "Make directory");
1035  if( !g_file_make_directory( getGFile(), nullptr, &pError))
1037  return;
1038  }
1039 
1040  if ( !xInputStream.is() )
1041  {
1042  ucbhelper::cancelCommandExecution( css::uno::makeAny
1043  ( css::ucb::MissingInputStreamException
1044  ( OUString(), static_cast< cppu::OWeakObject * >( this ) ) ),
1045  xEnv );
1046  }
1047 
1048  GFileOutputStream* pOutStream = nullptr;
1049  if ( bReplaceExisting )
1050  {
1051  if (!(pOutStream = g_file_replace(getGFile(), nullptr, false, G_FILE_CREATE_PRIVATE, nullptr, &pError)))
1053  }
1054  else
1055  {
1056  if (!(pOutStream = g_file_create (getGFile(), G_FILE_CREATE_PRIVATE, nullptr, &pError)))
1058  }
1059 
1060  css::uno::Reference < css::io::XOutputStream > xOutput = new ::gio::OutputStream(pOutStream);
1061  copyData( xInputStream, xOutput );
1062 
1063  if (mbTransient)
1064  {
1065  mbTransient = false;
1066  inserted();
1067  }
1068 }
1069 
1070 const GFileCopyFlags DEFAULT_COPYDATA_FLAGS =
1071  static_cast<GFileCopyFlags>(G_FILE_COPY_OVERWRITE|G_FILE_COPY_TARGET_DEFAULT_PERMS);
1072 
1073 void Content::transfer( const css::ucb::TransferInfo& aTransferInfo, const css::uno::Reference< css::ucb::XCommandEnvironment >& xEnv )
1074 {
1075  OUString sDest = m_xIdentifier->getContentIdentifier();
1076  if (!sDest.endsWith("/")) {
1077  sDest += "/";
1078  }
1079  if (aTransferInfo.NewTitle.getLength())
1080  sDest += aTransferInfo.NewTitle;
1081  else
1082  sDest += OUString::createFromAscii(g_file_get_basename(getGFile()));
1083 
1084  GFile *pDest = g_file_new_for_uri(OUStringToOString(sDest, RTL_TEXTENCODING_UTF8).getStr());
1085  GFile *pSource = g_file_new_for_uri(OUStringToOString(aTransferInfo.SourceURL, RTL_TEXTENCODING_UTF8).getStr());
1086 
1087  gboolean bSuccess = false;
1088  GError *pError = nullptr;
1089  if (aTransferInfo.MoveData)
1090  bSuccess = g_file_move(pSource, pDest, G_FILE_COPY_OVERWRITE, nullptr, nullptr, nullptr, &pError);
1091  else
1092  bSuccess = g_file_copy(pSource, pDest, DEFAULT_COPYDATA_FLAGS, nullptr, nullptr, nullptr, &pError);
1093  g_object_unref(pSource);
1094  g_object_unref(pDest);
1095  if (!bSuccess)
1097 }
1098 
1099 css::uno::Sequence< css::ucb::ContentInfo > Content::queryCreatableContentsInfo(
1100  const css::uno::Reference< css::ucb::XCommandEnvironment >& xEnv)
1101 {
1102  if ( isFolder( xEnv ) )
1103  {
1104  css::uno::Sequence< css::ucb::ContentInfo > seq(2);
1105 
1106  // Minimum set of props we really need
1107  css::uno::Sequence< css::beans::Property > props( 1 );
1108  props[0] = css::beans::Property(
1109  "Title",
1110  -1,
1112  css::beans::PropertyAttribute::MAYBEVOID | css::beans::PropertyAttribute::BOUND );
1113 
1114  // file
1115  seq[0].Type = GIO_FILE_TYPE;
1116  seq[0].Attributes = ( css::ucb::ContentInfoAttribute::INSERT_WITH_INPUTSTREAM |
1117  css::ucb::ContentInfoAttribute::KIND_DOCUMENT );
1118  seq[0].Properties = props;
1119 
1120  // folder
1121  seq[1].Type = GIO_FOLDER_TYPE;
1122  seq[1].Attributes = css::ucb::ContentInfoAttribute::KIND_FOLDER;
1123  seq[1].Properties = props;
1124 
1125  return seq;
1126  }
1127  else
1128  {
1129  return css::uno::Sequence< css::ucb::ContentInfo >();
1130  }
1131 }
1132 
1133 css::uno::Sequence< css::ucb::ContentInfo > SAL_CALL Content::queryCreatableContentsInfo()
1134 {
1135  return queryCreatableContentsInfo( css::uno::Reference< css::ucb::XCommandEnvironment >() );
1136 }
1137 
1138 css::uno::Reference< css::ucb::XContent >
1139  SAL_CALL Content::createNewContent( const css::ucb::ContentInfo& Info )
1140 {
1141  bool create_document;
1142  const char *name;
1143 
1144  if ( Info.Type == GIO_FILE_TYPE )
1145  create_document = true;
1146  else if ( Info.Type == GIO_FOLDER_TYPE )
1147  create_document = false;
1148  else
1149  {
1150  SAL_WARN("ucb.ucp.gio", "Failed to create new content '" << Info.Type << "'");
1151  return css::uno::Reference< css::ucb::XContent >();
1152  }
1153 
1154  SAL_INFO("ucb.ucp.gio", "createNewContent (" << create_document << ")");
1155  OUString aURL = m_xIdentifier->getContentIdentifier();
1156 
1157  if ( ( aURL.lastIndexOf( '/' ) + 1 ) != aURL.getLength() )
1158  aURL += "/";
1159 
1160  name = create_document ? "[New_Content]" : "[New_Collection]";
1161  aURL += OUString::createFromAscii( name );
1162 
1163  css::uno::Reference< css::ucb::XContentIdentifier > xId(new ::ucbhelper::ContentIdentifier(aURL));
1164 
1165  try
1166  {
1167  return new ::gio::Content( m_xContext, m_pProvider, xId, !create_document );
1168  } catch ( css::ucb::ContentCreationException & )
1169  {
1170  return css::uno::Reference< css::ucb::XContent >();
1171  }
1172 }
1173 
1174 css::uno::Sequence< css::uno::Type > SAL_CALL Content::getTypes()
1175 {
1176  if ( isFolder( css::uno::Reference< css::ucb::XCommandEnvironment >() ) )
1177  {
1178  static cppu::OTypeCollection s_aFolderCollection
1179  (CPPU_TYPE_REF( css::lang::XTypeProvider ),
1180  CPPU_TYPE_REF( css::lang::XServiceInfo ),
1181  CPPU_TYPE_REF( css::lang::XComponent ),
1182  CPPU_TYPE_REF( css::ucb::XContent ),
1183  CPPU_TYPE_REF( css::ucb::XCommandProcessor ),
1184  CPPU_TYPE_REF( css::beans::XPropertiesChangeNotifier ),
1185  CPPU_TYPE_REF( css::ucb::XCommandInfoChangeNotifier ),
1186  CPPU_TYPE_REF( css::beans::XPropertyContainer ),
1187  CPPU_TYPE_REF( css::beans::XPropertySetInfoChangeNotifier ),
1188  CPPU_TYPE_REF( css::container::XChild ),
1189  CPPU_TYPE_REF( css::ucb::XContentCreator ) );
1190  return s_aFolderCollection.getTypes();
1191  }
1192  else
1193  {
1194  static cppu::OTypeCollection s_aFileCollection
1195  (CPPU_TYPE_REF( css::lang::XTypeProvider ),
1196  CPPU_TYPE_REF( css::lang::XServiceInfo ),
1197  CPPU_TYPE_REF( css::lang::XComponent ),
1198  CPPU_TYPE_REF( css::ucb::XContent ),
1199  CPPU_TYPE_REF( css::ucb::XCommandProcessor ),
1200  CPPU_TYPE_REF( css::beans::XPropertiesChangeNotifier ),
1201  CPPU_TYPE_REF( css::ucb::XCommandInfoChangeNotifier ),
1202  CPPU_TYPE_REF( css::beans::XPropertyContainer ),
1203  CPPU_TYPE_REF( css::beans::XPropertySetInfoChangeNotifier ),
1204  CPPU_TYPE_REF( css::container::XChild ) );
1205 
1206  return s_aFileCollection.getTypes();
1207  }
1208 }
1209 
1210 css::uno::Sequence< css::beans::Property > Content::getProperties(
1211  const css::uno::Reference< css::ucb::XCommandEnvironment > & /*xEnv*/ )
1212 {
1213  static const css::beans::Property aGenericProperties[] =
1214  {
1215  css::beans::Property( "IsDocument",
1217  css::beans::PropertyAttribute::BOUND | css::beans::PropertyAttribute::READONLY ),
1218  css::beans::Property( "IsFolder",
1220  css::beans::PropertyAttribute::BOUND | css::beans::PropertyAttribute::READONLY ),
1221  css::beans::Property( "Title",
1223  css::beans::PropertyAttribute::BOUND ),
1224  css::beans::Property( "IsReadOnly",
1226  css::beans::PropertyAttribute::BOUND | css::beans::PropertyAttribute::READONLY ),
1227  css::beans::Property( "DateCreated",
1229  css::beans::PropertyAttribute::BOUND | css::beans::PropertyAttribute::READONLY ),
1230  css::beans::Property( "DateModified",
1232  css::beans::PropertyAttribute::BOUND | css::beans::PropertyAttribute::READONLY ),
1233  css::beans::Property( "Size",
1235  css::beans::PropertyAttribute::BOUND | css::beans::PropertyAttribute::READONLY ),
1236  css::beans::Property( "IsVolume",
1238  css::beans::PropertyAttribute::BOUND | css::beans::PropertyAttribute::READONLY ),
1239  css::beans::Property( "IsCompactDisc",
1241  css::beans::PropertyAttribute::BOUND | css::beans::PropertyAttribute::READONLY ),
1242  css::beans::Property( "IsRemoveable",
1244  css::beans::PropertyAttribute::BOUND | css::beans::PropertyAttribute::READONLY ),
1245  css::beans::Property( "IsHidden",
1247  css::beans::PropertyAttribute::BOUND | css::beans::PropertyAttribute::READONLY ),
1248  css::beans::Property( "CreatableContentsInfo",
1249  -1, cppu::UnoType<css::uno::Sequence< css::ucb::ContentInfo >>::get(),
1250  css::beans::PropertyAttribute::BOUND | css::beans::PropertyAttribute::READONLY )
1251  };
1252 
1253  const int nProps = SAL_N_ELEMENTS(aGenericProperties);
1254  return css::uno::Sequence< css::beans::Property > ( aGenericProperties, nProps );
1255 }
1256 
1257 css::uno::Sequence< css::ucb::CommandInfo > Content::getCommands( const css::uno::Reference< css::ucb::XCommandEnvironment > & xEnv)
1258 {
1259  static const css::ucb::CommandInfo aCommandInfoTable[] =
1260  {
1261  // Required commands
1262  css::ucb::CommandInfo
1263  ( "getCommandInfo",
1264  -1, cppu::UnoType<void>::get() ),
1265  css::ucb::CommandInfo
1266  ( "getPropertySetInfo",
1267  -1, cppu::UnoType<void>::get() ),
1268  css::ucb::CommandInfo
1269  ( "getPropertyValues",
1270  -1, cppu::UnoType<css::uno::Sequence< css::beans::Property >>::get() ),
1271  css::ucb::CommandInfo
1272  ( "setPropertyValues",
1273  -1, cppu::UnoType<css::uno::Sequence< css::beans::PropertyValue >>::get() ),
1274 
1275  // Optional standard commands
1276  css::ucb::CommandInfo
1277  ( "delete",
1278  -1, cppu::UnoType<bool>::get() ),
1279  css::ucb::CommandInfo
1280  ( "insert",
1282  css::ucb::CommandInfo
1283  ( "open",
1285 
1286  // Folder Only, omitted if not a folder
1287  css::ucb::CommandInfo
1288  ( "transfer",
1290  css::ucb::CommandInfo
1291  ( "createNewContent",
1293  };
1294 
1295  const int nProps = SAL_N_ELEMENTS(aCommandInfoTable);
1296  return css::uno::Sequence< css::ucb::CommandInfo >(aCommandInfoTable, isFolder(xEnv) ? nProps : nProps - 2);
1297 }
1298 
1300 
1301 void SAL_CALL Content::acquire() throw()
1302 {
1303  ContentImplHelper::acquire();
1304 }
1305 
1306 void SAL_CALL Content::release() throw()
1307 {
1308  ContentImplHelper::release();
1309 }
1310 
1311 css::uno::Any SAL_CALL Content::queryInterface( const css::uno::Type & rType )
1312 {
1313  css::uno::Any aRet = cppu::queryInterface( rType, static_cast< css::ucb::XContentCreator * >( this ) );
1314  return aRet.hasValue() ? aRet : ContentImplHelper::queryInterface(rType);
1315 }
1316 
1318 {
1319  return "com.sun.star.comp.GIOContent";
1320 }
1321 
1322 css::uno::Sequence< OUString > SAL_CALL Content::getSupportedServiceNames()
1323 {
1324  css::uno::Sequence<OUString> aSNS { "com.sun.star.ucb.GIOContent" };
1325  return aSNS;
1326 }
1327 
1328 }
1329 
1330 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual ~Content() override
Definition: gio_content.cxx:97
css::uno::Any getBadArgExcept()
css::uno::Reference< css::uno::XComponentContext > m_xContext
OUString sMessage
std::vector< ContentImplHelperRef > ContentRefList
ContentProvider *const m_pProvider
Definition: gio_content.hxx:67
GFile * mpFile
Definition: gio_content.hxx:68
void destroy(bool bDeletePhysical)
static css::lang::IllegalAccessException getReadOnlyException(const css::uno::Reference< css::uno::XInterface > &rContext)
virtual css::uno::Sequence< css::ucb::CommandInfo > getCommands(const css::uno::Reference< css::ucb::XCommandEnvironment > &xEnv) override
virtual css::uno::Sequence< css::ucb::ContentInfo > SAL_CALL queryCreatableContentsInfo() override
css::uno::Any mapGIOError(GError *error)
virtual void SAL_CALL release() override
void getFileInfo(css::uno::Reference< css::ucb::XCommandEnvironment > const &env, GFileInfo **info, bool fail)
virtual void SAL_CALL acquire() override
GFile * getGFile()
void convertToIOException(GError *pError, const css::uno::Reference< css::uno::XInterface > &rContext)
Any SAL_CALL getCaughtException()
static css::util::DateTime getDateFromUnix(time_t t)
virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() override
void notifyPropertiesChange(const css::uno::Sequence< css::beans::PropertyChangeEvent > &evt) const
static void Completed(GObject *source, GAsyncResult *res, gpointer user_data)
bool isFolder(const css::uno::Reference< css::ucb::XCommandEnvironment > &xEnv)
XTYPEPROVIDER_COMMON_IMPL(Content)
std::unique_ptr< GMainContext, detail::MainContextUnref > MainContextRef
Definition: gio_mount.hxx:53
bool exchangeIdentity(const css::uno::Reference< css::ucb::XContentIdentifier > &xNewId)
#define SAL_N_ELEMENTS(arr)
GError * Mount(GFile *pFile)
virtual OUString SAL_CALL getContentType() override
err
GFileInfo * mpInfo
Definition: gio_content.hxx:69
bool feedSink(const css::uno::Reference< css::uno::XInterface > &aSink)
void cancelCommandExecution(const uno::Any &rException, const uno::Reference< ucb::XCommandEnvironment > &xEnv)
Content(const css::uno::Reference< css::uno::XComponentContext > &rxContext, ContentProvider *pProvider, const css::uno::Reference< css::ucb::XContentIdentifier > &Identifier)
Definition: gio_content.cxx:74
MountOperation(const css::uno::Reference< css::ucb::XCommandEnvironment > &xEnv)
css::uno::Reference< css::ucb::XContentIdentifier > m_xIdentifier
static void copyData(const css::uno::Reference< css::io::XInputStream > &xIn, const css::uno::Reference< css::io::XOutputStream > &xOut)
OUString sName
int i
const GFileCopyFlags DEFAULT_COPYDATA_FLAGS
css::uno::Reference< css::beans::XPropertySetInfo > getPropertySetInfo(const css::uno::Reference< css::ucb::XCommandEnvironment > &xEnv, bool bCache=true)
css::uno::Reference< css::ucb::XCommandInfo > getCommandInfo(const css::uno::Reference< css::ucb::XCommandEnvironment > &xEnv, bool bCache=true)
virtual OUString getParentURL() override
sal_uInt16 sal_Char * pName
OUString newName(const OUString &aNewPrefix, const OUString &aOldPrefix, const OUString &old_Name)
Definition: filglob.cxx:170
GMountOperation * ooo_mount_operation_new(ucb::ucp::gio::glib::MainContextRef &&context, const css::uno::Reference< css::ucb::XCommandEnvironment > &rEnv)
Definition: gio_mount.cxx:202
void transfer(const css::ucb::TransferInfo &rTransferInfo, const css::uno::Reference< css::ucb::XCommandEnvironment > &xEnv)
virtual OUString SAL_CALL getImplementationName() override
virtual css::uno::Sequence< css::beans::Property > getProperties(const css::uno::Reference< css::ucb::XCommandEnvironment > &xEnv) override
#define GIO_FILE_TYPE
Definition: gio_content.hxx:53
virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type &rType) override
std::vector< ContentRef > ContentRefList
Definition: gio_content.hxx:85
rtl::Reference< ContentProviderImplHelper > m_xProvider
OString OUStringToOString(const OUString &str, ConnectionSettings const *settings)
GMountOperation * mpAuthentication
css::uno::Reference< css::sdbc::XRow > getPropertyValues(const css::uno::Sequence< css::beans::Property > &rProperties, const css::uno::Reference< css::ucb::XCommandEnvironment > &xEnv)
GFileInfo * getGFileInfo(const css::uno::Reference< css::ucb::XCommandEnvironment > &xEnv, GError **ppError=nullptr)
void queryChildren(ContentRefList &rChildren)
const int TRANSFER_BUFFER_SIZE
virtual css::uno::Reference< css::ucb::XContent > SAL_CALL createNewContent(const css::ucb::ContentInfo &Info) override
#define CPPU_TYPE_REF(T)
#define SAL_INFO(area, stream)
static SolarMutex * get()
ucb::ucp::gio::glib::MainContextRef mContext
const char * name
virtual css::uno::Any SAL_CALL execute(const css::ucb::Command &aCommand, sal_Int32 CommandId, const css::uno::Reference< css::ucb::XCommandEnvironment > &Environment) override
css::uno::Sequence< css::uno::Type > SAL_CALL getTypes()
#define FALSE
#define GIO_FOLDER_TYPE
Definition: gio_content.hxx:54
css::uno::Any convertToException(GError *pError, const css::uno::Reference< css::uno::XInterface > &rContext, bool bThrow)
#define SAL_WARN(area, stream)
bool exchange(const css::uno::Reference< css::ucb::XContentIdentifier > &rNewId)
#define EXCEPT(aExcept)
virtual void SAL_CALL abort(sal_Int32 CommandId) override
sal_Int32 nPos
bool doSetFileInfo(GFileInfo *pNewInfo)
css::uno::Any SAL_CALL queryInterface(const css::uno::Type &rType, Interface1 *p1)
css::uno::Any open(const css::ucb::OpenCommandArgument2 &rArg, const css::uno::Reference< css::ucb::XCommandEnvironment > &xEnv)
css::uno::Sequence< css::uno::Any > setPropertyValues(const css::uno::Sequence< css::beans::PropertyValue > &rValues, const css::uno::Reference< css::ucb::XCommandEnvironment > &xEnv)
void insert(const css::uno::Reference< css::io::XInputStream > &xInputStream, bool bReplaceExisting, const css::uno::Reference< css::ucb::XCommandEnvironment > &xEnv)
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override