1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
|
/*
* Copyright © 2004-2006 Jens Oknelid, paskharen@gmail.com
*
* 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 "WulforUtil.hh"
#include <client/ClientManager.h>
vector<int> WulforUtil::splitString(const string &str, const string &delimiter)
{
string::size_type loc, len, pos = 0;
vector<int> array;
if (!str.empty())
{
while ((loc = str.find(delimiter, pos)) != string::npos)
{
len = loc - pos;
array.push_back(Util::toInt(str.substr(pos, len)));
pos = loc + delimiter.size();
}
len = str.size() - pos;
array.push_back(Util::toInt(str.substr(pos, len)));
}
return array;
}
string WulforUtil::linuxSeparator(const string &ps)
{
string str = ps;
for (string::iterator it = str.begin(); it != str.end(); ++it)
if ((*it) == '\\')
(*it) = '/';
return str;
}
string WulforUtil::windowsSeparator(const string &ps)
{
string str = ps;
for (string::iterator it = str.begin(); it != str.end(); ++it)
if ((*it) == '/')
(*it) = '\\';
return str;
}
string WulforUtil::getNicks(const CID& cid)
{
return Util::toString(ClientManager::getInstance()->getNicks(cid));
}
string WulforUtil::getNicks(const User::Ptr& user)
{
return getNicks(user->getCID());
}
/*
* @return Pair of hubnames as a string and a bool representing the user's online status
*/
pair<string, bool> WulforUtil::getHubNames(const CID& cid)
{
StringList hubs = ClientManager::getInstance()->getHubNames(cid);
if (hubs.empty())
return make_pair("Offline", false);
else
return make_pair(Util::toString(hubs), true);
}
pair<string, bool> WulforUtil::getHubNames(const User::Ptr& user)
{
return getHubNames(user->getCID());
}
string WulforUtil::getTextFromMenu(GtkMenuItem *item)
{
string text;
GtkWidget *child = gtk_bin_get_child(GTK_BIN(item));
if (child && GTK_IS_LABEL(child))
text = gtk_label_get_text(GTK_LABEL(child));
return text;
}
|