File indexing completed on 2024-02-25 16:46:59

0001 // SPDX-FileCopyrightText: 2023 Joshua Goins <josh@redstrate.com>
0002 // SPDX-License-Identifier: GPL-3.0-or-later
0003 
0004 #include "polltimemodel.h"
0005 
0006 #include <KLocalizedString>
0007 
0008 PollTimeModel::PollTimeModel(QObject *parent)
0009     : QAbstractListModel(parent)
0010 {
0011     m_times = {
0012         {i18nc("@item:inlistbox Poll expire times", "5 minutes"), 300},
0013         {i18nc("@item:inlistbox Poll expire times", "30 minutes"), 1800},
0014         {i18nc("@item:inlistbox Poll expire times", "1 hour"), 3600},
0015         {i18nc("@item:inlistbox Poll expire times", "6 hours"), 26000},
0016         {i18nc("@item:inlistbox Poll expire times", "12 hours"), 43200},
0017         {i18nc("@item:inlistbox Poll expire times", "1 day"), 86400},
0018         {i18nc("@item:inlistbox Poll expire times", "3 days"), 259200},
0019         {i18nc("@item:inlistbox Poll expire times", "7 days"), 604800},
0020     };
0021 }
0022 
0023 QVariant PollTimeModel::data(const QModelIndex &index, int role) const
0024 {
0025     if (!index.isValid())
0026         return {};
0027 
0028     if (index.row() < 0 || index.row() >= m_times.size())
0029         return {};
0030 
0031     switch (role) {
0032     case CustomRoles::TextRole:
0033         return m_times[index.row()].name;
0034     case CustomRoles::TimeRole:
0035         return m_times[index.row()].time;
0036     default:
0037         return {};
0038     }
0039 }
0040 
0041 int PollTimeModel::rowCount(const QModelIndex &parent) const
0042 {
0043     Q_UNUSED(parent);
0044     return m_times.count();
0045 }
0046 
0047 QHash<int, QByteArray> PollTimeModel::roleNames() const
0048 {
0049     return {
0050         {CustomRoles::TextRole, "text"},
0051         {CustomRoles::TimeRole, "time"},
0052     };
0053 }
0054 
0055 int PollTimeModel::getTime(const int index)
0056 {
0057     return m_times[index].time;
0058 }