1
/* Copyright (C) 1999-2001 Lubos Lunak <l.lunak@kde.org>
2
Copyright (C) 2008 Michael Jansen <kde@michael-jansen.biz>
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;
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.
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.
18
#include "windows_helper/window_selection_rules.h"
19
#include "windows_helper/window_selection_rules.h"
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,
35
: Windowdef( comment_P ),
37
_title_match_type( title_type_P ),
39
_wclass_match_type( wclass_type_P ),
41
_role_match_type( role_type_P ),
42
_window_types( window_types_P )
46
Windowdef_simple::Windowdef_simple( KConfigGroup& cfg_P )
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 );
59
void Windowdef_simple::cfg_write( KConfigGroup& cfg_P ) const
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()
73
Windowdef_simple* Windowdef_simple::copy() const
75
return new Windowdef_simple( comment(), title(), title_match_type(), wclass(),
76
wclass_match_type(), role(), role_match_type(), window_types());
80
const QString Windowdef_simple::description() const
82
return i18n( "Window simple: " ) + comment();
86
bool Windowdef_simple::is_substr_match( const QString& str1_P, const QString& str2_P,
87
substr_type_t type_P )
94
return str1_P.contains( str2_P ) > 0;
96
return str1_P == str2_P;
100
return rg.indexIn( str1_P ) >= 0;
103
return str1_P.contains( str2_P ) == 0;
105
return str1_P != str2_P;
108
QRegExp rg( str2_P );
109
return rg.indexIn( str1_P ) < 0;
116
bool Windowdef_simple::match( const Window_data& window_P )
118
if( !type_match( window_P.type ))
120
if( !is_substr_match( window_P.title, title(), _title_match_type ))
122
if( !is_substr_match( window_P.wclass, wclass(), _wclass_match_type ))
124
if( !is_substr_match( window_P.role, role(), _role_match_type ))
126
kDebug() << "window match:" << window_P.title << ":OK";
131
const QString& Windowdef_simple::role() const
137
Windowdef_simple::substr_type_t Windowdef_simple::role_match_type() const
139
return _role_match_type;
143
void Windowdef_simple::set_title(const QString &title)
149
void Windowdef_simple::set_title_match_type(const substr_type_t &type)
151
_title_match_type = type;
155
void Windowdef_simple::set_role(const QString &role)
161
void Windowdef_simple::set_role_match_type(const substr_type_t &type)
163
_role_match_type = type;
167
void Windowdef_simple::set_window_types(const int types)
169
_window_types = types;
173
void Windowdef_simple::set_wclass(const QString &wclass)
179
void Windowdef_simple::set_wclass_match_type(const substr_type_t &type)
181
_wclass_match_type = type;
185
const QString& Windowdef_simple::title() const
191
Windowdef_simple::substr_type_t Windowdef_simple::title_match_type() const
193
return _title_match_type;
197
bool Windowdef_simple::type_match( window_type_t type_P ) const
199
return window_types() & type_P;
203
bool Windowdef_simple::type_match( NET::WindowType type_P ) const
205
return ( window_types() & ( 1 << type_P ))
206
|| ( type_P == NET::Unknown && ( window_types() & WINDOW_TYPE_NORMAL ));
207
// CHECKME HACK haaaack !
211
const QString& Windowdef_simple::wclass() const
217
Windowdef_simple::substr_type_t Windowdef_simple::wclass_match_type() const
219
return _wclass_match_type;
223
int Windowdef_simple::window_types() const
225
return _window_types;
228
} // namespace KHotKeys