Пример #1
0
/** ***************************************************************************/
ChromeBookmarks::Extension::Extension() : IExtension("Chromebookmarks") {
    qDebug("[%s] Initialize extension", name_);

    // Load settings
    qApp->settings()->beginGroup(name_);
    offlineIndex_.setFuzzy(qApp->settings()->value(CFG_FUZZY, DEF_FUZZY).toBool());

    // Load and set a valid path
    QVariant v = qApp->settings()->value(CFG_PATH);
    if (v.isValid() && v.canConvert(QMetaType::QString) && QFileInfo(v.toString()).exists())
        setPath(v.toString());
    else
        restorePath();

    // If the path changed write it to the settings
    connect(this, &Extension::pathChanged, [this](const QString& path){
        qApp->settings()->setValue(QString("%1/%2").arg(name_, CFG_PATH), path);
    });

    qApp->settings()->endGroup();

    // Deserialize data
    QFile dataFile(QDir(QStandardPaths::writableLocation(QStandardPaths::DataLocation)).
                   filePath(QString("%1.dat").arg(name_)));
    if (dataFile.exists()) {
        if (dataFile.open(QIODevice::ReadOnly|QIODevice::Text)) {
            qDebug("[%s] Deserializing from %s", name_, dataFile.fileName().toLocal8Bit().data());
            QDataStream in(&dataFile);
            quint64 count;
            for (in >> count ;count != 0; --count){
                shared_ptr<Bookmark> deshrp = std::make_shared<Bookmark>();
                deshrp->deserialize(in);
                index_.push_back(deshrp);
            }
            dataFile.close();

            // Build the offline index
            for (const auto &item : index_)
                offlineIndex_.add(item);
        } else
Пример #2
0
ProjectCreateImpl::ProjectCreateImpl(QWidget *parent) :
    QDialog(parent)
{
  setupUi(this);

  //bool is_new = (MusEGlobal::museProject == MusEGlobal::museProjectInitPath);  
  directoryPath = MusEGlobal::config.projectBaseFolder;

  QStringList filters = localizedStringListFromCharArray(MusEGlobal::project_create_file_save_pattern, "file_patterns");
  projectFileTypeCB->addItems(filters);

  QString proj_title = MusEGlobal::muse->projectTitle();
  QString proj_path  = MusEGlobal::muse->projectPath();
  QString proj_ext   = MusEGlobal::muse->projectExtension();
  
  projectNameEdit->setText(proj_title); 

  bool is_template = proj_path.startsWith(MusEGlobal::configPath + "/templates");
  
  templateCheckBox->setChecked(is_template);
  
  projDirPath = proj_path;
    
  int type_idx = 0;
  if(!proj_ext.isEmpty())
  {  
    // FIXME Imperfect. Trying to avoid adding yet another series of character strings.   p4.0.40
    type_idx = projectFileTypeCB->findText(proj_ext, Qt::MatchContains | Qt::MatchCaseSensitive);
    if(type_idx == -1)
      type_idx = 0;
  }  
  projectFileTypeCB->setCurrentIndex(type_idx);
  
  projDirToolButton->setIcon(*openIcon);
  browseDirButton->setIcon(*openIcon);
  restorePathButton->setIcon(*undoIcon);

  restorePathButton->setEnabled(false);  // Disabled at first.
  
  //createFolderCheckbox->setChecked(MusEGlobal::config.projectStoreInFolder && is_new); // Suggest no folder if not new.
  
  connect(templateCheckBox,SIGNAL(toggled(bool)), this, SLOT(templateButtonChanged(bool)));
  //connect(templateCheckBox,SIGNAL(clicked()), this, SLOT(updateDirectoryPath()));
  connect(projDirToolButton,SIGNAL(clicked()), this, SLOT(browseProjDir()));
  connect(restorePathButton,SIGNAL(clicked()), this, SLOT(restorePath()));
  connect(browseDirButton,SIGNAL(clicked()), this, SLOT(selectDirectory()));
  //connect(projectNameEdit,SIGNAL(textChanged(QString)), this, SLOT(updateDirectoryPath()));
  connect(projectNameEdit,SIGNAL(textChanged(QString)), this, SLOT(updateProjectName()));
  connect(createFolderCheckbox,SIGNAL(clicked()), this, SLOT(createProjFolderChanged()));
  connect(projectFileTypeCB,SIGNAL(currentIndexChanged(int)), this, SLOT(updateDirectoryPath()));
  connect(buttonBox, SIGNAL(accepted()), this, SLOT(ok()));
#if QT_VERSION >= 0x040700
  projectNameEdit->setPlaceholderText("<Project Name>");
  // Orcan: Commented out since there is no QPlainTextEdit::setPlaceholderText()
  //        as of Qt-4.7.1
  //commentEdit->setPlaceholderText("<Add information about project here>");
#endif
  updateDirectoryPath();
  projectNameEdit->setFocus();
  show();
}
Пример #3
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;
    }
}