summaryrefslogtreecommitdiffstats
path: root/src/controller.h
blob: d928ddee9903742d9c8cbe5fa1e4fcb524759500 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/***************************************************************************
    copyright            : (C) 2003-2006 by Robby Stephenson
    email                : robby@periapsis.org
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of version 2 of the GNU General Public License as  *
 *   published by the Free Software Foundation;                            *
 *                                                                         *
 ***************************************************************************/

#ifndef TELLICOCONTROLLER_H
#define TELLICOCONTROLLER_H

class TQPopupMenu;

namespace Tellico {
  class MainWindow;
  class GroupView;
  class GroupIterator;
  namespace Data {
    class Collection;
  }
}

#include "entry.h"

#include <tqobject.h>

namespace Tellico {
class Observer;

/**
 * @author Robby Stephenson
 */
class Controller : public TQObject {
Q_OBJECT
  TQ_OBJECT

public:
  static Controller* self() { return s_self; }
  /**
   * Initializes the singleton. Should just be called once, from Tellico::MainWindow
   */
  static void init(MainWindow* parent, const char* name=0) {
    if(!s_self) s_self = new Controller(parent, name);
  }

  const Data::EntryVec& selectedEntries() const { return m_selectedEntries; }
  Data::EntryVec visibleEntries();

  void editEntry(Data::EntryPtr) const;
  void hideTabs() const;
  /**
   * Plug the default collection actions into a widget
   */
  void plugCollectionActions(TQPopupMenu* popup);
  /**
   * Plug the default entry actions into a widget
   */
  void plugEntryActions(TQPopupMenu* popup);
  void updateActions() const;

  GroupIterator groupIterator() const;
  /**
   * Returns the name of the field being used to group the entries.
   * That field name may not be an actual field in the collection, since
   * pseudo-groups like _people exist.
   */
  TQString groupBy() const;
  /**
   * Returns a list of the fields being used to group the entries.
   * For ordinary fields, the list has a single item, the field name.
   * For the pseudo-group _people, all the people fields are included.
   */
  TQStringList expandedGroupBy() const;
  /**
   * Returns a list of the titles of the fields being used to sort the entries in the detailed column view.
   */
  TQStringList sortTitles() const;
  /**
   * Returns the title of the fields currently visible in the detailed column view.
   */
  TQStringList visibleColumns() const;

  void    addObserver(Observer* obs);
  void removeObserver(Observer* obs);

  void addedField(Data::CollPtr coll, Data::FieldPtr field);
  void modifiedField(Data::CollPtr coll, Data::FieldPtr oldField, Data::FieldPtr newField);
  void removedField(Data::CollPtr coll, Data::FieldPtr field);

  void addedEntries(Data::EntryVec entries);
  void modifiedEntries(Data::EntryVec entries);
  void removedEntries(Data::EntryVec entries);

  void addedBorrower(Data::BorrowerPtr borrower);
  void modifiedBorrower(Data::BorrowerPtr borrower);

  void addedFilter(FilterPtr filter);
  void removedFilter(FilterPtr filter);

  void reorderedFields(Data::CollPtr coll);
  void updatedFetchers();

public slots:
  /**
   * When a collection is added to the document, certain actions need to be taken
   * by the parent app. The collection toolbar is updated, the entry count is set, and
   * the collection's modified signal is connected to the @ref GroupView widget.
   *
   * @param coll A pointer to the collection being added
   */
  void slotCollectionAdded(Tellico::Data::CollPtr coll);
  void slotCollectionModified(Tellico::Data::CollPtr coll);
  /**
   * Removes a collection from all the widgets
   *
   * @param coll A pointer to the collection being added
   */
  void slotCollectionDeleted(Tellico::Data::CollPtr coll);
  void slotRefreshField(Tellico::Data::FieldPtr field);

  void slotClearSelection();
  /**
   * Updates the widgets when entries are selected.
   *
   * param widget A pointer to the widget where the entries were selected
   * @param widget The widget doing the selecting, if NULL, then use previous
   * @param entries The list of selected entries
   */
  void slotUpdateSelection(TQWidget* widget, const Tellico::Data::EntryVec& entries);
  void slotUpdateCurrent(const Tellico::Data::EntryVec& entries);
  void slotCopySelectedEntries();
  void slotUpdateSelectedEntries(const TQString& source);
  void slotDeleteSelectedEntries();
  void slotMergeSelectedEntries();
  void slotUpdateFilter(Tellico::FilterPtr filter);
  void slotCheckOut();
  void slotCheckIn();
  void slotCheckIn(const Data::EntryVec& entries);
  void slotGoPrevEntry();
  void slotGoNextEntry();

signals:
  void collectionAdded(int collType);

private:
  static Controller* s_self;
  Controller(MainWindow* parent, const char* name);

  void blockAllSignals(bool block) const;
  bool canCheckIn() const;
  void plugUpdateMenu(TQPopupMenu* popup);
  enum EntryDirection { PrevEntry, NextEntry };
  void goEntrySibling(EntryDirection dir);

  MainWindow* m_mainWindow;

  bool m_working;

  typedef PtrVector<Tellico::Observer> ObserverVec;
  ObserverVec m_observers;

  /**
   * Keep track of the selected entries so that a top-level delete has something for reference
   */
  Data::EntryVec m_selectedEntries;
  Data::EntryVec m_currentEntries;
  TQWidget* m_widgetWithSelection;
};

} // end namespace
#endif