[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: KDE/kdelibs/kfile
From: Peter Penz <peter.penz () gmx ! at>
Date: 2010-05-11 21:29:27
Message-ID: 20100511212927.AB67CAC8B3 () svn ! kde ! org
[Download RAW message or body]
SVN commit 1125640 by ppenz:
As the protocols list is available now in the editable mode of the URL navigator by \
clearing the line, the line-editor for the host can be removed now in the breadcrumb \
mode.
This bypasses some usability issues and defines a clear responsibility: The \
breadcrumb mode is for navigation only, the editable mode for editing.
As a nice side effect this simplifies the code a lot.
BUG: 194237
M +29 -118 kurlnavigator.cpp
M +0 -1 kurlnavigator.h
--- trunk/KDE/kdelibs/kfile/kurlnavigator.cpp #1125639:1125640
@@ -32,7 +32,6 @@
#include <kfileplacesmodel.h>
#include <kglobalsettings.h>
#include <kicon.h>
-#include <klineedit.h>
#include <klocale.h>
#include <kmenu.h>
#include <kprotocolinfo.h>
@@ -69,7 +68,6 @@
void initialize(const KUrl& url);
void slotReturnPressed();
- void slotRemoteHostActivated();
void slotProtocolChanged(const QString&);
void openPathSelectorMenu();
@@ -171,7 +169,6 @@
KUrlNavigatorPlacesSelector* m_placesSelector;
KUrlComboBox* m_pathBox;
KUrlNavigatorProtocolCombo* m_protocols;
- KLineEdit* m_host;
KUrlNavigatorDropDownButton* m_dropDownButton;
QList<KUrlNavigatorButton*> m_navButtons;
KUrlNavigatorButtonBase* m_toggleEditableMode;
@@ -191,7 +188,6 @@
m_placesSelector(0),
m_pathBox(0),
m_protocols(0),
- m_host(0),
m_dropDownButton(0),
m_navButtons(),
m_toggleEditableMode(0),
@@ -223,14 +219,6 @@
connect(m_protocols, SIGNAL(activated(QString)),
q, SLOT(slotProtocolChanged(QString)));
- // create editor for editing the host
- m_host = new KLineEdit(QString(), q);
- m_host->setClearButtonShown(true);
- connect(m_host, SIGNAL(editingFinished()),
- q, SLOT(slotRemoteHostActivated()));
- connect(m_host, SIGNAL(returnPressed()),
- q, SIGNAL(returnPressed()));
-
// create drop down button for accessing all paths of the URL
m_dropDownButton = new KUrlNavigatorDropDownButton(q);
connect(m_dropDownButton, SIGNAL(clicked()),
@@ -264,8 +252,6 @@
}
m_layout->addWidget(m_protocols);
m_layout->addWidget(m_dropDownButton);
- m_layout->addWidget(m_host);
- m_layout->setStretchFactor(m_host, 1);
m_layout->addWidget(m_pathBox, 1);
m_layout->addWidget(m_toggleEditableMode);
@@ -330,47 +316,19 @@
}
}
-void KUrlNavigator::Private::slotRemoteHostActivated()
-{
- KUrl currentUrl = q->locationUrl();
- const KUrl newUrl(m_protocols->currentProtocol() + "://" + m_host->text());
-
- const bool changed = newUrl.scheme() != currentUrl.scheme() ||
- newUrl.host() != currentUrl.host() ||
- newUrl.user() != currentUrl.user() ||
- newUrl.port() != currentUrl.port();
- if (changed) {
- currentUrl.setScheme(newUrl.scheme());
- currentUrl.setHost(newUrl.host());
- currentUrl.setUser(newUrl.user());
- currentUrl.setPort(newUrl.port());
- q->setLocationUrl(currentUrl);
- }
-}
-
void KUrlNavigator::Private::slotProtocolChanged(const QString& protocol)
{
KUrl url;
+ if (m_editable) {
url.setScheme(protocol);
url.setPath("/");
-
- if (m_editable) {
m_pathBox->setEditUrl(url);
- } else if (KProtocolInfo::protocolClass(protocol) == QLatin1String(":local")) {
- // No host is required, the URL can be applied immediately
- q->setLocationUrl(url);
} else {
- foreach (KUrlNavigatorButton* button, m_navButtons) {
- button->hide();
- button->deleteLater();
+ url = q->locationUrl();
+ url.setScheme(protocol);
+ q->setLocationUrl(url);
}
- m_navButtons.clear();
-
- m_host->setText(QString());
- m_host->show();
- m_host->setFocus();
}
-}
void KUrlNavigator::Private::openPathSelectorMenu()
{
@@ -513,8 +471,14 @@
void KUrlNavigator::Private::slotPathBoxChanged(const QString& text)
{
- m_protocols->setVisible(text.isEmpty());
+ if (text.isEmpty()) {
+ const QString protocol = q->locationUrl().scheme();
+ m_protocols->setProtocol(protocol);
+ m_protocols->show();
+ } else {
+ m_protocols->hide();
}
+}
void KUrlNavigator::Private::updateContent()
{
@@ -525,7 +489,6 @@
if (m_editable) {
m_protocols->hide();
- m_host->hide();
m_dropDownButton->hide();
deleteButtons();
@@ -535,21 +498,16 @@
m_pathBox->show();
m_pathBox->setUrl(currentUrl);
} else {
- m_dropDownButton->setVisible(!m_showFullPath);
m_pathBox->hide();
- QString path = currentUrl.pathOrUrl();
- removeTrailingSlash(path);
+ m_protocols->hide();
+ m_dropDownButton->setVisible(!m_showFullPath);
m_toggleEditableMode->setSizePolicy(QSizePolicy::Expanding, \
QSizePolicy::Preferred); q->setSizePolicy(QSizePolicy::Expanding, \
QSizePolicy::Fixed);
- // The URL consists of a protocol, a host and a variable number of \
directories.
- // The directories are mapped to URL navigator buttons represented by \
m_buttons.
- // - If a part of the URL is represented by a Places bookmark, this part \
will
- // be also represented as button if m_showFullPath is false.
- // - If no part of the URL is represented by a Places bookmark, a \
protocols-combo
- // and a host-editor will be shown if no subdirectories are available.
+ // Calculate the start index for the directories that should be shown as \
buttons + // and create the buttons
KUrl placeUrl;
if ((m_placesSelector != 0) && !m_showFullPath) {
placeUrl = m_placesSelector->selectedPlaceUrl();
@@ -558,38 +516,7 @@
QString placePath = placeUrl.isValid() ? placeUrl.pathOrUrl() : \
retrievePlacePath(); removeTrailingSlash(placePath);
- // update the protocol-combo
- const QString protocol = currentUrl.scheme();
- m_protocols->setProtocol(protocol);
-
- // update the host-editor
- QString hostText = currentUrl.host();
- if (!currentUrl.user().isEmpty()) {
- hostText = currentUrl.user() + '@' + hostText;
- }
- if (currentUrl.port() != -1) {
- hostText = hostText + ':' + QString::number(currentUrl.port());
- }
- m_host->setText(hostText);
-
- // check whether the protocol-combo and the host-editor should be shown
- const bool hasPlaceItem = currentUrl.isLocalFile() || placeUrl.isValid();
- const bool showProtocols = !hasPlaceItem &&
- (KProtocolInfo::protocolClass(protocol) != \
QLatin1String(":local"));
- const bool showHost = showProtocols && (placePath == path);
- m_protocols->setVisible(showProtocols);
- m_host->setVisible(showHost);
-
- // calculate the start index for the directories that should be shown as \
buttons
- // and create the buttons
- int startIndex = placePath.count('/');
- if (showHost) {
- // the host is shown by the line editor m_host and no button should be \
created
- ++startIndex;
- } else if (!hasPlaceItem && hostText.isEmpty()) {
- --startIndex;
- }
-
+ const int startIndex = placePath.count('/');
updateButtons(startIndex);
}
}
@@ -613,8 +540,8 @@
do {
createButton = (idx - startIndex >= oldButtonCount);
const bool isFirstButton = (idx == startIndex);
- const QString dirName = path.section('/', idx, idx);
- hasNext = (isFirstButton && !m_host->isVisible()) || !dirName.isEmpty();
+ const QString dirName = path.section(QLatin1Char('/'), idx, idx);
+ hasNext = isFirstButton || !dirName.isEmpty();
if (hasNext) {
QString text;
if (isFirstButton) {
@@ -626,14 +553,9 @@
}
if (text.isEmpty()) {
if (currentUrl.isLocalFile()) {
- text = m_showFullPath ? "/" : i18n("Custom Path");
- } else if (!m_host->isVisible() && !m_host->text().isEmpty()) {
- text = m_host->text();
+ text = m_showFullPath ? QLatin1String("/") : i18n("Custom \
Path"); } else {
- // The host is already displayed by the m_host widget,
- // no button may be added for this index.
- ++idx;
- continue;
+ text = currentUrl.protocol() + QLatin1String(": ") + \
currentUrl.host(); }
}
}
@@ -664,7 +586,7 @@
}
++idx;
- button->setActiveSubDirectory(path.section('/', idx, idx));
+ button->setActiveSubDirectory(path.section(QLatin1Char('/'), idx, idx));
}
} while (hasNext);
@@ -697,7 +619,7 @@
return;
}
- // subtract all widgets from the available width, that must be shown anyway
+ // Subtract all widgets from the available width, that must be shown anyway
int availableWidth = q->width() - m_toggleEditableMode->minimumWidth();
if ((m_placesSelector != 0) && m_placesSelector->isVisible()) {
@@ -708,11 +630,7 @@
availableWidth -= m_protocols->width();
}
- if (m_host->isVisible()) {
- availableWidth -= m_host->width();
- }
-
- // check whether buttons must be hidden at all...
+ // Check whether buttons must be hidden at all...
int requiredButtonWidth = 0;
foreach (const KUrlNavigatorButton* button, m_navButtons) {
requiredButtonWidth += button->minimumWidth();
@@ -725,7 +643,7 @@
availableWidth -= m_dropDownButton->width();
}
- // hide buttons...
+ // Hide buttons...
QList<KUrlNavigatorButton*>::const_iterator it = m_navButtons.constEnd();
const QList<KUrlNavigatorButton*>::const_iterator itBegin = \
m_navButtons.constBegin(); bool isLastButton = true;
@@ -751,7 +669,7 @@
isLastButton = false;
}
- // all buttons have the correct activation state and
+ // All buttons have the correct activation state and
// can be shown now
foreach (KUrlNavigatorButton* button, buttonsToShow) {
button->show();
@@ -761,10 +679,9 @@
m_dropDownButton->show();
} else {
// Check whether going upwards is possible. If this is the case, show the \
drop-down button.
- const KUrl url = m_navButtons.front()->url();
- const bool visible = (url != url.upUrl()) &&
- (url.protocol() != "nepomuksearch") &&
- !m_protocols->isVisible();
+ KUrl url = m_navButtons.front()->url();
+ url.adjustPath(KUrl::AddTrailingSlash);
+ const bool visible = !url.equals(url.upUrl()) && (url.protocol() != \
"nepomuksearch"); m_dropDownButton->setVisible(visible);
}
}
@@ -775,7 +692,7 @@
index = 0;
}
- // keep scheme, hostname etc. as this is needed for e. g. browsing
+ // Keep scheme, hostname etc. as this is needed for e. g. browsing
// FTP directories
const KUrl currentUrl = q->locationUrl();
KUrl newUrl = currentUrl;
@@ -1042,12 +959,8 @@
KUrl KUrlNavigator::uncommittedUrl() const
{
- if (isUrlEditable()) {
return KUrl(d->m_pathBox->currentText().trimmed());
- } else {
- return KUrl(d->m_protocols->currentProtocol() + "://" + d->m_host->text());
}
-}
void KUrlNavigator::setLocationUrl(const KUrl& newUrl)
{
@@ -1144,8 +1057,6 @@
{
if (isUrlEditable()) {
d->m_pathBox->setFocus();
- } else if (d->m_host) {
- d->m_host->setFocus();
} else {
QWidget::setFocus();
}
--- trunk/KDE/kdelibs/kfile/kurlnavigator.h #1125639:1125640
@@ -442,7 +442,6 @@
private:
Q_PRIVATE_SLOT(d, void slotReturnPressed())
- Q_PRIVATE_SLOT(d, void slotRemoteHostActivated())
Q_PRIVATE_SLOT(d, void slotProtocolChanged(const QString& protocol))
Q_PRIVATE_SLOT(d, void switchView())
Q_PRIVATE_SLOT(d, void dropUrls(const KUrl& destination, QDropEvent*))
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic