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

List:       kde-core-devel
Subject:    Re: /tmp/kde-$USER/ offenders
From:       David Faure <david () mandrakesoft ! com>
Date:       2002-12-11 21:25:18
[Download RAW message or body]

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Wednesday 11 December 2002 17:18, David Faure wrote:
> On Wednesday 11 December 2002 16:42, George Staikos wrote:
> > 		konquerorki9Vza.html (from HTML source that was viewed)
> 
> Viewing HTML source never unlinks the ktempfile indeed.
> One solution I can think of, would be to use kfmexec (maybe it needs
> to be extended, because it currently downloads and creates the tempfile
> itself, whereas in the khtml case the tempfile is created by khtml).

Cool, it also works for local temp files, out of the box.
Patch attached.

- -- 
David FAURE, david@mandrakesoft.com, faure@kde.org
http://people.mandrakesoft.com/~david/
Contributing to: http://www.konqueror.org/, http://www.koffice.org/
Get the latest KOffice - http://download.kde.org/stable/koffice-1.2/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (GNU/Linux)

iD8DBQE9960+72KcVAmwbhARAoKDAJ9PmXB76iCokzMfDDE/RTJls6jDXgCfVT2t
rYJpt5z86jIy3srN3BRfSPE=
=qnks
-----END PGP SIGNATURE-----

["khtml_part_tempfile.diff" (text/x-diff)]

Index: khtml_part.cpp
===================================================================
RCS file: /home/kde/kdelibs/khtml/khtml_part.cpp,v
retrieving revision 1.779
diff -u -p -b -r1.779 khtml_part.cpp
--- khtml_part.cpp	11 Dec 2002 03:47:11 -0000	1.779
+++ khtml_part.cpp	11 Dec 2002 21:23:03 -0000
@@ -2695,6 +2695,7 @@ void KHTMLPart::urlSelected( const QStri
 void KHTMLPart::slotViewDocumentSource()
 {
   KURL url(m_url);
+  bool isTempFile = false;
   if (!(url.isLocalFile()) && KHTMLPageCache::self()->isValid(d->m_cacheId))
   {
      KTempFile sourceFile(QString::null, QString::fromLatin1(".html"));
@@ -2703,11 +2704,11 @@ void KHTMLPart::slotViewDocumentSource()
         KHTMLPageCache::self()->saveData(d->m_cacheId, sourceFile.dataStream());
         url = KURL();
         url.setPath(sourceFile.name());
+        isTempFile = true;
      }
   }
 
-  //  emit d->m_extension->openURLRequest( m_url, KParts::URLArgs( false, 0, 0, \
                QString::fromLatin1( "text/plain" ) ) );
-  (void) KRun::runURL( url, QString::fromLatin1("text/plain") );
+  (void) KRun::runURL( url, QString::fromLatin1("text/plain"), isTempFile );
 }
 
 void KHTMLPart::slotViewPageInfo()
@@ -2752,6 +2753,7 @@ void KHTMLPart::slotViewFrameSource()
     return;
 
   KURL url = frame->url();
+  bool isTempFile = false;
   if (!(url.isLocalFile()) && frame->inherits("KHTMLPart"))
   {
        long cacheId = static_cast<KHTMLPart *>(frame)->d->m_cacheId;
@@ -2764,11 +2766,12 @@ void KHTMLPart::slotViewFrameSource()
                KHTMLPageCache::self()->saveData(cacheId, sourceFile.dataStream());
                url = KURL();
                url.setPath(sourceFile.name());
+               isTempFile = true;
            }
      }
   }
 
-  (void) KRun::runURL( url, QString::fromLatin1("text/plain") );
+  (void) KRun::runURL( url, QString::fromLatin1("text/plain"), isTempFile );
 }
 
 KURL KHTMLPart::backgroundURL() const


["krun.diff" (text/x-diff)]

Index: krun.h
===================================================================
RCS file: /home/kde/kdelibs/kio/kio/krun.h,v
retrieving revision 1.80
diff -u -p -r1.80 krun.h
--- krun.h	27 Nov 2002 20:53:33 -0000	1.80
+++ krun.h	11 Dec 2002 21:23:28 -0000
@@ -48,7 +48,7 @@ namespace KIO {
  * If the mimetype is known, or if you even know the service (application) to
  * use for this file, use one of the static methods.
  *
- * By default KRun uses auto deletion. It causes the KRun instance to delete 
+ * By default KRun uses auto deletion. It causes the KRun instance to delete
  * itself when the it finished its task. If you allocate the KRun
  * object on the stack you must disable auto deletion, otherwise it will crash.
  *
@@ -113,7 +113,7 @@ public:
   bool hasFinished() const { return m_bFinished; }
 
   /**
-   * Checks whether auto delete is activated. 
+   * Checks whether auto delete is activated.
    * Auto-deletion causes the KRun instance to delete itself
    * when the it finished its task.
    * By default auto deletion is on.
@@ -142,13 +142,17 @@ public:
   void setPreferredService( const QString& desktopEntryName );
 
   /**
-   * Open a list of URLs with a certain service.
+   * Open a list of URLs with a certain service (application).
    *
    * @param _service the service to run
    * @param _urls the list of URLs, can be empty (app launched
    *        without argument)
+   * @param tempFiles if true and _urls are local files, they will be deleted
+   *        when the application exits.
    * @return the process id, or 0 on error
    */
+  static pid_t run( const KService& _service, const KURL::List& _urls, bool \
tempFiles ); +  // BIC merge with method above, using tempFiles=false
   static pid_t run( const KService& _service, const KURL::List& _urls );
 
   /**
@@ -177,8 +181,12 @@ public:
    * the mime type and call @ref run() afterwards.
    * @param _url the URL to open
    * @param _mimetype the mime type of the resource
+   * @param tempFile if true and _url is a local file, it will be deleted
+   *        when the launched application exits.
    * @return the process id, or 0 on error
    */
+  static pid_t runURL( const KURL& _url, const QString& _mimetype, bool tempFile );
+  // BIC merge with method above, using tempFiles=false
   static pid_t runURL( const KURL& _url, const QString& _mimetype );
 
   /**
@@ -213,8 +221,12 @@ public:
   /**
    * Display the Open-With dialog for those URLs, and run the chosen application.
    * @param lst the list of applications to run
+   * @param tempFiles if true and lst are local files, they will be deleted
+   *        when the application exits.
    * @return false if the dialog was canceled
    */
+  static bool displayOpenWithDialog( const KURL::List& lst, bool tempFiles );
+  // BIC merge with method above, using tempFiles=false
   static bool displayOpenWithDialog( const KURL::List& lst );
 
   /**
@@ -233,8 +245,12 @@ public:
    *        call.
    *        If the arguments are intended for an exec() kind of call and
    *        the Exec line contains shell commands then "/bin/sh -c" is added.
+   * @param tempFiles if true and _urls are local files, they will be deleted
+   *        when the application exits.
    * @return a list of arguments suitable for either system() or exec().
    */
+  static QStringList processDesktopExec(const KService &_service, const KURL::List \
&_urls, bool has_shell, bool tempFiles); +  // BIC merge with method above, using \
tempFiles=false  static QStringList processDesktopExec(const KService &_service, \
const KURL::List &_urls, bool has_shell);  
   /**
Index: krun.cpp
===================================================================
RCS file: /home/kde/kdelibs/kio/kio/krun.cpp,v
retrieving revision 1.215
diff -u -p -r1.215 krun.cpp
--- krun.cpp	18 Nov 2002 17:02:20 -0000	1.215
+++ krun.cpp	11 Dec 2002 21:23:29 -0000
@@ -59,9 +59,14 @@ public:
     QString m_preferredService;
 };
 
-// This is called by foundMimeType, since it knows the mimetype of the URL
 pid_t KRun::runURL( const KURL& u, const QString& _mimetype )
 {
+    return runURL( u, _mimetype, false );
+}
+
+// This is called by foundMimeType, since it knows the mimetype of the URL
+pid_t KRun::runURL( const KURL& u, const QString& _mimetype, bool tempFile )
+{
 
   if ( _mimetype == "inode/directory-locked" )
   {
@@ -88,6 +93,7 @@ pid_t KRun::runURL( const KURL& u, const
       QString path = u.path();
       shellQuote( path );
       return (KRun::runCommand(path)); // just execute the url as a command
+      // ## TODO implement deleting the file if tempFile==true
     }
   }
 
@@ -103,23 +109,28 @@ pid_t KRun::runURL( const KURL& u, const
     // Open-with dialog
     // TODO : pass the mimetype as a parameter, to show it (comment field) in the \
                dialog !
     // Hmm, in fact KOpenWithDlg::setServiceType already guesses the mimetype from \
                the first URL of the list...
-    return displayOpenWithDialog( lst );
+    return displayOpenWithDialog( lst, tempFile );
   }
 
-  return KRun::run( *offer, lst );
+  return KRun::run( *offer, lst, tempFile );
 }
 
 bool KRun::displayOpenWithDialog( const KURL::List& lst )
 {
+    return displayOpenWithDialog( lst, false );
+}
+
+bool KRun::displayOpenWithDialog( const KURL::List& lst, bool tempFiles )
+{
     KOpenWithDlg l( lst, i18n("Open with:"), QString::null, 0L );
     if ( l.exec() )
     {
       KService::Ptr service = l.service();
       if ( !!service )
-        return KRun::run( *service, lst );
+        return KRun::run( *service, lst, tempFiles );
 
       kdDebug(250) << "No service set, running " << l.text() << endl;
-      return KRun::run( l.text(), lst );
+      return KRun::run( l.text(), lst ); // TODO handle tempFiles
     }
     return false;
 }
@@ -398,7 +409,12 @@ static void substitute(QStringList &_lis
   }
 }
 
-QStringList KRun::processDesktopExec(const KService &_service, const KURL::List& \
_urls, bool has_shell) +// BIC: merge with method below
+QStringList KRun::processDesktopExec(const KService &_service, const KURL::List& \
_urls, bool has_shell) { +    return processDesktopExec( _service, _urls, has_shell, \
false ); +}
+
+QStringList KRun::processDesktopExec(const KService &_service, const KURL::List& \
_urls, bool has_shell, bool tempFiles)  {
   QString exec = _service.exec();
   QString user = _service.username();
@@ -434,7 +450,7 @@ QStringList KRun::processDesktopExec(con
     if ( !(*it).isLocalFile() )
       b_local_files = false;
 
-  if ( b_local_app && !b_local_files )
+  if ( (b_local_app && !b_local_files) || tempFiles )
   {
      // We need to run the app through kfmexec
      QStringList result = breakup(exec);
@@ -481,7 +497,7 @@ QStringList KRun::processDesktopExec(con
 
   KConfigGroupSaver gs(KGlobal::config(), "General");
   QString terminal = KGlobal::config()->readEntry("TerminalApplication", "konsole");
-  
+
   if (terminal == "konsole")
     terminal += " -caption=%c %i %m";
 
@@ -604,10 +620,10 @@ static pid_t runCommandInternal( KProces
 #endif
 }
 
-static pid_t runTempService( const KService& _service, const KURL::List& _urls )
+static pid_t runTempService( const KService& _service, const KURL::List& _urls, bool \
tempFiles )  {
   if (!_urls.isEmpty()) {
-    kdDebug(7010) << "First url " << _urls.first().url() << endl;
+    kdDebug(7010) << "runTempService: first url " << _urls.first().url() << endl;
   }
 
   QStringList args;
@@ -623,15 +639,15 @@ static pid_t runTempService( const KServ
       {
          KURL::List singleUrl;
          singleUrl.append(*it);
-         runTempService( _service, singleUrl );
+         runTempService( _service, singleUrl, tempFiles );
       }
       KURL::List singleUrl;
       singleUrl.append(_urls.first());
-      args = KRun::processDesktopExec(_service, singleUrl, false);
+      args = KRun::processDesktopExec(_service, singleUrl, false, tempFiles);
   }
   else
   {
-      args = KRun::processDesktopExec(_service, _urls, false);
+      args = KRun::processDesktopExec(_service, _urls, false, tempFiles);
   }
 
   KProcess * proc = new KProcess;
@@ -644,24 +660,33 @@ static pid_t runTempService( const KServ
   return runCommandInternal( proc, _service.exec(), _service.name(), _service.icon() \
);  }
 
+// BIC merge with method below
 pid_t KRun::run( const KService& _service, const KURL::List& _urls )
 {
+    return run( _service, _urls, false );
+}
+
+pid_t KRun::run( const KService& _service, const KURL::List& _urls, bool tempFiles )
+{
   if (!KDesktopFile::isAuthorizedDesktopFile( _service.desktopEntryPath()))
   {
      KMessageBox::sorry(0, i18n("You are not authorized to execute this service."));
      return 0;
   }
 
-  // Remember we opened those urls, for the "recent documents" menu in kicker
-  KURL::List::ConstIterator it = _urls.begin();
-  for(; it != _urls.end(); ++it) {
-     //kdDebug(7010) << "KRecentDocument::adding " << (*it).url() << endl;
-     KRecentDocument::add( *it, _service.desktopEntryName() );
+  if ( !tempFiles )
+  {
+      // Remember we opened those urls, for the "recent documents" menu in kicker
+      KURL::List::ConstIterator it = _urls.begin();
+      for(; it != _urls.end(); ++it) {
+          //kdDebug(7010) << "KRecentDocument::adding " << (*it).url() << endl;
+          KRecentDocument::add( *it, _service.desktopEntryName() );
+      }
   }
 
-  if (_service.desktopEntryPath().isEmpty())
+  if ( tempFiles || _service.desktopEntryPath().isEmpty())
   {
-     return runTempService(_service, _urls);
+     return runTempService(_service, _urls, tempFiles);
   }
 
   kdDebug(7010) << "KRun::run " << _service.desktopEntryPath() << endl;



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

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