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

List:       kde-devel
Subject:    [PATCH] kget , Expert Mode file save
From:       "seamus seamus" <broseamus () gmail ! com>
Date:       2006-03-29 0:37:08
Message-ID: 48e5b02c0603281637u50b6afb3m5d46ca1838e45d9c () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


The attached patch applies to:
    kget/kmainwidget.cpp
    kget/kmainwidget.h
    kget/transferlist.cpp
    kget/transferlist.h

When in Expert mode and trying to download a file that can not be saved
because
of another file with the same name, give the file a new name that does not
exist in the file system.

For example, the file foo.goo exists and you try to download another file
named foo.goo, the file
will be given the new name foo.1.goo

Regards,
Seamus

[Attachment #5 (text/html)]

The attached patch applies to:<br>&nbsp;&nbsp;&nbsp; \
kget/kmainwidget.cpp<br>&nbsp;&nbsp;&nbsp; kget/kmainwidget.h<br>&nbsp;&nbsp;&nbsp; \
kget/transferlist.cpp<br>&nbsp;&nbsp;&nbsp; kget/transferlist.h<br><br>When in Expert \
mode and trying to download a file that can not be saved because <br>of another file \
with the same name, give the file a new name that does not exist in the file \
system.<br><br>For example, the file foo.goo exists and you try to download another \
file named foo.goo, the file<br>will be given the new name  \
foo.1.goo<br><br>Regards,<br>Seamus<br><br>


["patch.diff" (text/plain)]

Index: kmainwidget.cpp
===================================================================
--- kmainwidget.cpp	(revision 523670)
+++ kmainwidget.cpp	(working copy)
@@ -1112,9 +1112,21 @@
             }
 
             //check if destination already exists
-            if(KIO::NetAccess::exists(destURL, false, this))
+            if(exists(destURL))
             {
-                if (KMessageBox::warningYesNo(this,i18n("Destination file \
\n%1\nalready exists.\nDo you want to overwrite it?").arg( destURL.prettyURL()), \
QString::null, i18n("Overwrite"), i18n("Do Not Overwrite") ) +				if(b_expertMode)
+				{
+					QString fileName = destURL.fileName();
+					fileName = fileName.left(fileName.find('.') + 1);
+					QString fileExt = destURL.fileName();
+					fileExt = fileExt.right(fileExt.length() - fileName.length() + 1);
+					int c=0;
+					do{
+						destURL.setFileName(fileName + QString::number(++c) + fileExt);
+					}while(exists(destURL));
+					bDestisMalformed=false;
+				}
+                else if (KMessageBox::warningYesNo(this,i18n("Destination file \
\n%1\nalready exists.\nDo you want to overwrite it?").arg( destURL.prettyURL()), \
QString::null, i18n("Overwrite"), i18n("Do Not Overwrite") )  == KMessageBox::Yes)
                 {
                     bDestisMalformed=false;
@@ -1155,6 +1167,12 @@
 #endif
 }
 
+bool KMainWidget::exists(const KURL& destURL)
+{
+	return(	KIO::NetAccess::exists(destURL, false, this) ||
+			myTransferList->findByDest(destURL) != 0L );
+}
+	
 
 void KMainWidget::addTransfers( const KURL::List& src, const QString& destDir )
 {
Index: transferlist.cpp
===================================================================
--- transferlist.cpp	(revision 523670)
+++ transferlist.cpp	(working copy)
@@ -224,7 +224,19 @@
     return 0L;
 }
 
+Transfer * TransferList::findByDest(const KURL& _dest)
+{
+    TransferIterator it(this);
 
+    for (; it.current(); ++it) {
+        if (it.current()->getDest() == _dest) {
+            return it.current();
+        }
+    }
+
+    return 0L;
+}
+
 void TransferList::readTransfers(const KURL& file)
 {
     QString tmpFile;
Index: transferlist.h
===================================================================
--- transferlist.h	(revision 523670)
+++ transferlist.h	(working copy)
@@ -76,6 +76,7 @@
     }
     bool updateStatus(int counter);
     Transfer * find(const KURL& _src);
+	Transfer * findByDest(const KURL& _dest);
     bool areTransfersQueuedOrScheduled();
 
     void readTransfers(const KURL& file);
Index: kmainwidget.h
===================================================================
--- kmainwidget.h	(revision 523670)
+++ kmainwidget.h	(working copy)
@@ -194,6 +194,7 @@
 private:
     QString getSaveDirectoryFor( const QString& filename ) const;
     bool sanityChecksSuccessful( const KURL& url );
+	bool exists(const KURL& destURL);
 
     TransferList * myTransferList;
     KHelpMenu *menuHelp;



>> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<


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

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