Fwd: KFileDialog combined keyword/filename suggestion

Jonathan Marten jjm2 at keelhaul.demon.co.uk
Wed Mar 11 07:21:08 GMT 2009


Albert Astals Cid <aacid at kde.org> writes:
> You forgot to attach the patch :D

It's attached to the bug report
(https://bugs.kde.org/show_bug.cgi?id=186230).  Follows here too...

-------------------------------------------------
Index: kfile/kfilewidget.cpp
===================================================================
--- kfile/kfilewidget.cpp	(revision 937775)
+++ kfile/kfilewidget.cpp	(working copy)
@@ -315,6 +315,7 @@
     : QWidget(parent), KAbstractFileWidget(), d(new KFileWidgetPrivate(this))
 {
     KUrl startDir(_startDir);
+    kDebug(kfile_area) << "startDir" << startDir;
     QString filename;
 
     d->okButton = new KPushButton(KStandardGuiItem::ok(), this);
@@ -334,6 +335,12 @@
     opsWidgetLayout->addWidget(d->toolbar);
 
     d->model = new KFilePlacesModel(this);
+
+    // Resolve this now so that a 'kfiledialog:' URL, if specified,
+    // does not get inserted into the urlNavigator history.
+    d->url = getStartUrl( startDir, d->fileClass, filename );
+    startDir = d->url;
+
     d->urlNavigator = new KUrlNavigator(d->model, startDir, d->opsWidget); //d->toolbar);
     d->urlNavigator->setPlacesSelectorVisible(false);
     opsWidgetLayout->addWidget(d->urlNavigator);
@@ -572,15 +579,16 @@
         coll->action("inline preview")->setChecked(pg->isPreviewShown());
     }
 
-    d->url = getStartUrl( startDir, d->fileClass );
-    startDir = d->url;
-
-    KIO::StatJob *statJob = KIO::stat(startDir, KIO::HideProgressInfo);
-    bool res = KIO::NetAccess::synchronousRun(statJob, 0);
-    if (!res || !statJob->statResult().isDir()) {
-        startDir.adjustPath(KUrl::RemoveTrailingSlash);
-        filename = startDir.fileName();
-        startDir.setFileName(QString());
+    bool statRes = false;
+    if ( filename.isEmpty() ) {
+        KIO::StatJob *statJob = KIO::stat(startDir, KIO::HideProgressInfo);
+        statRes = KIO::NetAccess::synchronousRun(statJob, 0);
+        if (!statRes || !statJob->statResult().isDir()) {
+            startDir.adjustPath(KUrl::RemoveTrailingSlash);
+            filename = startDir.fileName();
+            startDir.setFileName(QString());
+        }
+        kDebug(kfile_area) << "statJob found filename" << filename;
     }
 
     d->ops->setUrl(startDir, true);
@@ -589,9 +597,11 @@
         d->placesView->setUrl(startDir);
     }
 
-    // we know it is not a dir, and we could stat it. Set it.
+    // We have a file name either explicitly specified, or have checked that
+    // we could stat it and it is not a directory.  Set it.
     if (!filename.isEmpty()) {
-        if (res) {
+        kDebug(kfile_area) << "selecting filename" << filename;
+        if (statRes) {
             d->setLocationText(filename);
         } else {
             d->locationEdit->lineEdit()->setText(filename);
@@ -737,7 +747,7 @@
     // Make sure that one of the modes was provided
     if (!((mode & KFile::File) || (mode & KFile::Directory) || (mode & KFile::Files))) {
         mode |= KFile::File;
-        kDebug() << "No mode() provided";
+        kDebug(kfile_area) << "No mode() provided";
     }
 
     // if we are on file mode, and the list of provided files/folder is greater than one, inform
@@ -1150,7 +1160,15 @@
     if (!url.isEmpty()) {
         QPixmap mimeTypeIcon = KIconLoader::global()->loadMimeTypeIcon( KMimeType::iconNameForUrl( url ), KIconLoader::Small );
         if (url.hasPath()) {
-            q->setUrl(url.path(), false);
+            if (!url.directory().isEmpty())
+            {
+                KUrl u(url);
+                u.setFileName("");
+                q->setUrl(u, false);
+            }
+            else {
+                q->setUrl(url.path(), false);
+            }
         }
         setDummyHistoryEntry(url.fileName() , mimeTypeIcon );
     } else {
@@ -2446,24 +2464,58 @@
     static_cast<KToggleAction *>(q->actionCollection()->action("toggleBookmarks"))->setChecked( show );
 }
 
-// static
+
+// static, overloaded
 KUrl KFileWidget::getStartUrl( const KUrl& startDir,
-                               QString& recentDirClass )
+                               QString& recentDirClass)
 {
-//     kDebug(kfile_area);
+    QString fileName;					// result discarded
+    return getStartUrl( startDir, recentDirClass, fileName );
+}
 
+
+// static, overloaded
+KUrl KFileWidget::getStartUrl( const KUrl& startDir,
+                               QString& recentDirClass,
+                               QString& fileName)
+{
     recentDirClass.clear();
+    fileName.clear();
     KUrl ret;
 
     bool useDefaultStartDir = startDir.isEmpty();
     if ( !useDefaultStartDir )
     {
-        if (startDir.protocol() == "kfiledialog")
+        if ( startDir.protocol() == "kfiledialog" )
         {
+
+//  The startDir URL with this protocol may be in the format:
+//                                                    directory()   fileName()
+//  1.  kfiledialog:///keyword                           "/"         keyword
+//  2.  kfiledialog:///keyword?global                    "/"         keyword
+//  3.  kfiledialog:///keyword/                          "/"         keyword
+//  4.  kfiledialog:///keyword/?global                   "/"         keyword
+//  5.  kfiledialog:///keyword/filename                /keyword      filename
+//  6.  kfiledialog:///keyword/filename?global         /keyword      filename
+
+            QString keyword;
+            QString urlDir = startDir.directory();
+            QString urlFile = startDir.fileName();
+            if ( urlDir == "/" )			// '1'..'4' above
+            {
+                keyword = urlFile;
+                fileName = QString();
+            }
+            else					// '5' or '6' above
+            {
+                keyword = urlDir.mid( 1 );
+                fileName = urlFile;
+            }
+
             if ( startDir.query() == "?global" )
-              recentDirClass = QString( "::%1" ).arg( startDir.path().mid( 1 ) );
+              recentDirClass = QString( "::%1" ).arg( keyword );
             else
-              recentDirClass = QString( ":%1" ).arg( startDir.path().mid( 1 ) );
+              recentDirClass = QString( ":%1" ).arg( keyword );
 
             ret = KUrl( KRecentDirs::dir(recentDirClass) );
         }
@@ -2494,6 +2546,7 @@
         ret = *lastDirectory;
     }
 
+    kDebug(kfile_area) << "for" << startDir << "ret" << ret << "recentDirClass" << recentDirClass << "fileName" << fileName;
     return ret;
 }
 
Index: kfile/kfilewidget.h
===================================================================
--- kfile/kfilewidget.h	(revision 937775)
+++ kfile/kfilewidget.h	(working copy)
@@ -44,17 +44,29 @@
     /**
       * Constructs a file selector widget.
       *
-      * @param startDir This can either be
-      *         @li The URL of the directory to start in.
-      *         @li A KUrl() to start in the current working
-      *             directory, or the last directory where a file has been
-      *             selected.
-      *         @li An URL starting with 'kfiledialog:///<keyword>' to start in the
-      *             directory last used by a filedialog in the same application that specified
-      *             the same keyword.
-      *         @li An URL starting with 'kfiledialog:///<keyword>?global' to start
-      *             in the directory last used by a filedialog in any application that specified the
-      *             same keyword.
+      * @param startDir This can either be:
+      *         @li An empty URL (KUrl()) to start in the current working directory,
+      *             or the last directory where a file has been selected.
+      *         @li The path or URL of a starting directory.
+      *         @li An initial file name to select, with the starting directory being
+      *             the current working directory or the last directory where a file
+      *             has been selected.
+      *         @li The path or URL of a file, specifying both the starting directory and
+      *             an initially selected file name.
+      *         @li A URL of the form @c kfiledialog:///<keyword> to start in the
+      *             directory last used by a filedialog in the same application that
+      *             specified the same keyword.
+      *         @li A URL of the form @c kfiledialog:///<keyword>/<filename>
+      *             to start in the directory last used by a filedialog in the same
+      *             application that specified the same keyword, and to initially
+      *             select the specified filename.
+      *         @li A URL of the form @c kfiledialog:///<keyword>?global to start
+      *             in the directory last used by a filedialog in any application that
+      *             specified the same keyword.
+      *         @li A URL of the form @c kfiledialog:///<keyword>/<filename>?global
+      *             to start in the directory last used by a filedialog in any
+      *             application that specified the same keyword, and to initially
+      *             select the specified filename.
       *
       * @param parent The parent widget of this widget
       *
@@ -338,17 +350,43 @@
      * This method implements the logic to determine the user's default directory
      * to be listed. E.g. the documents directory, home directory or a recently
      * used directory.
-     * @param startDir A url, to be used. May use the 'kfiledialog:///keyword' and
-     *                 'kfiledialog:///keyword?global' syntax
-     *                 as documented in the KFileDialog() constructor.
-     * @param recentDirClass If the 'kfiledialog:///' syntax is used, recentDirClass
-     *        will contain the string to be used later for KRecentDir::dir()
+     * @param startDir A URL specifying the initial directory, or using the
+     *                 @c kfiledialog:/// syntax to specify a last used
+     *                 directory.  If this URL specifies a file name, it is
+     *                 ignored.  Refer to the KFileWidget::KFileWidget()
+     *                 documentation for the @c kfiledialog:/// URL syntax.
+     * @param recentDirClass If the @c kfiledialog:/// syntax is used, this
+     *        will return the string to be passed to KRecentDirs::dir() and
+     *        KRecentDirs::add().
      * @return The URL that should be listed by default (e.g. by KFileDialog or
      *         KDirSelectDialog).
+     * @see KFileWidget::KFileWidget()
      */
     static KUrl getStartUrl( const KUrl& startDir, QString& recentDirClass );
 
     /**
+     * Similar to getStartUrl(const KUrl& startDir,QString& recentDirClass),
+     * but allows both the recent start directory keyword and a suggested file name
+     * to be returned.
+     * @param startDir A URL specifying the initial directory and/or filename,
+     *                 or using the @c kfiledialog:/// syntax to specify a
+     *                 last used location.
+     *                 Refer to the KFileWidget::KFileWidget()
+     *                 documentation for the @c kfiledialog:/// URL syntax.
+     * @param recentDirClass If the @c kfiledialog:/// syntax is used, this
+     *        will return the string to be passed to KRecentDirs::dir() and
+     *        KRecentDirs::add().
+     * @param fileName The suggested file name, if specified as part of the
+     *        @p StartDir URL.
+     * @return The URL that should be listed by default (e.g. by KFileDialog or
+     *         KDirSelectDialog).
+     *
+     * @see KFileWidget::KFileWidget()
+     * @since 4.3
+     */
+    static KUrl getStartUrl( const KUrl& startDir, QString& recentDirClass, QString& fileName );
+
+    /**
      * @internal
      * Used by KDirSelectDialog to share the dialog's start directory.
      */
Index: kio/kfile/kfiledialog.h
===================================================================
--- kio/kfile/kfiledialog.h	(revision 937775)
+++ kio/kfile/kfiledialog.h	(working copy)
@@ -86,17 +86,11 @@
     /**
       * Constructs a file dialog.
       *
-      * @param startDir This can either be
-      *         @li The URL of the directory to start in.
-      *         @li A KUrl() to start in the current working
-      *             directory, or the last directory where a file has been
-      *             selected.
-      *         @li An URL starting with 'kfiledialog:///<keyword>' to start in the
-      *             directory last used by a filedialog in the same application that specified
-      *             the same keyword.
-      *         @li An URL starting with 'kfiledialog:///<keyword>?global' to start
-      *             in the directory last used by a filedialog in any application that specified the
-      *             same keyword.
+      * @param startDir Specifies the starting directory and/or initially selected
+      *                 file name, or a last used directory and optional file name
+      *                 using the @c kfiledialog:/// syntax.
+      *                 Refer to the KFileWidget documentation for more information
+      *                 on this parameter.
       *
       * @param filter A shell glob or a mime-type-filter that specifies
       *               which files to display.
@@ -109,6 +103,8 @@
       *               display a check box with the caption "Open as read-only".
       *               When creating this widget, you don't need to specify a parent,
       *               since the widget's parent will be set automatically by KFileDialog.
+      *
+      * @see KFileWidget::KFileWidget()
       */
     KFileDialog( const KUrl& startDir, const QString& filter,
                  QWidget *parent, QWidget* widget = 0 );
@@ -334,23 +330,17 @@
      * Note that with
      * this method the user must select an existing filename.
      *
-     * @param startDir This can either be
-     *         @li The URL of the directory to start in.
-     *         @li A KUrl() to start in the current working
-     *             directory, or the last directory where a file has been
-     *             selected.
-     *         @li An URL starting with 'kfiledialog:///<keyword>' to start in the
-     *             directory last used by a filedialog in the same application that specified
-     *             the same keyword.
-     *         @li An URL starting with 'kfiledialog:///<keyword>?global' to start
-     *             in the directory last used by a filedialog in any application that specified the
-     *             same keyword.
+     * @param startDir Starting directory or @c kfiledialog:/// URL.
+     *                 Refer to the KFileWidget documentation for more information
+     *                 on this parameter.
      * @param filter A shell glob or a mime-type-filter that specifies which files to display.
      *    The preferred option is to set a list of mimetype names, see setMimeFilter() for details.
      *    Otherwise you can set the text to be displayed for the each glob, and
      *    provide multiple globs, see setFilter() for details.
      * @param parent The widget the dialog will be centered on initially.
      * @param caption The name of the dialog widget.
+     *
+     * @see KFileWidget::KFileWidget()
      */
     static QString getOpenFileName( const KUrl& startDir= KUrl(),
                                     const QString& filter= QString(),
@@ -375,23 +365,17 @@
      * Note that with
      * this method the user must select an existing filename.
      *
-     * @param startDir This can either be
-     *         @li The URL of the directory to start in.
-     *         @li A KUrl() to start in the current working
-     *             directory, or the last directory where a file has been
-     *             selected.
-     *         @li An URL starting with 'kfiledialog:///<keyword>' to start in the
-     *             directory last used by a filedialog in the same application that specified
-     *             the same keyword.
-     *         @li An URL starting with 'kfiledialog:///<keyword>?global' to start
-     *             in the directory last used by a filedialog in any application that specified the
-     *             same keyword.
+     * @param startDir Starting directory or @c kfiledialog:/// URL.
+     *                 Refer to the KFileWidget documentation for more information
+     *                 on this parameter.
      * @param filter A shell glob or a mime-type-filter that specifies which files to display.
      *    The preferred option is to set a list of mimetype names, see setMimeFilter() for details.
      *    Otherwise you can set the text to be displayed for the each glob, and
      *    provide multiple globs, see setFilter() for details.
      * @param parent The widget the dialog will be centered on initially.
      * @param caption The name of the dialog widget.
+     *
+     * @see KFileWidget::KFileWidget()
      */
     static QStringList getOpenFileNames( const KUrl& startDir= KUrl(),
                                          const QString& filter = QString(),
@@ -407,23 +391,17 @@
      * Note that with
      * this method the user must select an existing URL.
      *
-     * @param startDir This can either be
-     *         @li The URL of the directory to start in.
-     *         @li A KUrl() to start in the current working
-     *             directory, or the last directory where a file has been
-     *             selected.
-     *         @li An URL starting with 'kfiledialog:///<keyword>' to start in the
-     *             directory last used by a filedialog in the same application that specified
-     *             the same keyword.
-     *         @li An URL starting with 'kfiledialog:///<keyword>?global' to start
-     *             in the directory last used by a filedialog in any application that specified the
-     *             same keyword.
+     * @param startDir Starting directory or @c kfiledialog:/// URL.
+     *                 Refer to the KFileWidget documentation for more information
+     *                 on this parameter.
      * @param filter A shell glob or a mime-type-filter that specifies which files to display.
      *    The preferred option is to set a list of mimetype names, see setMimeFilter() for details.
      *    Otherwise you can set the text to be displayed for the each glob, and
      *    provide multiple globs, see setFilter() for details.
      * @param parent The widget the dialog will be centered on initially.
      * @param caption The name of the dialog widget.
+     *
+     * @see KFileWidget::KFileWidget()
      */
     static KUrl getOpenUrl( const KUrl& startDir = KUrl(),
                             const QString& filter = QString(),
@@ -439,23 +417,17 @@
      * Note that with
      * this method the user must select an existing filename.
      *
-     * @param startDir This can either be
-     *         @li The URL of the directory to start in.
-     *         @li A KUrl() to start in the current working
-     *             directory, or the last directory where a file has been
-     *             selected.
-     *         @li An URL starting with 'kfiledialog:///<keyword>' to start in the
-     *             directory last used by a filedialog in the same application that specified
-     *             the same keyword.
-     *         @li An URL starting with 'kfiledialog:///<keyword>?global' to start
-     *             in the directory last used by a filedialog in any application that specified the
-     *             same keyword.
+     * @param startDir Starting directory or @c kfiledialog:/// URL.
+     *                 Refer to the KFileWidget documentation for more information
+     *                 on this parameter.
      * @param filter A shell glob or a mime-type-filter that specifies which files to display.
      *    The preferred option is to set a list of mimetype names, see setMimeFilter() for details.
      *    Otherwise you can set the text to be displayed for the each glob, and
      *    provide multiple globs, see setFilter() for details.
      * @param parent The widget the dialog will be centered on initially.
      * @param caption The name of the dialog widget.
+     *
+     * @see KFileWidget::KFileWidget()
      */
     static KUrl::List getOpenUrls( const KUrl& startDir = KUrl(),
                                    const QString& filter = QString(),
@@ -471,23 +443,17 @@
      * Note that with this
      * method the user need not select an existing filename.
      *
-     * @param startDir This can either be
-     *         @li The URL of the directory to start in.
-     *         @li A KUrl() to start in the current working
-     *             directory, or the last directory where a file has been
-     *             selected.
-     *         @li An URL starting with 'kfiledialog:///<keyword>' to start in the
-     *             directory last used by a filedialog in the same application that specified
-     *             the same keyword.
-     *         @li An URL starting with 'kfiledialog:///<keyword>?global' to start
-     *             in the directory last used by a filedialog in any application that specified the
-     *             same keyword.
+     * @param startDir Starting directory or @c kfiledialog:/// URL.
+     *                 Refer to the KFileWidget documentation for more information
+     *                 on this parameter.
      * @param filter A shell glob or a mime-type-filter that specifies which files to display.
      *    The preferred option is to set a list of mimetype names, see setMimeFilter() for details.
      *    Otherwise you can set the text to be displayed for the each glob, and
      *    provide multiple globs, see setFilter() for details.
      * @param parent The widget the dialog will be centered on initially.
      * @param caption The name of the dialog widget.
+     *
+     * @see KFileWidget::KFileWidget()
      */
     static QString getSaveFileName( const KUrl& startDir = KUrl(),
                                     const QString& filter = QString(),
@@ -510,23 +476,17 @@
      * Note that with this
      * method the user need not select an existing filename.
      *
-     * @param startDir This can either be
-     *         @li The URL of the directory to start in.
-     *         @li A KUrl() to start in the current working
-     *             directory, or the last directory where a file has been
-     *             selected.
-     *         @li An URL starting with 'kfiledialog:///<keyword>' to start in the
-     *             directory last used by a filedialog in the same application that specified
-     *             the same keyword.
-     *         @li An URL starting with 'kfiledialog:///<keyword>?global' to start
-     *             in the directory last used by a filedialog in any application that specified the
-     *             same keyword.
+     * @param startDir Starting directory or @c kfiledialog:/// URL.
+     *                 Refer to the KFileWidget documentation for more information
+     *                 on this parameter.
      * @param filter A shell glob or a mime-type-filter that specifies which files to display.
      *    The preferred option is to set a list of mimetype names, see setMimeFilter() for details.
      *    Otherwise you can set the text to be displayed for the each glob, and
      *    provide multiple globs, see setFilter() for details.
      * @param parent The widget the dialog will be centered on initially.
      * @param caption The name of the dialog widget.
+     *
+     * @see KFileWidget::KFileWidget()
      */
     static KUrl getSaveUrl( const KUrl& startDir = KUrl(),
                             const QString& filter = QString(),
@@ -538,20 +498,14 @@
      * Creates a modal directory-selection dialog and returns the selected
      * directory (local only) or an empty string if none was chosen.
      *
-     * @param startDir This can either be
-     *         @li The URL of the directory to start in.
-     *         @li A KUrl() to start in the current working
-     *             directory, or the last directory where a file has been
-     *             selected.
-     *         @li An URL starting with 'kfiledialog:///<keyword>' to start in the
-     *             directory last used by a filedialog in the same application that specified
-     *             the same keyword.
-     *         @li An URL starting with 'kfiledialog:///<keyword>?global' to start
-     *             in the directory last used by a filedialog in any application that specified the
-     *             same keyword.
+     * @param startDir Starting directory or @c kfiledialog:/// URL.
+     *                 Refer to the KFileWidget documentation for more information
+     *                 on this parameter.
      * @param parent The widget the dialog will be centered on initially.
      * @param caption The name of the dialog widget.
      * @return the path to an existing local directory.
+     *
+     * @see KFileWidget::KFileWidget()
      */
     static QString getExistingDirectory( const KUrl& startDir = KUrl(),
                                          QWidget * parent = 0,
@@ -562,20 +516,14 @@
      * directory or an empty string if none was chosen.
      * This version supports remote urls.
      *
-     * @param startDir This can either be
-     *         @li The URL of the directory to start in.
-     *         @li A KUrl() to start in the current working
-     *             directory, or the last directory where a file has been
-     *             selected.
-     *         @li An URL starting with 'kfiledialog:///<keyword>' to start in the
-     *             directory last used by a filedialog in the same application that specified
-     *             the same keyword.
-     *         @li An URL starting with 'kfiledialog:///<keyword>?global' to start
-     *             in the directory last used by a filedialog in any application that specified the
-     *             same keyword.
+     * @param startDir Starting directory or @c kfiledialog:/// URL.
+     *                 Refer to the KFileWidget documentation for more information
+     *                 on this parameter.
      * @param parent The widget the dialog will be centered on initially.
      * @param caption The name of the dialog widget.
      * @return the url to an existing directory (local or remote).
+     *
+     * @see KFileWidget::KFileWidget()
      */
     static KUrl getExistingDirectoryUrl( const KUrl& startDir = KUrl(),
                                          QWidget * parent = 0,
@@ -585,19 +533,13 @@
      * Creates a modal file dialog with an image previewer and returns the
      * selected url or an empty string if none was chosen.
      *
-     * @param startDir This can either be
-     *         @li The URL of the directory to start in.
-     *         @li A KUrl() to start in the current working
-     *             directory, or the last directory where a file has been
-     *             selected.
-     *         @li An URL starting with 'kfiledialog:///<keyword>' to start in the
-     *             directory last used by a filedialog in the same application that specified
-     *             the same keyword.
-     *         @li An URL starting with 'kfiledialog:///<keyword>?global' to start
-     *             in the directory last used by a filedialog in any application that specified the
-     *             same keyword.
+     * @param startDir Starting directory or @c kfiledialog:/// URL.
+     *                 Refer to the KFileWidget documentation for more information
+     *                 on this parameter.
      * @param parent The widget the dialog will be centered on initially.
      * @param caption The name of the dialog widget.
+     *
+     * @see KFileWidget::KFileWidget()
      */
     static KUrl getImageOpenUrl( const KUrl& startDir = KUrl(),
                                  QWidget *parent = 0,
@@ -694,13 +636,18 @@
      * This method implements the logic to determine the user's default directory
      * to be listed. E.g. the documents directory, home directory or a recently
      * used directory.
-     * @param startDir A url, to be used. May use the 'kfiledialog:///keyword' and
-     *                 'kfiledialog:///keyword?global' syntax
-     *                 as documented in the KFileDialog() constructor.
-     * @param recentDirClass If the 'kfiledialog:///' syntax is used, recentDirClass
-     *        will contain the string to be used later for KRecentDir::dir()
+     *
+     * @param startDir Starting directory or @c kfiledialog:/// URL.
+     *                 Refer to the KFileWidget documentation for more information
+     *                 on this parameter.
+     * @param recentDirClass If the @c kfiledialog:/// syntax is used, this
+     *        will return the string to be passed to KRecentDirs::dir() and
+     *        KRecentDirs::add().
      * @return The URL that should be listed by default (e.g. by KFileDialog or
      *         KDirSelectDialog).
+     *
+     * @see KFileWidget::KFileWidget()
+     * @see KFileWidget::getStartUrl( const KUrl& startDir, QString& recentDirClass );
      */
     static KUrl getStartUrl( const KUrl& startDir, QString& recentDirClass );
 
Index: kio/kfile/tests/kfiledialogtest.cpp
===================================================================
--- kio/kfile/tests/kfiledialogtest.cpp	(revision 937775)
+++ kio/kfile/tests/kfiledialogtest.cpp	(working copy)
@@ -39,10 +39,20 @@
     KCmdLineArgs::init( argc, argv, &aboutData );
     KApplication app;
 
-    KFileDialog keywordDlg(KUrl("kfiledialog://testKeyword"), QString("*.*|"), 0);
+    // Test for: saved location keyword.
+    //     - Should return to the starting directory last used for this test.
+    //     - Should have no entered file name.
+    KFileDialog keywordDlg(KUrl("kfiledialog:///testKeyword"), QString("*.*|"), 0);
     keywordDlg.setMode(KFile::Files);
     keywordDlg.exec();
 
+    // Test for: saved location keyword with file name.
+    //     - Should return to the starting directory last used for this test.
+    //     - Should enter the file name 'new.file'.
+    KFileDialog keywordDlg2(KUrl("kfiledialog:///testKeyword/new.file"), QString("*.*|"), 0);
+    keywordDlg2.setMode(KFile::Files);
+    keywordDlg2.exec();
+
     // bug 173137
     KFileDialog dlg(KUrl(QString()), QString("*.*|"), 0);
     dlg.setMode(KFile::Files | KFile::Directory);
Index: kio/kfile/kfiledialog.cpp
===================================================================
--- kio/kfile/kfiledialog.cpp	(revision 937775)
+++ kio/kfile/kfiledialog.cpp	(working copy)
@@ -720,7 +720,7 @@
     bool defaultDir = dir.isEmpty();
     bool specialDir = !defaultDir && dir.protocol() == "kfiledialog";
     KFileDialog dlg(specialDir ? dir : KUrl(), filter, parent);
-    if ( !specialDir )
+    if ( !specialDir && !defaultDir )
         dlg.setSelection( dir.url() ); // may also be a filename
 
     dlg.setCaption(caption.isEmpty() ? i18n("Save As") : caption);


-- end ------------------------------------------

-- 
Jonathan Marten                         http://www.keelhaul.demon.co.uk
Twickenham, UK                          jjm2 at keelhaul.demon.co.uk




More information about the kde-core-devel mailing list