void BackgroundListModel::reload(const QStringList &selected)
{
    if (!m_packages.isEmpty()) {
        beginRemoveRows(QModelIndex(), 0, m_packages.count() - 1);
        m_packages.clear();
        endRemoveRows();
        emit countChanged();
    }

    if (!m_wallpaper) {
        return;
    }

    if (!selected.isEmpty()) {
        qDebug() << "selected" << selected;
        processPaths(selected);
    }

    const QStringList dirs = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QStringLiteral("wallpapers/"), QStandardPaths::LocateDirectory);
    qDebug() << " WP : -------" << dirs;

    BackgroundFinder *finder = new BackgroundFinder(m_wallpaper.data(), dirs);
    connect(finder, &BackgroundFinder::backgroundsFound, this, &BackgroundListModel::backgroundsFound);
    m_findToken = finder->token();
    finder->start();
    m_removableWallpapers = QSet<QString>::fromList(selected);
}
Example #2
0
void makeAbsolutePaths(YAML::Node& config,
                       const std::string& configPath,
                       const std::set<std::string>& PATHS) {
  auto configDir = filesystem::Path{configPath}.parentPath();

  auto transformFunc = [&](const std::string& nodePath) -> std::string {
    // Catch stdin/stdout and do not process
    if(nodePath == "stdin" || nodePath == "stdout")
      return nodePath;

    // replace relative path w.r.t. config directory
    try {
      return canonical(filesystem::Path{nodePath}, configDir).string();
    } catch(filesystem::FilesystemError& e) {
      // will fail if file does not exist; use parent in that case
      std::cerr << e.what() << std::endl;
      auto parentPath = filesystem::Path{nodePath}.parentPath();
      return (canonical(parentPath, configDir)
              / filesystem::Path{nodePath}.filename())
          .string();
    }
  };

  processPaths(config, transformFunc, PATHS);
}
void BackgroundListModel::backgroundsFound(const QStringList &paths, const QString &token)
{
    if (token == m_findToken) {
        processPaths(paths);
    }
}