Transmission: update to 2.82
[tomato.git] / release / src / router / transmission / qt / utils.h
bloba8e5bf681f4779f6be21f67ffbff17c9022f0ee3
1 /*
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 $
13 #ifndef QTR_UTILS
14 #define QTR_UTILS
16 #include <QString>
17 #include <QObject>
18 #include <QIcon>
20 #include <cctype> // isxdigit()
22 #include "speed.h"
24 class Utils: public QObject
26 Q_OBJECT
28 public:
29 Utils( ) { }
30 virtual ~Utils( ) { }
32 public:
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 );
38 // meh
39 static void toStderr( const QString& qstr );
41 ///
42 /// URLs
43 ///
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;
51 return true;
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);
64 #endif