summaryrefslogtreecommitdiff
path: root/revision_utils.cpp
blob: d91db8351b41374655b40c23b93f46ba31264497 (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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#include "revision_utils.hpp"

#include <cstring>

#include <QCoreApplication>
#include <QRegularExpression>
#include <QSysInfo>

#include "scs_version.h"

namespace
{
  QString revision_extract_number (QString const& s)
  {
    QString revision;

    // try and match a number (hexadecimal allowed)
    QRegularExpression re {R"(^[$:]\w+: (r?[\da-f]+[^$]*)\$$)"};
    auto match = re.match (s);
    if (match.hasMatch ())
      {
        revision = match.captured (1);
      }
    return revision;
  }
}

QString revision (QString const& scs_rev_string)
{
  //  return "251203";
  QString result;
  auto revision_from_scs = revision_extract_number (scs_rev_string);

#if defined (CMAKE_BUILD)
  QString scs_info {":Rev: " SCS_VERSION_STR " $"};

  auto revision_from_scs_info = revision_extract_number (scs_info);
  if (!revision_from_scs_info.isEmpty ())
    {
      // we managed to get the revision number from svn info etc.
      result = revision_from_scs_info;
    }
  else if (!revision_from_scs.isEmpty ())
    {
      // fall back to revision passed in if any
      result = revision_from_scs;
    }
  else
    {
      // match anything
      QRegularExpression re {R"(^[$:]\w+: ([^$]*)\$$)"};
      auto match = re.match (scs_info);
      if (match.hasMatch ())
        {
          result = match.captured (1);
        }
    }
#else
  if (!revision_from_scs.isEmpty ())
    {
      // not CMake build so all we have is revision passed
      result = revision_from_scs;
    }
#endif
  return result.trimmed ();
}

QString display_revision ()
{
  auto build_revision = revision ();

#if defined (CMAKE_BUILD) && defined (WSJT_SOURCE_REVISION)
  QString source_revision {WSJT_SOURCE_REVISION};
  if (!source_revision.isEmpty ())
    {
      source_revision = source_revision.left (6);
      if (source_revision != build_revision.left (6))
        {
          return QString {"(source %1, build %2)"}.arg (
            source_revision,
            build_revision.isEmpty () ? QString {"unavailable"} : build_revision);
        }
    }
#endif

  if (build_revision.isEmpty ())
    {
      return QString {"(revision unavailable)"};
    }

  return QString {"(revision %1)"}.arg (build_revision);
}

QString version (bool include_patch)
{
#if defined (CMAKE_BUILD)
  QString v {TO_STRING__ (PROJECT_VERSION_MAJOR) "." TO_STRING__ (PROJECT_VERSION_MINOR)};
  if (include_patch)
    {
      v += "." TO_STRING__ (PROJECT_VERSION_PATCH) + QString {BUILD_TYPE_REVISION};
    }
#else
  QString v {"Not for Release"};
#endif
  return v;
}

QString program_title (QString const& revision)
{
  QString id {QCoreApplication::applicationName () + "   v" + QCoreApplication::applicationVersion ()};
  return id + " " + revision ;
}

QString branded_program_title (QString const& revision)
{
  // applicationName() itself must stay plain ASCII -- it also names the jt9 shared-memory key and settings/lock/temp paths.
  QString name {QCoreApplication::applicationName ()};
  auto const instance_separator = name.indexOf (" - ");
  name.insert (instance_separator < 0 ? name.size () : instance_separator, "™");
  QString id {name + "   v" + QCoreApplication::applicationVersion ()};
  return id + " " + revision ;
}

QString http_user_agent ()
{
  // See User-Agent format definition https://www.rfc-editor.org/rfc/rfc9110#name-user-agent
  QString const platform {
    "(" + QSysInfo::prettyProductName () + "; "
    + QSysInfo::productType () + " " + QSysInfo::productVersion () + "; "
    + QSysInfo::currentCpuArchitecture () + "; "
    + QString {"rv:%1"}.arg (QSysInfo::kernelVersion ()) + ")"};

  return QString {"WSJT-X/" + version () + "_" + revision ()}.simplified () + " " + platform;
}

QString copyright_notice_text ()
{
  return QCoreApplication::translate (
    "main",
    "If you make fair use of any part of WSJT-X, MAP65, QMAP, or our "
    "associated utility programs under terms of the GNU General Public "
    "License, you must display the following copyright notice prominently "
    "in your derivative work:\n\n"
    "\"The algorithms, source code, look-and-feel of WSJT-X, MAP65, QMAP, "
    "and related programs, and protocol specifications for the modes "
    "FSK441, FST4, FST4W, FT4, FT8, ISCAT, JT4, JT6M, JT9, JT65, JTMS, "
    "JTTY, MSK144, QRA64, Q65, and WSPR are Copyright (C) 2001-2026 by one "
    "or more of the following authors: Joseph Taylor, K1JT; Bill "
    "Somerville, G4WJS; Steven Franke, K9AN; Nico Palermo, IV3NWV; Greg "
    "Beam, KI7MT; Michael Black, W9MDB; Edson Pereira, PY2SDR; Philip Karn, "
    "KA9Q; Uwe Risse, DG2YCB; Brian Moran, N9ADG; Roger Rehr, W3SZ; John "
    "Nelson, G4KLA; Charlie Suckling, DL3WDG; Terrell Deppe, KJ5HST; David "
    "Christle, KD0BTO; and other members of the WSJT™ Development Team.\"");
}