Changeset View
Changeset View
Standalone View
Standalone View
src/SessionManager.cpp
Show First 20 Lines • Show All 55 Lines • ▼ Show 20 Line(s) | |||||
56 | SessionManager::~SessionManager() | 56 | SessionManager::~SessionManager() | ||
57 | { | 57 | { | ||
58 | if (!_sessions.isEmpty()) { | 58 | if (!_sessions.isEmpty()) { | ||
59 | qCDebug(KonsoleDebug) << "Konsole SessionManager destroyed with" | 59 | qCDebug(KonsoleDebug) << "Konsole SessionManager destroyed with" | ||
60 | << _sessions.count() | 60 | << _sessions.count() | ||
61 | <<"session(s) still alive"; | 61 | <<"session(s) still alive"; | ||
62 | // ensure that the Session doesn't later try to call back and do things to the | 62 | // ensure that the Session doesn't later try to call back and do things to the | ||
63 | // SessionManager | 63 | // SessionManager | ||
64 | foreach (Session *session, _sessions) { | 64 | for (auto *session : _sessions) { | ||
65 | disconnect(session, nullptr, this, nullptr); | 65 | disconnect(session, nullptr, this, nullptr); | ||
66 | } | 66 | } | ||
67 | } | 67 | } | ||
68 | } | 68 | } | ||
69 | 69 | | |||
70 | Q_GLOBAL_STATIC(SessionManager, theSessionManager) | 70 | Q_GLOBAL_STATIC(SessionManager, theSessionManager) | ||
71 | SessionManager* SessionManager::instance() | 71 | SessionManager* SessionManager::instance() | ||
72 | { | 72 | { | ||
73 | return theSessionManager; | 73 | return theSessionManager; | ||
74 | } | 74 | } | ||
75 | 75 | | |||
76 | bool SessionManager::isClosingAllSessions() const | 76 | bool SessionManager::isClosingAllSessions() const | ||
77 | { | 77 | { | ||
78 | return _isClosingAllSessions; | 78 | return _isClosingAllSessions; | ||
79 | } | 79 | } | ||
80 | 80 | | |||
81 | void SessionManager::closeAllSessions() | 81 | void SessionManager::closeAllSessions() | ||
82 | { | 82 | { | ||
83 | _isClosingAllSessions = true; | 83 | _isClosingAllSessions = true; | ||
84 | foreach (Session *session, _sessions) { | 84 | for (auto *session : _sessions) { | ||
85 | session->close(); | 85 | session->close(); | ||
86 | } | 86 | } | ||
87 | _sessions.clear(); | 87 | _sessions.clear(); | ||
88 | } | 88 | } | ||
89 | 89 | | |||
90 | const QList<Session *> SessionManager::sessions() const | 90 | const QList<Session *> SessionManager::sessions() const | ||
91 | { | 91 | { | ||
92 | return _sessions; | 92 | return _sessions; | ||
▲ Show 20 Lines • Show All 44 Lines • ▼ Show 20 Line(s) | 133 | { | |||
137 | _sessionProfiles.remove(session); | 137 | _sessionProfiles.remove(session); | ||
138 | _sessionRuntimeProfiles.remove(session); | 138 | _sessionRuntimeProfiles.remove(session); | ||
139 | 139 | | |||
140 | session->deleteLater(); | 140 | session->deleteLater(); | ||
141 | } | 141 | } | ||
142 | 142 | | |||
143 | void SessionManager::applyProfile(const Profile::Ptr &profile, bool modifiedPropertiesOnly) | 143 | void SessionManager::applyProfile(const Profile::Ptr &profile, bool modifiedPropertiesOnly) | ||
144 | { | 144 | { | ||
145 | foreach (Session *session, _sessions) { | 145 | for (auto *session : _sessions) { | ||
146 | if (_sessionProfiles[session] == profile) { | 146 | if (_sessionProfiles[session] == profile) { | ||
147 | applyProfile(session, profile, modifiedPropertiesOnly); | 147 | applyProfile(session, profile, modifiedPropertiesOnly); | ||
148 | } | 148 | } | ||
149 | } | 149 | } | ||
150 | } | 150 | } | ||
151 | 151 | | |||
152 | Profile::Ptr SessionManager::sessionProfile(Session *session) const | 152 | Profile::Ptr SessionManager::sessionProfile(Session *session) const | ||
153 | { | 153 | { | ||
▲ Show 20 Lines • Show All 139 Lines • ▼ Show 20 Line(s) | |||||
293 | { | 293 | { | ||
294 | auto *session = qobject_cast<Session *>(sender()); | 294 | auto *session = qobject_cast<Session *>(sender()); | ||
295 | Q_ASSERT(session); | 295 | Q_ASSERT(session); | ||
296 | 296 | | |||
297 | // store the font for each view if zoom was applied so that they can | 297 | // store the font for each view if zoom was applied so that they can | ||
298 | // be restored after applying the new profile | 298 | // be restored after applying the new profile | ||
299 | QHash<TerminalDisplay *, QFont> zoomFontSizes; | 299 | QHash<TerminalDisplay *, QFont> zoomFontSizes; | ||
300 | 300 | | |||
301 | foreach (TerminalDisplay *view, session->views()) { | 301 | for (auto *view : session->views()) { | ||
302 | const QFont &viewCurFont = view->getVTFont(); | 302 | const QFont &viewCurFont = view->getVTFont(); | ||
303 | if (viewCurFont != _sessionProfiles[session]->font()) { | 303 | if (viewCurFont != _sessionProfiles[session]->font()) { | ||
304 | zoomFontSizes.insert(view, viewCurFont); | 304 | zoomFontSizes.insert(view, viewCurFont); | ||
305 | } | 305 | } | ||
306 | } | 306 | } | ||
307 | 307 | | |||
308 | ProfileCommandParser parser; | 308 | ProfileCommandParser parser; | ||
309 | QHash<Profile::Property, QVariant> changes = parser.parse(text); | 309 | QHash<Profile::Property, QVariant> changes = parser.parse(text); | ||
Show All 27 Lines | |||||
337 | 337 | | |||
338 | void SessionManager::saveSessions(KConfig *config) | 338 | void SessionManager::saveSessions(KConfig *config) | ||
339 | { | 339 | { | ||
340 | // The session IDs can't be restored. | 340 | // The session IDs can't be restored. | ||
341 | // So we need to map the old ID to the future new ID. | 341 | // So we need to map the old ID to the future new ID. | ||
342 | int n = 1; | 342 | int n = 1; | ||
343 | _restoreMapping.clear(); | 343 | _restoreMapping.clear(); | ||
344 | 344 | | |||
345 | foreach (Session *session, _sessions) { | 345 | for (auto *session : _sessions) { | ||
346 | QString name = QLatin1String("Session") + QString::number(n); | 346 | QString name = QLatin1String("Session") + QString::number(n); | ||
347 | KConfigGroup group(config, name); | 347 | KConfigGroup group(config, name); | ||
348 | 348 | | |||
349 | group.writePathEntry("Profile", | 349 | group.writePathEntry("Profile", | ||
350 | _sessionProfiles.value(session)->path()); | 350 | _sessionProfiles.value(session)->path()); | ||
351 | session->saveSession(group); | 351 | session->saveSession(group); | ||
352 | _restoreMapping.insert(session, n); | 352 | _restoreMapping.insert(session, n); | ||
353 | n++; | 353 | n++; | ||
Show All 25 Lines | 371 | for (int n = 1; n <= sessions; n++) { | |||
379 | } | 379 | } | ||
380 | Session *session = createSession(ptr); | 380 | Session *session = createSession(ptr); | ||
381 | session->restoreSession(sessionGroup); | 381 | session->restoreSession(sessionGroup); | ||
382 | } | 382 | } | ||
383 | } | 383 | } | ||
384 | 384 | | |||
385 | Session *SessionManager::idToSession(int id) | 385 | Session *SessionManager::idToSession(int id) | ||
386 | { | 386 | { | ||
387 | foreach (Session *session, _sessions) { | 387 | for (auto *session : _sessions) { | ||
388 | if (session->sessionId() == id) { | 388 | if (session->sessionId() == id) { | ||
389 | return session; | 389 | return session; | ||
390 | } | 390 | } | ||
391 | } | 391 | } | ||
392 | // this should not happen | 392 | // this should not happen | ||
393 | qCDebug(KonsoleDebug) << "Failed to find session for ID" << id; | 393 | qCDebug(KonsoleDebug) << "Failed to find session for ID" << id; | ||
394 | return nullptr; | 394 | return nullptr; | ||
395 | } | 395 | } |