Пример #1
0
Web::DictInfo Web::dictInfo(const QString &dict)
{
    QString filename = workPath() + "/" + dict + ".webdict";
    if (! QFile::exists(filename))
        return DictInfo();
    QSettings dictFile(filename, QSettings::IniFormat);
    DictInfo info(name(), dict,
            dictFile.value("author").toString(),
            dictFile.value("description").toString());
    return info;
}
Пример #2
0
void Web::setLoadedDicts(const QStringList &dicts)
{
    for (QStringList::const_iterator i = dicts.begin(); i != dicts.end(); ++i)
    {
        QString filename = workPath() + "/" + *i + ".webdict";
        if (! QFile::exists(filename))
            continue;
        QSettings dict(filename, QSettings::IniFormat);
        QString query = dict.value("query").toString();
        if (! query.isEmpty())
        {
            m_loadedDicts[*i].query = query;
            m_loadedDicts[*i].codec = dict.value("charset").toByteArray();
        }
    }
}
Пример #3
0
// refresh using projectPath
void
ProjectView::refresh()
{
  m_model->clear();

  QStringList header;
  header << tr("Content of %1").arg(m_projName) << tr("Note");
  m_model->setHorizontalHeaderLabels(header);

  APPEND_ROW(m_model, tr("Datasets")     );
  APPEND_ROW(m_model, tr("Data Displays"));
  APPEND_ROW(m_model, tr("Verilog")      );
  APPEND_ROW(m_model, tr("Verilog-A")    );
  APPEND_ROW(m_model, tr("VHDL")         );
  APPEND_ROW(m_model, tr("Octave")       );
  APPEND_ROW(m_model, tr("Schematics")   );
  APPEND_ROW(m_model, tr("Others")       );

  setExpanded(m_model->index(6, 0), true);

  if (!m_valid) {
    return;
  }

  // put all files into "Content"-ListView
  QDir workPath(m_projPath);
  QStringList files = workPath.entryList("*", QDir::Files, QDir::Name);
  QStringList::iterator it;
  QString extName, fileName;
  QList<QStandardItem *> columnData;

#define APPEND_CHILD(category, data) \
  m_model->item(category, 0)->appendRow(data);

  for(it = files.begin(); it != files.end(); ++it) {
    fileName = (*it).toAscii();
    extName = QFileInfo(workPath.filePath(fileName)).suffix();

    columnData.clear();
    columnData.append(new QStandardItem(fileName));

    if(extName == "dat") {
      APPEND_CHILD(0, columnData);
    }
    else if(extName == "dpl") {
      APPEND_CHILD(1, columnData);
    }
    else if(extName == "v") {
      APPEND_CHILD(2, columnData);
    }
    else if(extName == "va") {
      APPEND_CHILD(3, columnData);
    }
    else if((extName == "vhdl") || (extName == "vhd")) {
      APPEND_CHILD(4, columnData);
    }
    else if((extName == "m") || (extName == "oct")) {
      APPEND_CHILD(5, columnData);
    }
    else if(extName == "sch") {
      int n = Schematic::testFile(workPath.filePath(fileName));
      if(n >= 0) {
        if(n > 0) {
          columnData.append(new QStandardItem(QString::number(n)+tr("-port")));
        }
      }
      APPEND_CHILD(6, columnData);
    }
    else {
      APPEND_CHILD(7, columnData);
    }
  }

  resizeColumnToContents(0);
}
Пример #4
0
QStringList Web::availableDicts() const
{
    QStringList result = QDir(workPath()).entryList(QStringList("*.webdict"), QDir::Files, QDir::Name);
    result.replaceInStrings(".webdict", "");
    return result;
}
Пример #5
0
void Plugin::addFile(const std::string filepath)
{
    logger().debug("Adding file");
    // Check if file exists and it's not a directory
    File file(filepath);
    if (!file.exists())
    {
        std::cout << "Failed to add file " << filepath.c_str() << ": file does not exist" << std::endl;
        return;
    }
    if (file.isDirectory())
    {
        std::cout << "Failed to add file " << filepath.c_str() << ": file is a directory" << std::endl;
        return;

    }
    File index(Plugin::GIT_BIN_INDEX);
    if (!index.exists())
    {
        index.createFile();
    }
    // Find this file in the index
    if (isFileIndexed(filepath) && file.isLink())
    {
        logger().debug("File already in cache");
        auto entry = getIndexEntry(filepath);
        if (entry == nullptr)
        {
            std::cout << "Failed to retrieve index meta data for " << filepath << std::endl;
            return;
        }
        // Not fresh. Update existing index file
        // Remove file from index before recalculating everything
        for (auto it = _index.begin(); it != _index.end();) 
        {
            if ((*it).filepath == filepath)
            {
                // Remove link
                std::cout << "Replacing link with original file" << std::endl; 
                file.remove();
                Process::Args restoreArgs;
                std::string restorePath(Plugin::GIT_CACHE_DIR);
                restorePath.append("/wf/");
                restorePath.append((*it).uuid);
                restoreArgs.push_back(restorePath);
                restoreArgs.push_back(filepath);
                Process::launch("mv", restoreArgs, 0, 0, 0);
                it = _index.erase(it); 
            } else {
                it++;
            }
        } 

    }
    // Add new file into index
    UUIDGenerator gen;
    IndexEntry e;
    e.filepath = filepath;
    e.md5 = getFileMd5(filepath);
    e.uuid = gen.createRandom().toString();
    do 
    {
        e.uuid = gen.createRandom().toString();
    }
    while (!isUuidUnique(e.uuid));
    _index.push_back(e);
    writeIndex();

    // Place two copies of this file into cache
    // One copy is original file and don't tracked in any way
    // Second copy is a file we will create link to

    Process::Args args;
    args.push_back(filepath);
    std::string origPath(Plugin::GIT_CACHE_DIR);
    origPath.append("/of/").append(e.uuid);
    args.push_back(origPath);
    Poco::ProcessHandle copyProcess = Process::launch("cp", args, 0, 0, 0);
    if (copyProcess.wait() != 0)
    {
        std::cout << "Failed to move file into git-bin cache" << std::endl;
        return;
    }
    // Second stage copy
    args.clear();
    args.push_back(filepath);
    std::string workPath(Plugin::GIT_CACHE_DIR);
    workPath.append("/wf/").append(e.uuid);
    args.push_back(workPath);
    copyProcess = Process::launch("mv", args, 0, 0, 0);
    if (copyProcess.wait() != 0)
    {
        std::cout << "Failed to move file on stage 2" << std::endl;
        return;
    }

    // Make a link
    args.clear();
    args.push_back("-s");
    Path rel(filepath);
    std::string relPath;
    for (int i = 0; i < rel.depth(); i++)
    {
        relPath.append("../");
    }
    relPath.append(workPath);
    args.push_back(relPath);
    args.push_back(filepath);
    Poco::ProcessHandle linkProcess = Process::launch("ln", args, 0, 0, 0); 
    if (linkProcess.wait() != 0)
    {
        std::cout << "Failed to create link to file" << std::endl;
        return;
    }

    args.clear();
    args.push_back("add");
    args.push_back(filepath);
    Poco::ProcessHandle gitAddProcess = Process::launch("git", args, 0, 0, 0);
    if (gitAddProcess.wait() != 0)
    {
        std::cout << "Failed to add file into git index (git add)" << std::endl;
        return;
    }
}