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

« back to all changes in this revision

Viewing changes to khotkeys/libkhotkeysprivate/conditions/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
 
 
20
#include "conditions/conditions.h"
 
21
 
 
22
#include "conditions/active_window_condition.h"
 
23
#include "conditions/existing_window_condition.h"
 
24
#include "conditions/conditions_visitor.h"
 
25
 
 
26
#include <KDE/KConfigGroup>
 
27
#include <KDE/KDebug>
 
28
 
 
29
namespace KHotKeys {
 
30
 
 
31
Condition::Condition( Condition_list_base* parent )
 
32
    : _parent(NULL)
 
33
    {
 
34
    if (parent)
 
35
        {
 
36
        parent->append(this);
 
37
        Q_ASSERT(_parent);
 
38
        }
 
39
    }
 
40
 
 
41
 
 
42
Condition::Condition( KConfigGroup&, Condition_list_base* parent )
 
43
    : _parent(NULL)
 
44
    {
 
45
    if (parent)
 
46
        {
 
47
        parent->append(this);
 
48
        Q_ASSERT(_parent);
 
49
        }
 
50
    }
 
51
 
 
52
 
 
53
Condition::~Condition()
 
54
    {
 
55
    if( _parent ) _parent->removeAll( this );
 
56
    }
 
57
 
 
58
 
 
59
void Condition::cfg_write( KConfigGroup& cfg_P ) const
 
60
    {
 
61
    cfg_P.writeEntry( "Type", "ERROR" );
 
62
    }
 
63
 
 
64
 
 
65
Condition* Condition::create_cfg_read( KConfigGroup& cfg_P, Condition_list_base* parent_P )
 
66
    {
 
67
    QString type = cfg_P.readEntry( "Type" );
 
68
    if( type == "ACTIVE_WINDOW" )
 
69
        return new Active_window_condition( cfg_P, parent_P );
 
70
    if( type == "EXISTING_WINDOW" )
 
71
        return new Existing_window_condition( cfg_P, parent_P );
 
72
    if( type == "NOT" )
 
73
        return new Not_condition( cfg_P, parent_P );
 
74
    if( type == "AND" )
 
75
        return new And_condition( cfg_P, parent_P );
 
76
    if( type == "OR" )
 
77
        return new Or_condition( cfg_P, parent_P );
 
78
    kWarning() << "Unknown Condition type read from cfg file\n";
 
79
    return NULL;
 
80
    }
 
81
 
 
82
 
 
83
const Condition_list_base* Condition::parent() const
 
84
    {
 
85
    return _parent;
 
86
    }
 
87
 
 
88
 
 
89
Condition_list_base* Condition::parent()
 
90
    {
 
91
    return _parent;
 
92
    }
 
93
 
 
94
 
 
95
void Condition::reparent(Condition_list_base *parent)
 
96
    {
 
97
    if (_parent == parent) return;
 
98
 
 
99
    if (_parent) _parent->removeAll(this);
 
100
    _parent = parent;
 
101
    if (_parent) _parent->append(this);
 
102
    }
 
103
 
 
104
 
 
105
void Condition::updated() const
 
106
    {
 
107
    if (!khotkeys_active() || !_parent)
 
108
        {
 
109
        return;
 
110
        }
 
111
 
 
112
    _parent->updated();
 
113
    }
 
114
 
 
115
 
 
116
void Condition::visit( ConditionsVisitor *visitor )
 
117
    {
 
118
    visitor->visitCondition( this );
 
119
    }
 
120
 
 
121
 
 
122
} // namespace KHotKeys