Example #1
0
String KURL::fileSystemPath() const
{
    if (!isValid())
        return String();

    if (isLocalFile())
        return static_cast<QUrl>(*this).toLocalFile();

    // A valid qrc resource path begins with a colon.
    if (protocolIs("qrc"))
        return ":" + decodeURLEscapeSequences(path());

    return String();
}
Example #2
0
bool showInWindowsShell(const QString &filePath, bool deselect) {
   QFileInfo appFI(filePath);
   auto matchPath = appFI.dir().path().toLower();
   auto matchName = appFI.fileName().toLower();

   QAxObject shellApp("Shell.Application");

   QAxObject *windows = shellApp.querySubObject("Windows()");
   windows->disableMetaObject();
   auto count = windows->dynamicCall("Count()").toInt();
   qDebug() << count;
   for (int i = 0; i < count; ++i) {
      QAxObject *win = windows->querySubObject("Item(QVariant)", {i});
      win->disableMetaObject();

      auto program = win->dynamicCall("FullName()").toString();
      QFileInfo programFI(program);
      if (programFI.baseName().toLower() != "explorer") continue;
      auto url = win->dynamicCall("LocationURL()").toUrl();
      if (!url.isLocalFile()) continue;
      auto path = url.path().mid(1).toLower();
      if (path != matchPath) continue;

      QAxObject *doc = win->querySubObject("Document()");

      QAxObject *folder = doc->querySubObject("Folder()");
      folder->disableMetaObject();
      QAxObject *folderItems = folder->querySubObject("Items()");
      folderItems->disableMetaObject();

      QAxObject *ourEntry = {};
      int count = folderItems->dynamicCall("Count()").toInt();
      for (int j = 0; j < count; j++) {
         QAxObject *entry = folderItems->querySubObject("Item(QVariant)", j);
         entry->disableMetaObject();
         auto name = entry->dynamicCall("Name()").toString().toLower();
         if (name == matchName) ourEntry = entry;
      }
      if (ourEntry) {
         if (false)
            ourEntry->dynamicCall("InvokeVerb(QVariant)", QVariant());  // open etc.
         auto rc = doc->dynamicCall("SelectItem(QVariant, int)", ourEntry->asVariant(),
                                    SVSI_SELECT | (deselect ? SVSI_DESELECTOTHERS : 0));
         auto hwnd = win->dynamicCall("HWND()").toLongLong();
         BringWindowToTop(HWND(hwnd));
         return true;
      }
   }
   return false;
}
Example #3
0
QString QUrl::toString( bool encodedPath, bool forcePrependProtocol ) const
{
    QString res, p = path();
    if ( encodedPath )
	encode( p );

    if ( isLocalFile() ) {
	if ( forcePrependProtocol )
	    res = d->protocol + ":" + p;
	else
	    res = p;
    } else if ( d->protocol == "mailto" ) {
	res = d->protocol + ":" + p;
    } else {
	res = d->protocol + "://";
	if ( !d->user.isEmpty() || !d->pass.isEmpty() ) {
	    QString tmp;
	    if ( !d->user.isEmpty() ) {
		tmp = d->user;
		encode( tmp );
		res += tmp;
	    }
	    if ( !d->pass.isEmpty() ) {
		tmp = d->pass;
		encode( tmp );
		res += ":" + tmp;
	    }
	    res += "@";
	}
	res += d->host;
	if ( d->port != -1 )
	    res += ":" + QString( "%1" ).arg( d->port );
	if ( !p.isEmpty() ) {
	    if ( !d->host.isEmpty() && p[0]!='/' )
		res += "/";
	    res += p;
	}
    }

    if ( !d->refEncoded.isEmpty() )
	res += "#" + d->refEncoded;
    if ( !d->queryEncoded.isEmpty() )
	res += "?" + d->queryEncoded;

    return res;
}
Example #4
0
QString Q3Url::toString( bool encodedPath, bool forcePrependProtocol ) const
{
    QString res, p = path();
    if ( encodedPath )
	encode( p );

    if ( isLocalFile() ) {
	if ( forcePrependProtocol )
	    res = d->protocol + QLatin1String(":") + p;
	else
	    res = p;
    } else if ( d->protocol == QLatin1String("mailto") ) {
	res = d->protocol + QLatin1String(":") + p;
    } else {
	res = d->protocol + QLatin1String("://");
	if ( !d->user.isEmpty() || !d->pass.isEmpty() ) {
	    QString tmp;
	    if ( !d->user.isEmpty() ) {
		tmp = d->user;
		encode( tmp );
		res += tmp;
	    }
	    if ( !d->pass.isEmpty() ) {
		tmp = d->pass;
		encode( tmp );
		res += QLatin1String(":") + tmp;
	    }
	    res += QLatin1String("@");
	}
	res += d->host;
	if ( d->port != -1 )
	    res += QLatin1String(":") + QString( QLatin1String("%1") ).arg( d->port );
	if ( !p.isEmpty() ) {
	    if ( !d->host.isEmpty() && p[0]!= QLatin1Char( '/' ) )
		res += QLatin1String("/");
	    res += p;
	}
    }

    if ( !d->refEncoded.isEmpty() )
	res += QLatin1String("#") + d->refEncoded;
    if ( !d->queryEncoded.isEmpty() )
	res += QLatin1String("?") + d->queryEncoded;

    return res;
}
Example #5
0
ERYDBDataFile::Types ERYDBPolicy::getType( const std::string& path, Contexts ctxt )
{
	bool isLocal = isLocalFile( path );

	if( ctxt == PRIMPROC )
	{
		if( isLocal || !useHdfs() )
			return ERYDBDataFile::UNBUFFERED;
		else
			return ERYDBDataFile::HDFS;
	}
	else
	{
		if( isLocal || !useHdfs() )
			return ERYDBDataFile::BUFFERED;
		else
			return ERYDBDataFile::HDFS;
	}
}
Example #6
0
QString Mrl::displayName() const {
	if (isLocalFile())
		return fileName();
	QString disc;
	if (isDvd())
		disc = qApp->translate("Mrl", "DVD");
	else if (isBluray())
		disc = qApp->translate("Mrl", "Blu-ray");
	if (disc.isEmpty())
		return location();
	auto dev = device();
	if (dev.isEmpty())
		return disc;
	if (!dev.startsWith(_L("/dev/"))) {
		QRegularExpression regex("/([^/]+)/*$");
		auto match = regex.match(dev);
		if (match.hasMatch())
			dev = match.captured(1);
	}
	return disc % _L(" (") % dev % _L(')');
}
Example #7
0
/*!
    Returns the path of the URL. If \a correct is TRUE, the path is
    cleaned (deals with too many or too few slashes, cleans things
    like "/../..", etc). Otherwise path() returns exactly the path
    that was parsed or set.

    \sa setPath() hasPath()
*/
QString QUrl::path( bool correct ) const
{
    if ( !correct )
	return d->path;

    if ( d->cleanPathDirty ) {
	bool check = TRUE;
	if ( QDir::isRelativePath( d->path ) ) {
	    d->cleanPath = d->path;
	} else if ( isLocalFile() ) {
#if defined(Q_OS_WIN32) || defined(Q_OS_OS2)
	    // hack for stuff like \\machine\path and //machine/path on windows
	    if ( ( d->path.left( 1 ) == "/" || d->path.left( 1 ) == "\\" ) && 
		 d->path.length() > 1 ) {
		d->cleanPath = d->path;
		bool share = (d->cleanPath[0] == '\\' && d->cleanPath[1] == '\\') || 
		             (d->cleanPath[0] == '/' && d->cleanPath[1] == '/');
		slashify( d->cleanPath, FALSE );
		d->cleanPath = QDir::cleanDirPath( d->cleanPath );
		if ( share ) {
		    check = FALSE;
		    while (d->cleanPath.at(0) != '/' || d->cleanPath.at(1) != '/')
			d->cleanPath.prepend("/");
		}
	    }
#endif
	    if ( check ) {
		QFileInfo fi( d->path );
		if ( !fi.exists() )
		    d->cleanPath = d->path;
		else if ( fi.isDir() ) {
		    QString dir =
			QDir::cleanDirPath( (qt_resolve_symlinks ?
					    QDir( d->path ).canonicalPath() :
					    QDir( d->path ).absPath()) ) + "/";
		    if ( dir == "//" )
			d->cleanPath = "/";
		    else
			d->cleanPath = dir;
		} else {
		    QString p =
			QDir::cleanDirPath( (qt_resolve_symlinks ?
					    fi.dir().canonicalPath() :
					    fi.dir().absPath()) );
		    d->cleanPath = p + "/" + fi.fileName();
		}
	    }
	} else {
	    if ( d->path != "/" && d->path[ (int)d->path.length() - 1 ] == '/' )
		d->cleanPath = QDir::cleanDirPath( d->path ) + "/";
	    else
		d->cleanPath = QDir::cleanDirPath( d->path );
	}

	if ( check )
	    slashify( d->cleanPath, FALSE );
	d->cleanPathDirty = FALSE;
    }

    return d->cleanPath;
}
Example #8
0
	QString toLocalFile() const {return isLocalFile() ? m_loc.right(m_loc.size() - 7) : QString();}
Example #9
0
/*!
    Returns the path of the URL. If \a correct is true, the path is
    cleaned (deals with too many or too few slashes, cleans things
    like "/../..", etc). Otherwise path() returns exactly the path
    that was parsed or set.

    \sa setPath() hasPath()
*/
QString Q3Url::path( bool correct ) const
{
    if ( !correct )
	return d->path;

    if ( d->cleanPathDirty ) {
	bool check = true;
	if ( QDir::isRelativePath( d->path ) ) {
	    d->cleanPath = d->path;
	} else if ( isLocalFile() ) {
#if defined(Q_OS_WIN32)
	    // hack for stuff like \\machine\path and //machine/path on windows
	    if ( ( d->path.left( 1 ) == QLatin1String("/") || d->path.left( 1 ) == QLatin1String("\\") ) &&
		 d->path.length() > 1 ) {
		d->cleanPath = d->path;
		bool share = (d->cleanPath[0] == QLatin1Char('\\') && d->cleanPath[1] == QLatin1Char('\\')) ||
		             (d->cleanPath[0] == QLatin1Char('/') && d->cleanPath[1] == QLatin1Char('/'));
		slashify( d->cleanPath, false );
		d->cleanPath = QDir::cleanDirPath( d->cleanPath );
		if ( share ) {
		    check = false;
		    while (d->cleanPath.at(0) != QLatin1Char('/') || d->cleanPath.at(1) != QLatin1Char('/'))
			d->cleanPath.prepend(QLatin1String("/"));
		}
	    }
#endif
	    if ( check ) {
		QFileInfo fi( d->path );
		if ( !fi.exists() )
		    d->cleanPath = d->path;
		else if ( fi.isDir() ) {
                    QString canPath = QDir( d->path ).canonicalPath();
                    QString dir;
                    if ( qt_resolve_symlinks && !canPath.isNull() )
                       dir = QDir::cleanDirPath( canPath );
                    else
                       dir = QDir::cleanDirPath( QDir( d->path ).absPath() );
                    dir += QLatin1String("/");
		    if ( dir == QLatin1String("//") )
			d->cleanPath = QLatin1String("/");
		    else
			d->cleanPath = dir;
		} else {
		    QString p =
			QDir::cleanDirPath( (qt_resolve_symlinks ?
					    fi.dir().canonicalPath() :
					    fi.dir().absPath()) );
		    d->cleanPath = p + QLatin1String("/") + fi.fileName();
		}
	    }
	} else {
	    if ( d->path != QLatin1String("/") && d->path[ (int)d->path.length() - 1 ] == QLatin1Char('/') )
		d->cleanPath = QDir::cleanDirPath( d->path ) + QLatin1String("/");
	    else
		d->cleanPath = QDir::cleanDirPath( d->path );
	}

	if ( check )
	    slashify( d->cleanPath, false );
	d->cleanPathDirty = false;
    }

    return d->cleanPath;
}