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