From 821a246b101038937f8070152a9c14ead1c4169b Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Tue, 2 Feb 2010 03:36:05 +0100 Subject: This should fix last wrong encoded urls --- src/urlbar/urlbar.cpp | 53 ++++++++++++++++++++++++++++++--------------------- 1 file changed, 31 insertions(+), 22 deletions(-) (limited to 'src/urlbar') diff --git a/src/urlbar/urlbar.cpp b/src/urlbar/urlbar.cpp index be19dae4..adeba6ae 100644 --- a/src/urlbar/urlbar.cpp +++ b/src/urlbar/urlbar.cpp @@ -140,13 +140,15 @@ void UrlBar::setUrl(const QUrl& url) if(url.scheme() == "about") { m_currentUrl = KUrl(); + updateUrl(); // updateUrl before setFocus setFocus(); } else { m_currentUrl = KUrl(url); + updateUrl(); } - updateUrl(); + } @@ -302,36 +304,43 @@ bool UrlBar::isLoading() return true; } + void UrlBar::keyPressEvent(QKeyEvent *event) { QString currentText = m_lineEdit->text().trimmed(); - if ((event->key() == Qt::Key_Enter || event->key() == Qt::Key_Return) - && !currentText.startsWith(QLatin1String("http://"), Qt::CaseInsensitive)) + if (event->key() == Qt::Key_Enter || event->key() == Qt::Key_Return) { - QString append; - if (event->modifiers() == Qt::ControlModifier) + if( !currentText.startsWith(QLatin1String("http://"), Qt::CaseInsensitive) ) { - append = QLatin1String(".com"); + QString append; + if (event->modifiers() == Qt::ControlModifier) + { + append = QLatin1String(".com"); + } + else if (event->modifiers() == (Qt::ControlModifier | Qt::ShiftModifier)) + { + append = QLatin1String(".org"); + } + else if (event->modifiers() == Qt::ShiftModifier) + { + append = QLatin1String(".net"); + } + + QUrl url(QLatin1String("http://www.") + currentText); + QString host = url.host(); + if (!host.endsWith(append, Qt::CaseInsensitive)) + { + host += append; + url.setHost(host); + m_lineEdit->setText(url.toString()); + } } - else if (event->modifiers() == (Qt::ControlModifier | Qt::ShiftModifier)) - { - append = QLatin1String(".org"); - } - else if (event->modifiers() == Qt::ShiftModifier) - { - append = QLatin1String(".net"); - } - - QUrl url(QLatin1String("http://www.") + currentText); - QString host = url.host(); - if (!host.endsWith(append, Qt::CaseInsensitive)) + else { - host += append; - url.setHost(host); - m_lineEdit->setText(url.toString()); + // fill lineEdit with its stripped contents to remove trailing spaces + m_lineEdit->setText(currentText); } } KHistoryComboBox::keyPressEvent(event); } - -- cgit v1.2.1