Commit 3e363170 authored by David Faure's avatar David Faure
Browse files

First round of cleanups, mainly of the view manager.

Always create the tab container (95% of the code paths would convert the container to a tab container after the fact,
so let's just do it before hand and simplify the code in many places). But create its popupmenu on demand.
Port all inherits() calls to qobject_cast.
Next step is to add unit tests, meanwhile shout if anything broke :)

svn path=/trunk/KDE/kdebase/apps/; revision=673169
parent 225459c8
......@@ -334,11 +334,10 @@ void KonqViewModeAction::slotPopupAboutToHide()
for (; i < containerCount(); ++i )
{
QWidget *widget = container( i );
if ( !widget->inherits( "KToolBar" ) )
KToolBar *tb = ::qobject_cast<KToolBar *>( widget );
if ( !tb )
continue;
KToolBar *tb = static_cast<KToolBar *>( widget );
KToolBarButton *button = tb->getButton( itemId( i ) );
button->setDown( isChecked() );
......
......@@ -34,7 +34,7 @@
#include <kdebug.h>
#include <klocale.h>
#include <kmessagebox.h>
#include <kmimetypetrader.h>
#include <kmimetypetrader.h>
#include <kparts/factory.h>
#include <kservicetypetrader.h>
#include <kdeversion.h>
......@@ -62,13 +62,14 @@ KParts::ReadOnlyPart *KonqViewFactory::create( QWidget *parentWidget, QObject *
QObject *obj = 0L;
if ( m_factory->inherits( "KParts::Factory" ) )
KParts::Factory* kpartsFactory = ::qobject_cast<KParts::Factory *>( m_factory );
if ( kpartsFactory )
{
if ( m_createBrowser )
obj = static_cast<KParts::Factory *>(m_factory)->createPart( parentWidget, parent, "Browser/View", m_args );
obj = kpartsFactory->createPart( parentWidget, parent, "Browser/View", m_args );
if ( !obj )
obj = static_cast<KParts::Factory *>(m_factory)->createPart( parentWidget, parent, "KParts::ReadOnlyPart", m_args );
obj = kpartsFactory->createPart( parentWidget, parent, "KParts::ReadOnlyPart", m_args );
}
else
{
......@@ -79,10 +80,10 @@ KParts::ReadOnlyPart *KonqViewFactory::create( QWidget *parentWidget, QObject *
obj = m_factory->create( parentWidget, "KParts::ReadOnlyPart", m_args );
}
if ( !obj->inherits( "KParts::ReadOnlyPart" ) ) {
KParts::ReadOnlyPart* part = ::qobject_cast<KParts::ReadOnlyPart *>( obj );
if ( !part ) {
kError(1202) << "Part " << obj << " (" << obj->metaObject()->className() << ") doesn't inherit KParts::ReadOnlyPart !" << endl;
} else {
KParts::ReadOnlyPart* part = static_cast<KParts::ReadOnlyPart *>( obj );
QFrame* frame = qobject_cast<QFrame*>( part->widget() );
if ( frame ) {
frame->setFrameStyle( QFrame::NoFrame );
......@@ -206,9 +207,9 @@ void KonqFactory::getOffers( const QString & serviceType,
{
#ifdef __GNUC__
#warning Temporary hack
#endif
#endif
if ( partServiceOffers && serviceType[0].isUpper() ) {
*partServiceOffers = KServiceTypeTrader::self()->query( serviceType,
*partServiceOffers = KServiceTypeTrader::self()->query( serviceType,
"DesktopEntryName != 'kfmclient' and DesktopEntryName != 'kfmclient_dir' and DesktopEntryName != 'kfmclient_html'");
return;
......
......@@ -235,7 +235,7 @@ void KonqFrameStatusBar::slotSpeedProgress( int bytesPerSecond )
QString sizeStr;
if ( bytesPerSecond > 0 )
sizeStr = i18n( "%1/s" , KIO::convertSize( bytesPerSecond ) );
sizeStr = i18n( "%1/s", KIO::convertSize( bytesPerSecond ) );
else
sizeStr = i18n( "Stalled" );
......@@ -244,7 +244,7 @@ void KonqFrameStatusBar::slotSpeedProgress( int bytesPerSecond )
void KonqFrameStatusBar::slotConnectToNewView(KonqView *, KParts::ReadOnlyPart *,KParts::ReadOnlyPart *newOne)
{
if (newOne!=0)
if (newOne)
connect(newOne,SIGNAL(setStatusBarText(const QString &)),this,SLOT(slotDisplayStatusText(const QString&)));
slotDisplayStatusText( QString() );
}
......@@ -372,14 +372,14 @@ KParts::ReadOnlyPart *KonqFrame::attach( const KonqViewFactory &viewFactory )
assert( m_pPart->widget() );
attachInternal();
attachWidget(m_pPart->widget());
m_pStatusBar->slotConnectToNewView(0, 0,m_pPart);
m_pStatusBar->slotConnectToNewView(0, 0, m_pPart);
return m_pPart;
}
void KonqFrame::attachInternal()
void KonqFrame::attachWidget(QWidget* widget)
{
//kDebug(1202) << "KonqFrame::attachInternal()" << endl;
delete m_pLayout;
......@@ -389,14 +389,13 @@ void KonqFrame::attachInternal()
m_pLayout->setMargin( 0 );
m_pLayout->setSpacing( 0 );
m_pLayout->addWidget( m_pPart->widget(), 1 );
m_pLayout->addWidget( widget, 1 );
m_pLayout->addWidget( m_pStatusBar, 0 );
m_pPart->widget()->show();
widget->show();
m_pLayout->activate();
m_pPart->widget()->installEventFilter(this);
widget->installEventFilter(this);
}
bool KonqFrame::eventFilter(QObject* /*obj*/, QEvent *ev)
......@@ -416,9 +415,9 @@ bool KonqFrame::eventFilter(QObject* /*obj*/, QEvent *ev)
void KonqFrame::insertTopWidget( QWidget * widget )
{
assert(m_pLayout);
assert(widget);
m_pLayout->insertWidget( 0, widget );
if (widget!=0)
widget->installEventFilter(this);
widget->installEventFilter(this);
}
void KonqFrame::setView( KonqView* child )
......
......@@ -63,9 +63,10 @@ class KonqCheckBox : public QCheckBox
{
Q_OBJECT // for classname
public:
KonqCheckBox(QWidget *parent=0)
:QCheckBox( parent ) {}
explicit KonqCheckBox(QWidget *parent=0)
: QCheckBox( parent ) {}
protected:
// ######## Qt4 TODO: not called anymore!
void drawButton( QPainter * );
};
......@@ -77,70 +78,70 @@ protected:
*/
class KonqFrameStatusBar : public KStatusBar
{
Q_OBJECT
Q_OBJECT
public:
KonqFrameStatusBar( KonqFrame *_parent = 0 );
virtual ~KonqFrameStatusBar();
/**
* Checks/unchecks the linked-view checkbox
*/
void setLinkedView( bool b );
/**
* Shows/hides the active-view indicator
*/
void showActiveViewIndicator( bool b );
/**
* Shows/hides the linked-view indicator
*/
void showLinkedViewIndicator( bool b );
/**
* Updates the active-view indicator and the statusbar color.
*/
void updateActiveStatus();
public Q_SLOTS:
void slotConnectToNewView(KonqView *, KParts::ReadOnlyPart *oldOne,KParts::ReadOnlyPart *newOne);
void slotLoadingProgress( int percent );
void slotSpeedProgress( int bytesPerSecond );
void slotDisplayStatusText(const QString& text);
public:
KonqFrameStatusBar( KonqFrame *_parent = 0 );
virtual ~KonqFrameStatusBar();
/**
* Checks/unchecks the linked-view checkbox
*/
void setLinkedView( bool b );
/**
* Shows/hides the active-view indicator
*/
void showActiveViewIndicator( bool b );
/**
* Shows/hides the linked-view indicator
*/
void showLinkedViewIndicator( bool b );
/**
* Updates the active-view indicator and the statusbar color.
*/
void updateActiveStatus();
public Q_SLOTS:
void slotConnectToNewView(KonqView *, KParts::ReadOnlyPart *oldOne,KParts::ReadOnlyPart *newOne);
void slotLoadingProgress( int percent );
void slotSpeedProgress( int bytesPerSecond );
void slotDisplayStatusText(const QString& text);
void slotClear();
void message ( const QString & message );
Q_SIGNALS:
/**
* This signal is emitted when the user clicked the bar.
*/
void clicked();
/**
* The "linked view" checkbox was clicked
*/
void linkedViewClicked( bool mode );
protected:
virtual bool eventFilter(QObject*,QEvent *);
virtual void resizeEvent( QResizeEvent* );
virtual void mousePressEvent( QMouseEvent* );
/**
* Brings up the context menu for this frame
*/
virtual void splitFrameMenu();
/**
* Takes care of the statusbars size
**/
virtual void fontChange(const QFont &oldFont);
private:
KonqFrame* m_pParentKonqFrame;
QCheckBox *m_pLinkedViewCheckBox;
QProgressBar *m_progressBar;
KSqueezedTextLabel *m_pStatusLabel;
QLabel* m_led;
QString m_savedMessage;
void slotClear();
void message ( const QString & message );
Q_SIGNALS:
/**
* This signal is emitted when the user clicked the bar.
*/
void clicked();
/**
* The "linked view" checkbox was clicked
*/
void linkedViewClicked( bool mode );
protected:
virtual bool eventFilter(QObject*,QEvent *);
virtual void resizeEvent( QResizeEvent* );
virtual void mousePressEvent( QMouseEvent* );
/**
* Brings up the context menu for this frame
*/
virtual void splitFrameMenu();
/**
* Takes care of the statusbars size
**/
virtual void fontChange(const QFont &oldFont);
private:
KonqFrame* m_pParentKonqFrame;
QCheckBox *m_pLinkedViewCheckBox;
QProgressBar *m_progressBar;
KSqueezedTextLabel *m_pStatusLabel;
QLabel* m_led;
QString m_savedMessage;
};
......@@ -186,11 +187,7 @@ protected:
* widget handling i.e. it attaches/detaches the view widget and activates
* them on click at the statusbar.
*
* KonqFrame makes the difference between built-in views and remote ones.
* We create a layout in it (with the KonqFrameStatusBar as top item in the layout)
* For builtin views we have the view as direct child widget of the layout
* For remote views we have an OPFrame, having the view attached, as child
* widget of the layout
* We create a vertical layout in the frame, with the view and the KonqFrameStatusBar.
*/
class KonqFrame : public QWidget, public KonqFrameBase
......@@ -198,7 +195,7 @@ class KonqFrame : public QWidget, public KonqFrameBase
Q_OBJECT
public:
explicit KonqFrame( QWidget* parent, KonqFrameContainerBase *parentContainer = 0L );
explicit KonqFrame( QWidget* parent, KonqFrameContainerBase *parentContainer = 0 );
virtual ~KonqFrame();
/**
......@@ -211,12 +208,12 @@ public:
* Filters the CTRL+Tab event from the views and emits ctrlTabPressed to
make KonqMainWindow switch to the next view
*/
virtual bool eventFilter(QObject*obj,QEvent *ev);
virtual bool eventFilter(QObject*obj, QEvent *ev);
/**
* Inserts the part's widget and the statusbar into the layout
* Inserts the widget and the statusbar into the layout
*/
void attachInternal();
void attachWidget(QWidget* widget);
/**
* Inserts a widget at the top of the part's widget, in the layout
......@@ -249,7 +246,6 @@ public:
virtual void reparentFrame(QWidget * parent,
const QPoint & p );
//virtual KonqFrameContainerBase* parentContainer();
virtual QWidget* asQWidget() { return this; }
virtual QByteArray frameType() { return QByteArray("View"); }
......@@ -285,8 +281,6 @@ protected:
QPointer<KParts::ReadOnlyPart> m_pPart;
KonqViewManager* m_pViewManager;
KSeparator *m_separator;
KonqFrameStatusBar* m_pStatusBar;
......
......@@ -48,8 +48,8 @@ KonqFrameContainer::KonqFrameContainer( Qt::Orientation o,
KonqFrameContainer::~KonqFrameContainer()
{
//kDebug(1202) << "KonqFrameContainer::~KonqFrameContainer() " << this << " - " << className() << endl;
delete m_pFirstChild;
delete m_pSecondChild;
delete m_pFirstChild;
delete m_pSecondChild;
}
void KonqFrameContainer::listViews( ChildViewList *viewList )
......
......@@ -28,7 +28,7 @@ public:
virtual ~KonqFrameContainerBase() {}
/**
* Call this after inserting a new frame into the splitter.
* Call this after inserting a new frame into the container.
*/
virtual void insertChildFrame( KonqFrameBase * frame, int index = -1 ) = 0;
/**
......@@ -52,7 +52,7 @@ public:
virtual void activateChild() { if (m_pActiveChild) m_pActiveChild->activateChild(); }
virtual KonqView* activeChildView() { if (m_pActiveChild) return m_pActiveChild->activeChildView();
else return 0L; }
else return 0; }
protected:
KonqFrameContainerBase() {}
......
......@@ -242,8 +242,11 @@ void ToggleViewGUIClient::slotToggleView( bool toggle )
if ( toggle )
{
KonqView *childView = viewManager->splitWindow( horizontal ? Qt::Vertical : Qt::Horizontal,
// Don't crash when doing things too quickly.
if ( !m_mainWindow->currentView() )
return;
KonqView *childView = viewManager->splitMainContainer( m_mainWindow->currentView(),
horizontal ? Qt::Vertical : Qt::Horizontal,
QLatin1String( "Browser/View" ),
serviceName,
!horizontal /* vertical = make it first */);
......
......@@ -66,6 +66,7 @@
#include <QtGui/QClipboard>
#include <QtCore/QArgument>
#include <QtGui/QLayout>
#include <QStackedWidget>
#include <QtCore/QFileInfo>
#ifdef Q_WS_X11
#include <QX11Info>
......@@ -360,7 +361,7 @@ QWidget * KonqMainWindow::createContainer( QWidget *parent, int index, const QDo
if ( res && (element.tagName() == tagToolBar) && (element.attribute( "name" ) == nameBookmarkBar) )
{
assert( res->inherits( "KToolBar" ) );
assert( ::qobject_cast<KToolBar*>( res ) );
if (!KAuthorized::authorizeKAction("bookmarks"))
{
delete res;
......@@ -401,7 +402,7 @@ void KonqMainWindow::removeContainer( QWidget *container, QWidget *parent, QDomE
if ( element.tagName() == tagToolBar && element.attribute( "name" ) == nameBookmarkBar )
{
assert( container->inherits( "KToolBar" ) );
assert( ::qobject_cast<KToolBar*>( container ) );
if (m_paBookmarkBar)
m_paBookmarkBar->clear();
}
......@@ -793,19 +794,12 @@ bool KonqMainWindow::openView( QString mimeType, const KUrl &_url, KonqView *chi
{
if (req.newTab)
{
KonqFrameTabs* tabContainer = 0;
int index = 0;
if ( m_pViewManager->docContainer() && m_pViewManager->docContainer()->frameType() == "Tabs")
{
tabContainer = static_cast<KonqFrameTabs*>(m_pViewManager->docContainer());
index = tabContainer->currentIndex();
}
KonqFrameTabs* tabContainer = m_pViewManager->tabContainer();
int index = tabContainer->currentIndex();
childView = m_pViewManager->addTab( mimeType, serviceName, false, req.openAfterCurrentPage );
if (req.newTabInFront && childView)
{
if ( !tabContainer )
tabContainer = static_cast<KonqFrameTabs*>(m_pViewManager->docContainer());
if ( req.openAfterCurrentPage )
tabContainer->setCurrentIndex( index + 1 );
else
......@@ -816,10 +810,10 @@ bool KonqMainWindow::openView( QString mimeType, const KUrl &_url, KonqView *chi
else
{
// Create a new view
// Initialize always uses force auto-embed even if user setting is "separate viewer",
// createFirstView always uses force auto-embed even if user setting is "separate viewer",
// since this window has no view yet - we don't want to keep an empty mainwindow.
// This can happen with e.g. application/pdf from a target="_blank" link, or window.open.
childView = m_pViewManager->Initialize( mimeType, serviceName );
childView = m_pViewManager->createFirstView( mimeType, serviceName );
if ( childView )
{
......@@ -887,8 +881,9 @@ bool KonqMainWindow::openView( QString mimeType, const KUrl &_url, KonqView *chi
childView->setTypedURL( req.typedUrl );
if ( childView->browserExtension() )
childView->browserExtension()->setUrlArgs( req.args );
if ( childView->part()->inherits("KonqDirPart") )
static_cast<KonqDirPart *>(childView->part())->setFilesToSelect( req.filesToSelect );
KonqDirPart* dirPart = ::qobject_cast<KonqDirPart*>( childView->part() );
if ( dirPart )
dirPart->setFilesToSelect( req.filesToSelect );
if ( !url.isEmpty() )
childView->openUrl( url, originalURL, req.nameFilter, req.tempFile );
}
......@@ -986,7 +981,7 @@ QObject *KonqMainWindow::lastFrame( KonqView *view )
QObject *nextFrame, *viewFrame;
nextFrame = view->frame();
viewFrame = 0;
while ( nextFrame != 0 && ! nextFrame->inherits( "QWidgetStack" ) ) {
while ( nextFrame != 0 && !::qobject_cast<QStackedWidget*>(nextFrame) ) {
viewFrame = nextFrame;
nextFrame = nextFrame->parent();
}
......@@ -1319,7 +1314,7 @@ void KonqMainWindow::slotSendURL()
fileNameList += (*it).fileName();
}
QString subject;
if ( m_currentView && !m_currentView->part()->inherits("KonqDirPart") )
if ( m_currentView && !::qobject_cast<KonqDirPart*>( m_currentView->part() ) )
subject = m_currentView->caption();
else
subject = fileNameList;
......@@ -1363,7 +1358,7 @@ void KonqMainWindow::slotSendFile()
}
}
QString subject;
if ( m_currentView && !m_currentView->part()->inherits("KonqDirPart") )
if ( m_currentView && !::qobject_cast<KonqDirPart*>( m_currentView->part() ) )
subject = m_currentView->caption();
else
subject = fileNameList;
......@@ -1436,7 +1431,7 @@ void KonqMainWindow::slotToolFind()
{
kDebug(1202) << "KonqMainWindow::slotToolFind sender:" << sender()->metaObject()->className() << endl;
if ( m_currentView && m_currentView->part()->inherits("KonqDirPart") )
if ( m_currentView && ::qobject_cast<KonqDirPart*>( m_currentView->part() ) )
{
KonqDirPart* dirPart = static_cast<KonqDirPart *>(m_currentView->part());
......@@ -1464,7 +1459,7 @@ void KonqMainWindow::slotToolFind()
connect( dirPart, SIGNAL( findClosed(KonqDirPart *) ),
this, SLOT( slotFindClosed(KonqDirPart *) ) );
}
else if ( sender()->inherits( "KAction" ) ) // don't go there if called by the singleShot below
else if ( ::qobject_cast<KAction*>(sender()) ) // don't go there if called by the singleShot below
{
KUrl url;
if ( m_currentView && m_currentView->url().isLocalFile() )
......@@ -1549,8 +1544,9 @@ void KonqMainWindow::slotViewModeToggle( bool toggle )
KUrl url = m_currentView->url();
QString locationBarURL = m_currentView->locationBarURL();
QStringList filesToSelect;
if( m_currentView->part()->inherits( "KonqDirPart" ) ) {
const KFileItemList fileItemsToSelect = static_cast<KonqDirPart*>(m_currentView->part())->selectedFileItems();
KonqDirPart* dirPart = ::qobject_cast<KonqDirPart *>(m_currentView->part());
if( dirPart ) {
const KFileItemList fileItemsToSelect = dirPart->selectedFileItems();
KFileItemList::const_iterator it = fileItemsToSelect.begin();
const KFileItemList::const_iterator end = fileItemsToSelect.end();
for ( ; it != end; ++it ) {
......@@ -1601,7 +1597,7 @@ void KonqMainWindow::slotViewModeToggle( bool toggle )
for (int i = 0; i < m_toolBarViewModeActions.size(); ++i)
if ( m_toolBarViewModeActions.at(i)->objectName() == oldService->desktopEntryName() )
{
assert( m_toolBarViewModeActions.at(i)->inherits( "KonqViewModeAction" ) );
assert( ::qobject_cast<KonqViewModeAction *>( m_toolBarViewModeActions.at(i) ) );
KonqViewModeAction *action = static_cast<KonqViewModeAction *>( m_toolBarViewModeActions.at(i) );
......@@ -1630,8 +1626,9 @@ void KonqMainWindow::slotViewModeToggle( bool toggle )
m_currentView->changeViewMode( m_currentView->serviceType(), modeName );
KUrl locURL( locationBarURL );
QString nameFilter = detectNameFilter( locURL );
if( m_currentView->part()->inherits( "KonqDirPart" ) )
static_cast<KonqDirPart*>( m_currentView->part() )->setFilesToSelect( filesToSelect );
KonqDirPart* dirPart = ::qobject_cast<KonqDirPart *>(m_currentView->part());
if( dirPart )
dirPart->setFilesToSelect( filesToSelect );
m_currentView->openUrl( locURL, locationBarURL, nameFilter );
}
......@@ -2521,16 +2518,20 @@ void KonqMainWindow::slotFileNewAboutToShow()
void KonqMainWindow::slotSplitViewHorizontal()
{
KonqView * newView = m_pViewManager->splitView( Qt::Horizontal );
if (newView == 0) return;
newView->openUrl( m_currentView->url(), m_currentView->locationBarURL() );
if ( !m_currentView )
return;
KonqView * newView = m_pViewManager->splitView( m_currentView, Qt::Horizontal );
if (newView == 0) return;
newView->openUrl( m_currentView->url(), m_currentView->locationBarURL() );
}
void KonqMainWindow::slotSplitViewVertical()
{
KonqView * newView = m_pViewManager->splitView( Qt::Vertical );
if (newView == 0) return;
newView->openUrl( m_currentView->url(), m_currentView->locationBarURL() );
if ( !m_currentView )
return;
KonqView * newView = m_pViewManager->splitView( m_currentView, Qt::Vertical );
if (newView == 0) return;
newView->openUrl( m_currentView->url(), m_currentView->locationBarURL() );
}
void KonqMainWindow::slotAddTab()
......@@ -2548,7 +2549,9 @@ void KonqMainWindow::slotAddTab()
void KonqMainWindow::slotDuplicateTab()
{
m_pViewManager->duplicateTab( 0, KonqSettings::openAfterCurrentPage() );
if ( !m_currentView )
return;
m_pViewManager->duplicateTab( m_currentView->frame(), KonqSettings::openAfterCurrentPage() );
}
void KonqMainWindow::slotDuplicateTabPopup()
......@@ -2558,7 +2561,9 @@ void KonqMainWindow::slotDuplicateTabPopup()
void KonqMainWindow::slotBreakOffTab()
{
if (m_currentView && m_currentView->part() &&
if ( !m_currentView )
return;
if (m_currentView->part() &&
(m_currentView->part()->metaObject()->indexOfProperty("modified") != -1) ) {
QVariant prop = m_currentView->part()->property("modified");
if (prop.isValid() && prop.toBool())
......@@ -2568,7 +2573,7 @@ void KonqMainWindow::slotBreakOffTab()
return;
}
m_pViewManager->breakOffTab();
m_pViewManager->breakOffTab( m_currentView->frame(), size() );
updateViewActions();
}
......@@ -2598,7 +2603,7 @@ void KonqMainWindow::slotBreakOffTabPopup()
void KonqMainWindow::slotBreakOffTabPopupDelayed()
{
m_pViewManager->breakOffTab( m_pWorkingTab );
m_pViewManager->breakOffTab( m_pWorkingTab, size() );
updateViewActions();
}
......@@ -2697,7 +2702,7 @@ void KonqMainWindow::slotRemoveTab()
return;
}
m_pViewManager->removeTab();
m_pViewManager->removeTab( m_currentView->frame() );
}
void KonqMainWindow::slotRemoveTabPopup()
......@@ -2912,14 +2917,12 @@ void KonqMainWindow::slotNewDir()
KUrl::List KonqMainWindow::currentURLs() const
{
KUrl::List urls;
if ( m_currentView )
{
if ( m_currentView ) {
urls.append( m_currentView->url() );
if ( m_currentView->part()->inherits("KonqDirPart") )
{
const KFileItemList itemList = static_cast<KonqDirPart *>(m_currentView->part())->selectedFileItems();
if (!itemList.isEmpty()) // Return list of selected items only if we have a selection