• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

NepomukDaemons

main.cpp

Go to the documentation of this file.
00001 /* This file is part of the KDE Project
00002    Copyright (c) 2008 Sebastian Trueg <trueg@kde.org>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License version 2 as published by the Free Software Foundation.
00007 
00008    This library is distributed in the hope that it will be useful,
00009    but WITHOUT ANY WARRANTY; without even the implied warranty of
00010    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011    Library General Public License for more details.
00012 
00013    You should have received a copy of the GNU Library General Public License
00014    along with this library; see the file COPYING.LIB.  If not, write to
00015    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00016    Boston, MA 02110-1301, USA.
00017 */
00018 
00019 
00020 #include <KComponentData>
00021 #include <KCmdLineArgs>
00022 #include <KAboutData>
00023 #include <KService>
00024 #include <KServiceTypeTrader>
00025 #include <KDebug>
00026 
00027 #include <QtCore/QTextStream>
00028 #include <QtCore/QTimer>
00029 #include <QtGui/QApplication>
00030 #include <QtDBus/QDBusConnection>
00031 #include <QtDBus/QDBusConnectionInterface>
00032 
00033 #include <signal.h>
00034 #include <stdio.h>
00035 
00036 #include "servicecontrol.h"
00037 
00038 namespace {
00039 #ifndef Q_OS_WIN
00040     void signalHandler( int signal )
00041     {
00042         switch( signal ) {
00043         case SIGHUP:
00044         case SIGQUIT:
00045         case SIGINT:
00046             QCoreApplication::exit( 0 );
00047         }
00048     }
00049 #endif
00050 
00051     void installSignalHandler() {
00052 #ifndef Q_OS_WIN
00053         struct sigaction sa;
00054         ::memset( &sa, 0, sizeof( sa ) );
00055         sa.sa_handler = signalHandler;
00056         sigaction( SIGHUP, &sa, 0 );
00057         sigaction( SIGINT, &sa, 0 );
00058         sigaction( SIGQUIT, &sa, 0 );
00059 #endif
00060     }
00061 }
00062 
00063 
00064 int main( int argc, char** argv )
00065 {
00066     KAboutData aboutData( "nepomukservicestub", "nepomuk",
00067                           ki18n("Nepomuk Service Stub"),
00068                           "0.2",
00069                           ki18n("Nepomuk Service Stub"),
00070                           KAboutData::License_GPL,
00071                           ki18n("(c) 2008, Sebastian Trüg"),
00072                           KLocalizedString(),
00073                           "http://nepomuk.kde.org" );
00074     aboutData.addAuthor(ki18n("Sebastian Trüg"),ki18n("Maintainer"), "trueg@kde.org");
00075 
00076     KCmdLineOptions options;
00077     options.add("+servicename", ki18nc("@info:shell", "Service to start"));
00078     KCmdLineArgs::addCmdLineOptions( options );
00079 
00080     KCmdLineArgs::init( argc, argv, &aboutData );
00081 
00082     QApplication app( argc, argv );
00083     installSignalHandler();
00084     QApplication::setQuitOnLastWindowClosed( false );
00085 
00086     // FIXME: set the proper KConfig rc name using the service name
00087 
00088     KCmdLineArgs* args = KCmdLineArgs::parsedArgs();
00089 
00090     if( args->count() != 1 ) {
00091         KCmdLineArgs::usageError( i18n("No service name specified") );
00092     }
00093 
00094     QTextStream s( stderr );
00095 
00096     QString serviceName = args->arg(0);
00097     args->clear();
00098 
00099     aboutData.setAppName( serviceName.toLocal8Bit() );
00100     KComponentData compData( aboutData );
00101 
00102 
00103     // check if NepomukServer is running
00104     // ====================================
00105 //     if( !QDBusConnection::sessionBus().interface()->isServiceRegistered( "org.kde.NepomukServer" ) ) {
00106 //         s << "Nepomuk server not running." << endl;
00107 //         return ErrorMissingDependency;
00108 //     }
00109 
00110 
00111     // search the service
00112     // ====================================
00113     KService::List services = KServiceTypeTrader::self()->query( "NepomukService", "DesktopEntryName == '" + serviceName + "'" );
00114     if( services.isEmpty() ) {
00115         s << i18n( "Unknown service name:") << " " <<  serviceName << endl;
00116         return Nepomuk::ServiceControl::ErrorUnknownServiceName;
00117     }
00118     KService::Ptr service = services.first();
00119 
00120 
00121     // Check if this service is already running
00122     // ====================================
00123     if( QDBusConnection::sessionBus().interface()->isServiceRegistered( Nepomuk::ServiceControl::dbusServiceName( serviceName ) ) ) {
00124         s << "Service " << serviceName << " already running." << endl;
00125         return Nepomuk::ServiceControl::ErrorServiceAlreadyRunning;
00126     }
00127 
00128 
00129     // Check the service dependencies
00130     // ====================================
00131     QStringList dependencies = service->property( "X-KDE-Nepomuk-dependencies", QVariant::StringList ).toStringList();
00132     foreach( const QString &dep, dependencies ) {
00133         if( !QDBusConnection::sessionBus().interface()->isServiceRegistered( Nepomuk::ServiceControl::dbusServiceName( dep ) ) ) {
00134             s << "Missing dependency " << dep << endl;
00135             return Nepomuk::ServiceControl::ErrorMissingDependency;
00136         }
00137     }
00138 
00139 
00140     // register the service control
00141     // ====================================
00142     Nepomuk::ServiceControl* control = new Nepomuk::ServiceControl( serviceName, service, &app );
00143 
00144 
00145     // start the service (queued since we need an event loop)
00146     // ====================================
00147     QTimer::singleShot( 0, control, SLOT( start() ) );
00148 
00149     return app.exec();
00150 }

NepomukDaemons

Skip menu "NepomukDaemons"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

API Reference

Skip menu "API Reference"
  • KCMShell
  • KNotify
  • KStyles
  • Nepomuk Daemons
Generated for API Reference by doxygen 1.5.7
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal