Welcome to mirror list, hosted at ThFree Co, Russian Federation.

shellextensionsserver.h « gui « src - github.com/nextcloud/desktop.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 491d4cfe0d2981fc0fbbc9179936202877609054 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*
 * Copyright (C) by Oleksandr Zolotov <alex@nextcloud.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.
 */

#pragma once

#include <QObject>
#include <QLocalServer>
#include <QMutex>
#include <QSize>
#include <QVariant>

class QJsonDocument;
class QLocalSocket;

namespace OCC {
class ShellExtensionsServer : public QObject
{
    struct ThumbnailRequestInfo
    {
        QString path;
        QSize size;
        QString folderAlias;

        [[nodiscard]] bool isValid() const { return !path.isEmpty() && !size.isEmpty() && !folderAlias.isEmpty(); }
    };

    struct CustomStateRequestInfo
    {
        QString path;
        QString folderAlias;

        bool isValid() const { return !path.isEmpty() && !folderAlias.isEmpty(); }
    };

    Q_OBJECT
public:
    ShellExtensionsServer(QObject *parent = nullptr);
    ~ShellExtensionsServer() override;

    static QString getFetchThumbnailPath();

    void setIsSharedInvalidationInterval(qint64 interval);

signals:
    void fetchSharesJobFinished(const QString &folderAlias);

private:
    void sendJsonMessageWithVersion(QLocalSocket *socket, const QVariantMap &message);
    void sendEmptyDataAndCloseSession(QLocalSocket *socket);
    void closeSession(QLocalSocket *socket);
    void processCustomStateRequest(QLocalSocket *socket, const CustomStateRequestInfo &customStateRequestInfo);
    void processThumbnailRequest(QLocalSocket *socket, const ThumbnailRequestInfo &thumbnailRequestInfo);

    void parseCustomStateRequest(QLocalSocket *socket, const QVariantMap &message);
    void parseThumbnailRequest(QLocalSocket *socket, const QVariantMap &message);

private slots:
    void slotNewConnection();
    void slotSharesFetched(const QJsonDocument &reply);
    void slotSharesFetchError(int statusCode, const QString &message);

private:
    QLocalServer _localServer;
    QStringList _runningFetchShareJobsForPaths;
    QMap<qintptr, QMetaObject::Connection> _customStateSocketConnections;
    qint64 _isSharedInvalidationInterval = 0;
};
} // namespace OCC