bool getPath(char *path, const char *exe) { char envPath[MAX_CMD_SIZE + 1]; char *envPathPtr = envPath; path[0] = '\0'; strcpy(envPath, getenv("PATH")); for (;;) { char pathTemp[MAX_CMD_SIZE + 1]; int i; for (i = 0; envPathPtr[i] != '\0' && envPathPtr[i] != ':'; i++) ; strncpy(pathTemp, envPathPtr, i); pathTemp[i] = '\0'; strcat(pathTemp, "/"); strcat(pathTemp, exe); if (testExecutable(pathTemp)) { strcpy(path, pathTemp); return true; } if (envPathPtr[i] == '\0') break; envPathPtr += i + 1; } return false; }
OpenWithManagerDialog::OpenWithManagerDialog(QWidget *parentObject) : QDialog(parentObject), ui(new Ui::OpenWithManagerDialog), m_factoryModel(new OpenWithExecutableModel(this)), m_patternModel(new OpenWithPatternModel(this)), m_patternMapper(new QDataWidgetMapper(this)), m_handlerMapper(new QDataWidgetMapper(this)), m_patternTypeDelegate(new PatternTypeDelegate(this)), m_dirty(false) { // Setup ui: ui->setupUi(this); // Setup MVC: ui->tableFactories->setModel(m_factoryModel); ui->tablePattern->setModel(m_patternModel); ui->tablePattern->setItemDelegate(m_patternTypeDelegate); ui->comboMatch->setModel(m_patternTypeDelegate->patternTypeModel()); m_handlerMapper->setModel(m_factoryModel); m_handlerMapper->setSubmitPolicy(QDataWidgetMapper::AutoSubmit); m_handlerMapper->addMapping(ui->editName, 0); m_handlerMapper->addMapping(ui->comboType, 1, "currentIndex"); m_handlerMapper->addMapping(ui->editExec, 2); m_patternMapper->setModel(m_patternModel); m_patternMapper->setSubmitPolicy(QDataWidgetMapper::ManualSubmit); m_patternMapper->setItemDelegate(m_patternTypeDelegate); m_patternMapper->addMapping(ui->editPattern, OpenWithPatternModel::PatternCol); m_patternMapper->addMapping(ui->comboMatch, OpenWithPatternModel::PatternTypeCol); m_patternMapper->addMapping(ui->checkCaseSensitive, OpenWithPatternModel::CaseSensitivityCol); // Setup executable completion QFileSystemModel *fsModel = new QFileSystemModel(this); fsModel->setFilter(QDir::Files | QDir::Dirs | QDir::NoDot); fsModel->setRootPath(QDir::rootPath()); QCompleter *fsCompleter = new QCompleter(fsModel, this); ui->editExec->setCompleter(fsCompleter); // Factory GUI: connect(ui->pushAddFactory, SIGNAL(clicked()), this, SLOT(addFactory())); connect(ui->pushRemoveFactory, SIGNAL(clicked()), this, SLOT(removeFactory())); connect(ui->comboType, SIGNAL(currentIndexChanged(int)), this, SLOT(factoryTypeChanged(int))); connect(ui->tableFactories->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), this, SLOT(factorySelectionChanged())); // Executable GUI: connect(ui->pushExec, SIGNAL(clicked()), SLOT(browseExecutable())); connect(ui->editExec, SIGNAL(textChanged(QString)), SLOT(testExecutable())); // Pattern GUI: connect(ui->pushAddPattern, SIGNAL(clicked()), this, SLOT(addPattern())); connect(ui->pushRemovePattern, SIGNAL(clicked()), this, SLOT(removePattern())); connect(ui->tablePattern->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), this, SLOT(patternSelectionChanged())); connect(ui->pushApplyPattern, SIGNAL(clicked()), m_patternMapper, SLOT(submit())); connect(ui->pushRevertPattern, SIGNAL(clicked()), m_patternMapper, SLOT(revert())); connect(m_patternModel, SIGNAL(rowsInserted(QModelIndex, int, int)), this, SLOT(patternDimensionsChanged())); connect(m_patternModel, SIGNAL(rowsRemoved(QModelIndex, int, int)), this, SLOT(patternDimensionsChanged())); connect(m_patternModel, SIGNAL(modelReset()), this, SLOT(patternDimensionsChanged())); // Test updates: connect(ui->editTest, SIGNAL(textChanged(QString)), this, SLOT(checkTestText())); connect(m_patternModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(checkTestText())); connect(m_patternModel, SIGNAL(layoutChanged()), this, SLOT(checkTestText())); connect(ui->tableFactories->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), this, SLOT(checkTestText())); // handle apply button: connect(ui->buttonBox, SIGNAL(clicked(QAbstractButton*)), SLOT(buttonBoxClicked(QAbstractButton*))); // Mark dirty when the data changes. connect(m_factoryModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), SLOT(markDirty())); connect(m_factoryModel, SIGNAL(rowsInserted(QModelIndex, int, int)), SLOT(markDirty())); connect(m_factoryModel, SIGNAL(rowsRemoved(QModelIndex, int, int)), SLOT(markDirty())); connect(m_patternModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), SLOT(markDirty())); connect(m_patternModel, SIGNAL(rowsInserted(QModelIndex, int, int)), SLOT(markDirty())); connect(m_patternModel, SIGNAL(rowsRemoved(QModelIndex, int, int)), SLOT(markDirty())); }