Warning, file /maui/index-fm/src/models/pathlist.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /*
0002  * <one line to give the program's name and a brief idea of what it does.>
0003  * Copyright (C) 2019  camilo <chiguitar@unal.edu.co>
0004  *
0005  * This program is free software: you can redistribute it and/or modify
0006  * it under the terms of the GNU General Public License as published by
0007  * the Free Software Foundation, either version 3 of the License, or
0008  * (at your option) any later version.
0009  *
0010  * This program is distributed in the hope that it will be useful,
0011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0013  * GNU General Public License for more details.
0014  *
0015  * You should have received a copy of the GNU General Public License
0016  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
0017  */
0018 
0019 #include "pathlist.h"
0020 #include <QDebug>
0021 
0022 PathList::PathList(QObject *parent) : MauiList(parent)
0023 {
0024 }
0025 
0026 void PathList::componentComplete()
0027 {
0028   connect(this, &PathList::pathChanged, this, &PathList::setList);
0029   this->setList();
0030 }
0031 
0032 QString PathList::getPath() const
0033 {
0034   return this->m_path;
0035 }
0036 
0037 const FMH::MODEL_LIST &PathList::items() const
0038 {
0039   return this->list;
0040 }
0041 
0042 void PathList::setList()
0043 {
0044   const auto paths = PathList::splitPath(m_path);
0045 
0046   Q_EMIT this->preListChanged();
0047   this->list = paths;
0048   Q_EMIT this->postListChanged();
0049 
0050   Q_EMIT this->countChanged();
0051 }
0052 
0053 void PathList::setPath(const QString &path)
0054 {
0055   if (path == this->m_path)
0056     return;
0057 
0058   this->m_path = path;
0059   Q_EMIT this->pathChanged();
0060 }
0061 
0062 FMH::MODEL_LIST PathList::splitPath(const QString &path)
0063 {
0064   FMH::MODEL_LIST res;
0065 
0066   QString _url = path;
0067 
0068   while (_url.endsWith("/"))
0069     {
0070       _url.chop(1);
0071     }
0072 
0073   _url += "/";
0074 
0075   const auto count = _url.count("/");
0076 
0077   for (auto i = 0; i < count; i++)
0078     {
0079       _url = QString(_url).left(_url.lastIndexOf("/"));
0080       auto label = QString(_url).right(_url.length() - _url.lastIndexOf("/") - 1);
0081 
0082       if (label.isEmpty())
0083         continue;
0084 
0085       if (label.contains(":") && i == count - 1) // handle the protocol
0086         {
0087           res << FMH::MODEL {{FMH::MODEL_KEY::LABEL, "/"}, {FMH::MODEL_KEY::PATH, _url + "///"}};
0088           break;
0089         }
0090 
0091       res << FMH::MODEL {{FMH::MODEL_KEY::LABEL, label}, {FMH::MODEL_KEY::PATH, _url}};
0092     }
0093   std::reverse(res.begin(), res.end());
0094   return res;
0095 }