Commit ce48e250 authored by Daniel Teske's avatar Daniel Teske
Browse files

Add support for MMB clicks on back/forward, up and home toolbar icons.

Also works in the back/forward dropdown menus and in the go menu.
Either opens a new tab or a new window. NewTabInFront and the Shift
button determine wheter the new tab is in front.
Tabs openend by back/forward and up respect openAfterCurrentTab, Home not.
The history is copied for back and forward.
(And Ctrl+Left support.)

svn path=/trunk/kdebase/konqueror/; revision=379899
parent 321a9b44
......@@ -429,7 +429,7 @@ QString KonqMainWindow::detectNameFilter( QString & url )
return nameFilter;
}
void KonqMainWindow::openFilteredURL( const QString & _url, bool inNewTab, bool tempFile )
void KonqMainWindow::openFilteredURL( const QString & _url, const KonqOpenURLRequest & _req)
{
QString url = _url;
QString nameFilter = detectNameFilter( url );
......@@ -456,14 +456,8 @@ void KonqMainWindow::openFilteredURL( const QString & _url, bool inNewTab, bool
}
m_currentDir = QString::null;
// Remember the initial (typed) URL
KonqOpenURLRequest req( _url );
KonqOpenURLRequest req( _req );
req.nameFilter = nameFilter;
req.newTab = inNewTab;
req.newTabInFront = true;
req.tempFile = tempFile;
req.openAfterCurrentPage = false;
openURL( 0L, filteredURL, QString::null, req );
// #4070: Give focus to view after URL was entered manually
......@@ -474,6 +468,16 @@ void KonqMainWindow::openFilteredURL( const QString & _url, bool inNewTab, bool
}
void KonqMainWindow::openFilteredURL( const QString & _url, bool inNewTab, bool tempFile )
{
KonqOpenURLRequest req( _url );
req.newTab = inNewTab;
req.newTabInFront = true;
req.tempFile = tempFile;
openFilteredURL( _url, req );
}
void KonqMainWindow::openURL( KonqView *_view, const KURL &_url,
const QString &_serviceType, KonqOpenURLRequest& req,
bool trustedSource )
......@@ -1769,14 +1773,44 @@ void KonqMainWindow::slotReloadPopup()
slotReload( m_pWorkingTab->activeChildView() );
}
void KonqMainWindow::slotHome()
void KonqMainWindow::slotHome(KAction::ActivationReason, Qt::ButtonState state)
{
QString homeURL = m_pViewManager->profileHomeURL();
QString homeURL = m_pViewManager->profileHomeURL();
if (homeURL.isEmpty())
homeURL = KonqFMSettings::settings()->homeURL();
if (homeURL.isEmpty())
homeURL = KonqFMSettings::settings()->homeURL();
openURL( 0L, KURL( KonqMisc::konqFilteredURL( this, homeURL ) ) );
KConfig *config = KGlobal::config();
KConfigGroupSaver cs( config, QString::fromLatin1("FMSettings") );
bool mmbOpensTab = config->readBoolEntry( "MMBOpensTab", false );
KonqOpenURLRequest req;
req.newTab = true;
req.newTabInFront = config->readBoolEntry( "NewTabsInFront", false ) ;
if (state & Qt::ShiftButton)
req.newTabInFront = !req.newTabInFront;
if( state & Qt::ControlButton ) // Ctrl Left/MMB
openFilteredURL( homeURL, req);
else if( state & Qt::MidButton )
{
if(mmbOpensTab)
openFilteredURL( homeURL, req);
else
{
KURL finalURL = KonqMisc::konqFilteredURL( this, homeURL );
KonqMisc::createNewWindow( finalURL.url() );
}
}
else
openFilteredURL( homeURL, false );
}
void KonqMainWindow::slotHome()
{
slotHome(KAction::UnknownActivation, Qt::LeftButton);
}
void KonqMainWindow::slotGoApplications()
......@@ -2949,14 +2983,46 @@ void KonqMainWindow::slotUpAboutToShow()
}
}
void KonqMainWindow::slotUp(KAction::ActivationReason, Qt::ButtonState state)
{
m_goState = state;
QTimer::singleShot( 0, this, SLOT( slotUpDelayed() ) );
}
void KonqMainWindow::slotUp()
{
QTimer::singleShot( 0, this, SLOT( slotUpDelayed() ) );
m_goState = Qt::LeftButton;
QTimer::singleShot( 0, this, SLOT( slotUpDelayed() ) );
}
void KonqMainWindow::slotUpDelayed()
{
openURL( 0L, m_currentView->upURL() );
KConfig *config = KGlobal::config();
KConfigGroupSaver cs( config, QString::fromLatin1("FMSettings") );
bool mmbOpensTab = config->readBoolEntry( "MMBOpensTab", false );
KonqOpenURLRequest req;
req.newTab = true;
req.openAfterCurrentPage = config->readBoolEntry( "OpenAfterCurrentPage", false );
req.newTabInFront = config->readBoolEntry( "NewTabsInFront", false ) ;
if (m_goState & Qt::ShiftButton)
req.newTabInFront = !req.newTabInFront;
const QString& url = m_currentView->upURL().url();
if(m_goState & Qt::ControlButton)
openFilteredURL(url, req );
else if(m_goState & Qt::MidButton)
{
if(mmbOpensTab)
openFilteredURL( url, req);
else
KonqMisc::createNewWindow( url );
}
else
openFilteredURL( url, false );
m_goState = Qt::LeftButton;
}
void KonqMainWindow::slotUpActivated( int id )
......@@ -2977,10 +3043,17 @@ void KonqMainWindow::slotGoMenuAboutToShow()
void KonqMainWindow::slotGoHistoryActivated( int steps )
{
slotGoHistoryActivated( steps, Qt::LeftButton );
}
void KonqMainWindow::slotGoHistoryActivated( int steps, Qt::ButtonState state )
{
kdDebug() <<"slotGoHistoryActivated( "<<steps<<", "<<state<<" )"<<endl;
if (!m_goBuffer)
{
// Only start 1 timer.
m_goBuffer = steps;
m_goState = state;
QTimer::singleShot( 0, this, SLOT(slotGoHistoryDelayed()));
}
}
......@@ -2988,12 +3061,43 @@ void KonqMainWindow::slotGoHistoryActivated( int steps )
void KonqMainWindow::slotGoHistoryDelayed()
{
if (!m_currentView) return;
int steps = m_goBuffer;
KConfig *config = KGlobal::config();
KConfigGroupSaver cs( config, QString::fromLatin1("FMSettings") );
bool openAfterCurrentPage = config->readBoolEntry( "OpenAfterCurrentPage", false );
bool mmbOpensTab = config->readBoolEntry( "MMBOpensTab", false );
bool inFront = config->readBoolEntry( "NewTabsInFront", false );
if(m_goState & Qt::ShiftButton)
inFront = !inFront;
if(m_goState & Qt::ControlButton)
{
KonqView * newView = m_pViewManager->addTabFromHistory( m_goBuffer, openAfterCurrentPage );
if (newView && inFront)
m_pViewManager->showTab( newView );
}
else if(m_goState & Qt::MidButton)
{
if(mmbOpensTab)
{
KonqView * newView = m_pViewManager->addTabFromHistory( m_goBuffer, openAfterCurrentPage );
if (newView && inFront)
m_pViewManager->showTab( newView );
}
else
KonqMisc::newWindowFromHistory(this->currentView(), m_goBuffer);
}
else
{
m_currentView->go( m_goBuffer );
makeViewsFollow(m_currentView->url(), KParts::URLArgs(),m_currentView->serviceType(),m_currentView);
}
m_goBuffer = 0;
m_currentView->go( steps );
makeViewsFollow(m_currentView->url(), KParts::URLArgs(),m_currentView->serviceType(),m_currentView);
m_goState = Qt::LeftButton;
}
void KonqMainWindow::slotBackAboutToShow()
{
m_paBack->popupMenu()->clear();
......@@ -3006,9 +3110,14 @@ void KonqMainWindow::slotBack()
slotGoHistoryActivated(-1);
}
void KonqMainWindow::slotBack(KAction::ActivationReason, Qt::ButtonState state)
{
slotGoHistoryActivated( -1, state );
}
void KonqMainWindow::slotBackActivated( int id )
{
slotGoHistoryActivated( -(m_paBack->popupMenu()->indexOf( id ) + 1) );
slotGoHistoryActivated( -(m_paBack->popupMenu()->indexOf( id ) + 1), m_paBack->popupMenu()->state());
}
void KonqMainWindow::slotForwardAboutToShow()
......@@ -3023,9 +3132,14 @@ void KonqMainWindow::slotForward()
slotGoHistoryActivated( 1 );
}
void KonqMainWindow::slotForward(KAction::ActivationReason, Qt::ButtonState state)
{
slotGoHistoryActivated( 1, state );
}
void KonqMainWindow::slotForwardActivated( int id )
{
slotGoHistoryActivated( m_paForward->popupMenu()->indexOf( id ) + 1 );
slotGoHistoryActivated( m_paForward->popupMenu()->indexOf( id ) + 1, m_paForward->popupMenu()->state() );
}
void KonqMainWindow::initCombo()
......@@ -3578,16 +3692,22 @@ void KonqMainWindow::initActions()
m_paLinkView = new KToggleAction( i18n( "Lin&k View"), 0, this, SLOT( slotLinkView() ), actionCollection(), "link" );
// Go menu
m_paUp = new KToolBarPopupAction( i18n( "&Up" ), "up", KStdAccel::shortcut(KStdAccel::Up), this, SLOT( slotUp() ), actionCollection(), "up" );
m_paUp = new KToolBarPopupAction( i18n( "&Up" ), "up", KStdAccel::shortcut(KStdAccel::Up), actionCollection(), "up" );
connect( m_paUp, SIGNAL( activated( KAction::ActivationReason, Qt::ButtonState) ), this,
SLOT( slotUp(KAction::ActivationReason, Qt::ButtonState) ) );
connect( m_paUp->popupMenu(), SIGNAL( aboutToShow() ), this, SLOT( slotUpAboutToShow() ) );
connect( m_paUp->popupMenu(), SIGNAL( activated( int ) ), this, SLOT( slotUpActivated( int ) ) );
QPair< KGuiItem, KGuiItem > backForward = KStdGuiItem::backAndForward();
m_paBack = new KToolBarPopupAction( backForward.first, KStdAccel::shortcut(KStdAccel::Back), this, SLOT( slotBack() ), actionCollection(), "back" );
m_paBack = new KToolBarPopupAction( backForward.first, KStdAccel::shortcut(KStdAccel::Back), 0, "", actionCollection(), "back" );
connect( m_paBack, SIGNAL( activated( KAction::ActivationReason, Qt::ButtonState) ), this,
SLOT( slotBack(KAction::ActivationReason, Qt::ButtonState) ) );
connect( m_paBack->popupMenu(), SIGNAL( aboutToShow() ), this, SLOT( slotBackAboutToShow() ) );
connect( m_paBack->popupMenu(), SIGNAL( activated( int ) ), this, SLOT( slotBackActivated( int ) ) );
m_paForward = new KToolBarPopupAction( backForward.second, KStdAccel::shortcut(KStdAccel::Forward), this, SLOT( slotForward() ), actionCollection(), "forward" );
m_paForward = new KToolBarPopupAction( backForward.second, KStdAccel::shortcut(KStdAccel::Forward), 0, "", actionCollection(), "forward" );
connect( m_paForward, SIGNAL( activated( KAction::ActivationReason, Qt::ButtonState) ), this,
SLOT( slotForward(KAction::ActivationReason, Qt::ButtonState) ) );
connect( m_paForward->popupMenu(), SIGNAL( aboutToShow() ), this, SLOT( slotForwardAboutToShow() ) );
connect( m_paForward->popupMenu(), SIGNAL( activated( int ) ), this, SLOT( slotForwardActivated( int ) ) );
......@@ -3595,7 +3715,9 @@ void KonqMainWindow::initActions()
connect( m_paHistory, SIGNAL( menuAboutToShow() ), this, SLOT( slotGoMenuAboutToShow() ) );
connect( m_paHistory, SIGNAL( activated( int ) ), this, SLOT( slotGoHistoryActivated( int ) ) );
m_paHome = new KAction( i18n( "Home URL" ), "gohome", KStdAccel::shortcut(KStdAccel::Home), this, SLOT( slotHome() ), actionCollection(), "home" );
m_paHome = new KAction( i18n( "Home URL" ), "gohome", KStdAccel::shortcut(KStdAccel::Home), actionCollection(), "home" );
connect( m_paHome, SIGNAL( activated( KAction::ActivationReason, Qt::ButtonState) ), this,
SLOT( slotHome(KAction::ActivationReason, Qt::ButtonState) ) );
(void) new KAction( i18n( "App&lications" ), 0, this, SLOT( slotGoApplications() ), actionCollection(), "go_applications" );
(void) new KAction( i18n( "&Storage Media" ), 0, this, SLOT( slotGoMedia() ), actionCollection(), "go_media" );
......
......@@ -103,6 +103,12 @@ public:
KonqMainWindow( const KURL &initialURL = KURL(), bool openInitialURL = true, const char *name = 0, const QString& xmluiFile="konqueror.rc");
~KonqMainWindow();
/**
* Filters the URL and calls the main openURL method.
*/
void openFilteredURL( const QString & _url, const KonqOpenURLRequest& _req);
/**
* Filters the URL and calls the main openURL method.
*/
......@@ -169,7 +175,7 @@ public:
const MapViews & viewMap() const { return m_mapViews; }
KonqView *currentView() const { return m_currentView; }
KParts::ReadOnlyPart *currentPart() const;
/** URL of current part, or URLs of selected items for directory views */
......@@ -369,10 +375,14 @@ public slots:
// Go menu
void slotUp();
void slotUp(KAction::ActivationReason, Qt::ButtonState state);
void slotUpDelayed();
void slotBack();
void slotBack(KAction::ActivationReason, Qt::ButtonState state);
void slotForward();
void slotForward(KAction::ActivationReason, Qt::ButtonState state);
void slotHome();
void slotHome(KAction::ActivationReason, Qt::ButtonState state);
void slotGoApplications();
void slotGoMedia();
void slotGoSettings();
......@@ -402,6 +412,7 @@ public slots:
virtual void setIcon( const QPixmap& );
void slotGoHistoryActivated( int steps );
void slotGoHistoryActivated( int steps, Qt::ButtonState state );
void slotAddTab();
......@@ -672,6 +683,7 @@ private:
uint m_bViewModeToggled:1;
int m_goBuffer;
Qt::ButtonState m_goState;
MapViews m_mapViews;
......
......@@ -97,7 +97,7 @@ KonqMainWindow * KonqMisc::createSimpleWindow( const KURL & url, const KParts::U
return win;
}
KonqMainWindow * KonqMisc::createNewWindow( const KURL &url, const KParts::URLArgs &args, bool forbidUseHTML, QStringList filesToSelect, bool tempFile )
KonqMainWindow * KonqMisc::createNewWindow( const KURL &url, const KParts::URLArgs &args, bool forbidUseHTML, QStringList filesToSelect, bool tempFile, bool openURL )
{
kdDebug() << "KonqMisc::createNewWindow url=" << url << endl;
......@@ -107,10 +107,12 @@ KonqMainWindow * KonqMisc::createNewWindow( const KURL &url, const KParts::URLAr
? "webbrowsing" : "filemanagement";
QString profile = locate( "data", QString::fromLatin1("konqueror/profiles/") + profileName );
return createBrowserWindowFromProfile( profile, profileName, url, args, forbidUseHTML, filesToSelect, tempFile );
return createBrowserWindowFromProfile(profile, profileName,
url, args,
forbidUseHTML, filesToSelect, tempFile, openURL );
}
KonqMainWindow * KonqMisc::createBrowserWindowFromProfile( const QString &path, const QString &filename, const KURL &url, const KParts::URLArgs &args, bool forbidUseHTML, const QStringList& filesToSelect, bool tempFile )
KonqMainWindow * KonqMisc::createBrowserWindowFromProfile( const QString &path, const QString &filename, const KURL &url, const KParts::URLArgs &args, bool forbidUseHTML, const QStringList& filesToSelect, bool tempFile, bool openURL )
{
kdDebug(1202) << "void KonqMisc::createBrowserWindowFromProfile() " << endl;
kdDebug(1202) << "path=" << path << ",filename=" << filename << ",url=" << url.prettyURL() << endl;
......@@ -154,13 +156,37 @@ KonqMainWindow * KonqMisc::createBrowserWindowFromProfile( const QString &path,
req.args = args;
req.filesToSelect = filesToSelect;
req.tempFile = tempFile;
mainWindow->viewManager()->loadViewProfile( cfg, filename, url, req );
mainWindow->viewManager()->loadViewProfile( cfg, filename, url, req, false, openURL );
}
mainWindow->setInitialFrameName( args.frameName );
mainWindow->show();
return mainWindow;
}
KonqMainWindow * KonqMisc::newWindowFromHistory( KonqView* view, int steps )
{
int oldPos = view->historyPos();
int newPos = oldPos + steps;
const HistoryEntry * he = view->historyAt(newPos);
if(!he)
return 0L;
KonqMainWindow* mainwindow = createNewWindow(he->url, KParts::URLArgs(),
false, QStringList(), false, /*openURL*/false);
if(!mainwindow)
return 0L;
KonqView* newView = mainwindow->currentView();
if(!newView)
return 0L;
newView->copyHistory(view);
newView->setHistoryPos(newPos);
newView->restoreHistory();
return mainwindow;
}
QString KonqMisc::konqFilteredURL( QWidget* parent, const QString& _url, const QString& _path )
{
if ( !_url.startsWith( "about:" ) ) // Don't filter "about:" URLs
......
......@@ -26,6 +26,7 @@
#include <krun.h>
#include <kparts/browserextension.h>
class KonqMainWindow;
class KonqView;
class KonqMisc
{
......@@ -58,22 +59,26 @@ public:
/**
* Create a new window with a single view, showing @p url, using @p args
*/
static KonqMainWindow * createSimpleWindow( const KURL &url, const KParts::URLArgs &args, bool tempFile = false );
static KonqMainWindow * createSimpleWindow( const KURL &url, const KParts::URLArgs &args,
bool tempFile = false);
/**
* Create a new window for @p url using @p args and the appropriate profile for this URL.
* @param forbidUseHTML internal. True when called by "Find Files"
* @param openURL If it is false, no url is openend in the new window. The url is used to guess the profile
*/
static KonqMainWindow * createNewWindow( const KURL &url,
const KParts::URLArgs &args = KParts::URLArgs(),
bool forbidUseHTML = false,
QStringList filesToSelect = QStringList(),
bool tempFile = false );
bool tempFile = false,
bool openURL = true);
/**
* Create a new window from the profile defined by @p filename and @p path.
* @param url an optionnal URL to open in this profile.
* @param forbidUseHTML internal. True when called by "Find Files"
* @param openURL If false no url is opened
*/
static KonqMainWindow * createBrowserWindowFromProfile( const QString &path,
const QString &filename,
......@@ -81,7 +86,16 @@ public:
const KParts::URLArgs &args = KParts::URLArgs(),
bool forbidUseHTML = false,
const QStringList& filesToSelect = QStringList(),
bool tempFile = false );
bool tempFile = false,
bool openURL = true);
/**
* Creates a new window from the history of a view, copies the history
* @param view the History is copied from this view
* @param steps Restore currentPos() + steps
*/
static KonqMainWindow * newWindowFromHistory( KonqView* view, int steps );
/**
* Applies the URI filters to @p url.
*
......
......@@ -801,7 +801,12 @@ void KonqView::go( int steps )
kdDebug(1202) << "New position " << m_lstHistory.at() << endl;
#endif
HistoryEntry h( *currentHistoryEntry ); // make a copy of the current history entry, as the data
restoreHistory();
}
void KonqView::restoreHistory()
{
HistoryEntry h( *(m_lstHistory.current()) ); // make a copy of the current history entry, as the data
// the pointer points to will change with the following calls
#ifdef DEBUG_HISTORY
......@@ -845,6 +850,16 @@ void KonqView::go( int steps )
#endif
}
const HistoryEntry * KonqView::historyAt(const int pos)
{
if(pos<0 || pos>=(int)m_lstHistory.count())
return 0L;
int oldpos = m_lstHistory.at();
const HistoryEntry* h = m_lstHistory.at(pos);
m_lstHistory.at( oldpos );
return h;
}
void KonqView::copyHistory( KonqView *other )
{
m_lstHistory.clear();
......@@ -852,6 +867,7 @@ void KonqView::copyHistory( KonqView *other )
QPtrListIterator<HistoryEntry> it( other->m_lstHistory );
for (; it.current(); ++it )
m_lstHistory.append( new HistoryEntry( *it.current() ) );
m_lstHistory.at(other->m_lstHistory.at());
}
KURL KonqView::url() const
......
......@@ -131,6 +131,11 @@ public:
*/
bool canGoForward()const { return m_lstHistory.at() != ((int)m_lstHistory.count())-1; }
/**
* @return the position in the history
*/
int historyPos() const { return m_lstHistory.at(); }
uint historyLength() { return m_lstHistory.count(); }
/**
......@@ -138,11 +143,23 @@ public:
*/
void go( int steps );
/**
* Helper function for go() and KonqViewManager
*/
void restoreHistory();
void setHistoryPos(int newPos) { m_lstHistory.at( newPos ); }
/**
* @return the history of this view
*/
const QPtrList<HistoryEntry> & history() { return m_lstHistory; }
/**
* @return the HistoryEntry at postion @p pos
*/
const HistoryEntry* historyAt(const int pos);
/**
* Creates a deep copy of the @p other view's history buffers.
*/
......
......@@ -348,6 +348,42 @@ KonqView* KonqViewManager::addTab(const QString &serviceType, const QString &ser
return childView;
}
KonqView* KonqViewManager::addTabFromHistory( int steps, bool openAfterCurrentPage )
{
if (m_pDocContainer == 0L)
{
if (m_pMainWindow &&
m_pMainWindow->currentView() &&
m_pMainWindow->currentView()->frame()) {
m_pDocContainer = m_pMainWindow->currentView()->frame();
} else {
kdDebug(1202) << "This view profile does not support tabs." << endl;
return 0L;
}
}
if (m_pDocContainer->frameType() != "Tabs") convertDocContainer();
int oldPos = m_pMainWindow->currentView()->historyPos();
int newPos = oldPos + steps;
const HistoryEntry * he = m_pMainWindow->currentView()->historyAt(newPos);
if(!he)
return 0L;
KonqView* newView = 0L;
newView = addTab( he->strServiceType, he->strServiceName, false, openAfterCurrentPage );
if(!newView)
return 0L;
newView->copyHistory(m_pMainWindow->currentView());
newView->setHistoryPos(newPos);
newView->restoreHistory();
return newView;
}
void KonqViewManager::duplicateTab( KonqFrameBase* tab, bool openAfterCurrentPage )
{
#ifdef DEBUG_VIEWMGR
......@@ -1079,17 +1115,17 @@ void KonqViewManager::saveViewProfile( KConfig & cfg, bool saveURLs, bool saveWi
void KonqViewManager::loadViewProfile( const QString & path, const QString & filename,
const KURL & forcedURL, const KonqOpenURLRequest &req,
bool resetWindow )
bool resetWindow, bool openURL )
{
KConfig cfg( path, true );
cfg.setDollarExpansion( true );
cfg.setGroup( "Profile" );
loadViewProfile( cfg, filename, forcedURL, req, resetWindow );
loadViewProfile( cfg, filename, forcedURL, req, resetWindow, openURL );
}
void KonqViewManager::loadViewProfile( KConfig &cfg, const QString & filename,
const KURL & forcedURL, const KonqOpenURLRequest &req,
bool resetWindow )
bool resetWindow, bool openURL )
{
if ( docContainer() && docContainer()->frameType()=="Tabs" )
{
......@@ -1165,7 +1201,7 @@ void KonqViewManager::loadViewProfile( KConfig &cfg, const QString & filename,
// from profile loading (e.g. in switchView)
m_bLoadingProfile = true;
loadItem( cfg, m_pMainWindow, rootItem, defaultURL, forcedURL.isEmpty() );
loadItem( cfg, m_pMainWindow, rootItem, defaultURL, openURL && forcedURL.isEmpty() );
m_bLoadingProfile = false;
......@@ -1211,7 +1247,7 @@ void KonqViewManager::loadViewProfile( KConfig &cfg, const QString & filename,
nextChildView->setViewName( req.args.frameName );
}
if ( !forcedURL.isEmpty())
if ( openURL && !forcedURL.isEmpty())
{
KonqOpenURLRequest _req(req);
KConfig *config = KGlobal::config();
......