KEditFileType: prevent inadvertent editing of application/octet-stream

The default fallback mime type is not something that should be edited by the user except when explicitly requested.

A confirmation is shown now before allowing the user to edit this mime type.

Also, since KMimeType::mimeType(...) does NOT return a null value but the default mime type, the check for incorrect mime type failed, since it expected a null return value, and the default fallback mime type was used instead, making the user inadvertedly edit the default mime type. Incorrect mime types are now promptly recognized, and an error message is shown to the user in such cases.

Signed-off-by: Mavridis Philippe <mavridisf@gmail.com>
pull/503/head
Mavridis Philippe 5 months ago
parent 7cc4d46cf5
commit 1585ac78f9
No known key found for this signature in database
GPG Key ID: F8D2D7E2F989A494

@ -28,6 +28,9 @@
#include <tdecmdlineargs.h> #include <tdecmdlineargs.h>
#include <tdesycoca.h> #include <tdesycoca.h>
#include <kstandarddirs.h> #include <kstandarddirs.h>
#include <tdemessagebox.h>
#include <stdlib.h>
#ifdef TQ_WS_X11 #ifdef TQ_WS_X11
#include <X11/Xlib.h> #include <X11/Xlib.h>
@ -153,9 +156,39 @@ int main(int argc, char ** argv)
mime = new KMimeType( loc, mimeString.arg( inc ), TQString::null, comment, patterns ); mime = new KMimeType( loc, mimeString.arg( inc ), TQString::null, comment, patterns );
} }
else { else {
// The user has explicitly requested application/octet-stream
if (arg == KMimeType::defaultMimeType())
{
int res = KMessageBox::warningYesNo(nullptr, i18n(
"<qt>You are about to edit the fallback filetype for unknown/binary files."
"<br><br>This is not something you should normally do unless you know exactly"
" what you are doing."
"<br>Incautious editing of this file type may cause unexpected behaviour of"
" your system."
"<br><br>Are you sure you want to continue?</qt>"
));
if (res != KMessageBox::Yes)
{
kdWarning() << "Editing of default fallback mime type prevented." << endl;
::exit(0);
}
mime = KMimeType::defaultMimeTypePtr();
}
// The user has NOT explicitly requested it, so if KMimeType::mimeType(...)
// returns it, then it's safe to assume that the mimetype is incorrect.
else
{
mime = KMimeType::mimeType( arg ); mime = KMimeType::mimeType( arg );
if (!mime) if (mime == KMimeType::defaultMimeTypePtr())
kdFatal() << "Mimetype " << arg << " not found" << endl; {
KMessageBox::error(nullptr, i18n("Mimetype %1 not found!").arg(arg));
kdError() << "Mimetype " << arg << " not found" << endl;
::exit(1);
}
}
} }
FileTypeDialog dlg( mime, createType ); FileTypeDialog dlg( mime, createType );

Loading…
Cancel
Save