File: buddy.cpp

package info (click to toggle)
libmsn 4.1-1.2
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 1,936 kB
  • ctags: 1,588
  • sloc: cpp: 13,581; makefile: 47
file content (76 lines) | stat: -rw-r--r-- 2,378 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*
 * buddy.cpp
 * libmsn
 *
 * Created by Mark Rowe on Mon Apr 19 2004.
 * Refactored by Tiago Salem Herrmann on 08/2007.
 * Copyright (c) 2004 Mark Rowe. All rights reserved.
 * Copyright (c) 2007 Tiago Salem Herrmann. All rights reserved
 *
 * 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) any later version.
 *
 * 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, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#include <msn/buddy.h>
#include <cassert>

namespace MSN
{
    std::string buddyStatusToString(BuddyStatus state)
    {
        switch (state)
        {
            case STATUS_AVAILABLE:
                return "NLN";
            case STATUS_BUSY:
                return "BSY";
            case STATUS_IDLE:
                return "IDL";
            case STATUS_BERIGHTBACK:
                return "BRB";
            case STATUS_AWAY:
                return "AWY";
            case STATUS_ONTHEPHONE:
                return "PHN";
            case STATUS_OUTTOLUNCH:
            return "LUN";
            case STATUS_INVISIBLE:
                return "HDN";
            default:
                assert(false);
        }
    }
    
    BuddyStatus buddyStatusFromString(std::string state)
    {
        if (state == "NLN")
            return STATUS_AVAILABLE;
        else if (state == "BSY")
            return STATUS_BUSY;
        else if (state == "IDL")
            return STATUS_IDLE;
        else if (state == "BRB")
            return STATUS_BERIGHTBACK;
        else if (state == "AWY")
            return STATUS_AWAY;
        else if (state == "PHN")
            return STATUS_ONTHEPHONE;
        else if (state == "LUN")
            return STATUS_OUTTOLUNCH;
        else if (state == "HDN")
            return STATUS_INVISIBLE;
        else
            throw std::runtime_error("Unknown status!");
    }
}