File indexing completed on 2024-04-28 05:08:26
0001 /*************************************************************************** 0002 Copyright (C) 2003-2009 Robby Stephenson <robby@periapsis.org> 0003 ***************************************************************************/ 0004 0005 /*************************************************************************** 0006 * * 0007 * This program is free software; you can redistribute it and/or * 0008 * modify it under the terms of the GNU General Public License as * 0009 * published by the Free Software Foundation; either version 2 of * 0010 * the License or (at your option) version 3 or any later version * 0011 * accepted by the membership of KDE e.V. (or its successor approved * 0012 * by the membership of KDE e.V.), which shall act as a proxy * 0013 * defined in Section 14 of version 3 of the license. * 0014 * * 0015 * This program is distributed in the hope that it will be useful, * 0016 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0018 * GNU General Public License for more details. * 0019 * * 0020 * You should have received a copy of the GNU General Public License * 0021 * along with this program. If not, see <http://www.gnu.org/licenses/>. * 0022 * * 0023 ***************************************************************************/ 0024 0025 #ifndef TELLICO_KERNEL_H 0026 #define TELLICO_KERNEL_H 0027 0028 #include "datavectors.h" 0029 #include "borrower.h" 0030 0031 class QUndoStack; 0032 class QWidget; 0033 class QString; 0034 class QStringList; 0035 class QUndoCommand; 0036 class QUrl; 0037 0038 namespace Tellico { 0039 class Filter; 0040 namespace Data { 0041 class Collection; 0042 } 0043 0044 /** 0045 * @author Robby Stephenson 0046 */ 0047 class Kernel : public QObject { 0048 Q_OBJECT 0049 0050 public: 0051 static Kernel* self() { return s_self; } 0052 /** 0053 * Initializes the singleton. Should just be called once, from Tellico::MainWindow 0054 */ 0055 static void init(QWidget* parent) { if(!s_self) s_self = new Kernel(parent); } 0056 0057 /** 0058 * Returns a pointer to the parent widget. This is mainly used for error dialogs and the like. 0059 * 0060 * @return The widget pointer 0061 */ 0062 QWidget* widget() { return m_widget; } 0063 0064 /** 0065 * Returns the url of the current document. 0066 * 0067 * @return The URL 0068 */ 0069 QUrl URL() const; 0070 0071 int collectionType() const; 0072 QString collectionTypeName() const; 0073 0074 void sorry(const QString& text, QWidget* widget=nullptr); 0075 0076 void resetHistory(); 0077 0078 void addEntries(Data::EntryList entries, bool checkFields); 0079 void modifyEntries(Data::EntryList oldEntries, Data::EntryList newEntries, const QStringList& modifiedFields); 0080 void updateEntry(Data::EntryPtr oldEntry, Data::EntryPtr newEntry, bool overWrite); 0081 void removeEntries(Data::EntryList entries); 0082 0083 bool addLoans(Data::EntryList entries); 0084 bool modifyLoan(Data::LoanPtr loan); 0085 bool removeLoans(Data::LoanList loans); 0086 0087 void addFilter(FilterPtr filter); 0088 bool modifyFilter(FilterPtr filter); 0089 bool removeFilter(FilterPtr filter); 0090 0091 void appendCollection(Data::CollPtr coll); 0092 void mergeCollection(Data::CollPtr coll); 0093 void replaceCollection(Data::CollPtr coll); 0094 0095 void renameCollection(); 0096 QUndoStack* commandHistory() { return m_commandHistory; } 0097 0098 int askAndMerge(Data::EntryPtr entry1, Data::EntryPtr entry2, Data::FieldPtr field, 0099 QString value1 = QString(), QString value2 = QString()); 0100 0101 public Q_SLOTS: 0102 void beginCommandGroup(const QString& name); 0103 void endCommandGroup(); 0104 0105 bool addField(Data::FieldPtr field); 0106 bool modifyField(Data::FieldPtr field); 0107 bool removeField(Data::FieldPtr field); 0108 void reorderFields(const Data::FieldList& fields); 0109 0110 private: 0111 static Kernel* s_self; 0112 0113 // all constructors are private 0114 Kernel(QWidget* parent); 0115 Q_DISABLE_COPY(Kernel) 0116 ~Kernel(); 0117 0118 void doCommand(QUndoCommand* command); 0119 0120 QWidget* m_widget; 0121 QUndoStack* m_commandHistory; 0122 }; 0123 0124 } // end namespace 0125 #endif