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

internallinkwidget.cpp « gui « src - github.com/nextcloud/desktop.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: e8c65005fe5f455686460f9705e378d8d335ddbe (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
80
81
82
83
84
85
86
/*
 * Copyright (C) 2022 by Claudio Cambra <claudio.cambra@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.
 */

#include "internallinkwidget.h"
#include "accountstate.h"
#include "folderman.h"
#include "theme.h"

#include "QProgressIndicator.h"
#include <QClipboard>

namespace OCC {

Q_LOGGING_CATEGORY(lcInternalLink, "nextcloud.gui.internallink", QtInfoMsg)

InternalLinkWidget::InternalLinkWidget(const QString &localPath,
    QWidget *parent)
    : QWidget(parent)
    , _localPath(localPath)
{
    _ui->setupUi(this);

    const auto folder = FolderMan::instance()->folderForPath(_localPath);
    const auto folderRelativePath = _localPath.mid(folder->cleanPath().length() + 1);
    const auto serverRelativePath = QDir(folder->remotePath()).filePath(folderRelativePath);

    const auto bindLinkSlot = [this](QString link) { slotLinkFetched(link); };

    fetchPrivateLinkUrl(
        folder->accountState()->account(),
        serverRelativePath,
        {},
        this,
        bindLinkSlot
    );

    _ui->copyInternalLinkButton->setEnabled(false);
    _ui->internalLinkProgressIndicator->setVisible(true);
    _ui->internalLinkProgressIndicator->startAnimation();

    connect(_ui->copyInternalLinkButton, &QPushButton::clicked, this, &InternalLinkWidget::slotCopyInternalLink);
}

void InternalLinkWidget::slotLinkFetched(const QString &url)
{
    _internalUrl = url;
    _ui->copyInternalLinkButton->setEnabled(true);
    _ui->internalLinkProgressIndicator->setVisible(false);
    _ui->internalLinkProgressIndicator->stopAnimation();
    _ui->horizontalSpacer->changeSize(0, 0);
    _ui->horizontalSpacer_2->changeSize(0, 0);
}

void InternalLinkWidget::slotCopyInternalLink() const
{
    QApplication::clipboard()->setText(_internalUrl);
}

void InternalLinkWidget::setupUiOptions()
{
    customizeStyle();
}

void InternalLinkWidget::slotStyleChanged()
{
    customizeStyle();
}

void InternalLinkWidget::customizeStyle()
{
    _ui->copyInternalLinkButton->setIcon(Theme::createColorAwareIcon(":/client/theme/copy.svg"));
    _ui->internalLinkIconLabel->setPixmap(Theme::createColorAwarePixmap(":/client/theme/external.svg"));
}

}