Make a branch to make krunner Good Enough For Aaron™.
[kdebase/uwolfer.git] / runtime / kmimetypefinder / kmimetypefinder.cpp
blobd4e2db4ab20428f95402c07f97abe6283d628ceb
1 /*
2 * Copyright (C) 2002 David Faure <faure@kde.org>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License version 2 as published by the Free Software Foundation;
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Library General Public License for more details.
13 * You should have received a copy of the GNU Library General Public License
14 * along with this library; see the file COPYING.LIB. If not, write to
15 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16 * Boston, MA 02110-1301, USA.
19 #include <kmimetype.h>
20 #include <kcmdlineargs.h>
21 //#include <kapplication.h>
22 #include <kdeversion.h>
23 #include <kcomponentdata.h>
25 #include <stdio.h>
27 int main(int argc, char *argv[])
29 KCmdLineArgs::init( argc, argv, "kmimetypefinder", 0, ki18n("MimeType Finder"), KDE_VERSION_STRING , ki18n("Gives the mimetype for a given file"));
32 KCmdLineOptions options;
34 options.add("+filename", ki18n("the filename to test"));
36 KCmdLineArgs::addCmdLineOptions( options );
38 // KApplication app;
39 KComponentData instance("kmimetypefinder");
41 KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
42 if( args->count() < 1 ) {
43 printf( "No filename specified\n" );
44 return 1;
46 const QString fileName = args->arg( 0 );
47 int accuracy;
48 KMimeType::Ptr mime = KMimeType::findByPath( fileName, 0, false, &accuracy );
49 if ( mime && mime->name() != KMimeType::defaultMimeType() ) {
50 printf("%s\n", mime->name().toLatin1().constData());
51 printf("(accuracy %d)\n", accuracy);
52 } else {
53 return 1; // error
56 return 0;