Review Request: Internal viewer: improve handling of unknown MIME types
Raphael Kubo da Costa
rakuco at freebsd.org
Sun Dec 25 02:44:34 UTC 2011
-----------------------------------------------------------
This is an automatically generated e-mail. To reply, visit:
http://git.reviewboard.kde.org/r/103110/#review9246
-----------------------------------------------------------
I like the idea of the patch, but some issues need to be solved first:
- The coding style issues:
- if (foo) bar();
needs to become
if (foo) {
bar();
}
as we follow kdelibs' coding style.
- Single-letter variable names (such as `s') should be avoided.
- Aren't "mime" and "type" separate words? If so, camel-casing them as such (`mimeType' instead of `mimetype') makes sense.
- The code won't compile in master without some calls to QLatin1String.
- The code solving the TODO item about the dialog size should go into a separate review request/commit.
- I had not noticed we probe the file for its mimetype in so many places. My suggestion: determine the file's mimetype once in ArkViewer::view() and turn ArkViewer::getViewer(const QString &filename) into ArkViewer::getViewer(const KMimeType::Ptr &mimeType). The `asMimetype' argument you added to ArkViewer::viewInInternalViewer() can then be made mandatory, saving us another KMimeType::find*() call.
- The changes in ArkViewer::view() could check whether an external viewer is needed first and save some indentation and logic in the rest of the method. The logic would look like this:
void ArkViewer::view(...)
{
// Determine mimetype, call getViewer().
const bool needsExternalViewer = (!viewer.isNull()) && (viewer->hasServiceType(QL1S("KParts/ReadOnlyPart")));
if (needsExternalViewer) {
// Call the KRun::run/runUrl() code, yadda yadda.
return;
}
bool viewInInternalViewer = true;
if (viewer.isNull()) {
// Ask the user if the file should be previewed as text/plain
if (response == KMessageBox::Cancel) {
viewInInternalViewer = false;
}
}
if (viewInInternalViewer) {
// The ArkViewer::viewInInternalViewer() dance.
}
QFile::remove(...);
}
part/arkviewer.cpp
<http://git.reviewboard.kde.org/r/103110/#comment7657>
- It'd be good to use i18nc() here to give translators some context.
- Semantic markup would be good too.
- Don't you need to close the <qt> tag (if it is needed at all)?
- I feel that information such as the mimetype should be kept away from the user, or at most visible in a "more details" part of the dialog. Do you have strong feelings for showing the mimetype here?
part/arkviewer.cpp
<http://git.reviewboard.kde.org/r/103110/#comment7656>
This sounds like a good idea, but it is not directly related to the purpose of this request. I'd rather review it (and have it committed) separately.
part/arkviewer.cpp
<http://git.reviewboard.kde.org/r/103110/#comment7655>
Does this change from KRun::runUrl bring any benefits?
part/arkviewer.cpp
<http://git.reviewboard.kde.org/r/103110/#comment7654>
Why have the calls to QFile::remove been changed? It looks like the file is not being removed when it is previewed by the internal viewer anymore?
part/arkviewer.cpp
<http://git.reviewboard.kde.org/r/103110/#comment7653>
Not needed.
part/arkviewer.cpp
<http://git.reviewboard.kde.org/r/103110/#comment7652>
Why?
- Raphael Kubo da Costa
On Nov. 11, 2011, 10:02 p.m., Jonathan Marten wrote:
>
> -----------------------------------------------------------
> This is an automatically generated e-mail. To reply, visit:
> http://git.reviewboard.kde.org/r/103110/
> -----------------------------------------------------------
>
> (Updated Nov. 11, 2011, 10:02 p.m.)
>
>
> Review request for KDE Utils and Raphael Kubo da Costa.
>
>
> Description
> -------
>
> Archives often contain files which contain and are viewable as plain text, but either resolve to a MIME type that does not have a suitable viewer KPart available, or the default MIME type application/octet-stream. Trying to view such a file is simply rejected - and there is no "Open with" operation, so it is not easily possible to open the file in KWrite or another application.
>
> This change gives the user the option, in this case, of viewing the file as plain text - whether this is will result in a sensible display for the file is their decision. If they want to do that, ArkViewer::viewInInternalViewer() is forced to display the file as text/plain and not to try to detect the MIME type from the file name.
>
> The size of the internal viewer window is also saved and restored, as per the TODO comment.
>
> This change does introduce some new GUI strings, so it will not be able to be committed until after the KDE SC 4.8 release.
>
>
> Diffs
> -----
>
> part/arkviewer.h b810e17
> part/arkviewer.cpp 9bfd651
>
> Diff: http://git.reviewboard.kde.org/r/103110/diff/diff
>
>
> Testing
> -------
>
> Built ark with these changes, attempted to preview archive file contents for a variety of file types. The extremely annoying "The internal viewer cannot preview this file" error message is now a thing of the past.
>
>
> Thanks,
>
> Jonathan Marten
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kde.org/pipermail/kde-utils-devel/attachments/20111225/86997b3f/attachment-0001.html>
More information about the Kde-utils-devel
mailing list