Classified ads
camodel.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 modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (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
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with Classified Ads. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #ifndef CLASSIFIED_CLASSIFIEDADMODEL_H
21 #define CLASSIFIED_CLASSIFIEDADMODEL_H
22 #include <QSqlDatabase>
23 #include "../mcontroller.h" // because enum from there is needed
24 #include "../net/protocol.h" // for SendQueueItem
25 #include "datamodelbase.h"
26 
27 class Hash ;
29 class Profile ;
30 class CA ;
31 
38 class ClassifiedAdsModel : public ModelBase {
39  Q_OBJECT
40 
41 public:
46  enum PurposeOfAd {
53  } ;
58  enum ConcernOfAd {
87  } ;
88 
96  class CAObserver {
101  virtual void newCaReceived(const CA& aNewCa) = 0 ;
102  } ;
109  ClassifiedAdsModel(MController *aMController,
110  const MModelProtocolInterface &aModel) ;
113 
115  const QString& purposeOfAdString(PurposeOfAd aPurpose) const ;
120  QString localizedPurposeOfAdString(PurposeOfAd aPurpose) const ;
121  const QString& concernOfAdString(ConcernOfAd aConcern) const ;
122  QString localizedConcernOfAdString(ConcernOfAd aConcern) const ;
123 
134  Hash publishClassifiedAd( const Profile& aPublishingProfile,CA& aAd ) ;
135 
141  bool caDataForPublish(const Hash& aFingerPrint,
142  QByteArray& aResultingCaData,
143  QByteArray& aResultingSignature,
144  QByteArray& aPublicKeyOfPublisher,
145  quint32* aTimeOfPublish = NULL ) ;
146 
150  CA caByHash(const Hash& aFingerPrint) ;
151 
168  bool publishedCAReceived(const Hash& aFingerPrint,
169  const QByteArray& aContent,
170  const QByteArray& aSignature,
171  const QList<quint32>& aBangPath,
172  const QByteArray& aKeyOfPublisher,
173  const unsigned char aFlags,
174  const quint32 aTimeStamp,
175  const Hash& aFromNode ) ;
176 
190  bool sentCAReceived(const Hash& aFingerPrint,
191  const QByteArray& aContent,
192  const QByteArray& aSignature,
193  const QByteArray& aKeyOfPublisher,
194  const unsigned char aFlags,
195  const quint32 aTimeStamp,
196  const Hash& aFromNode ) ;
197 
201  void installCAObserver(CAObserver* aObserver) ;
205  void removeCAObserver(CAObserver* aObserver) ;
206 
225  void fillBucket(QList<SendQueueItem>& aSendQueue,
226  const Hash& aStartOfBucket,
227  const Hash& aEndOfBucket,
228  quint32 aLastMutualConnectTime,
229  const Hash& aForNode );
243  void caListingByClassification(const Hash& aClassificationHash,
244  quint32 aStartDate,
245  quint32 aEndDate,
246  QList<QPair<Hash,quint32> >& aResultingArticles,
247  const Hash& aRequestingNode ) ;
262  bool caListingByClassificationReceived(QList<QPair<Hash,quint32> >& aReceivedArticles,
263  const Hash& aRequestingNode,
264  const Hash& aClassification) ;
268  void reIndexAllAdsIntoFTS() ;
269 signals:
270  void error
272  const QString& aExplanation) ;
279  void contentReceived(const Hash& aHashOfContent,
280  const Hash& aHashOfClassification,
281  const ProtocolItemType aTypeOfReceivdContent) ;
282 private: // methods
288  bool doHandleReceivedCA(const Hash& aFingerPrint,
289  const QByteArray& aContent,
290  const QByteArray& aSignature,
291  const QList<quint32>& aBangPath,
292  const QByteArray& aKeyOfPublisher,
293  const unsigned char aFlags,
294  const quint32 aTimeStamp,
295  bool aWasPublish,
296  const Hash& aFromNode ) ;
297 private: // member variables:
300  QList<CAObserver*>* iNewCaObservers ;
301 } ;
302 #endif
ClassifiedAdsModel(MController *aMController, const MModelProtocolInterface &aModel)
Definition: camodel.h:75
Definition: camodel.h:60
void fillBucket(QList< SendQueueItem > &aSendQueue, const Hash &aStartOfBucket, const Hash &aEndOfBucket, quint32 aLastMutualConnectTime, const Hash &aForNode)
Definition: camodel.h:50
virtual void newCaReceived(const CA &aNewCa)=0
const MModelProtocolInterface & iModel
Definition: camodel.h:299
QList< CAObserver * > * iNewCaObservers
Definition: camodel.h:300
ConcernOfAd
Definition: camodel.h:58
bool caListingByClassificationReceived(QList< QPair< Hash, quint32 > > &aReceivedArticles, const Hash &aRequestingNode, const Hash &aClassification)
Hash is class that carries 160-bit digest.
Definition: hash.h:37
CAErrorSituation
Definition: mcontroller.h:48
CA caByHash(const Hash &aFingerPrint)
QString localizedConcernOfAdString(ConcernOfAd aConcern) const
bool caDataForPublish(const Hash &aFingerPrint, QByteArray &aResultingCaData, QByteArray &aResultingSignature, QByteArray &aPublicKeyOfPublisher, quint32 *aTimeOfPublish=NULL)
ProtocolItemType
Definition: protocol.h:124
This is part of datamodel for storage/retrieval of classified ads.
Definition: camodel.h:38
Definition: camodel.h:52
bool sentCAReceived(const Hash &aFingerPrint, const QByteArray &aContent, const QByteArray &aSignature, const QByteArray &aKeyOfPublisher, const unsigned char aFlags, const quint32 aTimeStamp, const Hash &aFromNode)
Definition: camodel.h:51
bool doHandleReceivedCA(const Hash &aFingerPrint, const QByteArray &aContent, const QByteArray &aSignature, const QList< quint32 > &aBangPath, const QByteArray &aKeyOfPublisher, const unsigned char aFlags, const quint32 aTimeStamp, bool aWasPublish, const Hash &aFromNode)
Carrier-class for classified ad.
Definition: ca.h:34
Pure-virtual interface of datamodel for message parser to use.
Definition: mmodelprotocolinterface.h:44
Pure-virtual interface class for controller. This is spammed across parties needing access to applica...
Definition: mcontroller.h:39
datamodel-parts common part. this is inherited and contains common funcs
Definition: datamodelbase.h:38
bool publishedCAReceived(const Hash &aFingerPrint, const QByteArray &aContent, const QByteArray &aSignature, const QList< quint32 > &aBangPath, const QByteArray &aKeyOfPublisher, const unsigned char aFlags, const quint32 aTimeStamp, const Hash &aFromNode)
void reIndexAllAdsIntoFTS()
Definition: camodel.h:61
const QString & concernOfAdString(ConcernOfAd aConcern) const
Definition: camodel.h:48
void removeCAObserver(CAObserver *aObserver)
void caListingByClassification(const Hash &aClassificationHash, quint32 aStartDate, quint32 aEndDate, QList< QPair< Hash, quint32 > > &aResultingArticles, const Hash &aRequestingNode)
Definition: camodel.h:69
MController * iController
Definition: camodel.h:298
void installCAObserver(CAObserver *aObserver)
Definition: camodel.h:59
void contentReceived(const Hash &aHashOfContent, const Hash &aHashOfClassification, const ProtocolItemType aTypeOfReceivdContent)
const QString & purposeOfAdString(PurposeOfAd aPurpose) const
Definition: camodel.h:49
Hash publishClassifiedAd(const Profile &aPublishingProfile, CA &aAd)
Definition: camodel.h:72
Definition: camodel.h:70
Carrier-class for user-profile data.
Definition: profile.h:36
QString localizedPurposeOfAdString(PurposeOfAd aPurpose) const
Definition: camodel.h:47
Definition: camodel.h:71
void error(MController::CAErrorSituation aError, const QString &aExplanation)
Definition: camodel.h:96
Definition: camodel.h:68
Definition: camodel.h:81
PurposeOfAd
Definition: camodel.h:46