Commit adc02ed7 authored by David Faure's avatar David Faure
Browse files

Started the big design cleanup:

 - Implemented visitor support to KonqFrameBase and children, to reduce interdependencies,
  moved printFrameInfo to visitor, and used visitor in unit tests too, to inspect structure.
 - Simplify KonqMainWindow ctor
 - Pass explicit mimetype to addTab() (fixed one performance bug, in kde3 branch as well)
 - Simplify splitView arguments
 - Unit tests for most of the KonqViewMgr API, to allow for further refactorings

svn path=/trunk/KDE/kdebase/apps/; revision=677505
parent 8d8c5a8e
......@@ -12,9 +12,6 @@ check_symbol_exists(mallinfo "stdlib.h" KDE_MALLINFO_STDL
# TODO KDE_MALLINFO_FIELD_usmblks
configure_file(config-konqueror.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config-konqueror.h )
set(libkonqueror_intern_KCFG_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/konq_settingsxt.kcfgc)
kde4_add_kcfg_files(libkonqueror_intern_SRCS ${libkonqueror_intern_KCFG_SRCS})
add_subdirectory( client )
# on the way out
#add_subdirectory( iconview )
......@@ -41,8 +38,7 @@ add_subdirectory( tests )
########### next target ###############
set(konqueror_KDEINIT_SRCS ${libkonqueror_intern_SRCS}
konq_main.cc
set(konquerorprivate_SRCS
konq_application.cpp
konq_guiclients.cc
konq_run.cc
......@@ -64,17 +60,19 @@ set(konqueror_KDEINIT_SRCS ${libkonqueror_intern_SRCS}
KonqMainWindowAdaptor.cpp
KonqViewAdaptor.cpp
)
kde4_add_kcfg_files(konquerorprivate_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/konq_settingsxt.kcfgc)
kde4_automoc(${konqueror_KDEINIT_SRCS})
QT4_ADD_DBUS_INTERFACE(konqueror_KDEINIT_SRCS org.kde.Konqueror.Main.xml konqueror_interface)
kde4_add_kdeinit_executable( konqueror ${konqueror_KDEINIT_SRCS})
kde4_automoc(${konquerorprivate_SRCS})
target_link_libraries(kdeinit_konqueror ${KDE4_KDE3SUPPORT_LIBS} ${KDE4_KUTILS_LIBS} konq )
qt4_add_dbus_interface(konquerorprivate_SRCS org.kde.Konqueror.Main.xml konqueror_interface)
install(TARGETS kdeinit_konqueror DESTINATION ${LIB_INSTALL_DIR} )
kde4_add_library(konquerorprivate ${konquerorprivate_SRCS})
target_link_libraries(konquerorprivate ${KDE4_KDE3SUPPORT_LIBS} ${KDE4_KUTILS_LIBS} konq)
kde4_add_kdeinit_executable( konqueror konq_main.cc)
target_link_libraries(kdeinit_konqueror konquerorprivate )
target_link_libraries( konqueror kdeinit_konqueror )
install(TARGETS kdeinit_konqueror DESTINATION ${LIB_INSTALL_DIR} )
install(TARGETS konqueror DESTINATION ${BIN_INSTALL_DIR})
......
......@@ -39,7 +39,7 @@ class KonqMainWindowAdaptor : public QDBusAbstractAdaptor
public:
KonqMainWindowAdaptor( KonqMainWindow * mainWindow );
explicit KonqMainWindowAdaptor( KonqMainWindow * mainWindow );
~KonqMainWindowAdaptor();
public slots:
......
......@@ -36,7 +36,7 @@ class KonqViewAdaptor : public QObject
public:
KonqViewAdaptor( KonqView * view );
explicit KonqViewAdaptor( KonqView * view );
~KonqViewAdaptor();
public slots:
......
......@@ -10,7 +10,7 @@ class KonqBrowserInterface : public KParts::BrowserInterface
Q_OBJECT
Q_PROPERTY( uint historyLength READ historyLength )
public:
KonqBrowserInterface( KonqView *view );
explicit KonqBrowserInterface( KonqView *view );
uint historyLength() const;
......
......@@ -38,7 +38,7 @@ class KonqCombo : public KHistoryComboBox
Q_OBJECT
public:
KonqCombo( QWidget *parent );
explicit KonqCombo( QWidget *parent );
~KonqCombo();
// initializes with the completion object and calls loadItems()
......
/* -*- indent-tabs-mode: t; tab-width: 4; c-basic-offset:4 -*-
/*
konq_extensionmanager.cc - Extension Manager for Konqueror
Copyright (c) 2003 by Martijn Klingens <klingens@kde.org>
......
/* -*- indent-tabs-mode: t; tab-width: 4; c-basic-offset:4 -*-
/*
konq_extensionmanager.h - Extension Manager for Konqueror
......
......@@ -32,20 +32,21 @@
// KDE
#include <kaboutdata.h>
#include <kdebug.h>
#include <klibloader.h>
#include <klocale.h>
#include <kmessagebox.h>
#include <kmimetypetrader.h>
#include <kparts/factory.h>
#include <kparts/part.h>
#include <kservicetypetrader.h>
#include <kdeversion.h>
// Local
#include <konq_view.h>
#include <konq_settings.h>
#include <konq_mainwindow.h>
#include "konq_settings.h"
#include "konq_mainwindow.h"
KAboutData *KonqFactory::s_aboutData = 0;
static KAboutData *s_aboutData = 0;
KonqViewFactory::KonqViewFactory( KLibFactory *factory, const QStringList &args,
bool createBrowser )
......@@ -58,9 +59,9 @@ KonqViewFactory::KonqViewFactory( KLibFactory *factory, const QStringList &args,
KParts::ReadOnlyPart *KonqViewFactory::create( QWidget *parentWidget, QObject * parent )
{
if ( !m_factory )
return 0L;
return 0;
QObject *obj = 0L;
QObject *obj = 0;
KParts::Factory* kpartsFactory = ::qobject_cast<KParts::Factory *>( m_factory );
if ( kpartsFactory )
......@@ -146,7 +147,7 @@ KonqViewFactory KonqFactory::createView( const QString &serviceType,
}
}
KLibFactory *factory = 0L;
KLibFactory *factory = 0;
if ( service )
{
......
......@@ -25,17 +25,16 @@
#include <QtCore/QStringList>
#include <klibloader.h>
#include <kservice.h>
#include <kparts/part.h>
class KAboutData;
class KLibFactory;
namespace KParts { class ReadOnlyPart; }
class KonqViewFactory
class KonqViewFactory // TODO rename to KonqPartFactory?
{
public:
KonqViewFactory() : m_factory( 0L ), m_createBrowser( false ) {}
KonqViewFactory() : m_factory( 0 ), m_createBrowser( false ) {}
KonqViewFactory( KLibFactory *factory, const QStringList &args, bool createBrowser );
......@@ -60,24 +59,34 @@ private:
bool m_createBrowser;
};
/**
* Factory for creating (loading) parts when creating a view.
*/
class KonqFactory
{
public:
static KonqViewFactory createView( const QString &serviceType,
const QString &serviceName = QString(),
KService::Ptr *serviceImpl = 0,
KService::List *partServiceOffers = 0,
KService::List *appServiceOffers = 0,
bool forceAutoEmbed = false );
static void getOffers( const QString & serviceType,
KService::List *partServiceOffers = 0,
KService::List *appServiceOffers = 0);
static const KAboutData* aboutData();
private:
static KAboutData *s_aboutData;
/**
* Return the factory that can be used to actually create the part inside a view.
*
* The implementation locates the part module (library), using the trader
* and opens it (using klibfactory), which gives us a factory that can be used to
* actually create the part (later on, when the KonqView exists).
*
* Not a static method so that we can define an abstract base class
* with another implementation, for unit tests, if wanted.
*/
KonqViewFactory createView( const QString &serviceType,
const QString &serviceName = QString(),
KService::Ptr *serviceImpl = 0,
KService::List *partServiceOffers = 0,
KService::List *appServiceOffers = 0,
bool forceAutoEmbed = false );
static void getOffers( const QString & serviceType,
KService::List *partServiceOffers = 0,
KService::List *appServiceOffers = 0);
static const KAboutData* aboutData();
};
#endif
......@@ -52,6 +52,7 @@
#include "konq_tabs.h"
#include "konq_view.h"
#include "konq_viewmgr.h"
#include "konq_framevisitor.h"
#define DEFAULT_HEADER_HEIGHT 13
......@@ -287,13 +288,6 @@ void KonqFrameStatusBar::updateActiveStatus()
//###################################################################
void KonqFrameBase::printFrameInfo(const QString& spaces)
{
kDebug(1202) << spaces << "KonqFrameBase " << this << " printFrameInfo not implemented in derived class!" << endl;
}
//###################################################################
KonqFrame::KonqFrame( QWidget* parent, KonqFrameContainerBase *parentContainer )
: QWidget ( parent )
{
......@@ -351,16 +345,7 @@ void KonqFrame::copyHistory( KonqFrameBase *other )
childView()->copyHistory( static_cast<KonqFrame *>( other )->childView() );
}
void KonqFrame::printFrameInfo( const QString& spaces )
{
QString className = "NoPart";
if (part()) className = part()->widget()->metaObject()->className();
kDebug(1202) << spaces << "KonqFrame " << this << " visible=" << QString("%1").arg(isVisible()) << " containing view "
<< childView() << " visible=" << QString("%1").arg(isVisible())
<< " and part " << part() << " whose widget is a " << className << endl;
}
KParts::ReadOnlyPart *KonqFrame::attach( const KonqViewFactory &viewFactory )
KParts::ReadOnlyPart *KonqFrame::attach( const KonqViewFactory &viewFactory )
{
KonqViewFactory factory( viewFactory );
......@@ -493,4 +478,9 @@ KonqView* KonqFrame::activeChildView()
return m_pView;
}
bool KonqFrame::accept( KonqFrameVisitor* visitor )
{
return visitor->visit( this );
}
#include "konq_frame.moc"
......@@ -20,6 +20,7 @@
#define __konq_frame_h__
#include "konq_factory.h"
#include <kparts/part.h> // for the inline QPointer usage
#include <QtCore/QPointer>
#include <QtGui/QColor>
......@@ -35,6 +36,7 @@
#include <KPixmapEffect>
#include <KStatusBar>
class KonqFrameVisitor;
class QPixmap;
class QVBoxLayout;
class QProgressBar;
......@@ -81,7 +83,7 @@ class KonqFrameStatusBar : public KStatusBar
Q_OBJECT
public:
KonqFrameStatusBar( KonqFrame *_parent = 0 );
explicit KonqFrameStatusBar( KonqFrame *_parent = 0 );
virtual ~KonqFrameStatusBar();
/**
......@@ -152,17 +154,17 @@ class KonqFrameBase
public:
virtual ~KonqFrameBase() {}
virtual bool accept( KonqFrameVisitor* visitor ) = 0;
virtual void saveConfig( KConfigGroup& config, const QString &prefix, bool saveURLs, KonqFrameBase* docContainer, int id = 0, int depth = 0) = 0;
virtual void copyHistory( KonqFrameBase *other ) = 0;
virtual void printFrameInfo( const QString& spaces );
virtual void reparentFrame( QWidget* parent,
const QPoint & p ) = 0;
virtual KonqFrameContainerBase* parentContainer() const { return m_pParentContainer; }
virtual void setParentContainer(KonqFrameContainerBase* parent) { m_pParentContainer = parent; }
KonqFrameContainerBase* parentContainer() const { return m_pParentContainer; }
void setParentContainer(KonqFrameContainerBase* parent) { m_pParentContainer = parent; }
virtual void setTitle( const QString &title , QWidget* sender) = 0;
virtual void setTabIcon( const KUrl &url, QWidget* sender ) = 0;
......@@ -198,6 +200,8 @@ public:
explicit KonqFrame( QWidget* parent, KonqFrameContainerBase *parentContainer = 0 );
virtual ~KonqFrame();
virtual bool accept( KonqFrameVisitor* visitor );
/**
* Attach a view to the KonqFrame.
* @param viewFactory the view to attach (instead of the current one, if any)
......@@ -238,8 +242,6 @@ public:
virtual void saveConfig( KConfigGroup& config, const QString &prefix, bool saveURLs, KonqFrameBase* docContainer, int id = 0, int depth = 0 );
virtual void copyHistory( KonqFrameBase *other );
virtual void printFrameInfo( const QString& spaces );
virtual void setTitle( const QString &title, QWidget* sender );
virtual void setTabIcon( const KUrl &url, QWidget* sender );
......
......@@ -22,14 +22,7 @@
#include <kconfig.h>
#include <math.h> // pow()
//###################################################################
void KonqFrameContainerBase::printFrameInfo(const QString& spaces)
{
kDebug(1202) << spaces << "KonqFrameContainerBase " << this << ", this shouldn't happen!" << endl;
}
//###################################################################
#include "konq_framevisitor.h"
KonqFrameContainer::KonqFrameContainer( Qt::Orientation o,
QWidget* parent,
......@@ -123,24 +116,6 @@ KonqFrameBase* KonqFrameContainer::otherChild( KonqFrameBase* child )
return 0L;
}
void KonqFrameContainer::printFrameInfo( const QString& spaces )
{
kDebug(1202) << spaces << "KonqFrameContainer " << this << " visible=" << QString("%1").arg(isVisible())
<< " activeChild=" << m_pActiveChild << endl;
if (!m_pActiveChild)
kDebug(1202) << "WARNING: " << this << " has a null active child!" << endl;
KonqFrameBase* child = firstChild();
if (child != 0L)
child->printFrameInfo(spaces + " ");
else
kDebug(1202) << spaces << " Null child" << endl;
child = secondChild();
if (child != 0L)
child->printFrameInfo(spaces + " ");
else
kDebug(1202) << spaces << " Null child" << endl;
}
void KonqFrameContainer::reparentFrame( QWidget* parent, const QPoint & p )
{
setParent( parent );
......@@ -223,4 +198,19 @@ bool KonqFrameContainer::hasWidgetAfter( QWidget* w ) const
return QSplitter::widget( idx + 1 ) != 0;
}
bool KonqFrameContainer::accept( KonqFrameVisitor* visitor )
{
if ( !visitor->visit( this ) )
return false;
Q_ASSERT( m_pFirstChild );
if ( m_pFirstChild && !m_pFirstChild->accept( visitor ) )
return false;
Q_ASSERT( m_pSecondChild );
if ( m_pSecondChild && !m_pSecondChild->accept( visitor ) )
return false;
if ( !visitor->endVisit( this ) )
return false;
return true;
}
#include "konq_framecontainer.moc"
......@@ -22,6 +22,10 @@
#include "konq_frame.h"
#include <QtGui/QSplitter>
/**
* Base class for containers
* This implements the Composite pattern: a composite is a type of base element.
*/
class KonqFrameContainerBase : public KonqFrameBase
{
public:
......@@ -36,15 +40,12 @@ public:
*/
virtual void removeChildFrame( KonqFrameBase * frame ) = 0;
//inherited
virtual void printFrameInfo( const QString& spaces );
virtual QByteArray frameType() { return QByteArray("ContainerBase"); }
virtual void reparentFrame(QWidget * parent,
const QPoint & p ) = 0;
virtual KonqFrameBase* activeChild() { return m_pActiveChild; }
KonqFrameBase* activeChild() const { return m_pActiveChild; }
virtual void setActiveChild( KonqFrameBase* activeChild ) { m_pActiveChild = activeChild;
m_pParentContainer->setActiveChild( this ); }
......@@ -68,8 +69,7 @@ protected:
* That means that they always have two children. Which are either again
* KonqFrameContainers or, as leaves, KonqFrames.
*/
class KonqFrameContainer : public QSplitter, public KonqFrameContainerBase
class KonqFrameContainer : public QSplitter, public KonqFrameContainerBase // TODO rename to KonqFrameContainerSplitter?
{
Q_OBJECT
friend class KonqFrame; //for emitting ctrlTabPressed() only, aleXXX
......@@ -79,6 +79,8 @@ public:
KonqFrameContainerBase* parentContainer );
virtual ~KonqFrameContainer();
virtual bool accept( KonqFrameVisitor* visitor );
virtual void listViews( ChildViewList *viewList );
virtual void saveConfig( KConfigGroup& config, const QString &prefix, bool saveURLs, KonqFrameBase* docContainer, int id = 0, int depth = 0 );
......@@ -88,8 +90,6 @@ public:
KonqFrameBase* secondChild() { return m_pSecondChild; }
KonqFrameBase* otherChild( KonqFrameBase* child );
virtual void printFrameInfo( const QString& spaces );
void swapChildren();
virtual void setTitle( const QString &title, QWidget* sender );
......
......@@ -74,7 +74,7 @@ class ToggleViewGUIClient : public QObject
{
Q_OBJECT
public:
ToggleViewGUIClient( KonqMainWindow *mainWindow );
explicit ToggleViewGUIClient( KonqMainWindow *mainWindow );
virtual ~ToggleViewGUIClient();
bool empty() const { return m_empty; }
......
......@@ -38,6 +38,7 @@
#endif
#include <QtDBus/QtDBus>
#include <QDir>
static const KCmdLineOptions options[] =
{
......@@ -78,7 +79,7 @@ extern "C" KDE_EXPORT int kdemain( int argc, char **argv )
{
QString className = KXmlGuiWindow::classNameOfToplevel( n );
if( className == QLatin1String( "KonqMainWindow" ))
(new KonqMainWindow( KUrl(), false ) )->restore( n );
(new KonqMainWindow() )->restore( n );
else
kWarning() << "Unknown class " << className << " in session saved data!" << endl;
n++;
......@@ -138,7 +139,7 @@ extern "C" KDE_EXPORT int kdemain( int argc, char **argv )
QDBusReply<bool> retVal = ref.call( QDBus::Block, "registerPreloadedKonqy", QDBusConnection::sessionBus().baseService(), info.screen());
if( !retVal )
return 0; // too many preloaded or failed
KonqMainWindow* win = new KonqMainWindow( KUrl(), false ); // prepare an empty window too
KonqMainWindow* win = new KonqMainWindow; // prepare an empty window too
// KonqMainWindow ctor sets always the preloaded flag to false, so create the window before this
KonqMainWindow::setPreloadedFlag( true );
KonqMainWindow::setPreloadedWindow( win );
......@@ -160,7 +161,7 @@ extern "C" KDE_EXPORT int kdemain( int argc, char **argv )
if ( !profilePath.isEmpty() ) {
KonqMisc::createBrowserWindowFromProfile( profilePath, profile );
} else {
KonqMainWindow *mainWindow = new KonqMainWindow;
KonqMainWindow *mainWindow = new KonqMainWindow( KUrl( QDir::homePath() ) );
mainWindow->show();
}
}
......
......@@ -71,7 +71,6 @@
#ifdef Q_WS_X11
#include <QX11Info>
#endif
//Added by qt3to4:
#include <QtCore/QEvent>
#include <QtGui/QKeyEvent>
#include <QtCore/QByteRef>
......@@ -134,7 +133,8 @@
#endif
#include <kauthorized.h>
#include <ktoolinvocation.h>
#include "konq_mainwindow_p.h"
#include "konq_mainwindow_p.h" // TODO rename to konq_extendedbookmarkowner.h
#include "konq_framevisitor.h"
#include <QtDBus/QtDBus>
#include <kconfiggroup.h>
......@@ -162,7 +162,7 @@ KonqExtendedBookmarkOwner::KonqExtendedBookmarkOwner(KonqMainWindow *w)
m_pKonqMainWindow = w;
}
KonqMainWindow::KonqMainWindow( const KUrl &initialURL, bool openInitialURL, const QString& xmluiFile)
KonqMainWindow::KonqMainWindow( const KUrl &initialURL, const QString& xmluiFile)
: KParts::MainWindow()
{
setPreloadedFlag( false );
......@@ -281,19 +281,12 @@ KonqMainWindow::KonqMainWindow( const KUrl &initialURL, bool openInitialURL, con
this, SLOT( slotUndoAvailable( bool ) ) );
m_bNeedApplyKonqMainWindowSettings = true;
if ( !initialURL.isEmpty() )
{
openFilteredUrl( initialURL.url() );
}
else if ( openInitialURL )
{
KUrl homeURL;
homeURL.setPath( QDir::homePath() );
openUrl( 0, homeURL );
}
else
if ( !initialURL.isEmpty() ) {
openFilteredUrl( initialURL.url() );
} else {
// silent
m_bNeedApplyKonqMainWindowSettings = false;
}
// Read basic main-view settings, and set to autosave
setAutoSaveSettings( "KonqMainWindow", false );
......@@ -524,7 +517,7 @@ void KonqMainWindow::openUrl( KonqView *_view, const KUrl &_url,
if ( !view && !req.newTab )
view = m_currentView; /* Note, this can be 0, e.g. on startup */
else if ( !view && req.newTab ) {
view = m_pViewManager->addTab(QString(),
view = m_pViewManager->addTab("text/html",
QString(),
false,
req.openAfterCurrentPage);
......@@ -1117,25 +1110,25 @@ void KonqMainWindow::slotCreateNewWindow( const KUrl &url, const KParts::URLArgs
}
if ( KonqSettings::popupsWithinTabs() || ( KonqSettings::mmbOpensTab() && windowArgs.lowerWindow ) ) {
bool aftercurrentpage = KonqSettings::openAfterCurrentPage();
bool newtabsinfront = KonqSettings::newTabsInFront();
const bool aftercurrentpage = KonqSettings::openAfterCurrentPage();
bool newtabsinfront = KonqSettings::newTabsInFront();
if ( windowArgs.lowerWindow )
newtabsinfront =! newtabsinfront;
newtabsinfront = !newtabsinfront;
KonqView* newView = m_pViewManager->addTab(QString(), QString(), false, aftercurrentpage);
KonqView* newView = m_pViewManager->addTab("text/html", QString(), false, aftercurrentpage);
if (newView == 0) return;
if (newtabsinfront)
m_pViewManager->showTab( newView );
m_pViewManager->showTab( newView );
openUrl( newView, url.isEmpty() ? KUrl("about:blank") : url, QString());
openUrl( newView, url.isEmpty() ? KUrl("about:blank") : url, QString() );
newView->setViewName( args.frameName );
part=newView->part();
return;
}
mainWindow = new KonqMainWindow( KUrl(), false );
mainWindow = new KonqMainWindow;
mainWindow->setInitialFrameName( args.frameName );
mainWindow->resetAutoSaveSettings(); // Don't autosave
......@@ -1288,7 +1281,7 @@ void KonqMainWindow::slotDuplicateWindow()
KConfig config( tempFile.fileName() );
m_pViewManager->saveViewProfile( config, true, true );
KonqMainWindow *mainWindow = new KonqMainWindow( KUrl(), false, xmlFile());
KonqMainWindow *mainWindow = new KonqMainWindow( KUrl(), xmlFile() );
mainWindow->viewManager()->loadViewProfile( config, m_pViewManager->currentProfile() );
if (mainWindow->currentView())
{
......@@ -1399,7 +1392,7 @@ void KonqMainWindow::slotOpenTerminal()
if(args.count() == 0)
return;
QString prog = args.takeFirst();
KProcess::startDetached(prog, args, dir, NULL);
kDebug(1202) << "slotOpenTerminal: directory " << dir
......@@ -1440,7 +1433,8 @@ void KonqMainWindow::slotToolFind()
return;
}
KonqViewFactory factory = KonqFactory::createView( "Konqueror/FindPart" );
KonqFactory konqFactory;
KonqViewFactory factory = konqFactory.createView( "Konqueror/FindPart" );
if ( factory.isNull() )
{
KMessageBox::error( this, i18n("Cannot create the find part, check your installation.") );
......@@ -2535,21 +2529,23 @@ void KonqMainWindow::slotSplitViewVertical()
void KonqMainWindow::slotAddTab()