Bug 94864

Summary: workdir option sets starting directory only for the very first session in konsole
Product: [Applications] konsole Reporter: Rudo Thomas <rudo>
Component: generalAssignee: Konsole Developer <konsole-devel>
Status: RESOLVED FIXED    
Severity: wishlist    
Priority: NOR    
Version: unspecified   
Target Milestone: ---   
Platform: Gentoo Packages   
OS: Linux   
Latest Commit: Version Fixed In:
Sentry Crash Report:
Attachments: This patch solved the problem described.
Revised version of the patch.
More recent patch

Description Rudo Thomas 2004-12-10 23:40:04 UTC
Version:            (using KDE KDE 3.3.1)
Installed from:    Gentoo Packages

Hello.

I think the --workdir konsole option does not work as it should.

Yes, it opens the first tab in the right folder, but any newly opened
one starts in the directory konsole was run from.

The proposed patch (against kdebase-3.3.1) makes these changes:
 * when --workdir DIR is specified
   * the first tab is opened at DIR
   * any subsequent tab is opened in DIR, but only if the session has
     empty Directory setting
   * it is saved/restored by session management
  (* bookmarks work without change)

Any comments are welcome.

Please consider applying. It should be binary compatible with previous
versions.

Have a pleasant day.
Comment 1 Rudo Thomas 2004-12-10 23:41:28 UTC
Created attachment 8612 [details]
This patch solved the problem described.

Still applies to 3.3.2.
Comment 2 Rudo Thomas 2004-12-12 14:29:53 UTC
Created attachment 8632 [details]
Revised version of the patch.

The previous version always set workdir when restoring session. The revised one
(against 3.3.2) solves this issue. It is not binary compatible, however. This
makes it a candidate for inclusion in KDE-3.4...?
Comment 3 Kurt Hindenburg 2004-12-18 20:31:33 UTC
I'm aware of your patch.  I'm busy with another konsole patch for the moment.    When I get some free time I'll test it. It is possible it will make it in for 3.4
Comment 4 Kurt Hindenburg 2004-12-26 05:39:35 UTC
Created attachment 8816 [details]
More recent patch

With all the changes recently, the old patch didn't apply cleanly.  Here is a
new version for CVS.
I don't use --workdir and I'm not sure if it 'expected' that all newly created
sessions should start up at --workdir.
Comment 5 Rudo Thomas 2004-12-27 16:11:45 UTC
Hmmm. How would you describe the expected effect of the workdir option
then?

I think setting the directory for the first session *only* does not make
much sense.

Happy new year :-)

Rudo.

Comment 6 Kurt Hindenburg 2004-12-31 01:08:49 UTC
CVS commit by hindenburg: 

Allow --workdir to set the directory in new sessions.
Thanks to Rudo Thomas for the patch, which had to be altered slightly.

FEATURE: 94864


  M +10 -1     konsole.cpp   1.495
  M +3 -1      konsole.h   1.193
  M +3 -2      main.cpp   1.276


--- kdebase/konsole/konsole/konsole.cpp  #1.494:1.495
@@ -188,5 +188,5 @@ static const char * const fonts[] = {
 
 Konsole::Konsole(const char* name, int histon, bool menubaron, bool tabbaron, bool frameon, bool scrollbaron,
-                 QCString type, bool b_inRestore, const int wanted_tabbar )
+                 QCString type, bool b_inRestore, const int wanted_tabbar, const QString &workdir )
 :DCOPObject( "konsole" )
 ,KMainWindow(0, name)
@@ -265,4 +265,5 @@ Konsole::Konsole(const char* name, int h
 ,sessionNumberMapper(0)
 ,sl_sessionShortCuts(0)
+,s_workDir(workdir)
 {
   isRestored = b_inRestore;
@@ -1433,4 +1434,7 @@ void Konsole::saveProperties(KConfig* co
       saveMainWindowSettings(config);
   }
+
+  if (!s_workDir.isEmpty())
+    config->writePathEntry("workdir", s_workDir);
 }
 
@@ -2672,4 +2676,9 @@ QString Konsole::newSession(KSimpleConfi
      txt = _title;
 
+  // apply workdir only when the session config does not have a directory
+  if (cwd.isEmpty())
+     cwd = s_workDir;
+  // bookmarks take precedence over workdir
+  // however, --workdir option has precedence in the very first session
   if (!_cwd.isEmpty())
      cwd = _cwd;

--- kdebase/konsole/konsole/konsole.h  #1.192:1.193
@@ -69,5 +69,6 @@ public:
   Konsole(const char * name, int histon, bool menubaron, bool tabbaron,
     bool frameon, bool scrollbaron,
-    QCString type = 0, bool b_inRestore = false, const int wanted_tabbar = 0);
+    QCString type = 0, bool b_inRestore = false, const int wanted_tabbar = 0,
+    const QString &workdir=QString::null);
 
   ~Konsole();
@@ -415,4 +416,5 @@ private:
   QSignalMapper* sessionNumberMapper;
   QStringList    sl_sessionShortCuts;
+  QString  s_workDir;
 };
 

--- kdebase/konsole/konsole/main.cpp  #1.275:1.276
@@ -473,6 +473,7 @@ extern "C" int KDE_EXPORT kdemain(int ar
         sIcon = sessionconfig->readEntry("Icon0","openterm");
         sCwd = sessionconfig->readPathEntry("Cwd0");
+        workDir = sessionconfig->readPathEntry("workdir");
         n_tabbar = QMIN(sessionconfig->readUnsignedNumEntry("tabbar",Konsole::TabBottom),2);
-        Konsole *m = new Konsole(wname,histon,menubaron,tabbaron,frameon,scrollbaron,0/*type*/,true,n_tabbar);
+        Konsole *m = new Konsole(wname,histon,menubaron,tabbaron,frameon,scrollbaron,0/*type*/,true,n_tabbar, workDir);
 
         m->newSession(sPgm, eargs, sTerm, sIcon, sTitle, sCwd);
@@ -542,5 +543,5 @@ extern "C" int KDE_EXPORT kdemain(int ar
   else
   {
-    Konsole*  m = new Konsole(wname,histon,menubaron,tabbaron,frameon,scrollbaron,type, false, 0);
+    Konsole*  m = new Konsole(wname,histon,menubaron,tabbaron,frameon,scrollbaron,type, false, 0, workDir);
     m->newSession((shell ? QFile::decodeName(shell) : QString::null), eargs, term, QString::null, title, workDir);
     m->enableFullScripting(full_script);