2 * This file Copyright (C) Mnemosyne LLC
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2
6 * as published by the Free Software Foundation.
8 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
10 * $Id: utils.h 14150 2013-07-27 21:58:14Z jordan $
20 #include <cctype> // isxdigit()
24 class Utils
: public QObject
33 static QString
remoteFileChooser( QWidget
* parent
, const QString
& title
, const QString
& myPath
, bool dir
, bool local
);
34 static const QIcon
& guessMimeIcon( const QString
& filename
);
35 // Test if string is UTF-8 or not
36 static bool isValidUtf8 ( const char *s
);
39 static void toStderr( const QString
& qstr
);
45 static bool isMagnetLink( const QString
& s
) { return s
.startsWith( QString::fromUtf8( "magnet:?" ) ); }
47 static bool isHexHashcode( const QString
& s
)
49 if( s
.length() != 40 ) return false;
50 foreach( QChar ch
, s
) if( !isxdigit( ch
.unicode() ) ) return false;
54 static bool isUriWithSupportedScheme( const QString
& s
)
56 static const QString ftp
= QString::fromUtf8( "ftp://" );
57 static const QString http
= QString::fromUtf8( "http://" );
58 static const QString https
= QString::fromUtf8( "https://" );
59 return s
.startsWith(http
) || s
.startsWith(https
) || s
.startsWith(ftp
);