File indexing completed on 2024-05-19 15:44:21
0001 /* 0002 SPDX-FileCopyrightText: 2006-2007 Alexander Dymo <adymo@kdevelop.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "urldocument.h" 0008 0009 #include <QIcon> 0010 #include <QWidget> 0011 0012 #include <KTextEdit> 0013 #include <KLocalizedString> 0014 #include <KIO/Global> 0015 0016 namespace Sublime { 0017 0018 // class UrlDocumentPrivate 0019 0020 class UrlDocumentPrivate 0021 { 0022 public: 0023 QUrl url; 0024 }; 0025 0026 0027 0028 // class UrlDocument 0029 0030 UrlDocument::UrlDocument(Controller *controller, const QUrl &url) 0031 : Document(url.fileName(), controller) 0032 , d_ptr(new UrlDocumentPrivate()) 0033 { 0034 setUrl(url); 0035 } 0036 0037 UrlDocument::~UrlDocument() = default; 0038 0039 QUrl UrlDocument::url() const 0040 { 0041 Q_D(const UrlDocument); 0042 0043 return d->url; 0044 } 0045 0046 void UrlDocument::setUrl(const QUrl& newUrl) 0047 { 0048 Q_D(UrlDocument); 0049 0050 Q_ASSERT(newUrl.adjusted(QUrl::NormalizePathSegments) == newUrl); 0051 d->url = newUrl; 0052 // remote URLs might not have a file name 0053 Q_ASSERT(!newUrl.fileName().isEmpty() || !newUrl.isLocalFile()); 0054 auto title = newUrl.fileName(); 0055 if (title.isEmpty()) { 0056 title = i18n("Untitled"); 0057 } 0058 setTitle(title); 0059 setToolTip(newUrl.toDisplayString(QUrl::PreferLocalFile)); 0060 } 0061 0062 QWidget *UrlDocument::createViewWidget(QWidget *parent) 0063 { 0064 ///@todo adymo: load file contents here 0065 return new KTextEdit(parent); 0066 } 0067 0068 QString UrlDocument::documentType() const 0069 { 0070 return QStringLiteral("Url"); 0071 } 0072 0073 QString UrlDocument::documentSpecifier() const 0074 { 0075 Q_D(const UrlDocument); 0076 0077 return d->url.url(); 0078 } 0079 0080 QIcon UrlDocument::defaultIcon() const 0081 { 0082 Q_D(const UrlDocument); 0083 0084 return QIcon::fromTheme(KIO::iconNameForUrl(d->url)); 0085 } 0086 0087 QString UrlDocument::title(TitleType type) const 0088 { 0089 if (type == Extended) 0090 return Document::title() + QLatin1String(" (") + url().toDisplayString(QUrl::PreferLocalFile) + QLatin1Char(')'); 0091 else 0092 return Document::title(); 0093 } 0094 0095 } 0096 0097 #include "moc_urldocument.cpp"