コード例 #1
0
ファイル: ChatUrls.cpp プロジェクト: johnbolia/schat
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());
  }
}
コード例 #2
0
ファイル: ChannelNotice.cpp プロジェクト: johnbolia/schat
/*!
 * Отправка обновлённой информации о себе.
 */
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;
}
コード例 #3
0
ファイル: ChannelNotice.cpp プロジェクト: johnbolia/schat
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;
}
コード例 #4
0
ファイル: TabWidget.cpp プロジェクト: Artanomell/schat
/*!
 * Создание или повторная инициализация вкладки канала.
 *
 * \param id     Идентификатор канала.
 * \param create \b true если необходимо создать канал.
 * \param show   \b true если необходимо выбрать эту вкладку.
 *
 * \return Возвращает указатель на вкладку или 0 в случае ошибки.
 */
ChannelBaseTab *TabWidget::channelTab(const QByteArray &id, bool create, bool show)
{
  SLOG_DEBUG("id =" << SimpleID::encode(id) << "create =" << create << "show =" << show);

  if (!Channel::isCompatibleId(id))
    return 0;

  ChannelBaseTab *tab = 0;

  if (m_channels.contains(id)) {
    tab = m_channels.value(id);
    create = false;
  }

  ClientChannel channel = ChatClient::channels()->get(id);
  if (!channel) {
    if (!m_prefetch.contains(id))
      m_prefetch.append(id);

    return 0;
  }

  if (create) {
    if (channel->type() == SimpleID::UserId)
      tab = new PrivateTab(channel, this);
    else if (channel->type() == SimpleID::ChannelId)
      tab = new ChannelTab(channel, this);

    if (tab) {
      m_channels[id] = tab;
      tab->setOnline();
      addTab(tab, tab->icon(), channel->name());
      connect(tab, SIGNAL(actionTriggered(bool)), SLOT(openTab()));

      if (channel->type() == SimpleID::ChannelId && isAutoPin(channel->id()))
        tab->pin();

      if (m_autoPin.contains(id)) {
        m_autoPin.removeAll(id);
        tab->pin();
        emit pinned(tab);
      }
    }

    closePage(PROGRESS_TAB);
    closePage(WELCOME_TAB);
  }

  if (show && tab)
    setCurrentIndex(indexOf(tab));

  return tab;
}
コード例 #5
0
ファイル: UserItem.cpp プロジェクト: Artanomell/schat
UserItem::UserItem(ClientChannel user, ClientChannel channel)
  : QStandardItem()
  , m_bold(false)
  , m_italic(false)
  , m_self(false)
  , m_underline(false)
  , m_channel(channel)
  , m_user(user)
{
  m_self = ChatClient::id() == user->id();

  reload();
}
コード例 #6
0
ファイル: ChannelNotice.cpp プロジェクト: johnbolia/schat
/*!
 * Формирование пакета для отправки клиенту заголовка канала.
 *
 * \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;
}
コード例 #7
0
ファイル: ChatHooks.cpp プロジェクト: youngdev/schat
/*!
 * Получение идентификатора пользователя из менеджера сетей
 * и установка базовых данных из настроек.
 */
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();
}
コード例 #8
0
ファイル: ChatIcons.cpp プロジェクト: Artanomell/schat
/*!
 * Иконка канала.
 */
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);
}
コード例 #9
0
ファイル: ChatUrls.cpp プロジェクト: johnbolia/schat
/*!
 * Преобразует канал в 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
ファイル: UrlFilter.cpp プロジェクト: johnbolia/schat
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;
}