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

MacPasteboard.cpp « core « src - github.com/keepassxreboot/keepassxc.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 98dc6f7ab37ffd6c530702fb47088c77a1d59294 (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
87
88
89
90
91
92
93
94
/*
 *  Copyright (C) 2017 KeePassXC Team <team@keepassxc.org>
 *
 *  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 or (at your option)
 *  version 3 of the License.
 *
 *  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, see <http://www.gnu.org/licenses/>.
 */

#include "MacPasteboard.h"

QString MacPasteboard::convertorName() { return QLatin1String("MacPasteboard"); }

QString MacPasteboard::flavorFor(const QString& mimetype) {
    if (mimetype == QLatin1String("text/plain")) {
        return QLatin1String("public.utf8-plain-text");
    } else if (mimetype == QLatin1String("application/x-nspasteboard-concealed-type")) {
        return QLatin1String("org.nspasteboard.ConcealedType");
    }

    int i = mimetype.indexOf(QLatin1String("charset="));

    if (i >= 0) {
        QString cs(mimetype.mid(i + 8).toLower());
        i = cs.indexOf(QLatin1Char(';'));

        if (i >= 0) {
            cs = cs.left(i);
        }

        if (cs == QLatin1String("system")) {
            return QLatin1String("public.utf8-plain-text");
        } else if (cs == QLatin1String("iso-10646-ucs-2") ||
                   cs == QLatin1String("utf16")) {
            return QLatin1String("public.utf16-plain-text");
        }
    }
    return QString();
}

QString MacPasteboard::mimeFor(QString flavor) {
    if (flavor == QLatin1String("public.utf8-plain-text"))
        return QLatin1String("text/plain");
    if (flavor == QLatin1String("org.nspasteboard.ConcealedType"))
        return QLatin1String("application/x-nspasteboard-concealed-type");
    if (flavor == QLatin1String("public.utf16-plain-text"))
        return QLatin1String("text/plain;charset=utf16");
    return QString();
}

bool MacPasteboard::canConvert(const QString& mimetype, QString flavor) {
    Q_UNUSED(mimetype);
    Q_UNUSED(flavor);
    return true;
}

QVariant MacPasteboard::convertToMime(const QString& mimetype, QList<QByteArray> data, QString flavor) {
    if (data.count() > 1)
        qWarning("QMime::convertToMime: Cannot handle multiple member data");
    const QByteArray& firstData = data.first();
    QVariant ret;
    if (flavor == QLatin1String("public.utf8-plain-text")) {
        ret = QString::fromUtf8(firstData);
    } else if (flavor == QLatin1String("org.nspasteboard.ConcealedType")) {
        ret = QString::fromUtf8(firstData);
    } else if (flavor == QLatin1String("public.utf16-plain-text")) {
        ret = QTextCodec::codecForName("UTF-16")->toUnicode(firstData);
    } else {
        qWarning("QMime::convertToMime: unhandled mimetype: %s",
                 qPrintable(mimetype));
    }
    return ret;
}

QList<QByteArray> MacPasteboard::convertFromMime(const QString&, QVariant data, QString flavor) {
    QList<QByteArray> ret;
    QString string = data.toString();
    if (flavor == QLatin1String("public.utf8-plain-text"))
        ret.append(string.toUtf8());
    else if (flavor == QLatin1String("org.nspasteboard.ConcealedType"))
        ret.append(string.toUtf8());
    else if (flavor == QLatin1String("public.utf16-plain-text"))
        ret.append(QTextCodec::codecForName("UTF-16")->fromUnicode(string));
    return ret;
}