Bug 156919

Summary: Embedded terminal should notify the host about changes in current working directory
Product: [Applications] konsole Reporter: Robert Knight <robertknight>
Component: kpartAssignee: Konsole Developer <konsole-devel>
Status: RESOLVED FIXED    
Severity: wishlist CC: blueice, chemobejk, hein
Priority: NOR    
Version: unspecified   
Target Milestone: ---   
Platform: Compiled Sources   
OS: Linux   
Latest Commit: Version Fixed In: 4.9.0
Sentry Crash Report:
Attachments: Implement new signal Part::currentDirectoryChanged(const QString&)

Description Robert Knight 2008-01-29 15:53:58 UTC
Version:           2.1 (using Devel)
Installed from:    Compiled sources

The embedded terminal should notify the host (via a signal) when the current working directory in the terminal changes.
Comment 1 Robert Knight 2008-01-29 15:54:25 UTC
This is a requirement for implementing: Bug #156732
Comment 2 Eike Hein 2008-01-29 15:56:48 UTC
I'd be interested in that as well, as it is a requirement for eventually implementing some measure of session saving and restore in Yakuake.
Comment 3 Stefan Becker 2008-09-10 21:19:05 UTC
This will change the part interface. Can this be done in a backward compatible way? I'm new to this stuff...


This is a difficult thing to implement as konsole isn't the process and therefore doesn't see any state changes from it. It can only poll for changes from its child process(es).


I see three ways how to do this:

a) new signal Konsole::SessionManager::directoryChanged()

I looked at yakuake. If I change the directory the window title gets updated shortly afterwards just like the tabs in konsole. So I assume yakuake already receives Konsole::Session::titleChanged() signals? Or how does yakuake know?


b) implement the same functionality as in Konsole::SessionController

Use a one-shot, 2 second QTimer that is armed at the end of Konsole::Part::sendInput(). The timeout() signal will be connected to a new slot that sends the Konsole::Part::directoryChanged() signal when necessary.


c) implement a new part method/signal that can be used to poll the current directory

Regular polling would then be the responsibility of the client. This solution might be necessary if a KPart is not allowed to use a QTimer.


Comments?
Comment 4 Eike Hein 2008-09-11 11:17:09 UTC
KParts generally have a setWindowCaption() signal that the Konsole KPart emits with the contents of the "Tab title format" setting of the active profile, and that Yakuake then uses for the title bar or optionally tab titles. The user can set "Tab title format" to be the CWD, and that does work. Only that Yakuake of course can't really rely on that being the case.
Comment 5 Robert Knight 2008-09-11 11:58:14 UTC
> b) implement the same functionality as in Konsole::SessionController
> Use a one-shot, 2 second QTimer that is armed at the end of 
> Konsole::Part::sendInput(). The timeout() signal will be connected to a
> new slot that sends the Konsole::Part::directoryChanged() signal
> when necessary. 

The best place for this is the ViewProperties class which provides an interface that the ViewContainer classes (the tab widgets) use to get the text, icon and state of a tab.  SessionController inherits from ViewProperties and checks for changes in the current directory/program etc. of a session in the SessionController::snapshot() method which then updates the session's title.  The snapshot() method is called, with a short delay, after any input to the terminal.  

So, you could add a new signal currentDirChanged(QString) to ViewProperties and emit that from SessionController::snapshot()

In Konsole::Part you can listen for this signal by connecting to it in Part::activeViewChanged(SessionController*) - the same as for the titleChanged() signal.
Comment 6 Stefan Becker 2008-09-11 12:26:43 UTC
But you would still need a new signal that is emitted by the Konsole::Part, i.e.

void Part::activeDirectoryChanged(ViewProperties* properties)
{
	emit setCurrentDirectory(properties->currentDir());
}

And yakuake would connect to that, right?
Comment 7 Robert Knight 2008-09-11 12:50:59 UTC
> But you would still need a new signal that is emitted by the Konsole::Part, 
> i.e. void Part::activeDirectoryChanged(ViewProperties* properties)
> { emit setCurrentDirectory(properties->currentDir()); }
> And yakuake would connect to that, right? 

Yes.  Following Qt conventions the signal would be called directoryChanged() or currentDirectoryChanged().

Thank-you for looking into this at the tab restoration by the way.  I'm short changed for hobby time at the moment so it is really appreciated.
Comment 8 Stefan Becker 2008-09-12 20:42:41 UTC
Created attachment 27384 [details]
Implement new signal Part::currentDirectoryChanged(const QString&)

Before I could implement the signal I had to refactor the ProcessInfo usage. Now Session is the sole user of ProcessInfo and the process information can be found from one place. That's why the patch against kdebase-4.1.1 is so big.

The development history for the proposed patch can be found in my git repository at

   git clone http://chemobejk.dyndns.org/git/konsole/.git

in the branch kde-bug-156919.


From c79186f6c8eee10e9d2d1b506e807505085403c9 Mon Sep 17 00:00:00 2001
From: Stefan Becker <stefan.becker@nokia.com>
Date: Fri, 12 Sep 2008 21:33:00 +0300
Subject: [PATCH] Implement new signal Part::currentDirectoryChanged()

Simply forwards SessionController::currentDirectoryChanged() signal.

With this commit bug #156919 should be fixed. Please review & merge.
Comment 9 Eike Hein 2008-09-14 11:29:17 UTC
Hm, another thing that a Konsole KPart user would need for proper session restore would be a way to get and set the profile programmatically.

Robert, is there a changeSessionSettings() command to change the profile wholesale? That would still result in initially loading the wrong profile before switching to the right one (and with different bg colors, that probably means ugly flashing), but until the interface can be/is changed to accomodate a larger modification like an instanciation routine that takes a profile parameter, that's probably the best that can be done.

And with feature freeze on October 11th, things are on a pretty tight deadline now.
Comment 10 Stefan Becker 2008-09-14 21:28:33 UTC
BTW did you try the new code? Does it work for yakuake?
Comment 11 Eike Hein 2008-09-15 11:31:42 UTC
Sorry, I haven't had the time to work on on it yet. But on the face of it, a currentDirectoryChanged() signal that hands the app something that can be used in showShellInDir() later seems right. One of the more interesting things will be seeing what it does e.g. for ssh.
Comment 12 Kurt Hindenburg 2009-03-16 01:00:43 UTC
Do you a patch that applies to either 4.2 branch or trunk?
Comment 13 Stefan Becker 2009-03-16 06:32:57 UTC
No. But I think only the Part.* and SessionController.* parts from the old patch need to be applied. The rest of the changes were already integrated into 4.2.
Comment 14 Jekyll Wu 2012-03-23 14:58:51 UTC
Git commit 675dbcb2fe777b22044510579321148989d29cfb by Jekyll Wu.
Committed on 23/03/2012 at 15:16.
Pushed by jekyllwu into branch 'master'.

Emit signal currentDirectoryChanged(QString) after current directory changes

Note: the signal is not emitted immediately after the current directory
changes. There is noticable delay (usually below 1 second) at the
moment.
REVIEW: 104372
FIXED-IN:4.9.0

M  +4    -0    src/Part.cpp
M  +5    -0    src/Part.h
M  +8    -1    src/Session.cpp
M  +7    -0    src/Session.h
M  +3    -0    src/SessionController.cpp
M  +6    -0    src/SessionController.h

http://commits.kde.org/konsole/675dbcb2fe777b22044510579321148989d29cfb