fileprovider_mac.mm 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*
  2. * Copyright (C) 2022 by Claudio Cambra <claudio.cambra@nextcloud.com>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful, but
  10. * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  11. * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  12. * for more details.
  13. */
  14. #import <Foundation/Foundation.h>
  15. #include <QLoggingCategory>
  16. #include "configfile.h"
  17. #include "fileprovider.h"
  18. namespace OCC {
  19. Q_LOGGING_CATEGORY(lcMacFileProvider, "nextcloud.gui.macfileprovider", QtInfoMsg)
  20. namespace Mac {
  21. FileProvider* FileProvider::_instance = nullptr;
  22. FileProvider::FileProvider(QObject * const parent)
  23. : QObject(parent)
  24. {
  25. Q_ASSERT(!_instance);
  26. if (!fileProviderAvailable()) {
  27. qCInfo(lcMacFileProvider) << "File provider system is not available on this version of macOS.";
  28. deleteLater();
  29. return;
  30. } else if (!ConfigFile().macFileProviderModuleEnabled()) {
  31. qCInfo(lcMacFileProvider) << "File provider module is not enabled in application config.";
  32. deleteLater();
  33. return;
  34. }
  35. qCInfo(lcMacFileProvider) << "Initialising file provider domain manager.";
  36. _domainManager = std::make_unique<FileProviderDomainManager>(new FileProviderDomainManager(this));
  37. if (_domainManager) {
  38. qCDebug(lcMacFileProvider()) << "Initialized file provider domain manager";
  39. }
  40. qCDebug(lcMacFileProvider) << "Initialising file provider socket server.";
  41. _socketServer = std::make_unique<FileProviderSocketServer>(new FileProviderSocketServer(this));
  42. if (_socketServer) {
  43. qCDebug(lcMacFileProvider) << "Initialised file provider socket server.";
  44. }
  45. }
  46. FileProvider *FileProvider::instance()
  47. {
  48. if (!fileProviderAvailable()) {
  49. qCInfo(lcMacFileProvider) << "File provider system is not available on this version of macOS.";
  50. return nullptr;
  51. } else if (!ConfigFile().macFileProviderModuleEnabled()) {
  52. qCInfo(lcMacFileProvider) << "File provider module is not enabled in application config.";
  53. return nullptr;
  54. }
  55. if (!_instance) {
  56. _instance = new FileProvider();
  57. }
  58. return _instance;
  59. }
  60. FileProvider::~FileProvider()
  61. {
  62. _instance = nullptr;
  63. }
  64. bool FileProvider::fileProviderAvailable()
  65. {
  66. if (@available(macOS 11.0, *)) {
  67. return true;
  68. }
  69. return false;
  70. }
  71. } // namespace Mac
  72. } // namespace OCC