Warning, file /office/calligra/gemini/Settings.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /* This file is part of the KDE project
0002  * SPDX-FileCopyrightText: 2012 Arjen Hiemstra <ahiemstra@heimr.nl>
0003  *
0004  * SPDX-License-Identifier: LGPL-2.0-or-later
0005  */
0006 
0007 #include "Settings.h"
0008 #include "DocumentListModel.h"
0009 
0010 #include <QApplication>
0011 #include <QUrl>
0012 #include <QMimeType>
0013 
0014 #include <KSharedConfig>
0015 #include <kconfiggroup.h>
0016 
0017 #include "Theme.h"
0018 #include "PropertyContainer.h"
0019 // #include <qtquick/CQTextDocumentCanvas.h>
0020 #include <KoDocumentEntry.h>
0021 #include <part/KWDocument.h>
0022 #include <stage/part/KPrDocument.h>
0023 
0024 class Settings::Private
0025 {
0026 public:
0027     Private() : temporaryFile(false), focusItem(0) { }
0028 
0029     QString currentFile;
0030     QString currentFileClass;
0031     bool temporaryFile;
0032     QQuickItem *focusItem;
0033     Theme* theme;
0034 };
0035 
0036 Settings::Settings( QObject* parent )
0037     : QObject( parent ), d( new Private )
0038 {
0039     QString theme = KSharedConfig::openConfig()->group("General").readEntry<QString>("theme", "default");
0040     d->theme = Theme::load(theme, this);
0041     connect(d->theme, &Theme::fontCacheRebuilt, this, &Settings::themeChanged);
0042 }
0043 
0044 Settings::~Settings()
0045 {
0046     delete d;
0047 }
0048 
0049 QString Settings::currentFile() const
0050 {
0051     return d->currentFile;
0052 }
0053 
0054 QString Settings::currentFileClass() const
0055 {
0056     return d->currentFileClass;
0057 }
0058 
0059 void Settings::setCurrentFile(const QString& fileName)
0060 {
0061     qApp->processEvents();
0062     if(fileName.isEmpty()) {
0063         d->currentFile = fileName;
0064         d->currentFileClass = "No document set, consequently no class. This is expected behaviour, do not report.";
0065         emit currentFileChanged();
0066     }
0067     else if (fileName != d->currentFile) {
0068         QUrl url(fileName);
0069         if(url.scheme() == "newfile") {
0070             QUrlQuery query(url.query());
0071             d->currentFileClass = query.queryItemValue("mimetype");
0072         }
0073         else {
0074             QMimeDatabase db;
0075             QMimeType mimeType = db.mimeTypeForUrl(url);
0076             KoDocumentEntry documentEntry = KoDocumentEntry::queryByMimeType(mimeType.name());
0077             if(documentEntry.supportsMimeType(WORDS_MIME_TYPE)) {
0078                 d->currentFileClass = WORDS_MIME_TYPE;
0079             } else if(documentEntry.supportsMimeType(STAGE_MIME_TYPE)) {
0080                 d->currentFileClass = STAGE_MIME_TYPE;
0081             } else {
0082                 d->currentFileClass = QString("Unsupported document! Reported mimetype is %1").arg(mimeType.name());
0083             }
0084         }
0085         d->currentFile = fileName;
0086         emit currentFileChanged();
0087     }
0088 }
0089 
0090 bool Settings::isTemporaryFile() const
0091 {
0092     return d->temporaryFile;
0093 }
0094 
0095 void Settings::setTemporaryFile(bool temp)
0096 {
0097     if (temp != d->temporaryFile) {
0098         d->temporaryFile = temp;
0099         emit temporaryFileChanged();
0100     }
0101 }
0102 
0103 QQuickItem* Settings::focusItem()
0104 {
0105     return d->focusItem;
0106 }
0107 
0108 void Settings::setFocusItem(QQuickItem* item)
0109 {
0110     if (item != d->focusItem) {
0111         d->focusItem = item;
0112         emit focusItemChanged();
0113     }
0114 }
0115 
0116 QObject* Settings::theme() const
0117 {
0118     return d->theme;
0119 }
0120 
0121 QString Settings::themeID() const
0122 {
0123     if(d->theme)
0124         return d->theme->id();
0125 
0126     return QString();
0127 }
0128 
0129 void Settings::setThemeID(const QString& id)
0130 {
0131     if(!d->theme || id != d->theme->id()) {
0132         if(d->theme) {
0133             delete d->theme;
0134             d->theme = 0;
0135         }
0136 
0137         d->theme = Theme::load(id, this);
0138         KSharedConfig::openConfig()->group("General").writeEntry<QString>("theme", id);
0139 
0140         emit themeChanged();
0141     }
0142 }
0143 
0144 int Settings::mimeTypeToDocumentClass(QString mimeType) const
0145 {
0146     DocumentListModel::DocumentType documentClass = DocumentListModel::UnknownType;
0147     if(mimeType == QLatin1String("application/vnd.oasis.opendocument.text") ||
0148        mimeType == QLatin1String("application/msword") ||
0149        mimeType == QLatin1String("application/rtf") ||
0150        mimeType == QLatin1String("application/vnd.openxmlformats-officedocument.wordprocessingml.document") ||
0151        mimeType == QLatin1String("application/vnd.openxmlformats-officedocument.wordprocessingml.template") ||
0152        mimeType == QLatin1String("application/vnd.ms-word.document.macroEnabled.12") ||
0153        mimeType == QLatin1String("application/vnd.ms-word.template.macroEnabled.12"))
0154     {
0155         documentClass = DocumentListModel::TextDocumentType;
0156     }
0157     else
0158     if(mimeType == QLatin1String("application/vnd.oasis.opendocument.presentation") ||
0159        mimeType == QLatin1String("application/vnd.ms-powerpoint") ||
0160        mimeType == QLatin1String("application/vnd.openxmlformats-officedocument.presentationml.presentation") ||
0161        mimeType == QLatin1String("application/vnd.openxmlformats-officedocument.presentationml.template") ||
0162        mimeType == QLatin1String("application/vnd.openxmlformats-officedocument.presentationml.slideshow") ||
0163        mimeType == QLatin1String("application/vnd.ms-powerpoint.presentation.macroEnabled.12") ||
0164        mimeType == QLatin1String("application/vnd.ms-powerpoint.template.macroEnabled.12") ||
0165        mimeType == QLatin1String("application/vnd.ms-powerpoint.slideshow.macroEnabled.12") )
0166     {
0167         documentClass = DocumentListModel::PresentationType;
0168     }
0169 //     else
0170 //     if(mimeType == QLatin1String("application/vnd.oasis.opendocument.spreadsheet") ||
0171 //        mimeType == QLatin1String("application/vnd.ms-excel") ||
0172 //        mimeType == QLatin1String("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet") ||
0173 //        mimeType == QLatin1String("application/vnd.openxmlformats-officedocument.spreadsheetml.template") ||
0174 //        mimeType == QLatin1String("application/vnd.ms-excel.sheet.macroEnabled") ||
0175 //        mimeType == QLatin1String("application/vnd.ms-excel.sheet.macroEnabled.12") ||
0176 //        mimeType == QLatin1String("application/vnd.ms-excel.template.macroEnabled.12") )
0177 //     {
0178 //         documentClass = DocumentListModel::SpreadSheetType;
0179 //     }
0180     return documentClass;
0181 }