IRCWindowListModel.cpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #include "IRCWindowListModel.h"
  2. #include "IRCChannel.h"
  3. #include "IRCClient.h"
  4. #include "IRCWindow.h"
  5. #include <stdio.h>
  6. #include <time.h>
  7. IRCWindowListModel::IRCWindowListModel(IRCClient& client)
  8. : m_client(client)
  9. {
  10. }
  11. IRCWindowListModel::~IRCWindowListModel()
  12. {
  13. }
  14. int IRCWindowListModel::row_count(const GModelIndex&) const
  15. {
  16. return m_client.window_count();
  17. }
  18. int IRCWindowListModel::column_count(const GModelIndex&) const
  19. {
  20. return 1;
  21. }
  22. String IRCWindowListModel::column_name(int column) const
  23. {
  24. switch (column) {
  25. case Column::Name:
  26. return "Name";
  27. }
  28. ASSERT_NOT_REACHED();
  29. }
  30. GModel::ColumnMetadata IRCWindowListModel::column_metadata(int column) const
  31. {
  32. switch (column) {
  33. case Column::Name:
  34. return { 70, TextAlignment::CenterLeft };
  35. }
  36. ASSERT_NOT_REACHED();
  37. }
  38. GVariant IRCWindowListModel::data(const GModelIndex& index, Role role) const
  39. {
  40. if (role == Role::Display) {
  41. switch (index.column()) {
  42. case Column::Name: {
  43. auto& window = m_client.window_at(index.row());
  44. if (window.unread_count())
  45. return String::format("%s (%d)", window.name().characters(), window.unread_count());
  46. return window.name();
  47. }
  48. }
  49. }
  50. if (role == Role::ForegroundColor) {
  51. switch (index.column()) {
  52. case Column::Name: {
  53. auto& window = m_client.window_at(index.row());
  54. if (window.unread_count())
  55. return Color(Color::Red);
  56. if (!window.channel().is_open())
  57. return Color(Color::LightGray);
  58. return Color(Color::Black);
  59. }
  60. }
  61. }
  62. return {};
  63. }
  64. void IRCWindowListModel::update()
  65. {
  66. did_update();
  67. }