1 /*************************************************************************** 2 qgis.g.browser.cpp 3 --------------------- 4 begin : February 2010 5 copyright : (C) 2010 by Radim Blazek 6 email : radim dot blazek at gmail dot com 7 *************************************************************************** 8 * * 9 * This program is free software; you can redistribute it and/or modify * 10 * it under the terms of the GNU General Public License as published by * 11 * the Free Software Foundation; either version 2 of the License, or * 12 * (at your option) any later version. * 13 * * 14 ***************************************************************************/ 15 #include <stdlib.h> 16 #include <stdio.h> 17 #include <iostream> 18 #include <QUrl> 19 #include <QDesktopServices> 20 #include <QString> 21 22 #ifdef Q_OS_WIN 23 #include <windows.h> 24 #else 25 #include <unistd.h> 26 #endif 27 28 // Open a URL by default browser main(int argc,char ** argv)29int main( int argc, char **argv ) 30 { 31 if ( argc < 2 ) 32 { 33 fprintf( stderr, "URL argument missing\n" ); 34 exit( 1 ); 35 } 36 QString urlStr( argv[1] ); 37 QUrl url( urlStr ); 38 #ifdef Q_OS_WIN 39 // openUrl on windows fails to open 'file://c:...' it must be 'file:///c:...' (3 slashes) 40 if ( url.scheme() == "file" ) 41 { 42 // this does not work, the drive was already removed by QT: 43 //url.setPath ( "/" + url.path() ); 44 urlStr.replace( "file://", "file:///" ); 45 url.setUrl( urlStr ); 46 std::cout << "path reset to: " << qPrintable( url.path() ) << std::endl; 47 } 48 #endif 49 QDesktopServices::openUrl( url ); 50 #ifdef Q_OS_WIN 51 Sleep( 1000 ); 52 #else 53 sleep( 1 ); // not nice but if it exits immediately the page sometimes does not open 54 #endif 55 exit( 0 ); 56 } 57