Classified ads
model.h
Go to the documentation of this file.
1 /* -*-C++-*- -*-coding: utf-8-unix;-*-
2  Classified Ads is Copyright (c) Antti Jarvinen 2013.
3 
4  This file is part of Classified Ads.
5 
6  Classified Ads is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Lesser General Public
8  License as published by the Free Software Foundation; either
9  version 2.1 of the License, or (at your option) any later version.
10 
11  Classified Ads is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  Lesser General Public License for more details.
15 
16  You should have received a copy of the GNU Lesser General Public
17  License along with Classified Ads; if not, write to the Free Software
18  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20 
21 #ifndef CLASSIFIED_DATAMODEL_H
22 #define CLASSIFIED_DATAMODEL_H
23 #include <QSqlDatabase>
24 #include <QObject>
25 #include "../mcontroller.h" // because enum from there is needed
26 #include "../net/connection.h"
27 #include <QHostAddress>
28 #include <QPair>
29 #include "netrequestexecutor.h"
30 #include "nodemodel.h"
33 
34 class QSqlDatabase ;
35 class QMutex ;
36 class Hash ;
37 class QSslCertificate ;
38 class QSslKey ;
39 class SearchModel ;
40 class TrustTreeModel ;
49  Q_OBJECT
50 
51 public:
52  // public enums
65  } ;
76  } ;
77  // methods
78  Model(MController *aMController) ;
79  ~Model() ;
81  virtual ProfileModel& profileModel() const ;
82  virtual BinaryFileModel& binaryFileModel() const ;
83  virtual ClassifiedAdsModel& classifiedAdsModel() const ;
84  virtual PrivMessageModel& privateMessageModel() const ;
85  virtual ProfileCommentModel& profileCommentModel() const ;
86  virtual SearchModel* searchModel() const ;
87  virtual TrustTreeModel* trustTreeModel() const ;
88  void addOpenNetworkConnection(Connection *aConnection) ;
95  void removeOpenNetworkConnection(Connection *aDeletedConnection) ;
96 
107  void addItemToSend(const Hash& aDestinationNode,
108  QByteArray* aBytesToSend) ;
109 
113  const QList <Connection *>& getConnections() const ;
120  QList <NetworkRequestExecutor::NetworkRequestQueueItem>& getNetRequests() const ;
129  aRequest) const ;
134  virtual bool lock() ;
139  virtual void unlock() ;
145  virtual MNodeModelProtocolInterface& nodeModel() const ;
160  void closeAllConnections(bool aDeleteAlso) ;
165  Connection *aConnection) ;
172  PublishItem nextItemToPublish(bool* aFound) ;
187  const Hash& aHash,
188  const QList<quint32>& aBangPath,
189  const Hash& aSecondaryAddr = KNullHash ) ;
203  PublishItem addNodeToPublishedItem(const Hash& aContentHash,const Hash& aNodeHash) ;
212 
221 
222 
223 public slots:
227  void notifyOfContentReceived(const Hash& aHashOfContent,
228  const ProtocolItemType aTypeOfReceivdContent) ;
232  void notifyOfContentReceived(const Hash& aHashOfContent,
233  const Hash& aHashOfClassification,
234  const ProtocolItemType aTypeOfReceivdContent) ;
235 protected:
239  void timerEvent(QTimerEvent *event);
240 private:
241  bool openDB();
242  QSqlError lastError();
243  // 1st-time initialization methods ahead
244  bool createTables() ;
245  // additions to first version of tables
246  bool createTablesV2() ;
247  void initPseudoRandom() ;
248 signals:
250  const QString& aExplanation) ;
251 private:
253  QSqlDatabase iDb;
254  QMutex* iMutex ;
255  QList <Connection *> *iConnections ;
262  QList <NetworkRequestExecutor::NetworkRequestQueueItem>* iNetReqQueue ;
267  int iTimerId ;
273 } ;
274 #endif
Model::CallAcceptanceSetting getCallAcceptanceSetting()
Definition: model.h:75
void initPseudoRandom()
virtual PrivMessageModel & privateMessageModel() const
void setRingtoneSetting(Model::RingtoneSetting aRingTone)
void addItemToBePublished(ProtocolItemType aType, const Hash &aHash, const QList< quint32 > &aBangPath, const Hash &aSecondaryAddr=KNullHash)
virtual SearchModel * searchModel() const
PublishItem addNodeToPublishedItem(const Hash &aContentHash, const Hash &aNodeHash)
Definition: model.h:61
void addItemToSend(const Hash &aDestinationNode, QByteArray *aBytesToSend)
void notifyOfContentReceived(const Hash &aHashOfContent, const ProtocolItemType aTypeOfReceivdContent)
void addOpenNetworkConnection(Connection *aConnection)
Definition: model.h:60
Logic for handling tasks received from other peers or from user.
Definition: netrequestexecutor.h:40
Model-class for performing text-based searches on objects in db This datamodel part is dual-use ; it ...
Definition: searchmodel.h:45
This is is part of datamodel for storing comments of user profiles.
Definition: profilecommentmodel.h:38
This is is part of datamodel for storing private messages.
Definition: privmsgmodel.h:51
ProfileCommentModel * iProfileCommentModel
Definition: model.h:269
virtual void unlock()
Definition: model.h:73
const QList< Connection * > & getConnections() const
int iTimerId
Definition: model.h:267
MController * iController
Definition: model.h:252
Hash is class that carries 160-bit digest.
Definition: hash.h:38
CAErrorSituation
Definition: mcontroller.h:52
time_t iTimeOfLastNetworkAddrCheck
Definition: model.h:272
bool createTablesV2()
ContentEncryptionModel * iContentEncryptionModel
Definition: model.h:263
virtual void addNetworkRequest(NetworkRequestExecutor::NetworkRequestQueueItem &aRequest) const
TrustTreeModel * iTrustTreeModel
Definition: model.h:271
QList< NetworkRequestExecutor::NetworkRequestQueueItem > & getNetRequests() const
ConnectionState
Definition: connection.h:47
ProtocolItemType
Definition: protocol.h:150
This is part of datamodel for storage/retrieval of classified ads.
Definition: camodel.h:40
ProfileModel * iProfileModel
Definition: model.h:264
void setCallAcceptanceSetting(Model::CallAcceptanceSetting aAcceptance)
Model(MController *aMController)
virtual bool lock()
PublishItem nextItemToPublish(bool *aFound)
Pure-virtual interface of datamodel for message parser to use.
Definition: mmodelprotocolinterface.h:45
Definition: model.h:63
virtual BinaryFileModel & binaryFileModel() const
Definition: model.h:74
Pure-virtual interface class for controller. This is spammed across parties needing access to applica...
Definition: mcontroller.h:43
void connectionStateChanged(Connection::ConnectionState aState, Connection *aConnection)
virtual ProfileCommentModel & profileCommentModel() const
Hash KNullHash
void timerEvent(QTimerEvent *event)
bool createTables()
NetworkRequestExecutor * iNetReqExecutor
Definition: model.h:257
M of the MVC pattern. Handles permanent storage.
Definition: model.h:48
RingtoneSetting
Definition: model.h:59
This is is part of datamodel for storing user profiles.
Definition: profilemodel.h:39
PrivMessageModel * iPrivMsgModel
Definition: model.h:268
virtual ProfileModel & profileModel() const
void closeAllConnections(bool aDeleteAlso)
Model::RingtoneSetting getRingtoneSetting()
ContentEncryptionModel & contentEncryptionModel() const
This is node-specific part of the datamodel.
Definition: nodemodel.h:46
QList< Connection * > * iConnections
Definition: model.h:255
NetworkRequestExecutor * getNetReqExecutor()
virtual ClassifiedAdsModel & classifiedAdsModel() const
void error(MController::CAErrorSituation aError, const QString &aExplanation)
ClassifiedAdsModel * iCaModel
Definition: model.h:266
Definition: model.h:64
NodeModel * iNodeModel
Definition: model.h:256
QSqlError lastError()
Work queue item.
Definition: netrequestexecutor.h:60
CallAcceptanceSetting
Definition: model.h:72
virtual MNodeModelProtocolInterface & nodeModel() const
QMutex * iMutex
Definition: model.h:254
Definition: model.h:62
BinaryFileModel * iBinaryFileModel
Definition: model.h:265
Pure-virtual interface of nodemodel.
Definition: mnodemodelprotocolinterface.h:39
SearchModel * iSearchModel
Definition: model.h:270
This is is part of datamodel for trust tree related operation.
Definition: trusttreemodel.h:55
Carrier for keeping state of item about to be published.
Definition: protocol.h:196
Class that represents a network connection.
Definition: connection.h:43
virtual TrustTreeModel * trustTreeModel() const
QList< NetworkRequestExecutor::NetworkRequestQueueItem > * iNetReqQueue
Definition: model.h:262
QSqlDatabase iDb
Definition: model.h:253
This is part of datamodel for any binary blobs.
Definition: binaryfilemodel.h:39
This is content-crypto-operations-specific part of the datamodel.
Definition: contentencryptionmodel.h:37
bool openDB()
void removeOpenNetworkConnection(Connection *aDeletedConnection)