2013-10-03 19:04:55 +04:00
|
|
|
/*
|
|
|
|
* Copyright (C) by Dominik Schmidt <dev@dominik-schmidt.de>
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef SOCKETAPI_H
|
|
|
|
#define SOCKETAPI_H
|
|
|
|
|
2014-07-11 02:31:24 +04:00
|
|
|
#include "syncfileitem.h"
|
2016-03-24 20:20:49 +03:00
|
|
|
#include "syncfilestatus.h"
|
2018-04-06 18:13:29 +03:00
|
|
|
#include "sharedialog.h" // for the ShareDialogStartPage
|
|
|
|
#include "common/syncjournalfilerecord.h"
|
2013-10-03 19:04:55 +04:00
|
|
|
|
2015-06-15 15:51:11 +03:00
|
|
|
#if defined(Q_OS_MAC)
|
|
|
|
#include "socketapisocket_mac.h"
|
|
|
|
#else
|
|
|
|
#include <QLocalServer>
|
|
|
|
typedef QLocalServer SocketApiServer;
|
|
|
|
#endif
|
|
|
|
|
2013-10-03 19:04:55 +04:00
|
|
|
class QUrl;
|
|
|
|
class QLocalSocket;
|
|
|
|
class QStringList;
|
|
|
|
|
2014-11-10 00:34:07 +03:00
|
|
|
namespace OCC {
|
2013-10-03 19:04:55 +04:00
|
|
|
|
2014-10-13 17:38:57 +04:00
|
|
|
class SyncFileStatus;
|
|
|
|
class Folder;
|
2017-01-11 20:27:22 +03:00
|
|
|
class SocketListener;
|
2014-10-13 17:38:57 +04:00
|
|
|
|
2015-06-29 19:56:09 +03:00
|
|
|
/**
|
|
|
|
* @brief The SocketApi class
|
|
|
|
* @ingroup gui
|
2015-06-26 18:07:47 +03:00
|
|
|
*/
|
2013-10-03 19:04:55 +04:00
|
|
|
class SocketApi : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2018-11-11 12:56:22 +03:00
|
|
|
explicit SocketApi(QObject *parent = nullptr);
|
2013-10-03 19:04:55 +04:00
|
|
|
virtual ~SocketApi();
|
|
|
|
|
2014-07-15 15:34:32 +04:00
|
|
|
public slots:
|
2015-05-12 16:50:38 +03:00
|
|
|
void slotUpdateFolderView(Folder *f);
|
2014-07-25 14:20:38 +04:00
|
|
|
void slotUnregisterPath(const QString &alias);
|
|
|
|
void slotRegisterPath(const QString &alias);
|
2017-09-20 12:48:13 +03:00
|
|
|
void broadcastStatusPushMessage(const QString &systemPath, SyncFileStatus fileStatus);
|
2014-09-03 18:12:21 +04:00
|
|
|
|
|
|
|
signals:
|
2018-04-06 18:13:29 +03:00
|
|
|
void shareCommandReceived(const QString &sharePath, const QString &localPath, ShareDialogStartPage startPage);
|
2014-09-03 18:12:21 +04:00
|
|
|
|
2013-10-03 19:04:55 +04:00
|
|
|
private slots:
|
2014-06-02 14:08:06 +04:00
|
|
|
void slotNewConnection();
|
2013-10-03 19:04:55 +04:00
|
|
|
void onLostConnection();
|
2017-01-11 20:27:22 +03:00
|
|
|
void slotSocketDestroyed(QObject *obj);
|
2014-06-02 14:08:06 +04:00
|
|
|
void slotReadSocket();
|
2013-10-03 19:04:55 +04:00
|
|
|
|
2018-04-06 18:13:29 +03:00
|
|
|
static void copyUrlToClipboard(const QString &link);
|
|
|
|
static void emailPrivateLink(const QString &link);
|
|
|
|
static void openPrivateLink(const QString &link);
|
2017-09-15 15:24:34 +03:00
|
|
|
|
2013-10-03 19:04:55 +04:00
|
|
|
private:
|
2018-04-06 18:13:29 +03:00
|
|
|
// Helper structure for getting information on a file
|
|
|
|
// based on its local path - used for nearly all remote
|
|
|
|
// actions.
|
|
|
|
struct FileData
|
|
|
|
{
|
|
|
|
static FileData get(const QString &localFile);
|
|
|
|
SyncFileStatus syncFileStatus() const;
|
|
|
|
SyncJournalFileRecord journalRecord() const;
|
|
|
|
|
|
|
|
Folder *folder;
|
|
|
|
QString localPath;
|
|
|
|
QString folderRelativePath;
|
|
|
|
QString accountRelativePath;
|
|
|
|
};
|
|
|
|
|
2017-01-11 20:27:22 +03:00
|
|
|
void broadcastMessage(const QString &msg, bool doWait = false);
|
2013-10-03 19:04:55 +04:00
|
|
|
|
2018-04-06 18:13:29 +03:00
|
|
|
// opens share dialog, sends reply
|
|
|
|
void processShareRequest(const QString &localFile, SocketListener *listener, ShareDialogStartPage startPage);
|
|
|
|
|
2017-01-11 20:27:22 +03:00
|
|
|
Q_INVOKABLE void command_RETRIEVE_FOLDER_STATUS(const QString &argument, SocketListener *listener);
|
|
|
|
Q_INVOKABLE void command_RETRIEVE_FILE_STATUS(const QString &argument, SocketListener *listener);
|
2013-10-03 19:04:55 +04:00
|
|
|
|
2017-01-11 20:27:22 +03:00
|
|
|
Q_INVOKABLE void command_VERSION(const QString &argument, SocketListener *listener);
|
2014-08-27 14:02:47 +04:00
|
|
|
|
2017-01-11 20:27:22 +03:00
|
|
|
Q_INVOKABLE void command_SHARE_MENU_TITLE(const QString &argument, SocketListener *listener);
|
2017-05-10 10:37:10 +03:00
|
|
|
|
|
|
|
// The context menu actions
|
|
|
|
Q_INVOKABLE void command_SHARE(const QString &localFile, SocketListener *listener);
|
2018-04-06 18:13:29 +03:00
|
|
|
Q_INVOKABLE void command_MANAGE_PUBLIC_LINKS(const QString &localFile, SocketListener *listener);
|
|
|
|
Q_INVOKABLE void command_COPY_PUBLIC_LINK(const QString &localFile, SocketListener *listener);
|
2017-05-10 10:37:10 +03:00
|
|
|
Q_INVOKABLE void command_COPY_PRIVATE_LINK(const QString &localFile, SocketListener *listener);
|
|
|
|
Q_INVOKABLE void command_EMAIL_PRIVATE_LINK(const QString &localFile, SocketListener *listener);
|
2018-01-23 18:38:47 +03:00
|
|
|
Q_INVOKABLE void command_OPEN_PRIVATE_LINK(const QString &localFile, SocketListener *listener);
|
2017-05-10 10:37:10 +03:00
|
|
|
|
2018-04-06 18:13:29 +03:00
|
|
|
// Fetch the private link and call targetFun
|
|
|
|
void fetchPrivateLinkUrlHelper(const QString &localFile, const std::function<void(const QString &url)> &targetFun);
|
|
|
|
|
2018-01-19 16:02:46 +03:00
|
|
|
/** Sends translated/branded strings that may be useful to the integration */
|
2017-05-10 10:37:10 +03:00
|
|
|
Q_INVOKABLE void command_GET_STRINGS(const QString &argument, SocketListener *listener);
|
|
|
|
|
2018-04-06 18:13:29 +03:00
|
|
|
// Sends the context menu options relating to sharing to listener
|
|
|
|
void sendSharingContextMenuOptions(const FileData &fileData, SocketListener *listener);
|
|
|
|
|
2018-01-18 17:17:29 +03:00
|
|
|
/** Send the list of menu item. (added in version 1.1)
|
|
|
|
* argument is a list of files for which the menu should be shown, separated by '\x1e'
|
|
|
|
* Reply with GET_MENU_ITEMS:BEGIN
|
2018-01-19 16:02:46 +03:00
|
|
|
* followed by several MENU_ITEM:[Action]:[flag]:[Text]
|
|
|
|
* If flag contains 'd', the menu should be disabled
|
2018-01-18 17:17:29 +03:00
|
|
|
* and ends with GET_MENU_ITEMS:END
|
|
|
|
*/
|
|
|
|
Q_INVOKABLE void command_GET_MENU_ITEMS(const QString &argument, SocketListener *listener);
|
|
|
|
|
2015-03-13 20:30:45 +03:00
|
|
|
QString buildRegisterPathMessage(const QString &path);
|
2015-01-23 18:09:38 +03:00
|
|
|
|
2016-04-28 23:43:53 +03:00
|
|
|
QSet<QString> _registeredAliases;
|
2017-01-11 20:27:22 +03:00
|
|
|
QList<SocketListener> _listeners;
|
2015-06-15 15:51:11 +03:00
|
|
|
SocketApiServer _localServer;
|
2013-10-03 19:04:55 +04:00
|
|
|
};
|
|
|
|
}
|
|
|
|
#endif // SOCKETAPI_H
|