Simplify code dealing with creating new sessions.
ClosedPublic

Authored by tcanabrava on May 18 2018, 4:21 PM.

Details

Summary

Remove duplicated code in various places dealing
with starting new sessions.

Test Plan

open konsole, multiple tabs, closed, didn't crash, seems to work.

Diff Detail

Repository
R319 Konsole
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
tcanabrava created this revision.May 18 2018, 4:21 PM
Restricted Application added a project: Konsole. · View Herald TranscriptMay 18 2018, 4:21 PM
Restricted Application added a subscriber: konsole-devel. · View Herald Transcript
tcanabrava requested review of this revision.May 18 2018, 4:21 PM
tcanabrava edited the test plan for this revision. (Show Details)May 18 2018, 4:21 PM
tcanabrava added a reviewer: Konsole.

I like the removal of duplicated code; however something still not correct. If you have konsole debug turned on and run konsole from another term you can see "org.kde.konsole: Attempted to re-run an already running session ( 28261 )" which should not be there. Briefly looking at the code, ViewManager::newSession has session->run() which is the removed code does not.

tcanabrava updated this revision to Diff 35354.Jun 1 2018, 3:59 PM
  • Don't start the session if it's unwanted.
hindenburg added inline comments.Jun 9 2018, 11:10 PM
src/ViewManager.cpp
1090–1091

did you mean runSession here? This currently doesn't compile.

tcanabrava updated this revision to Diff 36045.Jun 12 2018, 1:03 PM
  • Don't start the session if it's unwanted.
  • Remove Typo
tcanabrava marked an inline comment as done.Jun 12 2018, 1:03 PM
tcanabrava added inline comments.
src/ViewManager.cpp
1090–1091

"never commit code while sleeping", yes, sorry. fixed.

Ok, haven't found any regressions. The below item should be fixed later as I didn't realize it before.

While testing this, I notice Konsole on desktop session restore and demo_konsolepart, KONSOLE_DBUS_WINDOW is not set.

tcanabrava marked an inline comment as done.Jun 13 2018, 1:27 PM
This comment was removed by tcanabrava.
tcanabrava updated this revision to Diff 36099.Jun 13 2018, 1:42 PM
  • Remove forgotten duplicated code in Parts.cpp

Ok, haven't found any regressions. The below item should be fixed later as I didn't realize it before.

While testing this, I notice Konsole on desktop session restore and demo_konsolepart, KONSOLE_DBUS_WINDOW is not set.

While looking for this I'v found a 4rth time the same code was duplicated in the Konsole codebase, but on the parts it didn't set the KONSOLE_DBUS_WINDOW, I'v fixed by calling the SessionManager method and removing duplication.
For the restore window part - how do I test this?

For the restore window part - how do I test this?

Having a Konsole open and then logging off your desktop; when you log back in, the Konsole should be restored

> Having a Konsole open and then logging off your desktop; when you log back in, the Konsole should be restored

I found the code that deals with that:

void restoreSession(Application &app)
{
    int n = 1;
    while (KMainWindow::canBeRestored(n)) {
        app.newMainWindow()->restore(n++);
    }
}

and I'v tried to debug it but I failed to find the place that created the session while restoring. It's probabely calling SessionManager::createSession directly instead of requesting a new session from the ViewManager.
if you have time to help me find the incorrect call I'll be grateful as I'v spend quite a lot of time trying to find it

> Having a Konsole open and then logging off your desktop; when you log back in, the Konsole should be restored

I found the code that deals with that:

void restoreSession(Application &app)
{
    int n = 1;
    while (KMainWindow::canBeRestored(n)) {
        app.newMainWindow()->restore(n++);
    }
}

Application::newMainWindow, it calls this

connect(window, &Konsole::MainWindow::newWindowRequest, this,
        &Konsole::Application::createWindow);

createWindow:

MainWindow *window = newMainWindow();
window->createSession(profile, directory);
finalizeNewMainWindow(window);
> Having a Konsole open and then logging off your desktop; when you log back in, the Konsole should be restored

I found the code that deals with that:

void restoreSession(Application &app)
{
    int n = 1;
    while (KMainWindow::canBeRestored(n)) {
        app.newMainWindow()->restore(n++);
    }
}

Application::newMainWindow, it calls this

connect(window, &Konsole::MainWindow::newWindowRequest, this,
        &Konsole::Application::createWindow);

createWindow:

MainWindow *window = newMainWindow();
window->createSession(profile, directory);
finalizeNewMainWindow(window);

and window->createSession calls ViewManager::newSession that calls
session->addEnvironmentEntry(QStringLiteral("KONSOLE_DBUS_WINDOW=/Windows/%1").arg(managerId()));

that's the reason I said it's strange that the KONSOLE_DBUS_WINDOW is not set, as the only codepoint that I can follow always sets it.

and window->createSession calls ViewManager::newSession that calls
session->addEnvironmentEntry(QStringLiteral("KONSOLE_DBUS_WINDOW=/Windows/%1").arg(managerId()));

that's the reason I said it's strange that the KONSOLE_DBUS_WINDOW is not set, as the only codepoint that I can follow always sets it.

Yes, I'd have to debug this more to see why the addEnvironmentEntry doesn't appear be saved. We don't need to hold up this patch IMHO

Be my guest to accept and commit. I'm debugging this right now so I'd expect a patch today / tomorrow.

hindenburg retitled this revision from Remove triplicated code to Simplify code dealing with creating new sessions..Jun 14 2018, 2:28 PM
hindenburg edited the summary of this revision. (Show Details)
hindenburg accepted this revision.Jun 14 2018, 2:39 PM
This revision is now accepted and ready to land.Jun 14 2018, 2:39 PM
This revision was automatically updated to reflect the committed changes.