• Skip to content
  • Skip to link menu
KDE 4.6 API Reference
  • KDE API Reference
  • kdelibs
  • KDE Home
  • Contact Us
 

KInit

kioslave.cpp

Go to the documentation of this file.
00001 /*
00002  * This file is part of the KDE libraries
00003  * Copyright (c) 1999-2000 Waldo Bastian <bastian@kde.org>
00004  *           (c) 1999 Mario Weilguni <mweilguni@sime.com>
00005  *           (c) 2001 Lubos Lunak <l.lunak@kde.org>
00006  *
00007  * This library is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Library General Public
00009  * License version 2 as published by the Free Software Foundation.
00010  *
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Library General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Library General Public License
00017  * along with this library; see the file COPYING.LIB.  If not, write to
00018  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00019  * Boston, MA 02110-1301, USA.
00020  */
00021 
00022 #include <kdebug.h>
00023 #include <config.h>
00024 
00025 #include <stdlib.h>
00026 #include <stdio.h>
00027 #include <errno.h>
00028 #include <locale.h>
00029 
00030 #include <QtCore/QString>
00031 #include <QtCore/QLibrary>
00032 #include <QtCore/QFile>
00033 
00034 #if defined(Q_WS_WIN) || defined(Q_WS_MAC)
00035 #define USE_KPROCESS_FOR_KIOSLAVES
00036 #endif
00037 
00038 #ifdef USE_KPROCESS_FOR_KIOSLAVES
00039 #include <QtCore/QDir>
00040 #include <QtCore/QProcess>
00041 #include <QtCore/QStringList>
00042 #ifdef Q_WS_WIN
00043 #include <windows.h>
00044 #include <process.h>
00045 #endif
00046 #include "kstandarddirs.h"
00047 #endif
00048 
00049 #ifndef Q_WS_WIN
00050 /* These are to link libkio even if 'smart' linker is used */
00051 #include <kio/authinfo.h>
00052 extern "C" KIO::AuthInfo* _kioslave_init_kio() { return new KIO::AuthInfo(); }
00053 #endif 
00054 
00055 int main(int argc, char **argv)
00056 {
00057      if (argc < 5)
00058      {
00059         fprintf(stderr, "Usage: kioslave <slave-lib> <protocol> <klauncher-socket> <app-socket>\n\nThis program is part of KDE.\n");
00060         exit(1);
00061      }
00062 #ifndef _WIN32_WCE
00063      setlocale(LC_ALL, "");
00064 #endif
00065      QString libpath = QFile::decodeName(argv[1]);
00066 
00067      if (libpath.isEmpty())
00068      {
00069         fprintf(stderr, "library path is empty.\n");
00070         exit(1); 
00071      }
00072 
00073      QLibrary lib(libpath);
00074 #ifdef USE_KPROCESS_FOR_KIOSLAVES
00075      qDebug("trying to load '%s'", qPrintable(libpath));
00076 #endif
00077      if ( !lib.load() || !lib.isLoaded() )
00078      {
00079 #ifdef USE_KPROCESS_FOR_KIOSLAVES
00080         libpath = KStandardDirs::installPath("module") + QFileInfo(libpath).fileName();
00081         lib.setFileName( libpath );
00082         if(!lib.load() || !lib.isLoaded())
00083         {
00084             QByteArray kdedirs = qgetenv("KDEDIRS");
00085             if (!kdedirs.size()) {
00086               qDebug("not able to find '%s' because KDEDIRS environment variable is not set.\n"
00087                      "Set KDEDIRS to the KDE installation root dir and restart klauncher to fix this problem.",
00088                      qPrintable(libpath));
00089               exit(1);
00090             }
00091             QString paths = QString::fromLocal8Bit(kdedirs);
00092             QStringList pathlist = paths.split(';');
00093             Q_FOREACH(const QString &path, pathlist) {
00094               QString slave_path = path + QLatin1String("/lib/kde4/") + QFileInfo(libpath).fileName();
00095               qDebug("trying to load '%s'",slave_path.toAscii().data());
00096               lib.setFileName(slave_path);
00097               if (lib.load() && lib.isLoaded() )
00098                 break;
00099             }
00100             if (!lib.isLoaded())
00101             {
00102               qWarning("could not open %s: %s", libpath.data(), qPrintable (lib.errorString()) );
00103               exit(1);
00104             }
00105         }
00106 #else
00107         fprintf(stderr, "could not open %s: %s", qPrintable(libpath),
00108                 qPrintable (lib.errorString()) );
00109         exit(1);
00110 #endif
00111      }  
00112 
00113      void* sym = lib.resolve("kdemain");
00114      if (!sym )
00115      {
00116         fprintf(stderr, "Could not find kdemain: %s\n", qPrintable(lib.errorString() ));
00117         exit(1);
00118      }
00119 
00120 #ifdef Q_WS_WIN
00121      // enter debugger in case debugging is actived 
00122      QString slaveDebugWait( QString::fromLocal8Bit( qgetenv("KDE_SLAVE_DEBUG_WAIT") ) );
00123      if (slaveDebugWait == QLatin1String("all") || slaveDebugWait == argv[2]) 
00124      {
00125 # ifdef Q_CC_MSVC
00126         // msvc debugger or windbg supports jit debugging, the latter requires setting up windbg jit with windbg -i
00127         DebugBreak();
00128 # else
00129         // gdb does not support win32 jit debug support, so implement it by ourself
00130         WCHAR buf[1024];
00131         GetModuleFileName(NULL,buf, 1024);
00132         QStringList params;
00133         params << QString::fromUtf16((const unsigned short*)buf);
00134         params << QString::number(GetCurrentProcessId());
00135         QProcess::startDetached("gdb",params);
00136         Sleep(1000);
00137 # endif
00138      } 
00139 # if defined(Q_CC_MSVC) && !defined(_WIN32_WCE)
00140      else {
00141         QString slaveDebugPopup( QString::fromLocal8Bit( qgetenv("KDE_SLAVE_DEBUG_POPUP") ) );
00142         if (slaveDebugPopup == QLatin1String("all") || slaveDebugPopup == argv[2]) {
00143            // A workaround for OSes where DebugBreak() does not work in administrative mode (actually Vista with msvc 2k5)
00144            // - display a native message box so developer can attach the debugger to the KIO slave process and click OK.
00145            MessageBoxA(NULL, 
00146              QString("Please attach the debugger to process #%1 (%2)").arg(getpid()).arg(argv[0]).toLatin1(), 
00147              QString("\"%1\" KIO Slave Debugging").arg(argv[2]).toLatin1(), MB_OK|MB_ICONINFORMATION|MB_TASKMODAL);
00148         }
00149      }
00150 # endif
00151 #endif // Q_WS_WIN
00152 
00153      int (*func)(int, char *[]) = (int (*)(int, char *[])) sym;
00154 
00155      exit( func(argc-1, argv+1)); /* Launch! */
00156 }

KInit

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

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.7.3
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