/***************************************************************************
- * Copyright (C) 2006 by Peter Penz *
- * peter.penz@gmx.at *
+ * Copyright (C) 2006 by Peter Penz (peter.penz@gmx.at) *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
***************************************************************************/
+#include "bookmarkselector.h"
#include <assert.h>
#include <q3popupmenu.h>
#include <kglobalsettings.h>
#include <kbookmarkmanager.h>
-#include "bookmarkselector.h"
#include "dolphinsettings.h"
-#include "dolphinview.h"
-#include "dolphinmainwindow.h"
#include "urlnavigator.h"
BookmarkSelector::BookmarkSelector(UrlNavigator* parent) :
UrlButton(parent),
- m_selectedIndex(0)
+ m_selectedIndex(0),
+ m_urlNavigator(parent)
{
setFocusPolicy(Qt::NoFocus);
return QSize(height, height);
}
-void BookmarkSelector::paintEvent(QPaintEvent* event)
+void BookmarkSelector::paintEvent(QPaintEvent* /*event*/)
{
QPainter painter(this);
}
// dimm the colors if the parent view does not have the focus
- const DolphinView* parentView = urlNavigator()->dolphinView();
- const DolphinMainWindow* dolphin = parentView->mainWindow();
-
- const bool isActive = (dolphin->activeView() == parentView);
+ const bool isActive = m_urlNavigator->isActive();
if (!isActive) {
QColor dimmColor(palette().brush(QPalette::Background).color());
foregroundColor = mixColors(foregroundColor, dimmColor);
{
m_selectedIndex = index;
- KBookmark bookmark = selectedBookmark();
+ const KBookmark bookmark = selectedBookmark();
setPixmap(SmallIcon(bookmark.icon()));
-
- emit bookmarkActivated(index);
+ emit bookmarkActivated(bookmark.url());
}
#include "bookmarkselector.moc"
/***************************************************************************
- * Copyright (C) 2006 by Peter Penz *
- * peter.penz@gmx.at *
+ * Copyright (C) 2006 by Peter Penz (peter.penz@gmx.at) *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* inside the bookmark selector.
*
* @see UrlNavigator
- * @author Peter Penz <peter.penz@gmx.at>
*/
class BookmarkSelector : public UrlButton
{
signals:
/**
* Is send when a bookmark has been activated by the user.
- * @param index Index of the selected bookmark.
+ * @param url URL of the selected bookmark.
*/
- void bookmarkActivated(int index);
+ void bookmarkActivated(const KUrl& url);
protected:
/**
private:
int m_selectedIndex;
+ UrlNavigator* m_urlNavigator;
Q3PopupMenu* m_bookmarksMenu;
};
setActiveView(m_view[PrimaryIdx]);\r
}\r
}\r
+ emit activeViewChanged();\r
}\r
\r
void DolphinMainWindow::reloadView()\r
m_topLayout->setSpacing(0);
m_topLayout->setMargin(0);
+ connect(m_mainWindow, SIGNAL(activeViewChanged()),
+ this, SLOT(updateActivationState()));
+
m_urlNavigator = new UrlNavigator(url, this);
connect(m_urlNavigator, SIGNAL(urlChanged(const KUrl&)),
this, SLOT(loadDirectory(const KUrl&)));
+ connect(m_urlNavigator, SIGNAL(urlsDropped(const KUrl::List&, const KUrl&)),
+ this, SLOT(dropUrls(const KUrl::List&, const KUrl&)));
+ connect(m_urlNavigator, SIGNAL(activated()),
+ this, SLOT(requestActivation()));
+ connect(this, SIGNAL(contentsMoved(int, int)),
+ m_urlNavigator, SLOT(storeContentsPosition(int, int)));
m_statusBar = new DolphinStatusBar(this);
bool DolphinView::isActive() const
{
- return (mainWindow()->activeView() == this);
+ return m_mainWindow->activeView() == this;
}
void DolphinView::setMode(Mode mode)
startDirLister(m_urlNavigator->url(), true);
}
-void DolphinView::declareViewActive()
-{
- mainWindow()->setActiveView( this );
-}
-
void DolphinView::mouseReleaseEvent(QMouseEvent* event)
{
QWidget::mouseReleaseEvent(event);
const KUrl& destination = (directory == 0) ? url() :
directory->url();
+ dropUrls(urls, destination);
+}
+
+void DolphinView::dropUrls(const KUrl::List& urls,
+ const KUrl& destination)
+{
m_mainWindow->dropUrls(urls, destination);
}
+
void DolphinView::updateSorting(DolphinView::Sorting sorting)
{
ViewProperties props(url());
emit contentsMoved(contentsX(), contentsY());
}
+void DolphinView::updateActivationState()
+{
+ m_urlNavigator->setActive(isActive());
+}
+
void DolphinView::createView()
{
// delete current view
/** Reloads the current directory. */
void reload();
- /**
- * Declare this View as the activeview of the mainWindow()
- */
- void declareViewActive();
-
public slots:
/**
* Popups the filter bar above the status bar if \a show is true.
void dropUrls(const KUrl::List& urls,
const QPoint& pos);
+ /**
+ * Drops the URLs \a urls at the
+ * destination \a destination.
+ */
+ void dropUrls(const KUrl::List& urls,
+ const KUrl& destination);
/**
* Updates the view properties of the current URL to the
* sorting given by \a sorting.
*/
void emitContentsMoved();
+ /**
+ * Updates the activation state of the view by checking whether
+ * the currently active view is this view.
+ */
+ void updateActivationState();
+
private:
void startDirLister(const KUrl& url, bool reload = false);
#include "dolphinmainwindow.h"
-UrlButton::UrlButton(UrlNavigator* parent)
-: QPushButton(parent),
- m_displayHint(0),
- m_urlNavigator(parent)
+UrlButton::UrlButton(UrlNavigator* parent) :
+ QPushButton(parent),
+ m_displayHint(0),
+ m_urlNavigator(parent)
{
setFocusPolicy(Qt::NoFocus);
setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Fixed);
setMinimumHeight(parent->minimumHeight());
- connect(this, SIGNAL(clicked()), parent, SLOT(slotRequestActivation()));
- connect(parent->dolphinView()->mainWindow(), SIGNAL(activeViewChanged()),
- this, SLOT(update()));
+ connect(this, SIGNAL(clicked()), parent, SLOT(requestActivation()));
}
UrlButton::~UrlButton()
{
}
-UrlNavigator* UrlButton::urlNavigator() const
-{
- return m_urlNavigator;
-}
-
void UrlButton::setDisplayHintEnabled(DisplayHint hint,
bool enable)
{
explicit UrlButton(UrlNavigator* parent);
virtual ~UrlButton();
- UrlNavigator* urlNavigator() const;
+ UrlNavigator* urlNavigator() const { return m_urlNavigator; }
protected:
enum DisplayHint {
#include <qsizepolicy.h>
#include <qtooltip.h>
//Added by qt3to4:
+#include <QDir>
#include <Q3ValueList>
#include <QKeyEvent>
#include <QCheckBox>
#include <kactioncollection.h>
#include <kiconloader.h>
#include <kio/job.h>
+#include <kfileitem.h>
#include <klocale.h>
#include <kprotocolinfo.h>
#include <kurl.h>
#include <kvbox.h>
#include "bookmarkselector.h"
-#include "dolphinmainwindow.h"
#include "dolphinsettings.h"
-#include "dolphinstatusbar.h"
-#include "dolphinview.h"
#include "generalsettings.h"
#include "protocolcombo.h"
#include "urlnavigatorbutton.h"
-UrlNavigator::HistoryElem::HistoryElem()
- : m_url(),
+UrlNavigator::HistoryElem::HistoryElem() :
+ m_url(),
m_currentFileName(),
m_contentsX(0),
m_contentsY(0)
{
}
-UrlNavigator::HistoryElem::HistoryElem(const KUrl& url)
- : m_url(url),
+UrlNavigator::HistoryElem::HistoryElem(const KUrl& url) :
+ m_url(url),
m_currentFileName(),
m_contentsX(0),
m_contentsY(0)
}
UrlNavigator::UrlNavigator(const KUrl& url,
- DolphinView* dolphinView) :
- KHBox(dolphinView),
+ QWidget* parent) :
+ KHBox(parent),
+ m_active(true),
m_historyIndex(0),
- m_dolphinView(dolphinView),
m_protocols(0),
m_protocolSeparator(0),
m_host(0)
}
m_bookmarkSelector = new BookmarkSelector(this);
- connect(m_bookmarkSelector, SIGNAL(bookmarkActivated(int)),
- this, SLOT(slotBookmarkActivated(int)));
+ connect(m_bookmarkSelector, SIGNAL(bookmarkActivated(const KUrl&)),
+ this, SLOT(setUrl(const KUrl&)));
m_pathBox = new KUrlComboBox(KUrlComboBox::Directories, true, this);
connect(m_pathBox, SIGNAL(urlActivated(const KUrl&)),
this, SLOT(slotUrlActivated(const KUrl&)));
- connect(dolphinView, SIGNAL(contentsMoved(int, int)),
- this, SLOT(slotContentsMoved(int, int)));
- connect(dolphinView, SIGNAL(redirection(const KUrl&, const KUrl&)),
- this, SLOT(slotRedirection(const KUrl&, const KUrl&)));
-/* connect(dolphinView, SIGNAL(redirection(const KUrl&)),
- this, SLOT(slotRedirection(const KUrl&)));*/
+ //connect(dolphinView, SIGNAL(redirection(const KUrl&, const KUrl&)),
+ // this, SLOT(slotRedirection(const KUrl&, const KUrl&)));
updateContent();
}
{
}
-void UrlNavigator::setUrl(const KUrl& url)
-{
- QString urlStr(url.pathOrUrl());
- //kDebug() << "setUrl(" << url << ")" << endl;
- if ( urlStr.length() > 0 && urlStr.at(0) == '~') {
- // replace '~' by the home directory
- urlStr.remove(0, 1);
- urlStr.insert(0, QDir::home().path());
- }
-
- const KUrl transformedUrl(urlStr);
-
- if (m_historyIndex > 0) {
- // Check whether the previous element of the history has the same Url.
- // If yes, just go forward instead of inserting a duplicate history
- // element.
- const KUrl& nextUrl = m_history[m_historyIndex - 1].url();
- if (transformedUrl == nextUrl) {
- goForward();
-// kDebug() << "goin' forward in history" << endl;
- return;
- }
- }
-
- const KUrl& currUrl = m_history[m_historyIndex].url();
- if (currUrl == transformedUrl) {
- // don't insert duplicate history elements
-// kDebug() << "currUrl == transformedUrl" << endl;
- return;
- }
-
- updateHistoryElem();
-
- const Q3ValueListIterator<UrlNavigator::HistoryElem> it = m_history.at(m_historyIndex);
- m_history.insert(it, HistoryElem(transformedUrl));
-
- updateContent();
-
- emit urlChanged(transformedUrl);
- emit historyChanged();
-
- // Prevent an endless growing of the history: remembering
- // the last 100 Urls should be enough...
- if (m_historyIndex > 100) {
- m_history.erase(m_history.begin());
- --m_historyIndex;
- }
-
-/* kDebug() << "history starting ====================" << endl;
- int i = 0;
- for (QValueListIterator<UrlNavigator::HistoryElem> it = m_history.begin();
- it != m_history.end();
- ++it, ++i)
- {
- kDebug() << i << ": " << (*it).url() << endl;
- }
- kDebug() << "history done ========================" << endl;*/
-}
-
const KUrl& UrlNavigator::url() const
{
assert(!m_history.empty());
}
}
-DolphinView* UrlNavigator::dolphinView() const
+void UrlNavigator::setActive(bool active)
+{
+ if (active != m_active) {
+ m_active = active;
+ update();
+ if (active) {
+ emit activated();
+ }
+ }
+}
+
+void UrlNavigator::dropUrls(const KUrl::List& urls,
+ const KUrl& destination)
+{
+ kDebug() << "------------------- URLS dropped" << endl;
+ emit urlsDropped(urls, destination);
+}
+
+void UrlNavigator::setUrl(const KUrl& url)
+{
+ QString urlStr(url.pathOrUrl());
+ //kDebug() << "setUrl(" << url << ")" << endl;
+ if ( urlStr.length() > 0 && urlStr.at(0) == '~') {
+ // replace '~' by the home directory
+ urlStr.remove(0, 1);
+ urlStr.insert(0, QDir::home().path());
+ }
+
+ const KUrl transformedUrl(urlStr);
+
+ if (m_historyIndex > 0) {
+ // Check whether the previous element of the history has the same Url.
+ // If yes, just go forward instead of inserting a duplicate history
+ // element.
+ const KUrl& nextUrl = m_history[m_historyIndex - 1].url();
+ if (transformedUrl == nextUrl) {
+ goForward();
+// kDebug() << "goin' forward in history" << endl;
+ return;
+ }
+ }
+
+ const KUrl& currUrl = m_history[m_historyIndex].url();
+ if (currUrl == transformedUrl) {
+ // don't insert duplicate history elements
+// kDebug() << "currUrl == transformedUrl" << endl;
+ return;
+ }
+
+ updateHistoryElem();
+
+ const Q3ValueListIterator<UrlNavigator::HistoryElem> it = m_history.at(m_historyIndex);
+ m_history.insert(it, HistoryElem(transformedUrl));
+
+ updateContent();
+
+ emit urlChanged(transformedUrl);
+ emit historyChanged();
+
+ // Prevent an endless growing of the history: remembering
+ // the last 100 Urls should be enough...
+ if (m_historyIndex > 100) {
+ m_history.erase(m_history.begin());
+ --m_historyIndex;
+ }
+
+/* kDebug() << "history starting ====================" << endl;
+ int i = 0;
+ for (QValueListIterator<UrlNavigator::HistoryElem> it = m_history.begin();
+ it != m_history.end();
+ ++it, ++i)
+ {
+ kDebug() << i << ": " << (*it).url() << endl;
+ }
+ kDebug() << "history done ========================" << endl;*/
+
+ requestActivation();
+}
+
+void UrlNavigator::requestActivation()
+{
+ kDebug() << "--------------------------- request activation" << endl;
+ setActive(true);
+}
+
+void UrlNavigator::storeContentsPosition(int x, int y)
{
- return m_dolphinView;
+ m_history[m_historyIndex].setContentsX(x);
+ m_history[m_historyIndex].setContentsY(y);
}
void UrlNavigator::keyReleaseEvent(QKeyEvent* event)
}
}
-void UrlNavigator::slotRequestActivation()
-{
- m_dolphinView->requestActivation();
-}
-
-void UrlNavigator::slotBookmarkActivated(int index)
-{
- m_dolphinView->statusBar()->clear();
- m_dolphinView->requestActivation();
-
- KBookmark bookmark = DolphinSettings::instance().bookmark(index);
- m_dolphinView->setUrl(bookmark.url());
-}
-
void UrlNavigator::slotRedirection(const KUrl& oldUrl, const KUrl& newUrl)
{
// kDebug() << "received redirection to " << newUrl << endl;
m_urls.append(newUrl);*/
}
-void UrlNavigator::slotContentsMoved(int x, int y)
-{
- m_history[m_historyIndex].setContentsX(x);
- m_history[m_historyIndex].setContentsY(y);
-}
-
void UrlNavigator::slotClicked()
{
if (isUrlEditable()) {
}
else {
setUrl(m_pathBox->currentText());
- m_dolphinView->setFocus();
+ emit requestActivation();
}
}
if (item != 0) {
m_history[m_historyIndex].setCurrentFileName(item->name());
}
- m_history[m_historyIndex].setContentsX(m_dolphinView->contentsX());
- m_history[m_historyIndex].setContentsY(m_dolphinView->contentsY());
}
void UrlNavigator::updateContent()
m_toggleButton->setToolTip(QString());
QString path(url().pathOrUrl());
- const QAction* action = dolphinView()->mainWindow()->actionCollection()->action("editable_location");
+
+ // TODO: prevent accessing the DolphinMainWindow out from this scope
+ //const QAction* action = dolphinView()->mainWindow()->actionCollection()->action("editable_location");
// TODO: registry of default shortcuts
- QString shortcut = action? action->shortcut().toString() : "Ctrl+L";
+ //QString shortcut = action? action->shortcut().toString() : "Ctrl+L";
+ const QString shortcut = "Ctrl+L";
+
if (m_toggleButton->isChecked()) {
delete m_protocols; m_protocols = 0;
delete m_protocolSeparator; m_protocolSeparator = 0;
delete m_host; m_host = 0;
- m_toggleButton->setToolTip(i18n("Browse (%1, Escape)",shortcut));
+ m_toggleButton->setToolTip(i18n("Browse (%1, Escape)", shortcut));
setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
m_pathBox->show();
m_pathBox->setUrl(url());
}
else {
- m_toggleButton->setToolTip(i18n("Edit location (%1)",shortcut));
+ m_toggleButton->setToolTip(i18n("Edit location (%1)", shortcut));
setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
m_pathBox->hide();
class KUrlComboBox;
class BookmarkSelector;
-class DolphinView;
class ProtocolCombo;
/**
int m_contentsY;
};
- UrlNavigator(const KUrl& url, DolphinView* dolphinView);
+ UrlNavigator(const KUrl& url, QWidget* parent);
virtual ~UrlNavigator();
- /**
- * Sets the current active Url.
- * The signals UrlNavigator::urlChanged and UrlNavigator::historyChanged
- * are submitted.
- */
- void setUrl(const KUrl& url);
-
/** Returns the current active Url. */
const KUrl& url() const;
*/
void editUrl(bool editOrBrowse); //TODO: switch to an enum
- DolphinView* dolphinView() const;
+ /**
+ * Set the URL navigator to the active mode, if \a active
+ * is true. The active mode is default. Using the URL navigator
+ * in the inactive mode is useful when having split views,
+ * where the inactive view is indicated by a an inactive URL
+ * navigator visually.
+ */
+ void setActive(bool active);
+
+ /**
+ * Returns true, if the URL navigator is in the active mode.
+ * @see UrlNavigator::setActive()
+ */
+ bool isActive() const { return m_active; }
+
+ /**
+ * Handles the dropping of the URLs \a urls to the given
+ * destination \a destination and emits the signal urlsDropped.
+ */
+ void dropUrls(const KUrl::List& urls,
+ const KUrl& destination);
+
+public slots:
+ /**
+ * Sets the current active URL.
+ * The signals UrlNavigator::urlChanged and UrlNavigator::historyChanged
+ * are submitted.
+ */
+ void setUrl(const KUrl& url);
+
+ /**
+ * Activates the URL navigator (UrlNavigator::isActive() will return true)
+ * and emits the signal 'activationChanged()'.
+ */
+ void requestActivation();
+
+ /**
+ * Stores the coordinates of the contents into
+ * the current history element.
+ */
+ void storeContentsPosition(int x, int y);
signals:
+ /**
+ * Is emitted, if the URL navigator has been activated by
+ * a user interaction.
+ */
+ void activated();
+
+ /**
+ * Is emitted, if the URL has been changed e. g. by
+ * the user.
+ * @see setUrl()
+ */
void urlChanged(const KUrl& url);
+
+ /**
+ * Is emitted, if the history has been changed. Usually
+ * the history is changed if a new URL has been selected.
+ */
void historyChanged();
+ /**
+ * Is emitted if the URLs \a urls have been dropped
+ * to the destination \a destination.
+ */
+ void urlsDropped(const KUrl::List& urls,
+ const KUrl& destination);
+
protected:
/** If the Escape key is pressed, the navigation bar should switch
to the browse mode. */
void slotUrlActivated(const KUrl& url);
void slotRemoteHostActivated();
void slotProtocolChanged(const QString& protocol);
-
- void slotRequestActivation();
- void slotBookmarkActivated(int index);
-
void slotRedirection(const KUrl&, const KUrl&);
- /**
- * Stores the coordinates of the moved content into
- * the current history element. Is usually triggered
- * by the signal 'contentsMoved' emitted by DolphinView.
- */
- void slotContentsMoved(int x, int y);
-
/**
* Switches the navigation bar between the editable and noneditable
* state (see setUrlEditable()) and is connected to the clicked signal
void slotClicked();
private:
+ bool m_active;
int m_historyIndex;
- DolphinView* m_dolphinView;
Q3ValueList<HistoryElem> m_history;
QCheckBox* m_toggleButton;
BookmarkSelector* m_bookmarkSelector;
***************************************************************************/
#include "urlnavigatorbutton.h"
-#include <qcursor.h>
-#include <qfontmetrics.h>
-#include <qpainter.h>
-#include <qtimer.h>
-#include <qtooltip.h>
-//Added by qt3to4:
-#include <QDropEvent>
-#include <QDragLeaveEvent>
-#include <Q3PopupMenu>
-#include <QEvent>
-#include <QDragEnterEvent>
+
+#include <assert.h>
+
+#include "urlnavigator.h"
#include <kglobalsettings.h>
#include <kiconloader.h>
+#include <kio/job.h>
#include <kio/jobclasses.h>
#include <klocale.h>
#include <kurl.h>
-#include <assert.h>
-#include "urlnavigator.h"
-#include "dolphinview.h"
-#include "dolphinmainwindow.h"
+#include <Q3PopupMenu>
+#include <QPainter>
+#include <QTimer>
UrlNavigatorButton::UrlNavigatorButton(int index, UrlNavigator* parent) :
UrlButton(parent),
m_index(-1),
+ m_popupDelay(0),
m_listJob(0)
{
setAcceptDrops(true);
}
// dimm the colors if the parent view does not have the focus
- const DolphinView* parentView = urlNavigator()->dolphinView();
- const DolphinMainWindow* dolphin = parentView->mainWindow();
-
- const bool isActive = (dolphin->activeView() == parentView);
+ const bool isActive = urlNavigator()->isActive();
if (!isActive) {
QColor dimmColor(palette().brush(QPalette::Background).color());
foregroundColor = mixColors(foregroundColor, dimmColor);
QString path(urlNavigator()->url().prettyUrl());
path = path.section('/', 0, m_index + 2);
- DolphinMainWindow* win = urlNavigator()->dolphinView()->mainWindow();
- win->dropUrls(urls, KUrl(path));
+ urlNavigator()->dropUrls(urls, KUrl(path));
setDisplayHintEnabled(DraggedHint, false);
update();
return;
}
- UrlNavigator* navigator = urlNavigator();
- assert(navigator != 0);
- navigator->setUrl(navigator->url(m_index));
+ urlNavigator()->setUrl(urlNavigator()->url(m_index));
}
void UrlNavigatorButton::startPopupDelay()
KIO::UDSEntryList::const_iterator itEnd = entries.constEnd();
while (it != itEnd) {
QString name;
- bool isDir = false;
+ //bool isDir = false;
KIO::UDSEntry entry = *it;
/* KDE3 reference:
#ifndef UrlNAVIGATORBUTTON_H
#define UrlNAVIGATORBUTTON_H
-#include <qstringlist.h>
-#include <QEvent>
-#include <QDragLeaveEvent>
-#include <QDropEvent>
-#include <QDragEnterEvent>
-
#include <kio/global.h>
-
#include <urlbutton.h>
+class KJob;
class KUrl;
class UrlNavigator;
class QPainter;
Q_OBJECT
public:
- explicit UrlNavigatorButton(int index, UrlNavigator* parent = 0);
+ explicit UrlNavigatorButton(int index, UrlNavigator* parent);
virtual ~UrlNavigatorButton();
void setIndex(int index);
int index() const { return m_index; }
int arrowWidth() const;
bool isTextClipped() const;
+private:
int m_index;
QTimer* m_popupDelay;
KIO::Job* m_listJob;