From kde-devel Wed Mar 29 00:37:08 2006 From: "seamus seamus" Date: Wed, 29 Mar 2006 00:37:08 +0000 To: kde-devel Subject: [PATCH] kget , Expert Mode file save Message-Id: <48e5b02c0603281637u50b6afb3m5d46ca1838e45d9c () mail ! gmail ! com> X-MARC-Message: https://marc.info/?l=kde-devel&m=114361705931363 MIME-Version: 1 Content-Type: multipart/mixed; boundary="------=_Part_1178_19156495.1143592628345" ------=_Part_1178_19156495.1143592628345 Content-Type: multipart/alternative; boundary="----=_Part_1179_8453119.1143592628345" ------=_Part_1179_8453119.1143592628345 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline 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 ------=_Part_1179_8453119.1143592628345 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline The attached patch applies to:
    kget/kmainwidget.cpp    kget/kmainwidget.h
    kget/transfer= list.cpp
    kget/transferlist.h

When in Expert mo= de 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 a= nd you try to download another file named foo.goo, the file
will be give= n the new name=20 foo.1.goo

Regards,
Seamus

------=_Part_1179_8453119.1143592628345-- ------=_Part_1178_19156495.1143592628345 Content-Type: text/plain; name=patch.diff; charset=us-ascii Content-Transfer-Encoding: 7bit X-Attachment-Id: f_elcwotu0 Content-Disposition: attachment; filename="patch.diff" 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; ------=_Part_1178_19156495.1143592628345 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline >> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe << ------=_Part_1178_19156495.1143592628345--