TDE core libraries
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

kmimefromext.cpp 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /*
  2. * Copyright (C) 2002 David Faure <faure@kde.org>
  3. *
  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;
  7. *
  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.
  12. *
  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.
  17. */
  18. #include <ktrader.h>
  19. #include <kmimetype.h>
  20. #include <tdecmdlineargs.h>
  21. #include <tdeapplication.h>
  22. #include <stdio.h>
  23. static TDECmdLineOptions options[] =
  24. {
  25. { "+filename", "the filename to test", 0 },
  26. TDECmdLineLastOption
  27. };
  28. int main(int argc, char *argv[])
  29. {
  30. TDECmdLineArgs::init( argc, argv, "kmimefromext", "A mimetype testing tool, gives the mimetype for a given filename", "0.0" );
  31. TDECmdLineArgs::addCmdLineOptions( options );
  32. TDEApplication app;
  33. TDECmdLineArgs *args = TDECmdLineArgs::parsedArgs();
  34. TQString fileName = args->arg( 0 );
  35. // The "true" here means only the filename will be looked at.
  36. // "Mime-magic" will not interfer. The file doesn't exist.
  37. // TODO: a cmd line parameter for controlling this bool ;)
  38. KMimeType::Ptr mime = KMimeType::findByPath( fileName, 0, true );
  39. if ( mime && mime->name() != KMimeType::defaultMimeType() )
  40. printf( "%s\n", mime->name().latin1());
  41. else
  42. return 1; // error
  43. return 0;
  44. }