Skip to content

Commit c420316

Browse files
ein-shvedyorikvanhavre
authored andcommitted
about: handle additional modules in clipboard
We are able to pass extra modules path with command line arguments. Handle such modules when copying about information to clipboard. Change-Id: I158b6ea021cc0a5dfd27693d22f6c56a6bdcd239
1 parent 278ce80 commit c420316

File tree

2 files changed

+45
-21
lines changed

2 files changed

+45
-21
lines changed

src/Gui/DlgAbout.cpp

Lines changed: 43 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,40 @@ void AboutDialog::linkActivated(const QUrl& link)
534534
licenseView->setSource(link);
535535
}
536536

537+
void AboutDialog::addModuleInfo(QTextStream& str, const QString& modPath, bool& firstMod)
538+
{
539+
QFileInfo mod(modPath);
540+
if (mod.isHidden()) { // Ignore hidden directories
541+
return;
542+
}
543+
if (firstMod) {
544+
firstMod = false;
545+
str << "Installed mods: \n";
546+
}
547+
str << " * " << (mod.isDir() ? QDir(modPath).dirName() : mod.fileName());
548+
try {
549+
auto metadataFile =
550+
boost::filesystem::path(mod.absoluteFilePath().toStdString()) / "package.xml";
551+
if (boost::filesystem::exists(metadataFile)) {
552+
App::Metadata metadata(metadataFile);
553+
if (metadata.version() != App::Meta::Version()) {
554+
str << QLatin1String(" ") + QString::fromStdString(metadata.version().str());
555+
}
556+
}
557+
}
558+
catch (const Base::Exception& e) {
559+
auto what = QString::fromUtf8(e.what()).trimmed().replace(QChar::fromLatin1('\n'),
560+
QChar::fromLatin1(' '));
561+
str << " (Malformed metadata: " << what << ")";
562+
}
563+
QFileInfo disablingFile(mod.absoluteFilePath(), QString::fromLatin1("ADDON_DISABLED"));
564+
if (disablingFile.exists()) {
565+
str << " (Disabled)";
566+
}
567+
568+
str << "\n";
569+
}
570+
537571
void AboutDialog::copyToClipboard()
538572
{
539573
QString data;
@@ -680,28 +714,16 @@ void AboutDialog::copyToClipboard()
680714
bool firstMod = true;
681715
if (fs::exists(modDir) && fs::is_directory(modDir)) {
682716
for (const auto& mod : fs::directory_iterator(modDir)) {
683-
auto dirName = mod.path().filename().string();
684-
if (dirName[0] == '.') { // Ignore dot directories
685-
continue;
686-
}
687-
if (firstMod) {
688-
firstMod = false;
689-
str << "Installed mods: \n";
690-
}
691-
str << " * " << QString::fromStdString(mod.path().filename().string());
692-
auto metadataFile = mod.path() / "package.xml";
693-
if (fs::exists(metadataFile)) {
694-
App::Metadata metadata(metadataFile);
695-
if (metadata.version() != App::Meta::Version()) {
696-
str << QLatin1String(" ") + QString::fromStdString(metadata.version().str());
697-
}
698-
}
699-
auto disablingFile = mod.path() / "ADDON_DISABLED";
700-
if (fs::exists(disablingFile)) {
701-
str << " (Disabled)";
702-
}
717+
auto dirName = mod.path().string();
718+
addModuleInfo(str, QString::fromStdString(dirName), firstMod);
719+
}
720+
}
721+
auto additionalModules = config.find("AdditionalModulePaths");
703722

704-
str << "\n";
723+
if (additionalModules != config.end()) {
724+
auto mods = QString::fromStdString(additionalModules->second).split(QChar::fromLatin1(';'));
725+
for (const auto& mod : mods) {
726+
addModuleInfo(str, mod, firstMod);
705727
}
706728
}
707729

src/Gui/DlgAbout.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <QDialog>
2727
#include <QTextBrowser>
2828
#include <Gui/MDIView.h>
29+
#include <qlocale.h>
2930

3031
namespace Gui
3132
{
@@ -88,6 +89,7 @@ class GuiExport AboutDialog: public QDialog
8889
void showCollectionInformation();
8990
void showPrivacyPolicy();
9091
void showOrHideImage(const QRect& rect);
92+
void addModuleInfo(QTextStream& inout_str, const QString& modPath, bool& inout_first);
9193

9294
protected:
9395
QPixmap aboutImage() const;

0 commit comments

Comments
 (0)