Example #1
0
QUrl searchForResourceSearchPath(const QUrl& baseUrl,
                                 const QUrl& url,
                                 const QStringList& searchPath)
{
  if (url.isRelative()) {
    if (!baseUrl.isLocalFile()) {
      return baseUrl.resolved(url);
    }

    auto path = url.path();
    if (!path.startsWith("/")) {
      auto resolvedUrl = baseUrl.resolved(url);
      if (QFile::exists(resolvedUrl.toLocalFile())) {
        return resolvedUrl;
      }
    } else if (!path.contains("/../")) {
      auto pathRelPart = path.split(QRegularExpression("^/+"))[1];
      for (const auto& str : searchPath) {
        auto dir = QDir(str);
        auto absPath = QDir::cleanPath(dir.absoluteFilePath(pathRelPart));

        if (QFile::exists(absPath)) {
          return QUrl::fromLocalFile(absPath);
        }
      }

      return QUrl();
    } else {
      return QUrl();
    }
  }

  return url;
}
void FilePropertyWidgetQt::dropEvent(QDropEvent* drop) {
    auto data = drop->mimeData();
    if (data->hasUrls()) {
        if(data->urls().size()>0) {
            auto url = data->urls().first();
            property_->set(url.toLocalFile().toStdString());

            drop->accept();
        }
    }
}
void FilePropertyWidgetQt::dragEnterEvent(QDragEnterEvent* event) {
    switch (property_->getAcceptMode()) {
        case FileProperty::AcceptMode::Save: {
            event->ignore();
            return;
        }
        case FileProperty::AcceptMode::Open: {
            if (event->mimeData()->hasUrls()) {
                auto data = event->mimeData();
                if (data->hasUrls()) {
                    if (data->urls().size() > 0) {
                        auto url = data->urls().first();
                        auto file = url.toLocalFile().toStdString();
                        
                        switch (property_->getFileMode()) {
                            case FileProperty::FileMode::AnyFile:
                            case FileProperty::FileMode::ExistingFile:
                            case FileProperty::FileMode::ExistingFiles: {
                                auto ext = toLower(filesystem::getFileExtension(file));
                                for (const auto& filter : property_->getNameFilters()) {
                                    if (filter.extension_ == ext) {
                                        event->accept();
                                        return;
                                    }
                                }
                                break;
                            }
                        
                            case FileProperty::FileMode::Directory:
                            case FileProperty::FileMode::DirectoryOnly: {
                                if(filesystem::directoryExists(file)) {
                                    event->accept();
                                    return;
                                }
                                break;
                            }
                        }
                    }
                }
            }
            event->ignore();
            return;
        }      
    }
}
Example #4
0
	QString location() const { auto loc = toLocalFile(); return loc.isEmpty() ? m_loc : loc; }