From 6bb3270865990c74ae50773ff828aba393d2b90d Mon Sep 17 00:00:00 2001 From: Mikkel Krautz Date: Thu, 24 Nov 2016 00:26:17 +0100 Subject: [PATCH] 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. --- src/License.cpp | 50 +++++++++++++++++++++++++++++++++++++++++++++++++ src/License.h | 39 ++++++++++++++++++++++++++++++++++++++ src/mumble.pri | 4 ++-- 3 files changed, 91 insertions(+), 2 deletions(-) create mode 100644 src/License.cpp create mode 100644 src/License.h diff --git a/src/License.cpp b/src/License.cpp new file mode 100644 index 000000000..e530e77b6 --- /dev/null +++ b/src/License.cpp @@ -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 . + +#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 License::thirdPartyLicenses() { + QList 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 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; +} diff --git a/src/License.h b/src/License.h new file mode 100644 index 000000000..ed3992562 --- /dev/null +++ b/src/License.h @@ -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 . + +#ifndef MUMBLE_LICENSE_H_ +#define MUMBLE_LICENSE_H_ + +#include +#include + +/// 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 thirdPartyLicenses(); + /// Get a human-readable, ready-to-print combination + /// of all of Mumble's third-party license information. + static QString printableThirdPartyLicenseInfo(); +}; + +#endif diff --git a/src/mumble.pri b/src/mumble.pri index e87d40e5a..66aa96da8 100644 --- a/src/mumble.pri +++ b/src/mumble.pri @@ -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