File indexing completed on 2025-01-26 05:24:14

0001 /*
0002     This file is part of the Kasten Framework, made within the KDE community.
0003 
0004     SPDX-FileCopyrightText: 2009, 2011 Friedrich W. H. Kossebau <kossebau@kde.org>
0005 
0006     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0007 */
0008 
0009 #include "filesystembrowsertool.hpp"
0010 
0011 // Kasten core
0012 #include <Kasten/DocumentSyncManager>
0013 #include <Kasten/Versionable>
0014 #include <Kasten/AbstractDocument>
0015 #include <Kasten/AbstractModelSynchronizer>
0016 
0017 // KF
0018 #include <KLocalizedString>
0019 #include <KIO/Global>
0020 
0021 #include <QUrl>
0022 
0023 namespace Kasten {
0024 
0025 FileSystemBrowserTool::FileSystemBrowserTool(DocumentSyncManager* documentSyncManager)
0026     : mDocumentSyncManager(documentSyncManager)
0027 {
0028     setObjectName(QStringLiteral("FileSystemBrowser"));
0029 }
0030 
0031 FileSystemBrowserTool::~FileSystemBrowserTool() = default;
0032 
0033 QString FileSystemBrowserTool::title() const { return i18nc("@title:window", "Filesystem"); }
0034 
0035 QUrl FileSystemBrowserTool::currentUrl() const
0036 {
0037     QUrl result;
0038 
0039     if (mDocument) {
0040         result = KIO::upUrl(mDocumentSyncManager->urlOf(mDocument));
0041     }
0042 
0043     return result;
0044 }
0045 
0046 bool FileSystemBrowserTool::hasCurrentUrl() const
0047 {
0048     return (mDocument && mDocument->synchronizer());
0049 }
0050 
0051 void FileSystemBrowserTool::setTargetModel(AbstractModel* model)
0052 {
0053     const bool oldHasCurrentUrl = hasCurrentUrl();
0054 
0055     mDocument = model ? model->findBaseModel<AbstractDocument*>() : nullptr;
0056 
0057     const bool newHasCurrentUrl = hasCurrentUrl();
0058 
0059     if (oldHasCurrentUrl != newHasCurrentUrl) {
0060         Q_EMIT hasCurrentUrlChanged(newHasCurrentUrl);
0061     }
0062 }
0063 
0064 void FileSystemBrowserTool::open(const QUrl& url)
0065 {
0066     mDocumentSyncManager->load(url);
0067 }
0068 
0069 }
0070 
0071 #include "moc_filesystembrowsertool.cpp"