1 /*****************************************************************************
2  *   Copyright (C) 2004-2019 by Thomas Fischer <fischer@unix-ag.uni-kl.de>   *
3  *                                                                           *
4  *                                                                           *
5  *   This program is free software; you can redistribute it and/or modify    *
6  *   it under the terms of the GNU General Public License as published by    *
7  *   the Free Software Foundation; either version 2 of the License, or       *
8  *   (at your option) any later version.                                     *
9  *                                                                           *
10  *   This program is distributed in the hope that it will be useful,         *
11  *   but WITHOUT ANY WARRANTY; without even the implied warranty of          *
12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           *
13  *   GNU General Public License for more details.                            *
14  *                                                                           *
15  *   You should have received a copy of the GNU General Public License       *
16  *   along with this program; if not, see <https://www.gnu.org/licenses/>.   *
17  *****************************************************************************/
18 
19 #include "filesettings.h"
20 
21 #include <QFormLayout>
22 #include <QCheckBox>
23 
24 #include <KComboBox>
25 #include <KLocalizedString>
26 
27 #include "preferences.h"
28 #include "guihelper.h"
29 #include "italictextitemmodel.h"
30 #include "fileview.h"
31 #include "models/filemodel.h"
32 #include "value.h"
33 #include "file.h"
34 
FileSettings(QWidget * parent)35 FileSettings::FileSettings(QWidget *parent)
36         : FileSettingsWidget(parent), m_fileView(nullptr)
37 {
38     setEnabled(false);
39 
40     connect(this, &FileSettings::widgetsChanged, this, &FileSettings::widgetsChangedSlot);
41 
42     connect(&OpenFileInfoManager::instance(), &OpenFileInfoManager::currentChanged, this, &FileSettings::currentFileChangedSlot);
43     /// Monitoring file flag changes to get notified of
44     /// "Save As" operations where the file settings
45     /// may get changed (requires a reload of properties)
46     connect(&OpenFileInfoManager::instance(), &OpenFileInfoManager::flagsChanged, this, &FileSettings::flagsChangedSlot);
47 }
48 
setFileView(FileView * fileView)49 void FileSettings::setFileView(FileView *fileView)
50 {
51     m_fileView = fileView;
52     currentFileChangedSlot();
53 }
54 
widgetsChangedSlot()55 void FileSettings::widgetsChangedSlot()
56 {
57     File *file = m_fileView != nullptr && m_fileView->fileModel() != nullptr ? m_fileView->fileModel()->bibliographyFile() : nullptr;
58     if (file != nullptr) {
59         saveProperties(file);
60         /// Notify main view about change it its data
61         m_fileView->externalModification();
62     }
63 }
64 
currentFileChangedSlot()65 void FileSettings::currentFileChangedSlot() {
66     File *file = m_fileView != nullptr && m_fileView->fileModel() != nullptr ? m_fileView->fileModel()->bibliographyFile() : nullptr;
67     loadProperties(file);
68     setEnabled(file != nullptr);
69 }
70 
flagsChangedSlot(const OpenFileInfo::StatusFlags statusFlags)71 void FileSettings::flagsChangedSlot(const OpenFileInfo::StatusFlags statusFlags)
72 {
73     if (statusFlags.testFlag(OpenFileInfo::Open)) {
74         File *file = m_fileView != nullptr && m_fileView->fileModel() != nullptr ? m_fileView->fileModel()->bibliographyFile() : nullptr;
75         loadProperties(file);
76     }
77 }
78