예제 #1
0
/*!
 * Получение канала из URL адреса.
 */
ClientChannel ChatUrls::channel(const QUrl &url)
{
  ClientChannel channel;
  if (url.scheme() != LS("chat") && url.host() != LS("channel"))
    return channel;

  QStringList path = ChatUrls::path(url);
  if (path.isEmpty())
    return channel;

  QByteArray id = SimpleID::decode(path.at(0).toLatin1());
  if (!Channel::isCompatibleId(id))
    return channel;

  channel = ChatClient::channels()->get(id);
  if (channel)
    return channel;

  channel = ClientChannel(new Channel(id, ChatId::fromBase32(QUrlQuery(url).queryItemValue(LS("name")).toLatin1())));
  channel->gender().setRaw(QUrlQuery(url).queryItemValue(LS("gender")).toInt());
  if (!channel->isValid())
    return ClientChannel();

  return channel;
}
예제 #2
0
void ChatUrls::openChannelUrl(const QUrl &url)
{
  QStringList actions = ChatUrls::actions(url);
  if (actions.isEmpty())
    return;

  ClientChannel channel = ChatUrls::channel(url);
  if (!channel)
    return;

  QString action = actions.first();

  if (action == LS("open")) {
    ChatNotify::start(Notify::OpenChannel, channel->id());
  }
  else if (action == LS("info")) {
    ChatNotify::start(Notify::OpenInfo, channel->id());
  }
  else if (action == LS("insert")) {
    ChatNotify::start(Notify::InsertText, QChar(QChar::Nbsp) + QString(LS("<a class=\"nick color-%1\" href=\"%2\">%3</a>"))
        .arg(Gender::colorToString(channel->gender().color()))
        .arg(url.toString())
        .arg(Qt::escape(channel->name())) + QChar(QChar::Nbsp));
  }
  else if (action == LS("edit")) {
    if (actions.size() == 1)
      return;

    if (actions.at(1) == LS("topic") && channel->type() == SimpleID::ChannelId)
      ChatNotify::start(Notify::EditTopic, channel->id());
  }
}
예제 #3
0
/*!
 * Отправка обновлённой информации о себе.
 */
ChannelPacket ChannelNotice::update(ClientChannel channel)
{
  ChannelPacket packet(new ChannelNotice(channel->id(), channel->id(), CHANNELS_UPDATE_CMD, DateTime::utc()));
  packet->setText(channel->name());
  packet->gender        = channel->gender().raw();
  packet->channelStatus = channel->status().value();
  return packet;
}
예제 #4
0
ChannelPacket ChannelNotice::info(ClientChannel channel, qint64 date)
{
  ChannelPacket packet(new ChannelNotice(channel->id(), channel->id(), CHANNELS_INFO_CMD, date ? date : DateTime::utc()));
  packet->setDirection(Server2Client);
  packet->setText(channel->name());
  packet->gender        = channel->gender().raw();
  packet->channelStatus = channel->status().value();
  return packet;
}
예제 #5
0
/*!
 * Иконка канала.
 */
QIcon ChatIcons::icon(ClientChannel channel, int options)
{
  QString file = LS(":/images/channel.png");

  if (channel->type() == ChatId::UserId || channel->id().isEmpty()) {
    file = LS(":/images/user");
    int gender = channel->gender().value();
    int color  = channel->gender().color();

    if (gender == Gender::Unknown) {
      file += LS("-unknown");
    }
    else if (gender == Gender::Ghost) {
      file += LS("-ghost");
    }
    else if (gender == Gender::Bot) {
      file += LS("-bot");
    }
    else if (color != Gender::Default) {
      file += LS("-") + Gender::colorToString(color);
    }

    if (gender == Gender::Female)
      file += LS("-female");

    file += LS(".png");
  }
  else if (channel->type() == ChatId::ChannelId && channel->gender().color() == Gender::Green) {
    file = LS(":/images/secure.png");
  }

  const Status& status = channel->status();
  if (options & OfflineStatus && status.value() == Status::Offline && !(options & Statuses))
    options |= Statuses;

  if (options & Statuses) {
    if (options & OfflineStatus && (status.value() == Status::Offline || !channel->isSynced()))
      return QIcon(QIcon(file).pixmap(16, 16, QIcon::Disabled));

    return ChatIcons::icon(file, overlay(status.value()));
  }

  return QIcon(file);
}
예제 #6
0
/*!
 * Сообщение о выходе пользователя из чата.
 */
ServiceMessage ServiceMessage::quit(const QByteArray &user)
{
  QString text;
  ClientChannel channel = ChatClient::channels()->get(user);

  if (channel) {
    if (channel->gender().value() == Gender::Female)
      text = tr("has quit chat", "Female");
    else
      text = tr("has quit chat", "Male");
  }

  return ServiceMessage(text, user);
}
예제 #7
0
/*!
 * Формирование пакета для отправки клиенту заголовка канала.
 *
 * \param channel Канал.
 * \param dest    Идентификатор получателя.
 * \param command Команда.
 */
ChannelPacket ChannelNotice::channel(ClientChannel channel, const QByteArray &dest, const QString &command)
{
  ChannelPacket packet(new ChannelNotice(channel->id(), dest, command, DateTime::utc()));
  packet->setDirection(Server2Client);
  packet->setText(channel->name());
  packet->gender        = channel->gender().raw();
  packet->channelStatus = channel->status().value();
//  packet.setData(channel->feeds().headers(0));

  if (channel->type() == SimpleID::ChannelId)
    packet->channels = channel->channels().all();

  return packet;
}
예제 #8
0
/*!
 * Получение идентификатора пользователя из менеджера сетей
 * и установка базовых данных из настроек.
 */
QByteArray Networks::id() const
{
  ClientChannel channel = ChatClient::channel();
  channel->setName(ChatCore::settings()->value("Profile/Nick").toString());
  channel->gender().setRaw(ChatCore::settings()->value("Profile/Gender").toInt());
  channel->status().set(ChatCore::settings()->value("Profile/Status").toInt());

  Network item = ChatCore::networks()->item(ChatCore::networks()->selected());
  if (!item->isValid())
    return QByteArray();

  channel->setId(item->userId());

  return channel->id();
}
예제 #9
0
/*!
 * Преобразует канал в URL адрес.
 *
 * \param channel Указатель на канал.
 * \param action  Действие над каналом.
 */
QUrl ChatUrls::toUrl(ClientChannel channel, const QString &action)
{
  QUrl out(LS("chat://channel"));
  out.setPath(SimpleID::encode(channel->id()) + (action.isEmpty() ? QString() : "/" + action));

  QList<QPair<QString, QString> > queries;
  queries.append(QPair<QString, QString>(LS("name"),   ChatId::toBase32(channel->name().toUtf8())));
  queries.append(QPair<QString, QString>(LS("gender"), QString::number(channel->gender().raw())));

# if QT_VERSION >= 0x050000
  QUrlQuery query;
  query.setQueryItems(queries);
  out.setQuery(query);
# else
  out.setQueryItems(queries);
# endif

  return out;
}
예제 #10
0
bool UrlFilter::filter(QList<HtmlToken> &tokens, int options) const
{
    Q_UNUSED(options)

    QString name;

    for (int i = 0; i < tokens.size(); ++i) {
        const HtmlToken &token = tokens.at(i);
        if (token.type == HtmlToken::StartTag && token.tag == LS("a")) {
            HtmlATag tag(tokens.at(i));

            if (tag.url.startsWith(LS("chat://channel/"))) {
                tag.classes = LS("nick");
                ClientChannel user = ChatUrls::channel(QUrl(tag.url));
                if (user) {
                    tag.classes += LC(' ') + SimpleID::encode(user->id());
                    name = user->name();

                    tag.classes += LS(" color-") + Gender::colorToString(user->gender().color());
                }

                tokens[i].text = tag.toText();
            }
            else if (tag.title.isEmpty()) {
                tag.title = tag.url;
                tokens[i].text = tag.toText();
            }
        }
        else if (token.type == HtmlToken::Text && !name.isEmpty()) {
            tokens[i].text = Qt::escape(name);
            name.clear();
        }
    }

    return true;
}