~ubuntu-branches/ubuntu/trusty/fluxbox/trusty-proposed

« back to all changes in this revision

Viewing changes to src/Resources.cc

  • Committer: Bazaar Package Importer
  • Author(s): Dmitry E. Oboukhov
  • Date: 2008-07-01 10:38:14 UTC
  • mfrom: (2.1.12 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080701103814-khx2b6il152x9p93
Tags: 1.0.0+deb1-8
* x-dev has been removed from build-depends (out-of-date package).
* Standards-Version bumped to 3.8.0.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// Resources.cc for Fluxbox Window Manager
2
 
// Copyright (c) 2004 - 2005 Henrik Kinnunen (fluxgen at fluxbox dot org)
3
 
//
4
 
// Permission is hereby granted, free of charge, to any person obtaining a
5
 
// copy of this software and associated documentation files (the "Software"),
6
 
// to deal in the Software without restriction, including without limitation
7
 
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
8
 
// and/or sell copies of the Software, and to permit persons to whom the
9
 
// Software is furnished to do so, subject to the following conditions:
10
 
//
11
 
// The above copyright notice and this permission notice shall be included in
12
 
// all copies or substantial portions of the Software.
13
 
//
14
 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
 
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
 
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17
 
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
 
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19
 
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20
 
// DEALINGS IN THE SOFTWARE.
21
 
 
22
 
// $Id: Resources.cc 3995 2005-05-06 18:04:14Z mathias $
23
 
 
24
 
 
25
 
// holds main resource functions
26
 
 
27
 
#include "fluxbox.hh"
28
 
#include "FbTk/StringUtil.hh"
29
 
 
30
 
#include <stdio.h>
31
 
#include <string>
32
 
 
33
 
using namespace std;
34
 
using namespace FbTk;
35
 
 
36
 
//-----------------------------------------------------------------
37
 
//---- accessors for int, bool, and some enums with Resource ------
38
 
//-----------------------------------------------------------------
39
 
 
40
 
namespace FbTk {
41
 
 
42
 
template<>
43
 
void FbTk::Resource<int>::
44
 
setFromString(const char* strval) {
45
 
    int val;
46
 
    if (sscanf(strval, "%d", &val)==1)
47
 
        *this = val;
48
 
}
49
 
 
50
 
template<>
51
 
void FbTk::Resource<std::string>::
52
 
setFromString(const char *strval) {
53
 
    *this = strval;
54
 
}
55
 
 
56
 
template<>
57
 
void FbTk::Resource<bool>::
58
 
setFromString(char const *strval) {
59
 
    *this = (bool)!strcasecmp(strval, "true");
60
 
}
61
 
 
62
 
template<>
63
 
void FbTk::Resource<Fluxbox::TitlebarList>::
64
 
setFromString(char const *strval) {
65
 
    vector<std::string> val;
66
 
    StringUtil::stringtok(val, strval);
67
 
    int size=val.size();
68
 
    //clear old values
69
 
    m_value.clear();
70
 
                
71
 
    for (int i=0; i<size; i++) {
72
 
        if (strcasecmp(val[i].c_str(), "Maximize")==0)
73
 
            m_value.push_back(Fluxbox::MAXIMIZE);
74
 
        else if (strcasecmp(val[i].c_str(), "Minimize")==0)
75
 
            m_value.push_back(Fluxbox::MINIMIZE);
76
 
        else if (strcasecmp(val[i].c_str(), "Shade")==0)
77
 
            m_value.push_back(Fluxbox::SHADE);
78
 
        else if (strcasecmp(val[i].c_str(), "Stick")==0)
79
 
            m_value.push_back(Fluxbox::STICK);
80
 
        else if (strcasecmp(val[i].c_str(), "MenuIcon")==0)
81
 
            m_value.push_back(Fluxbox::MENUICON);
82
 
        else if (strcasecmp(val[i].c_str(), "Close")==0)
83
 
            m_value.push_back(Fluxbox::CLOSE);
84
 
    }
85
 
}
86
 
 
87
 
template<>
88
 
void FbTk::Resource<Fluxbox::TabsAttachArea>::
89
 
setFromString(char const *strval) {
90
 
    if (strcasecmp(strval, "Titlebar")==0)
91
 
        m_value= Fluxbox::ATTACH_AREA_TITLEBAR;
92
 
    else
93
 
        m_value= Fluxbox::ATTACH_AREA_WINDOW;
94
 
}
95
 
 
96
 
template<>
97
 
void FbTk::Resource<unsigned int>::
98
 
setFromString(const char *strval) {     
99
 
    if (sscanf(strval, "%ul", &m_value) != 1)
100
 
        setDefaultValue();
101
 
}
102
 
 
103
 
template<>
104
 
void FbTk::Resource<long long>::
105
 
setFromString(const char *strval) {     
106
 
    if (sscanf(strval, "%llu", &m_value) != 1)
107
 
        setDefaultValue();
108
 
}
109
 
 
110
 
 
111
 
//-----------------------------------------------------------------
112
 
//---- manipulators for int, bool, and some enums with Resource ---
113
 
//-----------------------------------------------------------------
114
 
template<>
115
 
std::string FbTk::Resource<bool>::
116
 
getString() {                           
117
 
    return std::string(**this == true ? "true" : "false");
118
 
}
119
 
 
120
 
template<>
121
 
std::string FbTk::Resource<int>::
122
 
getString() {
123
 
    char strval[256];
124
 
    sprintf(strval, "%d", **this);
125
 
    return std::string(strval);
126
 
}
127
 
 
128
 
template<>
129
 
std::string FbTk::Resource<std::string>::
130
 
getString() { return **this; }
131
 
 
132
 
 
133
 
template<>
134
 
std::string FbTk::Resource<Fluxbox::TitlebarList>::
135
 
getString() {
136
 
    string retval;
137
 
    int size=m_value.size();
138
 
    for (int i=0; i<size; i++) {
139
 
        switch (m_value[i]) {
140
 
        case Fluxbox::SHADE:
141
 
            retval.append("Shade");
142
 
            break;
143
 
        case Fluxbox::MINIMIZE:
144
 
            retval.append("Minimize");
145
 
            break;
146
 
        case Fluxbox::MAXIMIZE:
147
 
            retval.append("Maximize");
148
 
            break;
149
 
        case Fluxbox::CLOSE:
150
 
            retval.append("Close");
151
 
            break;
152
 
        case Fluxbox::STICK:
153
 
            retval.append("Stick");
154
 
            break;
155
 
        case Fluxbox::MENUICON:
156
 
            retval.append("MenuIcon");
157
 
            break;
158
 
        default:
159
 
            break;
160
 
        }
161
 
        retval.append(" ");
162
 
    }
163
 
 
164
 
    return retval;
165
 
}
166
 
 
167
 
template<>
168
 
std::string FbTk::Resource<Fluxbox::TabsAttachArea>::
169
 
getString() {
170
 
    if (m_value == Fluxbox::ATTACH_AREA_TITLEBAR)
171
 
        return "Titlebar";
172
 
    else
173
 
        return "Window";
174
 
}
175
 
 
176
 
template<>
177
 
string FbTk::Resource<unsigned int>::
178
 
getString() {
179
 
    char tmpstr[128];
180
 
    sprintf(tmpstr, "%ul", m_value);
181
 
    return string(tmpstr);
182
 
}
183
 
 
184
 
template<>
185
 
string FbTk::Resource<long long>::
186
 
getString() {
187
 
    char tmpstr[128];
188
 
    sprintf(tmpstr, "%llu", (unsigned long long) m_value);
189
 
    return string(tmpstr);
190
 
}
191
 
 
192
 
template<>
193
 
void FbTk::Resource<Fluxbox::Layer>::
194
 
setFromString(const char *strval) {
195
 
    int tempnum = 0;
196
 
    if (sscanf(strval, "%d", &tempnum) == 1)
197
 
        m_value = tempnum;
198
 
    else if (strcasecmp(strval, "Menu") == 0)
199
 
        m_value = Fluxbox::instance()->getMenuLayer();
200
 
    else if (strcasecmp(strval, "AboveDock") == 0)
201
 
        m_value = Fluxbox::instance()->getAboveDockLayer();
202
 
    else if (strcasecmp(strval, "Dock") == 0)
203
 
        m_value = Fluxbox::instance()->getDockLayer();
204
 
    else if (strcasecmp(strval, "Top") == 0)
205
 
        m_value = Fluxbox::instance()->getTopLayer();
206
 
    else if (strcasecmp(strval, "Normal") == 0)
207
 
        m_value = Fluxbox::instance()->getNormalLayer();
208
 
    else if (strcasecmp(strval, "Bottom") == 0)
209
 
        m_value = Fluxbox::instance()->getBottomLayer();
210
 
    else if (strcasecmp(strval, "Desktop") == 0)
211
 
        m_value = Fluxbox::instance()->getDesktopLayer();
212
 
    else 
213
 
        setDefaultValue();
214
 
}
215
 
 
216
 
 
217
 
template<>
218
 
string FbTk::Resource<Fluxbox::Layer>::
219
 
getString() {
220
 
 
221
 
    if (m_value.getNum() == Fluxbox::instance()->getMenuLayer()) 
222
 
        return string("Menu");
223
 
    else if (m_value.getNum() == Fluxbox::instance()->getAboveDockLayer()) 
224
 
        return string("AboveDock");
225
 
    else if (m_value.getNum() == Fluxbox::instance()->getDockLayer()) 
226
 
        return string("Dock");
227
 
    else if (m_value.getNum() == Fluxbox::instance()->getTopLayer()) 
228
 
        return string("Top");
229
 
    else if (m_value.getNum() == Fluxbox::instance()->getNormalLayer()) 
230
 
        return string("Normal");
231
 
    else if (m_value.getNum() == Fluxbox::instance()->getBottomLayer()) 
232
 
        return string("Bottom");
233
 
    else if (m_value.getNum() == Fluxbox::instance()->getDesktopLayer()) 
234
 
        return string("Desktop");
235
 
    else {
236
 
        char tmpstr[128];
237
 
        sprintf(tmpstr, "%d", m_value.getNum());
238
 
        return string(tmpstr);
239
 
    }
240
 
}
241
 
template<>
242
 
void FbTk::Resource<long>::
243
 
setFromString(const char *strval) {   
244
 
    if (sscanf(strval, "%ld", &m_value) != 1)
245
 
        setDefaultValue();
246
 
}
247
 
 
248
 
template<>
249
 
string FbTk::Resource<long>::
250
 
getString() {
251
 
    char tmpstr[128];
252
 
    sprintf(tmpstr, "%ld", m_value);
253
 
    return string(tmpstr);
254
 
}
255
 
 
256
 
}