HaikuDepot: Implementation of model classes for package info representation

This commit is contained in:
Stephan Aßmus 2013-07-28 11:56:45 +02:00
parent 10ad1350c5
commit 82bdec56d4
3 changed files with 291 additions and 0 deletions

View File

@ -8,6 +8,7 @@ Application HaikuDepot :
main.cpp
MainWindow.cpp
PackageActionsView.cpp
PackageInfo.cpp
PackageInfoView.cpp
PackageListView.cpp
support.cpp

View File

@ -0,0 +1,191 @@
/*
* Copyright 2013, Stephan Aßmus <superstippi@gmx.de>.
* All rights reserved. Distributed under the terms of the MIT License.
*/
#include "PackageInfo.h"
#include <stdio.h>
// #pragma mark - UserInfo
UserInfo::UserInfo()
:
fNickName()
{
}
UserInfo::UserInfo(const BString& fNickName)
:
fNickName(fNickName)
{
}
UserInfo::UserInfo(const UserInfo& other)
:
fNickName(other.fNickName)
{
}
UserInfo&
UserInfo::operator=(const UserInfo& other)
{
fNickName = other.fNickName;
return *this;
}
bool
UserInfo::operator==(const UserInfo& other) const
{
return fNickName == other.fNickName;
}
bool
UserInfo::operator!=(const UserInfo& other) const
{
return !(*this == other);
}
// #pragma mark - UserRating
UserRating::UserRating()
:
fUserInfo(),
fComment(),
fRating(0.0f),
fPackageVersion()
{
}
UserRating::UserRating(const UserInfo& userInfo, const BString& comment,
float rating, const BString& packageVersion)
:
fUserInfo(userInfo),
fComment(comment),
fRating(rating),
fPackageVersion(packageVersion)
{
}
UserRating::UserRating(const UserRating& other)
:
fUserInfo(other.fUserInfo),
fComment(other.fComment),
fRating(other.fRating),
fPackageVersion(other.fPackageVersion)
{
}
UserRating&
UserRating::operator=(const UserRating& other)
{
fUserInfo = other.fUserInfo;
fComment = other.fComment;
fRating = other.fRating;
fPackageVersion = other.fPackageVersion;
return *this;
}
bool
UserRating::operator==(const UserRating& other) const
{
return fUserInfo == other.fUserInfo
&& fComment == other.fComment
&& fRating == other.fRating
&& fPackageVersion == other.fPackageVersion;
}
bool
UserRating::operator!=(const UserRating& other) const
{
return !(*this == other);
}
// #pragma mark - PackageInfo
PackageInfo::PackageInfo()
:
fTitle(),
fVersion(),
fDescription(),
fChangelog(),
fUserRatings()
{
}
PackageInfo::PackageInfo(const BString& title, const BString& version,
const BString& description, const BString& changelog)
:
fTitle(title),
fVersion(version),
fDescription(description),
fChangelog(changelog),
fUserRatings()
{
}
PackageInfo::PackageInfo(const PackageInfo& other)
:
fTitle(other.fTitle),
fVersion(other.fVersion),
fDescription(other.fDescription),
fChangelog(other.fChangelog),
fUserRatings(other.fUserRatings)
{
}
PackageInfo&
PackageInfo::operator=(const PackageInfo& other)
{
fTitle = other.fTitle;
fVersion = other.fVersion;
fDescription = other.fDescription;
fChangelog = other.fChangelog;
fUserRatings = other.fUserRatings;
return *this;
}
bool
PackageInfo::operator==(const PackageInfo& other) const
{
return fTitle == other.fTitle
&& fVersion == other.fVersion
&& fDescription == other.fDescription
&& fChangelog == other.fChangelog
&& fUserRatings == other.fUserRatings;
}
bool
PackageInfo::operator!=(const PackageInfo& other) const
{
return !(*this == other);
}
bool
PackageInfo::AddUserRating(const UserRating& rating)
{
return fUserRatings.Add(rating);
}

View File

@ -0,0 +1,99 @@
/*
* Copyright 2013, Stephan Aßmus <superstippi@gmx.de>.
* All rights reserved. Distributed under the terms of the MIT License.
*/
#ifndef PACKAGE_INFO_H
#define PACKAGE_INFO_H
#include <String.h>
#include "List.h"
class UserInfo {
public:
UserInfo();
UserInfo(const BString& nickName);
UserInfo(const UserInfo& other);
UserInfo& operator=(const UserInfo& other);
bool operator==(const UserInfo& other) const;
bool operator!=(const UserInfo& other) const;
const BString& NickName() const;
private:
BString fNickName;
};
class UserRating {
public:
UserRating();
UserRating(const UserInfo& userInfo,
const BString& comment, float rating,
const BString& packageVersion);
UserRating(const UserRating& other);
UserRating& operator=(const UserRating& other);
bool operator==(const UserRating& other) const;
bool operator!=(const UserRating& other) const;
const UserInfo& User() const
{ return fUserInfo; }
const BString& Comment() const
{ return fComment; }
const float Rating() const
{ return fRating; }
const BString& PackageVersion() const
{ return fPackageVersion; }
private:
UserInfo fUserInfo;
BString fComment;
float fRating;
BString fPackageVersion;
};
typedef List<UserRating, false> UserRatingList;
class PackageInfo {
public:
PackageInfo();
PackageInfo(const BString& title,
const BString& version,
const BString& description,
const BString& changelog);
PackageInfo(const PackageInfo& other);
PackageInfo& operator=(const PackageInfo& other);
bool operator==(const PackageInfo& other) const;
bool operator!=(const PackageInfo& other) const;
const BString& Title() const
{ return fTitle; }
const BString& Version() const
{ return fVersion; }
const BString& Description() const
{ return fDescription; }
const BString& Changelog() const
{ return fChangelog; }
bool AddUserRating(const UserRating& rating);
private:
BString fTitle;
BString fVersion;
BString fDescription;
BString fChangelog;
UserRatingList fUserRatings;
};
typedef List<PackageInfo, false> PackageInfoList;
#endif // PACKAGE_INFO_H