PageRenderTime 100ms CodeModel.GetById 17ms RepoModel.GetById 2ms app.codeStats 0ms

/src/plugins/grass/qgis.g.browser.cpp

https://github.com/linz/Quantum-GIS
C++ | 41 lines | 35 code | 2 blank | 4 comment | 3 complexity | 83f29a5addae35f7d66ffac195976bfc MD5 | raw file
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <unistd.h>
  4. #include <iostream>
  5. #include <QUrl>
  6. #include <QDesktopServices>
  7. #include <QString>
  8. #ifdef Q_OS_WIN
  9. #include <windows.h>
  10. #endif
  11. // Open a URL by default browser
  12. int main( int argc, char **argv )
  13. {
  14. if ( argc < 2 )
  15. {
  16. fprintf( stderr, "URL argument missing\n" );
  17. exit( 1 );
  18. }
  19. QString urlStr( argv[1] );
  20. QUrl url( urlStr );
  21. #ifdef Q_OS_WIN
  22. // openUrl on windows fails to open 'file://c:...' it must be 'file:///c:...' (3 slashes)
  23. if ( url.scheme() == "file" )
  24. {
  25. // this does not work, the drive was already removed by QT:
  26. //url.setPath ( "/" + url.path() );
  27. urlStr.replace( "file://", "file:///" );
  28. url.setUrl( urlStr );
  29. std::cout << "path reset to: " << qPrintable( url.path() ) << std::endl;
  30. }
  31. #endif
  32. QDesktopServices::openUrl( url );
  33. #ifdef Q_OS_WIN
  34. Sleep( 1000 );
  35. #else
  36. sleep( 1 ); // not nice but if it exits immediately the page sometimes does not open
  37. #endif
  38. exit( 0 );
  39. }