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

List:       kde-devel
Subject:    Re: KFileDialog setMimeFilter question
From:       Alessandro Diaferia <alediaferia () gmail ! com>
Date:       2010-06-09 22:31:51
Message-ID: AANLkTimOab5QpWWOmLqPszv8_eM2HN8v3shDfYgeHr-u () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


2010/6/3 Reece Dunn <msclrhd@googlemail.com>

> Hi,
>
> I am currently writing an application that is using KFileDialog (as
> QFileDialog does not support mimetype filters on files) as follows:
>
>                KFileDialog open(m_edit->fileName(), QString(), this);
>                open.setCaption(i18nc("@title:window", "Open Document"));
>                open.setOperationMode(KFileDialog::Opening);
>                open.setMimeFilter(QStringList() << "text/plain" <<
> "text/html",
> m_edit->mimeType());
>                open.setMode(KFile::File | KFile::ExistingOnly |
> KFile::LocalOnly);
>
>                if (open.exec())
>                        loadFile(open.selectedFile());
>
> The loadFile function then does:
>
>        KMimeType::Ptr type = KMimeType::findByPath(fileName);
>        if (!m_edit->loadDocument(fileName, type->name()))
>                ...
>
> to get the mimetype of the file being loaded (as
> open.currentMimeFilter() could return "text/plain" for HTML files and
> thus show the HTML code instead of the results from setHtml).
>
> This is working, except that if the user selects plain text, they can
> select a format like RTF or XML. If they do this, findByPath returns a
> mimetype different to text/plain (e.g. application/rtf for RTF files).
> This makes my m_edit->loadDocument function fail (unsupported
> mimetype).
>
> Also, the user sees HTML files displayed in the dialog when text/plain.
>
>

> So, the question is: is it possible to restrict the text/plain filter
> to text/plain types only (i.e. ignoring the parent/inherited
> mimetypes)?
>

Probably a function like setMimeExcludeFilter. The function would eventually
call the same one from the used KDirLister.
But this is surely not possible by KDE 4.5


>
> NOTE: This is on KDE in Ubuntu 10.04.
>
> Thanks,
> - Reece
>
> >> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to
> unsubscribe <<
>

Just my 2 cc.

-- 
Alessandro Diaferia
KDE Developer
KDE e.V. member

[Attachment #5 (text/html)]

<br><br><div class="gmail_quote">2010/6/3 Reece Dunn <span dir="ltr">&lt;<a \
href="mailto:msclrhd@googlemail.com">msclrhd@googlemail.com</a>&gt;</span><br><blockquote \
class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, \
204, 204); padding-left: 1ex;"> Hi,<br>
<br>
I am currently writing an application that is using KFileDialog (as<br>
QFileDialog does not support mimetype filters on files) as follows:<br>
<br>
                        KFileDialog open(m_edit-&gt;fileName(), QString(), this);<br>
                        open.setCaption(i18nc(&quot;@title:window&quot;, &quot;Open \
Document&quot;));<br>  open.setOperationMode(KFileDialog::Opening);<br>
                        open.setMimeFilter(QStringList() &lt;&lt; \
&quot;text/plain&quot; &lt;&lt; &quot;text/html&quot;,<br> \
                m_edit-&gt;mimeType());<br>
                        open.setMode(KFile::File | KFile::ExistingOnly | \
KFile::LocalOnly);<br> <br>
                        if (open.exec())<br>
                                    loadFile(open.selectedFile());<br>
<br>
The loadFile function then does:<br>
<br>
            KMimeType::Ptr type = KMimeType::findByPath(fileName);<br>
            if (!m_edit-&gt;loadDocument(fileName, type-&gt;name()))<br>
                        ...<br>
<br>
to get the mimetype of the file being loaded (as<br>
open.currentMimeFilter() could return &quot;text/plain&quot; for HTML files and<br>
thus show the HTML code instead of the results from setHtml).<br>
<br>
This is working, except that if the user selects plain text, they can<br>
select a format like RTF or XML. If they do this, findByPath returns a<br>
mimetype different to text/plain (e.g. application/rtf for RTF files).<br>
This makes my m_edit-&gt;loadDocument function fail (unsupported<br>
mimetype).<br>
<br>
Also, the user sees HTML files displayed in the dialog when text/plain.<br>
<br></blockquote><div>  </div><blockquote class="gmail_quote" style="margin: 0pt 0pt \
0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;"> So, the \
question is: is it possible to restrict the text/plain filter<br> to text/plain types \
only (i.e. ignoring the parent/inherited<br> \
mimetypes)?<br></blockquote><div><br>Probably a function like setMimeExcludeFilter. \
The function would eventually call the same one from the used KDirLister.<br>But this \
is surely not possible by KDE 4.5<br>  <br></div><blockquote class="gmail_quote" \
style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); \
padding-left: 1ex;">

<br>
NOTE: This is on KDE in Ubuntu 10.04.<br>
<br>
Thanks,<br>
- Reece<br>
<br>
&gt;&gt; Visit <a href="http://mail.kde.org/mailman/listinfo/kde-devel#unsub" \
target="_blank">http://mail.kde.org/mailman/listinfo/kde-devel#unsub</a> to \
unsubscribe &lt;&lt;<br> </blockquote></div><br>Just my 2 cc.<br clear="all"><br>-- \
<br>Alessandro Diaferia<br>KDE Developer<br>KDE e.V. member<br><br>



>> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<


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

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