ScannedFileItem *
ScannedFileItem::create(SourceFile const &scannedFile) {
  auto item = new ScannedFileItem{ scannedFile, QStringList{
      QFileInfo{scannedFile.m_fileName}.fileName(),
      to_qs(format_timecode(scannedFile.m_playlistDuration, 0)),
      to_qs(format_file_size(scannedFile.m_playlistSize)),
    }};

  item->setTextAlignment(1, Qt::AlignRight | Qt::AlignVCenter);
  item->setTextAlignment(2, Qt::AlignRight | Qt::AlignVCenter);

  return item;
}
Example #2
0
void
Track::setDefaults() {
  auto &settings = Settings::get();

  if (isAudio() && settings.m_setAudioDelayFromFileName)
    m_delay = extractAudioDelayFromFileName();

  if (settings.m_disableAVCompression && (isVideo() || isAudio()))
    m_compression = CompNone;

  m_forcedTrackFlag        = m_properties[Q("forced_track")] == "1";
  m_defaultTrackFlagWasSet = m_properties[Q("default_track")] == "1";
  m_name                   = m_properties[Q("track_name")];
  m_cropping               = m_properties[Q("cropping")];
  if (!m_properties[Q("stereo_mode")].isEmpty())
    m_stereoscopy = m_properties[Q("stereo_mode")].toUInt() + 1;

  auto idx = map_to_iso639_2_code(to_utf8(m_properties[Q("language")]), true);
  if (0 <= idx)
    m_language = to_qs(iso639_languages[idx].iso639_2_code);

  QRegExp re_displayDimensions{"^(\\d+)x(\\d+)$"};
  if (-1 != re_displayDimensions.indexIn(m_properties[Q("display_dimensions")])) {
    m_displayWidth  = re_displayDimensions.cap(1);
    m_displayHeight = re_displayDimensions.cap(2);
  }
}
Example #3
0
QString
Settings::exeWithPath(QString const &exe) {
#if defined(SYS_WINDOWS)
  auto path = bfs::path{ to_utf8(exe) };
  if (path.is_absolute())
    return exe;

  return to_qs((mtx::sys::get_installation_path() / path).string());
#else  // defined(SYS_WINDOWS)
  return exe;
#endif // defined(SYS_WINDOWS)
}
void
SelectPlaylistDialog::onScannedFileSelected(QTreeWidgetItem *current,
                                            QTreeWidgetItem *) {
  auto selectedItem = static_cast<ScannedFileItem *>(current);
  if (!selectedItem)
    return;

  auto const &file = *selectedItem->m_file;

  ui->duration->setText(to_qs(format_timecode(file.m_playlistDuration, 0)));
  ui->size->setText(to_qs(format_file_size(file.m_playlistSize)));
  ui->numberOfChapters->setText(QString::number(file.m_playlistChapters));

  ui->tracks->setSortingEnabled(false);
  ui->playlistItems->setSortingEnabled(false);

  ui->tracks->clear();
  ui->playlistItems->clear();

  auto newItems = QList<QTreeWidgetItem *>{};
  for (auto const &track : file.m_tracks)
    newItems << TrackItem::create(*track);

  ui->tracks->insertTopLevelItems(0, newItems);

  newItems.clear();
  for (auto const &playlistFile : file.m_playlistFiles)
    newItems << createPlaylistItemItem(playlistFile);

  ui->playlistItems->insertTopLevelItems(0, newItems);

  ui->tracks->setSortingEnabled(true);
  ui->tracks->sortItems(ui->tracks->sortColumn(), Qt::AscendingOrder);

  ui->playlistItems->setSortingEnabled(true);
  ui->playlistItems->sortItems(ui->playlistItems->sortColumn(), Qt::AscendingOrder);

  Util::resizeViewColumnsToContents(ui->tracks);
  Util::resizeViewColumnsToContents(ui->playlistItems);
}
Example #5
0
QHash<QString, QString>
FileIdentifier::parseProperties(QString const &line)
  const {
  QHash<QString, QString> properties;

  QRegExp re{"\\[(.+)\\]"};
  if (-1 == re.indexIn(line))
    return properties;

  for (auto &pair : re.cap(1).split(QRegExp{"\\s+"}, QString::SkipEmptyParts)) {
    QRegExp re{"(.+):(.+)"};
    if (-1 == re.indexIn(pair))
      continue;

    auto key = to_qs(unescape(to_utf8(re.cap(1))));
    if (!properties[key].isEmpty())
      properties[key] += Q("\t");
    properties[key] += to_qs(unescape(to_utf8(re.cap(2))));
  }

  return properties;
}
QStringList const &
FileTypeFilter::get() {
  if (!s_filter.isEmpty())
    return s_filter;

  auto &file_types = file_type_t::get_supported();

  std::map<QString, bool> all_extensions_map;
  for (auto &file_type : file_types) {
    auto extensions = to_qs(file_type.extensions).split(" ");
    QStringList extensions_full;

    for (auto &extension : extensions) {
      all_extensions_map[extension] = true;
      extensions_full << QString{"*.%1"}.arg(extension);

#if !defined(SYS_WINDOWS)
      auto extension_upper = extension.toUpper();
      all_extensions_map[extension_upper] = true;
      if (extension_upper != extension)
        extensions_full << QString("*.%1").arg(extension_upper);
#endif  // !SYS_WINDOWS
    }

    s_filter << QString("%1 (%2)").arg(to_qs(file_type.title)).arg(extensions_full.join(" "));
  }

  QStringList all_extensions;
  for (auto &extension : all_extensions_map)
    all_extensions << QString("*.%1").arg(extension.first);

  std::sort(s_filter.begin(), s_filter.end());

  s_filter.push_front(Q("%1 (*)").arg(QY("All files")));
  s_filter.push_front(Q("%1 (%2)").arg(QY("All supported media files")).arg(all_extensions.join(" ")));

  return s_filter;
}
void
AvailableUpdateInfoDialog::setChangeLogContent(QString const &content) {
  auto html = QStringList{};
  html << Q("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">"
            "<html><head><meta name=\"qrichtext\" content=\"1\" />"
            "<style type=\"text/css\">"
            "p, li { white-space: pre-wrap; }\n"
            "</style>"
            "</head><body>");

  html << Q("<h1><a href=\"%1\">MKVToolNix ChangeLog</a></h1>").arg(to_qs(MTX_CHANGELOG_URL).toHtmlEscaped());

  html << content;

  html << Q("</body></html>");

  ui->changeLog->setHtml(html.join(Q("")));
}
Example #8
0
void
SourceFileModel::setItemsFromSourceFile(QList<QStandardItem *> const &items,
                                        SourceFile *sourceFile)
  const {
  auto info = QFileInfo{sourceFile->m_fileName};

  items[0]->setText(info.fileName());
  items[1]->setText(sourceFile->isAdditionalPart() ? QY("(additional part)") : sourceFile->container());
  items[2]->setText(to_qs(format_file_size(sourceFile->isPlaylist() ? sourceFile->m_playlistSize : info.size())));
  items[3]->setText(info.path());

  items[0]->setData(reinterpret_cast<quint64>(sourceFile), Util::SourceFileRole);
  items[0]->setIcon(  sourceFile->isAdditionalPart() ? m_additionalPartIcon
                    : sourceFile->isAppended()       ? m_addedIcon
                    :                                  m_normalIcon);

  items[2]->setTextAlignment(Qt::AlignRight | Qt::AlignVCenter);
}
QList<QStandardItem *>
SourceFileModel::createRow(SourceFile *sourceFile)
  const {
  auto items = QList<QStandardItem *>{};
  auto info  = QFileInfo{sourceFile->m_fileName};

  items << new QStandardItem{info.fileName()};
  items << new QStandardItem{sourceFile->isAdditionalPart() ? QY("(additional part)") : sourceFile->m_container};
  items << new QStandardItem{to_qs(format_file_size(sourceFile->isPlaylist() ? sourceFile->m_playlistSize : info.size()))};
  items << new QStandardItem{info.path()};

  items[0]->setData(reinterpret_cast<quint64>(sourceFile), Util::SourceFileRole);
  items[0]->setIcon(  sourceFile->isAdditionalPart() ? m_additionalPartIcon
                    : sourceFile->isAppended()       ? m_addedIcon
                    :                                  m_normalIcon);

  items[2]->setTextAlignment(Qt::AlignRight);

  return items;
}
void
AvailableUpdateInfoDialog::updateCheckFinished(UpdateCheckStatus status,
                                               mtx_release_version_t releaseVersion) {
  auto statusStr = UpdateCheckStatus::NoNewReleaseAvailable == status ? QY("Currently no newer version is available online.")
                 : UpdateCheckStatus::NewReleaseAvailable   == status ? QY("There is a new version available online.")
                 :                                                      QY("There was an error querying the update status.");
  ui->status->setText(statusStr);

  if (UpdateCheckStatus::Failed == status)
    return;

  ui->currentVersion->setText(to_qs(releaseVersion.current_version.to_string()));
  ui->availableVersion->setText(to_qs(releaseVersion.latest_source.to_string()));
  ui->close->setText(QY("&Close"));

  auto url = releaseVersion.urls.find("general");
  if ((url != releaseVersion.urls.end()) && !url->second.empty()) {
    m_downloadURL = to_qs(url->second);
    ui->downloadURL->setText(Q("<html><body><a href=\"%1\">%1</a></body></html>").arg(m_downloadURL.toHtmlEscaped()));
    ui->download->setEnabled(true);
  }

  if (!m_releasesInfo)
    return;

  auto html              = QStringList{};
  auto numReleasesOutput = 0;
  auto releases          = m_releasesInfo->select_nodes("/mkvtoolnix-releases/release[not(@version='HEAD')]");
  auto re_released       = boost::regex{"^released\\s+v?[\\d\\.]+", boost::regex::perl | boost::regex::icase};
  auto re_bug            = boost::regex{"(#\\d+)", boost::regex::perl | boost::regex::icase};
  auto bug_formatter     = [](boost::smatch const &matches) -> std::string {
    auto number_str = matches[1].str().substr(1);
    return (boost::format("<a href=\"https://github.com/mbunkus/mkvtoolnix/issues/%1%\">#%1%</a>") % number_str).str();
  };

  releases.sort();

  for (auto &release : releases) {
    auto version_str   = std::string{release.node().attribute("version").value()};
    auto version_str_q = to_qs(version_str).toHtmlEscaped();
    auto codename_q    = to_qs(release.node().attribute("codename").value()).toHtmlEscaped();
    auto heading       = !codename_q.isEmpty() ? QY("Version %1 \"%2\"").arg(version_str_q).arg(codename_q) : QY("Version %1").arg(version_str_q);

    html << Q("<h2>%1</h2>").arg(heading)
         << Q("<p><ul>");

    for (auto change = release.node().child("changes").first_child() ; change ; change = change.next_sibling()) {
      if (   (std::string{change.name()} != "change")
          || boost::regex_search(change.child_value(), re_released))
        continue;

      auto text = boost::regex_replace(to_utf8(to_qs(change.child_value()).toHtmlEscaped()), re_bug, bug_formatter);
      html     << Q("<li>%1</li>").arg(to_qs(text));
    }

    html << Q("</ul></p>");

    numReleasesOutput++;
    if ((10 < numReleasesOutput) && (version_number_t{version_str} < releaseVersion.current_version))
      break;
  }

  html << Q("<p><a href=\"%1\">%2</a></h1>").arg(MTX_CHANGELOG_URL).arg(QY("Read full ChangeLog online"));

  setChangeLogContent(html.join(Q("\n")));
}
Example #11
0
static QString
unescape_mkvtoolnix(QString const &source) {
  return to_qs(::unescape(to_utf8(source)));
}
Example #12
0
QString
MainWindow::versionStringForSettings(version_number_t const &version) {
  return Q("version_%1").arg(to_qs(boost::regex_replace(version.to_string(), boost::regex("[^\\d]+", boost::regex::perl), "_")));
}
Example #13
0
static QString
unescape_mkvtoolnix(QString const &source) {
  if (source == Q("#EMPTY#"))
    return Q("");
  return to_qs(::unescape(to_utf8(source)));
}
Example #14
0
static QString
escape_mkvtoolnix(QString const &source) {
  if (source.isEmpty())
    return QString{"#EMPTY#"};
  return to_qs(::escape(to_utf8(source)));
}