Skip to content
Snippets Groups Projects
Config.h 4.2 KiB
Newer Older
  • Learn to ignore specific revisions
  • // SPDX-FileCopyrightText: Nheko Contributors
    
    Nicolas Werner's avatar
    Nicolas Werner committed
    //
    // SPDX-License-Identifier: GPL-3.0-or-later
    
    
    Nicolas Werner's avatar
    Nicolas Werner committed
    #include <QRegularExpression>
    
    #include <QString>
    
    
    // clazy:excludeall=non-pod-global-static
    
    
    // Non-theme app configuration. Layouts, fonts spacing etc.
    //
    // Font sizes are in pixels.
    
    namespace conf {
    
    Nicolas Werner's avatar
    Nicolas Werner committed
    inline constexpr int WIDGET_MARGIN  = 20;
    inline constexpr int WIDGET_SPACING = 15;
    
    Nicolas Werner's avatar
    Nicolas Werner committed
    inline constexpr auto LABEL_MEDIUM_SIZE_RATIO = 1.3;
    
    namespace strings {
    
    Nicolas Werner's avatar
    Nicolas Werner committed
    inline const QString url_html = QStringLiteral("<a href=\"\\1\">\\1</a>");
    inline const QRegularExpression url_regex(
    
    Nicolas Werner's avatar
    Nicolas Werner committed
      // match an unquoted URL
      []() {
          const auto general_unicode = QStringLiteral(
            R"((?:[^\x{0}-\x{7f}\p{Cc}\s\p{P}]|[\x{2010}\x{2011}\x{2012}\x{2013}\x{2014}\x{2015}]))");
          const auto protocol                   = QStringLiteral(R"((?:[Hh][Tt][Tt][Pp][Ss]?))");
          const auto unreserved_subdelims_colon = QStringLiteral(R"([a-zA-Z0-9\-._~!$&'()*+,;=:])");
          const auto pct_enc                    = QStringLiteral(R"((?:%[[:xdigit:]]{2}))");
          const auto userinfo =
            "(?:" + unreserved_subdelims_colon + "*(?:" + pct_enc + unreserved_subdelims_colon + "*)*)";
          const auto dec_octet =
            QStringLiteral(R"((?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9]))");
          const auto ipv4_addr = "(?:" + dec_octet + R"((?:\.)" + dec_octet + "){3})";
          const auto h16       = QStringLiteral(R"((?:[[:xdigit:]]{1,4}))");
          const auto ls32      = "(?:" + h16 + ":" + h16 + "|" + ipv4_addr + ")";
          // clang-format off
    
    Nicolas Werner's avatar
    Nicolas Werner committed
            const auto ipv6_addr = "(?:"
                                   "(?:" + h16 + ":){6}" + ls32
                                   + "|" "::(?:" + h16 + ":){5}" + ls32
                                   + "|" + h16 + "?::(?:" + h16 + ":){4}" + ls32
                                   + "|" "(?:" + h16 + "(?::" + h16 + "){0,1})?::(?:" + h16 + ":){3}" + ls32
                                   + "|" "(?:" + h16 + "(?::" + h16 + "){0,2})?::(?:" + h16 + ":){2}" + ls32
                                   + "|" "(?:" + h16 + "(?::" + h16 + "){0,3})?::" + h16 + ":" + ls32
                                   + "|" "(?:" + h16 + "(?::" + h16 + "){0,4})?::" + ls32
                                   + "|" "(?:" + h16 + "(?::" + h16 + "){0,5})?::" + h16
                                   + "|" "(?:" + h16 + "(?::" + h16 + "){0,6})?::"
                                   ")";
    
    Nicolas Werner's avatar
    Nicolas Werner committed
          // clang-format on
          const auto ipvfuture  = R"((?:v[[:xdigit:]]+\.)" + unreserved_subdelims_colon + "+)";
          const auto ip_literal = R"((?:\[(?:)" + ipv6_addr + "|" + ipvfuture + R"()\]))";
          const auto host_alnum = "(?:[a-zA-Z0-9]|" + general_unicode + ")";
          const auto host_label = "(?:" + host_alnum + "+(?:-+" + host_alnum + "+)*)";
          const auto hostname   = "(?:" + host_label + R"((?:\.)" + host_label + R"()*\.?))";
          const auto host       = "(?:" + hostname + "|" + ip_literal + ")";
          const auto path = R"((?:/((?:[a-zA-Z0-9\-._~!$&'*+,;=:@/]|)" + pct_enc + R"(|\((?-1)\)|)" +
                            general_unicode + ")*))";
          const auto query = R"(((?:[a-zA-Z0-9\-._~!$&'*+,;=:@/?\\{}]|)" + pct_enc +
                             R"(|\((?-1)\)|\[(?-1)\]|)" + general_unicode + ")*)";
    
          // explicitly allow # in fragments because of matrix.to urls generated by some clients...
          const auto fragment = R"(((?:[a-zA-Z0-9\-._~!$&'*+,;=:@/?\\{}#]|)" + pct_enc +
                                R"(|\((?-1)\)|\[(?-1)\]|)" + general_unicode + ")*)";
    
    Nicolas Werner's avatar
    Nicolas Werner committed
          return R"((?<!["'\w])(?>()" + protocol + "://" + "(?:" + userinfo + "@)?" + host +
                 "(?::[0-9]+)?" + path +
                 "?"
                 R"((?:\?)" +
                 query +
                 ")?"
                 R"((?:#)" +
                 fragment +
                 ")?"
                 "(?<![.!?,;:'])"
                 R"())(?!["']))";
      }(),
      QRegularExpression::UseUnicodePropertiesOption);
    
    // A matrix link to be converted back to markdown
    
    Nicolas Werner's avatar
    Nicolas Werner committed
    inline const QRegularExpression
    
    Nicolas Werner's avatar
    Nicolas Werner committed
      matrixToLink(QStringLiteral(R"(<a href=\"(https://matrix.to/#/.*?)\">(.*?)</a>)"));
    
    // Window geometry.
    
    namespace window {
    
    Nicolas Werner's avatar
    Nicolas Werner committed
    inline constexpr int height = 600;
    inline constexpr int width  = 1066;
    
    Nicolas Werner's avatar
    Nicolas Werner committed
    inline constexpr int minHeight = 340;
    inline constexpr int minWidth  = 340;
    
    } // namespace window
    
    
    } // namespace conf