License: new class for easier access to license data.

This new class wraps the existing "licenses.h"-header,
but makes it easier to use.

The existing "licenses.h"-header uses static string
literals, which means that if two source files include
the file, both object files will include the string data.

This License file is introduced to avoid that problem,
but also to provide a more Qt-like API, with QStrings
instead of C-style char *s.
This commit is contained in:
Mikkel Krautz 2016-11-24 00:26:17 +01:00
parent cc2b1c7dae
commit 6bb3270865
3 changed files with 91 additions and 2 deletions

50
src/License.cpp Normal file
View File

@ -0,0 +1,50 @@
// Copyright 2005-2016 The Mumble Developers. All rights reserved.
// Use of this source code is governed by a BSD-style license
// that can be found in the LICENSE file at the root of the
// Mumble source tree or at <https://www.mumble.info/LICENSE>.
#include "murmur_pch.h"
#include "License.h"
#include "licenses.h"
QString License::license() {
return QString::fromUtf8(licenseMumble);
}
QString License::authors() {
return QString::fromUtf8(authorsMumble);
}
QList<LicenseInfo> License::thirdPartyLicenses() {
QList<LicenseInfo> licenses;
for (int i = 0; !licenses3rdParties[i].isEmpty(); i++) {
const ThirdPartyLicense *tpl = &licenses3rdParties[i];
LicenseInfo li;
li.name = QString::fromUtf8(tpl->name);
li.url = QString::fromUtf8(tpl->url);
li.license = QString::fromUtf8(tpl->license);
licenses << li;
}
return licenses;
}
QString License::printableThirdPartyLicenseInfo() {
QString output;
QList<LicenseInfo> thirdPartyLicenses = License::thirdPartyLicenses();
foreach (LicenseInfo li, thirdPartyLicenses) {
QString header = QString::fromLatin1("%1 (%2)\n").arg(li.name).arg(li.url);
QString headerHorizLine = QString::fromLatin1("-").repeated(header.size()) + QLatin1String("\n");
output.append(headerHorizLine);
output.append(header);
output.append(headerHorizLine);
output.append(QLatin1String("\n"));
output.append(li.license);
output.append(QLatin1String("\n\n"));
}
return output;
}

39
src/License.h Normal file
View File

@ -0,0 +1,39 @@
// Copyright 2005-2016 The Mumble Developers. All rights reserved.
// Use of this source code is governed by a BSD-style license
// that can be found in the LICENSE file at the root of the
// Mumble source tree or at <https://www.mumble.info/LICENSE>.
#ifndef MUMBLE_LICENSE_H_
#define MUMBLE_LICENSE_H_
#include <QString>
#include <QList>
/// LicenseInfo represents license information
/// for a third-party library used by Mumble.
struct LicenseInfo {
/// The name of the third-party library.
QString name;
/// A URL for the website of the third-party library.
QString url;
/// The license text for the third-party library.
QString license;
};
/// The License class contains static helpers for
/// getting Mumble license/author information.
class License {
public:
/// Get the Mumble license text (the LICENSE file)
static QString license();
/// Get the Mumble authors list (the AUTHORS file)
static QString authors();
/// Get a list of license information for Mumble's
/// third-party libraries.
static QList<LicenseInfo> thirdPartyLicenses();
/// Get a human-readable, ready-to-print combination
/// of all of Mumble's third-party license information.
static QString printableThirdPartyLicenseInfo();
};
#endif

View File

@ -14,8 +14,8 @@ CONFIG += qt thread debug_and_release warn_on
DEFINES *= MUMBLE_VERSION_STRING=$$VERSION
INCLUDEPATH += $$PWD . ../mumble_proto
VPATH += $$PWD
HEADERS *= ACL.h Channel.h CryptState.h Connection.h Group.h HTMLFilter.h User.h Net.h OSInfo.h Timer.h SSL.h Version.h SSLCipherInfo.h SSLCipherInfoTable.h licenses.h
SOURCES *= ACL.cpp Group.cpp Channel.cpp Connection.cpp HTMLFilter.cpp User.cpp Timer.cpp CryptState.cpp OSInfo.cpp Net.cpp SSL.cpp Version.cpp SSLCipherInfo.cpp
HEADERS *= ACL.h Channel.h CryptState.h Connection.h Group.h HTMLFilter.h User.h Net.h OSInfo.h Timer.h SSL.h Version.h SSLCipherInfo.h SSLCipherInfoTable.h licenses.h License.h
SOURCES *= ACL.cpp Group.cpp Channel.cpp Connection.cpp HTMLFilter.cpp User.cpp Timer.cpp CryptState.cpp OSInfo.cpp Net.cpp SSL.cpp Version.cpp SSLCipherInfo.cpp License.cpp
LIBS *= -lmumble_proto
# Note: Protobuf generates into its own directory so we can mark it as a
# system include folder for unix. Otherwise the generated code creates