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

List:       kde-core-devel
Subject:    patch: create non existent directories
From:       Felix Berger <bflat1 () gmx ! net>
Date:       2004-12-30 0:20:13
Message-ID: 200412300120.13431.bflat1 () gmx ! net
[Download RAW message or body]

Hi,

the applied patch is basically copy-paste from konq_diroperations.cc.

It enables KDiroperator::mkdir() and KDirSelectDialog::slotMkdir() to suggest 
a non existent folder name for local files.

The only thing I replaced in the konq_diroperations code was:

-          if (access(QFile::encodeName(url.path()), F_OK) == -1)
+          if (!KIO::NetAccess::exists( url, false, 0 ))

I didn't want to include <unistd.h>, I don't know if it's ok to depend on it 
there.

I don't really like the code duplication, at least KFileDialog and 
KDirSelectDialog could/should share some code there. What do you think?

Felix Berger

-- 
Use Debian GNU/Linux!
http://www.felix.beldesign.de/

["create_non_existent_folder.patch" (text/x-diff)]

? create_non_existant_folder.patch
? kssl/stamp-h4
Index: kfile/kdiroperator.cpp
===================================================================
RCS file: /home/kde/kdelibs/kio/kfile/kdiroperator.cpp,v
retrieving revision 1.195
diff -u -b -B -d -w -U5 -r1.195 kdiroperator.cpp
--- kfile/kdiroperator.cpp	10 Sep 2004 19:46:25 -0000	1.195
+++ kfile/kdiroperator.cpp	30 Dec 2004 00:03:41 -0000
@@ -380,14 +380,34 @@
 }
 
 void KDirOperator::mkdir()
 {
     bool ok;
-    QString where = url().prettyURL( +1, KURL::StripFileProtocol );
+    KURL parent( url() );
+    QString where = parent.prettyURL( +1, KURL::StripFileProtocol );
+
+    QString name = i18n( "New Folder" );
+    if (parent.isLocalFile())
+    {
+       QString base = name;
+       int n = 2;
+       while(true)
+       {
+          KURL url( parent );
+          url.addPath( name );
+
+          if (!KIO::NetAccess::exists( url, false, 0 ))
+             break;
+
+          name = base + QString("_%1").arg(n++);
+       }
+    }
+
+
     QString dir = KInputDialog::getText( i18n( "New Folder" ),
                                          i18n( "Create new folder in:\n%1" ).arg( where ),
-                                         i18n("New Folder"), &ok, this);
+                                         name, &ok, this);
     if (ok)
       mkdir( KIO::encodeFileName( dir ), true );
 }
 
 bool KDirOperator::mkdir( const QString& directory, bool enterDirectory )
Index: kfile/kdirselectdialog.cpp
===================================================================
RCS file: /home/kde/kdelibs/kio/kfile/kdirselectdialog.cpp,v
retrieving revision 1.23
diff -u -b -B -d -w -U5 -r1.23 kdirselectdialog.cpp
--- kfile/kdirselectdialog.cpp	18 Sep 2004 09:12:51 -0000	1.23
+++ kfile/kdirselectdialog.cpp	30 Dec 2004 00:03:42 -0000
@@ -392,21 +392,40 @@
 }
 
 void KDirSelectDialog::slotMkdir()
 {
     bool ok;
-    QString where = url().prettyURL( +1, KURL::StripFileProtocol );
+    KURL folderurl ( url() );
+    QString where = folderurl.prettyURL( +1, KURL::StripFileProtocol );
+
+    QString name = i18n( "New Folder" );
+    if (folderurl.isLocalFile())
+    {
+       QString base = name;
+       int n = 2;
+       while(true)
+       {
+          KURL url( folderurl );
+          url.addPath( name );
+
+          if (!KIO::NetAccess::exists( url, false, 0 ))
+             break;
+
+          name = base + QString("_%1").arg(n++);
+       }
+    }
+
+
     QString directory = KIO::encodeFileName( KInputDialog::getText( i18n( "New Folder" ),
                                          i18n( "Create new folder in:\n%1" ).arg( where ),
-                                         i18n("New Folder"), &ok, this));
+                                         name, &ok, this));
     if (!ok)
       return;
       
     bool selectDirectory = true;
     bool writeOk = false;
     bool exists = false;
-    KURL folderurl( url() );
 
     QStringList dirs = QStringList::split( QDir::separator(), directory );
     QStringList::ConstIterator it = dirs.begin();
 
     for ( ; it != dirs.end(); ++it )


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

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