示例#1
0
bool
FileIdentifier::identify() {
  if (m_fileName.isEmpty())
    return false;

  QStringList args;
  args << "--output-charset" << "utf-8" << "--identify-for-mmg" << m_fileName;

  auto process  = Process::execute(Settings::get().m_mkvmergeExe, args);
  auto exitCode = process->process().exitCode();
  m_output      = process->output();

  if (0 == exitCode)
    return parseOutput();

  if (3 == exitCode) {
    auto pos       = m_output.isEmpty() ? -1            : m_output[0].indexOf("container:");
    auto container = -1 == pos          ? QY("unknown") : m_output[0].mid(pos + 11);

    QMessageBox::critical(m_parent, QY("Unsupported file format"), QY("The file is an unsupported container format (%1).").arg(container));

    return false;
  }

  QMessageBox::critical(m_parent, QY("Unrecognized file format"), QY("The file was not recognized as a supported format (exit code: %1).").arg(exitCode));

  return false;
}
示例#2
0
void
MergeWidget::onBrowseOutput() {
  auto filter   = m_config.m_webmMode ? QY("WebM files") + Q(" (*.webm)") : QY("Matroska files") + Q(" (*.mkv *.mka *.mks *.mk3d)");
  auto fileName = getSaveFileName(QY("Select output file name"), filter, ui->output);
  if (!fileName.isEmpty())
    m_config.m_destination = fileName;
}
void
PrefsRunProgramWidget::changeExecutable() {
  Q_D(PrefsRunProgramWidget);

  auto filters = QStringList{};

#if defined(SYS_WINDOWS)
  filters << QY("Executable files") + Q(" (*.exe *.bat *.cmd)");
#endif
  filters << QY("All files") + Q(" (*)");

  auto realExecutable = Util::replaceMtxVariableWithApplicationDirectory(d->executable);
  auto newExecutable  = Util::getOpenFileName(this, QY("Select executable"), realExecutable, filters.join(Q(";;")));
  newExecutable       = QDir::toNativeSeparators(Util::replaceApplicationDirectoryWithMtxVariable(newExecutable));

  if (newExecutable.isEmpty() || (newExecutable == d->executable))
    return;

  changeArguments([&newExecutable](QStringList &arguments) {
    if (arguments.isEmpty())
      arguments << newExecutable;
    else
      arguments[0] = newExecutable;
  });

  d->executable = newExecutable;

  enableControls();

  emit titleChanged();
}
void
PrefsRunProgramWidget::setupTypeControl(Util::Settings::RunProgramConfig const &cfg) {
  Q_D(PrefsRunProgramWidget);

  auto addItemIfSupported = [this, d, &cfg](QString const &title, Util::Settings::RunProgramType type) {
    if (App::programRunner().isRunProgramTypeSupported(type)) {
      d->ui->cbType->addItem(title, static_cast<int>(type));

      if (cfg.m_type == type)
        d->ui->cbType->setCurrentIndex(d->ui->cbType->count() - 1);
    }
  };

  addItemIfSupported(QY("Execute a program"),      Util::Settings::RunProgramType::ExecuteProgram);
  addItemIfSupported(QY("Play an audio file"),     Util::Settings::RunProgramType::PlayAudioFile);
  addItemIfSupported(QY("Shut down the computer"), Util::Settings::RunProgramType::ShutDownComputer);
  addItemIfSupported(QY("Hibernate the computer"), Util::Settings::RunProgramType::HibernateComputer);
  addItemIfSupported(QY("Sleep the computer"),     Util::Settings::RunProgramType::SleepComputer);

  d->pagesByType[Util::Settings::RunProgramType::ExecuteProgram]    = d->ui->executeProgramTypePage;
  d->pagesByType[Util::Settings::RunProgramType::PlayAudioFile]     = d->ui->playAudioFileTypePage;
  d->pagesByType[Util::Settings::RunProgramType::ShutDownComputer]  = d->ui->emptyTypePage;
  d->pagesByType[Util::Settings::RunProgramType::HibernateComputer] = d->ui->emptyTypePage;
  d->pagesByType[Util::Settings::RunProgramType::SleepComputer]     = d->ui->emptyTypePage;

  showPageForType(cfg.m_type);

  if (d->ui->cbType->count() > 1)
    return;

  d->ui->lType->setVisible(false);
  d->ui->cbType->setVisible(false);
}
示例#5
0
bool
MainWindow::beforeCloseCheckRunningJobs() {
  auto tool = jobTool();
  if (!tool)
    return true;

  auto model = tool->model();
  if (!model->hasRunningJobs())
    return true;

  if (   Util::Settings::get().m_warnBeforeAbortingJobs
      && (Util::MessageBox::question(this)
            ->title(QY("Abort running jobs"))
            .text(Q("%1 %2").arg(QY("There is currently a job running.")).arg(QY("Do you really want to abort all currently running jobs?")))
            .buttonLabel(QMessageBox::Yes, QY("&Abort jobs"))
            .buttonLabel(QMessageBox::No,  QY("Cancel"))
            .exec()) == QMessageBox::No)
    return false;

  model->stop();
  model->withAllJobs([](Jobs::Job &job) {
    if (Jobs::Job::Running == job.status()) {
      job.setQuitAfterFinished(true);
      job.abort();
    }
  });

  return false;
}
void
AttachmentModel::retranslateUi() {
  setHorizontalHeaderLabels(          QStringList{} << QY("Name") << QY("MIME type") << QY("Description") << QY("Attach to") << QY("Source file name") << QY("Directory"));
  Util::setSymbolicColumnNames(*this, QStringList{} <<  Q("name") <<  Q("mimeType")  <<  Q("description") <<  Q("attachTo")  <<  Q("sourceFileName")   <<  Q("directory"));

  for (auto row = 0, numRows = rowCount(); row < numRows; ++row)
    setRowData(itemsForRow(row), *attachmentForRow(row));
}
示例#7
0
void
Tab::retranslateAttachmentsUI() {
  m_attachmentsModel->retranslateUi();

  m_addAttachmentsAction->setText(QY("&Add"));
  m_removeAttachmentsAction->setText(QY("&Remove"));

  // Attachment style
  ui->attachmentStyle->setItemData(0, static_cast<int>(Attachment::ToAllFiles));
  ui->attachmentStyle->setItemData(1, static_cast<int>(Attachment::ToFirstFile));

  setupAttachmentsToolTips();
}
示例#8
0
QStringList
Tab::selectAttachmentsToAdd() {
  QFileDialog dlg{this};
  dlg.setNameFilter(QY("All files") + Q(" (*)"));
  dlg.setFileMode(QFileDialog::ExistingFiles);
  dlg.setDirectory(Util::Settings::get().m_lastOpenDir);
  dlg.setWindowTitle(QY("Add attachments"));

  if (!dlg.exec())
    return QStringList{};

  Util::Settings::get().m_lastOpenDir = dlg.directory();

  return dlg.selectedFiles();
}
void
PrefsRunProgramWidget::setupToolTips() {
  Q_D(PrefsRunProgramWidget);

  auto conditionsToolTip = Q("%1 %2")
    .arg(QY("If any of these checkboxes is checked, the action will be executed when the corresponding condition is met."))
    .arg(QY("Independent of the checkboxes, every active configuration can be triggered manually from the \"job output\" tool."));

  Util::setToolTip(d->ui->leName, QY("This is an arbitrary name the GUI can use to refer to this particular configuration."));
  Util::setToolTip(d->ui->cbConfigurationActive, QY("Deactivating this checkbox is a way to disable a configuration temporarily without having to change its parameters."));
  Util::setToolTip(d->ui->pbExecuteNow, Q("%1 %2").arg(QY("Executes the action immediately.")).arg(QY("Note that most <MTX_…> variables are empty and will be removed for actions that can take variables as arguments.")));
  Util::setToolTip(d->ui->cbAfterJobQueueStopped, conditionsToolTip);
  Util::setToolTip(d->ui->cbAfterJobSuccessful,   conditionsToolTip);
  Util::setToolTip(d->ui->cbAfterJobError,        conditionsToolTip);
}
示例#10
0
QString
Job::displayableStatus(Status status) {
  return PendingManual == status ? QY("pending manual start")
       : PendingAuto   == status ? QY("pending automatic start")
       : Running       == status ? QY("running")
       : DoneOk        == status ? QY("completed OK")
       : DoneWarnings  == status ? QY("completed with warnings")
       : Failed        == status ? QY("failed")
       : Aborted       == status ? QY("aborted by user")
       : Disabled      == status ? QY("disabled")
       :                           QY("unknown");
}
示例#11
0
/*** qyOpenQuery - open a directory query.
 ***/
void*
qyOpenQuery(void* inf_v, pObjQuery query, pObjTrxTree* oxt)
    {
    pQyData inf = QY(inf_v);
    pQyQuery qy;

	/** Allocate the query structure **/
	qy = (pQyQuery)nmMalloc(sizeof(QyQuery));
	if (!qy) return NULL;
	memset(qy, 0, sizeof(QyQuery));
	qy->ObjInf = inf;
	qy->NextSubInfID = 0;
	qy->Query = query;
	qy->ObjInf = inf;
	xhInit(&qy->StructTable,17,0);

	/** Get the next subinf ready for retrieval. **/
	if (qy_internal_GetQueryItem(qy) < 0)
	    {
	    xhDeInit(&qy->StructTable);
	    nmFree(qy, sizeof(QyQuery));
	    return NULL;
	    }

	/** If a source= query, start it now. **/
	if (qy->ItemSrc != NULL) qy->LLQuery = qy_internal_StartQuery(qy);

    return (void*)qy;
    }
示例#12
0
/*** qySetAttrValue - sets the value of an attribute.  'val' must
 *** point to an appropriate data type.
 ***/
int
qySetAttrValue(void* inf_v, char* attrname, void* val, pObjTrxTree oxt)
    {
    pQyData inf = QY(inf_v);
    pStructInf find_inf;

	/** Choose the attr name **/
	if (!strcmp(attrname,"name"))
	    {
	    if (inf->NodeData == inf->BaseNode->Data)
	        {
	        if (!strcmp(inf->Obj->Pathname->Pathbuf,".")) return -1;
	        if (strlen(inf->Obj->Pathname->Pathbuf) - 
	            strlen(strrchr(inf->Obj->Pathname->Pathbuf,'/')) + 
		    strlen(*(char**)(val)) + 1 > 255)
		    {
		    mssError(1,"QY","SetAttr 'name': name too long for internal representation");
		    return -1;
		    }
	        strcpy(inf->Pathname, inf->Obj->Pathname->Pathbuf);
	        strcpy(strrchr(inf->Pathname,'/')+1,*(char**)(val));
	        if (rename(inf->Obj->Pathname->Pathbuf, inf->Pathname) < 0) return -1;
	        strcpy(inf->Obj->Pathname->Pathbuf, inf->Pathname);
		}
	    strcpy(inf->NodeData->Name,*(char**)val);
	    return 0;
	    }

	/** Otherwise, attempt to pass setattr through to lowlevel obj **/
	if (inf->LLObj) return objSetAttrValue(inf->LLObj, attrname, val);

	mssError(1,"QY","Invalid attribute for querytree object");

    return -1;
    }
示例#13
0
/*** qyGetAttrValue - get the value of an attribute by name.  The 'val'
 *** pointer must point to an appropriate data type.
 ***/
int
qyGetAttrValue(void* inf_v, char* attrname, void* val, pObjTrxTree* oxt)
    {
    pQyData inf = QY(inf_v);
    pStructInf find_inf;
    char* ptr;
    int i;

	/** Choose the attr name **/
	if (!strcmp(attrname,"name"))
	    {
	    *((char**)val) = obj_internal_PathPart(inf->Obj->Pathname, inf->Obj->Pathname->nElements - 1, 0);
	    obj_internal_PathPart(inf->Obj->Pathname,0,0);
	    return 0;
	    }

	/** If content-type, return as appropriate **/
	if (!strcmp(attrname,"content_type") && !(inf->LLObj))
	    {
	    *((char**)val) = inf->NodeData->UsrType;
	    return 0;
	    }

	/** Low-level object?  Lookup the attribute in it **/
	if (inf->LLObj) return objGetAttrValue(inf->LLObj, attrname, val);

	mssError(1,"QY","Invalid attribute for querytree object");

    return -1;
    }
示例#14
0
void
Tab::setAttachmentControlValues(Attachment *attachment) {
  m_currentlySettingInputControlValues = true;

  if (!attachment && ui->attachmentStyle->itemData(0).isValid())
    ui->attachmentStyle->insertItem(0, QY("<do not change>"));

  else if (attachment && !ui->attachmentStyle->itemData(0).isValid())
    ui->attachmentStyle->removeItem(0);

  if (!attachment) {
    ui->attachmentName->setText(Q(""));
    ui->attachmentDescription->setText(Q(""));
    ui->attachmentMIMEType->setEditText(Q(""));
    ui->attachmentStyle->setCurrentIndex(0);

  } else {
    ui->attachmentName->setText(        attachment->m_name);
    ui->attachmentDescription->setText( attachment->m_description);
    ui->attachmentMIMEType->setEditText(attachment->m_MIMEType);

    Util::setComboBoxIndexIf(ui->attachmentStyle, [&](QString const &, QVariant const &data) { return data.isValid() && (data.toInt() == static_cast<int>(attachment->m_style)); });
  }

  m_currentlySettingInputControlValues = false;
}
示例#15
0
ProcessPtr
Process::execute(QString const &command,
                 QStringList const &args,
                 bool useTempFile) {
  auto runner = [](QString const &commandToUse, QStringList const &argsToUse) {
    auto pr = std::make_shared<Process>( commandToUse, argsToUse );
    pr->run();
    return pr;
  };

  if (!useTempFile)
    return runner(command, args);

  QTemporaryFile optFile;

  if (!optFile.open())
    throw ProcessX{ to_utf8(QY("Error creating a temporary file (reason: %1).").arg(optFile.errorString())) };

  static const unsigned char utf8_bom[3] = {0xef, 0xbb, 0xbf};
  optFile.write(reinterpret_cast<char const *>(utf8_bom), 3);
  for (auto &arg : args)
    optFile.write(QString{"%1\n"}.arg(arg).toUtf8());
  optFile.close();

  QStringList argsToUse;
  argsToUse << QString{"@%1"}.arg(optFile.fileName());
  return runner(command, argsToUse);
}
示例#16
0
void
PreferencesDialog::setupProcessPriority() {
#if defined(SYS_WINDOWS)
  ui->cbMProcessPriority->addItem(QY("highest"), static_cast<int>(Util::Settings::HighestPriority)); // value 4, index 0
  ui->cbMProcessPriority->addItem(QY("higher"),  static_cast<int>(Util::Settings::HighPriority));    // value 3, index 1
#endif
  ui->cbMProcessPriority->addItem(QY("normal"),  static_cast<int>(Util::Settings::NormalPriority));  // value 2, index 2/0
  ui->cbMProcessPriority->addItem(QY("lower"),   static_cast<int>(Util::Settings::LowPriority));     // value 1, index 3/1
  ui->cbMProcessPriority->addItem(QY("lowest"),  static_cast<int>(Util::Settings::LowestPriority));  // value 0, index 4/2

  auto numPrios = ui->cbMProcessPriority->count();
  auto selected = 4 - static_cast<int>(m_cfg.m_priority) - (5 - numPrios);
  selected      = std::min<int>(std::max<int>(0, selected), numPrios);

  ui->cbMProcessPriority->setCurrentIndex(selected);
}
AvailableUpdateInfoDialog::AvailableUpdateInfoDialog(QWidget *parent)
  : QDialog{parent, Qt::Dialog | Qt::WindowMaximizeButtonHint | Qt::WindowCloseButtonHint}
  , ui{new Ui::AvailableUpdateInfoDialog}
{
  // Setup UI controls.
  ui->setupUi(this);

  setWindowTitle(QY("Online check for updates"));
  setChangeLogContent(Q(""));
  ui->status->setText(QY("Downloading release information"));

  auto thread = new UpdateCheckThread(parent);

  connect(thread, SIGNAL(checkFinished(mtx::gui::UpdateCheckStatus, mtx_release_version_t)), this, SLOT(updateCheckFinished(mtx::gui::UpdateCheckStatus, mtx_release_version_t)));
  connect(thread, SIGNAL(releaseInformationRetrieved(std::shared_ptr<pugi::xml_document>)),  this, SLOT(setReleaseInformation(std::shared_ptr<pugi::xml_document>)));

  thread->start();
}
示例#18
0
/*** qyGetNextMethod -- passthrough.
 ***/
char*
qyGetNextMethod(void* inf_v, pObjTrxTree oxt)
    {
    pQyData inf = QY(inf_v);

	/** Attempt to pass this through... **/
	if (inf->LLObj) return objGetNextMethod(inf->LLObj);

    return NULL;
    }
示例#19
0
/*** qyGetFirstAttr - get the first attribute name for this object.
 ***/
char*
qyGetFirstAttr(void* inf_v, pObjTrxTree oxt)
    {
    pQyData inf = QY(inf_v);

    	/** If low-level object, pass this through to it. **/
	if (inf->LLObj) return objGetFirstAttr(inf->LLObj);

    return NULL;
    }
示例#20
0
/*** qyAddAttr - add an attribute to an object.  Passthrough to lowlevel.
 ***/
int
qyAddAttr(void* inf_v, char* attrname, int type, void* val, pObjTrxTree oxt)
    {
    pQyData inf = QY(inf_v);

	/** Attempt to pass this through... **/
	if (inf->LLObj) return objAddAttr(inf->LLObj, attrname, type, val);

    return -1;
    }
示例#21
0
/*** qyOpenAttr - open an attribute as an object.  Passthrough.
 ***/
void*
qyOpenAttr(void* inf_v, char* attrname, int mode, pObjTrxTree oxt)
    {
    pQyData inf = QY(inf_v);

	/** Attempt to pass this through... **/
	if (inf->LLObj) return objOpenAttr(inf->LLObj, attrname, mode);

    return NULL;
    }
示例#22
0
/*** qyExecuteMethod - passthrough.
 ***/
int
qyExecuteMethod(void* inf_v, char* methodname, void* param, pObjTrxTree oxt)
    {
    pQyData inf = QY(inf_v);

	/** Attempt to pass this through... **/
	if (inf->LLObj) return objExecuteMethod(inf->LLObj, methodname, param);

    return -1;
    }
示例#23
0
void
Job::addLineToInternalLogs(QString const &line,
                           LineType type) {
  auto &storage = InfoLine    == type ? m_output
                : WarningLine == type ? m_warnings
                :                       m_errors;

  auto prefix   = InfoLine    == type ? Q("")
                : WarningLine == type ? Q("%1 ").arg(QY("Warning:"))
                :                       Q("%1 ").arg(QY("Error:"));

  m_fullOutput << Q("%1%2").arg(prefix).arg(line);
  storage      << line;

  m_modified    = true;

  if ((WarningLine == type) || (ErrorLine == type))
    updateUnacknowledgedWarningsAndErrors();
}
示例#24
0
void
Tool::retranslateUi() {
  ui->retranslateUi(this);
  m_model->retranslateUi();

  m_startAction->setText(QY("&Start selected jobs automatically"));
  m_viewOutputAction->setText(QY("&View output of selected jobs"));
  m_removeAction->setText(QY("&Remove selected jobs"));
  m_removeDoneAction->setText(QY("Remove &completed jobs"));
  m_removeDoneOkAction->setText(QY("Remove &successfully completed jobs"));
  m_removeAllAction->setText(QY("Remove a&ll jobs"));

  m_acknowledgeSelectedWarningsAction->setText(QY("Acknowledge selected warnings"));
  m_acknowledgeAllWarningsAction->setText(QY("Acknowledge all &warnings"));
  m_acknowledgeSelectedErrorsAction->setText(QY("Acknowledge selected errors"));
  m_acknowledgeAllErrorsAction->setText(QY("Acknowledge all &errors"));

  setupToolTips();
}
void
PrefsRunProgramWidget::changeAudioFile() {
  Q_D(PrefsRunProgramWidget);

  auto filters = QStringList{} << QY("Audio files") + Q(" (*.aac *.flac *.m4a *.mp3 *.ogg *.opus *.wav)")
                               << QY("All files")   + Q(" (*)");

  auto realAudioFile = Util::replaceMtxVariableWithApplicationDirectory(d->ui->leAudioFile->text());
  auto newAudioFile  = Util::getOpenFileName(this, QY("Select audio file"), realAudioFile, filters.join(Q(";;")));
  newAudioFile       = QDir::toNativeSeparators(Util::replaceApplicationDirectoryWithMtxVariable(newAudioFile));

  if (newAudioFile.isEmpty())
    return;

  d->ui->leAudioFile->setText(newAudioFile);

  enableControls();

  emit titleChanged();
}
示例#26
0
QVariant
SourceFileModel::headerData(int section,
                            Qt::Orientation orientation,
                            int role)
const {
    if (Qt::Horizontal != orientation)
        return QVariant{};

    if (Qt::DisplayRole == role)
        return FileNameColumn  == section ? QY("File name")
               : ContainerColumn == section ? QY("Container")
               : SizeColumn      == section ? QY("File size")
               : DirectoryColumn == section ? QY("Directory")
               :                               Q("INTERNAL ERROR");

    if (Qt::TextAlignmentRole == role)
        return SizeColumn == section ? Qt::AlignRight : Qt::AlignLeft;

    return QVariant{};
}
示例#27
0
void
AttachmentModel::setRowData(QList<QStandardItem *> const &items,
                            Attachment const &attachment) {
  auto info = QFileInfo{attachment.m_fileName};

  items[NameColumn       ]->setText(attachment.m_name);
  items[MIMETypeColumn   ]->setText(attachment.m_MIMEType);
  items[DescriptionColumn]->setText(attachment.m_description);
  items[StyleColumn      ]->setText(attachment.m_style == Attachment::ToAllFiles ? QY("to all output files") : QY("only to the first output file"));
  items[SourceFileColumn ]->setText(info.fileName());
  items[SourceDirColumn  ]->setText(info.path());
}
示例#28
0
QVariant
AttachmentModel::dataDisplay(QModelIndex const &index,
                             Attachment *attachment)
  const {
  if (NameColumn == index.column())
    return attachment->m_name;

  else if (MIMETypeColumn == index.column())
    return attachment->m_MIMEType;

  else if (DescriptionColumn == index.column())
    return attachment->m_description;

  else if (StyleColumn == index.column())
    return attachment->m_style == Attachment::ToAllFiles ? QY("to all files") : QY("only to the first file");

  else if (SourceFileColumn == index.column())
    return attachment->m_fileName;

  else
    return QVariant{};
}
示例#29
0
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
AttachmentModel::setRowData(QList<QStandardItem *> const &items,
                            Attachment const &attachment) {
  auto info = QFileInfo{attachment.m_fileName};
  auto size = QNY("%1 byte (%2)", "%1 bytes (%2)", info.size()).arg(info.size()).arg(Q(format_file_size(info.size())));

  items[NameColumn       ]->setText(attachment.m_name);
  items[MIMETypeColumn   ]->setText(attachment.m_MIMEType);
  items[DescriptionColumn]->setText(attachment.m_description);
  items[StyleColumn      ]->setText(attachment.m_style == Attachment::ToAllFiles ? QY("to all output files") : QY("only to the first output file"));
  items[SourceFileColumn ]->setText(info.fileName());
  items[SourceDirColumn  ]->setText(QDir::toNativeSeparators(info.path()));
  items[SizeColumn       ]->setText(size);
}