Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Utilities
Konsole
Commits
193777e2
Commit
193777e2
authored
Mar 27, 2012
by
Jekyll Wu
Browse files
Split class SessionManager into ProfileMananger and SessionManager
REVIEW: 104425
parent
1ffeb4bb
Changes
12
Hide whitespace changes
Inline
Side-by-side
src/Application.cpp
View file @
193777e2
...
...
@@ -33,6 +33,7 @@
// Konsole
#include
"SessionManager.h"
#include
"ProfileManager.h"
#include
"MainWindow.h"
#include
"Session.h"
#include
"ShellCommand.h"
...
...
@@ -63,7 +64,7 @@ void Application::init()
Application
::~
Application
()
{
SessionManager
::
instance
()
->
closeAllSessions
();
Session
Manager
::
instance
()
->
saveSettings
();
Profile
Manager
::
instance
()
->
saveSettings
();
}
MainWindow
*
Application
::
newMainWindow
()
...
...
@@ -224,11 +225,11 @@ void Application::createTabFromArgs(KCmdLineArgs* args, MainWindow* window,
Profile
::
Ptr
baseProfile
;
if
(
!
profile
.
isEmpty
())
{
baseProfile
=
Session
Manager
::
instance
()
->
loadProfile
(
profile
);
baseProfile
=
Profile
Manager
::
instance
()
->
loadProfile
(
profile
);
}
if
(
!
baseProfile
)
{
// fallback to default profile
baseProfile
=
Session
Manager
::
instance
()
->
defaultProfile
();
baseProfile
=
Profile
Manager
::
instance
()
->
defaultProfile
();
}
Profile
::
Ptr
newProfile
=
Profile
::
Ptr
(
new
Profile
(
baseProfile
));
...
...
@@ -297,10 +298,10 @@ MainWindow* Application::processWindowArgs(KCmdLineArgs* args)
Profile
::
Ptr
Application
::
processProfileSelectArgs
(
KCmdLineArgs
*
args
)
{
Profile
::
Ptr
defaultProfile
=
Session
Manager
::
instance
()
->
defaultProfile
();
Profile
::
Ptr
defaultProfile
=
Profile
Manager
::
instance
()
->
defaultProfile
();
if
(
args
->
isSet
(
"profile"
))
{
Profile
::
Ptr
profile
=
Session
Manager
::
instance
()
->
loadProfile
(
Profile
::
Ptr
profile
=
Profile
Manager
::
instance
()
->
loadProfile
(
args
->
getOption
(
"profile"
));
if
(
profile
)
return
profile
;
...
...
@@ -323,7 +324,7 @@ bool Application::processHelpArgs(KCmdLineArgs* args)
void
Application
::
listAvailableProfiles
()
{
QList
<
QString
>
paths
=
Session
Manager
::
instance
()
->
availableProfilePaths
();
QList
<
QString
>
paths
=
Profile
Manager
::
instance
()
->
availableProfilePaths
();
foreach
(
const
QString
&
path
,
paths
)
{
QFileInfo
info
(
path
);
...
...
@@ -335,7 +336,7 @@ void Application::listAvailableProfiles()
void
Application
::
listProfilePropertyInfo
()
{
Profile
::
Ptr
tempProfile
=
Session
Manager
::
instance
()
->
defaultProfile
();
Profile
::
Ptr
tempProfile
=
Profile
Manager
::
instance
()
->
defaultProfile
();
const
QStringList
names
=
tempProfile
->
propertiesInfoList
();
foreach
(
const
QString
&
name
,
names
)
{
...
...
src/CMakeLists.txt
View file @
193777e2
...
...
@@ -87,6 +87,7 @@ ${CMAKE_CURRENT_BINARY_DIR}/tests/CTestCustom.cmake)
ProfileList.cpp
ProfileReader.cpp
ProfileWriter.cpp
ProfileManager.cpp
Pty.cpp
RenameTabDialog.cpp
RenameTabWidget.cpp
...
...
src/EditProfileDialog.cpp
View file @
193777e2
...
...
@@ -52,7 +52,7 @@
#include
"KeyBindingEditor.h"
#include
"KeyboardTranslator.h"
#include
"KeyboardTranslatorManager.h"
#include
"
Session
Manager.h"
#include
"
Profile
Manager.h"
#include
"ShellCommand.h"
#include
"WindowSystemInfo.h"
#include
"Enumeration.h"
...
...
@@ -102,7 +102,7 @@ void EditProfileDialog::save()
if
(
_tempProfile
->
isEmpty
())
return
;
Session
Manager
::
instance
()
->
changeProfile
(
_profile
,
_tempProfile
->
setProperties
());
Profile
Manager
::
instance
()
->
changeProfile
(
_profile
,
_tempProfile
->
setProperties
());
// ensure that these settings are not undone by a call
// to unpreview()
...
...
@@ -595,7 +595,7 @@ void EditProfileDialog::unpreviewAll()
// undo any preview changes
if
(
!
map
.
isEmpty
())
Session
Manager
::
instance
()
->
changeProfile
(
_profile
,
map
,
false
);
Profile
Manager
::
instance
()
->
changeProfile
(
_profile
,
map
,
false
);
}
void
EditProfileDialog
::
unpreview
(
int
aProperty
)
{
...
...
@@ -606,7 +606,7 @@ void EditProfileDialog::unpreview(int aProperty)
QHash
<
Profile
::
Property
,
QVariant
>
map
;
map
.
insert
((
Profile
::
Property
)
aProperty
,
_previewedProperties
[
aProperty
]);
Session
Manager
::
instance
()
->
changeProfile
(
_profile
,
map
,
false
);
Profile
Manager
::
instance
()
->
changeProfile
(
_profile
,
map
,
false
);
_previewedProperties
.
remove
(
aProperty
);
}
...
...
@@ -650,7 +650,7 @@ void EditProfileDialog::preview(int aProperty , const QVariant& value)
}
// temporary change to color scheme
Session
Manager
::
instance
()
->
changeProfile
(
_profile
,
map
,
false
);
Profile
Manager
::
instance
()
->
changeProfile
(
_profile
,
map
,
false
);
}
void
EditProfileDialog
::
previewColorScheme
(
const
QModelIndex
&
index
)
{
...
...
src/MainWindow.cpp
View file @
193777e2
...
...
@@ -51,6 +51,7 @@
#include
"Session.h"
#include
"ViewManager.h"
#include
"SessionManager.h"
#include
"ProfileManager.h"
#include
"KonsoleSettings.h"
#include
"settings/GeneralSettings.h"
#include
"settings/TabBarSettings.h"
...
...
@@ -367,7 +368,7 @@ void MainWindow::sessionListChanged(const QList<QAction*>& sessionActions)
newTabMenu
->
addAction
(
sessionAction
);
// NOTE: defaultProfile seems to not work here, sigh.
Profile
::
Ptr
profile
=
Session
Manager
::
instance
()
->
defaultProfile
();
Profile
::
Ptr
profile
=
Profile
Manager
::
instance
()
->
defaultProfile
();
if
(
profile
&&
profile
->
name
()
==
sessionAction
->
text
().
remove
(
'&'
))
{
sessionAction
->
setIcon
(
KIcon
(
profile
->
icon
(),
0
,
QStringList
(
"emblem-favorite"
)));
newTabMenu
->
setDefaultAction
(
sessionAction
);
...
...
@@ -379,7 +380,7 @@ void MainWindow::sessionListChanged(const QList<QAction*>& sessionActions)
}
else
{
KMenu
*
newTabMenu
=
_newTabMenuAction
->
menu
();
newTabMenu
->
clear
();
Profile
::
Ptr
profile
=
Session
Manager
::
instance
()
->
defaultProfile
();
Profile
::
Ptr
profile
=
Profile
Manager
::
instance
()
->
defaultProfile
();
// NOTE: Compare names w/o any '&'
if
(
sessionActions
.
size
()
==
2
&&
sessionActions
[
1
]
->
text
().
remove
(
'&'
)
!=
profile
->
name
())
{
...
...
@@ -406,7 +407,7 @@ QString MainWindow::activeSessionDir() const
void
MainWindow
::
openUrls
(
const
QList
<
KUrl
>&
urls
)
{
Profile
::
Ptr
defaultProfile
=
Session
Manager
::
instance
()
->
defaultProfile
();
Profile
::
Ptr
defaultProfile
=
Profile
Manager
::
instance
()
->
defaultProfile
();
foreach
(
const
KUrl
&
url
,
urls
)
{
if
(
url
.
isLocalFile
())
...
...
@@ -419,7 +420,7 @@ void MainWindow::openUrls(const QList<KUrl>& urls)
void
MainWindow
::
newTab
()
{
Profile
::
Ptr
defaultProfile
=
Session
Manager
::
instance
()
->
defaultProfile
();
Profile
::
Ptr
defaultProfile
=
Profile
Manager
::
instance
()
->
defaultProfile
();
createSession
(
defaultProfile
,
activeSessionDir
()
);
}
...
...
@@ -441,7 +442,7 @@ void MainWindow::cloneTab()
Session
*
MainWindow
::
createSession
(
Profile
::
Ptr
profile
,
const
QString
&
directory
)
{
if
(
!
profile
)
profile
=
Session
Manager
::
instance
()
->
defaultProfile
();
profile
=
Profile
Manager
::
instance
()
->
defaultProfile
();
Session
*
session
=
SessionManager
::
instance
()
->
createSession
(
profile
);
...
...
@@ -462,7 +463,7 @@ Session* MainWindow::createSession(Profile::Ptr profile, const QString& director
Session
*
MainWindow
::
createSSHSession
(
Profile
::
Ptr
profile
,
const
KUrl
&
url
)
{
if
(
!
profile
)
profile
=
Session
Manager
::
instance
()
->
defaultProfile
();
profile
=
Profile
Manager
::
instance
()
->
defaultProfile
();
Session
*
session
=
SessionManager
::
instance
()
->
createSession
(
profile
);
...
...
@@ -500,7 +501,7 @@ void MainWindow::setFocus()
void
MainWindow
::
newWindow
()
{
Profile
::
Ptr
defaultProfile
=
Session
Manager
::
instance
()
->
defaultProfile
();
Profile
::
Ptr
defaultProfile
=
Profile
Manager
::
instance
()
->
defaultProfile
();
emit
newWindowRequest
(
defaultProfile
,
activeSessionDir
());
}
...
...
src/ManageProfilesDialog.cpp
View file @
193777e2
...
...
@@ -30,7 +30,7 @@
// Konsole
#include
"EditProfileDialog.h"
#include
"
Session
Manager.h"
#include
"
Profile
Manager.h"
#include
"ui_ManageProfilesDialog.h"
using
namespace
Konsole
;
...
...
@@ -43,7 +43,7 @@ ManageProfilesDialog::ManageProfilesDialog(QWidget* aParent)
setButtons
(
KDialog
::
Close
);
connect
(
this
,
SIGNAL
(
finished
()),
Session
Manager
::
instance
(),
SLOT
(
saveSettings
()));
Profile
Manager
::
instance
(),
SLOT
(
saveSettings
()));
_ui
=
new
Ui
::
ManageProfilesDialog
();
_ui
->
setupUi
(
mainWidget
());
...
...
@@ -60,13 +60,13 @@ ManageProfilesDialog::ManageProfilesDialog(QWidget* aParent)
populateTable
();
// listen for changes to profiles
connect
(
Session
Manager
::
instance
(),
SIGNAL
(
profileAdded
(
Profile
::
Ptr
)),
this
,
connect
(
Profile
Manager
::
instance
(),
SIGNAL
(
profileAdded
(
Profile
::
Ptr
)),
this
,
SLOT
(
addItems
(
Profile
::
Ptr
)));
connect
(
Session
Manager
::
instance
(),
SIGNAL
(
profileRemoved
(
Profile
::
Ptr
)),
this
,
connect
(
Profile
Manager
::
instance
(),
SIGNAL
(
profileRemoved
(
Profile
::
Ptr
)),
this
,
SLOT
(
removeItems
(
Profile
::
Ptr
)));
connect
(
Session
Manager
::
instance
(),
SIGNAL
(
profileChanged
(
Profile
::
Ptr
)),
this
,
connect
(
Profile
Manager
::
instance
(),
SIGNAL
(
profileChanged
(
Profile
::
Ptr
)),
this
,
SLOT
(
updateItems
(
Profile
::
Ptr
)));
connect
(
Session
Manager
::
instance
()
,
connect
(
Profile
Manager
::
instance
()
,
SIGNAL
(
favoriteStatusChanged
(
Profile
::
Ptr
,
bool
)),
this
,
SLOT
(
updateFavoriteStatus
(
Profile
::
Ptr
,
bool
)));
...
...
@@ -117,7 +117,7 @@ void ManageProfilesDialog::itemDataChanged(QStandardItem* item)
{
if
(
item
->
column
()
==
ShortcutColumn
)
{
QKeySequence
sequence
=
QKeySequence
::
fromString
(
item
->
text
());
Session
Manager
::
instance
()
->
setShortcut
(
item
->
data
(
ShortcutRole
).
value
<
Profile
::
Ptr
>
(),
Profile
Manager
::
instance
()
->
setShortcut
(
item
->
data
(
ShortcutRole
).
value
<
Profile
::
Ptr
>
(),
sequence
);
}
else
if
(
item
->
column
()
==
ProfileNameColumn
)
{
QString
newName
=
item
->
text
();
...
...
@@ -128,7 +128,7 @@ void ManageProfilesDialog::itemDataChanged(QStandardItem* item)
QHash
<
Profile
::
Property
,
QVariant
>
properties
;
properties
.
insert
(
Profile
::
Name
,
newName
);
Session
Manager
::
instance
()
->
changeProfile
(
profile
,
properties
);
Profile
Manager
::
instance
()
->
changeProfile
(
profile
,
properties
);
}
}
...
...
@@ -175,7 +175,7 @@ void ManageProfilesDialog::updateItemsForProfile(const Profile::Ptr profile, QLi
items
[
ProfileNameColumn
]
->
setData
(
QVariant
::
fromValue
(
profile
),
ProfileKeyRole
);
// Favorite Status
const
bool
isFavorite
=
Session
Manager
::
instance
()
->
findFavorites
().
contains
(
profile
);
const
bool
isFavorite
=
Profile
Manager
::
instance
()
->
findFavorites
().
contains
(
profile
);
if
(
isFavorite
)
items
[
FavoriteStatusColumn
]
->
setData
(
KIcon
(
"dialog-ok-apply"
),
Qt
::
DecorationRole
);
else
...
...
@@ -183,7 +183,7 @@ void ManageProfilesDialog::updateItemsForProfile(const Profile::Ptr profile, QLi
items
[
FavoriteStatusColumn
]
->
setData
(
QVariant
::
fromValue
(
profile
),
ProfileKeyRole
);
// Shortcut
QString
shortcut
=
Session
Manager
::
instance
()
->
shortcut
(
profile
).
toString
();
QString
shortcut
=
Profile
Manager
::
instance
()
->
shortcut
(
profile
).
toString
();
items
[
ShortcutColumn
]
->
setText
(
shortcut
);
items
[
ShortcutColumn
]
->
setData
(
QVariant
::
fromValue
(
profile
),
ShortcutRole
);
}
...
...
@@ -211,8 +211,8 @@ void ManageProfilesDialog::populateTable()
<<
i18nc
(
"@title:column Display profile in file menu"
,
"Show in Menu"
)
<<
i18nc
(
"@title:column Profile shortcut text"
,
"Shortcut"
));
QList
<
Profile
::
Ptr
>
profiles
=
Session
Manager
::
instance
()
->
allProfiles
();
Session
Manager
::
instance
()
->
sortProfiles
(
profiles
);
QList
<
Profile
::
Ptr
>
profiles
=
Profile
Manager
::
instance
()
->
allProfiles
();
Profile
Manager
::
instance
()
->
sortProfiles
(
profiles
);
foreach
(
const
Profile
::
Ptr
&
profile
,
profiles
)
{
addItems
(
profile
);
...
...
@@ -235,7 +235,7 @@ void ManageProfilesDialog::populateTable()
}
void
ManageProfilesDialog
::
updateDefaultItem
()
{
Profile
::
Ptr
defaultProfile
=
Session
Manager
::
instance
()
->
defaultProfile
();
Profile
::
Ptr
defaultProfile
=
Profile
Manager
::
instance
()
->
defaultProfile
();
const
int
rowCount
=
_sessionModel
->
rowCount
();
for
(
int
i
=
0
;
i
<
rowCount
;
i
++
)
{
...
...
@@ -258,7 +258,7 @@ void ManageProfilesDialog::updateDefaultItem()
void
ManageProfilesDialog
::
tableSelectionChanged
(
const
QItemSelection
&
)
{
const
int
selectedRows
=
_ui
->
sessionTable
->
selectionModel
()
->
selectedRows
().
count
();
const
Session
Manager
*
manager
=
Session
Manager
::
instance
();
const
Profile
Manager
*
manager
=
Profile
Manager
::
instance
();
const
bool
isNotDefault
=
(
selectedRows
>
0
)
&&
currentProfile
()
!=
manager
->
defaultProfile
();
const
bool
isDeletable
=
(
selectedRows
>
1
)
||
(
selectedRows
==
1
&&
isProfileDeletable
(
currentProfile
()));
...
...
@@ -273,13 +273,13 @@ void ManageProfilesDialog::tableSelectionChanged(const QItemSelection&)
void
ManageProfilesDialog
::
deleteSelected
()
{
foreach
(
const
Profile
::
Ptr
&
profile
,
selectedProfiles
())
{
if
(
profile
!=
Session
Manager
::
instance
()
->
defaultProfile
())
Session
Manager
::
instance
()
->
deleteProfile
(
profile
);
if
(
profile
!=
Profile
Manager
::
instance
()
->
defaultProfile
())
Profile
Manager
::
instance
()
->
deleteProfile
(
profile
);
}
}
void
ManageProfilesDialog
::
setSelectedAsDefault
()
{
Session
Manager
::
instance
()
->
setDefaultProfile
(
currentProfile
());
Profile
Manager
::
instance
()
->
setDefaultProfile
(
currentProfile
());
// do not allow the new default session type to be removed
_ui
->
deleteProfileButton
->
setEnabled
(
false
);
_ui
->
setAsDefaultButton
->
setEnabled
(
false
);
...
...
@@ -316,13 +316,13 @@ void ManageProfilesDialog::createProfile()
Profile
::
Ptr
selectedProfile
=
currentProfile
();
if
(
!
selectedProfile
)
sourceProfile
=
Session
Manager
::
instance
()
->
defaultProfile
();
sourceProfile
=
Profile
Manager
::
instance
()
->
defaultProfile
();
else
sourceProfile
=
selectedProfile
;
Q_ASSERT
(
sourceProfile
);
Profile
::
Ptr
newProfile
=
Profile
::
Ptr
(
new
Profile
(
Session
Manager
::
instance
()
->
fallbackProfile
()));
Profile
::
Ptr
newProfile
=
Profile
::
Ptr
(
new
Profile
(
Profile
Manager
::
instance
()
->
fallbackProfile
()));
newProfile
->
clone
(
sourceProfile
,
true
);
newProfile
->
setProperty
(
Profile
::
Name
,
i18nc
(
"@item This will be used as part of the file name"
,
"New Profile"
));
newProfile
->
setProperty
(
Profile
::
MenuIndex
,
QString
(
"0"
));
...
...
@@ -332,9 +332,9 @@ void ManageProfilesDialog::createProfile()
dialog
.
data
()
->
selectProfileName
();
if
(
dialog
.
data
()
->
exec
()
==
QDialog
::
Accepted
)
{
Session
Manager
::
instance
()
->
addProfile
(
newProfile
);
Session
Manager
::
instance
()
->
setFavorite
(
newProfile
,
true
);
Session
Manager
::
instance
()
->
changeProfile
(
newProfile
,
newProfile
->
setProperties
());
Profile
Manager
::
instance
()
->
addProfile
(
newProfile
);
Profile
Manager
::
instance
()
->
setFavorite
(
newProfile
,
true
);
Profile
Manager
::
instance
()
->
changeProfile
(
newProfile
,
newProfile
->
setProperties
());
}
delete
dialog
.
data
();
}
...
...
@@ -447,9 +447,9 @@ bool FavoriteItemDelegate::editorEvent(QEvent* aEvent, QAbstractItemModel*,
aEvent
->
type
()
==
QEvent
::
KeyPress
||
aEvent
->
type
()
==
QEvent
::
MouseButtonDblClick
)
{
Profile
::
Ptr
profile
=
index
.
data
(
ManageProfilesDialog
::
ProfileKeyRole
).
value
<
Profile
::
Ptr
>
();
const
bool
isFavorite
=
Session
Manager
::
instance
()
->
findFavorites
().
contains
(
profile
);
const
bool
isFavorite
=
Profile
Manager
::
instance
()
->
findFavorites
().
contains
(
profile
);
Session
Manager
::
instance
()
->
setFavorite
(
profile
,
!
isFavorite
);
Profile
Manager
::
instance
()
->
setFavorite
(
profile
,
!
isFavorite
);
}
return
true
;
...
...
src/Part.cpp
View file @
193777e2
...
...
@@ -39,6 +39,7 @@
#include
"Session.h"
#include
"SessionController.h"
#include
"SessionManager.h"
#include
"ProfileManager.h"
#include
"TerminalDisplay.h"
#include
"ViewManager.h"
...
...
@@ -87,7 +88,7 @@ Part::Part(QWidget* parentWidget , QObject* parent, const QVariantList&)
Part
::~
Part
()
{
Session
Manager
::
instance
()
->
saveSettings
();
Profile
Manager
::
instance
()
->
saveSettings
();
}
void
Part
::
createGlobalActions
()
...
...
src/ProfileList.cpp
View file @
193777e2
...
...
@@ -30,7 +30,7 @@
#include
<KDebug>
// Konsole
#include
"
Session
Manager.h"
#include
"
Profile
Manager.h"
using
Konsole
::
ProfileList
;
...
...
@@ -47,7 +47,7 @@ ProfileList::ProfileList(bool addShortcuts , QObject* parent)
_emptyListAction
=
new
QAction
(
i18n
(
"Default profile"
),
_group
);
// TODO - Handle re-sorts when user changes profile names
Session
Manager
*
manager
=
Session
Manager
::
instance
();
Profile
Manager
*
manager
=
Profile
Manager
::
instance
();
QList
<
Profile
::
Ptr
>
favoriteProfiles
=
manager
->
sortedFavorites
();
foreach
(
const
Profile
::
Ptr
&
profile
,
favoriteProfiles
)
{
...
...
@@ -128,7 +128,7 @@ void ProfileList::syncWidgetActions(QWidget* widget, bool sync)
}
void
ProfileList
::
favoriteChanged
(
Profile
::
Ptr
profile
,
bool
isFavorite
)
{
Session
Manager
*
manager
=
Session
Manager
::
instance
();
Profile
Manager
*
manager
=
Profile
Manager
::
instance
();
if
(
isFavorite
)
{
QAction
*
action
=
new
QAction
(
_group
);
...
...
src/ProfileManager.cpp
0 → 100644
View file @
193777e2
/*
This source file is part of Konsole, a terminal emulator.
Copyright 2006-2008 by Robert Knight <robertknight@gmail.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
*/
// Own
#include
"ProfileManager.h"
// Qt
#include
<QtCore/QDir>
#include
<QtCore/QFileInfo>
#include
<QtCore/QList>
#include
<QtCore/QString>
// KDE
#include
<KConfig>
#include
<KGlobal>
#include
<KDebug>
#include
<KConfigGroup>
#include
<KStandardDirs>
// Konsole
#include
"ProfileReader.h"
#include
"ProfileWriter.h"
using
namespace
Konsole
;
static
bool
profileIndexLessThan
(
const
Profile
::
Ptr
&
p1
,
const
Profile
::
Ptr
&
p2
)
{
return
p1
->
menuIndexAsInt
()
<=
p2
->
menuIndexAsInt
();
}
static
bool
profileNameLessThan
(
const
Profile
::
Ptr
&
p1
,
const
Profile
::
Ptr
&
p2
)
{
return
QString
::
localeAwareCompare
(
p1
->
name
(),
p2
->
name
())
<=
0
;
}
static
void
sortByIndexProfileList
(
QList
<
Profile
::
Ptr
>&
list
)
{
qStableSort
(
list
.
begin
(),
list
.
end
(),
profileIndexLessThan
);
}
static
void
sortByNameProfileList
(
QList
<
Profile
::
Ptr
>&
list
)
{
qStableSort
(
list
.
begin
(),
list
.
end
(),
profileNameLessThan
);
}
ProfileManager
::
ProfileManager
()
:
_loadedAllProfiles
(
false
)
,
_loadedFavorites
(
false
)
{
//load fallback profile
_fallbackProfile
=
Profile
::
Ptr
(
new
FallbackProfile
);
addProfile
(
_fallbackProfile
);
//locate and load default profile
KSharedConfigPtr
konsoleConfig
=
KSharedConfig
::
openConfig
(
"konsolerc"
);
const
KConfigGroup
group
=
konsoleConfig
->
group
(
"Desktop Entry"
);
const
QString
defaultProfileFileName
=
group
.
readEntry
(
"DefaultProfile"
,
"Shell.profile"
);
const
QString
path
=
KStandardDirs
::
locate
(
"data"
,
"konsole/"
+
defaultProfileFileName
);
if
(
!
path
.
isEmpty
())
{
Profile
::
Ptr
profile
=
loadProfile
(
path
);
if
(
profile
)
_defaultProfile
=
profile
;
}
Q_ASSERT
(
_profiles
.
count
()
>
0
);
Q_ASSERT
(
_defaultProfile
);
// get shortcuts and paths of profiles associated with
// them - this doesn't load the shortcuts themselves,
// that is done on-demand.
loadShortcuts
();
}
ProfileManager
::~
ProfileManager
()
{
}
K_GLOBAL_STATIC
(
ProfileManager
,
theProfileManager
)
ProfileManager
*
ProfileManager
::
instance
()
{
return
theProfileManager
;
}
Profile
::
Ptr
ProfileManager
::
loadProfile
(
const
QString
&
shortPath
)
{
// the fallback profile has a 'special' path name, "FALLBACK/"
if
(
shortPath
==
_fallbackProfile
->
path
())
return
_fallbackProfile
;
QString
path
=
shortPath
;
// add a suggested suffix and relative prefix if missing
QFileInfo
fileInfo
(
path
);
if
(
fileInfo
.
isDir
())
return
Profile
::
Ptr
();
if
(
fileInfo
.
suffix
()
!=
"profile"
)
path
.
append
(
".profile"
);
if
(
fileInfo
.
path
().
isEmpty
()
||
fileInfo
.
path
()
==
"."
)
path
.
prepend
(
QString
(
"konsole"
)
+
QDir
::
separator
());
// if the file is not an absolute path, look it up
if
(
!
fileInfo
.
isAbsolute
())
path
=
KStandardDirs
::
locate
(
"data"
,
path
);
// if the file is not found, return imediately
if
(
path
.
isEmpty
()
)
{
return
Profile
::
Ptr
();
}
// check that we have not already loaded this profile
foreach
(
const
Profile
::
Ptr
&
profile
,
_profiles
)
{
if
(
profile
->
path
()
==
path
)
return
profile
;
}
// guard to prevent problems if a profile specifies itself as its parent
// or if there is recursion in the "inheritance" chain
// (eg. two profiles, A and B, specifying each other as their parents)
static
QStack
<
QString
>
recursionGuard
;
PopStackOnExit
<
QString
>
popGuardOnExit
(
recursionGuard
);
if
(
recursionGuard
.
contains
(
path
))
{
kWarning
()
<<
"Ignoring attempt to load profile recursively from"
<<
path
;
return
_fallbackProfile
;
}
else
recursionGuard
.
push
(
path
);
// load the profile
ProfileReader
*
reader
=
new
KDE4ProfileReader
;
Profile
::
Ptr
newProfile
=
Profile
::
Ptr
(
new
Profile
(
fallbackProfile
()));
newProfile
->
setProperty
(
Profile
::
Path
,
path
);
QString
parentProfilePath
;
bool
result
=
reader
->
readProfile
(
path
,
newProfile
,
parentProfilePath
);
if
(
!
parentProfilePath
.
isEmpty
())
{
Profile
::
Ptr
parentProfile
=
loadProfile
(
parentProfilePath
);
newProfile
->
setParent
(
parentProfile
);
}
delete
reader
;
if
(
!
result
)
{
kWarning
()
<<
"Could not load profile from "
<<
path
;
return
Profile
::
Ptr
();
}
else
{
addProfile
(
newProfile
);
return
newProfile
;
}
}
QStringList
ProfileManager
::
availableProfilePaths
()
const
{
KDE4ProfileReader
kde4Reader
;
QStringList
profiles
;
profiles
+=
kde4Reader
.
findProfiles
();
return
profiles
;
}
void
ProfileManager
::
loadAllProfiles
()
{
if
(
_loadedAllProfiles
)
return
;
const
QStringList
&
paths
=
availableProfilePaths
();
foreach
(
const
QString
&
path
,
paths
)
{
loadProfile
(
path
);
}
_loadedAllProfiles
=
true
;
}
void
ProfileManager
::
sortProfiles
(
QList
<
Profile
::
Ptr
>&
list
)
{
QList
<
Profile
::
Ptr
>
lackingIndices
;
QList
<
Profile
::
Ptr
>
havingIndices
;
for
(
int
i
=
0
;
i
<
list
.
size
();
++
i
)
{
// dis-regard the fallback profile
if
(
list
.
at
(
i
)
->
path
()
==
_fallbackProfile
->
path
())
continue
;
if
(
list
.
at
(
i
)
->
menuIndexAsInt
()
==
0
)
lackingIndices
.
append
(
list
.
at
(
i
));
else
havingIndices
.
append
(
list
.
at
(
i
));
}
// sort by index
sortByIndexProfileList
(
havingIndices
);
// sort alphabetically those w/o an index
sortByNameProfileList
(
lackingIndices
);
// Put those with indices in sequential order w/o any gaps
int
i
=
0
;
for
(
i
=
0
;
i
<
havingIndices
.
size
();
++
i
)
{
Profile
::
Ptr
tempProfile
=
havingIndices
.
at
(
i
);
tempProfile
->
setProperty
(
Profile
::
MenuIndex
,
QString
::
number
(
i
+
1
));
havingIndices
.
replace
(
i
,
tempProfile
);
}
// Put those w/o indices in sequential order
for
(
int
j
=
0
;
j
<
lackingIndices
.
size
();
++
j
)
{
Profile
::
Ptr
tempProfile
=
lackingIndices
.
at
(
j
);
tempProfile
->
setProperty
(
Profile
::
MenuIndex
,
QString
::
number
(
j
+
1
+
i
));
lackingIndices
.
replace
(
j
,
tempProfile
);
}
// combine the 2 list: first those who had indices
list
.
clear
();
list
.
append
(
havingIndices
);
list
.
append
(
lackingIndices
);
}