diff options
Diffstat (limited to 'klinkstatus/src/utils/utils.cpp')
-rw-r--r-- | klinkstatus/src/utils/utils.cpp | 204 |
1 files changed, 204 insertions, 0 deletions
diff --git a/klinkstatus/src/utils/utils.cpp b/klinkstatus/src/utils/utils.cpp new file mode 100644 index 00000000..6259f8d0 --- /dev/null +++ b/klinkstatus/src/utils/utils.cpp @@ -0,0 +1,204 @@ +/*************************************************************************** + * Copyright (C) 2004 by Paulo Moura Guedes * + * [email protected] * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ + +#include "utils.h" + +#include <qprocess.h> +#include <qwidget.h> + +#include <kapplication.h> +#include <kmessagebox.h> +#include <kdebug.h> + + +QString htmlDocCharset[NUMBER_OF_HTML_CODES][2] = { + + { "€", "@" }, + { "	", "\t" }, + { " ", "\n" }, + { " ", "\r" }, + { " ", " " }, + { "!", "!" }, + { """, "\"" }, + { "#", "#" }, + { "$", "$" }, + { "%", "%" }, + { "&", "&" }, + { "'", "'" }, + { "(", "(" }, + { ")", ")" }, + { "*", "*" }, + { "+", "+" }, + { ",", "," }, + { "-", "-" }, + { ".", "." }, + { "/", "/" }, + // numbers.... + { ":", ":" }, + { ";", ";" }, + { "<", "<" }, + { "=", "=" }, + { ">", ">" }, + { "?", "?" }, + { "@", "@" }, + // letters... + { "[", "[" }, + { "\", "\\" }, + { "]", "]" }, + { "^", "^" }, + { "_", "_" }, + { "`", "`" }, + //letters... + { "{", "{" }, + { "|", "|" }, + { "}", "}" }, + { "~", "~" }, + { "€", "?" }, + { "‚", "," }, + { "ƒ", "?" }, + { "„", "\"" }, + { "…", "?" }, + { "†", "?" }, + { "‡", "?" }, + { "‰", "?" }, + { "Š", "?" }, + { "‹", "<" }, + { "Œ", "?" }, + { "Ž", "?" }, + { "‘", "'" }, + { "’", "'" }, + { "“", "\"" }, + { "”", "\"" }, + { "•", "*" }, + { "–", "-" }, + { "—", "-" }, + { "˜", "~" }, + { "™", "?" }, + { "š", "?" }, + { "›", ">" }, + { "œ", "?" }, + { "ž", "?" }, + { "Ÿ", "?" }, + { "¡", "?" }, + { "¢", "?" }, + { "£", "?" }, + { "¤", "?" }, + { "¥", "?" }, + { "¦", "?" }, + { "§", "?" }, + { "¨", "?" }, + { "©", "" }, + { "ª", "?" }, + { "«", "?" }, + { "¬", "?" }, + { "®", "?" }, + { "¯", "?" }, + { "°", "" }, + { "±", "?" }, + { "²", "" }, + { "³", "?" }, + { "´", "?" }, + { "µ", "?" }, + { "¶", "?" }, + { "·", "" }, + { "¸", "?" }, + { "¹", "?" }, + { "º", "?" }, + { "»", "?" }, + { "¼", "?" }, + { "½", "?" }, + { "¾", "?" } + +}; + + +void decode(QString& url) +{ + if( (int)url.find('&') != -1) + { + for(int i = 0; i != NUMBER_OF_HTML_CODES; ++i) + { + int index = url.find(htmlDocCharset[i][0]); + if(index != - 1) + { + url.replace(htmlDocCharset[i][0], htmlDocCharset[i][1]); + } + } + } +} +/* +void decode(string& url) +{ + if( (int)url.find('&') != -1) + { + for(int i = 0; i != NUMBER_OF_HTML_CODES; ++i) + { + int index = url.find(htmlDocCharset[i][0].latin1()); + if(index != - 1) + { + int length = htmlDocCharset[i][0].length(); + url.replace(index, length, htmlDocCharset[i][1].latin1()); + } + } + } +} +*/ +int smallerUnsigned(int a, int b) +{ + if(a >= 0 && b >= 0) + { + if(a < b) + return -1; + else if(a > b) + return 1; + else + return 0; + } + + else if(a < 0 && b < 0) + return 0; + + else if(a < 0) + return 1; + + else + return -1; +} + +namespace FileManager +{ +QString read(QString const& path) +{ + QFile file(path); + + if(!file.open(IO_ReadOnly)) + { + kdDebug() << "File " << path << " not found." << endl; + return QString(); + } + + QTextStream stream(&file); + QString fileString = stream.read(); + + file.close(); + + return fileString; +} +} |