Bug 263604 - some file dialogs are save and not load dialogs
Summary: some file dialogs are save and not load dialogs
Status: VERIFIED FIXED
Alias: None
Product: Kleopatra Mobile
Classification: Applications
Component: general (show other bugs)
Version: unspecified
Platform: Windows CE Microsoft Windows CE
: NOR normal (vote)
Target Milestone: ---
Assignee: Andre Heinecke
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-01-19 02:19 UTC by Marcus Brinkmann
Modified: 2011-02-15 16:45 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Marcus Brinkmann 2011-01-19 02:19:20 UTC
Version:           unspecified (using Devel) 
OS:                Windows CE

Two dialogues say they are save dialogs ("speichern"), but they are actually the system's open dialogues.  The problem is that in an open dialog the default settings are interpreted differently, and you can't specify a filename.  This leads to weird filenames being created such as "My Documents..p10" (yes, two dots, and the directory name is actually taken as the filename).

This also happened in kmail and was fixed with some flag change (Volker probably remembers).

The dialogs in question are:

1. Certificate export

2. After S/MIME key generation, the "Save CSR" dialog.


Reproducible: Always
Comment 1 Andre Heinecke 2011-01-19 16:23:30 UTC
Certificate export is the correct dialog, but the default filename is the fingerprint of the certificate and there is no file type filter preset.

During a test i was able to save a file to /My Documents/mytestcert.der without problems after entering mytestcert.der as the filename.
Comment 2 Andre Heinecke 2011-01-19 19:33:28 UTC
commit 650d05a1bdb5ea60f6bf1c9eb5ae5a601120b364
branch master
Author: Andre Heinecke <aheinecke@intevation.de>
Date:   Wed Jan 19 18:28:10 2011 +0000

    Convert filters to kde format for kfiledialog
    
        Instead of disabling filters when KFileDialog is used
        they are now converted to the correct format.
        The qt2KdeFilter is a copy out of KFileDialog.
    
        CCBUG: 263604

diff --git a/kleopatra/utils/filedialog.cpp b/kleopatra/utils/filedialog.cpp
index de7b826..4c28158 100644
--- a/kleopatra/utils/filedialog.cpp
+++ b/kleopatra/utils/filedialog.cpp
@@ -38,6 +38,7 @@
 #ifdef QT_NO_FILEDIALOG
 #include <KFileDialog>
 #include <KUrl>
+#include <QTextStream>
 #endif
 
 #include <QMap>
@@ -62,6 +63,35 @@ static void update( const QString & fname, const QString & id ) {
         (*dir_id_2_dir_map())[ id ] = QFileInfo( fname ).absolutePath();
 }
 
+#ifdef QT_NO_FILEDIALOG
+static QString qt2KdeFilter(const QString &f)
+{
+  QString               filter;
+  QTextStream           str(&filter, QIODevice::WriteOnly);
+  QStringList           list(f.split(";;").replaceInStrings("/", "\\/"));
+  QStringList::const_iterator it(list.begin()),
+    end(list.end());
+  bool                  first=true;
+
+  for(; it!=end; ++it)
+  {
+    int ob=(*it).lastIndexOf('('),
+        cb=(*it).lastIndexOf(')');
+
+    if(-1!=cb && ob<cb)
+    {
+      if(first)
+        first=false;
+      else
+        str << '\n';
+      str << (*it).mid(ob+1, (cb-ob)-1) << '|' << (*it).mid(0, ob);
+    }
+  }
+
+  return filter;
+}
+#endif
+
 QString FileDialog::getExistingDirectory( QWidget * parent, const QString & caption, const QString & dirID ) {
 #ifndef QT_NO_FILEDIALOG
     const QString fname = QFileDialog::getExistingDirectory( parent, caption, dir( dirID ) );
@@ -76,8 +106,7 @@ QString FileDialog::getOpenFileName( QWidget * parent, const QString & caption,
 #ifndef QT_NO_FILEDIALOG
     const QString fname = QFileDialog::getOpenFileName( parent, caption, dir( dirID ), filter );
 #else
-    Q_UNUSED( filter ); // incompatible syntax
-    const QString fname = KFileDialog::getOpenFileName( dir( dirID ), QString(), parent, caption );
+    const QString fname = KFileDialog::getOpenFileName( dir( dirID ), qt2KdeFilter( filter ), parent, caption );
 #endif
     update( fname, dirID );
     return fname;
@@ -87,8 +116,7 @@ QStringList FileDialog::getOpenFileNames( QWidget * parent, const QString & capt
 #ifndef QT_NO_FILEDIALOG
     const QStringList files = QFileDialog::getOpenFileNames( parent, caption, dir( dirID ), filter );
 #else
-    Q_UNUSED( filter ); // incompatible syntax
-    const QStringList files = KFileDialog::getOpenFileNames( dir( dirID ), QString(), parent, caption );
+    const QStringList files = KFileDialog::getOpenFileNames( dir( dirID ), qt2KdeFilter( filter ), parent, caption );
 #endif
     if ( !files.empty() )
         update( files.front(), dirID );
@@ -99,8 +127,7 @@ QString FileDialog::getSaveFileName( QWidget * parent, const QString & caption,
 #ifndef QT_NO_FILEDIALOG
     const QString fname = QFileDialog::getSaveFileName( parent, caption, dir( dirID ), filter );
 #else
-    Q_UNUSED( filter ); // incompatible syntax
-    const QString fname = KFileDialog::getSaveFileName( dir( dirID ), QString(), parent, caption );
+    const QString fname = KFileDialog::getSaveFileName( dir( dirID ), qt2KdeFilter( filter ), parent, caption );
 #endif
     update( fname, dirID );
     return fname;
@@ -112,7 +139,7 @@ QString FileDialog::getSaveFileNameEx( QWidget * parent, const QString & caption
 #ifndef QT_NO_FILEDIALOG
     const QString fname = QFileDialog::getSaveFileName( parent, caption, QDir( dir( dirID ) ).filePath( proposedFileName ), filter );
 #else
-    const QString fname = KFileDialog::getSaveFileName( QDir( dir( dirID ) ).filePath( proposedFileName ), QString(), parent, caption );
+    const QString fname = KFileDialog::getSaveFileName( QDir( dir( dirID ) ).filePath( proposedFileName ), qt2KdeFilter( filter ), parent, caption );
 #endif
     update( fname, dirID );
     return fname;
Comment 3 Bernhard E. Reiter 2011-01-21 11:48:04 UTC
Andre, do you believe this is fixed, by your patch?
Comment 4 Andre Heinecke 2011-01-21 12:00:15 UTC
The certificate export dialog was fixed, the save certificate request uses the same code but i was not able to test it since i did not get that far in the certifcate generation.
Comment 5 Andre Heinecke 2011-01-21 19:15:05 UTC
Git commit 0a594ef9ee1ebc538cf7f8f5696e2ec606286cb2 by Andre Heinecke
Pushed by aheinecke into branch master

Do not set the KFileDialog save default to a dir

    This is more of a problem in KFileDialog when there are
    no Qt filedialogs available. The setting for the start
    FileName is not recognized as a folder and set to a
    directory.
    This only happens if there is no proposedFileName available.

    BUG: 263604

M  +3    -2    kleopatra/utils/filedialog.cpp     

http://commits.kde.org/ee6cc38b/0a594ef9ee1ebc538cf7f8f5696e2ec606286cb2