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

List:       kde-core-devel
Subject:    [PATCH] Encoding box in the file dialog
From:       Andras Mantia <amantia () kde ! org>
Date:       2003-09-21 13:34:38
[Download RAW message or body]

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi,

  Here is the implementation of what I've talked about some days ago: mergin 
the Kate::FileDialog into KFileDialog. KFileDialog now has a new ctor for 
text files which provides an encoding combo. 
 Please review, and if there are no issues with it, I will commit, as we 
basicly agreed with the parties involved. The users of Kate::FileDialog will 
need to modify their code a little, as the parameters for the new ctor are 
not in the same order and the encoding setting must be queried with 
selectedEncoding() as it's not provided as the result of exec().

Andras

- -- 
Quanta Plus developer - http://quanta.sourceforge.net
K Desktop Environment - http://www.kde.org
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2-rc1-SuSE (GNU/Linux)

iD8DBQE/bajuTQdfac6L/08RAn17AJ4pOeN6T90orW9zPzQK5UEDSiqMSwCg2WvF
seyQuRtqV7jIn48ycb8ZuFg=
=nffz
-----END PGP SIGNATURE-----

["kfiledialog.h.diff" (text/x-diff)]

--- kfiledialog.h.orig	2003-09-15 18:01:47.000000000 +0300
+++ kfiledialog.h	2003-09-21 16:07:43.000000000 +0300
@@ -32,6 +32,8 @@
 #include <kfile.h>
 #include <kurl.h>
 #include <kmimetype.h>
+#include <kglobal.h>
+#include <klocale.h>
 #include <kio/jobclasses.h>
 
 class QCheckBox;
@@ -130,8 +132,8 @@
       * @param startDir This can either be
       *         @li The URL of the directory to start in.
       *         @li QString::null to start in the current working
-      *		    directory, or the last directory where a file has been
-      *		    selected.
+      *             directory, or the last directory where a file has been
+      *             selected.
       *         @li ':&lt;keyword&gt;' to start in the directory last used
       *             by a filedialog in the same application that specified
       *             the same keyword.
@@ -157,6 +159,34 @@
 		QWidget *parent, const char *name,
 		bool modal, QWidget* widget);
 
+      
+    /**
+      * Constructs a file dialog for text files with encoding selection possibility.
+      *
+      * @param startDir This can either be
+      *         @li The URL of the directory to start in.
+      *         @li QString::null to start in the current working
+      *		    directory, or the last directory where a file has been
+      *		    selected.
+      *         @li ':&lt;keyword&gt;' to start in the directory last used
+      *             by a filedialog in the same application that specified
+      *             the same keyword.
+      *         @li '::&lt;keyword&gt;' to start in the directory last used
+      *             by a filedialog in any application that specified the
+      *             same keyword.
+      *
+      * @param caption The caption of the dialog
+      *
+      * @param type This can either be
+      *		@li Opening (open dialog, the default setting)
+      *		@li Saving 
+      *
+      * @since 3.2
+      */
+    KFileDialog (const QString& startDir = QString::null,
+                    const QString& encoding = \
QString::fromLatin1(KGlobal::locale()->encoding()), +		    const QString& caption = \
QString::null, int type = Opening,  +                    QWidget *parent= 0, const \
char *name="", bool modal = true);  /**
      * Destructs the file dialog.
      */
@@ -171,6 +201,11 @@
      * @returns The list of selected URLs.
      */
     KURL::List selectedURLs() const;
+    
+    /**
+    * @returns The selected encoding if the constructor with the encoding parameter \
was used, otherwise QString::null. +    */
+    QString selectedEncoding() const;
 
     /**
      * @returns the currently shown directory.


["kfiledialog.cpp.diff" (text/x-diff)]

--- kfiledialog.cpp.orig	2003-09-13 19:30:57.000000000 +0300
+++ kfiledialog.cpp	2003-09-21 16:32:33.000000000 +0300
@@ -34,6 +34,7 @@
 #include <qlineedit.h>
 #include <qptrlist.h>
 #include <qpixmap.h>
+#include <qtextcodec.h>
 #include <qtooltip.h>
 #include <qtimer.h>
 #include <qwhatsthis.h>
@@ -41,6 +42,7 @@
 #include <kaccel.h>
 #include <kaction.h>
 #include <kapplication.h>
+#include <kcharsets.h>
 #include <kcmdlineargs.h>
 #include <kcompletionbox.h>
 #include <kconfig.h>
@@ -111,6 +113,7 @@
     QWidget *mainWidget;
 
     QLabel *locationLabel;
+    KComboBox *encoding;
 
     // @deprecated remove in KDE4
     QLabel *filterLabel;
@@ -172,6 +175,47 @@
     init( startDir, filter, widget );
 }
 
+KFileDialog::KFileDialog(const QString& startDir, const QString& encoding , 
+			 const QString& caption, int type, QWidget *parent, const char* name, bool modal)
+   : KDialogBase( parent, name, modal, QString::null, 0)			 
+{
+  init( startDir, "all/allfiles text/plain", 0);
+  setCaption( caption );
+  if (type == Opening) {
+    setMode(KFile::Files);
+    setOperationMode(Opening);
+    }
+  else {
+    setMode(KFile::File);
+    setOperationMode(Saving);
+    }
+
+  toolBar()->insertCombo(QStringList(), 33333, false, 0L, 0L, 0L, true);
+  d->encoding = toolBar()->getCombo(33333);
+
+  d->encoding->clear ();
+  QStringList encodings (KGlobal::charsets()->availableEncodingNames());
+  int insert = 0;
+  for (uint i=0; i < encodings.count(); i++)
+  {
+    bool found = false;
+    QTextCodec *codecForEnc = KGlobal::charsets()->codecForName(encodings[i], found);
+
+    if (found)
+    {
+      d->encoding->insertItem (encodings[i]);
+      if ( (codecForEnc->name() == encoding) || (encodings[i] == encoding) )
+      {
+        d->encoding->setCurrentItem(insert);
+      }
+
+      insert++;
+    }
+  }
+        
+     
+}
+
 KFileDialog::~KFileDialog()
 {
     hide();
@@ -783,6 +827,7 @@
     initStatic();
     d = new KFileDialogPrivate();
 
+    d->encoding = 0;
     d->boxLayout = 0;
     d->keepLocation = false;
     d->operationMode = Opening;
@@ -1396,6 +1441,14 @@
     return list;
 }
 
+QString KFileDialog::selectedEncoding() const
+{
+  if (d->encoding)
+     return d->encoding->currentText();
+  else
+    return QString::null;     
+}
+
 
 KURL::List& KFileDialog::parseSelectedURLs() const
 {


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

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