common.h 3.26 KB
Newer Older
1
/*
2
    SPDX-License-Identifier: GPL-2.0-or-later
3

4
5
    SPDX-FileCopyrightText: 2004 Peter Simonsson <psn@linux.se>
    SPDX-FileCopyrightText: 2006-2008 Eike Hein <hein@kde.org>
6
7
8
9
10
*/

#ifndef COMMON_H
#define COMMON_H

Urs Wolfer's avatar
Urs Wolfer committed
11
#include <QByteArray>
12
#include <QHash>
13
#include <QRegularExpression>
14
#include <QStringList>
15

16
17
18
19
class QString;

namespace Konversation
{
20
21
    static QRegularExpression ircMarkupsRegExp(QStringLiteral("[\\o{0000}-\\o{0037}]"));

22
    static QRegExp colorRegExp(QStringLiteral("((\003([0-9]|0[0-9]|1[0-5])(,([0-9]|0[0-9]|1[0-5])|)|\017)|\x02|\x03|\x09|\x13|\x15|\x16|\x1d|\x1f)"));
23
24
25
26
27
28

//     static QRegExp colorOnlyRegExp(QStringLiteral("(\003([0-9]|0[0-9]|1[0-5]|)(,([0-9]|0[0-9]|1[0-5])|,|)|\017)"));

    static QRegularExpression urlPattern(QStringLiteral("\\b((?:(?:([a-z][\\w\\.-]+:/{1,3})|www\\d{0,3}[.]|[a-z0-9.\\-]+[.][a-z]{2,4}/)(?:[^\\s()<>]+|\\(([^\\s()<>]+|(\\([^\\s()<>]+\\)))*\\))+(?:\\(([^\\s()<>]+|(\\([^\\s()<>]+\\)))*\\)|\\}\\]|[^\\s`!()\\[\\]{};:'\".,<>?%1%2%3%4%5%6])|[a-z0-9.\\-+_]+@[a-z0-9.\\-]+[.][a-z]{1,5}[^\\s/`!()\\[\\]{};:'\".,<>?%1%2%3%4%5%6]))").arg(QChar(0x00AB)).arg(QChar(0x00BB)).arg(QChar(0x201C)).arg(QChar(0x201D)).arg(QChar(0x2018)).arg(QChar(0x2019)));

    static QRegularExpression chanExp(QStringLiteral("(^|\\s|^\"|\\s\"|,|'|\\(|\\:|!|@|%|\\+)(#[^,\\s;\\)\\:\\/\\(\\<\\>]*[^.,\\s;\\)\\:\\/\\(\"\''\\<\\>?%1%2%3%4%5%6])").arg(QChar(0x00AB)).arg(QChar(0x00BB)).arg(QChar(0x201C)).arg(QChar(0x201D)).arg(QChar(0x2018)).arg(QChar(0x2019)));
29

30
31
32
33
    enum TabNotifyType
    {
        tnfNick,
        tnfHighlight,
34
        tnfPrivate,
Eike Hein's avatar
Eike Hein committed
35
        tnfNormal,
36
        tnfSystem,
37
38
39
        tnfControl,
        tnfNone
    };
40
41
42
43
44
45

    enum ConnectionState
    {
        SSNeverConnected,
        SSDeliberatelyDisconnected,
        SSInvoluntarilyDisconnected,
46
        SSScheduledToConnect,
47
48
49
50
        SSConnecting,
        SSConnected
    };

Eike Hein's avatar
Eike Hein committed
51
    enum ConnectionFlag
52
53
54
55
56
    {
        SilentlyReuseConnection,
        PromptToReuseConnection,
        CreateNewConnection
    };
57
58
59
60

    struct TextUrlData
    {
        QList<QPair<int, int> > urlRanges;
61
62
63
64
65
66
67
        QStringList fixedUrls;
    };

    struct TextChannelData
    {
        QList<QPair<int, int> > channelRanges;
        QStringList fixedChannels;
68
69
70
71
72
    };

    QString removeIrcMarkup(const QString& text);
    QString doVarExpansion(const QString& text);
    QString replaceFormattingCodes(const QString& text);
73
    QString replaceIRCMarkups(const QString& text);
Bernd Buschinski's avatar
Bernd Buschinski committed
74
75
76
77
    inline bool hasIRCMarkups(const QString& text)
    {
        return text.contains(ircMarkupsRegExp);
    }
78
79

    QList<QPair<int, int> > getUrlRanges(const QString& text);
80
81
82
    QList<QPair<int, int> > getChannelRanges(const QString& text);
    TextUrlData extractUrlData(const QString& string, bool doUrlFixup = true);
    TextChannelData extractChannelData(const QString& text, bool doChannelFixup = true);
83
    bool isUrl(const QString& text);
84
    QString extractColorCodes(const QString& text);
85
86
87
88

    bool isUtf8(const QByteArray& text);
    uint colorForNick(const QString& nickname);

89
    static QHash<QChar,QString> m_modesHash;
90
    QHash<QChar,QString> getChannelModesHash();
91
92
93
94
95

    QString sterilizeUnicode(const QString& s);
    QString& sterilizeUnicode(QString& s);
    QStringList& sterilizeUnicode(QStringList& list);
    QStringList sterilizeUnicode(const QStringList& inVal);
Dirk Mueller's avatar
Dirk Mueller committed
96
}
97
#endif