Rework the way window settings (size and menubar/toolbar visibility) is handled in konqueror;

the KMainWindow autosave mechanism is now used directly with the profiles; so when you resize
a webbrowsing window it is now automatically saved into the webbrowsing profile, etc.
GUI: For this reason the checkbox "save window size in profile" is gone from the profile dialog.

CCBUG: 63276

svn path=/trunk/KDE/kdebase/apps/; revision=798599
This commit is contained in:
David Faure 2008-04-18 16:34:43 +00:00
parent 7545efaa04
commit 9b8230b223
12 changed files with 269 additions and 271 deletions

View file

@ -52,7 +52,6 @@ void KonqActions::fillHistoryPopup(const QList<HistoryEntry*> &history, int hist
assert ( popup ); // kill me if this 0... :/
//kDebug(1202) << "fillHistoryPopup position: " << history.at();
HistoryEntry * current = history[ historyIndex ];
int index = 0;
if (onlyBack || onlyForward)
{

View file

@ -51,6 +51,8 @@ extern "C" KDE_EXPORT int kdemain( int argc, char **argv )
options.add("preload", ki18n("Preload for later use"));
options.add("mode <mode>", ki18n("Konqueror mode: FileManager or WebBrowser"));
options.add("profile <profile>", ki18n("Profile to open"));
options.add("profiles", ki18n("List available profiles"));
@ -77,6 +79,12 @@ extern "C" KDE_EXPORT int kdemain( int argc, char **argv )
crashlog_file.open();
KonqMainWindow::s_crashlog_file = &crashlog_file;
bool modeSet = false;
if (args->isSet("mode")) {
KonqMisc::setMode(QString::compare(args->getOption("mode"), "filemanager", Qt::CaseInsensitive) == 0 ? KonqMisc::FileManager : KonqMisc::WebBrowser);
modeSet = true;
}
if ( app.isSessionRestored() )
{
int n = 1;
@ -112,6 +120,12 @@ extern "C" KDE_EXPORT int kdemain( int argc, char **argv )
QString profilePath = profile;
if (profile[0] != '/')
profilePath = KStandardDirs::locate( "data", QLatin1String("konqueror/profiles/")+profile );
// Support for the standard kfmclient calls from Home.desktop and konqbrowser.desktop
if (profile.endsWith("filemanagement"))
KonqMisc::setMode(KonqMisc::FileManager);
else if (profile.endsWith("webbrowsing"))
KonqMisc::setMode(KonqMisc::WebBrowser);
QString url;
QStringList filesToSelect;
if (args->count() == 1)

View file

@ -302,11 +302,15 @@ KonqMainWindow::KonqMainWindow( const KUrl &initialURL, const QString& xmluiFile
m_bNeedApplyKonqMainWindowSettings = false;
}
// Read basic main-view settings, and set to autosave
setAutoSaveSettings( "KonqMainWindow", false );
if ( !initialGeometrySet() )
resize( 700, 480 );
// Read basic main-window settings, and enable autosave
// Note that this is just in case we won't use a profile, which is very rare.
// Normally setProfileConfig is called and we then use the profile for main window settings.
KConfigGroup mainWindowSettingsGroup(KonqMisc::modeDependentConfig(), "KonqMainWindow");
setAutoSaveSettings(mainWindowSettingsGroup);
if ( !initialGeometrySet() )
resize( 700, 480 );
//kDebug(1202) << "KonqMainWindow::KonqMainWindow " << this << " done";
if( s_initialMemoryUsage == -1 )
@ -1213,28 +1217,30 @@ void KonqMainWindow::slotCreateNewWindow( const KUrl &url,
mainWindow->viewManager()->setActivePart( *part, true );
}
QString profileName = QLatin1String( url.isLocalFile() ? "konqueror/profiles/filemanagement" : "konqueror/profiles/webbrowsing" );
QString profileName(url.isLocalFile() ? "konqueror/profiles/filemanagement" : "konqueror/profiles/webbrowsing");
if ( windowArgs.x() != -1 )
mainWindow->move( windowArgs.x(), mainWindow->y() );
if ( windowArgs.y() != -1 )
mainWindow->move( mainWindow->x(), windowArgs.y() );
KConfig cfg( KStandardDirs::locate( "data", profileName ) );
KConfigGroup profileGroup( &cfg, "Profile" );
QSize size = KonqViewManager::readConfigSize( profileGroup, mainWindow );
KSharedConfigPtr cfg = KSharedConfig::openConfig(KStandardDirs::locate("data",profileName), KConfig::SimpleConfig);
KConfigGroup profileGroup(cfg, "Profile");
// First, apply default size from profile
applyWindowSizeFromProfile(profileGroup);
int width;
if ( windowArgs.width() != -1 )
width = windowArgs.width();
else
width = size.isValid() ? size.width() : mainWindow->width();
width = mainWindow->width();
int height;
if ( windowArgs.height() != -1 )
height = windowArgs.height();
else
height = size.isValid() ? size.height() : mainWindow->height();
height = mainWindow->height();
mainWindow->resize( width, height );
@ -1331,7 +1337,7 @@ void KonqMainWindow::slotDuplicateWindow()
{
KTemporaryFile tempFile;
tempFile.open();
m_pViewManager->saveViewProfileToFile( tempFile.fileName(), QString(), true, true );
m_pViewManager->saveViewProfileToFile(tempFile.fileName(), QString(), KonqFrameBase::saveURLs);
KonqMainWindow *mainWindow = new KonqMainWindow( KUrl(), xmlFile() );
mainWindow->viewManager()->loadViewProfileFromFile( tempFile.fileName(), m_pViewManager->currentProfile() );
@ -1859,10 +1865,7 @@ void KonqMainWindow::slotConfigureSpellChecking()
void KonqMainWindow::slotConfigureToolbars()
{
if ( autoSaveSettings() ) {
KConfigGroup cg = KGlobal::config()->group( "KonqMainWindow" );
saveMainWindowSettings( cg );
}
slotForceSaveMainWindowSettings();
KEditToolBar dlg(factory(), this);
connect(&dlg,SIGNAL(newToolBarConfig()),this,SLOT(slotNewToolbarConfig()));
connect(&dlg,SIGNAL(newToolBarConfig()),this,SLOT(initBookmarkBar()));
@ -3274,12 +3277,9 @@ void KonqMainWindow::slotClearLocationBar()
void KonqMainWindow::slotForceSaveMainWindowSettings()
{
// kDebug(1202)<<"slotForceSaveMainWindowSettings()";
if ( autoSaveSettings() ) // don't do it on e.g. JS window.open windows with no toolbars!
{
KConfigGroup cg = KGlobal::config()->group( "KonqMainWindow" );
saveMainWindowSettings( cg );
KGlobal::config()->sync();
}
if ( autoSaveSettings() ) { // don't do it on e.g. JS window.open windows with no toolbars!
saveAutoSaveSettings();
}
}
void KonqMainWindow::slotShowMenuBar()
@ -4202,12 +4202,20 @@ void KonqMainWindow::setActionText( const char * name, const QString& text )
}
}
void KonqMainWindow::setProfileConfig(const KSharedConfigPtr& cfg)
{
// Read toolbar settings and window size from profile, and autosave into that profile from now on
setAutoSaveSettings(KConfigGroup(cfg, "Profile"));
currentProfileChanged();
}
void KonqMainWindow::currentProfileChanged()
{
bool enabled = !m_pViewManager->currentProfile().isEmpty();
m_paSaveViewProfile->setEnabled( enabled );
m_paSaveViewProfile->setText( enabled ? i18n("&Save View Profile \"%1\"...", m_pViewManager->currentProfileText())
: i18n("&Save View Profile...") );
const bool enabled = !m_pViewManager->currentProfile().isEmpty();
m_paSaveViewProfile->setEnabled(enabled);
m_paSaveViewProfile->setText(enabled ? i18n("&Save View Profile \"%1\"...", m_pViewManager->currentProfileText())
: i18n("&Save View Profile..."));
}
void KonqMainWindow::enableAllActions( bool enable )
@ -4768,12 +4776,12 @@ void KonqMainWindow::reparseConfiguration()
void KonqMainWindow::saveProperties( KConfigGroup& config )
{
KonqFrameBase::Options flags = KonqFrameBase::saveHistoryItems;
m_pViewManager->saveViewProfileToGroup( config, flags, false );
m_pViewManager->saveViewProfileToGroup(config, flags);
}
void KonqMainWindow::readProperties( const KConfigGroup& config )
{
m_pViewManager->loadViewProfileFromGroup( config, QString() /*no profile name*/ );
m_pViewManager->loadViewProfileFromGroup(config, QString() /*no profile name*/);
}
void KonqMainWindow::setInitialFrameName( const QString &name )
@ -4891,13 +4899,17 @@ void KonqMainWindow::updateViewModeActions()
void KonqMainWindow::slotInternalViewModeChanged()
{
const QString actionName = m_currentView->service()->desktopEntryName();
const QString actionData = m_currentView->internalViewMode();
Q_FOREACH(QAction* action, m_viewModesGroup->actions()) {
if (action->objectName() == actionName &&
action->data().toString() == actionData) {
action->setChecked(true);
break;
KParts::ReadOnlyPart *part = static_cast<KParts::ReadOnlyPart *>(sender());
KonqView * view = m_mapViews.value(part);
if (view) {
const QString actionName = view->service()->desktopEntryName();
const QString actionData = view->internalViewMode();
Q_FOREACH(QAction* action, m_viewModesGroup->actions()) {
if (action->objectName() == actionName &&
action->data().toString() == actionData) {
action->setChecked(true);
break;
}
}
}
}
@ -4992,12 +5004,13 @@ void KonqMainWindow::closeEvent( QCloseEvent *e )
}
}
// save size to have something to restore if the profile does not contain size
saveWindowSize();
addClosedWindowToUndoList();
if (settingsDirty() && autoSaveSettings())
saveAutoSaveSettings();
hide();
qApp->flush();
addClosedWindowToUndoList();
hide();
qApp->flush();
}
// We're going to close - tell the parts
MapViews::ConstIterator it = m_mapViews.begin();
@ -5033,16 +5046,15 @@ void KonqMainWindow::addClosedWindowToUndoList()
QString prefix = QString::fromLatin1( childFrame()->frameType() ) + QString::number(0);
closedWindowItem->configGroup().writeEntry( "RootItem", prefix );
prefix.append( QLatin1Char( '_' ) );
closedWindowItem->configGroup().writeEntry( "Width", width() );
closedWindowItem->configGroup().writeEntry( "Height", height() );
// Done by saveMainWindowSettings already:
//closedWindowItem->configGroup().writeEntry( "Width", width() );
//closedWindowItem->configGroup().writeEntry( "Height", height() );
closedWindowItem->configGroup().writeEntry( "FullScreen", fullScreenMode() );
closedWindowItem->configGroup().writeEntry( "XMLUIFile", xmlFile() );
tabContainer->saveConfig( closedWindowItem->configGroup(), prefix, flags, 0L, 0, 1);
// Save window settings
KConfigGroup cfg( &closedWindowItem->configGroup(), "Main Window Settings" );
saveMainWindowSettings( cfg );
saveMainWindowSettings( closedWindowItem->configGroup() );
closedWindowItem->configGroup().sync();
// 3. Finally add the KonqClosedWindowItem to the undo list
m_paClosedItems->setEnabled(true);
m_undoManager->addClosedWindowItem( closedWindowItem );
@ -5711,19 +5723,6 @@ KonqView * KonqMainWindow::currentView() const
return m_currentView;
}
void KonqMainWindow::saveWindowSize() const
{
KConfigGroup cg( KGlobal::config()->group( "KonqMainWindow_Size" ) );
KParts::MainWindow::saveWindowSize( cg );
KGlobal::config()->sync();
}
void KonqMainWindow::restoreWindowSize()
{
const KConfigGroup cg( KGlobal::config()->group( "KonqMainWindow_Size" ) );
KParts::MainWindow::restoreWindowSize( cg );
}
bool KonqMainWindow::accept( KonqFrameVisitor* visitor )
{
if ( !visitor->visit( this ) )
@ -5748,4 +5747,13 @@ bool KonqMainWindow::hasViewWithMimeType(const QString& mimeType) const
return false;
}
void KonqMainWindow::applyWindowSizeFromProfile(const KConfigGroup& profileGroup)
{
// KMainWindow::restoreWindowSize is protected so this logic can't move to KonqViewManager
const QSize size = KonqViewManager::readDefaultSize(profileGroup, this); // example: "Width=80%"
if (size.isValid())
resize(size);
restoreWindowSize(profileGroup); // example: "Width 1400=1120"
}
#include "konqmainwindow.moc"

View file

@ -252,8 +252,12 @@ public:
// public for konq_guiclients
void viewCountChanged();
// for the view manager
void currentProfileChanged();
/**
* For the view manager: we are loading the profile from this config file,
* so we should save mainwindow settings into that file from now on
*/
void setProfileConfig(const KSharedConfigPtr& cfg);
void currentProfileChanged();
// operates on all combos of all mainwindows of this instance
// up to now adds an entry or clears all entries
@ -313,11 +317,8 @@ public:
QString currentTitle() const;
QString currentURL() const;
QString currentProfile() const;
void applyWindowSizeFromProfile(const KConfigGroup& profileGroup);
QStringList configModules() const;
void saveWindowSize() const;
void restoreWindowSize();
void updateHistoryActions();
Q_SIGNALS:

View file

@ -102,8 +102,7 @@ KonqMainWindow * KonqMisc::createBrowserWindowFromProfile( const QString &path,
const KParts::BrowserArguments& browserArgs,
bool forbidUseHTML, const QStringList& filesToSelect, bool tempFile, bool openUrl )
{
kDebug(1202) << "void KonqMisc::createBrowserWindowFromProfile() ";
kDebug(1202) << "path=" << path << ",filename=" << filename << ",url=" << url.prettyUrl();
kDebug(1202) << "path=" << path << ", filename=" << filename << ", url=" << url;
abortFullScreenMode();
KonqOpenURLRequest req;
@ -115,7 +114,7 @@ KonqMainWindow * KonqMisc::createBrowserWindowFromProfile( const QString &path,
KonqMainWindow * mainWindow;
if ( path.isEmpty() )
{
// The profile doesn't exit -> creating a simple window
// The profile doesn't exist -> creating a simple window
mainWindow = new KonqMainWindow;
mainWindow->openUrl( 0, url, QString(), req );
}
@ -133,12 +132,12 @@ KonqMainWindow * KonqMisc::createBrowserWindowFromProfile( const QString &path,
}
else
{
KConfig cfg( path );
KConfigGroup profileGroup( &cfg, "Profile" );
QString xmluiFile = profileGroup.readPathEntry("XMLUIFile","konqueror.rc");
KSharedConfigPtr cfg = KSharedConfig::openConfig(path, KConfig::SimpleConfig);
const KConfigGroup profileGroup(cfg, "Profile");
const QString xmluiFile = profileGroup.readPathEntry("XMLUIFile","konqueror.rc");
mainWindow = new KonqMainWindow( KUrl(), xmluiFile );
mainWindow->viewManager()->loadViewProfileFromConfig( cfg, filename, url, req, false, openUrl );
mainWindow = new KonqMainWindow(KUrl(), xmluiFile);
mainWindow->viewManager()->loadViewProfileFromConfig(cfg, path, filename, url, req, false, openUrl);
}
if ( forbidUseHTML )
mainWindow->setShowHTML( false );
@ -205,4 +204,25 @@ QString KonqMisc::konqFilteredURL( QWidget* parent, const QString& _url, const Q
return _url; // return the original url if it cannot be filtered.
}
static KonqMisc::Mode s_mode = KonqMisc::WebBrowser;
void KonqMisc::setMode( Mode mode )
{
s_mode = mode;
}
KonqMisc::Mode KonqMisc::mode()
{
return s_mode;
}
KSharedConfigPtr KonqMisc::modeDependentConfig()
{
if (s_mode == KonqMisc::WebBrowser) {
return KGlobal::config();
} else {
return KSharedConfig::openConfig("kfmrc");
}
}
#include "konqmisc.moc"

View file

@ -26,49 +26,54 @@
#include <kparts/browserextension.h>
class KonqMainWindow;
class KonqView;
class KStandardDirs;
class KSharedConfig;
template <typename T> class KSharedPtr;
typedef KSharedPtr<KSharedConfig> KSharedConfigPtr;
class KONQ_TESTS_EXPORT KonqMisc
namespace KonqMisc // TODO rename to KonqGlobal?
{
public:
/*
private:
static KonqFileManager *s_pSelf;
public:
KonqFileManager() {}
~KonqFileManager() {}
enum Mode { FileManager, WebBrowser };
/**
* Sets the mode. ONLY called by konqmain! We cannot switch modes, we don't want to switch modes.
*/
void setMode( Mode mode );
/**
* Returns the mode used by this konqueror process.
*/
Mode mode();
static KonqFileManager *self()
{
if ( !s_pSelf )
s_pSelf = new KonqFileManager();
return s_pSelf;
}
*/
/**
* Returns the KConfig object where to load/save mode-dependent settings
* (where mode is filemanager or webbrowser).
* For instance the HomeURL setting.
*/
KSharedConfigPtr modeDependentConfig();
/**
* Stop full-screen mode in all windows.
*/
static void abortFullScreenMode();
void abortFullScreenMode();
/**
* Create a new window with a single view, showing @p url, using @p args
*/
static KonqMainWindow * createSimpleWindow( const KUrl &url, const KParts::OpenUrlArguments &args,
const KParts::BrowserArguments& browserArgs = KParts::BrowserArguments(),
bool tempFile = false);
KonqMainWindow * createSimpleWindow( const KUrl &url, const KParts::OpenUrlArguments &args,
const KParts::BrowserArguments& browserArgs = KParts::BrowserArguments(),
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::OpenUrlArguments &args = KParts::OpenUrlArguments(),
const KParts::BrowserArguments& browserArgs = KParts::BrowserArguments(),
bool forbidUseHTML = false,
const QStringList &filesToSelect = QStringList(),
bool tempFile = false,
bool openUrl = true);
KonqMainWindow * createNewWindow( const KUrl &url,
const KParts::OpenUrlArguments &args = KParts::OpenUrlArguments(),
const KParts::BrowserArguments& browserArgs = KParts::BrowserArguments(),
bool forbidUseHTML = false,
const QStringList &filesToSelect = QStringList(),
bool tempFile = false,
bool openUrl = true);
/**
* Create a new window from the profile defined by @p filename and @p path.
@ -76,22 +81,22 @@ public:
* @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,
const KUrl &url = KUrl(),
const KParts::OpenUrlArguments &args = KParts::OpenUrlArguments(),
const KParts::BrowserArguments& browserArgs = KParts::BrowserArguments(),
bool forbidUseHTML = false,
const QStringList& filesToSelect = QStringList(),
bool tempFile = false,
bool openUrl = true);
KonqMainWindow * createBrowserWindowFromProfile( const QString &path,
const QString &filename,
const KUrl &url = KUrl(),
const KParts::OpenUrlArguments &args = KParts::OpenUrlArguments(),
const KParts::BrowserArguments& browserArgs = KParts::BrowserArguments(),
bool forbidUseHTML = false,
const QStringList& filesToSelect = QStringList(),
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 );
KonqMainWindow * newWindowFromHistory( KonqView* view, int steps );
/**
* Applies the URI filters to @p url.
@ -100,8 +105,8 @@ public:
* @p _url to be filtered.
* @p _path the absolute path to append to the url before filtering it.
*/
static QString konqFilteredURL( QWidget* /*parent*/, const QString& /*_url*/, const QString& _path = QString() );
QString konqFilteredURL( QWidget* /*parent*/, const QString& /*_url*/, const QString& _path = QString() );
};
}
#endif

View file

@ -125,7 +125,6 @@ KonqProfileDlg::KonqProfileDlg( KonqViewManager *manager, const QString & presel
d->m_pListView->setMinimumSize( d->m_pListView->sizeHint() );
d->m_cbSaveURLs->setChecked( KonqSettings::saveURLInProfile() );
d->m_cbSaveSize->setChecked( KonqSettings::saveWindowSizeInProfile() );
connect( d->m_pListView, SIGNAL( itemSelectionChanged() ),
this, SLOT( slotSelectionChanged() ) );
@ -146,7 +145,6 @@ KonqProfileDlg::KonqProfileDlg( KonqViewManager *manager, const QString & presel
KonqProfileDlg::~KonqProfileDlg()
{
KonqSettings::setSaveURLInProfile( d->m_cbSaveURLs->isChecked() );
KonqSettings::setSaveWindowSizeInProfile( d->m_cbSaveSize->isChecked() );
}
void KonqProfileDlg::loadAllProfiles(const QString & preselectProfile)
@ -192,7 +190,7 @@ void KonqProfileDlg::slotSave()
kDebug(1202) << "Saving as " << name;
d->m_pViewManager->saveViewProfileToFile( name, d->m_pProfileNameLineEdit->text(),
d->m_cbSaveURLs->isChecked(), d->m_cbSaveSize->isChecked() );
d->m_cbSaveURLs->isChecked() ? KonqFrameBase::saveURLs : KonqFrameBase::None);
accept();
}

View file

@ -33,13 +33,6 @@
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="m_cbSaveSize" >
<property name="text" >
<string>Save &amp;window size in profile</string>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>

View file

@ -493,12 +493,6 @@ PATH_JAVA
<whatsthis></whatsthis>
<!-- checked -->
</entry>
<entry key="SaveWindowSizeInProfile" type="Bool">
<default>false</default>
<label></label>
<whatsthis></whatsthis>
<!-- checked -->
</entry>
<entry name="SettingsCompletionMode" key="CompletionMode" type="Enum">
<default code="true">KGlobalSettings::completionMode()</default>
<label></label>

View file

@ -739,7 +739,7 @@ void KonqView::appendHistoryEntry(HistoryEntry * historyEntry)
// If there are too many HistoryEntries remove old ones
while(m_lstHistory.count() > 0 && m_lstHistory.count() >= KonqSettings::maximumHistoryEntriesPerView())
delete m_lstHistory.takeFirst();
m_lstHistory.append( historyEntry );
}
@ -1335,7 +1335,7 @@ KParts::StatusBarExtension * KonqView::statusBarExtension() const
bool KonqView::supportsMimeType( const QString &mimeType ) const
{
KMimeType::Ptr mime = KMimeType::mimeType( mimeType );
KMimeType::Ptr mime = KMimeType::mimeType(mimeType, KMimeType::ResolveAliases);
if (!mime)
return false;
const QStringList lst = serviceTypes();

View file

@ -340,30 +340,22 @@ void KonqViewManager::openClosedWindow(const KonqClosedWindowItem& closedWindowI
kDebug(1202) << "begin";
const QString xmluiFile =
closedWindowItem.configGroup().readEntry("XMLUIFile","konqueror.rc");
// TODO factorize to avoid code duplication with loadViewProfileFromGroup
KonqMainWindow *mainWindow = new KonqMainWindow(KUrl(), xmluiFile);
if (closedWindowItem.configGroup().readEntry( "FullScreen", false ))
{
if (closedWindowItem.configGroup().readEntry("FullScreen", false)) {
// Full screen on
mainWindow->showFullScreen();
}
else
{
} else {
// Full screen off
if( mainWindow->isFullScreen())
mainWindow->showNormal();
const QSize size = readConfigSize( closedWindowItem.configGroup(), mainWindow );
if ( size.isValid() )
mainWindow->resize( size );
else // no size in the profile; use last known size
mainWindow->restoreWindowSize();
// Window size comes from the applyMainWindowSettings call below
}
mainWindow->viewManager()->loadRootItem( closedWindowItem.configGroup(), mainWindow->viewManager()->tabContainer(), KUrl(), true, KUrl() );
// read window settings
mainWindow->applyMainWindowSettings( KConfigGroup( KGlobal::config(), "KonqMainWindow" ), true );
mainWindow->applyMainWindowSettings( KConfigGroup( & closedWindowItem.configGroup(), "Main Window Settings" ), true );
mainWindow->viewManager()->loadRootItem(closedWindowItem.configGroup(), mainWindow->viewManager()->tabContainer(), KUrl(), true, KUrl());
mainWindow->applyMainWindowSettings(closedWindowItem.configGroup(), true);
mainWindow->activateChild();
mainWindow->show();
kDebug(1202) << "done";
@ -804,37 +796,23 @@ KonqView *KonqViewManager::setupView( KonqFrameContainerBase *parentContainer,
///////////////// Profile stuff ////////////////
void KonqViewManager::saveViewProfileToFile( const QString & fileName, const QString & profileName, bool saveURLs, bool saveWindowSize )
void KonqViewManager::saveViewProfileToFile(const QString & fileName, const QString & profileName, KonqFrameBase::Options options)
{
const QString path = KStandardDirs::locateLocal("data", QString::fromLatin1("konqueror/profiles/") +
fileName, KGlobal::mainComponent());
QFile::remove(path); // in case it exists already
QString path = KStandardDirs::locateLocal( "data", QString::fromLatin1( "konqueror/profiles/" ) +
fileName, KGlobal::mainComponent() );
KConfig _cfg(path, KConfig::SimpleConfig);
KConfigGroup profileGroup(&_cfg, "Profile");
if (!profileName.isEmpty())
profileGroup.writePathEntry("Name", profileName);
if ( QFile::exists( path ) )
QFile::remove( path );
saveViewProfileToGroup(profileGroup, options);
KConfig _cfg( path, KConfig::SimpleConfig );
KConfigGroup cfg(&_cfg, "Profile" );
if ( !profileName.isEmpty() )
cfg.writePathEntry( "Name", profileName );
KonqFrameBase::Options options = KonqFrameBase::None;
if(saveURLs)
options = KonqFrameBase::saveURLs;
saveViewProfileToGroup( cfg, options, saveWindowSize );
// Save menu/toolbar settings in profile. Relies on konq_mainwindow calling
// setAutoSaveSetting( "KonqMainWindow", false ). The false is important,
// we do not want this call save size settings in the profile, because we
// do it ourselves. Save in a separate group than the rest of the profile.
KConfigGroup cg = cfg.group( "Main Window Settings" );
m_pMainWindow->saveMainWindowSettings( cg );
cfg.sync();
_cfg.sync();
}
void KonqViewManager::saveViewProfileToGroup( KConfigGroup & profileGroup, const KonqFrameBase::Options &options, bool saveWindowSize )
void KonqViewManager::saveViewProfileToGroup(KConfigGroup & profileGroup, KonqFrameBase::Options options)
{
if( m_pMainWindow->childFrame() ) {
QString prefix = QString::fromLatin1( m_pMainWindow->childFrame()->frameType() )
@ -846,40 +824,54 @@ void KonqViewManager::saveViewProfileToGroup( KConfigGroup & profileGroup, const
profileGroup.writeEntry( "FullScreen", m_pMainWindow->fullScreenMode());
profileGroup.writeEntry("XMLUIFile", m_pMainWindow->xmlFile());
if ( saveWindowSize ) {
profileGroup.writeEntry( "Width", m_pMainWindow->width() );
profileGroup.writeEntry( "Height", m_pMainWindow->height() );
}
m_pMainWindow->saveMainWindowSettings(profileGroup);
}
void KonqViewManager::loadViewProfileFromFile( const QString & path, const QString & filename,
const KUrl & forcedUrl, const KonqOpenURLRequest &req,
bool resetWindow, bool openUrl )
{
KConfig config( path );
loadViewProfileFromConfig(config, filename, forcedUrl, req, resetWindow, openUrl );
KSharedConfig::Ptr config = KSharedConfig::openConfig(path, KConfig::SimpleConfig);
loadViewProfileFromConfig(config, path, filename, forcedUrl, req, resetWindow, openUrl );
}
void KonqViewManager::loadViewProfileFromConfig( const KConfig& cfg, const QString & filename,
void KonqViewManager::loadViewProfileFromConfig( const KSharedConfigPtr& _cfg,
const QString& path,
const QString & filename,
const KUrl & forcedUrl,
const KonqOpenURLRequest &req,
bool resetWindow, bool openUrl )
{
KConfigGroup profileGroup( &cfg, "Profile" );
KConfigGroup profileGroup(_cfg, "Profile");
loadViewProfileFromGroup( profileGroup, filename, forcedUrl, req, resetWindow, openUrl );
m_currentProfile = filename;
m_currentProfileText = profileGroup.readPathEntry("Name", filename);
m_profileHomeURL = profileGroup.readPathEntry("HomeURL", QString()); // TODO remove
if( resetWindow )
{ // force default settings for the GUI
m_pMainWindow->applyMainWindowSettings( KConfigGroup( KGlobal::config(), "KonqMainWindow" ), true );
#if 0 // This isn't needed, the size should always be there in the profile anyway
if( resetWindow ) {
m_pMainWindow->applyMainWindowSettings(KConfigGroup(KonqMisc::modeDependentConfig(),"KonqMainWindow"), true);
}
#endif
loadViewProfileFromGroup( profileGroup, filename, forcedUrl, req, openUrl );
KSharedConfigPtr cfg(_cfg);
if (!filename.isEmpty()) {
// We'll use the profile for saving window settings - so ensure we can save to it
const QString localPath = KStandardDirs::locateLocal("data", QString::fromLatin1("konqueror/profiles/") +
filename, KGlobal::mainComponent());
if (localPath != path) {
cfg = KSharedConfig::openConfig(localPath, KConfig::SimpleConfig);
_cfg->copyTo(localPath, cfg.data());
}
}
// Apply menu/toolbar settings saved in profile. Read from a separate group
// so that the window doesn't try to change the size stored in the Profile group.
// (If applyMainWindowSettings finds a "Width" or "Height" entry, it
// sets them to 0,0)
m_pMainWindow->applyMainWindowSettings( KConfigGroup(&cfg, "Main Window Settings") );
// setProfileConfig must be done after setting m_currentProfile/m_currentProfileText
// We also do it after loadViewProfileFromGroup so that we can override the default size (Width=80%)
m_pMainWindow->setProfileConfig(cfg);
#ifdef DEBUG_VIEWMGR
printFullHierarchy( m_pMainWindow );
@ -888,18 +880,13 @@ void KonqViewManager::loadViewProfileFromConfig( const KConfig& cfg, const QStri
void KonqViewManager::loadViewProfileFromGroup( const KConfigGroup &profileGroup, const QString & filename,
const KUrl & forcedUrl, const KonqOpenURLRequest &req,
bool resetWindow, bool openUrl )
bool openUrl )
{
Q_UNUSED(resetWindow);
Q_UNUSED(filename); // could be useful in case of error messages
m_currentProfile = filename;
m_currentProfileText = profileGroup.readPathEntry("Name", filename);
m_profileHomeURL = profileGroup.readPathEntry("HomeURL", QString());
m_pMainWindow->currentProfileChanged();
KUrl defaultURL;
if ( m_pMainWindow->currentView() )
defaultURL = m_pMainWindow->currentView()->url();
KUrl defaultURL;
if (m_pMainWindow->currentView())
defaultURL = m_pMainWindow->currentView()->url();
clear();
@ -927,8 +914,7 @@ void KonqViewManager::loadViewProfileFromGroup( const KConfigGroup &profileGroup
nextChildView->setViewName( req.browserArgs.frameName );
}
if ( openUrl && !forcedUrl.isEmpty())
{
if (openUrl && !forcedUrl.isEmpty()) {
KonqOpenURLRequest _req(req);
_req.openAfterCurrentPage = KonqSettings::openAfterCurrentPage();
_req.forceAutoEmbed = true; // it's a new window, let's use it
@ -938,35 +924,24 @@ void KonqViewManager::loadViewProfileFromGroup( const KConfigGroup &profileGroup
// TODO choose a linked view if any (instead of just the first one),
// then open the same URL in any non-linked one
}
else
{
if ( m_pMainWindow->locationBarURL().isEmpty() ) // No URL -> the user will want to type one
m_pMainWindow->focusLocationBar();
}
} else {
if (m_pMainWindow->locationBarURL().isEmpty()) // No URL -> the user will want to type one
m_pMainWindow->focusLocationBar();
}
// Window size
if ( !m_pMainWindow->initialGeometrySet() )
{
if (profileGroup.readEntry( "FullScreen",false ))
{
// Full screen on
m_pMainWindow->setWindowState( m_pMainWindow->windowState() | Qt::WindowFullScreen );
}
else
{
// Full screen off
m_pMainWindow->setWindowState( m_pMainWindow->windowState() & ~Qt::WindowFullScreen );
// Window size
if (!m_pMainWindow->initialGeometrySet()) {
if (profileGroup.readEntry("FullScreen", false)) {
// Full screen on
m_pMainWindow->setWindowState(m_pMainWindow->windowState() | Qt::WindowFullScreen);
} else {
// Full screen off
m_pMainWindow->setWindowState(m_pMainWindow->windowState() & ~Qt::WindowFullScreen);
m_pMainWindow->applyWindowSizeFromProfile(profileGroup);
}
}
const QSize size = readConfigSize( profileGroup, m_pMainWindow );
if ( size.isValid() )
m_pMainWindow->resize( size );
else // no size in the profile; use last known size
m_pMainWindow->restoreWindowSize();
}
}
//kDebug(1202) << "done";
//kDebug(1202) << "done";
}
void KonqViewManager::setActivePart( KParts::Part *part, QWidget * )
@ -1057,50 +1032,40 @@ void KonqViewManager::emitActivePartChanged()
m_pMainWindow->slotPartActivated( activePart() );
}
QSize KonqViewManager::readConfigSize( const KConfigGroup &cfg, QWidget *widget )
QSize KonqViewManager::readDefaultSize(const KConfigGroup &cfg, QWidget *widget)
{
bool ok;
QString widthStr = cfg.readEntry( "Width" );
QString heightStr = cfg.readEntry( "Height" );
QString widthStr = cfg.readEntry("Width");
QString heightStr = cfg.readEntry("Height");
int width = -1;
int height = -1;
const QRect geom = KGlobalSettings::desktopGeometry(widget);
QRect geom = KGlobalSettings::desktopGeometry(widget);
if ( widthStr.endsWith( '%' ) )
{
widthStr.truncate( widthStr.length() - 1 );
int relativeWidth = widthStr.toInt( &ok );
if ( ok ) {
bool ok;
if (widthStr.endsWith('%')) {
widthStr.truncate(widthStr.length()-1);
const int relativeWidth = widthStr.toInt(&ok);
if (ok) {
width = relativeWidth * geom.width() / 100;
}
}
else
{
} else {
width = widthStr.toInt( &ok );
if ( !ok )
if (!ok)
width = -1;
}
if ( heightStr.endsWith( '%' ) )
{
heightStr.truncate( heightStr.length() - 1 );
int relativeHeight = heightStr.toInt( &ok );
if ( ok ) {
if (heightStr.endsWith('%')) {
heightStr.truncate(heightStr.length() - 1);
int relativeHeight = heightStr.toInt(&ok);
if (ok) {
height = relativeHeight * geom.height() / 100;
}
}
else
{
height = heightStr.toInt( &ok );
if ( !ok )
} else {
height = heightStr.toInt(&ok);
if (!ok)
height = -1;
}
return QSize( width, height );
return QSize(width, height);
}
void KonqViewManager::loadRootItem( const KConfigGroup &cfg, KonqFrameContainerBase *parent,
@ -1254,12 +1219,12 @@ void KonqViewManager::loadItem( const KConfigGroup &cfg, KonqFrameContainerBase
loadItem( cfg, parent, "InitialView", defaultURL, openUrl, forcedUrl );
} else if( childList.count() == 1 )
{
if ( !m_tabContainer ) {
createTabContainer(parent->asQWidget(), parent);
parent->insertChildFrame( m_tabContainer );
}
loadItem( cfg, tabContainer(), childList.at(0), defaultURL, openUrl, forcedUrl );
QWidget* currentPage = m_tabContainer->currentWidget();
if (currentPage != 0L) {
@ -1269,14 +1234,14 @@ void KonqViewManager::loadItem( const KConfigGroup &cfg, KonqFrameContainerBase
activeChildView->setTabIcon( activeChildView->url() );
}
}
QWidget* w = m_tabContainer->widget(index);
Q_ASSERT(w);
m_tabContainer->setActiveChild( dynamic_cast<KonqFrameBase*>(w) );
m_tabContainer->setCurrentIndex( index );
m_tabContainer->show();
}
else
{

View file

@ -33,6 +33,7 @@
#include <kparts/partmanager.h>
#include "konqopenurlrequest.h"
class KMainWindow;
class KonqFrameTabs;
class QString;
class QTimer;
@ -177,10 +178,9 @@ public:
* @param fileName the name of the config file
* @param profileName the name of the profile
* @param saveURLs whether to save the URLs in the profile
* @param saveWindowSize whether to save the size of the window in the profile
*/
void saveViewProfileToFile( const QString & fileName, const QString & profileName,
bool saveURLs, bool saveWindowSize );
void saveViewProfileToFile(const QString & fileName, const QString & profileName,
KonqFrameBase::Options options);
/**
* Saves the current view layout to a group in a config file.
@ -188,9 +188,8 @@ public:
* Remove config file before saving, especially if saveURLs is false.
* @param cfg the config file
* @param options whether to save nothing, the URLs or the complete history of each view in the profile
* @param saveWindowSize whether to save the size of the window in the profile
*/
void saveViewProfileToGroup( KConfigGroup & cfg, const KonqFrameBase::Options &options, bool saveWindowSize );
void saveViewProfileToGroup(KConfigGroup & cfg, KonqFrameBase::Options options);
/**
@ -208,7 +207,9 @@ public:
const KonqOpenURLRequest &req = KonqOpenURLRequest(),
bool resetWindow = false, bool openUrl = true );
// Overload for KonqMisc::createBrowserWindowFromProfile
void loadViewProfileFromConfig( const KConfig& config, const QString & filename,
void loadViewProfileFromConfig( const KSharedConfigPtr& config,
const QString& path,
const QString & filename,
const KUrl & forcedUrl = KUrl(),
const KonqOpenURLRequest &req = KonqOpenURLRequest(),
bool resetWindow = false, bool openUrl = true );
@ -225,7 +226,7 @@ public:
void loadViewProfileFromGroup( const KConfigGroup& cfg, const QString & filename,
const KUrl & forcedUrl = KUrl(),
const KonqOpenURLRequest &req = KonqOpenURLRequest(),
bool resetWindow = false, bool openUrl = true );
bool openUrl = true );
/**
* Return the filename of the last profile that was loaded
* by the view manager. For "save settings".
@ -277,10 +278,10 @@ public:
void showProfileDlg( const QString & preselectProfile );
/**
* The widget is the one which you are referring to.
*/
static QSize readConfigSize( const KConfigGroup &cfg, QWidget *widget = NULL);
/**
* Read default size from profile (e.g. Width=80%)
*/
static QSize readDefaultSize(const KConfigGroup& cfg, QWidget* window);
#ifndef NDEBUG
void printFullHierarchy( KonqFrameContainerBase * container );