File indexing completed on 2025-01-19 04:22:43

0001 /*
0002 SPDX-FileCopyrightText: 2021 Hamed Masafi <hamed.masfi@gmail.com>
0003 
0004 SPDX-License-Identifier: GPL-3.0-or-later
0005 */
0006 
0007 #include "abstractgititemsmodel.h"
0008 #include "gitmanager.h"
0009 #include <QDebug>
0010 
0011 namespace Git
0012 {
0013 
0014 AbstractGitItemsModel::AbstractGitItemsModel(Manager *git, QObject *parent)
0015     : QAbstractListModel(parent)
0016     , mGit(git)
0017 {
0018     //    connect(git, &Manager::pathChanged, this, &Cache::load);
0019 }
0020 
0021 bool AbstractGitItemsModel::isLoaded() const
0022 {
0023     return m_status == Loaded;
0024 }
0025 
0026 AbstractGitItemsModel::Status AbstractGitItemsModel::status() const
0027 {
0028     return m_status;
0029 }
0030 
0031 void AbstractGitItemsModel::load()
0032 {
0033     if (!mGit->isValid())
0034         return;
0035 
0036     setStatus(Loading);
0037     fill();
0038 }
0039 
0040 void AbstractGitItemsModel::reset()
0041 {
0042     qDebug() << "Reset model now that it is ready?";
0043     beginResetModel();
0044     setStatus(Loaded);
0045     endResetModel();
0046 }
0047 
0048 void AbstractGitItemsModel::setStatus(Status newStatus)
0049 {
0050     if (m_status == newStatus)
0051         return;
0052     m_status = newStatus;
0053 
0054     if (m_status == Loaded)
0055         Q_EMIT loaded();
0056 
0057     Q_EMIT statusChanged();
0058 }
0059 
0060 } // namespace Git