~ubuntu-branches/ubuntu/utopic/kde-workspace/utopic-proposed

« back to all changes in this revision

Viewing changes to khotkeys/libkhotkeysprivate/windows_helper/window_selection_rules.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michał Zając
  • Date: 2011-07-09 08:31:15 UTC
  • Revision ID: james.westby@ubuntu.com-20110709083115-ohyxn6z93mily9fc
Tags: upstream-4.6.90
Import upstream version 4.6.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (C) 1999-2001 Lubos Lunak <l.lunak@kde.org>
 
2
   Copyright (C) 2008 Michael Jansen <kde@michael-jansen.biz>
 
3
 
 
4
   This program is free software; you can redistribute it and/or
 
5
   modify it under the terms of the GNU General Public License
 
6
   Version 2 as published by the Free Software Foundation;
 
7
 
 
8
   This program is distributed in the hope that it will be useful,
 
9
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
   GNU General Public License for more details.
 
12
 
 
13
   You should have received a copy of the GNU General Public License
 
14
   along with this program; if not, write to the Free Software
 
15
   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
16
*/
 
17
 
 
18
#include "windows_helper/window_selection_rules.h"
 
19
#include "windows_helper/window_selection_rules.h"
 
20
 
 
21
#include <KLocale>
 
22
#include <KDebug>
 
23
 
 
24
namespace KHotKeys {
 
25
 
 
26
Windowdef_simple::Windowdef_simple(
 
27
        const QString& comment_P,
 
28
        const QString& title_P,
 
29
        substr_type_t title_type_P,
 
30
        const QString& wclass_P,
 
31
        substr_type_t wclass_type_P,
 
32
        const QString& role_P,
 
33
        substr_type_t role_type_P,
 
34
        int window_types_P )
 
35
    :   Windowdef( comment_P ),
 
36
        _title( title_P ),
 
37
        _title_match_type( title_type_P ),
 
38
        _wclass( wclass_P ),
 
39
        _wclass_match_type( wclass_type_P ),
 
40
        _role( role_P ),
 
41
        _role_match_type( role_type_P ),
 
42
        _window_types( window_types_P )
 
43
    {}
 
44
 
 
45
 
 
46
Windowdef_simple::Windowdef_simple( KConfigGroup& cfg_P )
 
47
    : Windowdef( cfg_P )
 
48
    {
 
49
    _title = cfg_P.readEntry( "Title" );
 
50
    _title_match_type = static_cast< substr_type_t >( cfg_P.readEntry( "TitleType",0 ));
 
51
    _wclass = cfg_P.readEntry( "Class" );
 
52
    _wclass_match_type = static_cast< substr_type_t >( cfg_P.readEntry( "ClassType",0 ));
 
53
    _role = cfg_P.readEntry( "Role" );
 
54
    _role_match_type = static_cast< substr_type_t >( cfg_P.readEntry( "RoleType", 0 ));
 
55
    _window_types = cfg_P.readEntry( "WindowTypes",0 );
 
56
    }
 
57
 
 
58
 
 
59
void Windowdef_simple::cfg_write( KConfigGroup& cfg_P ) const
 
60
    {
 
61
    base::cfg_write( cfg_P );
 
62
    cfg_P.writeEntry( "Title", title());
 
63
    cfg_P.writeEntry( "TitleType", int(_title_match_type) );
 
64
    cfg_P.writeEntry( "Class", wclass());
 
65
    cfg_P.writeEntry( "ClassType", int(_wclass_match_type) );
 
66
    cfg_P.writeEntry( "Role", role());
 
67
    cfg_P.writeEntry( "RoleType", int(_role_match_type) );
 
68
    cfg_P.writeEntry( "WindowTypes", window_types());
 
69
    cfg_P.writeEntry( "Type", "SIMPLE" ); // overwrites value set in base::cfg_write()
 
70
    }
 
71
 
 
72
 
 
73
Windowdef_simple* Windowdef_simple::copy() const
 
74
    {
 
75
    return new Windowdef_simple( comment(), title(), title_match_type(), wclass(),
 
76
        wclass_match_type(), role(), role_match_type(), window_types());
 
77
    }
 
78
 
 
79
 
 
80
const QString Windowdef_simple::description() const
 
81
    {
 
82
    return i18n( "Window simple: " ) + comment();
 
83
    }
 
84
 
 
85
 
 
86
bool Windowdef_simple::is_substr_match( const QString& str1_P, const QString& str2_P,
 
87
    substr_type_t type_P )
 
88
    {
 
89
    switch( type_P )
 
90
        {
 
91
        case NOT_IMPORTANT :
 
92
          return true;
 
93
        case CONTAINS :
 
94
          return str1_P.contains( str2_P ) > 0;
 
95
        case IS :
 
96
          return str1_P == str2_P;
 
97
        case REGEXP :
 
98
            {
 
99
            QRegExp rg( str2_P );
 
100
          return rg.indexIn( str1_P ) >= 0;
 
101
            }
 
102
        case CONTAINS_NOT :
 
103
          return str1_P.contains( str2_P ) == 0;
 
104
        case IS_NOT :
 
105
          return str1_P != str2_P;
 
106
        case REGEXP_NOT :
 
107
            {
 
108
            QRegExp rg( str2_P );
 
109
          return rg.indexIn( str1_P ) < 0;
 
110
            }
 
111
        }
 
112
    return false;
 
113
    }
 
114
 
 
115
 
 
116
bool Windowdef_simple::match( const Window_data& window_P )
 
117
    {
 
118
    if( !type_match( window_P.type ))
 
119
        return false;
 
120
    if( !is_substr_match( window_P.title, title(), _title_match_type ))
 
121
        return false;
 
122
    if( !is_substr_match( window_P.wclass, wclass(), _wclass_match_type ))
 
123
        return false;
 
124
    if( !is_substr_match( window_P.role, role(), _role_match_type ))
 
125
        return false;
 
126
    kDebug() << "window match:" << window_P.title << ":OK";
 
127
    return true;
 
128
    }
 
129
 
 
130
 
 
131
const QString& Windowdef_simple::role() const
 
132
    {
 
133
    return _role;
 
134
    }
 
135
 
 
136
 
 
137
Windowdef_simple::substr_type_t Windowdef_simple::role_match_type() const
 
138
    {
 
139
    return _role_match_type;
 
140
    }
 
141
 
 
142
 
 
143
void Windowdef_simple::set_title(const QString &title)
 
144
    {
 
145
    _title = title;
 
146
    }
 
147
 
 
148
 
 
149
void Windowdef_simple::set_title_match_type(const substr_type_t &type)
 
150
    {
 
151
    _title_match_type = type;
 
152
    }
 
153
 
 
154
 
 
155
void Windowdef_simple::set_role(const QString &role)
 
156
    {
 
157
    _role = role;
 
158
    }
 
159
 
 
160
 
 
161
void Windowdef_simple::set_role_match_type(const substr_type_t &type)
 
162
    {
 
163
    _role_match_type = type;
 
164
    }
 
165
 
 
166
 
 
167
void Windowdef_simple::set_window_types(const int types)
 
168
    {
 
169
    _window_types = types;
 
170
    }
 
171
 
 
172
 
 
173
void Windowdef_simple::set_wclass(const QString &wclass)
 
174
    {
 
175
    _wclass = wclass;
 
176
    }
 
177
 
 
178
 
 
179
void Windowdef_simple::set_wclass_match_type(const substr_type_t &type)
 
180
    {
 
181
    _wclass_match_type = type;
 
182
    }
 
183
 
 
184
 
 
185
const QString& Windowdef_simple::title() const
 
186
    {
 
187
    return _title;
 
188
    }
 
189
 
 
190
 
 
191
Windowdef_simple::substr_type_t Windowdef_simple::title_match_type() const
 
192
    {
 
193
    return _title_match_type;
 
194
    }
 
195
 
 
196
 
 
197
bool Windowdef_simple::type_match( window_type_t type_P ) const
 
198
    {
 
199
    return window_types() & type_P;
 
200
    }
 
201
 
 
202
 
 
203
bool Windowdef_simple::type_match( NET::WindowType type_P ) const
 
204
    {
 
205
    return ( window_types() & ( 1 << type_P ))
 
206
        || ( type_P == NET::Unknown && ( window_types() & WINDOW_TYPE_NORMAL ));
 
207
        // CHECKME HACK haaaack !
 
208
    }
 
209
 
 
210
 
 
211
const QString& Windowdef_simple::wclass() const
 
212
    {
 
213
    return _wclass;
 
214
    }
 
215
 
 
216
 
 
217
Windowdef_simple::substr_type_t Windowdef_simple::wclass_match_type() const
 
218
    {
 
219
    return _wclass_match_type;
 
220
    }
 
221
 
 
222
 
 
223
int Windowdef_simple::window_types() const
 
224
    {
 
225
    return _window_types;
 
226
    }
 
227
 
 
228
} // namespace KHotKeys
 
229