void
{
if (name() != channel) {
return;
}
enum {
None,
Give,
Take
};
int state = None;
Aki::Irc::User *user = 0;
//Aki::Irc::User *user = d->userList->model()->data(d->userList->currentIndex(), NickListModel::IrcUserRole)
// .value<Aki::Irc::User*>();
for (int i = 0; i < d->userList->count(); ++i) {
index = d->userList->model()->index(i, 0);
user = d->userList->model()->data(index, NickListModel::IrcUserRole).value<Aki::Irc::User*>();
if (user->nick() == nick) {
kDebug() << "found";
break;
}
}
if (!user) {
return;
}
bool fromYou = from == d->socket->currentNick();
bool toYou = nick == d->socket->currentNick();
foreach
(QChar c, mode
) { state = Give;
kDebug() << "Give";
} else if (c
== QChar('-')) { state = Take;
kDebug() << "Take";
} else if (c
== QChar('o')) { if (state == Give) {
user->setModes(modes + c);
d->userList->model()->setData(d->userList->currentIndex(),
QVariant::fromValue<Aki
::Irc::User*>
(user
),
NickListModel::IrcUserRole);
d->channelOutput->addMode(from, nick, c, toYou, fromYou);
} else if (state == Take) {
user->removeModes(c);
d->userList->model()->setData(d->userList->currentIndex(),
QVariant::fromValue<Aki
::Irc::User*>
(user
),
NickListModel::IrcUserRole);
d->channelOutput->addRemoveMode(from, nick, c, toYou, fromYou);
}
} else if (c
== QChar('v')) { if (state == Give) {
user->setModes(modes + c);
d->userList->model()->setData(d->userList->currentIndex(),
QVariant::fromValue<Aki
::Irc::User*>
(user
),
NickListModel::IrcUserRole);
d->channelOutput->addMode(from, nick, c, toYou, fromYou);
} else if (state == Take) {
user->removeModes(c);
d->userList->model()->setData(d->userList->currentIndex(),
QVariant::fromValue<Aki
::Irc::User*>
(user
),
NickListModel::IrcUserRole);
d->channelOutput->addRemoveMode(from, nick, c, toYou, fromYou);
}
} else if (c
== QChar('h')) { if (state == Give) {
user->setModes(modes + c);
d->userList->model()->setData(d->userList->currentIndex(),
QVariant::fromValue<Aki
::Irc::User*>
(user
),
NickListModel::IrcUserRole);
d->channelOutput->addMode(from, nick, c, toYou, fromYou);
} else if (state == Take) {
user->removeModes(c);
d->userList->model()->setData(d->userList->currentIndex(),
QVariant::fromValue<Aki
::Irc::User*>
(user
),
NickListModel::IrcUserRole);
d->channelOutput->addRemoveMode(from, nick, c, toYou, fromYou);
}
}
}
}
void
ChannelTab::slotOnMode(const QString &from, const QString &channel, const QString &mode, const QString &nick)
{
if (name() != channel) {
return;
}
enum {
None,
Give,
Take
};
int state = None;
QModelIndex index;
Aki::Irc::User *user = 0;
//Aki::Irc::User *user = d->userList->model()->data(d->userList->currentIndex(), NickListModel::IrcUserRole)
// .value<Aki::Irc::User*>();
for (int i = 0; i < d->userList->count(); ++i) {
index = d->userList->model()->index(i, 0);
user = d->userList->model()->data(index, NickListModel::IrcUserRole).value<Aki::Irc::User*>();
if (user->nick() == nick) {
kDebug() << "found";
break;
}
}
if (!user) {
return;
}
QString modes = user->modes();
bool fromYou = from == d->socket->currentNick();
bool toYou = nick == d->socket->currentNick();
foreach (QChar c, mode) {
if (c == QChar('+')) {
state = Give;
kDebug() << "Give";
} else if (c == QChar('-')) {
state = Take;
kDebug() << "Take";
} else if (c == QChar('o')) {
if (state == Give) {
user->setModes(modes + c);
d->userList->model()->setData(d->userList->currentIndex(),
QVariant::fromValue<Aki::Irc::User*>(user),
NickListModel::IrcUserRole);
d->channelOutput->addMode(from, nick, c, toYou, fromYou);
} else if (state == Take) {
user->removeModes(c);
d->userList->model()->setData(d->userList->currentIndex(),
QVariant::fromValue<Aki::Irc::User*>(user),
NickListModel::IrcUserRole);
d->channelOutput->addRemoveMode(from, nick, c, toYou, fromYou);
}
} else if (c == QChar('v')) {
if (state == Give) {
user->setModes(modes + c);
d->userList->model()->setData(d->userList->currentIndex(),
QVariant::fromValue<Aki::Irc::User*>(user),
NickListModel::IrcUserRole);
d->channelOutput->addMode(from, nick, c, toYou, fromYou);
} else if (state == Take) {
user->removeModes(c);
d->userList->model()->setData(d->userList->currentIndex(),
QVariant::fromValue<Aki::Irc::User*>(user),
NickListModel::IrcUserRole);
d->channelOutput->addRemoveMode(from, nick, c, toYou, fromYou);
}
} else if (c == QChar('h')) {
if (state == Give) {
user->setModes(modes + c);
d->userList->model()->setData(d->userList->currentIndex(),
QVariant::fromValue<Aki::Irc::User*>(user),
NickListModel::IrcUserRole);
d->channelOutput->addMode(from, nick, c, toYou, fromYou);
} else if (state == Take) {
user->removeModes(c);
d->userList->model()->setData(d->userList->currentIndex(),
QVariant::fromValue<Aki::Irc::User*>(user),
NickListModel::IrcUserRole);
d->channelOutput->addRemoveMode(from, nick, c, toYou, fromYou);
}
}
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks