Apply astyle-kdelibs

Over the years, the coding style is all over the place.

Use 'git diff -w --ignore-all-space' to see non-whitespace changes.
This commit is contained in:
Kurt Hindenburg
2011-12-24 11:22:18 -05:00
parent d7ce9e8f0c
commit fa187da0c6
2 changed files with 250 additions and 304 deletions

View File

@@ -62,7 +62,7 @@ static bool profileNameLessThan(const Profile::Ptr& p1, const Profile::Ptr& p2)
static void sortByIndexProfileList(QList<Profile::Ptr>& list)
{
qStableSort(list.begin(), list.end(), profileIndexLessThan);
qStableSort(list.begin(), list.end(), profileIndexLessThan);
}
static void sortByNameProfileList(QList<Profile::Ptr>& list)
@@ -76,8 +76,8 @@ SessionManager::SessionManager()
{
//map finished() signals from sessions
_sessionMapper = new QSignalMapper(this);
connect( _sessionMapper , SIGNAL(mapped(QObject*)) , this ,
SLOT(sessionTerminated(QObject*)) );
connect(_sessionMapper , SIGNAL(mapped(QObject*)) , this ,
SLOT(sessionTerminated(QObject*)));
//load fallback profile
_fallbackProfile = Profile::Ptr(new FallbackProfile);
@@ -85,19 +85,18 @@ SessionManager::SessionManager()
//locate and load default profile
KSharedConfigPtr konsoleConfig = KSharedConfig::openConfig("konsolerc");
const KConfigGroup group = konsoleConfig->group( "Desktop Entry" );
QString defaultSessionFilename = group.readEntry("DefaultProfile","Shell.profile");
const KConfigGroup group = konsoleConfig->group("Desktop Entry");
QString defaultSessionFilename = group.readEntry("DefaultProfile", "Shell.profile");
QString path = KStandardDirs::locate("data","konsole/"+defaultSessionFilename);
if (!path.isEmpty())
{
QString path = KStandardDirs::locate("data", "konsole/" + defaultSessionFilename);
if (!path.isEmpty()) {
Profile::Ptr profile = loadProfile(path);
if ( profile )
if (profile)
_defaultProfile = profile;
}
Q_ASSERT( _profiles.count() > 0 );
Q_ASSERT( _defaultProfile );
Q_ASSERT(_profiles.count() > 0);
Q_ASSERT(_defaultProfile);
// get shortcuts and paths of profiles associated with
// them - this doesn't load the shortcuts themselves,
@@ -107,17 +106,16 @@ SessionManager::SessionManager()
SessionManager::~SessionManager()
{
if (_sessions.count() > 0)
{
if (_sessions.count() > 0) {
kWarning() << "Konsole SessionManager destroyed with sessions still alive";
// ensure that the Session doesn't later try to call back and do things to the
// ensure that the Session doesn't later try to call back and do things to the
// SessionManager
foreach(Session* session , _sessions)
disconnect(session , 0 , this , 0);
foreach(Session * session , _sessions)
disconnect(session , 0 , this , 0);
}
}
K_GLOBAL_STATIC( SessionManager , theSessionManager )
K_GLOBAL_STATIC(SessionManager , theSessionManager)
SessionManager* SessionManager::instance()
{
return theSessionManager;
@@ -137,21 +135,20 @@ Profile::Ptr SessionManager::loadProfile(const QString& shortPath)
if (fileInfo.isDir())
return Profile::Ptr();
if ( fileInfo.suffix() != "profile" )
if (fileInfo.suffix() != "profile")
path.append(".profile");
if ( fileInfo.path().isEmpty() || fileInfo.path() == "." )
path.prepend(QString("konsole")+QDir::separator());
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 an absolute path, look it up
if (!fileInfo.isAbsolute())
path = KStandardDirs::locate("data", path);
// check that we have not already loaded this profile
QSetIterator<Profile::Ptr> iter(_profiles);
while ( iter.hasNext() )
{
while (iter.hasNext()) {
Profile::Ptr profile = iter.next();
if ( profile->path() == path )
if (profile->path() == path)
return profile;
}
@@ -161,48 +158,41 @@ Profile::Ptr SessionManager::loadProfile(const QString& shortPath)
static QStack<QString> recursionGuard;
PopStackOnExit<QString> popGuardOnExit(recursionGuard);
if (recursionGuard.contains(path))
{
if (recursionGuard.contains(path)) {
kWarning() << "Ignoring attempt to load profile recursively from" << path;
return _fallbackProfile;
}
else
} else
recursionGuard.push(path);
// load the profile
ProfileReader* reader = 0;
if ( path.endsWith(QLatin1String(".desktop")) )
if (path.endsWith(QLatin1String(".desktop")))
reader = 0; // new KDE3ProfileReader;
else
reader = new KDE4ProfileReader;
if (!reader)
{
if (!reader) {
kWarning() << "Could not create loader to read profile from" << path;
return Profile::Ptr();
}
Profile::Ptr newProfile = Profile::Ptr(new Profile(fallbackProfile()));
newProfile->setProperty(Profile::Path,path);
newProfile->setProperty(Profile::Path, path);
QString parentProfilePath;
bool result = reader->readProfile(path,newProfile,parentProfilePath);
bool result = reader->readProfile(path, newProfile, parentProfilePath);
if ( !parentProfilePath.isEmpty() )
{
if (!parentProfilePath.isEmpty()) {
Profile::Ptr parentProfile = loadProfile(parentProfilePath);
newProfile->setParent(parentProfile);
}
delete reader;
if (!result)
{
if (!result) {
kWarning() << "Could not load profile from " << path;
return Profile::Ptr();
}
else
{
} else {
addProfile(newProfile);
return newProfile;
}
@@ -219,7 +209,7 @@ QStringList SessionManager::availableProfilePaths() const
void SessionManager::loadAllProfiles()
{
if ( _loadedAllProfiles )
if (_loadedAllProfiles)
return;
QStringList profiles = availableProfilePaths();
@@ -237,8 +227,7 @@ void SessionManager::sortProfiles(QList<Profile::Ptr>& list)
QList<Profile::Ptr> lackingIndices;
QList<Profile::Ptr> havingIndices;
for (int i = 0; i < list.size(); ++i)
{
for (int i = 0; i < list.size(); ++i) {
// dis-regard the fallback profile
if (list.at(i)->path() == _fallbackProfile->property<QString>(Profile::Path))
continue;
@@ -257,17 +246,15 @@ void SessionManager::sortProfiles(QList<Profile::Ptr>& list)
// Put those with indices in sequential order w/o any gaps
int i = 0;
for (i = 0; i < havingIndices.size(); ++i)
{
for (i = 0; i < havingIndices.size(); ++i) {
Profile::Ptr tempProfile = havingIndices.at(i);
tempProfile->setProperty(Profile::MenuIndex, QString::number(i+1));
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)
{
for (int j = 0; j < lackingIndices.size(); ++j) {
Profile::Ptr tempProfile = lackingIndices.at(j);
tempProfile->setProperty(Profile::MenuIndex, QString::number(j+1+i));
tempProfile->setProperty(Profile::MenuIndex, QString::number(j + 1 + i));
lackingIndices.replace(j, tempProfile);
}
@@ -280,7 +267,7 @@ void SessionManager::sortProfiles(QList<Profile::Ptr>& list)
void SessionManager::saveSettings()
{
// save default profile
setDefaultProfile( _defaultProfile );
setDefaultProfile(_defaultProfile);
// save shortcuts
saveShortcuts();
@@ -300,11 +287,10 @@ void SessionManager::saveSettings()
void SessionManager::closeAll()
{
// close remaining sessions
foreach( Session* session , _sessions )
{
foreach(Session * session , _sessions) {
session->close();
}
_sessions.clear();
_sessions.clear();
}
const QList<Session*> SessionManager::sessions() const
{
@@ -313,15 +299,15 @@ const QList<Session*> SessionManager::sessions() const
void SessionManager::updateSession(Session* session)
{
Profile::Ptr profile = _sessionProfiles[session];
Profile::Ptr profile = _sessionProfiles[session];
// Temp fix for crashes when changing profiles 256357, 246054
if (!profile)
profile = defaultProfile();
Q_ASSERT( profile );
Q_ASSERT(profile);
applyProfile(session,profile,false);
applyProfile(session, profile, false);
emit sessionUpdated(session);
}
@@ -338,21 +324,21 @@ Session* SessionManager::createSession(Profile::Ptr profile)
//configuration information found, create a new session based on this
session = new Session();
applyProfile(session,profile,false);
applyProfile(session, profile, false);
connect( session , SIGNAL(profileChangeCommandReceived(QString)) , this ,
SLOT(sessionProfileCommandReceived(QString)) );
connect(session , SIGNAL(profileChangeCommandReceived(QString)) , this ,
SLOT(sessionProfileCommandReceived(QString)));
//ask for notification when session dies
_sessionMapper->setMapping(session,session);
connect( session , SIGNAL(finished()) , _sessionMapper ,
SLOT(map()) );
_sessionMapper->setMapping(session, session);
connect(session , SIGNAL(finished()) , _sessionMapper ,
SLOT(map()));
//add session to active list
_sessions << session;
_sessionProfiles.insert(session,profile);
_sessionProfiles.insert(session, profile);
Q_ASSERT( session );
Q_ASSERT(session);
return session;
}
@@ -361,7 +347,7 @@ void SessionManager::sessionTerminated(QObject* sessionObject)
{
Session* session = qobject_cast<Session*>(sessionObject);
Q_ASSERT( session );
Q_ASSERT(session);
_sessions.removeAll(session);
_sessionProfiles.remove(session);
@@ -388,7 +374,9 @@ Profile::Ptr SessionManager::defaultProfile() const
return _defaultProfile;
}
Profile::Ptr SessionManager::fallbackProfile() const
{ return _fallbackProfile; }
{
return _fallbackProfile;
}
QString SessionManager::saveProfile(Profile::Ptr profile)
{
@@ -396,25 +384,24 @@ QString SessionManager::saveProfile(Profile::Ptr profile)
QString newPath = writer->getPath(profile);
writer->writeProfile(newPath,profile);
writer->writeProfile(newPath, profile);
delete writer;
return newPath;
}
void SessionManager::changeProfile(Profile::Ptr profile,
QHash<Profile::Property,QVariant> propertyMap, bool persistent)
void SessionManager::changeProfile(Profile::Ptr profile,
QHash<Profile::Property, QVariant> propertyMap, bool persistent)
{
Q_ASSERT(profile);
Q_ASSERT(profile);
// insert the changes into the existing Profile instance
QListIterator<Profile::Property> iter(propertyMap.keys());
while ( iter.hasNext() )
{
while (iter.hasNext()) {
const Profile::Property property = iter.next();
profile->setProperty(property,propertyMap[property]);
profile->setProperty(property, propertyMap[property]);
}
// never save a profile with empty name into disk!
@@ -423,38 +410,35 @@ void SessionManager::changeProfile(Profile::Ptr profile,
// when changing a group, iterate through the profiles
// in the group and call changeProfile() on each of them
//
// this is so that each profile in the group, the profile is
// this is so that each profile in the group, the profile is
// applied, a change notification is emitted and the profile
// is saved to disk
ProfileGroup::Ptr group = profile->asGroup();
if (group)
{
foreach(const Profile::Ptr& profile, group->profiles())
changeProfile(profile,propertyMap,persistent);
if (group) {
foreach(const Profile::Ptr & profile, group->profiles())
changeProfile(profile, propertyMap, persistent);
return;
}
// apply the changes to existing sessions
applyProfile(profile,true);
applyProfile(profile, true);
// notify the world about the change
emit profileChanged(profile);
// save changes to disk, unless the profile is hidden, in which case
// it has no file on disk
if ( persistent && !profile->isHidden() )
{
profile->setProperty(Profile::Path,saveProfile(profile));
// it has no file on disk
if (persistent && !profile->isHidden()) {
profile->setProperty(Profile::Path, saveProfile(profile));
}
}
void SessionManager::applyProfile(Profile::Ptr profile , bool modifiedPropertiesOnly)
{
QListIterator<Session*> iter(_sessions);
while ( iter.hasNext() )
{
while (iter.hasNext()) {
Session* next = iter.next();
if ( _sessionProfiles[next] == profile )
applyProfile(next,profile,modifiedPropertiesOnly);
if (_sessionProfiles[next] == profile)
applyProfile(next, profile, modifiedPropertiesOnly);
}
}
Profile::Ptr SessionManager::sessionProfile(Session* session) const
@@ -472,23 +456,22 @@ void SessionManager::applyProfile(Session* session, const Profile::Ptr profile ,
_sessionProfiles[session] = profile;
ShouldApplyProperty apply(profile,modifiedPropertiesOnly);
ShouldApplyProperty apply(profile, modifiedPropertiesOnly);
// Basic session settings
if ( apply.shouldApply(Profile::Name) )
session->setTitle(Session::NameRole,profile->name());
if (apply.shouldApply(Profile::Name))
session->setTitle(Session::NameRole, profile->name());
if ( apply.shouldApply(Profile::Command) )
if (apply.shouldApply(Profile::Command))
session->setProgram(profile->command());
if ( apply.shouldApply(Profile::Arguments) )
if (apply.shouldApply(Profile::Arguments))
session->setArguments(profile->arguments());
if ( apply.shouldApply(Profile::Directory) )
if (apply.shouldApply(Profile::Directory))
session->setInitialWorkingDirectory(profile->defaultWorkingDirectory());
if ( apply.shouldApply(Profile::Environment) )
{
if (apply.shouldApply(Profile::Environment)) {
// add environment variable containing home directory of current profile
// (if specified)
QStringList environment = profile->property<QStringList>(Profile::Environment);
@@ -497,63 +480,59 @@ void SessionManager::applyProfile(Session* session, const Profile::Ptr profile ,
session->setEnvironment(environment);
}
if ( apply.shouldApply(Profile::Icon) )
if (apply.shouldApply(Profile::Icon))
session->setIconName(profile->icon());
// Key bindings
if ( apply.shouldApply(Profile::KeyBindings) )
if (apply.shouldApply(Profile::KeyBindings))
session->setKeyBindings(profile->property<QString>(Profile::KeyBindings));
// Tab formats
if ( apply.shouldApply(Profile::LocalTabTitleFormat) )
session->setTabTitleFormat( Session::LocalTabTitle ,
profile->property<QString>(Profile::LocalTabTitleFormat));
if ( apply.shouldApply(Profile::RemoteTabTitleFormat) )
session->setTabTitleFormat( Session::RemoteTabTitle ,
profile->property<QString>(Profile::RemoteTabTitleFormat));
if (apply.shouldApply(Profile::LocalTabTitleFormat))
session->setTabTitleFormat(Session::LocalTabTitle ,
profile->property<QString>(Profile::LocalTabTitleFormat));
if (apply.shouldApply(Profile::RemoteTabTitleFormat))
session->setTabTitleFormat(Session::RemoteTabTitle ,
profile->property<QString>(Profile::RemoteTabTitleFormat));
// History
if ( apply.shouldApply(Profile::HistoryMode) || apply.shouldApply(Profile::HistorySize) )
{
if (apply.shouldApply(Profile::HistoryMode) || apply.shouldApply(Profile::HistorySize)) {
int mode = profile->property<int>(Profile::HistoryMode);
switch ((Profile::HistoryModeEnum)mode)
{
case Profile::DisableHistory:
session->setHistoryType( HistoryTypeNone() );
break;
switch ((Profile::HistoryModeEnum)mode) {
case Profile::DisableHistory:
session->setHistoryType(HistoryTypeNone());
break;
case Profile::FixedSizeHistory:
{
int lines = profile->property<int>(Profile::HistorySize);
session->setHistoryType( CompactHistoryType(lines) );
}
break;
case Profile::FixedSizeHistory: {
int lines = profile->property<int>(Profile::HistorySize);
session->setHistoryType(CompactHistoryType(lines));
}
break;
case Profile::UnlimitedHistory:
session->setHistoryType( HistoryTypeFile() );
break;
case Profile::UnlimitedHistory:
session->setHistoryType(HistoryTypeFile());
break;
}
}
// Terminal features
if ( apply.shouldApply(Profile::FlowControlEnabled) )
session->setFlowControlEnabled( profile->property<bool>(Profile::FlowControlEnabled) );
if (apply.shouldApply(Profile::FlowControlEnabled))
session->setFlowControlEnabled(profile->property<bool>(Profile::FlowControlEnabled));
// Encoding
if ( apply.shouldApply(Profile::DefaultEncoding) )
{
if (apply.shouldApply(Profile::DefaultEncoding)) {
QByteArray name = profile->property<QString>(Profile::DefaultEncoding).toUtf8();
session->setCodec( QTextCodec::codecForName(name) );
}
session->setCodec(QTextCodec::codecForName(name));
}
// Monitor Silence
if ( apply.shouldApply(Profile::SilenceSeconds) )
session->setMonitorSilenceSeconds( profile->property<int>(Profile::SilenceSeconds) );
if (apply.shouldApply(Profile::SilenceSeconds))
session->setMonitorSilenceSeconds(profile->property<int>(Profile::SilenceSeconds));
}
void SessionManager::addProfile(Profile::Ptr type)
{
if ( _profiles.isEmpty() )
if (_profiles.isEmpty())
_defaultProfile = type;
_profiles.insert(type);
@@ -563,62 +542,58 @@ void SessionManager::addProfile(Profile::Ptr type)
bool SessionManager::deleteProfile(Profile::Ptr type)
{
bool wasDefault = ( type == defaultProfile() );
bool wasDefault = (type == defaultProfile());
if ( type )
{
if (type) {
// try to delete the config file
if ( type->isPropertySet(Profile::Path) && QFile::exists(type->path()) )
{
if (!QFile::remove(type->path()))
{
if (type->isPropertySet(Profile::Path) && QFile::exists(type->path())) {
if (!QFile::remove(type->path())) {
kWarning() << "Could not delete profile: " << type->path()
<< "The file is most likely in a directory which is read-only.";
<< "The file is most likely in a directory which is read-only.";
return false;
}
}
// remove from favorites, profile list, shortcut list etc.
setFavorite(type,false);
setShortcut(type,QKeySequence());
setFavorite(type, false);
setShortcut(type, QKeySequence());
_profiles.remove(type);
// mark the profile as hidden so that it does not show up in the
// mark the profile as hidden so that it does not show up in the
// Manage Profiles dialog and is not saved to disk
type->setHidden(true);
}
// if we just deleted the default session type,
// replace it with a random type from the list
if ( wasDefault )
{
setDefaultProfile( _profiles.toList().first() );
if (wasDefault) {
setDefaultProfile(_profiles.toList().first());
}
emit profileRemoved(type);
return true;
return true;
}
void SessionManager::setDefaultProfile(Profile::Ptr profile)
{
Q_ASSERT ( _profiles.contains(profile) );
Q_ASSERT(_profiles.contains(profile));
_defaultProfile = profile;
_defaultProfile = profile;
QString path = profile->path();
QString path = profile->path();
if ( path.isEmpty() )
path = KDE4ProfileWriter().getPath(profile);
if (path.isEmpty())
path = KDE4ProfileWriter().getPath(profile);
QFileInfo fileInfo(path);
QFileInfo fileInfo(path);
// TODO: writing to konsolerc is a temporary workaround
KSharedConfigPtr config = KSharedConfig::openConfig("konsolerc");
KConfigGroup group = config->group("Desktop Entry");
group.writeEntry("DefaultProfile",fileInfo.fileName());
// TODO: writing to konsolerc is a temporary workaround
KSharedConfigPtr config = KSharedConfig::openConfig("konsolerc");
KConfigGroup group = config->group("Desktop Entry");
group.writeEntry("DefaultProfile", fileInfo.fileName());
}
QSet<Profile::Ptr> SessionManager::findFavorites()
QSet<Profile::Ptr> SessionManager::findFavorites()
{
if (!_loadedFavorites)
loadFavorites();
@@ -630,15 +605,12 @@ void SessionManager::setFavorite(Profile::Ptr profile , bool favorite)
if (!_profiles.contains(profile))
addProfile(profile);
if ( favorite && !_favorites.contains(profile) )
{
if (favorite && !_favorites.contains(profile)) {
_favorites.insert(profile);
emit favoriteStatusChanged(profile,favorite);
}
else if ( !favorite && _favorites.contains(profile) )
{
emit favoriteStatusChanged(profile, favorite);
} else if (!favorite && _favorites.contains(profile)) {
_favorites.remove(profile);
emit favoriteStatusChanged(profile,favorite);
emit favoriteStatusChanged(profile, favorite);
}
}
void SessionManager::loadShortcuts()
@@ -646,11 +618,10 @@ void SessionManager::loadShortcuts()
KSharedConfigPtr appConfig = KGlobal::config();
KConfigGroup shortcutGroup = appConfig->group("Profile Shortcuts");
QMap<QString,QString> entries = shortcutGroup.entryMap();
QMap<QString, QString> entries = shortcutGroup.entryMap();
QMapIterator<QString,QString> iter(entries);
while ( iter.hasNext() )
{
QMapIterator<QString, QString> iter(entries);
while (iter.hasNext()) {
iter.next();
QKeySequence shortcut = QKeySequence::fromString(iter.key());
@@ -659,7 +630,7 @@ void SessionManager::loadShortcuts()
ShortcutData data;
data.profilePath = profilePath;
_shortcuts.insert(shortcut,data);
_shortcuts.insert(shortcut, data);
}
}
void SessionManager::saveShortcuts()
@@ -668,19 +639,18 @@ void SessionManager::saveShortcuts()
KConfigGroup shortcutGroup = appConfig->group("Profile Shortcuts");
shortcutGroup.deleteGroup();
QMapIterator<QKeySequence,ShortcutData> iter(_shortcuts);
while ( iter.hasNext() )
{
QMapIterator<QKeySequence, ShortcutData> iter(_shortcuts);
while (iter.hasNext()) {
iter.next();
QString shortcutString = iter.key().toString();
shortcutGroup.writeEntry(shortcutString,
iter.value().profilePath);
}
iter.value().profilePath);
}
}
void SessionManager::setShortcut(Profile::Ptr profile ,
const QKeySequence& keySequence )
void SessionManager::setShortcut(Profile::Ptr profile ,
const QKeySequence& keySequence)
{
QKeySequence existingShortcut = shortcut(profile);
_shortcuts.remove(existingShortcut);
@@ -691,11 +661,11 @@ void SessionManager::setShortcut(Profile::Ptr profile ,
ShortcutData data;
data.profileKey = profile;
data.profilePath = profile->path();
// TODO - This won't work if the profile doesn't
// TODO - This won't work if the profile doesn't
// have a path yet
_shortcuts.insert(keySequence,data);
_shortcuts.insert(keySequence, data);
emit shortcutChanged(profile,keySequence);
emit shortcutChanged(profile, keySequence);
}
void SessionManager::loadFavorites()
{
@@ -704,37 +674,31 @@ void SessionManager::loadFavorites()
QSet<QString> favoriteSet;
if ( favoriteGroup.hasKey("Favorites") )
{
QStringList list = favoriteGroup.readEntry("Favorites", QStringList());
favoriteSet = QSet<QString>::fromList(list);
}
else
{
// if there is no favorites key at all, mark the
// supplied 'Shell.profile' as the only favorite
favoriteSet << "Shell.profile";
if (favoriteGroup.hasKey("Favorites")) {
QStringList list = favoriteGroup.readEntry("Favorites", QStringList());
favoriteSet = QSet<QString>::fromList(list);
} else {
// if there is no favorites key at all, mark the
// supplied 'Shell.profile' as the only favorite
favoriteSet << "Shell.profile";
}
// look for favorites amongst those already loaded
QSetIterator<Profile::Ptr> iter(_profiles);
while ( iter.hasNext() )
{
Profile::Ptr profile = iter.next();
const QString& path = profile->path();
if ( favoriteSet.contains( path ) )
{
_favorites.insert( profile );
favoriteSet.remove(path);
}
while (iter.hasNext()) {
Profile::Ptr profile = iter.next();
const QString& path = profile->path();
if (favoriteSet.contains(path)) {
_favorites.insert(profile);
favoriteSet.remove(path);
}
}
// load any remaining favorites
QSetIterator<QString> unloadedFavoriteIter(favoriteSet);
while ( unloadedFavoriteIter.hasNext() )
{
Profile::Ptr profile = loadProfile(unloadedFavoriteIter.next());
if (profile)
_favorites.insert(profile);
while (unloadedFavoriteIter.hasNext()) {
Profile::Ptr profile = loadProfile(unloadedFavoriteIter.next());
if (profile)
_favorites.insert(profile);
}
_loadedFavorites = true;
@@ -746,32 +710,29 @@ void SessionManager::saveFavorites()
QStringList paths;
QSetIterator<Profile::Ptr> keyIter(_favorites);
while ( keyIter.hasNext() )
{
while (keyIter.hasNext()) {
Profile::Ptr profile = keyIter.next();
Q_ASSERT( _profiles.contains(profile) && profile );
Q_ASSERT(_profiles.contains(profile) && profile);
paths << profile->path();
}
favoriteGroup.writeEntry("Favorites",paths);
favoriteGroup.writeEntry("Favorites", paths);
}
QList<QKeySequence> SessionManager::shortcuts()
QList<QKeySequence> SessionManager::shortcuts()
{
return _shortcuts.keys();
}
Profile::Ptr SessionManager::findByShortcut(const QKeySequence& shortcut)
{
Q_ASSERT( _shortcuts.contains(shortcut) );
Q_ASSERT(_shortcuts.contains(shortcut));
if ( !_shortcuts[shortcut].profileKey )
{
if (!_shortcuts[shortcut].profileKey) {
Profile::Ptr key = loadProfile(_shortcuts[shortcut].profilePath);
if (!key)
{
if (!key) {
_shortcuts.remove(shortcut);
return Profile::Ptr();
}
@@ -784,42 +745,37 @@ Profile::Ptr SessionManager::findByShortcut(const QKeySequence& shortcut)
void SessionManager::sessionProfileCommandReceived(const QString& text)
{
Session* session = qobject_cast<Session*>(sender());
Q_ASSERT( session );
Q_ASSERT(session);
ProfileCommandParser parser;
QHash<Profile::Property,QVariant> changes = parser.parse(text);
QHash<Profile::Property, QVariant> changes = parser.parse(text);
Profile::Ptr newProfile;
if ( !_sessionRuntimeProfiles.contains(session) )
{
if (!_sessionRuntimeProfiles.contains(session)) {
newProfile = new Profile(_sessionProfiles[session]);
_sessionRuntimeProfiles.insert(session,newProfile);
}
else
{
_sessionRuntimeProfiles.insert(session, newProfile);
} else {
newProfile = _sessionRuntimeProfiles[session];
}
QHashIterator<Profile::Property,QVariant> iter(changes);
while ( iter.hasNext() )
{
QHashIterator<Profile::Property, QVariant> iter(changes);
while (iter.hasNext()) {
iter.next();
newProfile->setProperty(iter.key(),iter.value());
}
newProfile->setProperty(iter.key(), iter.value());
}
_sessionProfiles[session] = newProfile;
applyProfile(newProfile,true);
applyProfile(newProfile, true);
emit sessionUpdated(session);
}
QKeySequence SessionManager::shortcut(Profile::Ptr profile) const
{
QMapIterator<QKeySequence,ShortcutData> iter(_shortcuts);
while (iter.hasNext())
{
QMapIterator<QKeySequence, ShortcutData> iter(_shortcuts);
while (iter.hasNext()) {
iter.next();
if ( iter.value().profileKey == profile
|| iter.value().profilePath == profile->path() )
if (iter.value().profileKey == profile
|| iter.value().profilePath == profile->path())
return iter.key();
}
@@ -833,8 +789,7 @@ void SessionManager::saveSessions(KConfig* config)
int n = 1;
_restoreMapping.clear();
foreach(Session* session, _sessions)
{
foreach(Session * session, _sessions) {
QString name = QLatin1String("Session") + QString::number(n);
KConfigGroup group(config, name);
@@ -860,10 +815,8 @@ void SessionManager::restoreSessions(KConfig* config)
int sessions;
// Any sessions saved?
if ((sessions = group.readEntry("NumberOfSessions", 0)) > 0)
{
for (int n = 1; n <= sessions; n++)
{
if ((sessions = group.readEntry("NumberOfSessions", 0)) > 0) {
for (int n = 1; n <= sessions; n++) {
QString name = QLatin1String("Session") + QString::number(n);
KConfigGroup sessionGroup(config, name);
@@ -879,10 +832,10 @@ void SessionManager::restoreSessions(KConfig* config)
Session* SessionManager::idToSession(int id)
{
Q_ASSERT(id);
foreach(Session* session, _sessions)
if (session->sessionId() == id)
return session;
Q_ASSERT(id);
foreach(Session * session, _sessions)
if (session->sessionId() == id)
return session;
// this should not happen
Q_ASSERT(0);
@@ -890,7 +843,7 @@ Session* SessionManager::idToSession(int id)
}
SessionListModel::SessionListModel(QObject* parent)
: QAbstractListModel(parent)
: QAbstractListModel(parent)
{
}
@@ -898,8 +851,8 @@ void SessionListModel::setSessions(const QList<Session*>& sessions)
{
_sessions = sessions;
foreach(Session* session, sessions)
connect(session,SIGNAL(finished()),this,SLOT(sessionFinished()));
foreach(Session * session, sessions)
connect(session, SIGNAL(finished()), this, SLOT(sessionFinished()));
reset();
}
@@ -910,45 +863,42 @@ QVariant SessionListModel::data(const QModelIndex& index, int role) const
int row = index.row();
int column = index.column();
Q_ASSERT( row >= 0 && row < _sessions.count() );
Q_ASSERT( column >= 0 && column < 2 );
Q_ASSERT(row >= 0 && row < _sessions.count());
Q_ASSERT(column >= 0 && column < 2);
switch (role)
{
case Qt::DisplayRole:
if (column == 1)
return _sessions[row]->title(Session::DisplayedTitleRole);
else if (column == 0)
return _sessions[row]->sessionId();
break;
case Qt::DecorationRole:
if (column == 1)
return KIcon(_sessions[row]->iconName());
else
return QVariant();
switch (role) {
case Qt::DisplayRole:
if (column == 1)
return _sessions[row]->title(Session::DisplayedTitleRole);
else if (column == 0)
return _sessions[row]->sessionId();
break;
case Qt::DecorationRole:
if (column == 1)
return KIcon(_sessions[row]->iconName());
else
return QVariant();
}
return QVariant();
}
QVariant SessionListModel::headerData(int section, Qt::Orientation orientation,
int role) const
QVariant SessionListModel::headerData(int section, Qt::Orientation orientation,
int role) const
{
if (role != Qt::DisplayRole)
return QVariant();
if (orientation == Qt::Vertical)
return QVariant();
else
{
switch (section)
{
case 0:
return i18nc("@item:intable The session index", "Number");
case 1:
return i18nc("@item:intable The session title", "Title");
default:
return QVariant();
}
else {
switch (section) {
case 0:
return i18nc("@item:intable The session index", "Number");
case 1:
return i18nc("@item:intable The session title", "Title");
default:
return QVariant();
}
}
}
@@ -969,9 +919,8 @@ void SessionListModel::sessionFinished()
Session* session = qobject_cast<Session*>(sender());
int row = _sessions.indexOf(session);
if (row != -1)
{
beginRemoveRows(QModelIndex(),row,row);
if (row != -1) {
beginRemoveRows(QModelIndex(), row, row);
sessionRemoved(session);
_sessions.removeAt(row);
endRemoveRows();
@@ -979,8 +928,8 @@ void SessionListModel::sessionFinished()
}
QModelIndex SessionListModel::index(int row, int column, const QModelIndex& parent) const
{
if (hasIndex(row,column,parent))
return createIndex(row,column,_sessions[row]);
if (hasIndex(row, column, parent))
return createIndex(row, column, _sessions[row]);
else
return QModelIndex();
}

View File

@@ -57,7 +57,7 @@ class Session;
*/
class KONSOLEPRIVATE_EXPORT SessionManager : public QObject
{
Q_OBJECT
Q_OBJECT
public:
/**
@@ -133,8 +133,8 @@ public:
* set this to false if you want to preview possible changes to a profile but do not
* wish to make them permanent.
*/
void changeProfile(Profile::Ptr profile , QHash<Profile::Property,QVariant> propertyMap,
bool persistent = true);
void changeProfile(Profile::Ptr profile , QHash<Profile::Property, QVariant> propertyMap,
bool persistent = true);
/**
* Returns a Profile object describing the default type of session, which is used
@@ -298,7 +298,7 @@ protected slots:
*
* @param session The Session which has finished executing.
*/
void sessionTerminated( QObject* session );
void sessionTerminated(QObject* session);
private slots:
void sessionProfileCommandReceived(const QString& text);
@@ -332,23 +332,22 @@ private:
// if modifiedPropertiesOnly is true, only properties which
// are set in @p profile are update ( ie. properties for which profile->isPropertySet(<property>)
// returns true )
void applyProfile(Session* session , const Profile::Ptr profile , bool modifiedPropertiesOnly);
void applyProfile(Session* session , const Profile::Ptr profile , bool modifiedPropertiesOnly);
QSet<Profile::Ptr> _profiles;
QHash<Session*,Profile::Ptr> _sessionProfiles;
QHash<Session*,Profile::Ptr> _sessionRuntimeProfiles;
QHash<Session*,int> _restoreMapping;
QHash<Session*, Profile::Ptr> _sessionProfiles;
QHash<Session*, Profile::Ptr> _sessionRuntimeProfiles;
QHash<Session*, int> _restoreMapping;
struct ShortcutData
{
struct ShortcutData {
Profile::Ptr profileKey;
QString profilePath;
};
QMap<QKeySequence,ShortcutData> _shortcuts; // shortcut keys -> profile path
QMap<QKeySequence, ShortcutData> _shortcuts; // shortcut keys -> profile path
QList<Session*> _sessions; // list of running sessions
Profile::Ptr _defaultProfile;
Profile::Ptr _defaultProfile;
Profile::Ptr _fallbackProfile;
QSet<Profile::Ptr> _favorites; // list of favorite profiles
@@ -359,15 +358,14 @@ private:
};
/** Utility class to simplify code in SessionManager::applyProfile(). */
class ShouldApplyProperty
class ShouldApplyProperty
{
public:
ShouldApplyProperty(const Profile::Ptr profile , bool modifiedOnly) :
_profile(profile) , _modifiedPropertiesOnly(modifiedOnly) {}
ShouldApplyProperty(const Profile::Ptr profile , bool modifiedOnly) :
_profile(profile) , _modifiedPropertiesOnly(modifiedOnly) {}
bool shouldApply(Profile::Property property) const
{
return !_modifiedPropertiesOnly || _profile->isPropertySet(property);
bool shouldApply(Profile::Property property) const {
return !_modifiedPropertiesOnly || _profile->isPropertySet(property);
}
private:
const Profile::Ptr _profile;
@@ -385,11 +383,10 @@ template <class T>
class PopStackOnExit
{
public:
PopStackOnExit(QStack<T>& stack) : _stack(stack) , _count(stack.count()) {}
~PopStackOnExit()
{
while (_stack.count() > _count)
_stack.pop();
PopStackOnExit(QStack<T>& stack) : _stack(stack) , _count(stack.count()) {}
~PopStackOnExit() {
while (_stack.count() > _count)
_stack.pop();
}
private:
QStack<T>& _stack;
@@ -406,7 +403,7 @@ private:
*/
class SessionListModel : public QAbstractListModel
{
Q_OBJECT
Q_OBJECT
public:
SessionListModel(QObject* parent = 0);
@@ -421,8 +418,8 @@ public:
// reimplemented from QAbstractItemModel
virtual QModelIndex index(int row, int column, const QModelIndex& parent) const;
virtual QVariant data(const QModelIndex& index, int role) const;
virtual QVariant headerData(int section, Qt::Orientation orientation,
int role) const;
virtual QVariant headerData(int section, Qt::Orientation orientation,
int role) const;
virtual int columnCount(const QModelIndex& parent) const;
virtual int rowCount(const QModelIndex& parent) const;
virtual QModelIndex parent(const QModelIndex& index) const;
@@ -434,7 +431,7 @@ private slots:
void sessionFinished();
private:
QList<Session*> _sessions;
QList<Session*> _sessions;
};
}