add more spacing
[personal-kdebase.git] / runtime / nepomuk / server / main.cpp
blob70e9b64209d7775da3111c0894b53173c40d18e9
1 /* This file is part of the KDE Project
2 Copyright (c) 2007 Sebastian Trueg <trueg@kde.org>
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License version 2 as published by the Free Software Foundation.
8 This library 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 GNU
11 Library General Public License for more details.
13 You should have received a copy of the GNU Library General Public License
14 along with this library; see the file COPYING.LIB. If not, write to
15 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16 Boston, MA 02110-1301, USA.
19 #include "nepomukserver.h"
20 #include "nepomukserver_export.h"
22 #include <kuniqueapplication.h>
23 #include <kapplication.h>
24 #include <kcmdlineargs.h>
25 #include <kaboutdata.h>
26 #include <klocale.h>
27 #include <kglobal.h>
28 #include <kconfig.h>
29 #include <kconfiggroup.h>
30 #include <kdebug.h>
32 #include <signal.h>
34 namespace {
35 #ifndef Q_OS_WIN
36 void signalHandler( int signal )
38 switch( signal ) {
39 case SIGHUP:
40 case SIGQUIT:
41 case SIGTERM:
42 case SIGINT:
43 if ( qApp ) {
44 qApp->quit();
48 #endif
50 void installSignalHandler() {
51 #ifndef Q_OS_WIN
52 struct sigaction sa;
53 ::memset( &sa, 0, sizeof( sa ) );
54 sa.sa_handler = signalHandler;
55 sigaction( SIGHUP, &sa, 0 );
56 sigaction( SIGINT, &sa, 0 );
57 sigaction( SIGQUIT, &sa, 0 );
58 sigaction( SIGTERM, &sa, 0 );
59 #endif
64 namespace Nepomuk {
65 class ServerApplication : public KUniqueApplication
67 public:
68 ServerApplication()
69 : KUniqueApplication(),
70 m_server( 0 ) {
73 int newInstance() {
74 if ( !m_server ) {
75 m_server = new Server( this );
77 return 0;
80 private:
81 Server* m_server;
86 extern "C" NEPOMUK_SERVER_EXPORT int kdemain( int argc, char** argv )
88 KAboutData aboutData( "NepomukServer", "nepomuk",
89 ki18n("Nepomuk Server"),
90 "0.2",
91 ki18n("Nepomuk Server - Manages Nepomuk storage and services"),
92 KAboutData::License_GPL,
93 ki18n("(c) 2008, Sebastian Trüg"),
94 KLocalizedString(),
95 "http://nepomuk.kde.org" );
96 aboutData.addAuthor(ki18n("Sebastian Trüg"),ki18n("Maintainer"), "trueg@kde.org");
98 KCmdLineArgs::init( argc, argv, &aboutData );
100 KUniqueApplication::addCmdLineOptions();
102 KComponentData componentData( &aboutData );
104 if ( !KUniqueApplication::start() ) {
105 fprintf( stderr, "Nepomuk server already running.\n" );
106 return 0;
109 installSignalHandler();
111 Nepomuk::ServerApplication app;
112 app.setQuitOnLastWindowClosed( false );
113 return app.exec();