Fixed bug #1734670: when logging off of MSN it did not hide the contacts
[centerim.git] / kkconsui / include / colorschemer.h
blob87fceda0c6675b8c4a9b32a57420fcd2d4030606
1 #ifndef __COLORSCHEMER_H__
2 #define __COLORSCHEMER_H__
4 #include <map>
5 #include <string>
6 #include <fstream>
8 #include "conscommon.h"
10 struct colordef {
11 string name, def;
12 int code;
15 void parsecolordef(const string sdef, int pair, colordef &d);
17 template <class T>
18 class colorschemer {
19 private:
20 map<T, colordef> colors;
22 public:
23 void clear() {
24 colors.clear();
27 void push(T elem, const string &def) {
28 parsecolordef(def, (int) elem, colors[elem]);
31 void load(const string &fname) {
32 ifstream f(fname.c_str());
33 if(f.is_open()) {
34 load(f);
35 f.close();
39 void save(const string &fname) const {
40 ofstream f(fname.c_str());
41 if(f.is_open()) {
42 save(f);
43 f.close();
47 void save(ofstream &f) const {
48 typename map<T, colordef>::const_iterator ic;
50 for(ic = colors.begin(); ic != colors.end(); ic++) {
51 f << ic->second.name << "\t" << ic->second.def << endl;
55 void load(ifstream &f) {
56 int pos;
57 string buf, p;
58 typename map<T, colordef>::iterator ic;
60 while(!f.eof()) {
61 getstring(f, buf);
63 if((pos = buf.find_first_of(" \t")) != -1) {
64 p = buf.substr(0, pos);
66 for(ic = colors.begin(); ic != colors.end(); ic++) {
67 if(ic->second.name == p) {
68 push(ic->first, buf);
69 break;
76 int operator[] (T elem) const {
77 typename map<T, colordef>::const_iterator ic = colors.find(elem);
78 return (ic != colors.end()) ? ic->second.code : normalcolor(0);
81 friend std::ostream& operator<< (std::ostream &o, const colorschemer &s) {
82 s.save(o);
83 return o;
87 #endif