delay a few things on startup, such as setting the visibility mode, which ensures...
[personal-kdebase.git] / apps / konqueror / src / konqview.cpp
blob88bcb9f0954abecd6b3823f12f0f11ed02e7ce1a
1 /*
2 This file is part of the KDE project
3 Copyright (C) 1998-2005 David Faure <faure@kde.org>
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; see the file COPYING. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
22 #include "konqview.h"
23 #include "KonqViewAdaptor.h"
24 #include "konqsettingsxt.h"
25 #include "konqframestatusbar.h"
26 #include "konqrun.h"
27 #include <konq_events.h>
28 #include "konqviewmanager.h"
29 #include "konqtabs.h"
30 #include "konqbrowseriface.h"
31 #include <kparts/statusbarextension.h>
32 #include <kparts/browserextension.h>
34 #include "konqhistorymanager.h"
35 #include "konqpixmapprovider.h"
37 #include <assert.h>
38 #include <kdebug.h>
39 #include <kcursor.h>
40 #include <kmessagebox.h>
41 #include <klocale.h>
42 #include <krandom.h>
43 #include <kio/job.h>
44 #include <kio/jobuidelegate.h>
45 #include <ktoggleaction.h>
47 #include <QtGui/QApplication>
48 #include <QtCore/QArgument>
49 #include <QtCore/QObject>
50 #include <QtCore/QByteRef>
51 #include <QtCore/QEvent>
52 #include <QtGui/QKeyEvent>
53 #include <QtCore/QFile>
54 #include <QtGui/QScrollArea>
55 #include <kjobuidelegate.h>
57 //#define DEBUG_HISTORY
59 KonqView::KonqView( KonqViewFactory &viewFactory,
60 KonqFrame* viewFrame,
61 KonqMainWindow *mainWindow,
62 const KService::Ptr &service,
63 const KService::List &partServiceOffers,
64 const KService::List &appServiceOffers,
65 const QString &serviceType,
66 bool passiveMode
69 m_pKonqFrame = viewFrame;
70 m_pKonqFrame->setView( this );
72 m_sLocationBarURL = "";
73 m_pageSecurity = KonqMainWindow::NotCrypted;
74 m_bLockHistory = false;
75 m_doPost = false;
76 m_pMainWindow = mainWindow;
77 m_pRun = NULL;
78 m_pPart = NULL;
80 m_randID = KRandom::random();
82 m_service = service;
83 m_partServiceOffers = partServiceOffers;
84 m_appServiceOffers = appServiceOffers;
85 m_serviceType = serviceType;
87 m_bAllowHTML = m_pMainWindow->isHTMLAllowed();
88 m_lstHistoryIndex = -1;
89 m_bLoading = false;
90 m_bPendingRedirection = false;
91 m_bPassiveMode = passiveMode;
92 m_bLockedLocation = false;
93 m_bLinkedView = false;
94 m_bAborted = false;
95 m_bToggleView = false;
96 m_bHierarchicalView = false;
97 m_bDisableScrolling = false;
98 m_bGotIconURL = false;
99 m_bPopupMenuEnabled = true;
100 m_browserIface = new KonqBrowserInterface( this );
101 m_bBackRightClick = KonqSettings::backRightClick();
102 m_bFollowActive = false;
103 m_bBuiltinView = false;
104 m_bURLDropHandling = false;
106 switchView( viewFactory );
109 KonqView::~KonqView()
111 //kDebug(1202) << "part=" << m_pPart;
113 if (KonqMainWindow::s_crashlog_file) {
114 QString part_url;
115 if (m_pPart)
116 part_url = m_pPart->url().url();
117 if (part_url.isNull())
118 part_url = "";
119 QByteArray line;
120 line = ( QString("close(%1):%2\n").arg(m_randID,0,16).arg(part_url) ).toUtf8();
121 KonqMainWindow::s_crashlog_file->write(line, line.length());
122 KonqMainWindow::s_crashlog_file->flush();
125 // We did so ourselves for passive views
126 if (m_pPart != 0L)
128 finishedWithCurrentURL();
129 if ( isPassiveMode() )
130 disconnect( m_pPart, SIGNAL( destroyed() ), m_pMainWindow->viewManager(), SLOT( slotObjectDestroyed() ) );
132 delete m_pPart;
135 qDeleteAll( m_lstHistory );
136 m_lstHistory.clear();
138 setRun( 0L );
139 //kDebug(1202) << this << "done";
142 void KonqView::openUrl( const KUrl &url, const QString & locationBarURL,
143 const QString & nameFilter, bool tempFile )
145 kDebug(1202) << "url=" << url << "locationBarURL=" << locationBarURL;
146 setPartMimeType();
148 if (KonqMainWindow::s_crashlog_file) {
149 QString part_url;
150 if (m_pPart)
151 part_url = m_pPart->url().url();
152 if (part_url.isNull())
153 part_url = "";
155 QString url_url = url.url();
156 if (url_url.isNull())
157 url_url = QString("");
159 QByteArray line;
161 line = ( QString("closed(%1):%2\n").arg(m_randID,0,16).arg(part_url) ).toUtf8();
162 KonqMainWindow::s_crashlog_file->write(line,line.length());
163 line = ( QString("opened(%3):%4\n").arg(m_randID,0,16).arg(url_url) ).toUtf8();
164 KonqMainWindow::s_crashlog_file->write(line,line.length());
165 KonqMainWindow::s_crashlog_file->flush();
168 KParts::OpenUrlArguments args;
169 if ( m_pPart )
170 args = m_pPart->arguments();
172 KParts::BrowserExtension *ext = browserExtension();
173 KParts::BrowserArguments browserArgs;
174 if ( ext )
175 browserArgs = ext->browserArguments();
177 // Typing "Enter" again after the URL of an aborted view, triggers a reload.
178 if ( m_bAborted && m_pPart && m_pPart->url() == url && !browserArgs.doPost())
180 if ( !prepareReload( args, browserArgs, false /* not softReload */ ) )
181 return;
182 m_pPart->setArguments( args );
185 #ifdef DEBUG_HISTORY
186 kDebug(1202) << "m_bLockedLocation=" << m_bLockedLocation << "browserArgs.lockHistory()=" << browserArgs.lockHistory();
187 #endif
188 if ( browserArgs.lockHistory() )
189 lockHistory();
191 if ( !m_bLockHistory )
193 // Store this new URL in the history, removing any existing forward history.
194 // We do this first so that everything is ready if a part calls completed().
195 createHistoryEntry();
196 } else
197 m_bLockHistory = false;
199 if ( m_pPart )
200 m_pPart->setProperty("nameFilter", nameFilter);
202 if ( m_bDisableScrolling )
203 callExtensionMethod( "disableScrolling" );
205 setLocationBarURL( locationBarURL );
206 setPageSecurity(KonqMainWindow::NotCrypted);
208 if ( !args.reload() )
210 // Save the POST data that is necessary to open this URL
211 // (so that reload can re-post it)
212 m_doPost = browserArgs.doPost();
213 m_postContentType = browserArgs.contentType();
214 m_postData = browserArgs.postData;
215 // Save the referrer
216 m_pageReferrer = args.metaData()["referrer"];
219 if ( tempFile ) {
220 // Store the path to the tempfile. Yes, we could store a bool only,
221 // but this would be more dangerous. If anything goes wrong in the code,
222 // we might end up deleting a real file.
223 if ( url.isLocalFile() )
224 m_tempFile = url.path();
225 else
226 kWarning(1202) << "Tempfile option is set, but URL is remote:" << url ;
229 aboutToOpenURL( url, args );
231 m_pPart->openUrl( url );
233 updateHistoryEntry(false /* don't save location bar URL yet */);
234 // add pending history entry
235 KonqHistoryManager::kself()->addPending( url, locationBarURL, QString());
237 #ifdef DEBUG_HISTORY
238 kDebug(1202) << "Current position:" << historyIndex();
239 #endif
242 void KonqView::switchView( KonqViewFactory &viewFactory )
244 //kDebug(1202);
245 if ( m_pPart )
246 m_pPart->widget()->hide();
248 KParts::ReadOnlyPart *oldPart = m_pPart;
249 m_pPart = m_pKonqFrame->attach( viewFactory ); // creates the part
251 // Set the statusbar in the BE asap to avoid a KMainWindow statusbar being created.
252 KParts::StatusBarExtension* sbext = statusBarExtension();
253 if ( sbext )
254 sbext->setStatusBar( frame()->statusbar() );
256 // Activate the new part
257 if ( oldPart )
259 m_pPart->setObjectName( oldPart->objectName() );
260 emit sigPartChanged( this, oldPart, m_pPart );
261 delete oldPart;
264 connectPart();
266 QVariant prop;
268 prop = m_service->property( "X-KDE-BrowserView-FollowActive");
269 if (prop.isValid() && prop.toBool())
271 //kDebug(1202) << "X-KDE-BrowserView-FollowActive -> setFollowActive";
272 setFollowActive(true);
275 prop = m_service->property( "X-KDE-BrowserView-Built-Into" );
276 m_bBuiltinView = (prop.isValid() && prop.toString() == "konqueror");
278 if ( !m_pMainWindow->viewManager()->isLoadingProfile() )
280 // Honor "non-removeable passive mode" (like the dirtree)
281 prop = m_service->property( "X-KDE-BrowserView-PassiveMode");
282 if ( prop.isValid() && prop.toBool() )
284 kDebug(1202) << "X-KDE-BrowserView-PassiveMode -> setPassiveMode";
285 setPassiveMode( true ); // set as passive
288 // Honor "linked view"
289 prop = m_service->property( "X-KDE-BrowserView-LinkedView");
290 if ( prop.isValid() && prop.toBool() )
292 setLinkedView( true ); // set as linked
293 // Two views : link both
294 if (m_pMainWindow->viewCount() <= 2) // '1' can happen if this view is not yet in the map
296 KonqView * otherView = m_pMainWindow->otherView( this );
297 if (otherView)
298 otherView->setLinkedView( true );
303 prop = m_service->property( "X-KDE-BrowserView-HierarchicalView");
304 if ( prop.isValid() && prop.toBool() )
306 kDebug() << "X-KDE-BrowserView-HierarchicalView -> setHierarchicalView";
307 setHierarchicalView( true ); // set as hierarchial
309 else
311 setHierarchicalView( false );
315 bool KonqView::ensureViewSupports( const QString &mimeType,
316 bool forceAutoEmbed )
318 if (supportsMimeType(mimeType)) {
319 // could be more specific, let's store it so that OpenUrlArguments::mimeType is correct
320 // testcase: http://acid3.acidtests.org/svg.xml should be opened as image/svg+xml
321 m_serviceType = mimeType;
322 return true;
324 return changePart(mimeType, QString(), forceAutoEmbed);
327 bool KonqView::changePart(const QString &mimeType,
328 const QString &serviceName,
329 bool forceAutoEmbed)
331 // Caller should call stop first.
332 assert( !m_bLoading );
334 //kDebug(1202) << "mimeType=" << mimeType
335 // << "requested serviceName=" << serviceName
336 // << "current service name=" << m_service->desktopEntryName();
338 if (serviceName == m_service->desktopEntryName()) {
339 m_serviceType = mimeType;
340 return true;
343 if (isLockedViewMode()) {
344 //kDebug(1202) << "This view's mode is locked - can't change";
345 return false; // we can't do that if our view mode is locked
348 KService::List partServiceOffers, appServiceOffers;
349 KService::Ptr service;
350 KonqFactory konqFactory;
351 KonqViewFactory viewFactory = konqFactory.createView( mimeType, serviceName, &service, &partServiceOffers, &appServiceOffers, forceAutoEmbed );
353 if ( viewFactory.isNull() )
355 // Revert location bar's URL to the working one
356 if(currentHistoryEntry())
357 setLocationBarURL( currentHistoryEntry()->locationBarURL );
358 return false;
361 m_serviceType = mimeType;
362 m_partServiceOffers = partServiceOffers;
363 m_appServiceOffers = appServiceOffers;
365 // Check if that's already the kind of part we have -> no need to recreate it
366 // Note: we should have an operator== for KService...
367 if ( m_service && m_service->entryPath() == service->entryPath() )
369 kDebug( 1202 ) << "Reusing service. Service type set to" << m_serviceType;
370 if ( m_pMainWindow->currentView() == this )
371 m_pMainWindow->updateViewModeActions();
373 else
375 m_service = service;
377 switchView( viewFactory );
380 if ( m_pMainWindow->viewManager()->activePart() != m_pPart )
382 // Make the new part active. Note that we don't do it each time we
383 // open a URL (becomes awful in view-follows-view mode), but we do
384 // each time we change the view mode.
385 // We don't do it in switchView either because it's called from the constructor too,
386 // where the location bar url isn't set yet.
387 //kDebug(1202) << "Giving focus to new part" << m_pPart;
388 m_pMainWindow->viewManager()->setActivePart( m_pPart );
390 return true;
393 void KonqView::connectPart()
395 //kDebug(1202);
396 connect( m_pPart, SIGNAL( started( KIO::Job * ) ),
397 this, SLOT( slotStarted( KIO::Job * ) ) );
398 connect( m_pPart, SIGNAL( completed() ),
399 this, SLOT( slotCompleted() ) );
400 connect( m_pPart, SIGNAL( completed(bool) ),
401 this, SLOT( slotCompleted(bool) ) );
402 connect( m_pPart, SIGNAL( canceled( const QString & ) ),
403 this, SLOT( slotCanceled( const QString & ) ) );
404 connect( m_pPart, SIGNAL( setWindowCaption( const QString & ) ),
405 this, SLOT( setCaption( const QString & ) ) );
406 if (!internalViewMode().isEmpty()) {
407 // Update checked action in "View Mode" menu when switching view mode in dolphin
408 connect(m_pPart, SIGNAL(viewModeChanged()),
409 m_pMainWindow, SLOT(slotInternalViewModeChanged()));
412 KParts::BrowserExtension *ext = browserExtension();
414 if ( ext )
416 ext->setBrowserInterface( m_browserIface );
418 connect( ext, SIGNAL( openUrlRequestDelayed(const KUrl &, const KParts::OpenUrlArguments&, const KParts::BrowserArguments &) ),
419 m_pMainWindow, SLOT( slotOpenURLRequest( const KUrl &, const KParts::OpenUrlArguments&, const KParts::BrowserArguments & ) ) );
421 if ( m_bPopupMenuEnabled )
423 m_bPopupMenuEnabled = false; // force
424 enablePopupMenu( true );
427 connect( ext, SIGNAL( setLocationBarUrl( const QString & ) ),
428 this, SLOT( setLocationBarURL( const QString & ) ) );
430 connect( ext, SIGNAL( setIconUrl( const KUrl & ) ),
431 this, SLOT( setIconURL( const KUrl & ) ) );
433 connect( ext, SIGNAL( setPageSecurity( int ) ),
434 this, SLOT( setPageSecurity( int ) ) );
436 connect( ext, SIGNAL( createNewWindow(const KUrl &, const KParts::OpenUrlArguments &, const KParts::BrowserArguments &, const KParts::WindowArgs &, KParts::ReadOnlyPart**) ),
437 m_pMainWindow, SLOT( slotCreateNewWindow( const KUrl &, const KParts::OpenUrlArguments &, const KParts::BrowserArguments &, const KParts::WindowArgs &, KParts::ReadOnlyPart**) ) );
439 connect( ext, SIGNAL( loadingProgress( int ) ),
440 m_pKonqFrame->statusbar(), SLOT( slotLoadingProgress( int ) ) );
442 connect( ext, SIGNAL( speedProgress( int ) ),
443 m_pKonqFrame->statusbar(), SLOT( slotSpeedProgress( int ) ) );
445 connect( ext, SIGNAL( selectionInfo( const KFileItemList& ) ),
446 this, SLOT( slotSelectionInfo( const KFileItemList& ) ) );
448 connect( ext, SIGNAL( mouseOverInfo( const KFileItem& ) ),
449 this, SLOT( slotMouseOverInfo( const KFileItem& ) ) );
451 connect( ext, SIGNAL( openUrlNotify() ),
452 this, SLOT( slotOpenURLNotify() ) );
454 connect( ext, SIGNAL( enableAction( const char *, bool ) ),
455 this, SLOT( slotEnableAction( const char *, bool ) ) );
457 connect( ext, SIGNAL( setActionText( const char *, const QString& ) ),
458 this, SLOT( slotSetActionText( const char *, const QString& ) ) );
460 connect( ext, SIGNAL( moveTopLevelWidget( int, int ) ),
461 this, SLOT( slotMoveTopLevelWidget( int, int ) ) );
463 connect( ext, SIGNAL( resizeTopLevelWidget( int, int ) ),
464 this, SLOT( slotResizeTopLevelWidget( int, int ) ) );
466 connect( ext, SIGNAL( requestFocus(KParts::ReadOnlyPart *) ),
467 this, SLOT( slotRequestFocus(KParts::ReadOnlyPart *) ) );
469 if (service()->desktopEntryName() != "konq_sidebartng") {
470 connect( ext, SIGNAL( infoMessage( const QString & ) ),
471 m_pKonqFrame->statusbar(), SLOT( message( const QString & ) ) );
473 connect( ext,
474 SIGNAL( addWebSideBar(const KUrl&, const QString&) ),
475 m_pMainWindow,
476 SLOT( slotAddWebSideBar(const KUrl&, const QString&) ) );
480 QVariant urlDropHandling;
482 if ( ext )
483 urlDropHandling = ext->property( "urlDropHandling" );
484 else
485 urlDropHandling = QVariant( true );
487 // Handle url drops if
488 // a) either the property says "ok"
489 // or
490 // b) the part is a plain krop (no BE)
491 m_bURLDropHandling = ( urlDropHandling.type() == QVariant::Bool &&
492 urlDropHandling.toBool() );
494 m_pPart->widget()->installEventFilter( this );
496 if (m_bBackRightClick) {
497 QAbstractScrollArea* scrollArea = ::qobject_cast<QAbstractScrollArea *>( m_pPart->widget() );
498 if ( scrollArea ) {
499 scrollArea->viewport()->installEventFilter( this );
503 #if 0
504 // KonqDirPart signal
505 if ( ::qobject_cast<KonqDirPart *>(m_pPart) )
507 connect( m_pPart, SIGNAL( findOpen( KonqDirPart * ) ),
508 m_pMainWindow, SLOT( slotFindOpen( KonqDirPart * ) ) );
510 #endif
513 void KonqView::slotEnableAction( const char * name, bool enabled )
515 if ( m_pMainWindow->currentView() == this )
516 m_pMainWindow->enableAction( name, enabled );
517 // Otherwise, we don't have to do anything, the state of the action is
518 // stored inside the browser-extension.
521 void KonqView::slotSetActionText( const char* name, const QString& text )
523 if ( m_pMainWindow->currentView() == this )
524 m_pMainWindow->setActionText( name, text );
525 // Otherwise, we don't have to do anything, the state of the action is
526 // stored inside the browser-extension.
529 void KonqView::slotMoveTopLevelWidget( int x, int y )
531 KonqFrameContainerBase* container = frame()->parentContainer();
532 // If tabs are shown, only accept to move the whole window if there's only one tab.
533 if (container->frameType() != KonqFrameBase::Tabs || static_cast<KonqFrameTabs*>(container)->count() == 1)
534 m_pMainWindow->move( x, y );
537 void KonqView::slotResizeTopLevelWidget( int w, int h )
539 KonqFrameContainerBase* container = frame()->parentContainer();
540 // If tabs are shown, only accept to resize the whole window if there's only one tab.
541 // ### Maybe we could store the size requested by each tab and resize the window to the biggest one.
542 if (container->frameType() != KonqFrameBase::Tabs || static_cast<KonqFrameTabs*>(container)->count() == 1)
543 m_pMainWindow->resize( w, h );
546 void KonqView::slotStarted( KIO::Job * job )
548 //kDebug(1202) << job;
549 setLoading( true );
551 if (job)
553 // Manage passwords properly...
554 kDebug(7035) << "Window ID =" << m_pMainWindow->window()->winId();
555 job->ui()->setWindow (m_pMainWindow->window());
557 connect( job, SIGNAL( percent( KJob *, unsigned long ) ), this, SLOT( slotPercent( KJob *, unsigned long ) ) );
558 connect( job, SIGNAL( speed( KJob *, unsigned long ) ), this, SLOT( slotSpeed( KJob *, unsigned long ) ) );
559 connect( job, SIGNAL( infoMessage( KJob *, const QString &, const QString & ) ), this, SLOT( slotInfoMessage( KJob *, const QString & ) ) );
563 void KonqView::slotRequestFocus( KParts::ReadOnlyPart * )
565 m_pMainWindow->viewManager()->showTab(this);
568 void KonqView::setLoading( bool loading, bool hasPending /*= false*/)
570 //kDebug(1202) << "loading=" << loading << "hasPending=" << hasPending;
571 m_bLoading = loading;
572 m_bPendingRedirection = hasPending;
573 if ( m_pMainWindow->currentView() == this )
574 m_pMainWindow->updateToolBarActions( hasPending );
576 m_pMainWindow->viewManager()->setLoading( this, loading || hasPending );
579 void KonqView::slotPercent( KJob *, unsigned long percent )
581 m_pKonqFrame->statusbar()->slotLoadingProgress( percent );
584 void KonqView::slotSpeed( KJob *, unsigned long bytesPerSecond )
586 m_pKonqFrame->statusbar()->slotSpeedProgress( bytesPerSecond );
589 void KonqView::slotInfoMessage( KJob *, const QString &msg )
591 m_pKonqFrame->statusbar()->message( msg );
594 void KonqView::slotCompleted()
596 slotCompleted( false );
599 void KonqView::slotCompleted( bool hasPending )
601 //kDebug(1202) << "hasPending=" << hasPending;
602 m_pKonqFrame->statusbar()->slotLoadingProgress( -1 );
604 if ( ! m_bLockHistory )
606 // Success... update history entry, including location bar URL
607 updateHistoryEntry( true );
609 if ( m_bAborted ) // remove the pending entry on error
610 KonqHistoryManager::kself()->removePending( url() );
611 else if ( currentHistoryEntry() ) // register as proper history entry
612 KonqHistoryManager::kself()->confirmPending(url(), typedUrl(),
613 currentHistoryEntry()->title);
615 emit viewCompleted( this );
617 setLoading( false, hasPending );
619 if (!m_bGotIconURL && !m_bAborted)
621 if ( KonqSettings::enableFavicon() == true )
623 // Try to get /favicon.ico
624 if ( supportsMimeType( "text/html" ) && url().protocol().startsWith( "http" ) )
625 KonqPixmapProvider::self()->downloadHostIcon( url().url() );
630 void KonqView::slotCanceled( const QString & errorMsg )
632 //kDebug(1202);
633 // The errorMsg comes from the ReadOnlyPart's job.
634 // It should probably be used in a KMessageBox
635 // Let's use the statusbar for now
636 m_pKonqFrame->statusbar()->message( errorMsg );
637 m_bAborted = true;
638 slotCompleted();
641 void KonqView::slotSelectionInfo( const KFileItemList &items )
643 KonqFileSelectionEvent ev( items, m_pPart );
644 QApplication::sendEvent( m_pMainWindow, &ev );
647 void KonqView::slotMouseOverInfo( const KFileItem& item )
649 KonqFileMouseOverEvent ev( item, m_pPart );
650 QApplication::sendEvent( m_pMainWindow, &ev );
653 void KonqView::setLocationBarURL( const KUrl& locationBarURL )
655 setLocationBarURL( locationBarURL.pathOrUrl() );
658 void KonqView::setLocationBarURL( const QString & locationBarURL )
660 //kDebug(1202) << locationBarURL << "this=" << this;
661 m_sLocationBarURL = locationBarURL;
662 if (m_pMainWindow->currentView() == this) {
663 //kDebug(1202) << "is current view" << this;
664 m_pMainWindow->setLocationBarURL( m_sLocationBarURL );
665 m_pMainWindow->setPageSecurity( m_pageSecurity );
667 if (!m_bPassiveMode)
668 setTabIcon( KUrl( m_sLocationBarURL ) );
671 void KonqView::setIconURL( const KUrl & iconURL )
672 // This function sets the favIcon in konqui's window if enabled,
673 // thus it is responsible for the icon in the taskbar.
674 // It does not set the tab's favIcon.
676 if ( KonqSettings::enableFavicon() )
678 KonqPixmapProvider::self()->setIconForUrl( m_sLocationBarURL, iconURL.url() );
679 m_bGotIconURL = true;
683 void KonqView::setPageSecurity( int pageSecurity )
685 m_pageSecurity = (KonqMainWindow::PageSecurity)pageSecurity;
687 if ( m_pMainWindow->currentView() == this )
688 m_pMainWindow->setPageSecurity( m_pageSecurity );
691 void KonqView::setTabIcon( const KUrl &url )
693 if (!m_bPassiveMode) frame()->setTabIcon( url, 0L );
696 void KonqView::setCaption( const QString & caption )
698 if (caption.isEmpty()) return;
700 QString adjustedCaption = caption;
701 // For local URLs we prefer to use only the directory name
702 if (url().isLocalFile())
704 // Is the caption a URL? If so, is it local? If so, only display the filename!
705 KUrl url(caption);
706 if (url.isValid() && url.isLocalFile() && url.fileName() == this->url().fileName())
707 adjustedCaption = url.fileName();
710 m_caption = adjustedCaption;
711 if (!m_bPassiveMode) frame()->setTitle( adjustedCaption , 0L );
714 void KonqView::slotOpenURLNotify()
716 #ifdef DEBUG_HISTORY
717 kDebug(1202);
718 #endif
719 updateHistoryEntry(true);
720 createHistoryEntry();
721 if ( m_pMainWindow->currentView() == this )
722 m_pMainWindow->updateToolBarActions();
725 void KonqView::createHistoryEntry()
727 // First, remove any forward history
728 HistoryEntry * current = currentHistoryEntry();
729 if (current)
731 #ifdef DEBUG_HISTORY
732 kDebug(1202) << "Truncating history";
733 #endif
734 while ( current != m_lstHistory.last() )
735 delete m_lstHistory.takeLast();
737 // Append a new entry
738 #ifdef DEBUG_HISTORY
739 kDebug(1202) << "Append a new entry";
740 #endif
741 appendHistoryEntry( new HistoryEntry );
742 setHistoryIndex( m_lstHistory.count()-1 ); // made current
743 #ifdef DEBUG_HISTORY
744 kDebug(1202) << "at=" << historyIndex() << "count=" << m_lstHistory.count();
745 #endif
748 void KonqView::appendHistoryEntry(HistoryEntry * historyEntry)
750 // If there are too many HistoryEntries remove old ones
751 while(m_lstHistory.count() > 0 && m_lstHistory.count() >= KonqSettings::maximumHistoryEntriesPerView())
752 delete m_lstHistory.takeFirst();
754 m_lstHistory.append( historyEntry );
757 void KonqView::updateHistoryEntry( bool saveLocationBarURL )
759 Q_ASSERT( !m_bLockHistory ); // should never happen
761 HistoryEntry * current = currentHistoryEntry();
762 if ( !current )
763 return;
765 current->reload = false; // We have a state for it now.
766 if ( browserExtension() )
768 current->buffer = QByteArray(); // Start with empty buffer.
769 QDataStream stream( &current->buffer, QIODevice::WriteOnly );
771 browserExtension()->saveState( stream );
774 #ifdef DEBUG_HISTORY
775 kDebug(1202) << "Saving part URL:" << m_pPart->url() << "in history position" << historyIndex();
776 #endif
777 current->url = m_pPart->url();
779 if (saveLocationBarURL)
781 #ifdef DEBUG_HISTORY
782 kDebug(1202) << "Saving location bar URL:" << m_sLocationBarURL << "in history position" << historyIndex();
783 #endif
784 current->locationBarURL = m_sLocationBarURL;
785 current->pageSecurity = m_pageSecurity;
787 #ifdef DEBUG_HISTORY
788 kDebug(1202) << "Saving title:" << m_caption << "in history position" << historyIndex();
789 #endif
790 current->title = m_caption;
791 current->strServiceType = m_serviceType;
792 current->strServiceName = m_service->desktopEntryName();
794 current->doPost = m_doPost;
795 current->postData = m_doPost ? m_postData : QByteArray();
796 current->postContentType = m_doPost ? m_postContentType : QString();
797 current->pageReferrer = m_pageReferrer;
800 void KonqView::goHistory( int steps )
802 // This is called by KonqBrowserInterface
803 if ( m_pMainWindow->currentView() == this )
804 m_pMainWindow->viewManager()->setActivePart( part() );
806 // Delay the go() call (we need to return to the caller first)
807 m_pMainWindow->slotGoHistoryActivated( steps );
810 void KonqView::go( int steps )
812 if ( !steps ) // [WildFox] i bet there are sites on the net with stupid devs who do that :)
814 #ifdef DEBUG_HISTORY
815 kDebug(1202) << "go(0) -> reload";
816 #endif
817 // [David] and you're right. And they expect that it reloads, apparently.
818 // [George] I'm going to make nspluginviewer rely on this too. :-)
819 m_pMainWindow->slotReload();
820 return;
823 int newPos = historyIndex() + steps;
824 #ifdef DEBUG_HISTORY
825 kDebug(1202) << "steps=" << steps
826 << "newPos=" << newPos
827 << "m_lstHistory.count()=" << m_lstHistory.count();
828 #endif
829 if( newPos < 0 || newPos >= m_lstHistory.count() )
830 return;
832 stop();
834 setHistoryIndex( newPos ); // sets current item
836 #ifdef DEBUG_HISTORY
837 kDebug(1202) << "New position" << historyIndex();
838 #endif
840 restoreHistory();
843 void KonqView::restoreHistory()
845 HistoryEntry h( *currentHistoryEntry() ); // make a copy of the current history entry, as the data
846 // the pointer points to will change with the following calls
848 #ifdef DEBUG_HISTORY
849 kDebug(1202) << "Restoring servicetype/name, and location bar URL from history:" << h.locationBarURL;
850 #endif
851 setLocationBarURL( h.locationBarURL );
852 setPageSecurity( h.pageSecurity );
853 m_sTypedURL.clear();
855 if (!changePart(h.strServiceType, h.strServiceName)) {
856 kWarning(1202) << "Couldn't change view mode to" << h.strServiceType << h.strServiceName;
857 return /*false*/;
860 setPartMimeType();
862 aboutToOpenURL( h.url );
864 if ( h.reload == false && browserExtension() )
866 //kDebug(1202) << "Restoring view from stream";
867 QDataStream stream( h.buffer );
869 browserExtension()->restoreState( stream );
871 m_doPost = h.doPost;
872 m_postContentType = h.postContentType;
873 m_postData = h.postData;
874 m_pageReferrer = h.pageReferrer;
876 else
877 m_pPart->openUrl( h.url );
879 if ( m_pMainWindow->currentView() == this )
880 m_pMainWindow->updateToolBarActions();
882 #ifdef DEBUG_HISTORY
883 kDebug(1202) << "New position (2)" << historyIndex();
884 #endif
887 const HistoryEntry * KonqView::historyAt(int pos)
889 return m_lstHistory.value(pos);
892 void KonqView::copyHistory( KonqView *other )
894 qDeleteAll( m_lstHistory );
895 m_lstHistory.clear();
897 foreach ( HistoryEntry* he, other->m_lstHistory )
898 appendHistoryEntry( new HistoryEntry( *he ) );
899 setHistoryIndex(other->historyIndex());
902 KUrl KonqView::url() const
904 assert( m_pPart );
905 return m_pPart->url();
908 KUrl KonqView::upUrl() const
910 KUrl currentURL;
911 if ( m_pRun )
912 currentURL = m_pRun->url();
913 else
914 currentURL = m_sLocationBarURL;
915 return currentURL.upUrl();
918 void KonqView::setRun( KonqRun * run )
920 if ( m_pRun )
922 // Tell the KonqRun to abort, but don't delete it ourselves.
923 // It could be showing a message box right now. It will delete itself anyway.
924 m_pRun->abort();
925 // finish() will be emitted later (when back to event loop)
926 // and we don't want it to call slotRunFinished (which stops the animation and stop button).
927 m_pRun->disconnect( m_pMainWindow );
928 if ( !run )
929 frame()->unsetCursor();
931 else if ( run )
932 frame()->setCursor( Qt::BusyCursor );
933 m_pRun = run;
936 void KonqView::stop()
938 //kDebug(1202);
939 m_bAborted = false;
940 finishedWithCurrentURL();
941 if ( m_bLoading || m_bPendingRedirection )
943 // aborted -> confirm the pending url. We might as well remove it, but
944 // we decided to keep it :)
945 KonqHistoryManager::kself()->confirmPending( url(), m_sTypedURL );
947 //kDebug(1202) << "m_pPart->closeUrl()";
948 m_pPart->closeUrl();
949 m_bAborted = true;
950 m_pKonqFrame->statusbar()->slotLoadingProgress( -1 );
951 setLoading( false, false );
953 if ( m_pRun )
955 // Revert to working URL - unless the URL was typed manually
956 // This is duplicated with KonqMainWindow::slotRunFinished, but we can't call it
957 // since it relies on sender()...
958 if ( currentHistoryEntry() && m_pRun->typedUrl().isEmpty() ) { // not typed
959 setLocationBarURL( currentHistoryEntry()->locationBarURL );
960 setPageSecurity( currentHistoryEntry()->pageSecurity );
963 setRun( 0L );
964 m_pKonqFrame->statusbar()->slotLoadingProgress( -1 );
966 if ( !m_bLockHistory && m_lstHistory.count() > 0 )
967 updateHistoryEntry(true);
970 void KonqView::finishedWithCurrentURL()
972 if ( !m_tempFile.isEmpty() )
974 kDebug(1202) << "######### Deleting tempfile after use:" << m_tempFile;
975 QFile::remove( m_tempFile );
976 m_tempFile.clear();
980 void KonqView::setPassiveMode( bool mode )
982 // In theory, if m_bPassiveMode is true and mode is false,
983 // the part should be removed from the part manager,
984 // and if the other way round, it should be readded to the part manager...
985 m_bPassiveMode = mode;
987 if ( mode && m_pMainWindow->viewCount() > 1 && m_pMainWindow->currentView() == this )
989 KParts::Part * part = m_pMainWindow->viewManager()->chooseNextView( this )->part(); // switch active part
990 m_pMainWindow->viewManager()->setActivePart( part );
993 // Update statusbar stuff
994 m_pMainWindow->viewManager()->viewCountChanged();
997 void KonqView::setHierarchicalView( bool mode )
999 m_bHierarchicalView=mode;
1004 void KonqView::setLinkedView( bool mode )
1006 m_bLinkedView = mode;
1007 if ( m_pMainWindow->currentView() == this )
1008 m_pMainWindow->linkViewAction()->setChecked( mode );
1009 frame()->statusbar()->setLinkedView( mode );
1012 void KonqView::setLockedLocation( bool b )
1014 m_bLockedLocation = b;
1017 void KonqView::aboutToOpenURL( const KUrl &url, const KParts::OpenUrlArguments &args )
1019 KParts::OpenUrlEvent ev( m_pPart, url, args );
1020 QApplication::sendEvent( m_pMainWindow, &ev );
1022 m_bGotIconURL = false;
1023 m_bAborted = false;
1026 void KonqView::setPartMimeType()
1028 KParts::OpenUrlArguments args( m_pPart->arguments() );
1029 args.setMimeType( m_serviceType );
1030 m_pPart->setArguments( args );
1033 QStringList KonqView::frameNames() const
1035 return childFrameNames( m_pPart );
1038 QStringList KonqView::childFrameNames( KParts::ReadOnlyPart *part )
1040 QStringList res;
1042 KParts::BrowserHostExtension *hostExtension = KParts::BrowserHostExtension::childObject( part );
1044 if ( !hostExtension )
1045 return res;
1047 res += hostExtension->frameNames();
1049 const QList<KParts::ReadOnlyPart*> children = hostExtension->frames();
1050 QListIterator<KParts::ReadOnlyPart *> i(children);
1051 while (i.hasNext())
1052 res += childFrameNames( i.next() );
1054 return res;
1057 KParts::BrowserHostExtension* KonqView::hostExtension( KParts::ReadOnlyPart *part, const QString &name )
1059 KParts::BrowserHostExtension *ext = KParts::BrowserHostExtension::childObject( part );
1061 if ( !ext )
1062 return 0;
1064 if ( ext->frameNames().contains( name ) )
1065 return ext;
1067 const QList<KParts::ReadOnlyPart*> children = ext->frames();
1068 QListIterator<KParts::ReadOnlyPart *> i(children);
1069 while (i.hasNext())
1071 KParts::BrowserHostExtension *childHost = hostExtension( i.next(), name);
1072 if ( childHost )
1073 return childHost;
1077 return 0;
1080 bool KonqView::callExtensionMethod( const char *methodName )
1082 QObject *obj = KParts::BrowserExtension::childObject( m_pPart );
1083 if ( !obj ) // not all views have a browser extension !
1084 return false;
1086 return QMetaObject::invokeMethod( obj, methodName, Qt::DirectConnection);
1089 bool KonqView::callExtensionBoolMethod( const char *methodName, bool value )
1091 QObject *obj = KParts::BrowserExtension::childObject( m_pPart );
1092 if ( !obj ) // not all views have a browser extension !
1093 return false;
1095 return QMetaObject::invokeMethod( obj, methodName, Qt::DirectConnection, Q_ARG(bool,value));
1098 bool KonqView::callExtensionURLMethod( const char *methodName, const KUrl& value )
1100 QObject *obj = KParts::BrowserExtension::childObject( m_pPart );
1101 if ( !obj ) // not all views have a browser extension !
1102 return false;
1104 return QMetaObject::invokeMethod( obj, methodName, Qt::DirectConnection, Q_ARG(KUrl, value));
1107 void KonqView::setViewName( const QString &name )
1109 //kDebug() << this << "name=" << name;
1110 if ( m_pPart )
1111 m_pPart->setObjectName( name );
1114 QString KonqView::viewName() const
1116 return m_pPart ? m_pPart->objectName() : QString();
1119 void KonqView::enablePopupMenu( bool b )
1121 Q_ASSERT( m_pMainWindow );
1123 KParts::BrowserExtension *ext = browserExtension();
1125 if ( !ext )
1126 return;
1128 if ( m_bPopupMenuEnabled == b )
1129 return;
1131 // enable context popup
1132 if ( b ) {
1133 m_bPopupMenuEnabled = true;
1135 connect( ext, SIGNAL(popupMenu(QPoint,KFileItemList,KParts::OpenUrlArguments,KParts::BrowserArguments,KParts::BrowserExtension::PopupFlags,KParts::BrowserExtension::ActionGroupMap)),
1136 m_pMainWindow, SLOT(slotPopupMenu(QPoint,KFileItemList,KParts::OpenUrlArguments,KParts::BrowserArguments,KParts::BrowserExtension::PopupFlags,KParts::BrowserExtension::ActionGroupMap)) );
1138 connect( ext, SIGNAL(popupMenu(QPoint,KUrl,mode_t,KParts::OpenUrlArguments,KParts::BrowserArguments,KParts::BrowserExtension::PopupFlags,KParts::BrowserExtension::ActionGroupMap)),
1139 m_pMainWindow, SLOT(slotPopupMenu(QPoint,KUrl,mode_t,KParts::OpenUrlArguments,KParts::BrowserArguments,KParts::BrowserExtension::PopupFlags,KParts::BrowserExtension::ActionGroupMap)) );
1141 else // disable context popup
1143 m_bPopupMenuEnabled = false;
1145 disconnect( ext, SIGNAL(popupMenu(QPoint,KFileItemList,KParts::OpenUrlArguments,KParts::BrowserArguments,KParts::BrowserExtension::PopupFlags,KParts::BrowserExtension::ActionGroupMap)),
1146 m_pMainWindow, SLOT(slotPopupMenu(QPoint,KFileItemList,KParts::OpenUrlArguments,KParts::BrowserArguments,KParts::BrowserExtension::PopupFlags,KParts::BrowserExtension::ActionGroupMap)) );
1148 disconnect( ext, SIGNAL(popupMenu(QPoint,KUrl,mode_t,KParts::OpenUrlArguments,KParts::BrowserArguments,KParts::BrowserExtension::PopupFlags,KParts::BrowserExtension::ActionGroupMap)),
1149 m_pMainWindow, SLOT(slotPopupMenu(QPoint,KUrl,mode_t,KParts::OpenUrlArguments,KParts::BrowserArguments,KParts::BrowserExtension::PopupFlags,KParts::BrowserExtension::ActionGroupMap)) );
1151 enableBackRightClick( m_bBackRightClick );
1154 // caller should ensure that this is called only when b changed, or for new parts
1155 void KonqView::enableBackRightClick( bool b )
1157 m_bBackRightClick = b;
1158 if ( b )
1159 connect( this, SIGNAL( backRightClick() ),
1160 m_pMainWindow, SLOT( slotBack() ) );
1161 else
1162 disconnect( this, SIGNAL( backRightClick() ),
1163 m_pMainWindow, SLOT( slotBack() ) );
1166 void KonqView::reparseConfiguration()
1168 callExtensionMethod( "reparseConfiguration" );
1169 const bool b = KonqSettings::backRightClick();
1170 if ( m_bBackRightClick != b ) {
1171 QAbstractScrollArea* scrollArea = ::qobject_cast<QAbstractScrollArea *>( m_pPart->widget() );
1172 if (scrollArea) {
1173 if ( m_bBackRightClick ) {
1174 scrollArea->viewport()->installEventFilter( this );
1175 } else {
1176 scrollArea->viewport()->removeEventFilter( this );
1179 enableBackRightClick( b );
1183 void KonqView::disableScrolling()
1185 m_bDisableScrolling = true;
1186 callExtensionMethod( "disableScrolling" );
1189 QString KonqView::dbusObjectPath()
1191 // TODO maybe this can be improved?
1192 // E.g. using the part's name, but we'd have to update the name in setViewName maybe?
1193 // And to make sure it's a valid dbus object path like in kmainwindow...
1194 static int s_viewNumber = 0;
1195 if ( m_dbusObjectPath.isEmpty() ) {
1196 m_dbusObjectPath = m_pMainWindow->dbusName() + '/' + QString::number( ++s_viewNumber );
1197 new KonqViewAdaptor( this );
1198 QDBusConnection::sessionBus().registerObject( m_dbusObjectPath, this );
1200 return m_dbusObjectPath;
1203 QString KonqView::partObjectPath()
1205 if ( !m_pPart )
1206 return QString();
1208 const QVariant dcopProperty = m_pPart->property( "dbusObjectPath" );
1209 return dcopProperty.toString();
1212 bool KonqView::eventFilter( QObject *obj, QEvent *e )
1214 if ( !m_pPart )
1215 return false;
1216 // kDebug() << "--" << obj->className() << "--" << e->type() << "--" ;
1217 if ( e->type() == QEvent::DragEnter && m_bURLDropHandling && obj == m_pPart->widget() )
1219 QDragEnterEvent *ev = static_cast<QDragEnterEvent *>( e );
1221 if ( KUrl::List::canDecode( ev->mimeData() ) )
1223 KUrl::List lstDragURLs = KUrl::List::fromMimeData( ev->mimeData() );
1225 QList<QWidget *> children = qFindChildren<QWidget *>( m_pPart->widget() );
1227 if ( !lstDragURLs.isEmpty()
1228 && !lstDragURLs.first().url().startsWith( "javascript:", Qt::CaseInsensitive ) && // ### this looks like a hack to me
1229 ev->source() != m_pPart->widget() &&
1230 !children.contains( ev->source() ) )
1231 ev->acceptProposedAction();
1234 else if ( e->type() == QEvent::Drop && m_bURLDropHandling && obj == m_pPart->widget() )
1236 QDropEvent *ev = static_cast<QDropEvent *>( e );
1238 KUrl::List lstDragURLs = KUrl::List::fromMimeData( ev->mimeData() );
1239 KParts::BrowserExtension *ext = browserExtension();
1240 if ( !lstDragURLs.isEmpty() && ext && lstDragURLs.first().isValid() )
1241 emit ext->openUrlRequest( lstDragURLs.first() ); // this will call m_pMainWindow::slotOpenURLRequest delayed
1244 if ( m_bBackRightClick )
1246 if ( e->type() == QEvent::ContextMenu )
1248 QContextMenuEvent *ev = static_cast<QContextMenuEvent *>( e );
1249 if ( ev->reason() == QContextMenuEvent::Mouse )
1251 return true;
1254 else if ( e->type() == QEvent::MouseButtonPress )
1256 QMouseEvent *ev = static_cast<QMouseEvent *>( e );
1257 if ( ev->button() == Qt::RightButton )
1259 return true;
1262 else if ( e->type() == QEvent::MouseButtonRelease )
1264 QMouseEvent *ev = static_cast<QMouseEvent *>( e );
1265 if ( ev->button() == Qt::RightButton )
1267 emit backRightClick();
1268 return true;
1271 else if ( e->type() == QEvent::MouseMove )
1273 QMouseEvent *ev = static_cast<QMouseEvent *>( e );
1274 if ( ev->button() == Qt::RightButton )
1276 obj->removeEventFilter( this );
1277 QMouseEvent me( QEvent::MouseButtonPress, ev->pos(), Qt::RightButton, Qt::RightButton, Qt::NoModifier );
1278 QApplication::sendEvent( obj, &me );
1279 QContextMenuEvent ce( QContextMenuEvent::Mouse, ev->pos(), ev->globalPos() );
1280 QApplication::sendEvent( obj, &ce );
1281 obj->installEventFilter( this );
1282 return true;
1287 if ( e->type() == QEvent::FocusIn )
1289 setActiveComponent();
1291 return false;
1294 void KonqView::setActiveComponent()
1296 if ( m_bBuiltinView || !m_pPart->componentData().isValid() /*never!*/)
1297 KGlobal::setActiveComponent( KGlobal::mainComponent() );
1298 else
1299 KGlobal::setActiveComponent( m_pPart->componentData() );
1302 bool KonqView::prepareReload( KParts::OpenUrlArguments& args, KParts::BrowserArguments& browserArgs, bool softReload )
1304 args.setReload( true );
1305 if ( softReload )
1306 browserArgs.softReload = true;
1308 // Repost form data if this URL is the result of a POST HTML form.
1309 if ( m_doPost && !browserArgs.redirectedRequest() )
1311 if ( KMessageBox::warningContinueCancel( 0, i18n(
1312 "The page you are trying to view is the result of posted form data. "
1313 "If you resend the data, any action the form carried out (such as search or online purchase) will be repeated. "),
1314 i18n( "Warning" ), KGuiItem(i18n( "Resend" )) ) == KMessageBox::Continue )
1316 browserArgs.setDoPost( true );
1317 browserArgs.setContentType( m_postContentType );
1318 browserArgs.postData = m_postData;
1320 else
1321 return false;
1323 // Re-set referrer
1324 args.metaData()["referrer"] = m_pageReferrer;
1326 return true;
1329 KParts::BrowserExtension * KonqView::browserExtension() const
1331 return KParts::BrowserExtension::childObject( m_pPart );
1334 KParts::StatusBarExtension * KonqView::statusBarExtension() const
1336 return KParts::StatusBarExtension::childObject( m_pPart );
1339 bool KonqView::supportsMimeType( const QString &mimeType ) const
1341 KMimeType::Ptr mime = KMimeType::mimeType(mimeType, KMimeType::ResolveAliases);
1342 if (!mime)
1343 return false;
1344 const QStringList lst = serviceTypes();
1345 for( QStringList::ConstIterator it = lst.begin(); it != lst.end(); ++it ) {
1346 if ( mime->is(*it) ) // same as mime == *it, but also respect inheritance, mimeType can be a subclass
1347 return true;
1349 return false;
1352 void HistoryEntry::saveConfig( KConfigGroup& config, const QString &prefix, const KonqFrameBase::Options &options)
1354 if (options & KonqFrameBase::saveURLs) {
1355 config.writeEntry( QString::fromLatin1( "Url" ).prepend( prefix ), url.url() );
1356 config.writeEntry( QString::fromLatin1( "LocationBarURL" ).prepend( prefix ), locationBarURL );
1357 config.writeEntry( QString::fromLatin1( "Title" ).prepend( prefix ), title );
1358 config.writeEntry( QString::fromLatin1( "StrServiceType" ).prepend( prefix ), strServiceType );
1359 config.writeEntry( QString::fromLatin1( "StrServiceName" ).prepend( prefix ), strServiceName );
1360 } else if(options & KonqFrameBase::saveHistoryItems) {
1361 config.writeEntry( QString::fromLatin1( "Url" ).prepend( prefix ), url.url() );
1362 config.writeEntry( QString::fromLatin1( "LocationBarURL" ).prepend( prefix ), locationBarURL );
1363 config.writeEntry( QString::fromLatin1( "Title" ).prepend( prefix ), title );
1364 config.writeEntry( QString::fromLatin1( "Buffer" ).prepend( prefix ), buffer );
1365 config.writeEntry( QString::fromLatin1( "StrServiceType" ).prepend( prefix ), strServiceType );
1366 config.writeEntry( QString::fromLatin1( "StrServiceName" ).prepend( prefix ), strServiceName );
1367 config.writeEntry( QString::fromLatin1( "PostData" ).prepend( prefix ), postData );
1368 config.writeEntry( QString::fromLatin1( "PostContentType" ).prepend( prefix ), postContentType );
1369 config.writeEntry( QString::fromLatin1( "DoPost" ).prepend( prefix ), doPost );
1370 config.writeEntry( QString::fromLatin1( "PageReferrer" ).prepend( prefix ), pageReferrer );
1371 config.writeEntry( QString::fromLatin1( "PageSecurity" ).prepend( prefix ), (int)pageSecurity );
1375 void HistoryEntry::loadItem( const KConfigGroup& config, const QString &prefix, const KonqFrameBase::Options &options)
1378 if (options & KonqFrameBase::saveURLs) {
1379 url = KUrl(config.readEntry( QString::fromLatin1( "Url" ).prepend( prefix ), "" ));
1380 locationBarURL = config.readEntry( QString::fromLatin1( "LocationBarURL" ).prepend( prefix ), "" );
1381 title = config.readEntry( QString::fromLatin1( "Title" ).prepend( prefix ), "" );
1382 strServiceType = config.readEntry( QString::fromLatin1( "StrServiceType" ).prepend( prefix ), "" );
1383 strServiceName = config.readEntry( QString::fromLatin1( "StrServiceName" ).prepend( prefix ), "" );
1384 reload = true;
1385 } else if(options & KonqFrameBase::saveHistoryItems) {
1386 url = KUrl(config.readEntry( QString::fromLatin1( "Url" ).prepend( prefix ), "" ));
1387 locationBarURL = config.readEntry( QString::fromLatin1( "LocationBarURL" ).prepend( prefix ), "" );
1388 title = config.readEntry( QString::fromLatin1( "Title" ).prepend( prefix ), "" );
1389 buffer = config.readEntry( QString::fromLatin1( "Buffer" ).prepend( prefix ), QByteArray() );
1390 strServiceType = config.readEntry( QString::fromLatin1( "StrServiceType" ).prepend( prefix ), "" );
1391 strServiceName = config.readEntry( QString::fromLatin1( "StrServiceName" ).prepend( prefix ), "" );
1392 postData = config.readEntry( QString::fromLatin1( "PostData" ).prepend( prefix ), QByteArray() );
1393 postContentType = config.readEntry( QString::fromLatin1( "PostContentType" ).prepend( prefix ), "" );
1394 doPost = config.readEntry( QString::fromLatin1( "DoPost" ).prepend( prefix ), false );
1395 pageReferrer = config.readEntry( QString::fromLatin1( "PageReferrer" ).prepend( prefix ), "" );
1396 pageSecurity = (KonqMainWindow::PageSecurity)config.readEntry( QString::fromLatin1( "PageSecurity" ).prepend( prefix ), 0 );
1397 reload = false;
1401 void KonqView::saveConfig( KConfigGroup& config, const QString &prefix, const KonqFrameBase::Options &options)
1403 config.writeEntry( QString::fromLatin1( "ServiceType" ).prepend( prefix ), serviceType() );
1404 config.writeEntry( QString::fromLatin1( "ServiceName" ).prepend( prefix ), service()->desktopEntryName() );
1405 config.writeEntry( QString::fromLatin1( "PassiveMode" ).prepend( prefix ), isPassiveMode() );
1406 config.writeEntry( QString::fromLatin1( "LinkedView" ).prepend( prefix ), isLinkedView() );
1407 config.writeEntry( QString::fromLatin1( "ToggleView" ).prepend( prefix ), isToggleView() );
1408 config.writeEntry( QString::fromLatin1( "LockedLocation" ).prepend( prefix ), isLockedLocation() );
1410 if (options & KonqFrameBase::saveURLs) {
1411 config.writePathEntry( QString::fromLatin1( "URL" ).prepend( prefix ), url().url() );
1412 } else if(options & KonqFrameBase::saveHistoryItems) {
1413 if (m_pPart && !m_bLockHistory)
1414 updateHistoryEntry(true);
1415 QList<HistoryEntry*>::Iterator it = m_lstHistory.begin();
1416 for ( int i = 0; it != m_lstHistory.end(); ++it, ++i )
1418 // In order to not end up with a huge config file, we only save full
1419 // history for current history item
1420 KonqFrameBase::Options options;
1421 if(i == m_lstHistoryIndex)
1422 options = KonqFrameBase::saveHistoryItems;
1423 else
1424 options = KonqFrameBase::saveURLs;
1426 (*it)->saveConfig(config, QString::fromLatin1( "HistoryItem" )
1427 + QString::number(i).prepend( prefix ), options);
1429 config.writeEntry( QString::fromLatin1( "CurrentHistoryItem" ).prepend( prefix ), m_lstHistoryIndex );
1430 config.writeEntry( QString::fromLatin1( "NumberOfHistoryItems" ).prepend( prefix ), historyLength() );
1434 void KonqView::loadHistoryConfig(const KConfigGroup& config, const QString &prefix)
1436 // First, remove any history
1437 qDeleteAll(m_lstHistory);
1438 m_lstHistory.clear();
1440 int historySize = config.readEntry( QString::fromLatin1( "NumberOfHistoryItems" ).prepend( prefix ), 0 );
1441 int currentIndex = config.readEntry( QString::fromLatin1( "CurrentHistoryItem" ).prepend( prefix ), historySize-1 );
1443 // No history to restore..
1444 if (historySize == 0)
1446 createHistoryEntry();
1447 return;
1450 // restore history list
1451 for ( int i = 0; i < historySize; ++i )
1453 HistoryEntry* historyEntry = new HistoryEntry;
1455 // Only current history item saves completely its HistoryEntry
1456 KonqFrameBase::Options options;
1457 if(i == currentIndex)
1458 options = KonqFrameBase::saveHistoryItems;
1459 else
1460 options = KonqFrameBase::saveURLs;
1462 historyEntry->loadItem(config, QString::fromLatin1( "HistoryItem" ) + QString::number(i).prepend( prefix ), options);
1464 appendHistoryEntry( historyEntry );
1467 // Shouldn't happen, but just in case..
1468 if(currentIndex >= historyLength())
1469 currentIndex = historyLength()-1;
1471 // set and load the correct history index
1472 setHistoryIndex( currentIndex );
1473 restoreHistory();
1477 QString KonqView::internalViewMode() const
1479 const QVariant viewModeProperty = m_pPart->property("currentViewMode");
1480 return viewModeProperty.toString();
1483 void KonqView::setInternalViewMode(const QString& viewMode)
1485 m_pPart->setProperty("currentViewMode", viewMode);
1488 QString KonqView::nameFilter() const
1490 const QVariant nameFilterProperty = m_pPart->property("nameFilter");
1491 return nameFilterProperty.toString();
1494 bool KonqView::showsDirectory() const
1496 return supportsMimeType(QString::fromLatin1("inode/directory"));
1499 #include "konqview.moc"