Exemple #1
0
bool QUrlProto::isParentOf(const QUrl &childUrl) const
{
  QUrl *item = qscriptvalue_cast<QUrl*>(thisObject());
  if (item)
    return item->isParentOf(childUrl);
  return false;
}
Exemple #2
0
int Url::isParentOf ( lua_State * L )// ( const QUrl & childUrl ) const : bool
{
	QUrl* lhs = ValueInstaller2<QUrl>::check( L, 1 );
	QUrl* childUrl = ValueInstaller2<QUrl>::check( L, 2 );
	Util::push( L, lhs->isParentOf( *childUrl ) );
	return 1;
}
Exemple #3
0
static QString displayUrl(const QUrl &url, const QUrl &base)
{
    if (base.isParentOf(url)) {
        return url.toDisplayString(QUrl::PreferLocalFile).mid(base.toDisplayString(QUrl::PreferLocalFile).length());
    } else {
        return ICore::self()->projectController()->prettyFileName(url, IProjectController::FormatPlain);
    }
}
bool NetworkAccessManager::isBlacklisted(QUrl url) {
  QListIterator<QUrl> iter(m_urlBlacklist);

  while (iter.hasNext()) {
    QUrl blacklisted = iter.next();

    if (blacklisted == url) {
      return true;
    } else if (blacklisted.path().isEmpty() && blacklisted.isParentOf(url)) {
      return true;
    }
  }

  return false;
};
QModelIndex FolderViewContextManagerItem::findRootIndex(const QUrl& wantedUrl)
{
    QModelIndex matchIndex;
    int matchUrlLength = 0;
    for (int row = 0; row < mModel->rowCount(); ++row) {
        QModelIndex index = mModel->index(row, 0);
        QUrl url = mModel->urlForIndex(index);
        int urlLength = url.url().length();
        if (url.isParentOf(wantedUrl) && urlLength > matchUrlLength) {
            matchIndex = index;
            matchUrlLength = urlLength;
        }
    }
    if (!matchIndex.isValid()) {
        qWarning() << "Found no root index for" << wantedUrl;
    }
    return matchIndex;
}
Exemple #6
0
int PlacesItemModel::closestItem(const QUrl& url) const
{
    int foundIndex = -1;
    int maxLength = 0;

    for (int i = 0; i < count(); ++i) {
        const QUrl itemUrl = placesItem(i)->url();
        if (url == itemUrl) {
            // We can't find a closer one, so stop here.
            foundIndex = i;
            break;
        } else if (itemUrl.isParentOf(url)) {
            const int length = itemUrl.path().length();
            if (length > maxLength) {
                foundIndex = i;
                maxLength = length;
            }
        }
    }

    return foundIndex;
}
QModelIndex FolderViewContextManagerItem::findClosestIndex(const QModelIndex& parent, const QUrl& wantedUrl)
{
    Q_ASSERT(mModel);
    QModelIndex index = parent;
    if (!index.isValid()) {
        index = findRootIndex(wantedUrl);
        if (!index.isValid()) {
            return QModelIndex();
        }
    }

    QUrl url = mModel->urlForIndex(index);
    if (!url.isParentOf(wantedUrl)) {
        qWarning() << url << "is not a parent of" << wantedUrl << "!";
        return QModelIndex();
    }

    QString relativePath = QDir(url.path()).relativeFilePath(wantedUrl.path());
    QModelIndex lastFoundIndex = index;
    Q_FOREACH(const QString & pathPart, relativePath.split(QDir::separator(), QString::SkipEmptyParts)) {
        bool found = false;
        for (int row = 0; row < mModel->rowCount(lastFoundIndex); ++row) {
            QModelIndex index = mModel->index(row, 0, lastFoundIndex);
            if (index.data().toString() == pathPart) {
                // FIXME: Check encoding
                found = true;
                lastFoundIndex = index;
                break;
            }
        }
        if (!found) {
            break;
        }
    }
    return lastFoundIndex;
}
Exemple #8
0
//! [set list content]
void FtpReply::setListContent()
{
    QUrl u = url();
    if (!u.path().endsWith("/"))
        u.setPath(u.path() + "/");

    QString base_url = url().toString();
    QString base_path = u.path();

    open(ReadOnly | Unbuffered);
    QString content(
        "<html>\n"
        "<head>\n"
        "  <title>" + Qt::escape(base_url) + "</title>\n"
        "  <style type=\"text/css\">\n"
        "  th { background-color: #aaaaaa; color: black }\n"
        "  table { border: solid 1px #aaaaaa }\n"
        "  tr.odd { background-color: #dddddd; color: black\n }\n"
        "  tr.even { background-color: white; color: black\n }\n"
        "  </style>\n"
        "</head>\n\n"
        "<body>\n"
        "<h1>" + tr("Listing for %1").arg(base_path) + "</h1>\n\n"
        "<table align=\"center\" cellspacing=\"0\" width=\"90%\">\n"
        "<tr><th>Name</th><th>Size</th></tr>\n");

    QUrl parent = u.resolved(QUrl(".."));

    if (parent.isParentOf(u))

        content += QString("<tr><td><strong><a href=\"" + parent.toString() + "\">"
            + tr("Parent directory") + "</a></strong></td><td></td></tr>\n");

    int i = 0;
    foreach (const QUrlInfo &item, items) {

        QUrl child = u.resolved(QUrl(item.name()));

        if (i == 0)
            content += QString("<tr class=\"odd\">");
        else
            content += QString("<tr class=\"even\">");

        content += QString("<td><a href=\"" + child.toString() + "\">"
                           + Qt::escape(item.name()) + "</a></td>");

        qint64 size = item.size();
        int unit = 0;
        while (size) {
            qint64 new_size = size/1024;
            if (new_size && unit < units.size()) {
                size = new_size;
                unit += 1;
            } else
                break;
        }

        if (item.isFile())
            content += QString("<td>" + QString::number(size) + " "
                               + units[unit] + "</td></tr>\n");
        else
            content += QString("<td></td></tr>\n");

        i = 1 - i;
    }