File indexing completed on 2025-01-12 04:35:48

0001 /***************************************************************************
0002  *   SPDX-License-Identifier: GPL-2.0-or-later
0003  *                                                                         *
0004  *   SPDX-FileCopyrightText: 2004-2019 Thomas Fischer <fischer@unix-ag.uni-kl.de>
0005  *                                                                         *
0006  *   This program is free software; you can redistribute it and/or modify  *
0007  *   it under the terms of the GNU General Public License as published by  *
0008  *   the Free Software Foundation; either version 2 of the License, or     *
0009  *   (at your option) any later version.                                   *
0010  *                                                                         *
0011  *   This program is distributed in the hope that it will be useful,       *
0012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
0013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
0014  *   GNU General Public License for more details.                          *
0015  *                                                                         *
0016  *   You should have received a copy of the GNU General Public License     *
0017  *   along with this program; if not, see <https://www.gnu.org/licenses/>. *
0018  ***************************************************************************/
0019 
0020 
0021 #include "filesettings.h"
0022 
0023 #include <QFormLayout>
0024 #include <QCheckBox>
0025 #include <QComboBox>
0026 
0027 #include <KLocalizedString>
0028 
0029 #include <Preferences>
0030 #include <Value>
0031 #include <File>
0032 #include <GUIHelper>
0033 #include <ItalicTextItemModel>
0034 #include <file/FileView>
0035 #include <models/FileModel>
0036 
0037 FileSettings::FileSettings(QWidget *parent)
0038         : FileSettingsWidget(parent), m_fileView(nullptr)
0039 {
0040     setEnabled(false);
0041 
0042     connect(this, &FileSettings::widgetsChanged, this, &FileSettings::widgetsChangedSlot);
0043 
0044     connect(&OpenFileInfoManager::instance(), &OpenFileInfoManager::currentChanged, this, &FileSettings::currentFileChangedSlot);
0045     /// Monitoring file flag changes to get notified of
0046     /// "Save As" operations where the file settings
0047     /// may get changed (requires a reload of properties)
0048     connect(&OpenFileInfoManager::instance(), &OpenFileInfoManager::flagsChanged, this, &FileSettings::flagsChangedSlot);
0049 }
0050 
0051 void FileSettings::setFileView(FileView *fileView)
0052 {
0053     m_fileView = fileView;
0054     currentFileChangedSlot();
0055 }
0056 
0057 void FileSettings::widgetsChangedSlot()
0058 {
0059     File *file = m_fileView != nullptr && m_fileView->fileModel() != nullptr ? m_fileView->fileModel()->bibliographyFile() : nullptr;
0060     if (file != nullptr) {
0061         saveProperties(file);
0062         /// Notify main view about change it its data
0063         m_fileView->externalModification();
0064     }
0065 }
0066 
0067 void FileSettings::currentFileChangedSlot() {
0068     File *file = m_fileView != nullptr && m_fileView->fileModel() != nullptr ? m_fileView->fileModel()->bibliographyFile() : nullptr;
0069     loadProperties(file);
0070     setEnabled(file != nullptr);
0071 }
0072 
0073 void FileSettings::flagsChangedSlot(const OpenFileInfo::StatusFlags statusFlags)
0074 {
0075     if (statusFlags.testFlag(OpenFileInfo::StatusFlag::Open)) {
0076         File *file = m_fileView != nullptr && m_fileView->fileModel() != nullptr ? m_fileView->fileModel()->bibliographyFile() : nullptr;
0077         loadProperties(file);
0078     }
0079 }