[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-devel
Subject: Patch for Ark to preselect a fileformat for uncertain fileextensions
From: "Daniel Nagy" <DanielNagy () gmx ! de>
Date: 2013-02-12 23:07:06
Message-ID: 20130212230706.18260 () gmx ! net
[Download RAW message or body]
Hi everybody,
i have written a small patch for Ark that adds two new commandline options.
You may have seen the box when Ark asks you to choose which archive type a file is
supposed to be when you dont open files with an ordinary fileextension.
If you dont know what I mean you can see that box by renaming a "foo.zip" to
"foo.xyz" an try to open that in Ark.
As I have not found a non-interactive way to preselect an entry and skip that box,
I have written this patch which will add
A new option "--fileformat <mimetype>".
This lets you select an option from that box without interaction, and
A new option "--fileformatlist", which will output a list of possible values
for "<fileformat>".
Now ( if you know that foo.xyz is actually a 'application/zip' ) you can
$ ark --fileformat="application/zip" foo.xyz
and it will open that file without the need to select that format excplicitly.
The background for writing this was that I work on a new file format which is
actually a zip-file and I wanted ark to open without interaction.
the part in the main.cpp ( which outputs the list of possible values )
may be written more crossplatform-friendly but i still hope you like the idea of the patch.
Best,
Daniel Nagy
["0001-ark-fileformat-option.patch" (text/x-patch)]
diff --git a/app/main.cpp b/app/main.cpp
index bcd187d..3e448d7 100644
--- a/app/main.cpp
+++ b/app/main.cpp
@@ -23,15 +23,18 @@
#include "mainwindow.h"
#include "batchextract.h"
#include "kerfuffle/addtoarchive.h"
+#include "kerfuffle/archive.h"
#include <KAboutData>
#include <KApplication>
#include <KCmdLineArgs>
#include <KDebug>
#include <KLocale>
+#include <KMimeType>
#include <QByteArray>
#include <QFileInfo>
+#include <iostream>
using Kerfuffle::AddToArchive;
@@ -93,6 +96,8 @@ int main(int argc, char **argv)
option.add("+[url]", ki18n("URL of an archive to be opened"));
option.add("d").add("dialog", ki18n("Show a dialog for specifying the options \
for the operation (extract/add)"));
option.add("o").add("destination <directory>", ki18n("Destination folder to \
extract to. Defaults to current path if not specified.")); + \
option.add("fileformat <mimetype>", ki18n("If [url] has an unknown file extension, \
open with this format.")); + option.add("fileformatlist", ki18n("List known file \
formats.")); option.add(":", ki18n("Options for adding files"));
option.add("c").add("add", ki18n("Query the user for an archive filename and add \
specified files to it. Quit when finished."));
option.add("t").add("add-to <filename>", ki18n("Add the specified files to \
'filename'. Create archive if it does not exist. Quit when finished.")); @@ -108,6 \
+113,24 @@ int main(int argc, char **argv) KApplication application;
application.setQuitOnLastWindowClosed(false);
+ if( KCmdLineArgs::parsedArgs()->isSet("fileformatlist") ) {
+ QStringList mimeTypeList;
+ QHash<QString, QString> mimeTypes;
+
+ mimeTypeList = Kerfuffle::supportedMimeTypes();
+
+ foreach(const QString& mime, mimeTypeList) {
+ KMimeType::Ptr mimePtr(KMimeType::mimeType(mime));
+ if (mimePtr) {
+ // Key = "application/zip", Value = "Zip Archive"
+ mimeTypes[mime] = mimePtr->comment();
+ std::cout << mime.toUtf8().data() << " - ( " << \
mimePtr->comment().toUtf8().data() << " )" << std::endl; + }
+ }
+
+ return 0;
+ }
+
//session restoring
if (application.isSessionRestored()) {
MainWindow* window = NULL;
@@ -199,6 +222,9 @@ int main(int argc, char **argv)
if (args->isSet("dialog")) {
window->setShowExtractDialog(true);
}
+ if (args->isSet("fileformat")) {
+ window->setForcedFileType(args->getOption("fileformat"));
+ }
window->openUrl(args->url(0));
}
window->show();
diff --git a/app/mainwindow.cpp b/app/mainwindow.cpp
index 59efe78..2b307a5 100644
--- a/app/mainwindow.cpp
+++ b/app/mainwindow.cpp
@@ -230,6 +230,15 @@ void MainWindow::setShowExtractDialog(bool option)
}
}
+void MainWindow::setForcedFileType(QString forced_filetype)
+{
+ if (forced_filetype.length()) {
+ m_openArgs.metaData()[QLatin1String( "forcedFileType" )] = forced_filetype;
+ } else {
+ m_openArgs.metaData().remove(QLatin1String( "forcedFileType" ));
+ }
+}
+
void MainWindow::quit()
{
close();
diff --git a/app/mainwindow.h b/app/mainwindow.h
index 5dd7fb8..5aaefa4 100644
--- a/app/mainwindow.h
+++ b/app/mainwindow.h
@@ -43,6 +43,7 @@ public:
public slots:
void openUrl(const KUrl& url);
void setShowExtractDialog(bool);
+ void setForcedFileType(QString);
private slots:
void updateActions();
diff --git a/part/part.cpp b/part/part.cpp
index d806262..9cb4e60 100644
--- a/part/part.cpp
+++ b/part/part.cpp
@@ -431,6 +431,9 @@ bool Part::openFile()
item = KInputDialog::getItem(i18nc("@title:window", "Invalid Archive \
Type"), i18nc("@info", "Ark cannot create archives of the type you have \
chosen.<nl/><nl/>Please choose another archive type below."), mimeComments, 0, \
false, &ok); + } else if ( \
arguments().metaData()[QLatin1String("forcedFileType")].length() ) { + \
item = mimeTypes.value( arguments().metaData()[QLatin1String("forcedFileType")] ); + \
ok = true; } else {
item = KInputDialog::getItem(i18nc("@title:window", "Unable to Determine \
Archive Type"), i18nc("@info", "Ark was unable to determine the archive type of the \
filename.<nl/><nl/>Please choose the correct archive type below."),
>> 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