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

« back to all changes in this revision

Viewing changes to khotkeys/libkhotkeysprivate/conditions/existing_window_condition.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
/*
 
2
   Copyright (C) 1999-2001 Lubos Lunak <l.lunak@kde.org>
 
3
   Copyright (C) 2008 Michael Jansen <kde@michael-jansen.biz>
 
4
 
 
5
   This library is free software; you can redistribute it and/or
 
6
   modify it under the terms of the GNU Library General Public
 
7
   License version 2 as published by the Free Software Foundation.
 
8
 
 
9
   This library 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 GNU
 
12
   Library General Public License for more details.
 
13
 
 
14
   You should have received a copy of the GNU Library General Public License
 
15
   along with this library; see the file COPYING.LIB.  If not, write to
 
16
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 
17
   Boston, MA 02110-1301, USA.
 
18
*/
 
19
#include "conditions/existing_window_condition.h"
 
20
 
 
21
#include "windows_helper/window_selection_list.h"
 
22
 
 
23
#include "windows_handler.h"
 
24
#include "khotkeysglobal.h"
 
25
 
 
26
 
 
27
namespace KHotKeys {
 
28
 
 
29
Existing_window_condition::Existing_window_condition( KConfigGroup& cfg_P, Condition_list_base* parent_P )
 
30
    : Condition( cfg_P, parent_P )
 
31
    {
 
32
    KConfigGroup windowConfig( cfg_P.config(), cfg_P.name() + "Window" );
 
33
    _window = new Windowdef_list( windowConfig );
 
34
    init();
 
35
    set_match();
 
36
    }
 
37
 
 
38
 
 
39
Existing_window_condition::Existing_window_condition( Windowdef_list* window_P,
 
40
    Condition_list_base* parent_P )
 
41
    : Condition( parent_P ), _window( window_P ), is_match( false )
 
42
    {
 
43
    init();
 
44
    set_match();
 
45
    }
 
46
 
 
47
 
 
48
Existing_window_condition::~Existing_window_condition()
 
49
    {
 
50
    disconnect( windows_handler, NULL, this, NULL );
 
51
    delete _window;
 
52
    }
 
53
 
 
54
 
 
55
void Existing_window_condition::cfg_write( KConfigGroup& cfg_P ) const
 
56
    {
 
57
    base::cfg_write( cfg_P );
 
58
    KConfigGroup windowConfig( cfg_P.config(), cfg_P.name() + "Window" );
 
59
    window()->cfg_write( windowConfig );
 
60
    cfg_P.writeEntry( "Type", "EXISTING_WINDOW" ); // overwrites value set in base::cfg_write()
 
61
    }
 
62
 
 
63
 
 
64
Existing_window_condition* Existing_window_condition::copy() const
 
65
    {
 
66
    return new Existing_window_condition(window()->copy());
 
67
    }
 
68
 
 
69
 
 
70
const QString Existing_window_condition::description() const
 
71
    {
 
72
    return i18n( "Existing window: " ) + window()->comment();
 
73
    }
 
74
 
 
75
 
 
76
void Existing_window_condition::init()
 
77
    {
 
78
    connect( windows_handler, SIGNAL( window_added( WId )), this, SLOT( window_added( WId )));
 
79
    connect( windows_handler, SIGNAL( window_removed( WId )), this, SLOT( window_removed( WId )));
 
80
    }
 
81
 
 
82
 
 
83
bool Existing_window_condition::match() const
 
84
    {
 
85
    return is_match;
 
86
    }
 
87
 
 
88
 
 
89
void Existing_window_condition::set_match( WId w_P )
 
90
    {
 
91
    if( w_P != None && !is_match )
 
92
        is_match = window()->match( Window_data( w_P ));
 
93
    else
 
94
        is_match = windows_handler->find_window( window()) != None;
 
95
    updated();
 
96
    }
 
97
 
 
98
 
 
99
const Windowdef_list* Existing_window_condition::window() const
 
100
    {
 
101
    return _window;
 
102
    }
 
103
 
 
104
 
 
105
Windowdef_list* Existing_window_condition::window()
 
106
    {
 
107
    return _window;
 
108
    }
 
109
 
 
110
 
 
111
void Existing_window_condition::window_added( WId w_P )
 
112
    {
 
113
    set_match( w_P );
 
114
    }
 
115
 
 
116
 
 
117
void Existing_window_condition::window_removed( WId )
 
118
    {
 
119
    set_match();
 
120
    }
 
121
 
 
122
 
 
123
} // namespace KHotKeys