IRCChannelMemberListModel.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include "IRCChannelMemberListModel.h"
  7. #include "IRCChannel.h"
  8. #include <stdio.h>
  9. #include <time.h>
  10. IRCChannelMemberListModel::IRCChannelMemberListModel(IRCChannel& channel)
  11. : m_channel(channel)
  12. {
  13. }
  14. IRCChannelMemberListModel::~IRCChannelMemberListModel()
  15. {
  16. }
  17. int IRCChannelMemberListModel::row_count(const GUI::ModelIndex&) const
  18. {
  19. return m_channel.member_count();
  20. }
  21. int IRCChannelMemberListModel::column_count(const GUI::ModelIndex&) const
  22. {
  23. return 1;
  24. }
  25. String IRCChannelMemberListModel::column_name(int column) const
  26. {
  27. switch (column) {
  28. case Column::Name:
  29. return "Name";
  30. }
  31. VERIFY_NOT_REACHED();
  32. }
  33. GUI::Variant IRCChannelMemberListModel::data(const GUI::ModelIndex& index, GUI::ModelRole role) const
  34. {
  35. if (role == GUI::ModelRole::TextAlignment)
  36. return Gfx::TextAlignment::CenterLeft;
  37. if (role == GUI::ModelRole::Display) {
  38. switch (index.column()) {
  39. case Column::Name:
  40. return m_channel.member_at(index.row());
  41. }
  42. }
  43. return {};
  44. }
  45. String IRCChannelMemberListModel::nick_at(const GUI::ModelIndex& index) const
  46. {
  47. return data(index, GUI::ModelRole::Display).to_string();
  48. }