Example #1
0
void BupSlave::open(const QUrl &pUrl, QIODevice::OpenMode pMode) {
	if(pMode & QIODevice::WriteOnly) {
		emit error(KIO::ERR_CANNOT_OPEN_FOR_WRITING, pUrl.toDisplayString());
		return;
	}

	QStringList lPathInRepo;
	if(!checkCorrectRepository(pUrl, lPathInRepo)) {
		emit error(KIO::ERR_SLAVE_DEFINED, i18n("No bup repository found.\n%1", pUrl.toDisplayString()));
		return;
	}

	Node *lNode = mRepository->resolve(lPathInRepo, true);
	if(lNode == NULL) {
		emit error(KIO::ERR_DOES_NOT_EXIST, lPathInRepo.join(QStringLiteral("/")));
		return;
	}

	File *lFile = qobject_cast<File *>(lNode);
	if(lFile == NULL) {
		emit error(KIO::ERR_IS_DIRECTORY, lPathInRepo.join(QStringLiteral("/")));
		return;
	}

	if(0 != lFile->seek(0)) {
		emit error(KIO::ERR_CANNOT_OPEN_FOR_READING, pUrl.toDisplayString());
		return;
	}

	mOpenFile = lFile;
	emit mimeType(lFile->mMimeType);
	emit totalSize(lFile->size());
	emit position(0);
	emit opened();
}
Example #2
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);
    }
}
Example #3
0
void RevDesc::on_anchorClicked(const QUrl& link) {
    static QRegularExpression anchorRE("^#(.+)$");
    qDebug() << "clicked on " << link.toDisplayString() << "\n";
    QWebFrame* frame = this->page()->mainFrame();

    QRegularExpressionMatch anchorMatch = anchorRE.match(link.toDisplayString());
    if(anchorMatch.hasMatch()) {
        frame->scrollToAnchor(anchorMatch.captured(1));
    }
}
Example #4
0
void KRSearchMod::scanURL(QUrl url)
{
    if (stopSearch) return;

    unScannedUrls.push(url);
    while (!unScannedUrls.isEmpty()) {
        QUrl urlToCheck = unScannedUrls.pop();

        if (stopSearch) return;

        if (query->isExcluded(urlToCheck)) {
            if (!query->searchInDirs().contains(urlToCheck))
                continue;
        }

        if (scannedUrls.contains(urlToCheck))
            continue;
        scannedUrls.push(urlToCheck);

        emit searching(urlToCheck.toDisplayString(QUrl::PreferLocalFile));

        if (urlToCheck.isLocalFile())
            scanLocalDir(urlToCheck);
        else
            scanRemoteDir(urlToCheck);
    }
}
Example #5
0
QByteArray loadFromCache(const QUrl& url) {
    if (auto cache = NetworkAccessManager::getInstance().cache()) {

        // caller is responsible for the deletion of the ioDevice, hence the unique_ptr
        if (auto ioDevice = std::unique_ptr<QIODevice>(cache->data(url))) {
            qCDebug(asset_client) << url.toDisplayString() << "loaded from disk cache.";
            return ioDevice->readAll();
        } else {
            qCDebug(asset_client) << url.toDisplayString() << "not in disk cache";
        }

    } else {
        qCWarning(asset_client) << "No disk cache to load assets from.";
    }
    return QByteArray();
}
Example #6
0
void BupSlave::listDir(const QUrl &pUrl) {
	QStringList lPathInRepo;
	if(!checkCorrectRepository(pUrl, lPathInRepo)) {
		emit error(KIO::ERR_SLAVE_DEFINED, i18n("No bup repository found.\n%1", pUrl.toDisplayString()));
		return;
	}
	Node *lNode = mRepository->resolve(lPathInRepo, true);
	if(lNode == NULL) {
		emit error(KIO::ERR_DOES_NOT_EXIST, lPathInRepo.join(QStringLiteral("/")));
		return;
	}
	Directory *lDir = qobject_cast<Directory *>(lNode);
	if(lDir == NULL) {
		emit error(KIO::ERR_IS_FILE, lPathInRepo.join(QStringLiteral("/")));
		return;
	}

	// give the directory a chance to reload if necessary.
	lDir->reload();

	const QString sDetails = metaData(QStringLiteral("details"));
	const int lDetails = sDetails.isEmpty() ? 2 : sDetails.toInt();

	NodeMapIterator i(lDir->subNodes());
	UDSEntry lEntry;
	while(i.hasNext()) {
		createUDSEntry(i.next().value(), lEntry, lDetails);
		emit listEntry(lEntry);
	}
	emit finished();
}
bool QFlatpakServices::openUrl(const QUrl &url)
{
    qCDebug(QFlatpakPlatformServices) << "Open url: " << url;

    QDBusMessage message = QDBusMessage::createMethodCall(QLatin1String("org.freedesktop.portal.Desktop"),
                                                          QLatin1String("/org/freedesktop/portal/desktop"),
                                                          QLatin1String("org.freedesktop.portal.OpenURI"),
                                                          QLatin1String("OpenURI"));

    // TODO get parent window id??
    QString parentWindowId = QLatin1String("x11:")/* + QString::number(parent->winId())*/;
    QVariantMap options; // TODO: handle "writable" option

    message << parentWindowId << url.toDisplayString() << options;

    QDBusPendingCall pendingCall = QDBusConnection::sessionBus().asyncCall(message);
    QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(pendingCall);
    watcher->waitForFinished(); // TODO sorry for a blocking call, but we cannot do it asynchronous here
    QDBusPendingReply<QDBusObjectPath> reply = *watcher;
    if (reply.isError()) {
        qCDebug(QFlatpakPlatformServices) << "Couldn't get reply";
        return false;
    }

    return true;
}
Example #8
0
/* ---------------------------------------------------------------------------------- */
bool kio_sieveProtocol::activate(const QUrl &url)
{
    changeCheck(url);
    if (!connect()) {
        return false;
    }

    infoMessage(i18n("Activating script..."));

    QString filename = url.fileName();

    if (filename.isEmpty()) {
        error(ERR_DOES_NOT_EXIST, url.toDisplayString());
        return false;
    }

    if (!sendData("SETACTIVE \"" + filename.toUtf8() + "\"")) {
        return false;
    }

    if (operationSuccessful()) {
        ksDebug << "Script activation complete." << endl;
        return true;
    } else {
        error(ERR_INTERNAL_SERVER, i18n("There was an error activating the script."));
        return false;
    }
}
Example #9
0
QVariantList RunningScriptsWidget::getRunning() {
    const int WINDOWS_DRIVE_LETTER_SIZE = 1;
    QVariantList result;
    foreach(const QString& runningScript, qApp->getRunningScripts()) {
        QUrl runningScriptURL = QUrl(runningScript);
        if (runningScriptURL.scheme().size() <= WINDOWS_DRIVE_LETTER_SIZE) {
            runningScriptURL = QUrl::fromLocalFile(runningScriptURL.toDisplayString(QUrl::FormattingOptions(QUrl::FullyEncoded)));
        }
        QVariantMap resultNode;
        resultNode.insert("name", runningScriptURL.fileName());
        resultNode.insert("url", runningScriptURL.toDisplayString(QUrl::FormattingOptions(QUrl::FullyEncoded)));
        // The path contains the exact path/URL of the script, which also is used in the stopScript function.
        resultNode.insert("path", runningScript);
        resultNode.insert("local", runningScriptURL.isLocalFile());
        result.append(resultNode);
    }
    return result;
}
void StartupSettingsPage::selectHomeUrl()
{
    const QUrl homeUrl(QUrl::fromUserInput(m_homeUrl->text(), QString(), QUrl::AssumeLocalFile));
    QUrl url = QFileDialog::getExistingDirectoryUrl(this, QString(), homeUrl);
    if (!url.isEmpty()) {
        m_homeUrl->setText(url.toDisplayString(QUrl::PreferLocalFile));
        slotSettingsChanged();
    }
}
Example #11
0
QVariant FlatTextarea::loadResource(int type, const QUrl &name) {
	QString imageName = name.toDisplayString();
	if (imageName.startsWith(qstr("emoji://e."))) {
		if (EmojiPtr emoji = emojiFromUrl(imageName)) {
			return QVariant(App::emojiSingle(emoji, _st.font->height));
		}
	}
	return QVariant();
}
Example #12
0
QVariant InputField::InputFieldInner::loadResource(int type, const QUrl &name) {
	QString imageName = name.toDisplayString();
	if (imageName.startsWith(qstr("emoji://e."))) {
		if (EmojiPtr emoji = emojiFromUrl(imageName)) {
			return QVariant(App::emojiSingle(emoji, f()->_st->font->height));
		}
	}
	return QVariant();
}
Example #13
0
QString PlacesItemEditDialog::text() const
{
    QString text = m_textEdit->text();
    if (text.isEmpty()) {
        const QUrl url = m_urlEdit->url();
        text = url.fileName().isEmpty() ? url.toDisplayString(QUrl::PreferLocalFile) : url.fileName();
    }
    return text;
}
Example #14
0
void BupSlave::get(const QUrl &pUrl) {
	QStringList lPathInRepo;
	if(!checkCorrectRepository(pUrl, lPathInRepo)) {
		emit error(KIO::ERR_SLAVE_DEFINED, i18n("No bup repository found.\n%1", pUrl.toDisplayString()));
		return;
	}

	// Assume that a symlink should be followed.
	// Kio will never call get() on a symlink if it actually wants to copy a
	// symlink, it would just create a symlink on the destination kioslave using the
	// target it already got from calling stat() on this one.
	Node *lNode = mRepository->resolve(lPathInRepo, true);
	if(lNode == NULL) {
		emit error(KIO::ERR_DOES_NOT_EXIST, lPathInRepo.join(QStringLiteral("/")));
		return;
	}
	File *lFile = qobject_cast<File *>(lNode);
	if(lFile == NULL) {
		emit error(KIO::ERR_IS_DIRECTORY, lPathInRepo.join(QStringLiteral("/")));
		return;
	}

	emit mimeType(lFile->mMimeType);
	// Emit total size AFTER mimetype
	emit totalSize(lFile->size());

	//make sure file is at the beginning
	lFile->seek(0);
	KIO::filesize_t lProcessedSize = 0;
	const QString lResumeOffset = metaData(QStringLiteral("resume"));
	if(!lResumeOffset.isEmpty()) {
		bool ok;
		KIO::fileoffset_t lOffset = lResumeOffset.toLongLong(&ok);
		if (ok && (lOffset > 0) && ((quint64)lOffset < lFile->size())) {
			if(0 == lFile->seek(lOffset)) {
				emit canResume();
				lProcessedSize = lOffset;
			}
		}
	}

	QByteArray lResultArray;
	int lRetVal;
	while(0 == (lRetVal = lFile->read(lResultArray))) {
		emit data(lResultArray);
		lProcessedSize += lResultArray.length();
		emit processedSize(lProcessedSize);
	}
	if(lRetVal == KIO::ERR_NO_CONTENT) {
		emit data(QByteArray());
		emit processedSize(lProcessedSize);
		emit finished();
	} else {
		emit error(lRetVal, lPathInRepo.join(QStringLiteral("/")));
	}
}
Example #15
0
ProgressDialog::ProgressDialog(const QUrl &url, QWidget *parent)
  : QProgressDialog(parent)
{
    setWindowTitle(tr("Download Progress"));
    setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
    setLabelText(tr("Downloading %1.").arg(url.toDisplayString()));
    setMinimum(0);
    setValue(0);
    setMinimumDuration(0);
}
Example #16
0
QUrl MainWindow::addQuery(QUrl url, QString key, QString value) {
  QString url_s = url.toDisplayString();

  if (url.hasQuery()) {
    url_s += "&" + key + "=" + value;
  } else {
    url_s += "?" + key + "=" + value;
  }

  return QUrl(url_s);
}
Example #17
0
void AssociatedFilesUI::setupForRemoteUrl(const QUrl &url, const QString &entryId) {
    d->sourceUrl = url;
    d->lineEditSourceUrl->setText(url.toDisplayString());
    if (entryId.isEmpty()) {
        d->labelGreeting->setText(i18n("The following remote document is about to be associated with the current entry:"));
        d->radioRenameToEntryId->setText(i18n("Rename after entry's id"));
    } else {
        d->labelGreeting->setText(i18n("The following remote document is about to be associated with entry '%1':", entryId));
        d->radioRenameToEntryId->setText(i18n("Rename after entry's id: '%1'", entryId));
    }
    updateUIandPreview();
}
Example #18
0
QUrl BrowseWidget::addQuery(const QUrl &t_url, const QString &t_key,
                            const QString &t_value) {
  QString url = t_url.toDisplayString();

  if (t_url.hasQuery()) {
    url += "&" + t_key + "=" + t_value;
  } else {
    url += "?" + t_key + "=" + t_value;
  }

  return QUrl(url);
}
Example #19
0
Sound::Sound(const QUrl& sampleURL, QObject* parent) :
    QObject(parent)
{
    // assume we have a QApplication or QCoreApplication instance and use the
    // QNetworkAccess manager to grab the raw audio file at the given URL

    QNetworkAccessManager *manager = new QNetworkAccessManager(this);
    connect(manager, SIGNAL(finished(QNetworkReply*)),
            this, SLOT(replyFinished(QNetworkReply*)));

    qDebug() << "Requesting audio file" << sampleURL.toDisplayString();
    manager->get(QNetworkRequest(sampleURL));
}
Example #20
0
QString Notepadqq::fileNameFromUrl(const QUrl &url)
{
    return QFileInfo(url.toDisplayString(
                         QUrl::RemoveScheme |
                         QUrl::RemovePassword |
                         QUrl::RemoveUserInfo |
                         QUrl::RemovePort |
                         QUrl::RemoveAuthority |
                         QUrl::RemoveQuery |
                         QUrl::RemoveFragment |
                         QUrl::PreferLocalFile )
                     ).fileName();
}
Example #21
0
bool saveToCache(const QUrl& url, const QByteArray& file) {
    if (auto cache = NetworkAccessManager::getInstance().cache()) {
        if (!cache->metaData(url).isValid()) {
            QNetworkCacheMetaData metaData;
            metaData.setUrl(url);
            metaData.setSaveToDisk(true);
            metaData.setLastModified(QDateTime::currentDateTime());
            metaData.setExpirationDate(QDateTime()); // Never expires

            // ioDevice is managed by the cache and should either be passed back to insert or remove!
            if (auto ioDevice = cache->prepare(metaData)) {
                ioDevice->write(file);
                cache->insert(ioDevice);
                qCDebug(asset_client) << url.toDisplayString() << "saved to disk cache";
                return true;
            }
            qCWarning(asset_client) << "Could not save" << url.toDisplayString() << "to disk cache.";
        }
    } else {
        qCWarning(asset_client) << "No disk cache to save assets to.";
    }
    return false;
}
Example #22
0
QUrl BrowseWidget::addPage(const QUrl &t_url, const int t_page) {
  QString url = t_url.toDisplayString();

  if (t_url.hasQuery()) {
    if (url.contains("page=[0-9]")) {
      url.replace("page=[0-9]", "page=" + QString::number(t_page));
    } else {
      url += "&page=" + QString::number(t_page);
    }
  } else {
    url += "?page=" + QString::number(t_page);
  }

  return QUrl(url);
}
Example #23
0
void KURLListRequester::slotBrowse()
{
    QUrl url;
    switch (mode) {
        case RequestFiles:
            url = QFileDialog::getOpenFileUrl(this);
            break;
        case RequestDirs:
            url = QFileDialog::getExistingDirectoryUrl(this);
            break;
    }
    if (!url.isEmpty())
        urlLineEdit->setText(url.toDisplayString(QUrl::PreferLocalFile));
    urlLineEdit->setFocus();
}
Example #24
0
void EditorTabWidget::on_fileNameChanged(const QUrl & /*oldFileName*/, const QUrl &newFileName)
{
    Editor *editor = dynamic_cast<Editor *>(sender());
    if (!editor)
        return;

    int index = indexOf(editor);

    QString fileName = QFileInfo(newFileName.toDisplayString(QUrl::RemoveScheme |
                                                   QUrl::RemovePassword |
                                                   QUrl::RemoveUserInfo |
                                                   QUrl::RemovePort |
                                                   QUrl::RemoveAuthority |
                                                   QUrl::RemoveQuery |
                                                   QUrl::RemoveFragment |
                                                   QUrl::PreferLocalFile
                                                   )).fileName();

    QString fullFileName = newFileName.toDisplayString(QUrl::PreferLocalFile |
                                                       QUrl::RemovePassword);

    setTabText(index, fileName);
    setTabToolTip(index, fullFileName);
}
Example #25
0
void KImportDlg::slotBrowse()
{
  // determine what the browse prefix should be from the current profile

  MyMoneyQifProfile tmpprofile;
  tmpprofile.loadProfile("Profile-" + profile());

  QUrl file = QFileDialog::getOpenFileUrl(this, i18n("Import File..."), QUrl("kfiledialog:///kmymoney-import"),
      i18n("Import files (%1);;All files (%2)", tmpprofile.filterFileType(), "*")
  );

  if (!file.isEmpty()) {
    m_qlineeditFile->setText(file.toDisplayString(QUrl::PreferLocalFile));
  }
}
Example #26
0
Sound::Sound(const QUrl& sampleURL, QObject* parent) :
    QObject(parent),
    _hasDownloaded(false)
{
    // assume we have a QApplication or QCoreApplication instance and use the
    // QNetworkAccess manager to grab the raw audio file at the given URL

    NetworkAccessManager& networkAccessManager = NetworkAccessManager::getInstance();

    qDebug() << "Requesting audio file" << sampleURL.toDisplayString();
    
    QNetworkReply* soundDownload = networkAccessManager.get(QNetworkRequest(sampleURL));
    connect(soundDownload, &QNetworkReply::finished, this, &Sound::replyFinished);
    connect(soundDownload, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(replyError(QNetworkReply::NetworkError)));
}
Example #27
0
QUrl MainWindow::addPage(QUrl url, int page) {
  QString url_s = url.toDisplayString();

  if (url.hasQuery()) {
    if (url_s.contains("page=[0-9]")) {
      url_s.replace("page=[0-9]", "page=" + QString::number(page));
    } else {
      url_s += "&page=" + QString::number(page);
    }
  } else {
    url_s += "?page=" + QString::number(page);
  }

  return QUrl(url_s);
}
Example #28
0
void BupSlave::mimetype(const QUrl &pUrl) {
	QStringList lPathInRepo;
	if(!checkCorrectRepository(pUrl, lPathInRepo)) {
		emit error(KIO::ERR_SLAVE_DEFINED, i18n("No bup repository found.\n%1", pUrl.toDisplayString()));
		return;
	}

	Node *lNode = mRepository->resolve(lPathInRepo);
	if(lNode == NULL) {
		emit error(KIO::ERR_DOES_NOT_EXIST, lPathInRepo.join(QStringLiteral("/")));
		return;
	}

	emit mimeType(lNode->mMimeType);
	emit finished();
}
Example #29
0
KUrlRequesterDlgForCopy::KUrlRequesterDlgForCopy(const QUrl &urlName, const QString &_text,
                                                 bool /*presAttrs*/, QWidget *parent, bool modal,
                                                 QUrl baseURL)
    : QDialog(parent), baseUrlCombo(0), copyDirStructureCB(0)
{
    setWindowModality(modal ? Qt::WindowModal : Qt::NonModal);

    QVBoxLayout *mainLayout = new QVBoxLayout;
    setLayout(mainLayout);

    mainLayout->addWidget(new QLabel(_text));

    urlRequester_ = new KUrlRequester(urlName, this);
    urlRequester_->setMinimumWidth(urlRequester_->sizeHint().width() * 3);
    mainLayout->addWidget(urlRequester_);
//     preserveAttrsCB = new QCheckBox(i18n("Preserve attributes (only for local targets)"), widget);
//     preserveAttrsCB->setChecked(presAttrs);
//     topLayout->addWidget(preserveAttrsCB);
    if (!baseURL.isEmpty()) {
        QFrame *line = new QFrame(this);
        line->setFrameStyle(QFrame::HLine | QFrame::Sunken);
        mainLayout->addWidget(line);
        copyDirStructureCB = new QCheckBox(i18n("Keep virtual folder structure"), this);
        connect(copyDirStructureCB, SIGNAL(toggled(bool)), this, SLOT(slotDirStructCBChanged()));
        copyDirStructureCB->setChecked(false);
        mainLayout->addWidget(copyDirStructureCB);
        QWidget *hboxWidget = new QWidget(this);
        QHBoxLayout * hbox = new QHBoxLayout(hboxWidget);
        QLabel * lbl = new QLabel(i18n("Base URL:"),  hboxWidget);
        hbox->addWidget(lbl);

        baseUrlCombo = new QComboBox(hboxWidget);
        baseUrlCombo->setMinimumWidth(baseUrlCombo->sizeHint().width() * 3);
        baseUrlCombo->setEnabled(copyDirStructureCB->isChecked());
        hbox->addWidget(baseUrlCombo);

        QUrl temp = baseURL, tempOld;
        do {
            QString baseURLText = temp.toDisplayString(QUrl::PreferLocalFile);
            baseUrlCombo->addItem(baseURLText);
            tempOld = temp;
            temp = KIO::upUrl(temp);
        } while (!tempOld.matches(temp, QUrl::StripTrailingSlash));
        baseUrlCombo->setCurrentIndex(0);

        mainLayout->addWidget(hboxWidget);
    }
Example #30
0
    void GUI::paste()
    {
        if (!paste_action->isEnabled())
            return;

        QClipboard* cb = QApplication::clipboard();
        QString text = cb->text(QClipboard::Clipboard);
        if (text.length() == 0)
            return;

        QUrl url = QFile::exists(text)?QUrl::fromLocalFile(text):QUrl(text);

        if (url.isValid())
            load(url);
        else
            KMessageBox::error(this, i18n("Invalid URL: %1", url.toDisplayString()));
    }