File indexing completed on 2024-03-24 15:48:01

0001 /* This file is part of the KDEproject
0002    Copyright (C) 2000 David Faure <faure@kde.org>
0003                  2000 Carsten Pfeiffer <pfeiffer@kde.org>
0004 
0005    This library is free software; you can redistribute it and/or
0006    modify it under the terms of the GNU Library General Public
0007    License version 2 as published by the Free Software Foundation.
0008 
0009    This library is distributed in the hope that it will be useful,
0010    but WITHOUT ANY WARRANTY; without even the implied warranty of
0011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0012    Library General Public License for more details.
0013 
0014    You should have received a copy of the GNU Library General Public License
0015    along with this library; see the file COPYING.LIB.  If not, write to
0016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0017    Boston, MA 02110-1301, USA.
0018 */
0019 
0020 #include "filetreeviewitem.h"
0021 
0022 #include <kfileitem.h>
0023 
0024 #include "filetreeview.h"
0025 
0026 
0027 FileTreeViewItem::FileTreeViewItem(FileTreeViewItem *parent,
0028                                    const KFileItem &fi,
0029                                    FileTreeBranch *branch)
0030     : QTreeWidgetItem(parent)
0031 {
0032     init(fi, branch);
0033     setFlags(flags() | Qt::ItemIsEditable);     // non-top level items are editable
0034 }
0035 
0036 FileTreeViewItem::FileTreeViewItem(FileTreeView *parent,
0037                                    const KFileItem &fi,
0038                                    FileTreeBranch *branch)
0039     : QTreeWidgetItem(parent)
0040 {
0041     init(fi, branch);
0042 }                           // top level item is not editable
0043 
0044 void FileTreeViewItem::init(const KFileItem &fi, FileTreeBranch *branch)
0045 {
0046     m_kfileitem = fi;
0047     m_branch = branch;
0048     m_wasListed = false;
0049 
0050     setIcon(0, QIcon::fromTheme(fi.iconName()));
0051     setText(0, fi.text());
0052 }
0053 
0054 bool FileTreeViewItem::alreadyListed() const
0055 {
0056     return (m_wasListed);
0057 }
0058 
0059 void FileTreeViewItem::setListed(bool wasListed)
0060 {
0061     m_wasListed = wasListed;
0062 }
0063 
0064 QUrl FileTreeViewItem::url() const
0065 {
0066     return (!m_kfileitem.isNull() ? m_kfileitem.url() : QUrl());
0067 }
0068 
0069 void FileTreeViewItem::setUrl(const QUrl &url)
0070 {
0071     if (!m_kfileitem.isNull()) {
0072         m_kfileitem.setUrl(url);
0073     }
0074 }
0075 
0076 QString FileTreeViewItem::path() const
0077 {
0078     return (!m_kfileitem.isNull() ? m_kfileitem.url().path() : QString());
0079 }
0080 
0081 bool FileTreeViewItem::isDir() const
0082 {
0083     return (!m_kfileitem.isNull() ? m_kfileitem.isDir() : false);
0084 }
0085 
0086 bool FileTreeViewItem::isRoot() const
0087 {
0088     return (this == m_branch->root());
0089 }