not quite so much needs to be delayed to the init() function
[personal-kdebase.git] / workspace / khotkeys / update / update.cpp
blobe5694c05096fc8c8616798f77d43fc36d2074db2
1 /****************************************************************************
3 KHotKeys
5 Copyright (C) 2003 Lubos Lunak <l.lunak@kde.org>
7 Distributed under the terms of the GNU General Public License version 2.
9 ****************************************************************************/
11 #define _UPDATE_CPP_
13 #include <config-workspace.h>
15 #include <kapplication.h>
16 #include <kcmdlineargs.h>
17 #include <kstandarddirs.h>
18 #include <kconfig.h>
19 #include <kdebug.h>
20 #include <QtDBus/QtDBus>
22 #include "khotkeysiface.h"
23 #include "kglobalaccel.h"
25 #include <settings.h>
27 using namespace KHotKeys;
29 int main( int argc, char* argv[] )
31 KCmdLineArgs::init( argc, argv, "khotkeys", 0, ki18n("KHotKeys Update"), "1.0" ,
32 ki18n("KHotKeys update utility"));
34 KCmdLineOptions options;
35 options.add("id <id>", ki18n("Id of the script to add to %1").subs(KHOTKEYS_CONFIG_FILE));
36 KCmdLineArgs::addCmdLineOptions( options );
37 KApplication app( true ); // X11 connection is necessary for KKey* stuff :-/
38 KCmdLineArgs* args = KCmdLineArgs::parsedArgs();
39 QString id = args->getOption( "id" );
40 QString file = KStandardDirs::locate( "data", "khotkeys/" + id + ".khotkeys" );
41 if( file.isEmpty())
43 kWarning() << "File " << id << " not found!" ;
44 return 1;
46 KGlobalAccel::self()->overrideMainComponentData(KComponentData("khotkeys"));
47 init_global_data( false, &app );
48 Settings settings;
49 settings.read_settings( true );
50 KConfig cfg( file );
51 if( !settings.import( cfg, false ))
53 kWarning() << "Import of " << id << " failed!" ;
54 return 2;
56 settings.write_settings();
57 QDBusConnection bus = QDBusConnection::sessionBus();
58 if( bus.interface()->isServiceRegistered( "org.kde.kded" ))
60 org::kde::khotkeys iface("org.kde.kded", "/modules/khotkeys", bus);
61 iface.reread_configuration();
62 kDebug() << "telling khotkeys daemon to reread configuration";
64 return 0;