Bug 95644 - "Open Terminal" does not work with media ioslave
Summary: "Open Terminal" does not work with media ioslave
Status: RESOLVED FIXED
Alias: None
Product: kio
Classification: Frameworks and Libraries
Component: media (show other bugs)
Version: unspecified
Platform: Compiled Sources Linux
: NOR normal
Target Milestone: ---
Assignee: Kevin Ottens
URL:
Keywords:
: 104016 (view as bug list)
Depends on:
Blocks:
 
Reported: 2004-12-22 13:18 UTC by Thomas McGuire
Modified: 2005-05-21 15:21 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments
Patch (1.63 KB, patch)
2005-04-27 20:19 UTC, Thomas McGuire
Details
unified patch (1.30 KB, patch)
2005-04-28 20:38 UTC, Ruben Jenster
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas McGuire 2004-12-22 13:18:09 UTC
Version:            (using KDE Devel)
Installed from:    Compiled sources
OS:                Linux

In Konqueror, using Tools->Open Terminal or pressing F4 does not open Konsole in the current directory if the media ioslave is used, e.g. media:/hda5/dokumente/ should open a terminal at /mnt/daten/dokumente, but instead goes to my home directory.

This is not the only example where the media ioslave does not behave like the normal file:/ protocol. For example, media:/ does not immediately recognize the deletion of a file , while file:/ does (the file icon immediately disappears from the view here).

Because of this, the new System ioslave, which is placed on the desktop, is unuseabe for me (I use Konsole a lot).
Comment 1 Thiago Macieira 2004-12-22 16:21:50 UTC
> This is not the only example where the media ioslave does not behave like
> the normal file:/ protocol.

kio_media isn't kio_file. But what you describe next looks like a bug, if you deleted from Konqueror. If you deleted externally, you'll see the behaviour you described.

The other part of your request -- opening of terminals -- is not designed to work the way you want.

Personally, I have no idea why accessing files in media:/ copies them to a temporary directory, then saves back.
Comment 2 Kevin Ottens 2004-12-23 13:57:06 UTC
Hmmm looks like a tough one...

Le Mercredi 22 Décembre 2004 13:18, Thomas McGuire a écrit :
> In Konqueror, using Tools->Open Terminal or pressing F4 does not open
> Konsole in the current directory if the media ioslave is used, e.g.
> media:/hda5/dokumente/ should open a terminal at /mnt/daten/dokumente, but
> instead goes to my home directory.

The only solution I see here would be to make konsole aware of media:/ urls... 
but I'm not sure it's the right way to go. In particular because a media:/ 
url may not refer to a file:/ url (a simple mountpoint) but could refer to 
another ioslave url.

> This is not the only example where the media ioslave does not behave like
> the normal file:/ protocol. For example, media:/ does not immediately
> recognize the deletion of a file , while file:/ does (the file icon
> immediately disappears from the view here).

Do you mean that the file was deleted from Konqueror? or from a shell?
If it's from a shell, the code path is not the same, and file:/ has a special 
treatment not available to other ioslaves...
If it's from Konqueror... that's a bug as Thiago already pointed it.

Comment 3 Thomas McGuire 2004-12-23 21:58:55 UTC
On Thursday 23 December 2004 12:57, Kévin ervin Ottens wrote:
> The only solution I see here would be to make konsole aware of media:/
> urls... but I'm not sure it's the right way to go. In particular
> because a media:/ url may not refer to a file:/ url (a simple
> mountpoint) but could refer to another ioslave url.
Another solution would be to introduce a new function so every ioslave can 
be asked for a normal unix path for the current kio path. If the ioslave 
supports this, I can just return the normal path, like '/home/tmg'.
The media ioslave could of course decide itself if a normal path is 
applicable in the given situation, it would of course not return a normal 
unix path for 'media:/', but one for 'media:/hdb1'.
Hope I could make myself clear.

> Do you mean that the file was deleted from Konqueror? or from a shell?
> If it's from a shell, the code path is not the same, and file:/ has a
> special treatment not available to other ioslaves...
> If it's from Konqueror... that's a bug as Thiago already pointed it.
Actually, I now think I was completely wrong. I've tested this again and 
can't see any difference. I guess when I wrote the bug report, I deleted 
the file from Konsole in the one case and with Konqueror in the other 
case.
Sorry for any inconvenience.

Comment 4 Thiago Macieira 2004-12-23 22:31:17 UTC
I believe the solution should be something else.

Please see the discussion in kde-devel: http://lists.kde.org/?t=110383209100003&r=1&w=2
Comment 5 Zack Cerza 2005-04-17 20:13:39 UTC
*** Bug 104016 has been marked as a duplicate of this bug. ***
Comment 6 Thomas McGuire 2005-04-27 20:19:42 UTC
Created attachment 10817 [details]
Patch

This patch fixes the problem by using KIO::NetAccess to stat the current
directory and therefore retrieving mostLocalURL() info.

Note that media:/hda1/folder/ works, but media:/hda1/ does not. This seems to
be a bug in the media ioslave or in the kio classes. Please inform the
author(s) about this.
Comment 7 Ruben Jenster 2005-04-28 13:16:27 UTC
I applied this patch to the konqueror sources , but the behaviour is the same as before. I just recompiled the konqueror after applying the patch.
Do I have to rebuild other packages? If yes, which ones do I have to rebuild?

Regards 

Ruben
Comment 8 Thiago Macieira 2005-04-28 14:09:06 UTC
Make sure you didn't test this on an old, preloaded Konqueror.
Comment 9 Kevin Ottens 2005-04-28 14:22:53 UTC
As for the patch, it looks ok...

My only concern currently is that we clearly have a pattern here (already
used in some places for konqueror, and in kscd). I'm pondering to add
a convenience class to kdelibs to take care of UDS_LOCAL_PATH easily.

I'll see in the following weeks what can be done, and if the new
convenience class (or NetAccess method?) is introduced in kdelibs I'll
rework this patch.
Comment 10 Ruben Jenster 2005-04-28 15:01:37 UTC
I have restarted kde after having compiled the patched konqueror, so it couldn't be a preloaded konqueror instance. Tried it with my cardreader and my external firewire disc. The virtual terminal will still go into my home directory. One more time: Do I have to recompile some other part of kdebase then the konqueror?
 
Comment 11 Thomas McGuire 2005-04-28 17:00:52 UTC
> As for the patch, it looks ok... 
So someone should commit it (I don't have a CVS account)

> I'll see in the following weeks what can be done, and if the new 
> convenience class (or NetAccess method?) is introduced in kdelibs I'll 
> rework this patch. 
Yes, that would probably a good idea. Maybe add a mostLocalURL() function to KURL, too, which does what my patch does: Stat the file to retrieve the UDS_ENTRY and then call KFileItem::mostLocalURL().
However I am not sure if this is the right thing since I don't know what happens when the network stalls.

Kévin, you are the author of the media ioslave, aren't you? Do you have any idea why my patch does not work for root-level folders like media:/hda1?


> Do I have to recompile some other part of kdebase then the konqueror? 
No recompiling Konqueror should be sufficient. You did reinstall it after that, did you?
Please also try to use the "Open Terminal" command on folders which are on your harddisk, e.g. media:/hda1/home/ruben/ and see if it makes any difference.
Comment 12 Ruben Jenster 2005-04-28 20:34:24 UTC
Yes I did reinstall konqueror :-)
Makes no difference if it is a local folder tried my boot partition media:/hdb1/grub -> terminal still goes to home directory.
Comment 13 Ruben Jenster 2005-04-28 20:38:16 UTC
Created attachment 10839 [details]
unified patch

I had to manually apply the patch. I had to create a unified version of the
patch so that it could automatically be applied by portage. Maybe you should
take a look at it Thomas.
Comment 14 Thomas McGuire 2005-04-29 14:08:39 UTC
> I had to manually apply the patch. I had to create a unified version of the 
> patch so that it could automatically be applied by portage. Maybe you should 
> take a look at it Thomas. 
I don't have Gentoo, so I don't know what is different with it.
However, I DID a unified patch (you mean diff with the -u flag, right?).
The only difference seems to be the header, but that is only because you used different filenames. Additionally, my patch had some additional lines at the bottom, I guess that was the problem. I hand-edited my patch because there were some unwanted changes in it, probably I messed up.

Sorry for the inconvenience.
Comment 15 Ruben Jenster 2005-04-29 14:28:46 UTC
Well, but it still doesn't work - any suggestions?
Comment 16 Kevin Ottens 2005-05-20 23:46:45 UTC
SVN commit 416222 by ervin:

Introduce a new NetAccess::mostLocalURL() which tries to map a given URL
to a local file using UDS_LOCAL_PATH. We have some use cases for this,
mostly applications which needs to seek (like Kaffeine for example).

Will be used to fix #95644 too, since it has a similar need.

CCBUG:95644



 M  +38 -0     trunk/KDE/kdelibs/kio/kio/netaccess.cpp  


--- trunk/KDE/kdelibs/kio/kio/netaccess.cpp #416221:416222
@@ -204,6 +204,44 @@
   return ret;
 }
 
+KURL NetAccess::mostLocalURL(const KURL & url, QWidget* window)
+{
+  if ( url.isLocalFile() )
+  {
+    return url;
+  }
+
+  KIO::UDSEntry entry;
+  if (!stat(url, entry, window))
+  {
+    return url;
+  }
+
+  QString path;
+
+  // Extract the local path from the KIO::UDSEntry
+  KIO::UDSEntry::ConstIterator it = entry.begin();
+  const KIO::UDSEntry::ConstIterator end = entry.end();
+  for ( ; it != end; ++it )
+  {
+    if ( (*it).m_uds == KIO::UDS_LOCAL_PATH )
+    {
+      path = (*it).m_str;
+      break;
+    }
+  }
+
+  if ( !path.isEmpty() )
+  {
+    KURL new_url;
+    new_url.setPath(path);
+    return new_url;
+  }
+
+  return url;
+}
+
+
 bool NetAccess::del( const KURL & url )
 {
   return NetAccess::del( url, 0 );
Comment 17 Kevin Ottens 2005-05-20 23:49:56 UTC
SVN commit 416224 by ervin:

ADD the UDS_LOCAL_PATH atom to media roots. Was previously missing.

CCBUG:95644


 M  +5 -0      trunk/KDE/kdebase/kioslave/media/mediaimpl.cpp  


--- trunk/KDE/kdebase/kioslave/media/mediaimpl.cpp #416223:416224
@@ -346,6 +346,11 @@
 		}
 	}
 
+	if (url.isLocalFile())
+	{
+		addAtom(infos, KIO::UDS_LOCAL_PATH, 0, url.path());
+	}
+	
 	return infos;
 }
 
Comment 18 Kevin Ottens 2005-05-20 23:53:28 UTC
SVN commit 416229 by ervin:

Now test if we can get a local directory, when we open a terminal on the
current view. It uses the new NetAccess::mostLocalURL() to take care of
UDS_LOCAL_PATH (used for example by media:/).

BUG:95644



 M  +11 -2     trunk/KDE/kdebase/konqueror/konq_mainwindow.cc  


--- trunk/KDE/kdebase/konqueror/konq_mainwindow.cc #416228:416229
@@ -100,6 +100,7 @@
 #include <kpopupmenu.h>
 #include <kprocess.h>
 #include <kio/scheduler.h>
+#include <kio/netaccess.h>
 #include <kaccelmanager.h>
 #include <kuser.h>
 #include <netwm.h>
@@ -1362,17 +1363,25 @@
 
   QString dir ( QDir::homeDirPath() );
 
+  //Try to get the directory of the current view
   if ( m_currentView )
   {
       KURL u( m_currentView->url() );
+
+      // If the given directory is not local, it can still be the URL of an
+      // ioslave using UDS_LOCAL_PATH which to be converted first.
+      u = KIO::NetAccess::mostLocalURL(u, this);
+
+      //If the URL is local after the above conversion, set the directory.
       if ( u.isLocalFile() )
       {
-          if ( m_currentView->serviceType() == "inode/directory" )
+          QString mime = m_currentView->serviceType();
+          if ( KMimeType::mimeType(mime)->is("inode/directory") )
               dir = u.path();
           else
               dir = u.directory();
+      }
   }
-  }
 
   KProcess cmd;
   cmd.setWorkingDirectory(dir);
Comment 19 Ruben Jenster 2005-05-21 01:52:19 UTC
I applied the patch to netaccess.cpp and kdelibs fails compiling

ION  -c -o libkiocore_la.all_cpp.lo libkiocore_la.all_cpp.cpp
In file included from libkiocore_la.all_cpp.cpp:8:
scheduler.cpp: In member function `void KIO::Scheduler::slotCleanIdleSlaves()':
scheduler.cpp:644: warning: `connection' is deprecated (declared at ./../kio/slave.h:203)
In file included from libkiocore_la.all_cpp.cpp:14:
netaccess.cpp: At global scope:
netaccess.cpp:208: error: no `KURL KIO::NetAccess::mostLocalURL(const KURL&, QWidget*)' member function declared in class `KIO::NetAccess'
In file included from libkiocore_la.all_cpp.cpp:18:
slavebase.cpp: In member function `void KIO::SlaveBase::connectSlave(const QString&)':
slavebase.cpp:328: warning: `__comp_ctor' is deprecated (declared at ../../kdecore/ksock.h:108)
In file included from libksycoca_la.all_cpp.cpp:38:
kfilemetainfo.cpp: In static member function `static KFileMetaInfoItem::Data* KFileMetaInfoItem::Data::makeNull()':
kfilemetainfo.cpp:91: warning: `setObject' is deprecated (declared at ../../kdecore/kstaticdeleter.h:85)
kfilemetainfo.cpp: In static member function `static KFileMetaInfo::Data* KFileMetaInfo::Data::makeNull()':
kfilemetainfo.cpp:758: warning: `setObject' is deprecated (declared at ../../kdecore/kstaticdeleter.h:85)
kfilemetainfo.cpp: In destructor `virtual KFileMetaInfoProvider::~KFileMetaInfoProvider()':
kfilemetainfo.cpp:911: warning: `setObject' is deprecated (declared at ../../kdecore/kstaticdeleter.h:85)
kfilemetainfo.cpp: In static member function `static KFileMetaInfoGroup::Data* KFileMetaInfoGroup::Data::makeNull()':
kfilemetainfo.cpp:1448: warning: `setObject' is deprecated (declared at ../../kdecore/kstaticdeleter.h:85)
kurlcompletion.cpp: At global scope:
kurlcompletion.cpp:1222: warning: unused parameter 'job'
make[3]: *** [libkiocore_la.all_cpp.lo] Fehler 1
make[3]: *** Warte auf noch nicht beendete Prozesse...
make[3]: Leaving directory `/var/tmp/portage/kdelibs-3.4.0-r2/work/kdelibs-3.4.0/kio/kio'
make[2]: *** [all-recursive] Fehler 1
make[2]: Leaving directory `/var/tmp/portage/kdelibs-3.4.0-r2/work/kdelibs-3.4.0/kio'
make[1]: *** [all-recursive] Fehler 1
make[1]: Leaving directory `/var/tmp/portage/kdelibs-3.4.0-r2/work/kdelibs-3.4.0'
make: *** [all] Fehler 2
Comment 20 Kevin Ottens 2005-05-21 07:42:45 UTC
SVN commit 416310 by ervin:

Oops! I forgot to commit the netaccess.h (and no, I'm generally not
committing one file at a time :-p).

CCBUG:95644



 M  +18 -6     trunk/KDE/kdelibs/kio/kio/netaccess.h  


--- trunk/KDE/kdelibs/kio/kio/netaccess.h #416309:416310
@@ -301,6 +301,24 @@
     static bool stat(const KURL& url, KIO::UDSEntry & entry) KDE_DEPRECATED;
 
     /**
+     * Tries to map a local URL for the given URL.
+     *
+     * This is a convenience function for KIO::stat + parsing the
+     * resulting UDSEntry.
+     *
+     * @param url The URL we are testing.
+     * @param window main window associated with this job. This is used to
+     *               automatically cache and discard authentication information
+     *               as needed. If NULL, authentication information will be
+     *               cached only for a short duration after which the user will
+     *               again be prompted for passwords as needed.
+     * @return a local URL corresponding to the same ressource than the
+     *         original URL, or the original URL if no local URL can be mapped
+     * @since 3.5
+     */
+    static KURL mostLocalURL(const KURL& url, QWidget* window);
+
+    /**
      * Deletes a file or a directory in a synchronous way.
      *
      * This is a convenience function for KIO::del
@@ -451,12 +469,6 @@
      */
     static int lastError() { return lastErrorCode; }
 
-    /**
-     * Try to map a given URL to a local file
-     * @since 3.5
-     */
-    KURL mostLocalURL( const KURL& url, QWidget* window );
-
 private:
     /**
      * Private constructor
Comment 21 Ruben Jenster 2005-05-21 15:04:52 UTC
Ok, now it does work when you open a removable media from the kicker's media applet. The media:/xxx address get's replaced by the URL. :-)
But when you open a remote media from the sidebar of the konqueror it does not work. The location bar still shows the media:/xxx address and the terminal emulator will open in the home directory.:-(

Comment 22 Ruben Jenster 2005-05-21 15:21:02 UTC
It also doesn't work if you enter a media:/xxx URL into the location bar manually. Or open the konqueror from a terminal with a media URL.
'konqueror media:/sda1'

And it seems that the kio_media_mounthelper doesn't work anymore because of this mod.

Error - kio_media_mounthelper
file:///media/Backup can not be found.