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
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_CLASSIFIEDADMODEL_H
22 #define CLASSIFIED_CLASSIFIEDADMODEL_H
23 #include <QSqlDatabase>
24 #include "../mcontroller.h" // because enum from there is needed
25 #include "../net/protocol.h" // for SendQueueItem
26 #include "datamodelbase.h"
27 #include <QStringList>
28 
29 class Hash ;
31 class Profile ;
32 class CA ;
33 
40 class ClassifiedAdsModel : public ModelBase {
41  Q_OBJECT
42 
43 public:
48  enum PurposeOfAd {
55  } ;
60  enum ConcernOfAd {
89  } ;
90 
98  class CAObserver {
103  virtual void newCaReceived(const CA& aNewCa) = 0 ;
104  } ;
111  ClassifiedAdsModel(MController *aMController,
112  const MModelProtocolInterface &aModel) ;
115 
117  const QString& purposeOfAdString(PurposeOfAd aPurpose) const ;
122  QString localizedPurposeOfAdString(PurposeOfAd aPurpose) const ;
123  const QString& concernOfAdString(ConcernOfAd aConcern) const ;
124  QString localizedConcernOfAdString(ConcernOfAd aConcern) const ;
125 
136  Hash publishClassifiedAd( const Profile& aPublishingProfile,CA& aAd ) ;
137 
143  bool caDataForPublish(const Hash& aFingerPrint,
144  QByteArray& aResultingCaData,
145  QByteArray& aResultingSignature,
146  QByteArray& aPublicKeyOfPublisher,
147  quint32* aTimeOfPublish = NULL ) ;
148 
152  CA caByHash(const Hash& aFingerPrint) ;
153 
170  bool publishedCAReceived(const Hash& aFingerPrint,
171  const QByteArray& aContent,
172  const QByteArray& aSignature,
173  const QList<quint32>& aBangPath,
174  const QByteArray& aKeyOfPublisher,
175  const unsigned char aFlags,
176  const quint32 aTimeStamp,
177  const Hash& aFromNode ) ;
178 
192  bool sentCAReceived(const Hash& aFingerPrint,
193  const QByteArray& aContent,
194  const QByteArray& aSignature,
195  const QByteArray& aKeyOfPublisher,
196  const unsigned char aFlags,
197  const quint32 aTimeStamp,
198  const Hash& aFromNode ) ;
199 
203  void installCAObserver(CAObserver* aObserver) ;
207  void removeCAObserver(CAObserver* aObserver) ;
208 
227  void fillBucket(QList<SendQueueItem>& aSendQueue,
228  const Hash& aStartOfBucket,
229  const Hash& aEndOfBucket,
230  quint32 aLastMutualConnectTime,
231  const Hash& aForNode );
245  void caListingByClassification(const Hash& aClassificationHash,
246  quint32 aStartDate,
247  quint32 aEndDate,
248  QList<QPair<Hash,quint32> >& aResultingArticles,
249  const Hash& aRequestingNode ) ;
264  bool caListingByClassificationReceived(QList<QPair<Hash,quint32> >& aReceivedArticles,
265  const Hash& aRequestingNode,
266  const Hash& aClassification) ;
270  void reIndexAllAdsIntoFTS() ;
271 
272  const QStringList& aboutComboBoxTexts() const ;
273  const QStringList& regardingComboBoxTexts() const ;
274  const QStringList& whereComboBoxTexts() const ;
275 signals:
276  void error
278  const QString& aExplanation) ;
285  void contentReceived(const Hash& aHashOfContent,
286  const Hash& aHashOfClassification,
287  const ProtocolItemType aTypeOfReceivdContent) ;
288 private: // methods
294  bool doHandleReceivedCA(const Hash& aFingerPrint,
295  const QByteArray& aContent,
296  const QByteArray& aSignature,
297  const QList<quint32>& aBangPath,
298  const QByteArray& aKeyOfPublisher,
299  const unsigned char aFlags,
300  const quint32 aTimeStamp,
301  bool aWasPublish,
302  const Hash& aFromNode ) ;
304  void initComboBoxTexts() ;
305 private: // member variables:
308  QList<CAObserver*>* iNewCaObservers ;
309  QStringList iAboutComboBoxTexts ;
311  QStringList iWhereComboBoxTexts ;
312 } ;
313 #endif
ClassifiedAdsModel(MController *aMController, const MModelProtocolInterface &aModel)
const QStringList & aboutComboBoxTexts() const
QStringList iRegardingComboBoxTexts
Definition: camodel.h:310
Definition: camodel.h:77
Definition: camodel.h:62
void fillBucket(QList< SendQueueItem > &aSendQueue, const Hash &aStartOfBucket, const Hash &aEndOfBucket, quint32 aLastMutualConnectTime, const Hash &aForNode)
QStringList iAboutComboBoxTexts
Definition: camodel.h:309
Definition: camodel.h:52
virtual void newCaReceived(const CA &aNewCa)=0
const MModelProtocolInterface & iModel
Definition: camodel.h:307
QList< CAObserver * > * iNewCaObservers
Definition: camodel.h:308
QString localizedPurposeOfAdString(PurposeOfAd aPurpose) const
ConcernOfAd
Definition: camodel.h:60
bool caListingByClassificationReceived(QList< QPair< Hash, quint32 > > &aReceivedArticles, const Hash &aRequestingNode, const Hash &aClassification)
Hash is class that carries 160-bit digest.
Definition: hash.h:38
CAErrorSituation
Definition: mcontroller.h:57
const QString & concernOfAdString(ConcernOfAd aConcern) const
CA caByHash(const Hash &aFingerPrint)
bool caDataForPublish(const Hash &aFingerPrint, QByteArray &aResultingCaData, QByteArray &aResultingSignature, QByteArray &aPublicKeyOfPublisher, quint32 *aTimeOfPublish=NULL)
ProtocolItemType
Definition: protocol.h:157
This is part of datamodel for storage/retrieval of classified ads.
Definition: camodel.h:40
const QStringList & regardingComboBoxTexts() const
Definition: camodel.h:54
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:53
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:35
Pure-virtual interface of datamodel for message parser to use.
Definition: mmodelprotocolinterface.h:46
const QStringList & whereComboBoxTexts() const
Pure-virtual interface class for controller. This is spammed across parties needing access to applica...
Definition: mcontroller.h:48
datamodel-parts common part. this is inherited and contains common funcs
Definition: datamodelbase.h:39
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:63
Definition: camodel.h:50
void removeCAObserver(CAObserver *aObserver)
void caListingByClassification(const Hash &aClassificationHash, quint32 aStartDate, quint32 aEndDate, QList< QPair< Hash, quint32 > > &aResultingArticles, const Hash &aRequestingNode)
Definition: camodel.h:71
MController * iController
Definition: camodel.h:306
void installCAObserver(CAObserver *aObserver)
QStringList iWhereComboBoxTexts
Definition: camodel.h:311
Definition: camodel.h:61
void contentReceived(const Hash &aHashOfContent, const Hash &aHashOfClassification, const ProtocolItemType aTypeOfReceivdContent)
const QString & purposeOfAdString(PurposeOfAd aPurpose) const
Definition: camodel.h:51
Hash publishClassifiedAd(const Profile &aPublishingProfile, CA &aAd)
Definition: camodel.h:74
Definition: camodel.h:72
Carrier-class for user-profile data.
Definition: profile.h:37
QString localizedConcernOfAdString(ConcernOfAd aConcern) const
Definition: camodel.h:49
Definition: camodel.h:73
void error(MController::CAErrorSituation aError, const QString &aExplanation)
Definition: camodel.h:98
Definition: camodel.h:70
Definition: camodel.h:83
PurposeOfAd
Definition: camodel.h:48