not quite so much needs to be delayed to the init() function
[personal-kdebase.git] / workspace / kwin / data / update_default_rules.cpp
blobd0b85c6cd4fc67f068447ab0523ad78f665e9297
1 /********************************************************************
2 KWin - the KDE window manager
3 This file is part of the KDE project.
5 Copyright (C) 2005 Lubos Lunak <l.lunak@kde.org>
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.
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.
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 *********************************************************************/
21 // read additional window rules and add them to kwinrulesrc
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>
33 int main( int argc, char* argv[] )
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 desriptions
41 QString file = KStandardDirs::locate( "data", QString( "kwin/default_rules/" ) + argv[ 1 ] );
42 if( file.isEmpty())
44 kWarning(1212) << "File " << argv[ 1 ] << " not found!" ;
45 return 1;
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 )
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 );
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);