[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kfm-devel
Subject:    Short URL support for KFM & Quick Mini Command Box
From:       Dawit Alemayehu <adawit () earthlink ! net>
Date:       1999-02-28 19:33:00
[Download RAW message or body]

Hello,

I have attached a patch that adds "short URL" support to KFM and minicli.  With
this enhancement the follwoing things are supported in kfm as well as the
minicli ( CTRL-F2 ) command box:

1.) Ability to type in short url's such as "slashdot.org" etc
2.) Ability to use the short cut to your home directory, for example
    entering ~/.bashrc would open the file with the default app ( in most
    people's case kedit )

Please test it and send feedback for improvement, fixes, flames or otherwise.

Thanks,
Dawit A.
["kfm-patch-990228.diff" (text/x-c++)]

--- /mnt/ext2/usr/local/src/kdebase/kfm/kfmgui.cpp	Sat Feb 27 14:32:02 1999
+++ kdebase/kfm/kfmgui.cpp	Sun Feb 28 13:23:48 1999
@@ -738,27 +749,48 @@
         {
 	  QString tmp( QDir::homeDirPath().data() );
 	  tmp += toolbarURL->getLinedText( TOOLBAR_URL_ID ) + 1;
-	  KURL u( tmp );
-	  url = u.url().data();
+            url = tmp.prepend("file:/").data();
 	}
-	// Does url begin with www? (sven)
+        //Valid URL?
+        // Do nothing if URL, for our purposes here, is VALID. (Dawit A.)
+        else if ( url.find("://") >= 0 || url.find("file:/") == 0 ||
+	              url.find ("news:") == 0 || url.find ("mailto:") == 0 ) ;
+        /*
+        // No protocol. Does url begin with www? (sven)
 	else if (url.find("www") == 0)
-	  url.prepend("http://");
+	      url.prepend("http://");  // Unecessary since we bind "http://" as \
default protocol. +        */
 
-	// Does url begin with "ftp."?  (sven)
+    	// No protocol. Does url begin with "ftp."?  (sven)
 	else if (url.find("ftp.") == 0)
 	  url.prepend("ftp://");
 
+        /*
+           When all else fails, check if the entered file/dir exists on \
current +           directory the local host. If it does not attach \
"http://" as a default +           protocol.  This allows users to type \
short URL addresses without the +           protocol portion being \
explicitly specified, Ex. slashdot.org. (Dawit A) +        */
+        else
+        {
+            KURL path ( getURL() );
+            QDir::setCurrent ( path.directory () );
+            QFileInfo f ( QDir::currentDirPath().append( "/" ).append( url \
).data() ); +            debug ( f.filePath() );
+        	if ( f.exists() )
+                url = f.filePath();
+            else
+                url = url.prepend ("http://");
+        }
+
 	KURL u( url.data() );
 	if ( u.isMalformed() )
 	{
 	    QString tmp;
 	    tmp << klocale->translate("Malformed URL\n") << \
                toolbarURL->getLinedText( TOOLBAR_URL_ID );
-	    QMessageBox::critical( (QWidget*)0L, klocale->translate( "KFM Error" \
                ),
-				   tmp );
+	        QMessageBox::critical( (QWidget*)0L, klocale->translate( "KFM \
Error" ), tmp );  return;
 	}
-	
 	view->openURL( url.data() );             
         //  update tree view Sep 5 rjakob
         if (url.left(5)=="file:")

--- /mnt/ext2/usr/local/src/kdebase/kwm/minicli.C	Sun Feb 28 12:44:36 1999
+++ kdebase/kwm/minicli.C	Sun Feb 28 13:48:16 1999
@@ -2,6 +2,7 @@
 // Copyright (C) 1997 Matthias Ettrich
 
 #include <qmsgbox.h>
+#include <qdir.h>
 #include <qframe.h>
 #include <qwindefs.h>
 #include <stdlib.h>
@@ -27,19 +28,64 @@
 QList <char> *history = 0;
 QListIterator <char> *it;
 
+/*
+   Function determines whether what the user entered in the minicli
+   box is executable or not. This code is eniterly based on the C
+   version of the 'which' command in csh/bash. (Dawit A.)
+*/
+
+bool isCmdExecuteable ( const char *name )
+{
+	QString test;
+    char *path = getenv( "PATH" );
+	char *pc = path;
+	bool found = false;
+
+	while ( *pc != '\0' && found == false )
+	{
+		int len = 0;
+		while ( *pc != ':' && *pc != '\0' )
+		{
+			len++;
+			pc++;
+		}
+		char save = *pc;
+		*pc = '\0';
+		test.sprintf( "%s/%s", pc-len, name);
+		*pc = save;
+		if (*pc) { pc++; }
+		found = ( access(test.data(), 01) == 0 );  /* is it executable ? */
+	}
+    if (found) debug ("%s : %s", test.data(), "is executeable" );
+    else debug ("%s : %s", test.data(), "is not executeable" );
+    return (found) ? true : false;
+}
+/*
+  Check for the existance of a local file/directory.
+  This function does not determine if a command can
+  be executed or not. (Dawit A.)
+*/
+bool isLocalResource ( const char * res )
+{
+   struct stat buff;
+   return ( stat( res, &buff ) == 0 && ( S_ISREG( buff.st_mode ) ||
+            S_ISDIR( buff.st_mode ) ) ) ? true :false;
+}
+
 void execute( const char* cmd){
   QString tmp;
 
   // Torben
   // WWW Adress ?
-  if ( strncmp( cmd, "www.", 4 ) == 0 ) {
-      tmp = "kfmclient openURL http://";
+/*  if ( strncmp( cmd, "www.", 4 ) == 0 ) {
+      tmp = "kfmclient exec http://";
       tmp += cmd;
       cmd = tmp.data();
-  }
+  } Not necessary since we bind "http://" by default (Dawit A.) */
+
   // FTP Adress ?
-  else if ( strncmp( cmd, "ftp.", 4 ) == 0 ) {
-      tmp = "kfmclient openURL ftp://";
+  if ( strncmp( cmd, "ftp.", 4 ) == 0 ) {
+      tmp = "kfmclient exec ftp://";
       tmp += cmd;
       cmd = tmp.data();
   }
@@ -60,30 +106,45 @@
   // Looks like an URL ?
   else if ( strstr( cmd, "://" ) != 0L )
   {
-      tmp = "kfmclient openURL ";
+      tmp = "kfmclient exec ";
       tmp += cmd;
       cmd = tmp.data();
   }
   // Usual file or directory
   else
   {
-      struct stat buff;
       const char *p = cmd;
       if ( strncmp( p, "file:", 5 ) == 0 )
-         p = p + 5;
-
+         p += 5;
+      // Home directory?
+      if ( *p == '~' )
+      {
+           tmp = QDir::homeDirPath();
+           tmp += (p + 1); // get rid off "~"
+           if ( isLocalResource ( tmp.data() ) )
+                cmd = tmp.prepend( "kfmclient exec file:" ).data();
+      }
       // An absolute path ?
-      if ( ( *p == '/') &&
-          // Just a document ?
-           ( stat( p, &buff ) == 0 && ( S_ISREG( buff.st_mode ) || \
S_ISDIR( buff.st_mode ) ) ) ) +      else if ( ( *p == '/') && \
isLocalResource ( p ) )  {
     	  // Tell KFM to open the document
-	     tmp = "kfmclient openURL ";
+	     tmp = "kfmclient exec ";
+    	 tmp += cmd;
+	     cmd = tmp.data();
+      }
+      /* Does not begin with '/' or '.', contains no spaces,
+         does not have a protocol specified and is not locally
+         executable. (Dawit A.) */
+      else if ( (*p != '/') && (*p != '.') && strchr ( p, ' ') == 0L  &&
+                strstr ( cmd, ":/" ) == 0L && !isCmdExecuteable ( p ) )
+      {
+          // Tell KFM to open the document by attaching
+          // "http://" as default protocol  (Dawit A.)
+          tmp = "kfmclient exec http://";
     	 tmp += cmd;
 	     cmd = tmp.data();
       }
   }
-
   KShellProcess proc;
   proc << cmd;
   proc.start(KShellProcess::DontCare);
--- /mnt/ext2/usr/local/src/kdebase/kwm/minicli.h	Sun Feb 28 12:47:45 1999
+++ kdebase/kwm/minicli.h	Fri Feb 26 18:55:18 1999
@@ -3,12 +3,17 @@
 //
 // Torben added command completion
 // 09.11.97
+//
+// Dawit added short URL support
+// 02.26.99
 
 #include <qlined.h>
 #include <qlabel.h>
 #include <kURLcompletion.h>
 
-void execute(const char* cmd);
+void execute( const char* );
+bool isCmdExecuteable ( const char* );
+bool isLocalResource ( const char* );
 
 class Minicli : public QFrame{
   Q_OBJECT



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic