source: trunk/qt/utils.h @ 13448

Last change on this file since 13448 was 13448, checked in by jordan, 10 years ago

(trunk, qt) #4760 'transmission-qt breaks unicode characters in the default target dir' -- fixed with patch from rb07

  • Property svn:keywords set to Date Rev Author Id
File size: 1.7 KB
Line 
1/*
2 * This file Copyright (C) Mnemosyne LLC
3 *
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.
7 *
8 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
9 *
10 * $Id: utils.h 13448 2012-08-19 16:12:20Z jordan $
11 */
12
13#ifndef QTR_UTILS
14#define QTR_UTILS
15
16#include <QString>
17#include <QObject>
18#include <QIcon>
19
20#include <cctype> // isxdigit()
21
22#include "speed.h"
23
24class Utils: public QObject
25{
26        Q_OBJECT
27
28    public:
29        Utils( ) { }
30        virtual ~Utils( ) { }
31
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 );
37
38        // meh
39        static void toStderr( const QString& qstr );
40
41        ///
42        /// URLs
43        ///
44
45        static bool isMagnetLink( const QString& s ) { return s.startsWith( QString::fromAscii( "magnet:?" ) ); }
46
47        static bool isHexHashcode( const QString& s )
48        {
49            if( s.length() != 40 ) return false;
50            foreach( QChar ch, s ) if( !isxdigit( ch.toAscii() ) ) return false;
51            return true;
52        }
53
54        static bool isUriWithSupportedScheme( const QString& s )
55        {
56            static const QString ftp = QString::fromAscii( "ftp://" );
57            static const QString http = QString::fromAscii( "http://" );
58            static const QString https = QString::fromAscii( "https://" );
59            return s.startsWith(http) || s.startsWith(https) || s.startsWith(ftp);
60        }
61
62};
63
64#endif
Note: See TracBrowser for help on using the repository browser.