bilbopost.cpp 5.03 KB
Newer Older
Mehrdad Momeny's avatar
Mehrdad Momeny committed
1 2 3
/*
    This file is part of Blogilo, A KDE Blogging Client

4 5
    Copyright (C) 2008-2010 Mehrdad Momeny <mehrdad.momeny@gmail.com>
    Copyright (C) 2008-2010 Golnaz Nilieh <g382nilieh@gmail.com>
Mehrdad Momeny's avatar
Mehrdad Momeny committed
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22

    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License as
    published by the Free Software Foundation; either version 2 of
    the License or (at your option) version 3 or any later version
    accepted by the membership of KDE e.V. (or its successor approved
    by the membership of KDE e.V.), which shall act as a proxy
    defined in Section 14 of version 3 of the license.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, see http://www.gnu.org/licenses/
*/
23 24

#include "bilbopost.h"
Laurent Montel's avatar
Laurent Montel committed
25
#include "blogilo_debug.h"
Laurent Montel's avatar
Laurent Montel committed
26
#include <QStringList>
27
#include <QDateTime>
Laurent Montel's avatar
Laurent Montel committed
28

29 30 31 32 33
class BilboPostPrivate
{
public:
    QString mAuthor;
    int mId;///id in DB
34
    int localId;
35
    bool mModifyTimeStamp;///Just for toolbox entry!
Laurent Montel's avatar
Laurent Montel committed
36
    QVector<Category> mCategoryList;
37 38
};

39
BilboPost::BilboPost()
Laurent Montel's avatar
Laurent Montel committed
40
    : KBlog::BlogPost(), d_ptr(new BilboPostPrivate)
41
{
42 43
    this->setCreationDateTime(QDateTime::currentDateTime());
    this->setModificationDateTime(QDateTime::currentDateTime());
Laurent Montel's avatar
Laurent Montel committed
44 45 46
    this->setCommentAllowed(true);
    this->setPrivate(false);
    this->setTrackBackAllowed(true);
47
    d_ptr->mModifyTimeStamp = false;
Laurent Montel's avatar
Laurent Montel committed
48 49 50
    this->setId(-1);
    this->setLocalId(-1);
    this->setStatus(KBlog::BlogPost::New);
51 52
}

Laurent Montel's avatar
Laurent Montel committed
53 54
BilboPost::BilboPost(const KBlog::BlogPost &post)
    : KBlog::BlogPost(post), d_ptr(new BilboPostPrivate)
55 56
{
    d_ptr->mId = -1;
57
    d_ptr->localId = -1;
58 59 60
    d_ptr->mModifyTimeStamp = false;
}

Laurent Montel's avatar
Laurent Montel committed
61
BilboPost::BilboPost(const BilboPost &post)
Laurent Montel's avatar
Laurent Montel committed
62
    : KBlog::BlogPost(post), d_ptr(new BilboPostPrivate)
63
{
Laurent Montel's avatar
Laurent Montel committed
64 65 66 67 68
    this->setAuthor(post.author());
    this->setModifyTimeStamp(post.isModifyTimeStamp());
    this->setId(post.id());
    setLocalId(post.localId());
    this->setCategoryList(post.categoryList());
69 70
}

71 72
BilboPost::~BilboPost()
{
73
    delete d_ptr;
74 75 76 77
}

QString BilboPost::author() const
{
78
    return d_ptr->mAuthor;
79 80
}

Laurent Montel's avatar
Laurent Montel committed
81
void BilboPost::setId(const int id)
82
{
83
    d_ptr->mId = id;
84 85 86 87
}

int BilboPost::id() const
{
88
    return d_ptr->mId;
89 90
}

Laurent Montel's avatar
Laurent Montel committed
91
void BilboPost::setAuthor(const QString &author)
92
{
93
    d_ptr->mAuthor = author;
94
}
95 96 97 98 99 100 101

int BilboPost::localId() const
{
    return d_ptr->localId;
}

void BilboPost::setLocalId(const int localId)
102
{
103 104
    d_ptr->localId = localId;
}
105 106 107

QString BilboPost::toString() const
{
Laurent Montel's avatar
Laurent Montel committed
108 109
    //  if(!title().isEmpty())
    //   qDebug("BilboPost::toString: title is %s", this->title());
110
    QString ret;
111
    ret = QStringLiteral("\n******* Post Info **********");
Laurent Montel's avatar
Laurent Montel committed
112 113 114
    ret += QLatin1String("\nID: ") + postId();
    ret += QLatin1String("\nTitle: ") + title();
    ret += QLatin1String("\nContent: ") + content();
115
    ret += QLatin1String("\nAdditionalContent: ") + additionalContent();
116 117
    ret += QLatin1String("\nTags: ") + tags().join(QStringLiteral(","));
    ret += QLatin1String("\nCategories: ") + categories().join(QStringLiteral(","));
118 119 120 121
    ret += QLatin1String("\nCreation Date Time: ") + creationDateTime().toString();
    ret += QLatin1String("\nStatus: ") + QString::number(status());
    ret += QLatin1String("\nIsPrivate: ") + QVariant(isPrivate()).toString();
    ret += QLatin1String("\n******* End Post Info ********\n");
122 123 124 125 126
    return ret;
}

bool BilboPost::isModifyTimeStamp() const
{
127
    return d_ptr->mModifyTimeStamp;
128 129
}

Laurent Montel's avatar
Laurent Montel committed
130
void BilboPost::setModifyTimeStamp(bool isModify)
131
{
132
    d_ptr->mModifyTimeStamp = isModify;
133 134
}

Laurent Montel's avatar
Laurent Montel committed
135
QVector<Category> BilboPost::categoryList() const
136
{
137
    return d_ptr->mCategoryList;
138 139
}

Laurent Montel's avatar
Laurent Montel committed
140
void BilboPost::setCategoryList(const QVector<Category> &list)
141
{
142
    d_ptr->mCategoryList = list;
143
    QStringList cats;
Laurent Montel's avatar
Cleanup  
Laurent Montel committed
144
    const int count = list.count();
Laurent Montel's avatar
Laurent Montel committed
145
    cats.reserve(count);
Laurent Montel's avatar
Laurent Montel committed
146 147
    for (int i = 0; i < count; ++i) {
        cats.append(list.at(i).name);
148
    }
Laurent Montel's avatar
Laurent Montel committed
149
    setCategories(cats);
150 151
}

Laurent Montel's avatar
Laurent Montel committed
152
void BilboPost::setProperties(const BilboPost &postProp)
153
{
Laurent Montel's avatar
Laurent Montel committed
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
    this->setCreationDateTime(postProp.creationDateTime());
    this->setModificationDateTime(postProp.modificationDateTime());
    this->setLink(postProp.link());
    this->setPermaLink(postProp.permaLink());
    this->setCategories(postProp.categories());
    this->setCategoryList(postProp.categoryList());
    this->setCommentAllowed(postProp.isCommentAllowed());
    this->setTags(postProp.tags());
    this->setMood(postProp.mood());
    this->setMusic(postProp.music());
    this->setSummary(postProp.summary());
    this->setTrackBackAllowed(postProp.isTrackBackAllowed());
    this->setAuthor(postProp.author());
    this->setModifyTimeStamp(postProp.isModifyTimeStamp());
    this->setSlug(postProp.slug());
}

BilboPost &BilboPost::operator=(const BilboPost &other)
172 173
{
    KBlog::BlogPost other2 = KBlog::BlogPost::operator=(other);
Laurent Montel's avatar
Laurent Montel committed
174 175
    BilboPost copy(other2);
    swap(copy);
176 177
    return *this;
}