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

« back to all changes in this revision

Viewing changes to kwin/data/update_default_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
/********************************************************************
 
2
 KWin - the KDE window manager
 
3
 This file is part of the KDE project.
 
4
 
 
5
Copyright (C) 2005 Lubos Lunak <l.lunak@kde.org>
 
6
 
 
7
This program is free software; you can redistribute it and/or modify
 
8
it under the terms of the GNU General Public License as published by
 
9
the Free Software Foundation; either version 2 of the License, or
 
10
(at your option) any later version.
 
11
 
 
12
This program is distributed in the hope that it will be useful,
 
13
but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
GNU General Public License for more details.
 
16
 
 
17
You should have received a copy of the GNU General Public License
 
18
along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
19
*********************************************************************/
 
20
 
 
21
// read additional window rules and add them to kwinrulesrc
 
22
 
 
23
#include <kconfig.h>
 
24
#include <kconfiggroup.h>
 
25
#include <kdebug.h>
 
26
#include <kcomponentdata.h>
 
27
#include <kstandarddirs.h>
 
28
#include <kaboutdata.h>
 
29
#include <kcmdlineargs.h>
 
30
#include <kglobal.h>
 
31
#include <QtDBus/QtDBus>
 
32
 
 
33
int main( int argc, char* argv[] )
 
34
    {
 
35
    if( argc != 2 )
 
36
        return 1;
 
37
    KAboutData about( "kwin_update_default_rules", "kwin", KLocalizedString(), 0 );
 
38
    KCmdLineArgs::init( argc, argv, &about );
 
39
    KComponentData inst( &about );
 
40
    Q_UNUSED( KGlobal::locale() ); // jump-start locales to get to translated descriptions
 
41
    QString file = KStandardDirs::locate( "data", QString( "kwin/default_rules/%1" ).arg(argv[ 1 ] ));
 
42
    if( file.isEmpty())
 
43
        {
 
44
        kWarning(1212) << "File " << argv[ 1 ] << " not found!" ;
 
45
        return 1;
 
46
        }
 
47
    KConfig src_cfg( file );
 
48
    KConfig dest_cfg( "kwinrulesrc" );
 
49
        KConfigGroup scg(&src_cfg, "General");
 
50
        KConfigGroup dcg(&dest_cfg, "General");
 
51
    int count = scg.readEntry( "count", 0 );
 
52
    int pos = dcg.readEntry( "count", 0 );
 
53
    for( int group = 1;
 
54
         group <= count;
 
55
         ++group )
 
56
        {
 
57
        QMap< QString, QString > entries = src_cfg.entryMap( QString::number( group ));
 
58
        ++pos;
 
59
        dest_cfg.deleteGroup( QString::number( pos ));
 
60
                KConfigGroup dcg2 (&dest_cfg, QString::number( pos ));
 
61
        for( QMap< QString, QString >::ConstIterator it = entries.constBegin();
 
62
             it != entries.constEnd();
 
63
             ++it )
 
64
            dcg2.writeEntry( it.key(), *it );
 
65
        }
 
66
    dcg.writeEntry( "count", pos );
 
67
    scg.sync();
 
68
    dcg.sync();
 
69
    // Send signal to all kwin instances
 
70
    QDBusMessage message =
 
71
        QDBusMessage::createSignal("/KWin", "org.kde.KWin", "reloadConfig");
 
72
    QDBusConnection::sessionBus().send(message);
 
73
 
 
74
    }