1 /*
2  * Copyright (C) 2001-2012 Jacek Sieka, arnetheduck on gmail point com
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17  */
18 
19 #pragma once
20 
21 #include "Util.h"
22 #include "Flags.h"
23 
24 namespace dcpp {
25 
26 class UserCommand : public Flags {
27 public:
28     typedef vector<UserCommand> List;
29 
30     enum {
31         TYPE_SEPARATOR,
32         TYPE_RAW,
33         TYPE_RAW_ONCE,
34         TYPE_REMOVE,
35         TYPE_CHAT,
36         TYPE_CHAT_ONCE,
37         TYPE_CLEAR = 255        // In a momentary lapse of reason, 255 was chosen in the nmdc version of usercommand for clearing them all
38     };
39 
40     enum {
41         CONTEXT_HUB = 0x01,
42         CONTEXT_USER = 0x02,
43         CONTEXT_SEARCH = 0x04,
44         CONTEXT_FILELIST = 0x08,
45         CONTEXT_MASK = CONTEXT_HUB | CONTEXT_USER | CONTEXT_SEARCH | CONTEXT_FILELIST
46     };
47 
48     enum {
49         FLAG_NOSAVE = 0x01
50     };
51 
UserCommand()52     UserCommand() : cid(0), type(0), ctx(0) { }
UserCommand(int aId,int aType,int aCtx,int aFlags,const string & aName,const string & aCommand,const string & aTo,const string & aHub)53     UserCommand(int aId, int aType, int aCtx, int aFlags, const string& aName, const string& aCommand, const string& aTo, const string& aHub) noexcept
54         : Flags(aFlags), cid(aId), type(aType), ctx(aCtx), name(aName), command(aCommand), to(aTo), hub(aHub)
55     {
56         setDisplayName();
57     }
58 
UserCommand(const UserCommand & rhs)59     UserCommand(const UserCommand& rhs) : Flags(rhs), cid(rhs.cid), type(rhs.type),
60                 ctx(rhs.ctx), name(rhs.name), command(rhs.command), to(rhs.to), hub(rhs.hub)
61     {
62         setDisplayName();
63     }
64 
65     UserCommand& operator=(const UserCommand& rhs) {
66         cid = rhs.cid; type = rhs.type; ctx = rhs.ctx;
67         name = rhs.name; command = rhs.command; to = rhs.to; hub = rhs.hub;
68         *((Flags*)this) = rhs;
69         displayName.clear();
70         setDisplayName();
71         return *this;
72     }
73 
isRaw()74     inline bool isRaw() const {
75         return type == TYPE_RAW || type == TYPE_RAW_ONCE;
76     }
isChat()77     inline bool isChat() const {
78         return type == TYPE_CHAT || type == TYPE_CHAT_ONCE;
79     }
once()80     inline bool once() const {
81         return type == TYPE_RAW_ONCE || type == TYPE_CHAT_ONCE;
82     }
83 
84     static bool adc(const string& h);
adc()85     inline bool adc() const { return adc(hub); }
86 
87     const StringList& getDisplayName() const;
88     void setDisplayName();
89 
90     GETSET(int, cid, Id);
91     GETSET(int, type, Type);
92     GETSET(int, ctx, Ctx);
93     GETSET(string, name, Name);
94     GETSET(string, command, Command);
95     GETSET(string, to, To);
96     GETSET(string, hub, Hub);
97 
98 private:
99     StringList displayName;
100 };
101 
102 } // namespace dcpp
103