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