2015-09-10 12:45:19 +03:00
|
|
|
/******************************************************************************
|
|
|
|
* Copyright (C) 2014 by Olivier Goffart <ogoffart@woboq.com *
|
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU General Public License as published by *
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or *
|
|
|
|
* (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* This program is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
* GNU General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU General Public License *
|
|
|
|
* along with this program; if not, write to the *
|
|
|
|
* Free Software Foundation, Inc., *
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
#include <KPluginFactory>
|
|
|
|
#include <KPluginLoader>
|
|
|
|
#include <KIOWidgets/kabstractfileitemactionplugin.h>
|
|
|
|
#include <QtNetwork/QLocalSocket>
|
|
|
|
#include <KIOCore/kfileitem.h>
|
|
|
|
#include <KIOCore/KFileItemListProperties>
|
|
|
|
#include <QtWidgets/QAction>
|
2015-09-11 13:50:07 +03:00
|
|
|
#include <QtCore/QTimer>
|
|
|
|
#include "ownclouddolphinpluginhelper.h"
|
2015-09-10 12:45:19 +03:00
|
|
|
|
|
|
|
class OwncloudDolphinPluginAction : public KAbstractFileItemActionPlugin
|
|
|
|
{
|
|
|
|
public:
|
2015-09-11 13:50:07 +03:00
|
|
|
explicit OwncloudDolphinPluginAction(QObject* parent, const QList<QVariant>&)
|
|
|
|
: KAbstractFileItemActionPlugin(parent) { }
|
2015-09-10 12:45:19 +03:00
|
|
|
|
|
|
|
QList<QAction*> actions(const KFileItemListProperties& fileItemInfos, QWidget* parentWidget) Q_DECL_OVERRIDE
|
|
|
|
{
|
2015-09-11 13:50:07 +03:00
|
|
|
auto helper = OwncloudDolphinPluginHelper::instance();
|
2015-09-10 12:45:19 +03:00
|
|
|
QList<QUrl> urls = fileItemInfos.urlList();
|
2015-09-11 13:50:07 +03:00
|
|
|
if (urls.count() != 1 || !helper->isConnected())
|
2015-09-10 12:45:19 +03:00
|
|
|
return {};
|
|
|
|
|
|
|
|
auto url = urls.first();
|
|
|
|
if (!url.isLocalFile())
|
|
|
|
return {};
|
|
|
|
auto localFile = url.toLocalFile();
|
|
|
|
|
2015-09-11 13:50:07 +03:00
|
|
|
const auto paths = helper->paths();
|
|
|
|
if (!std::any_of(paths.begin(), paths.end(), [&](const QString &s) {
|
2015-09-10 12:45:19 +03:00
|
|
|
return localFile.startsWith(s);
|
|
|
|
} ))
|
|
|
|
return {};
|
|
|
|
|
|
|
|
auto act = new QAction(parentWidget);
|
2015-09-11 13:50:07 +03:00
|
|
|
act->setText(helper->shareActionString());
|
|
|
|
connect(act, &QAction::triggered, this, [localFile, helper] {
|
2015-11-21 14:14:03 +03:00
|
|
|
helper->sendCommand(QByteArray("SHARE:"+localFile.toUtf8()+"\n"));
|
2015-09-10 12:45:19 +03:00
|
|
|
} );
|
|
|
|
return { act };
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
K_PLUGIN_FACTORY(OwncloudDolphinPluginActionFactory, registerPlugin<OwncloudDolphinPluginAction>();)
|
|
|
|
|
2015-10-19 16:22:27 +03:00
|
|
|
#include "ownclouddolphinactionplugin.moc"
|