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

« back to all changes in this revision

Viewing changes to khotkeys/libkhotkeysprivate/windows_helper/window_selection_list.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
 
 
19
#include "windows_helper/window_selection_list.h"
 
20
 
 
21
#include <KConfig>
 
22
#include <KDebug>
 
23
 
 
24
 
 
25
namespace KHotKeys {
 
26
 
 
27
 
 
28
Windowdef_list::Windowdef_list( const QString& comment_P )
 
29
    : QList< Windowdef* >(), _comment( comment_P )
 
30
    {
 
31
    }
 
32
 
 
33
 
 
34
Windowdef_list::Windowdef_list( KConfigGroup& cfg_P )
 
35
    : QList< Windowdef* >()
 
36
    {
 
37
    _comment = cfg_P.readEntry( "Comment" );
 
38
    int cnt = cfg_P.readEntry( "WindowsCount", 0 );
 
39
    for( int i = 0;
 
40
         i < cnt;
 
41
         ++i )
 
42
        {
 
43
        KConfigGroup windowGroup( cfg_P.config(), cfg_P.name() + QString::number( i ));
 
44
        Windowdef* window = Windowdef::create_cfg_read( windowGroup );
 
45
        if( window )
 
46
            append( window );
 
47
        }
 
48
    }
 
49
 
 
50
 
 
51
Windowdef_list::~Windowdef_list()
 
52
    {
 
53
    qDeleteAll(*this);
 
54
    }
 
55
 
 
56
 
 
57
const QString& Windowdef_list::comment() const
 
58
    {
 
59
    return _comment;
 
60
    }
 
61
 
 
62
 
 
63
void Windowdef_list::cfg_write( KConfigGroup& cfg_P ) const
 
64
    {
 
65
    int i = 0;
 
66
    for( ConstIterator it(begin());
 
67
         it!= end();
 
68
         ++it, ++i )
 
69
        {
 
70
        KConfigGroup itGroup( cfg_P.config(), cfg_P.name() + QString::number( i ) );
 
71
        (*it)->cfg_write( itGroup );
 
72
        }
 
73
    cfg_P.writeEntry( "WindowsCount", i );
 
74
    cfg_P.writeEntry( "Comment", comment());
 
75
    }
 
76
 
 
77
 
 
78
Windowdef_list* Windowdef_list::copy() const
 
79
    {
 
80
    Windowdef_list* ret = new Windowdef_list(comment());
 
81
    for( ConstIterator it(constBegin());
 
82
         it!= constEnd();
 
83
         ++it)
 
84
        {
 
85
        kDebug() << "Duplicating " << (*it)->comment();
 
86
        ret->append( (*it)->copy());
 
87
        }
 
88
    return ret;
 
89
    }
 
90
 
 
91
 
 
92
bool Windowdef_list::match( const Window_data& window_P ) const
 
93
    {
 
94
    if( count() == 0 ) // CHECKME no windows to match => ok
 
95
        return true;
 
96
    for( ConstIterator it(begin());
 
97
         it != end();
 
98
         ++it )
 
99
        if( (*it)->match( window_P ))
 
100
            return true;
 
101
    return false;
 
102
    }
 
103
 
 
104
 
 
105
void Windowdef_list::set_comment(const QString &comment)
 
106
    {
 
107
    _comment = comment;
 
108
    }
 
109
 
 
110
 
 
111
} // namespace KHotKeys