2015-01-05 19:23:09 +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 *
|
|
|
|
******************************************************************************/
|
|
|
|
|
2015-10-19 09:57:25 +03:00
|
|
|
#include <KOverlayIconPlugin>
|
2015-01-05 19:23:09 +03:00
|
|
|
#include <KPluginFactory>
|
|
|
|
#include <QtNetwork/QLocalSocket>
|
2015-09-07 21:59:30 +03:00
|
|
|
#include <KIOCore/kfileitem.h>
|
2015-09-11 13:50:07 +03:00
|
|
|
#include <QTimer>
|
|
|
|
#include "ownclouddolphinpluginhelper.h"
|
2015-01-05 19:23:09 +03:00
|
|
|
|
|
|
|
class OwncloudDolphinPlugin : public KOverlayIconPlugin
|
|
|
|
{
|
2015-12-02 15:14:15 +03:00
|
|
|
Q_PLUGIN_METADATA(IID "com.owncloud.ovarlayiconplugin" FILE "ownclouddolphinoverlayplugin.json")
|
2015-01-05 19:23:09 +03:00
|
|
|
Q_OBJECT
|
2015-10-19 09:57:25 +03:00
|
|
|
|
2015-01-05 19:23:09 +03:00
|
|
|
typedef QHash<QByteArray, QByteArray> StatusMap;
|
|
|
|
StatusMap m_status;
|
|
|
|
|
|
|
|
public:
|
2015-09-11 13:50:07 +03:00
|
|
|
|
|
|
|
OwncloudDolphinPlugin() {
|
|
|
|
auto helper = OwncloudDolphinPluginHelper::instance();
|
|
|
|
QObject::connect(helper, &OwncloudDolphinPluginHelper::commandRecieved,
|
|
|
|
this, &OwncloudDolphinPlugin::slotCommandRecieved);
|
2015-01-05 19:23:09 +03:00
|
|
|
}
|
|
|
|
|
2015-09-11 13:50:07 +03:00
|
|
|
QStringList getOverlays(const QUrl& url) override {
|
|
|
|
auto helper = OwncloudDolphinPluginHelper::instance();
|
|
|
|
if (!helper->isConnected())
|
|
|
|
return QStringList();
|
2015-01-05 19:23:09 +03:00
|
|
|
if (!url.isLocalFile())
|
|
|
|
return QStringList();
|
|
|
|
const QByteArray localFile = url.toLocalFile().toUtf8();
|
|
|
|
|
2015-11-21 14:14:03 +03:00
|
|
|
helper->sendCommand(QByteArray("RETRIEVE_FILE_STATUS:" + localFile + "\n"));
|
2015-01-05 19:23:09 +03:00
|
|
|
|
|
|
|
StatusMap::iterator it = m_status.find(localFile);
|
|
|
|
if (it != m_status.constEnd()) {
|
|
|
|
return overlaysForString(*it);
|
|
|
|
}
|
|
|
|
return QStringList();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2015-09-11 13:50:07 +03:00
|
|
|
QStringList overlaysForString(const QByteArray &status) {
|
2015-01-05 19:23:09 +03:00
|
|
|
QStringList r;
|
|
|
|
if (status.startsWith("NOP"))
|
|
|
|
return r;
|
|
|
|
|
|
|
|
if (status.startsWith("OK"))
|
2015-12-04 16:40:15 +03:00
|
|
|
r << "vcs-normal";
|
2015-01-05 19:23:09 +03:00
|
|
|
if (status.startsWith("SYNC") || status.startsWith("NEW"))
|
2015-12-04 16:40:15 +03:00
|
|
|
r << "vcs-update-required";
|
2015-10-19 16:53:40 +03:00
|
|
|
if (status.startsWith("IGNORE") || status.startsWith("WARN"))
|
2015-12-04 16:40:15 +03:00
|
|
|
r << "vcs-locally-modified-unstaged";
|
2015-10-19 16:53:40 +03:00
|
|
|
if (status.startsWith("ERROR"))
|
2015-12-04 16:40:15 +03:00
|
|
|
r << "vcs-conflicting";
|
2015-01-05 19:23:09 +03:00
|
|
|
|
|
|
|
if (status.contains("+SWM"))
|
|
|
|
r << "document-share";
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2015-09-11 13:50:07 +03:00
|
|
|
void slotCommandRecieved(const QByteArray &line) {
|
|
|
|
|
|
|
|
QList<QByteArray> tokens = line.split(':');
|
|
|
|
if (tokens.count() != 3)
|
|
|
|
return;
|
|
|
|
if (tokens[0] != "STATUS" && tokens[0] != "BROADCAST")
|
|
|
|
return;
|
|
|
|
if (tokens[2].isEmpty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
const QByteArray name = tokens[2];
|
|
|
|
QByteArray &status = m_status[name]; // reference to the item in the hash
|
|
|
|
if (status == tokens[1])
|
|
|
|
return;
|
|
|
|
status = tokens[1];
|
|
|
|
|
|
|
|
emit overlaysChanged(QUrl::fromLocalFile(QString::fromUtf8(name)), overlaysForString(status));
|
2015-01-05 19:23:09 +03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-10-19 16:22:27 +03:00
|
|
|
#include "ownclouddolphinoverlayplugin.moc"
|