kget<-->konqueror integration

pch at valleeurope.net pch at valleeurope.net
Wed Jun 19 13:31:06 BST 2002


On Wed, 19 Jun 2002, Simon Hausmann wrote:

> On Tue, Jun 18, 2002 at 09:29:20PM +0200, Patrick wrote:
> [...] 
> 
> Three minor thoughts about your patch:
> 
> * I think in the khtml_ext.cpp change the KConfig object is leaked
Yes you are right
> 
> * You might probably want to open konquerorrc read-only, so passing 
>   'true' instead of 'false' as second argument to the
>   KConfig constructor
If i cannot find the executable i want to disable the integration
this is why i open with the write flag.
> 
> * How about reading a 'DownloadManager' field from the config file,
>   containing the name of the program (with %f, %u, etc. in the
>   cmdline) which handles the download. If the field is non-empty
>   then that one is to be used. That way there would be no need to
>   hardcode 'kget' into the sources.
> 
Why not seams better than my boolean

Patrick

-------------- next part --------------
Index: khtml/khtml_ext.cpp
===================================================================
RCS file: /home/kde/kdelibs/khtml/khtml_ext.cpp,v
retrieving revision 1.48
diff -u -u -3 -p -r1.48 khtml_ext.cpp
--- khtml/khtml_ext.cpp	2002/04/23 12:53:19	1.48
+++ khtml/khtml_ext.cpp	2002/06/19 12:36:32
@@ -21,6 +21,9 @@
 #include <kurldrag.h>
 #include <kstringhandler.h>
 #include <kapplication.h>
+#include <kmessagebox.h>   
+#include <kstandarddirs.h> 
+#include <krun.h>          
 
 #include "dom/dom_element.h"
 #include "misc/htmltags.h"
@@ -475,11 +478,41 @@ void KHTMLPopupGUIClient::saveURL( const
         }
         if(!saved)
         {
-            KIO::Job *job = KIO::copy( url, destURL );
-            job->setMetaData(metadata);
-            job->addMetaData("MaxCacheSize", "0"); // Don't store in http cache.
-            job->setAutoErrorHandlingEnabled( true );
-        }
+            // DownloadManager <-> konqueror integration
+            // find if the integration is enabled 
+            //the empty key  means no integration
+            KConfig *cfg = new KConfig("konquerorrc", false, false);
+            cfg->setGroup("HTML Settings");
+            QString downloadManger=cfg->readEntry("DownloadManager");
+            if (!downloadManger.isEmpty())
+            {
+                //then find the download manager location
+                kdDebug(1000) << "Using: "<<downloadManger <<" as Download Manager" <<endl;
+                QString cmd=KStandardDirs::findExe(downloadManger);
+                if (cmd.isEmpty())
+                {
+                    QString errMsg=i18n("Sorry, I can't find  the Download Manager (%1) in your $PATH ").arg(downloadManger);
+                    QString errMsgEx= i18n("Try to reinstall it  \n\nThe integration with konqueror will be disabled!");
+                    KMessageBox::detailedSorry(0,errMsg,errMsgEx);
+                    cfg->writeEntry("DownloadManager",QString::null);
+                    cfg->sync ();
+                }
+                else
+                {
+                    cmd+=" " + url.url()+" "+destURL.url();
+                    kdDebug(1000) << "Calling command  "<<cmd<<endl;
+                    KRun::runCommand(cmd);
+                }
+            }
+            else
+            {
+                KIO::Job *job = KIO::copy( url, destURL );
+                job->setMetaData(metadata);
+                job->addMetaData("MaxCacheSize", "0"); // Don't store in http cache.
+                job->setAutoErrorHandlingEnabled( true );
+            } 
+            delete cfg;
+        } //end if(!saved)
     }
 }
 
Index: kparts/browserrun.cpp
===================================================================
RCS file: /home/kde/kdelibs/kparts/browserrun.cpp,v
retrieving revision 1.7
diff -u -u -3 -p -r1.7 browserrun.cpp
--- kparts/browserrun.cpp	2002/04/20 12:44:33	1.7
+++ kparts/browserrun.cpp	2002/06/19 12:36:33
@@ -25,7 +25,7 @@
 #include <kuserprofile.h>
 #include <ktempfile.h>
 #include <kdebug.h>
-
+#include <kstandarddirs.h>
 #include <assert.h>
 
 using namespace KParts;
@@ -229,11 +229,39 @@ BrowserRun::AskSaveResult BrowserRun::as
         QString::fromLatin1("askSave")+ mimeType ); // dontAskAgainName
     return choice == KMessageBox::Yes ? Save : ( choice == KMessageBox::No ? Open : Cancel );
 }
-
 // Default implementation, overriden in KHTMLRun
 void BrowserRun::save( const KURL & url, const QString & suggestedFilename )
 {
-    simpleSave( url, suggestedFilename );
+
+    // DownloadManager <-> konqueror integration
+    // find if the integration is enabled
+    //the empty key  means no integration
+    KConfig *cfg = new KConfig("konquerorrc", false, false);
+    cfg->setGroup("HTML Settings");
+    QString downloadManger=cfg->readEntry("DownloadManager");
+    if (!downloadManger.isEmpty())
+    {
+        //then find the download manager location 
+        kdDebug(1000) << "Using: "<<downloadManger <<" as Download Manager" <<endl;
+        QString cmd=KStandardDirs::findExe(downloadManger);
+        if (cmd.isEmpty())
+        {
+            QString errMsg=i18n("Sorry, I can't find  the Download Manager (%1) in your $PATH ").arg(downloadManger);
+            QString errMsgEx= i18n("Try to reinstall it  \n\nThe integration with konqueror will be disabled!");
+            KMessageBox::detailedSorry(0,errMsg,errMsgEx);
+            cfg->writeEntry("DownloadManager",QString::null);
+            cfg->sync ();
+        }
+        else
+        {
+	     cmd+=" " + url.url(); 
+            kdDebug(1000) << "Calling command  "<<cmd<<endl;
+            KRun::runCommand(cmd);
+        }
+    }
+    else
+        simpleSave( url, suggestedFilename );
+    delete cfg;
 }
 
 // static


More information about the kfm-devel mailing list