• 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 #ifdef Q_WS_WIN
00034 #include <QtCore/QDir>
00035 #include <QtCore/QProcess>
00036 #include <QtCore/QStringList>
00037 #include <windows.h>
00038 #include <process.h>
00039 #include "kstandarddirs.h"
00040 #endif
00041 
00042 #ifndef Q_WS_WIN
00043 /* These are to link libkio even if 'smart' linker is used */
00044 #include <kio/authinfo.h>
00045 extern "C" KIO::AuthInfo* _kioslave_init_kio() { return new KIO::AuthInfo(); }
00046 #endif 
00047 
00048 int main(int argc, char **argv)
00049 {
00050      if (argc < 5)
00051      {
00052         fprintf(stderr, "Usage: kioslave <slave-lib> <protocol> <klauncher-socket> <app-socket>\n\nThis program is part of KDE.\n");
00053         exit(1);
00054      }
00055 #ifndef _WIN32_WCE
00056      setlocale(LC_ALL, "");
00057 #endif
00058      QString libpath = QFile::decodeName(argv[1]);
00059 
00060      if (libpath.isEmpty())
00061      {
00062         fprintf(stderr, "library path is empty.\n");
00063         exit(1); 
00064      }
00065 
00066      QLibrary lib(libpath);
00067 #ifdef Q_WS_WIN
00068      qDebug("trying to load '%s'", qPrintable(libpath));
00069 #endif
00070      if ( !lib.load() || !lib.isLoaded() )
00071      {
00072 #ifdef Q_WS_WIN
00073         libpath = KStandardDirs::installPath("module") + QFileInfo(libpath).fileName();
00074         lib.setFileName( libpath );
00075         if(!lib.load() || !lib.isLoaded())
00076         {
00077             QByteArray kdedirs = qgetenv("KDEDIRS");
00078             if (!kdedirs.size()) {
00079               qDebug("not able to find '%s' because KDEDIRS environment variable is not set.\n"
00080                      "Set KDEDIRS to the KDE installation root dir and restart klauncher to fix this problem.",
00081                      qPrintable(libpath));
00082               exit(1);
00083             }
00084             QString paths = QString::fromLocal8Bit(kdedirs);
00085             QStringList pathlist = paths.split(';');
00086             Q_FOREACH(const QString &path, pathlist) {
00087               QString slave_path = path + QLatin1String("/lib/kde4/") + QFileInfo(libpath).fileName();
00088               qDebug("trying to load '%s'",slave_path.toAscii().data());
00089               lib.setFileName(slave_path);
00090               if (lib.load() && lib.isLoaded() )
00091                 break;
00092             }
00093             if (!lib.isLoaded())
00094             {
00095               qWarning("could not open %s: %s", libpath.data(), qPrintable (lib.errorString()) );
00096               exit(1);
00097             }
00098         }
00099 #else
00100         fprintf(stderr, "could not open %s: %s", qPrintable(libpath),
00101                 qPrintable (lib.errorString()) );
00102         exit(1);
00103 #endif
00104      }  
00105 
00106      void* sym = lib.resolve("kdemain");
00107      if (!sym )
00108      {
00109         fprintf(stderr, "Could not find kdemain: %s\n", qPrintable(lib.errorString() ));
00110         exit(1);
00111      }
00112 
00113 #ifdef Q_WS_WIN
00114      // enter debugger in case debugging is actived 
00115      QString slaveDebugWait( QString::fromLocal8Bit( qgetenv("KDE_SLAVE_DEBUG_WAIT") ) );
00116      if (slaveDebugWait == QLatin1String("all") || slaveDebugWait == argv[2]) 
00117      {
00118 # ifdef Q_CC_MSVC
00119         // msvc debugger or windbg supports jit debugging, the latter requires setting up windbg jit with windbg -i
00120         DebugBreak();
00121 # else
00122         // gdb does not support win32 jit debug support, so implement it by ourself
00123         WCHAR buf[1024];
00124         GetModuleFileName(NULL,buf, 1024);
00125         QStringList params;
00126         params << QString::fromUtf16((const unsigned short*)buf);
00127         params << QString::number(GetCurrentProcessId());
00128         QProcess::startDetached("gdb",params);
00129         Sleep(1000);
00130 # endif
00131      } 
00132 # if defined(Q_CC_MSVC) && !defined(_WIN32_WCE)
00133      else {
00134         QString slaveDebugPopup( QString::fromLocal8Bit( qgetenv("KDE_SLAVE_DEBUG_POPUP") ) );
00135         if (slaveDebugPopup == QLatin1String("all") || slaveDebugPopup == argv[2]) {
00136            // A workaround for OSes where DebugBreak() does not work in administrative mode (actually Vista with msvc 2k5)
00137            // - display a native message box so developer can attach the debugger to the KIO slave process and click OK.
00138            MessageBoxA(NULL, 
00139              QString("Please attach the debugger to process #%1 (%2)").arg(getpid()).arg(argv[0]).toLatin1(), 
00140              QString("\"%1\" KIO Slave Debugging").arg(argv[2]).toLatin1(), MB_OK|MB_ICONINFORMATION|MB_TASKMODAL);
00141         }
00142      }
00143 # endif
00144 #endif // Q_WS_WIN
00145 
00146      int (*func)(int, char *[]) = (int (*)(int, char *[])) sym;
00147 
00148      exit( func(argc-1, argv+1)); /* Launch! */
00149 }

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