InboxModel.cpp 922 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /*
  2. * Copyright (c) 2021, Luke Wilde <lukew@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include "InboxModel.h"
  7. InboxModel::InboxModel(Vector<InboxEntry> entries)
  8. : m_entries(move(entries))
  9. {
  10. }
  11. InboxModel::~InboxModel()
  12. {
  13. }
  14. int InboxModel::row_count(GUI::ModelIndex const&) const
  15. {
  16. return m_entries.size();
  17. }
  18. String InboxModel::column_name(int column_index) const
  19. {
  20. switch (column_index) {
  21. case Column::From:
  22. return "From";
  23. case Subject:
  24. return "Subject";
  25. default:
  26. VERIFY_NOT_REACHED();
  27. }
  28. }
  29. GUI::Variant InboxModel::data(GUI::ModelIndex const& index, GUI::ModelRole role) const
  30. {
  31. auto& value = m_entries[index.row()];
  32. if (role == GUI::ModelRole::Display) {
  33. if (index.column() == Column::From)
  34. return value.from;
  35. if (index.column() == Column::Subject)
  36. return value.subject;
  37. }
  38. return {};
  39. }