Classified ads
Classes | Public Types | Signals | Public Member Functions | Private Member Functions | Private Attributes | List of all members
ClassifiedAdsModel Class Reference

This is part of datamodel for storage/retrieval of classified ads. More...

#include <camodel.h>

Inheritance diagram for ClassifiedAdsModel:
Inheritance graph
[legend]
Collaboration diagram for ClassifiedAdsModel:
Collaboration graph
[legend]

Classes

class  CAObserver
 

Public Types

enum  PurposeOfAd {
  ToBeBought =0, ToBeSold =1, ToBeGivenAway =2, IsWanted =3,
  ToBeRented =4, ToBeAnnounced =5
}
 
enum  ConcernOfAd {
  ConcerningCars =0, ConcerningBoats =1, ConcerningBikes =2, ConcerningOtherVehicles =3,
  ConcerningVehicleParts =4, ConcerningHabitation =5, ConcerningHouseholdAppliances =6, ConcerningFurniture =7,
  ConcerningClothing =8, ConcerningTools =9, ConcerningSports =10, ConcerningMusic =11,
  ConcerningBooks =12, ConcerningMovies =13, ConcerningAnimals =14, ConcerningElectronics =15,
  ConcerningJobs =16, ConcerningTransportation =17, ConcerningServices =18, ConcerningHealthcare =19,
  ConcerningFoodstuff =20, ConcerningSoftware =21, ConcerningEvents =22, ConcerningEducation =23,
  ConcerningFinance =24, ConcerningJewelry =25, ConcerningReligiousRituals =26, ConcerningPhilosophy =27
}
 

Signals

void error (MController::CAErrorSituation aError, const QString &aExplanation)
 
void contentReceived (const Hash &aHashOfContent, const Hash &aHashOfClassification, const ProtocolItemType aTypeOfReceivdContent)
 
- Signals inherited from ModelBase
void error (MController::CAErrorSituation aError, const QString &aExplanation)
 

Public Member Functions

 ClassifiedAdsModel (MController *aMController, const MModelProtocolInterface &aModel)
 
 ~ClassifiedAdsModel ()
 
const QString & purposeOfAdString (PurposeOfAd aPurpose) const
 
QString localizedPurposeOfAdString (PurposeOfAd aPurpose) const
 
const QString & concernOfAdString (ConcernOfAd aConcern) const
 
QString localizedConcernOfAdString (ConcernOfAd aConcern) const
 
Hash publishClassifiedAd (const Profile &aPublishingProfile, CA &aAd)
 
bool caDataForPublish (const Hash &aFingerPrint, QByteArray &aResultingCaData, QByteArray &aResultingSignature, QByteArray &aPublicKeyOfPublisher, quint32 *aTimeOfPublish=NULL)
 
CA caByHash (const Hash &aFingerPrint)
 
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)
 
bool sentCAReceived (const Hash &aFingerPrint, const QByteArray &aContent, const QByteArray &aSignature, const QByteArray &aKeyOfPublisher, const unsigned char aFlags, const quint32 aTimeStamp, const Hash &aFromNode)
 
void installCAObserver (CAObserver *aObserver)
 
void removeCAObserver (CAObserver *aObserver)
 
void fillBucket (QList< SendQueueItem > &aSendQueue, const Hash &aStartOfBucket, const Hash &aEndOfBucket, quint32 aLastMutualConnectTime, const Hash &aForNode)
 
void caListingByClassification (const Hash &aClassificationHash, quint32 aStartDate, quint32 aEndDate, QList< QPair< Hash, quint32 > > &aResultingArticles, const Hash &aRequestingNode)
 
bool caListingByClassificationReceived (QList< QPair< Hash, quint32 > > &aReceivedArticles, const Hash &aRequestingNode, const Hash &aClassification)
 
void reIndexAllAdsIntoFTS ()
 
- Public Member Functions inherited from ModelBase
 ModelBase (QString aDataTableName, unsigned aMaxRowsToKeep)
 
 ~ModelBase ()
 
bool setTimeLastReference (const Hash &aObjectFingerPrint, quint32 aTimeWhenLastReferenced)
 
unsigned getMaxRowsToKeep ()
 
void setMaxRowsToKeep (unsigned aRows)
 
void truncateDataTableToMaxRows (void)
 
void updateDbTableRowCount ()
 

Private Member Functions

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)
 

Private Attributes

MControlleriController
 
const MModelProtocolInterfaceiModel
 
QList< CAObserver * > * iNewCaObservers
 

Additional Inherited Members

- Protected Attributes inherited from ModelBase
QString iDataTableName
 
unsigned iMaxRowsToKeep
 
unsigned iCurrentDbTableRowCount
 

Detailed Description

This is part of datamodel for storage/retrieval of classified ads.

This is persistent storage and search and retrieval of objects that are the classified ads that this program is about.

Member Enumeration Documentation

Another classification for an classified ad: what item/real life stuff the ad concerns

Enumerator
ConcerningCars 

is about cars

ConcerningBoats 

is about thing floating

ConcerningBikes 

is about 2-wheeled cars with no roof

ConcerningOtherVehicles 

is about other vehicles like moon rockets

ConcerningVehicleParts 

is about (spare) parts for moving things

ConcerningHabitation 

is about places of residence

ConcerningHouseholdAppliances 

is about machinery of residence

ConcerningFurniture 

is about furniture items

ConcerningClothing 

is about textiles

ConcerningTools 

is about tools

ConcerningSports 

is about sports, or items for sport

ConcerningMusic 

is about music or notes or instruments etc.

ConcerningBooks 

is about books

ConcerningMovies 

is about movies

ConcerningAnimals 

is about living creatures or accessories

ConcerningElectronics 

is about electronics

ConcerningJobs 

is about jobs like offers or requests

ConcerningTransportation 

is about moving things or persons

ConcerningServices 

is about services, any kind

ConcerningHealthcare 

is about health-care services or products

ConcerningFoodstuff 

is about things edible

ConcerningSoftware 

is about computer sw

ConcerningEvents 

is about events in time and place

ConcerningEducation 

is about education

ConcerningFinance 

is about financial services or products

ConcerningJewelry 

is about items for accenting ugliness

ConcerningReligiousRituals 

is about acts carrying attached meanings

ConcerningPhilosophy 

is about meanings

In classified ads the ads are classified. The classifications are defined here, first start about purpose of the ad

Enumerator
ToBeBought 

buy stuff ad

ToBeSold 

stuff for sale -ad

ToBeGivenAway 

crown jewels about to be given away here

IsWanted 

something is wanted, against payment or not

ToBeRented 

rental agreement, both ways

ToBeAnnounced 

just announcement about topic

Constructor & Destructor Documentation

ClassifiedAdsModel::ClassifiedAdsModel ( MController aMController,
const MModelProtocolInterface aModel 
)

Constructor

Parameters
aMControlleris application controller
aModelis datamodel
Returns
an instance
ClassifiedAdsModel::~ClassifiedAdsModel ( )

destructor

Member Function Documentation

CA ClassifiedAdsModel::caByHash ( const Hash aFingerPrint)

method for getting CA data for any purpose, like display

bool ClassifiedAdsModel::caDataForPublish ( const Hash aFingerPrint,
QByteArray &  aResultingCaData,
QByteArray &  aResultingSignature,
QByteArray &  aPublicKeyOfPublisher,
quint32 *  aTimeOfPublish = NULL 
)

method for getting ca data for publish purpose

Parameters
aTimeOfPublishif non-NULL will have its value set to publish time of the CA
void ClassifiedAdsModel::caListingByClassification ( const Hash aClassificationHash,
quint32  aStartDate,
quint32  aEndDate,
QList< QPair< Hash, quint32 > > &  aResultingArticles,
const Hash aRequestingNode 
)

Method for fetching list of classified ads whose classification matches given hash. This method produces content of reply to protocol item KAdsClassifiedAtHash.

Parameters
aClassificationHashad classification asked
aStartDatestart of time period asked
aEndDateend of time period asked
aResultingArticlesA list where results will be appended. Hash is the CA hash, unsigned is its timestamp
aRequestingNodefingerprint of node making the request
bool ClassifiedAdsModel::caListingByClassificationReceived ( QList< QPair< Hash, quint32 > > &  aReceivedArticles,
const Hash aRequestingNode,
const Hash aClassification 
)

method for handling list of classified ads produced by method caListingByClassification. The thing is that we come to this method when other node has sent us a list of ads available. We may want to store the article fingerprints and try to obtain them (the actual articles) later. For this reason the classified_ads database table allows null values in content ; that may be fetched later. Justification for this stupidity of not sending the article with the hash is bandwidht: there may be a node keeping the list of articles and rest of the ring keeping the articles.

This will modify contents of aReceivedArticles to not contain articles already found from db

const QString& ClassifiedAdsModel::concernOfAdString ( ConcernOfAd  aConcern) const
void ClassifiedAdsModel::contentReceived ( const Hash aHashOfContent,
const Hash aHashOfClassification,
const ProtocolItemType  aTypeOfReceivdContent 
)
signal

emitted when new classified ad is received.

Parameters
aHashOfContentis fingerprint of the article
aHashOfClassificationfingerprint of classification
aTypeOfReceivdContentType of content. This model mostly emits ClassifiedAd -types
bool ClassifiedAdsModel::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 
)
private

this method is called from publishedCAReceived and also on method where CA that is sent to us is to be handled

void ClassifiedAdsModel::error ( MController::CAErrorSituation  aError,
const QString &  aExplanation 
)
signal
void ClassifiedAdsModel::fillBucket ( QList< SendQueueItem > &  aSendQueue,
const Hash aStartOfBucket,
const Hash aEndOfBucket,
quint32  aLastMutualConnectTime,
const Hash aForNode 
)

Method for filling connected peers send queue with items that we have and that belong to said peers bucket.

Parameters
aSendQueueis send-queue of the connection that serves particular node
aStartOfBucketis hash where bucket of that peer starts. In practice it is the hash of the node itself.
aEndOfBucketis hash where bucket of that peer ends. That in turn depends on network size, or number of active nodes in the network. See method NodeModel::bucketEndHash for details.
aLastMutualConnectTimetime when node was last in contact. In practice we'll fill the bucket items published after this time.
void ClassifiedAdsModel::installCAObserver ( CAObserver aObserver)

method for installing observer for new ads

QString ClassifiedAdsModel::localizedConcernOfAdString ( ConcernOfAd  aConcern) const
QString ClassifiedAdsModel::localizedPurposeOfAdString ( PurposeOfAd  aPurpose) const

string returned is displayed to user. idea is that when hash of the classification is constructed, non-localized string from purposeOfAdString is used and same hash will be obtained regardless of the language used

Hash ClassifiedAdsModel::publishClassifiedAd ( const Profile aPublishingProfile,
CA aAd 
)

sends a classified ads to selected nodes in network for others to retrieve.

Parameters
aPublishingProfileis the publishing profile ; it is used to sign the content
aAdis the meat being thrown
Returns
Fingerprint of the published file or KNullHash if things went bad.
bool ClassifiedAdsModel::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 
)

called by protocol parser when a CA is received due to publish

Parameters
aFingerPrintis the profile Hash received from protocol header
aContentis actual ca data
aSignatureis digital signature of the aContent
aBangPathis list of low-order bits of hashes of nodes where this content has been. This is for preventing sending content back to nodes where it has already been.
aKeyOfPublisheris the key that was used to sign the file. that is transferred outside file just because the recipient might not have the key beforehand ; if she does, the existing key will be used in verifying process.
aFlagspossible flags telling about encyption and compression
aTimeStamptimestamp of file (if encrypted, it must be carried outside..)
Returns
true on success
const QString& ClassifiedAdsModel::purposeOfAdString ( PurposeOfAd  aPurpose) const

string returned here is used for constructing hash of the classification

void ClassifiedAdsModel::reIndexAllAdsIntoFTS ( )

debug method, more or less. reads all ads and feeds them to indexer

void ClassifiedAdsModel::removeCAObserver ( CAObserver aObserver)

method for removing previously installed observer for new ads

bool ClassifiedAdsModel::sentCAReceived ( const Hash aFingerPrint,
const QByteArray &  aContent,
const QByteArray &  aSignature,
const QByteArray &  aKeyOfPublisher,
const unsigned char  aFlags,
const quint32  aTimeStamp,
const Hash aFromNode 
)

called by protocol parser when a CA is received due to send

Parameters
aFingerPrintis the profile Hash received from protocol header
aContentis actual ca data
aSignatureis digital signature of the aContent
aKeyOfPublisheris the key that was used to sign the file. that is transferred outside file just because the recipient might not have the key beforehand ; if she does, the existing key will be used in verifying process.
aFlagspossible flags telling about encyption and compression
aTimeStamptimestamp of file (if encrypted, it must be carried outside..)
Returns
true on success

Member Data Documentation

MController* ClassifiedAdsModel::iController
private
const MModelProtocolInterface& ClassifiedAdsModel::iModel
private
QList<CAObserver*>* ClassifiedAdsModel::iNewCaObservers
private

The documentation for this class was generated from the following file: