11 #include "ui_VuoMetadataEditor.h"
21 map<QString, QString> VuoMetadataEditor::descriptionForLicense;
22 const QString VuoMetadataEditor::otherLicenseTitle =
"Other";
23 const QString VuoMetadataEditor::placeholderIconText =
"Icon for Exported App";
29 QDialog(parent, flags),
32 this->composition = composition;
35 ui->tabWidget->setCurrentIndex(0);
38 ui->descriptionDetailsLabel->setText(
"<style>a{color:#0099a9;}</style>"
39 + tr(
"What is the purpose of this composition? You can use <a href='%1'>Markdown</a> formatting.")
40 .arg(
"https://daringfireball.net/projects/markdown/basics"));
45 populateLicenseInfo();
48 connect(ui->name, &QLineEdit::textEdited,
this, &VuoMetadataEditor::updatePlaceholderTexts);
51 connect(ui->licenseTitle, &QComboBox::currentTextChanged,
this, &VuoMetadataEditor::updateLicenseFields);
52 connect(ui->licenseText, &QTextEdit::textChanged,
this, &VuoMetadataEditor::recordCustomLicenseText);
53 connect(ui->licenseLink, &QLineEdit::textChanged,
this, &VuoMetadataEditor::recordCustomLicenseText);
55 connect(ui->homepageLink, &QLineEdit::editingFinished,
this, &VuoMetadataEditor::sanitizeURL);
56 connect(ui->documentationLink, &QLineEdit::editingFinished,
this, &VuoMetadataEditor::sanitizeURL);
59 ui->iconFrame->setVisible(! isCodeEditor);
60 ui->iconLabel->setVisible(! isCodeEditor);
61 ui->bundleIdentifier->setVisible(! isCodeEditor);
62 ui->bundleIdentifierLabel->setVisible(! isCodeEditor);
63 ui->bundleIdentifierDetailsLabel->setVisible(! isCodeEditor);
64 ui->fxPlugGroup->setVisible(! isCodeEditor);
65 ui->fxPlugGroupLabel->setVisible(! isCodeEditor);
66 ui->fxPlugGroupDetailsLabel->setVisible(! isCodeEditor);
69 ui->categories->setVisible(isCodeEditor);
70 ui->categoriesLabel->setVisible(isCodeEditor);
71 ui->categoriesDetailsLabel->setVisible(isCodeEditor);
87 if (!iconURL.isEmpty())
89 string relativeDir, file, ext;
91 string iconFileName = file;
99 QString iconAbsolutePath = compositionDir.filePath(QDir(relativeDir.c_str()).filePath(iconFileName.c_str()));
101 QImageReader reader(iconAbsolutePath);
102 if (reader.canRead())
104 QIcon icon(iconAbsolutePath);
105 QPixmap pixmap = icon.pixmap(icon.actualSize(ui->iconLabel->size()-QSize(4,4)));
106 ui->iconLabel->setPixmap(pixmap);
109 ui->iconLabel->setText(placeholderIconText);
113 ui->iconLabel->setText(placeholderIconText);
118 ui->description->setFocus();
119 ui->description->moveCursor(QTextCursor::End);
123 ui->keywords->setText(QString::fromStdString(keywords));
124 ui->keywords->moveCursor(QTextCursor::End);
128 ui->copyright->moveCursor(QTextCursor::End);
132 QPair<QString, QString> licenseFields = getLicenseTextAndLinkFromDescription(license);
133 auto licenseFieldsHTTPS = QPair<QString, QString>(licenseFields.first.replace(
"http:",
"https:"),
134 licenseFields.second.replace(
"http:",
"https:"));
136 bool foundLicenseMatchInStandardOptions =
false;
137 for (
int i = 0; i < ui->licenseTitle->count() && !foundLicenseMatchInStandardOptions; ++i)
139 QString currentLicenseTitle = ui->licenseTitle->itemText(i);
140 QString currentLicenseDescription = descriptionForLicense[currentLicenseTitle];
141 QPair<QString, QString> currentLicenseFields = getLicenseTextAndLinkFromDescription(currentLicenseDescription);
143 if (((licenseFields.first == currentLicenseFields.first) && (licenseFields.second == currentLicenseFields.second))
144 || ((licenseFieldsHTTPS.first == currentLicenseFields.first) && (licenseFieldsHTTPS.second == currentLicenseFields.second)))
146 ui->licenseTitle->setCurrentText(currentLicenseTitle);
147 foundLicenseMatchInStandardOptions =
true;
150 if (!foundLicenseMatchInStandardOptions)
152 descriptionForLicense[otherLicenseTitle] = license;
153 ui->licenseTitle->setCurrentText(otherLicenseTitle);
156 updateLicenseFields(ui->licenseTitle->currentText());
172 ui->categories->setText(QString::fromStdString(categories));
173 ui->categories->moveCursor(QTextCursor::End);
175 updatePlaceholderTexts();
180 VuoMetadataEditor::~VuoMetadataEditor()
188 void VuoMetadataEditor::updatePlaceholderTexts()
193 ui->version->setPlaceholderText(
"1.0");
194 ui->homepageLink->setPlaceholderText(
"http://");
195 ui->documentationLink->setPlaceholderText(
"http://");
205 return QString(
"com.")
206 .append(
static_cast<VuoEditor *
>(qApp)->getUserName().c_str())
216 return QString(
static_cast<VuoEditor *
>(qApp)->getUserName().c_str())
217 .append(
"'s Plugins");
227 metadata->
setName( ui->name->text().toStdString() );
228 metadata->
setVersion( ui->version->text().toStdString() );
229 metadata->
setDescription( ui->description->toPlainText().toStdString() );
230 metadata->
setKeywords( commaSeparatedListToStdVector(ui->keywords->toPlainText()) );
231 metadata->
setCopyright( ui->copyright->toPlainText().toStdString() );
232 metadata->
setLicense( getLicense().toStdString() );
233 metadata->
setIconURL( iconURL.toStdString() );
234 metadata->
setHomepageURL( ui->homepageLink->text().toStdString() );
237 metadata->
setFxPlugGroup( ui->fxPlugGroup->text().toStdString() );
238 metadata->
setCategories( commaSeparatedListToStdVector(ui->categories->toPlainText()) );
246 QString VuoMetadataEditor::getLicense()
248 QString licenseText = ui->licenseText->toPlainText();
249 QString licenseLink = ui->licenseLink->text();
251 QString fullLicenseString = licenseText;
252 if (!licenseText.isEmpty() && !licenseLink.isEmpty())
253 fullLicenseString.append(
" ");
254 if (!licenseLink.isEmpty())
256 fullLicenseString.append(
"For more information, see ");
257 fullLicenseString.append(licenseLink);
258 fullLicenseString.append(
" .");
261 return fullLicenseString;
267 vector<string> VuoMetadataEditor::commaSeparatedListToStdVector(
const QString &listText)
271 QStringList list = listText.split(
',', QString::SkipEmptyParts);
272 for (
const QString &item : list)
273 vec.push_back(item.trimmed().toStdString());
283 const QMimeData *mimeData =
event->mimeData();
286 if (mimeData->hasFormat(
"text/uri-list"))
288 QList<QUrl> urls = mimeData->urls();
289 if (urls.size() == 1)
291 QString iconAbsolutePath = urls[0].path();
292 QImageReader reader(iconAbsolutePath);
293 if (reader.canRead())
301 event->setDropAction(Qt::IgnoreAction);
310 const QMimeData *mimeData =
event->mimeData();
311 if (mimeData->hasFormat(
"text/uri-list"))
315 QList<QUrl> urls = mimeData->urls();
317 if (urls.size() == 1)
319 QString iconAbsolutePath = urls[0].path();
320 string dir, file, ext;
323 QImageReader reader(iconAbsolutePath);
324 if (reader.canRead())
326 iconURL = compositionDir.relativeFilePath(iconAbsolutePath);
328 QIcon icon(iconAbsolutePath);
329 QPixmap pixmap = icon.pixmap(icon.actualSize(ui->iconLabel->size()-QSize(4,4)));
330 ui->iconLabel->setPixmap(pixmap);
346 if (ui->iconLabel->hasFocus() && ((event->key() == Qt::Key_Backspace) ||
347 (event->key() == Qt::Key_Delete)))
350 ui->iconLabel->setText(placeholderIconText);
354 QDialog::keyPressEvent(event);
362 void VuoMetadataEditor::populateLicenseInfo()
364 const QString CC_A =
"Creative Commons: Attribution";
365 const QString CC_A_ND =
"Creative Commons: Attribution + No Derivatives";
366 const QString CC_A_NC =
"Creative Commons: Attribution + Noncommercial";
367 const QString CC_A_NC_ND =
"Creative Commons: Attribution + Noncommercial + No Derivatives";
368 const QString CC_A_NC_SA =
"Creative Commons: Attribution + Noncommercial + Share Alike";
369 const QString CC_A_SA =
"Creative Commons: Attribution + Share Alike";
370 const QString MIT =
"MIT";
371 const QString BSD =
"BSD";
372 const QString PublicDomain =
"Public Domain";
374 descriptionForLicense[CC_A] =
"This composition may be modified and distributed under the terms of the Creative Commons: Attribution (CC BY) License. For more information, see https://creativecommons.org/licenses/by/4.0/ .";
375 descriptionForLicense[CC_A_ND] =
"This composition may be distributed under the terms of the Creative Commons: Attribution + No Derivatives (CC BY-ND) License. For more information, see https://creativecommons.org/licenses/by-nd/4.0/ .";
376 descriptionForLicense[CC_A_NC] =
"This composition may be modified and distributed under the terms of the Creative Commons: Attribution + Noncommercial (CC BY-NC) License. For more information, see https://creativecommons.org/licenses/by-nc/4.0/ .";
377 descriptionForLicense[CC_A_NC_ND] =
"This composition may be distributed under the terms of the Creative Commons: Attribution + Noncommercial + No Derivatives (CC BY-NC-ND) License. For more information, see https://creativecommons.org/licenses/by-nc-nd/4.0/ .";
378 descriptionForLicense[CC_A_NC_SA] =
"This composition may be modified and distributed under the terms of the Creative Commons: Attribution + Noncommercial + Share Alike (CC BY-NC-SA) License. For more information, see https://creativecommons.org/licenses/by-nc-sa/4.0/ .";
379 descriptionForLicense[CC_A_SA] =
"This composition may be modified and distributed under the terms of the Creative Commons: Attribution + Share Alike (CC BY-SA) License. For more information, see https://creativecommons.org/licenses/by-sa/4.0/ .";
380 descriptionForLicense[MIT] =
"This composition may be modified and distributed under the terms of the MIT License. For more information, see https://opensource.org/licenses/MIT .";
381 descriptionForLicense[BSD] =
"This composition may be modified and distributed under the terms of the BSD License. For more information, see https://opensource.org/licenses/BSD-3-Clause .";
382 descriptionForLicense[PublicDomain] =
"This composition is in the public domain and may be modified and distributed. For more information, see https://creativecommons.org/publicdomain/zero/1.0/ .";
383 descriptionForLicense[otherLicenseTitle] =
"";
385 QList<QString> licenseOptions = QList<QString>() << CC_A << CC_A_ND << CC_A_NC << CC_A_NC_ND << CC_A_NC_SA << CC_A_SA << MIT << BSD << PublicDomain << otherLicenseTitle;
386 foreach (QString licenseOption, licenseOptions)
387 ui->licenseTitle->addItem(licenseOption);
393 QPair<QString, QString> VuoMetadataEditor::getLicenseTextAndLinkFromDescription(QString description)
395 QRegExp descriptionTemplate(
"^((.*)\\s+)?For more information, see ([^\\s]*)\\s*\\.\\s*$");
396 if (!descriptionTemplate.exactMatch(description))
397 return QPair<QString, QString>(description,
"");
399 QString text = description;
400 QString link = description;
401 text.replace(descriptionTemplate,
"\\2");
402 link.replace(descriptionTemplate,
"\\3");
404 return QPair<QString, QString>(text, link);
410 void VuoMetadataEditor::updateLicenseFields(QString licenseTitle)
412 QString description = descriptionForLicense[licenseTitle];
413 QPair<QString, QString> licenseFields = getLicenseTextAndLinkFromDescription(description);
414 ui->licenseText->setText(licenseFields.first);
415 ui->licenseLink->setText(licenseFields.second);
417 bool otherLicenseSelected = (licenseTitle == otherLicenseTitle);
418 ui->licenseText->setReadOnly(!otherLicenseSelected);
419 ui->licenseLink->setReadOnly(!otherLicenseSelected);
421 if (otherLicenseSelected)
423 ui->licenseText->setFocus();
424 ui->licenseText->moveCursor(QTextCursor::End);
433 void VuoMetadataEditor::recordCustomLicenseText()
435 if (ui->licenseTitle->currentText() == otherLicenseTitle)
436 descriptionForLicense[otherLicenseTitle] = getLicense();
443 void VuoMetadataEditor::sanitizeURL()
446 if (sender && !sender->text().isEmpty() && !sender->text().contains(
"://"))
447 sender->setText(QString(
"http://").append(sender->text()));