File indexing completed on 2024-04-28 05:08:17

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_CONTROLLER_H
0026 #define TELLICO_CONTROLLER_H
0027 
0028 #include "entry.h"
0029 
0030 #include <QObject>
0031 #include <QList>
0032 
0033 class QMenu;
0034 
0035 namespace Tellico {
0036   class MainWindow;
0037   namespace Data {
0038     class Collection;
0039   }
0040   class Observer;
0041 
0042 /**
0043  * @author Robby Stephenson
0044  */
0045 class Controller : public QObject {
0046 Q_OBJECT
0047 
0048 public:
0049   static Controller* self() { return s_self; }
0050   /**
0051    * Initializes the singleton. Should just be called once, from Tellico::MainWindow
0052    */
0053   static void init(MainWindow* parent) {
0054     if(!s_self) s_self = new Controller(parent);
0055   }
0056 
0057   const Data::EntryList& selectedEntries() const { return m_selectedEntries; }
0058   Data::EntryList visibleEntries();
0059 
0060   void editEntry(Data::EntryPtr) const;
0061   void hideTabs() const;
0062   /**
0063    * Plug the default collection actions into a widget
0064    */
0065   void plugCollectionActions(QMenu* popup);
0066   /**
0067    * Plug the default entry actions into a widget
0068    */
0069   void plugEntryActions(QMenu* popup);
0070   QMenu* plugSortActions(QMenu* popup);
0071   void updateActions() const;
0072 
0073   /**
0074    * Returns the name of the field being used to group the entries.
0075    * That field name may not be an actual field in the collection, since
0076    * pseudo-groups like _people exist.
0077    */
0078   QString groupBy() const;
0079   /**
0080    * Returns a list of the fields being used to group the entries.
0081    * For ordinary fields, the list has a single item, the field name.
0082    * For the pseudo-group _people, all the people fields are included.
0083    */
0084   QStringList expandedGroupBy() const;
0085   /**
0086    * Returns a list of the titles of the fields being used to sort the entries in the detailed column view.
0087    */
0088   QStringList sortTitles() const;
0089   /**
0090    * Returns the title of the fields currently visible in the detailed column view.
0091    */
0092   QStringList visibleColumns() const;
0093 
0094   void    addObserver(Observer* obs);
0095   void removeObserver(Observer* obs);
0096 
0097   void addedField(Data::CollPtr coll, Data::FieldPtr field);
0098   void modifiedField(Data::CollPtr coll, Data::FieldPtr oldField, Data::FieldPtr newField);
0099   void removedField(Data::CollPtr coll, Data::FieldPtr field);
0100 
0101   void addedEntries(Data::EntryList entries);
0102   void modifiedEntries(Data::EntryList entries);
0103   void removedEntries(Data::EntryList entries);
0104 
0105   void addedBorrower(Data::BorrowerPtr borrower);
0106   void modifiedBorrower(Data::BorrowerPtr borrower);
0107 
0108   void addedFilter(FilterPtr filter);
0109   void removedFilter(FilterPtr filter);
0110 
0111   void reorderedFields(Data::CollPtr coll);
0112   void updatedFetchers();
0113 
0114   void clearFilter();
0115 
0116 public Q_SLOTS:
0117   /**
0118    * When a collection is added to the document, certain actions need to be taken
0119    * by the parent app. The collection toolbar is updated, the entry count is set, and
0120    * the collection's modified signal is connected to the @ref GroupView widget.
0121    *
0122    * @param coll A pointer to the collection being added
0123    */
0124   void slotCollectionAdded(Tellico::Data::CollPtr coll);
0125   void slotCollectionModified(Tellico::Data::CollPtr coll, bool structuralChange);
0126   /**
0127    * Removes a collection from all the widgets
0128    *
0129    * @param coll A pointer to the collection being added
0130    */
0131   void slotCollectionDeleted(Tellico::Data::CollPtr coll);
0132   void slotFieldAdded(Tellico::Data::CollPtr coll, Tellico::Data::FieldPtr field);
0133   void slotRefreshField(Tellico::Data::FieldPtr field);
0134 
0135   void slotClearSelection();
0136   /**
0137    * Updates the widgets when entries are selected.
0138    *
0139    * @param entries The list of selected entries
0140    */
0141   void slotUpdateSelection(const Tellico::Data::EntryList& entries);
0142   void slotCopySelectedEntries();
0143   void slotUpdateSelectedEntries(const QString& source);
0144   void slotDeleteSelectedEntries();
0145   void slotMergeSelectedEntries();
0146   void slotUpdateFilter(Tellico::FilterPtr filter);
0147   void slotCheckOut();
0148   void slotCheckIn();
0149   void slotCheckIn(const Data::EntryList& entries);
0150 
0151 Q_SIGNALS:
0152   void collectionAdded(int collType);
0153 
0154 private:
0155   static Controller* s_self;
0156   Controller(MainWindow* parent);
0157   ~Controller();
0158 
0159   void blockAllSignals(bool block) const;
0160   bool canCheckIn() const;
0161   void plugUpdateMenu(QMenu* popup);
0162 
0163   MainWindow* m_mainWindow;
0164 
0165   bool m_working;
0166 
0167   typedef QList<Tellico::Observer*> ObserverList;
0168   ObserverList m_observers;
0169 
0170   /**
0171    * Keep track of the selected entries so that a top-level delete has something for reference
0172    */
0173   Data::EntryList m_selectedEntries;
0174 };
0175 
0176 } // end namespace
0177 #endif