本文整理汇总了C++中QUrl::toString方法的典型用法代码示例。如果您正苦于以下问题:C++ QUrl::toString方法的具体用法?C++ QUrl::toString怎么用?C++ QUrl::toString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QUrl
的用法示例。
在下文中一共展示了QUrl::toString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: openURL
void JSKitPebble::openURL(const QUrl &url)
{
qCDebug(l) << "opening url" << url.toString();
emit _mgr->appOpenUrl(url);
}
示例2: parseTags
void Page::parseTags()
{
// Check redirection
QUrl redir = m_replyTags->attribute(QNetworkRequest::RedirectionTargetAttribute).toUrl();
if (!redir.isEmpty())
{
m_urlRegex = m_site->fixUrl(redir.toString(), m_urlRegex);
loadTags();
return;
}
QString source = QString::fromUtf8(m_replyTags->readAll());
m_tags.clear();
if (m_site->contains("Regex/Tags"))
{
QRegExp rxtags(m_site->value("Regex/Tags"));
rxtags.setMinimal(true);
int p = 0;
QStringList order = m_site->value("Regex/TagsOrder").split('|', QString::SkipEmptyParts);
while ((p = rxtags.indexIn(source, p)) != -1)
{
p += rxtags.matchedLength();
QString type = "", tag = "";
int count = 1;
if (order.empty())
{
switch (rxtags.captureCount())
{
case 4: order << "type" << "" << "count" << "tag"; break;
case 3: order << "type" << "tag" << "count"; break;
case 2: order << "type" << "tag"; break;
case 1: order << "tag"; break;
}
}
for (int o = 0; o < order.size(); o++)
{
if (order.at(o) == "tag" && tag.isEmpty())
{ tag = rxtags.cap(o + 1).replace(" ", "_").replace("&", "&").trimmed(); }
else if (order.at(o) == "type" && type.isEmpty())
{
type = rxtags.cap(o + 1).toLower().trimmed();
if (type.contains(", "))
{ type = type.split(", ").at(0).trimmed(); }
if (type == "series")
{ type = "copyright"; }
else if (type == "mangaka")
{ type = "artist"; }
else if (type == "game")
{ type = "copyright"; }
else if (type == "studio")
{ type = "circle"; }
else if (type == "source")
{ type = "general"; }
else if (type == "character group")
{ type = "general"; }
else if (type.length() == 1)
{
int tpe = type.toInt();
if (tpe >= 0 && tpe <= 4)
{
QStringList types = QStringList() << "general" << "artist" << "unknown" << "copyright" << "character";
type = types[tpe];
}
}
}
else if (order.at(o) == "count" && count != 0)
{ count = rxtags.cap(o + 1).toLower().endsWith('k') ? rxtags.cap(3).left(rxtags.cap(3).length() - 1).toInt() * 1000 : rxtags.cap(3).toInt(); }
}
if (type.isEmpty())
{ type = "unknown"; }
m_tags.append(Tag(tag, type, count));
}
}
// Getting last page
if (m_site->contains("Regex/Count") && m_imagesCount < 1)
{
QRegExp rxlast(m_site->value("Regex/Count"));
rxlast.indexIn(source, 0);
m_imagesCount = rxlast.cap(1).remove(",").toInt();
}
if (m_imagesCount < 1)
{
for (Tag tag : m_tags)
{
if (tag.text() == m_search.join(" "))
{
m_imagesCount = tag.count();
if (m_pagesCount < 0)
m_pagesCount = (int)ceil((m_imagesCount * 1.) / m_imagesPerPage);
}
}
}
if (m_site->contains("Regex/LastPage") && (m_imagesCount < 1 || m_imagesCount % 1000 == 0))
{
QRegExp rxlast(m_site->value("Regex/LastPage"));
rxlast.indexIn(source, 0);
m_pagesCount = rxlast.cap(1).remove(",").toInt();
if (m_pagesCount != 0)
//.........这里部分代码省略.........
示例3: setAddressUrl
void MainWindow::setAddressUrl(const QUrl& url)
{
setAddressUrl(url.toString(QUrl::RemoveUserInfo));
}
示例4: LocalFilePath
QString FileServerHandler::LocalFilePath(const QUrl &url,
const QString &wantgroup)
{
QString lpath = url.path();
if (lpath.section('/', -2, -2) == "channels")
{
// This must be an icon request. Check channel.icon to be safe.
QString querytext;
QString file = lpath.section('/', -1);
lpath = "";
MSqlQuery query(MSqlQuery::InitCon());
query.prepare("SELECT icon FROM channel WHERE icon LIKE :FILENAME ;");
query.bindValue(":FILENAME", QString("%/") + file);
if (query.exec() && query.next())
{
lpath = query.value(0).toString();
}
else
{
MythDB::DBError("Icon path", query);
}
}
else
{
lpath = lpath.section('/', -1);
QString fpath = lpath;
if (fpath.right(4) == ".png")
fpath = fpath.left(fpath.length() - 4);
ProgramInfo pginfo(fpath);
if (pginfo.GetChanID())
{
QString pburl = GetPlaybackURL(&pginfo);
if (pburl.left(1) == "/")
{
lpath = pburl.section('/', 0, -2) + "/" + lpath;
LOG(VB_FILE, LOG_INFO,
QString("Local file path: %1").arg(lpath));
}
else
{
LOG(VB_GENERAL, LOG_ERR,
QString("LocalFilePath unable to find local "
"path for '%1', found '%2' instead.")
.arg(lpath).arg(pburl));
lpath = "";
}
}
else if (!lpath.isEmpty())
{
// For securities sake, make sure filename is really the pathless.
QString opath = lpath;
StorageGroup sgroup;
if (!wantgroup.isEmpty())
{
sgroup.Init(wantgroup);
lpath = url.toString();
}
else
{
lpath = QFileInfo(lpath).fileName();
}
QString tmpFile = sgroup.FindFile(lpath);
if (!tmpFile.isEmpty())
{
lpath = tmpFile;
LOG(VB_FILE, LOG_INFO,
QString("LocalFilePath(%1 '%2'), found through "
"exhaustive search at '%3'")
.arg(url.toString()).arg(opath).arg(lpath));
}
else
{
LOG(VB_GENERAL, LOG_ERR, QString("LocalFilePath unable to "
"find local path for '%1'.")
.arg(opath));
lpath = "";
}
}
else
{
lpath = "";
}
}
return lpath;
}
示例5: parseNetworkReply
void SdtpCatalogDataProvider::parseNetworkReply( QNetworkReply *reply )
{
//
//
//
if( !m_netRequests.contains(reply) ) {
qDebug("Orphan request found with url = '%s'",
reply->url().toString().toLatin1().constData());
reply->deleteLater();
return;
}
#ifdef QT_DEBUG
qDebug("Network request '%s' took %d ms",
reply->url().toString().toLatin1().constData(),
m_debug_requestStart[reply].elapsed() );
m_debug_requestStart[reply].restart();
if ( reply->error() != QNetworkReply::NoError ) {
qDebug("QNetworkReply error! Code: %d", reply->error());
}
#endif
QPair<void*, RequestType> pair = m_netRequests[reply];
void* param = pair.first;
RequestType type = pair.second;
//
// HANDLE REDIRECTION
//
QUrl redirectUrl = reply->attribute(QNetworkRequest::RedirectionTargetAttribute).toUrl();
if ( !redirectUrl.isEmpty() && redirectUrl != reply->url()) {
// all non-local thumbnail redirects are disabled!
QString redirUrl = redirectUrl.toString();
if ( Thumbnail != type || !redirUrl.contains(QRegExp("is74.ru/", Qt::CaseInsensitive, QRegExp::Wildcard)) )
{
QNetworkReply* newReply = m_network->get(QNetworkRequest(redirectUrl));
#ifdef QT_DEBUG
debug_addRequestTime(newReply);
#endif
// replace reply ptr in hash
m_netRequests[newReply] = m_netRequests[reply];
m_netRequests.remove(reply);
return;
}
}
m_netRequests.remove(reply);
switch ( type ) {
case FoldersRecursive: {
XFolder* parent = static_cast<XFolder*>(param);
XFolderList *list = new XFolderList;
XFolderDict *dict = new XFolderDict;
bool ok = parseFoldersRecursiveData(parent, *reply, *dict, *list);
if ( ok ) {
emit data(FoldersRecursive, parent, list);
emit data(FoldersRecursiveDictionary, parent, dict);
} else {
delete list;
delete dict;
emit error(FoldersRecursive, parent);
}
break;
}
case Folders: {
XFolder* parent = static_cast<XFolder*>(param);
XFolderList *list = new XFolderList;
bool ok = parseFoldersData(parent, *reply, *list);
if ( ok )
emit data(Folders, parent, list);
else {
delete list;
emit error(Folders, parent);
}
break;
}
case Files: {
XFolder *parent = static_cast<XFolder*>(param);
XFileList *list = new XFileList;
bool ok = parseFilesData(parent, *reply, *list);
if ( ok )
emit data(Files, parent, list);
else {
delete list;
emit error(Files, parent);
}
break;
}
case FileDetails: {
XFile *file = static_cast<XFile*>(param);
XFile *dummy = new XFile(0,0,QString());;
bool ok = parseFileDetailsData(dummy, *reply);
if ( ok )
emit data(FileDetails, file, dummy);
else {
//.........这里部分代码省略.........
示例6: slotLinkClicked
void MyTextBrowser::slotLinkClicked(const QUrl &link)
{
char buf[MAX_PRINTF_LENGTH];
QString url;
int i;
url = link.toString();
// replace "href=\"//awite://" by "href=/"
while(1)
{
i = url.indexOf("awite://");
if(i < 0) break;
url = url.replace(i,8,"/");
if(opt.arg_debug) printf("MyTextBrowser::slotLinkClicked::link clicked = %s\n", (const char *) url.toUtf8());
}
if(opt.arg_debug) printf("slotLinkClicked(%s)\n", (const char *) url.toUtf8());
if(url.startsWith("http://") && (url.endsWith(".pdf") || url.endsWith(".PDF")))
{
QString cmd = opt.view_pdf;
cmd += " ";
url.replace(" ","%20");
cmd += url;
//#ifndef PVWIN32
// cmd += " &";
//#endif
mysystem(cmd.toUtf8());
}
else if(
!url.startsWith("http://audio.") &&
url.startsWith("http://") && (
url.endsWith(".mp3", Qt::CaseInsensitive) ||
url.endsWith(".ogg", Qt::CaseInsensitive) ||
url.endsWith(".m3u", Qt::CaseInsensitive) ||
url.endsWith(".asx", Qt::CaseInsensitive) ||
url.contains(".pls?", Qt::CaseInsensitive) ||
url.contains("mp3e", Qt::CaseInsensitive) ||
url.startsWith("http://www.youtube.com/watch?") ))
{
QString cmd = opt.view_audio;
cmd += " ";
url.replace(" ","%20");
cmd += url;
//#ifndef PVWIN32
// cmd += " &";
//#endif
mysystem(cmd.toUtf8());
}
else if(
!url.startsWith("http://video.") &&
url.startsWith("http://") && (
url.endsWith(".mp4", Qt::CaseInsensitive) ||
url.endsWith(".mov", Qt::CaseInsensitive) ||
url.endsWith(".ogv", Qt::CaseInsensitive) ||
url.endsWith(".avi", Qt::CaseInsensitive) ))
{
QString cmd = opt.view_video;
cmd += " ";
url.replace(" ","%20");
cmd += url;
//#ifndef PVWIN32
// cmd += " &";
//#endif
mysystem(cmd.toUtf8());
}
else
{
if(url.length()+40 > MAX_PRINTF_LENGTH) return;
sprintf(buf,"text(%d,\"%s\")\n", id,decode(url));
tcp_send(s,buf,strlen(buf));
#ifdef NO_WEBKIT
if (url.startsWith("http:")) setSource(QUrl(url));
else if(url.startsWith("https:")) setSource(QUrl(url));
else if(!url.contains("://")) setSource(QUrl(url));
#else
load(link);
#endif
}
}
示例7: urlSupported
bool MixtureCloud::urlSupported(const QUrl &url) const {
return urlPattern().indexIn(url.toString()) == 0;
}
示例8: launchWebBrowser
static bool launchWebBrowser(const QUrl &url)
{
if (url.scheme() == QLatin1String("mailto")) {
//Retrieve the commandline for the default mail client
//the default key used below is the command line for the mailto: shell command
DWORD bufferSize = sizeof(wchar_t) * MAX_PATH;
long returnValue = -1;
QString command;
HKEY handle;
LONG res;
wchar_t keyValue[MAX_PATH] = {0};
QString keyName(QLatin1String("mailto"));
//Check if user has set preference, otherwise use default.
res = RegOpenKeyEx(HKEY_CURRENT_USER,
L"Software\\Microsoft\\Windows\\Shell\\Associations\\UrlAssociations\\mailto\\UserChoice",
0, KEY_READ, &handle);
if (res == ERROR_SUCCESS) {
returnValue = RegQueryValueEx(handle, L"Progid", 0, 0, reinterpret_cast<unsigned char*>(keyValue), &bufferSize);
if (!returnValue)
keyName = QString::fromUtf16((const ushort*)keyValue);
RegCloseKey(handle);
}
keyName += QLatin1String("\\Shell\\Open\\Command");
res = RegOpenKeyExW(HKEY_CLASSES_ROOT, (const wchar_t*)keyName.utf16(), 0, KEY_READ, &handle);
if (res != ERROR_SUCCESS)
return false;
bufferSize = sizeof(wchar_t) * MAX_PATH;
returnValue = RegQueryValueEx(handle, L"", 0, 0, reinterpret_cast<unsigned char*>(keyValue), &bufferSize);
if (!returnValue)
command = QString::fromRawData((QChar*)keyValue, bufferSize);
RegCloseKey(handle);
if (returnValue)
return false;
command = expandEnvStrings(command);
command = command.trimmed();
//Make sure the path for the process is in quotes
int index = -1 ;
if (command[0]!= QLatin1Char('\"')) {
index = command.indexOf(QLatin1String(".exe "), 0, Qt::CaseInsensitive);
command.insert(index+4, QLatin1Char('\"'));
command.insert(0, QLatin1Char('\"'));
}
//pass the url as the parameter
index = command.lastIndexOf(QLatin1String("%1"));
if (index != -1){
command.replace(index, 2, url.toString());
}
//start the process
PROCESS_INFORMATION pi;
ZeroMemory(&pi, sizeof(pi));
STARTUPINFO si;
ZeroMemory(&si, sizeof(si));
si.cb = sizeof(si);
returnValue = CreateProcess(NULL, (wchar_t*)command.utf16(), NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
if (!returnValue)
return false;
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
return true;
}
if (!url.isValid())
return false;
if (url.scheme().isEmpty())
return openDocument(url);
quintptr returnValue = (quintptr)ShellExecute(0, 0, (wchar_t *)QString::fromUtf8(url.toEncoded().constData()).utf16(),
0, 0, SW_SHOWNORMAL);
return (returnValue > 32);
}
示例9: downloadFinished
void MainWindow::downloadFinished(QNetworkReply *reply)
{
QScrollBar *sb = ui->textBrowser->verticalScrollBar();
QUrl url = reply->url();
if (reply->error()) {
if ( !url.toString().contains("hgt.zip") ) {
ui->textBrowser->append("Download of " + QString(url.toEncoded().constData()) + " failed: " + QString(reply->errorString()));
sb->setValue(sb->maximum()); // get the info shown
}
QString fileUrl = url.toEncoded().constData();
} else {
QString path = url.path();
QString fileName = QFileInfo(path).fileName();
if (fileName.isEmpty()) fileName = "download";
QDir dir(dataDirectory);
dir.mkpath(dataDirectory);
QFile file(dataDirectory+"/"+fileName);
if (fileName.contains("dl")) {
// obtain url
QFile file(dataDirectory+"/"+fileName);
} else if (fileName.contains("hgt")) {
// obtain elevation files
dir.mkpath(dataDirectory+"/SRTM-3/");
file.setFileName(dataDirectory+"/SRTM-3/"+fileName);
GUILog( url.toString() + "\n", "download" );
}
if (file.open(QIODevice::WriteOnly)) {
file.write(reply->readAll());
file.close();
}
// download actual shapefile package
if (fileName.contains("dl")) {
QFile dlFile(dataDirectory+"/"+fileName);
if (!dlFile.open(QIODevice::ReadOnly | QIODevice::Text))
return;
QTextStream textStream( &dlFile);
QString dlUrl = textStream.readAll();
dlUrl.remove("<p>The document has moved <a href=\"");
dlUrl.remove("\">here</a></p>\n");
QNetworkReply *r = _manager->get(QNetworkRequest("http://mapserver.flightgear.org"+dlUrl));
connect(r, SIGNAL(downloadProgress(qint64, qint64)), this, SLOT(downloadShapefilesProgressBar(qint64, qint64)));
}
ui->textBrowser->append("Download of "+QString(url.toEncoded().constData())+" succeded saved to: "+QString(fileName));
sb->setValue(sb->maximum()); // get the info shown
// unzip shapefile package
if (fileName.contains("-")) {
// unpack zip
QString arguments;
#ifdef Q_OS_WIN
arguments += "7z.exe x \""+dataDirectory+"/"+fileName+"\" -o\""+dataDirectory+"\" -aoa";
#endif
#ifdef Q_OS_UNIX
arguments += "unzip -o "+dataDirectory+"/"+fileName+" -d "+dataDirectory;
#endif
//ui->textBrowser->append(arguments);
GUILog( arguments + "\n", "download" );
QProcess proc;
proc.start(arguments, QIODevice::ReadWrite);
proc.waitForReadyRead();
proc.waitForFinished(-1);
// delete temporary files
QFile shapeFile(dataDirectory+"/"+fileName);
shapeFile.remove();
QFile dlshpFile(dataDirectory+"/dlshp");
dlshpFile.remove();
// re-enable download button
ui->downloadShapefilesButton->setText("Download shapefiles");
ui->downloadShapefilesButton->setEnabled(1);
}
if (fileName.contains(".hgt.zip")){
// adjust progress bar
ui->downloadElevationProgressBar->setValue(ui->downloadElevationProgressBar->value()+1);
}
}
// re-enable download button
if (ui->downloadElevationProgressBar->value() == ui->downloadElevationProgressBar->maximum()) {
ui->downloadElevationButton->setEnabled(1);
}
}
示例10: Request
// Send request to the network manager
// Caller must hold m_mutex
bool NetStream::Request(const QUrl& url)
{
if (!IsSupported(url))
{
LOG(VB_GENERAL, LOG_WARNING, LOC +
QString("(%1) Request unsupported URL: %2")
.arg(m_id).arg(url.toString()) );
return false;
}
if (m_pending)
{
// Cancel the pending request
m_pending->m_bCancelled = true;
m_pending = 0;
}
if (m_reply)
{
// Abort the current reply
// NB the abort method appears to only work if called from NAMThread
m_reply->disconnect(this);
NAMThread::PostEvent(new NetStreamAbort(m_id, m_reply));
// NAMthread will delete the reply
m_reply = 0;
}
m_request.setUrl(url);
const QByteArray ua("User-Agent");
if (!m_request.hasRawHeader(ua))
m_request.setRawHeader(ua, "UK-MHEG/2 MYT001/001 MHGGNU/001");
if (m_pos > 0 || m_size >= 0)
m_request.setRawHeader("Range", QString("bytes=%1-").arg(m_pos).toLatin1());
#ifndef QT_NO_OPENSSL
if (m_request.url().scheme() == "https")
{
QSslConfiguration ssl(QSslConfiguration::defaultConfiguration());
QList<QSslCertificate> clist;
if (!m_cert.isEmpty())
{
clist = QSslCertificate::fromData(m_cert, QSsl::Der);
if (clist.isEmpty())
LOG(VB_GENERAL, LOG_WARNING, LOC + QString("Invalid certificate: %1")
.arg(m_cert.toPercentEncoding().constData()) );
}
if (clist.isEmpty())
// The BBC servers use a self certified cert so don't verify it
ssl.setPeerVerifyMode(QSslSocket::VerifyNone);
else
ssl.setCaCertificates(clist);
// We need to provide a client certificate for the BBC, See:
// openssl s_client -state -prexit -connect securegate.iplayer.bbc.co.uk:443
// for a list of accepted certificates
QString fname = gCoreContext->GetSetting("MhegClientCert", "");
if (!fname.isEmpty())
{
QFile f(QFile::exists(fname) ? fname : GetShareDir() + fname);
if (f.open(QIODevice::ReadOnly))
{
QSslCertificate cert(&f, QSsl::Pem);
if (!cert.isNull())
ssl.setLocalCertificate(cert);
else
LOG(VB_GENERAL, LOG_WARNING, LOC +
QString("'%1' is an invalid certificate").arg(f.fileName()) );
}
else
LOG(VB_GENERAL, LOG_WARNING, LOC +
QString("Opening client certificate '%1': %2")
.arg(f.fileName()).arg(f.errorString()) );
// Get the private key
fname = gCoreContext->GetSetting("MhegClientKey", "");
if (!fname.isEmpty())
{
QFile f(QFile::exists(fname) ? fname : GetShareDir() + fname);
if (f.open(QIODevice::ReadOnly))
{
QSslKey key(&f, QSsl::Rsa, QSsl::Pem, QSsl::PrivateKey,
gCoreContext->GetSetting("MhegClientKeyPass", "").toLatin1());
if (!key.isNull())
ssl.setPrivateKey(key);
else
LOG(VB_GENERAL, LOG_WARNING, LOC +
QString("'%1' is an invalid key").arg(f.fileName()) );
}
else
LOG(VB_GENERAL, LOG_WARNING, LOC +
QString("Opening private key '%1': %2")
.arg(f.fileName()).arg(f.errorString()) );
}
}
//.........这里部分代码省略.........
示例11: openUrl
void BrowserApplication::openUrl(const QUrl &url)
{
mainWindow()->loadPage(url.toString());
}
示例12: parseFiles
void Parser::parseFiles(QNetworkReply *reply, QMap<QNetworkReply*, Structureelement*> *replies, QString downloadDirectoryPath)
{
// Holen die aktuelle Veranstaltung aus der Map
Structureelement* aktuellerOrdner = replies->value(reply);
// Auslesen der Antwort und Speichern in dem XmlReader
QString replyText = reply->readAll();
QXmlStreamReader Reader;
Reader.addData(replyText);
// Vorbereitung der Daten für die Elemente
QString currentXmlTag;
QUrl url;
QString name;
QString time;
qint32 size = 0;
// Prüfen auf das Ende
while(!Reader.atEnd())
{
// Lese nächstes Element
Reader.readNext();
// 1. Fall: Öffnendes Element <Element>
if(Reader.isStartElement())
{
// Speichern des Namens
currentXmlTag = Reader.name().toString();
}
// 2. Fall: Schließendes Element mit Namen Response </Response>
else if (Reader.isEndElement() && Reader.name() == "response")
{
// Hinzufügen des Slashs bei der Url von Ordnern
if(!size)
url.setUrl(url.toString() % "/");
// Wechsel in den übergeordneten Ordner des aktuellen Elements
QString bla = url.toString();
while(!url.toString().contains((aktuellerOrdner->data(urlRole).toUrl().toString()), Qt::CaseSensitive))//(in = RegExp.indexIn(url.toString())) == -1)
{
aktuellerOrdner->sortChildren(0, Qt::AscendingOrder);
aktuellerOrdner = (Structureelement*)aktuellerOrdner->parent();
if (aktuellerOrdner == 0)
qDebug() << replyText;
}
// Ignorieren aller Adressen, die "/Forms" enthalten
if (!url.toString().contains("/Forms", Qt::CaseSensitive))
{
// Prüfe auf Elementart
// 1. Fall: Datei (size > 0)
if (size)
{
// Erstellen einer neuen Datei
Structureelement* newFile = new Structureelement(name, url, time, size);
// Hinzufügen des endungsabhängigen Icons
// PDF
if (name.contains(QRegExp(".pdf$", Qt::CaseInsensitive)))
newFile->setData(QIcon(":/Icons/Icons/filetype_pdf.png"), Qt::DecorationRole);
// ZIP
else if (name.contains(QRegExp(".zip$", Qt::CaseInsensitive)))
newFile->setData(QIcon(":/Icons/Icons/filetype_zip.png"), Qt::DecorationRole);
// RAR
else if (name.contains(QRegExp(".rar$", Qt::CaseInsensitive)))
newFile->setData(QIcon(":/Icons/Icons/filetype_rar.png"), Qt::DecorationRole);
// Sonstige
else
newFile->setData(QIcon(":/Icons/Icons/file.png"), Qt::DecorationRole);
QString path;
path.append(Utils::getStrukturelementPfad(aktuellerOrdner, downloadDirectoryPath) %"/");
path.append(name);
path.remove(0,8);
if(QFile::exists(path))
{
newFile->setData(SYNCHRONISED, synchronisedRole);
}
else
{
newFile->setData(NOT_SYNCHRONISED, synchronisedRole);
}
QList<QStandardItem*> row;
row.append(newFile);
row.append(new QStandardItem(QString::number(size/1024.0/1024.0, 'f', 2) % " MB"));
row.append(new QStandardItem(QDateTime::fromString(time, Qt::ISODate).toString("yyyy-MM-dd hh:mm")));
// Hinzufügen zum aktuellen Ordner
aktuellerOrdner->appendRow(row);
}
// 2. Fall: Ordner/Veranstaltung
// Ausschließen der Ordnernamen "documents" und "structured"
//.........这里部分代码省略.........
示例13: createSubThumbnail
bool ThumbnailProtocol::createSubThumbnail(QImage& thumbnail, const QString& filePath,
int segmentWidth, int segmentHeight)
{
if (m_enabledPlugins.isEmpty()) {
const KConfigGroup globalConfig(KSharedConfig::openConfig(), "PreviewSettings");
m_enabledPlugins = globalConfig.readEntry("Plugins", QStringList()
<< "imagethumbnail"
<< "jpegthumbnail"
<< "videopreview");
}
const QMimeDatabase db;
const QUrl fileUrl = QUrl::fromLocalFile(filePath);
const QString subPlugin = pluginForMimeType(db.mimeTypeForUrl(fileUrl).name());
if (subPlugin.isEmpty() || !m_enabledPlugins.contains(subPlugin)) {
return false;
}
ThumbCreator* subCreator = getThumbCreator(subPlugin);
if (!subCreator) {
// qDebug() << "found no creator for" << dir.filePath();
return false;
}
if ((segmentWidth <= 256) && (segmentHeight <= 256)) {
// check whether a cached version of the file is available for
// 128 x 128 or 256 x 256 pixels
int cacheSize = 0;
QCryptographicHash md5(QCryptographicHash::Md5);
md5.addData(QFile::encodeName(fileUrl.toString()));
const QString thumbName = QFile::encodeName(md5.result().toHex()).append(".png");
if (m_thumbBasePath.isEmpty()) {
m_thumbBasePath = QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation) + QLatin1String("/thumbnails/");
QDir basePath(m_thumbBasePath);
basePath.mkpath("normal/");
QFile::setPermissions(basePath.absoluteFilePath("normal"), QFile::ReadOwner | QFile::WriteOwner | QFile::ExeOwner);
basePath.mkpath("large/");
QFile::setPermissions(basePath.absoluteFilePath("large"), QFile::ReadOwner | QFile::WriteOwner | QFile::ExeOwner);
}
QDir thumbPath(m_thumbBasePath);
if ((segmentWidth <= 128) && (segmentHeight <= 128)) {
cacheSize = 128;
thumbPath.cd("normal");
} else {
cacheSize = 256;
thumbPath.cd("large");
}
if (!thumbnail.load(thumbPath.absoluteFilePath(thumbName))) {
// no cached version is available, a new thumbnail must be created
QSaveFile thumbnailfile(thumbPath.absoluteFilePath(thumbName));
bool savedCorrectly = false;
if (subCreator->create(filePath, cacheSize, cacheSize, thumbnail)) {
scaleDownImage(thumbnail, cacheSize, cacheSize);
// The thumbnail has been created successfully. Store the thumbnail
// to the cache for future access.
if (thumbnailfile.open(QIODevice::WriteOnly | QIODevice::Truncate)) {
savedCorrectly = thumbnail.save(&thumbnailfile, "PNG");
}
} else {
return false;
}
if(savedCorrectly)
{
thumbnailfile.commit();
}
}
} else if (!subCreator->create(filePath, segmentWidth, segmentHeight, thumbnail)) {
return false;
}
return true;
}
示例14: open
void QNetworkAccessFileBackend::open()
{
QUrl url = this->url();
if (url.host() == QLatin1String("localhost"))
url.setHost(QString());
#if !defined(Q_OS_WIN)
// do not allow UNC paths on Unix
if (!url.host().isEmpty()) {
// we handle only local files
error(QNetworkReply::ProtocolInvalidOperationError,
QCoreApplication::translate("QNetworkAccessFileBackend", "Request for opening non-local file %1").arg(url.toString()));
finished();
return;
}
#endif // !defined(Q_OS_WIN)
if (url.path().isEmpty())
url.setPath(QLatin1String("/"));
setUrl(url);
QString fileName = url.toLocalFile();
if (fileName.isEmpty()) {
if (url.scheme() == QLatin1String("qrc"))
fileName = QLatin1Char(':') + url.path();
else
fileName = url.toString(QUrl::RemoveAuthority | QUrl::RemoveFragment | QUrl::RemoveQuery);
}
file.setFileName(fileName);
if (operation() == QNetworkAccessManager::GetOperation) {
if (!loadFileInfo())
return;
}
QIODevice::OpenMode mode;
switch (operation()) {
case QNetworkAccessManager::GetOperation:
mode = QIODevice::ReadOnly;
break;
case QNetworkAccessManager::PutOperation:
mode = QIODevice::WriteOnly | QIODevice::Truncate;
uploadByteDevice = createUploadByteDevice();
QObject::connect(uploadByteDevice, SIGNAL(readyRead()), this, SLOT(uploadReadyReadSlot()));
QMetaObject::invokeMethod(this, "uploadReadyReadSlot", Qt::QueuedConnection);
break;
default:
Q_ASSERT_X(false, "QNetworkAccessFileBackend::open",
"Got a request operation I cannot handle!!");
return;
}
mode |= QIODevice::Unbuffered;
bool opened = file.open(mode);
// could we open the file?
if (!opened) {
QString msg = QCoreApplication::translate("QNetworkAccessFileBackend", "Error opening %1: %2")
.arg(this->url().toString(), file.errorString());
// why couldn't we open the file?
// if we're opening for reading, either it doesn't exist, or it's access denied
// if we're opening for writing, not existing means it's access denied too
if (file.exists() || operation() == QNetworkAccessManager::PutOperation)
error(QNetworkReply::ContentAccessDenied, msg);
else
error(QNetworkReply::ContentNotFoundError, msg);
finished();
}
}
示例15: slotNoOwnCloudFoundAuthTimeout
void OwncloudSetupWizard::slotNoOwnCloudFoundAuthTimeout(const QUrl&url)
{
_ocWizard->displayError(tr("Timeout while trying to connect to %1 at %2.")
.arg(Theme::instance()->appNameGUI(),
url.toString()), false);
}