1 | /*************************************************************************** |
2 | * Copyright (C) 2005-2014 by the Quassel Project * |
3 | * devel@quassel-irc.org * |
4 | * * |
5 | * This program is free software; you can redistribute it and/or modify * |
6 | * it under the terms of the GNU General Public License as published by * |
7 | * the Free Software Foundation; either version 2 of the License, or * |
8 | * (at your option) version 3. * |
9 | * * |
10 | * This program is distributed in the hope that it will be useful, * |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
13 | * GNU General Public License for more details. * |
14 | * * |
15 | * You should have received a copy of the GNU General Public License * |
16 | * along with this program; if not, write to the * |
17 | * Free Software Foundation, Inc., * |
18 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * |
19 | ***************************************************************************/ |
20 | |
21 | #ifndef UTIL_H |
22 | #define UTIL_H |
23 | |
24 | #include <QDir> |
25 | #include <QVariant> |
26 | #include <QString> |
27 | #include <QMetaMethod> |
28 | |
29 | // TODO Use versions from Network instead |
30 | QString nickFromMask(QString mask); |
31 | QString userFromMask(QString mask); |
32 | QString hostFromMask(QString mask); |
33 | bool isChannelName(QString str); |
34 | |
35 | //! Strip mIRC format codes |
36 | QString stripFormatCodes(QString); |
37 | |
38 | //! Remove accelerator markers (&) from the string |
39 | QString stripAcceleratorMarkers(const QString &); |
40 | |
41 | QString secondsToString(int timeInSeconds); |
42 | |
43 | //! Take a string and decode it using the specified text codec, recognizing utf8. |
44 | /** This function takes a string and first checks if it is encoded in utf8, in which case it is |
45 | * decoded appropriately. Otherwise, the specified text codec is used to transform the string. |
46 | * \param input The input string containing encoded data |
47 | * \param codec The text codec we use if the input is not utf8 |
48 | * \return The decoded string. |
49 | */ |
50 | QString decodeString(const QByteArray &input, QTextCodec *codec = 0); |
51 | |
52 | uint editingDistance(const QString &s1, const QString &s2); |
53 | |
54 | template<typename T> |
55 | QVariantList toVariantList(const QList<T> &list) |
56 | { |
57 | QVariantList variants; |
58 | for (int i = 0; i < list.count(); i++) { |
59 | variants << QVariant::fromValue<T>(list[i]); |
60 | } |
61 | return variants; |
62 | } |
63 | |
64 | |
65 | template<typename T> |
66 | QList<T> fromVariantList(const QVariantList &variants) |
67 | { |
68 | QList<T> list; |
69 | for (int i = 0; i < variants.count(); i++) { |
70 | list << variants[i].value<T>(); |
71 | } |
72 | return list; |
73 | } |
74 | |
75 | |
76 | QByteArray prettyDigest(const QByteArray &digest); |
77 | |
78 | #endif |
79 | |