ownclouddolphinactionplugin.cpp 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /******************************************************************************
  2. * Copyright (C) 2014 by Olivier Goffart <ogoffart@woboq.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, *
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  12. * GNU General Public License for more details. *
  13. * *
  14. * You should have received a copy of the GNU General Public License *
  15. * along with this program; if not, write to the *
  16. * Free Software Foundation, Inc., *
  17. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
  18. ******************************************************************************/
  19. #include <KPluginFactory>
  20. #include <KPluginLoader>
  21. #include <KIOWidgets/kabstractfileitemactionplugin.h>
  22. #include <QtNetwork/QLocalSocket>
  23. #include <KIOCore/kfileitem.h>
  24. #include <KIOCore/KFileItemListProperties>
  25. #include <QtWidgets/QAction>
  26. #include <QtCore/QTimer>
  27. #include "ownclouddolphinpluginhelper.h"
  28. class OwncloudDolphinPluginAction : public KAbstractFileItemActionPlugin
  29. {
  30. public:
  31. explicit OwncloudDolphinPluginAction(QObject* parent, const QList<QVariant>&)
  32. : KAbstractFileItemActionPlugin(parent) { }
  33. QList<QAction*> actions(const KFileItemListProperties& fileItemInfos, QWidget* parentWidget) Q_DECL_OVERRIDE
  34. {
  35. auto helper = OwncloudDolphinPluginHelper::instance();
  36. QList<QUrl> urls = fileItemInfos.urlList();
  37. if (urls.count() != 1 || !helper->isConnected())
  38. return {};
  39. auto url = urls.first();
  40. if (!url.isLocalFile())
  41. return {};
  42. auto localFile = url.toLocalFile();
  43. const auto paths = helper->paths();
  44. if (!std::any_of(paths.begin(), paths.end(), [&](const QString &s) {
  45. return localFile.startsWith(s);
  46. } ))
  47. return {};
  48. auto act = new QAction(parentWidget);
  49. act->setText(helper->shareActionString());
  50. connect(act, &QAction::triggered, this, [localFile, helper] {
  51. helper->sendCommand("SHARE:"+localFile.toUtf8()+"\n");
  52. } );
  53. return { act };
  54. }
  55. };
  56. K_PLUGIN_FACTORY(OwncloudDolphinPluginActionFactory, registerPlugin<OwncloudDolphinPluginAction>();)
  57. K_EXPORT_PLUGIN(OwncloudDolphinPluginActionFactory("ownclouddolhpinpluginaction"))
  58. #include "ownclouddolphinactionplugin.moc"