summaryrefslogtreecommitdiffstats
path: root/src/tellico_kernel.h
blob: bafa02235be7babbaf487cc3849c96e3e5f6aa8d (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
/***************************************************************************
    copyright            : (C) 2003-2006 by Robby Stephenson
    email                : [email protected]
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   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 TELLICO_KERNEL_H
#define TELLICO_KERNEL_H

#include "datavectors.h"
#include "borrower.h"

#include <kcommand.h>

class KURL;

class TQWidget;
class TQString;
class TQStringList;

namespace Tellico {
  class MainWindow;
  class Filter;
  namespace Command {
    class Group;
  }
  namespace Data {
    class Collection;
  }

/**
 * @author Robby Stephenson
 */
class Kernel {

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

  /**
   * Returns a pointer to the tqparent widget. This is mainly used for error dialogs and the like.
   *
   * @return The widget pointer
   */
  TQWidget* widget() { return m_widget; }

  /**
   * Returns the url of the current document.
   *
   * @return The URL
   */
  const KURL& URL() const;
  /**
   * Returns a list of the field titles, wraps the call to the collection itself.
   *
   * @return the field titles
   */
  const TQStringList& fieldTitles() const;
  /**
   * Returns the name of an field, given its title. Wraps the call to the collection itself.
   *
   * @param title The field title
   * @return The field name
   */
  TQString fieldNameByTitle(const TQString& title) const;
  /**
   * Returns the title of an field, given its name. Wraps the call to the collection itself.
   *
   * @param name The field name
   * @return The field title
   */
  TQString fieldTitleByName(const TQString& name) const;
  TQStringList valuesByFieldName(const TQString& name) const;

  int collectionType() const;
  TQString collectionTypeName() const;

  void sorry(const TQString& text, TQWidget* widget=0);

  void beginCommandGroup(const TQString& name);
  void endCommandGroup();
  void resetHistory();

  bool addField(Data::FieldPtr field);
  bool modifyField(Data::FieldPtr field);
  bool removeField(Data::FieldPtr field);

  void addEntries(Data::EntryVec entries, bool checkFields);
  void modifyEntries(Data::EntryVec oldEntries, Data::EntryVec newEntries);
  void updateEntry(Data::EntryPtr oldEntry, Data::EntryPtr newEntry, bool overWrite);
  void removeEntries(Data::EntryVec entries);

  bool addLoans(Data::EntryVec entries);
  bool modifyLoan(Data::LoanPtr loan);
  bool removeLoans(Data::LoanVec loans);

  void addFilter(FilterPtr filter);
  bool modifyFilter(FilterPtr filter);
  bool removeFilter(FilterPtr filter);

  void reorderFields(const Data::FieldVec& fields);

  void appendCollection(Data::CollPtr coll);
  void mergeCollection(Data::CollPtr coll);
  void replaceCollection(Data::CollPtr coll);

  // adds new fields into collection if any values in entries are not empty
  // first object is modified fields, second is new fields
  TQPair<Data::FieldVec, Data::FieldVec> mergeFields(Data::CollPtr coll,
                                                    Data::FieldVec fields,
                                                    Data::EntryVec entries);

  void renameCollection();
  const KCommandHistory* commandHistory() { return &m_commandHistory; }

  int askAndMerge(Data::EntryPtr entry1, Data::EntryPtr entry2, Data::FieldPtr field,
                  TQString value1 = TQString(), TQString value2 = TQString());

private:
  static Kernel* s_self;

  // all constructors are private
  Kernel(MainWindow* tqparent);
  Kernel(const Kernel&);
  Kernel& operator=(const Kernel&);

  void doCommand(KCommand* command);

  TQWidget* m_widget;
  KCommandHistory m_commandHistory;
  Command::Group* m_commandGroup;
};

} // end namespace
#endif