Statistics
| Branch: | Tag: | Revision:

root / kadu-core / status / base-status-container.cpp @ f38188d2

History | View | Annotate | Download (2.6 kB)

1
/*
2
 * %kadu copyright begin%
3
 * Copyright 2009, 2009, 2010 RafaƂ Malinowski (rafal.przemyslaw.malinowski@gmail.com)
4
 * Copyright 2009 Piotr Galiszewski (piotrgaliszewski@gmail.com)
5
 * %kadu copyright end%
6
 *
7
 * This program is free software; you can redistribute it and/or
8
 * modify it under the terms of the GNU General Public License as
9
 * published by the Free Software Foundation; either version 2 of
10
 * the License, or (at your option) any later version.
11
 *
12
 * This program is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
 * GNU General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU General Public License
18
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19
 */
20
21
#include "configuration/configuration-file.h"
22
#include "storage/storable-object.h"
23
24
#include "base-status-container.h"
25
26
BaseStatusContainer::BaseStatusContainer(StorableObject *storableObject) :
27
                MyStorableObject(storableObject)
28
{
29
}
30
31
void BaseStatusContainer::setDefaultStatus(const QString &startupStatus, bool offlineToInvisible,
32
                const QString &startupDescription, bool StartupLastDescription)
33
{
34
        if (!MyStorableObject->isValidStorage())
35
                return;
36
37
        QString description;
38
        if (StartupLastDescription)
39
                description = MyStorableObject->loadValue<QString>("LastStatusDescription");
40
        else
41
                description = startupDescription;
42
43
        QString name;
44
        if (startupStatus == "LastStatus")
45
        {
46
                name = MyStorableObject->loadValue<QString>("LastStatusName");
47
                if (name.isEmpty())
48
                        name = "Online";
49
                else if ("Offline" == name && offlineToInvisible)
50
                        name = "Invisible";
51
        }
52
        else
53
                name = startupStatus;
54
55
        if ("Offline" == name && offlineToInvisible)
56
                name = "Invisible";
57
58
        Status status;
59
        status.setType(name);
60
        status.setDescription(description);
61
62
        setPrivateStatus(config_file.readBoolEntry("General", "PrivateStatus"));
63
64
        setStatus(status);
65
}
66
67
void BaseStatusContainer::disconnectAndStoreLastStatus(bool disconnectWithCurrentDescription,
68
                const QString &disconnectDescription)
69
{
70
        if (!MyStorableObject->isValidStorage())
71
                return;
72
73
        MyStorableObject->storeValue("LastStatusDescription", status().description());
74
        MyStorableObject->storeValue("LastStatusName", statusName());
75
76
        if (status().type() == "Offline")
77
                return;
78
79
        Status disconnectStatus;
80
        disconnectStatus.setType("Offline");
81
        QString description;
82
        if (disconnectWithCurrentDescription)
83
                description = status().description();
84
        else
85
                description = disconnectDescription;
86
87
        disconnectStatus.setDescription(description);
88
        setStatus(disconnectStatus);
89
}