File indexing completed on 2024-06-09 04:42:37

0001 /*
0002  * SPDX-FileCopyrightText: 2020 George Florea Bănuș <georgefb899@gmail.com>
0003  *
0004  * SPDX-License-Identifier: GPL-3.0-or-later
0005  */
0006 
0007 //#include "_debug.h"
0008 #include "subtitlesfoldersmodel.h"
0009 //#include "subtitlessettings.h"
0010 
0011 
0012 
0013 SubtitlesFoldersModel::SubtitlesFoldersModel(QObject *parent)
0014     : QAbstractListModel(parent)
0015 {
0016 //    m_config = KSharedConfig::openConfig("georgefb/haruna.conf");
0017 //    m_list = m_config->group("Subtitles").readPathEntry("Folders", QStringList());
0018 }
0019 
0020 int SubtitlesFoldersModel::rowCount(const QModelIndex &parent) const
0021 {
0022     // For list models only the root node (an invalid parent) should return the list's size. For all
0023     // other (valid) parents, rowCount() should return 0 so that it does not become a tree model.
0024     if (parent.isValid())
0025         return 0;
0026 
0027     return m_list.size();
0028 }
0029 
0030 QVariant SubtitlesFoldersModel::data(const QModelIndex &index, int role) const
0031 {
0032     if (!index.isValid())
0033         return QVariant();
0034 
0035 
0036     QString path = m_list[index.row()];
0037 
0038     switch (role) {
0039     case Qt::DisplayRole:
0040         return QVariant(path);
0041     }
0042 
0043     return QVariant();
0044 }
0045 
0046 void SubtitlesFoldersModel::updateFolder(const QString &folder, int row)
0047 {
0048     m_list.replace(row, folder);
0049     QStringList newList = m_list;
0050     // remove empty strings
0051     // removing directly from m_list messes with the ui logic
0052     newList.removeAll(QString(""));
0053 
0054 //    SubtitlesSettings::self()->setSubtitlesFolders(newList);
0055 //    SubtitlesSettings::self()->save();
0056 }
0057 
0058 void SubtitlesFoldersModel::deleteFolder(int row)
0059 {
0060     beginRemoveRows(QModelIndex(), row, row);
0061     m_list.removeAt(row);
0062     endRemoveRows();
0063 //    m_config->group("Subtitles").writePathEntry("Folders", m_list);
0064 //    m_config->sync();
0065 }
0066 
0067 void SubtitlesFoldersModel::addFolder()
0068 {
0069     beginInsertRows(QModelIndex(), m_list.size(), m_list.size());
0070     m_list.append(QStringLiteral());
0071     endInsertRows();
0072 }