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

KDECore

kde-config.cpp

Go to the documentation of this file.
00001 // -*- c++ -*-
00002 /*
00003  * This file is part of the KDE libraries
00004  *
00005  * Copyright (c) 2008 David Jarvie <djarvie@kde.org>
00006  * Copyright (c) 2006-2007 Christian Ehrlicher <Ch.Ehrlicher@gmx.de>
00007  * Copyright (c) 2000-2007 Stephan Kulow <coolo@kde.org>
00008  *
00009  * This library is free software; you can redistribute it and/or
00010  * modify it under the terms of the GNU Library General Public
00011  * License as published by the Free Software Foundation; either
00012  * version 2 of the License, or (at your option) any later version.
00013  *
00014  * This library is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017  * Library General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU Library General Public License
00020  * along with this library; see the file COPYING.LIB.  If not, write to
00021  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00022  * Boston, MA 02110-1301, USA.
00023  */
00024 
00025 
00026 #include <kcmdlineargs.h>
00027 #include <klocale.h>
00028 #include <kcomponentdata.h>
00029 #include <kstandarddirs.h>
00030 #include <kglobal.h>
00031 #include <kconfig.h>
00032 #include <qdir.h>
00033 #include <stdio.h>
00034 #include <kaboutdata.h>
00035 #include <kdeversion.h>
00036 #include <QDir>
00037 #include <QtCore/QLibraryInfo>
00038 #include <QtCore/QCoreApplication>
00039 #include <QProcess>
00040 #include <config.h>
00041 #include <config-prefix.h>
00042 #include <kconfiggroup.h>
00043 #include <kkernel_win.h>
00044 #include <kde_file.h>
00045 
00046 static void printResult(const QString &s)
00047 {
00048     if (s.isEmpty())
00049         printf("\n");
00050     else {
00051         QString path = QDir::convertSeparators( s );
00052         printf("%s\n", path.toLocal8Bit().constData());
00053     }
00054 }
00055 
00056 static QString readXdg( const char* type )
00057 {
00058     QProcess proc;
00059     proc.start( "xdg-user-dir", QStringList() << type );
00060     if (!proc.waitForStarted() || !proc.waitForFinished())
00061         return QString();
00062     return QString::fromLocal8Bit( proc.readAll()).trimmed();
00063 }
00064 
00065 int main(int argc, char **argv)
00066 {
00067     QCoreApplication app(argc, argv);
00068     KAboutData about("kde4-config", "kdelibs4", ki18n("kde4-config"), "1.0",
00069                      ki18n("A little program to output installation paths"),
00070                      KAboutData::License_GPL,
00071                      ki18n("(C) 2000 Stephan Kulow"));
00072     KCmdLineArgs::init( argc, argv, &about);
00073 
00074     KCmdLineOptions options;
00075     options.add("expandvars",  ki18n("Left for legacy support"));
00076     options.add("prefix",      ki18n("Compiled in prefix for KDE libraries"));
00077     options.add("exec-prefix", ki18n("Compiled in exec_prefix for KDE libraries"));
00078     options.add("libsuffix",   ki18n("Compiled in library path suffix"));
00079     options.add("localprefix", ki18n("Prefix in $HOME used to write files"));
00080     options.add("version",     ki18n("Compiled in version string for KDE libraries"));
00081     options.add("types",       ki18n("Available KDE resource types"));
00082     options.add("path type",       ki18n("Search path for resource type"));
00083     options.add("locate filename", ki18n("Find filename inside the resource type given to --path"));
00084     options.add("userpath type",   ki18n("User path: desktop|autostart|document"));
00085     options.add("install type",    ki18n("Prefix to install resource files to"));
00086     options.add("qt-prefix",   ki18n("Installation prefix for Qt"));
00087     options.add("qt-binaries", ki18n("Location of installed Qt binaries"));
00088     options.add("qt-libraries", ki18n("Location of installed Qt libraries"));
00089     options.add("qt-plugins", ki18n("Location of installed Qt plugins"));
00090     KCmdLineArgs::addCmdLineOptions( options ); // Add my own options.
00091 
00092     KComponentData a(&about);
00093     (void)KGlobal::dirs(); // trigger the creation
00094     (void)KGlobal::config();
00095 
00096     // Get application specific arguments
00097     KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
00098 
00099     if (args->isSet("prefix"))
00100     {
00101         printResult(KDEDIR);
00102         return 0;
00103     }
00104 
00105     if (args->isSet("exec-prefix"))
00106     {
00107         printResult(EXEC_INSTALL_PREFIX);
00108         return 0;
00109     }
00110 
00111     if (args->isSet("libsuffix"))
00112     {
00113         QString tmp(KDELIBSUFF);
00114         tmp.remove('"');
00115         printResult(tmp.toLocal8Bit());
00116         return 0;
00117     }
00118 
00119     if (args->isSet("localprefix"))
00120     {
00121         printResult(KGlobal::dirs()->localkdedir());
00122         return 0;
00123     }
00124 
00125     if (args->isSet("version"))
00126     {
00127         printf("%s\n", KDE_VERSION_STRING);
00128         return 0;
00129     }
00130 
00131     if (args->isSet("types"))
00132     {
00133         QStringList types = KGlobal::dirs()->allTypes();
00134         types.sort();
00135         const char *helptexts[] = {
00136             "apps", I18N_NOOP("Applications menu (.desktop files)"),
00137             "autostart", I18N_NOOP("Autostart directories"),
00138             "cache", I18N_NOOP("Cached information (e.g. favicons, web-pages)"),
00139             "cgi", I18N_NOOP("CGIs to run from kdehelp"),
00140             "config", I18N_NOOP("Configuration files"),
00141             "data", I18N_NOOP("Where applications store data"),
00142             "emoticons", I18N_NOOP("Emoticons"),
00143             "exe", I18N_NOOP("Executables in $prefix/bin"),
00144             "html", I18N_NOOP("HTML documentation"),
00145             "icon", I18N_NOOP("Icons"),
00146             "kcfg", I18N_NOOP("Configuration description files"),
00147             "lib", I18N_NOOP("Libraries"),
00148             "include", I18N_NOOP("Includes/Headers"),
00149             "locale", I18N_NOOP("Translation files for KLocale"),
00150             "mime", I18N_NOOP("Mime types"),
00151             "module", I18N_NOOP("Loadable modules"),
00152             "pixmap", I18N_NOOP("Legacy pixmaps"),
00153             "qtplugins", I18N_NOOP("Qt plugins"),
00154             "services", I18N_NOOP("Services"),
00155             "servicetypes", I18N_NOOP("Service types"),
00156             "sound", I18N_NOOP("Application sounds"),
00157             "templates", I18N_NOOP("Templates"),
00158             "wallpaper", I18N_NOOP("Wallpapers"),
00159             "xdgdata-apps", I18N_NOOP("XDG Application menu (.desktop files)"),
00160             "xdgdata-dirs", I18N_NOOP("XDG Menu descriptions (.directory files)"),
00161             "xdgdata-icon", I18N_NOOP("XDG Icons"),
00162             "xdgdata-pixmap", I18N_NOOP("Legacy pixmaps"),
00163             "xdgdata-mime", I18N_NOOP("XDG Mime Types"),
00164             "xdgconf-menu", I18N_NOOP("XDG Menu layout (.menu files)"),
00165             "xdgconf-autostart", I18N_NOOP("XDG autostart directory"),
00166             "tmp", I18N_NOOP("Temporary files (specific for both current host and current user)"),
00167             "socket", I18N_NOOP("UNIX Sockets (specific for both current host and current user)"),
00168             0, 0
00169         };
00170         Q_FOREACH(const QString &type, types)
00171         {
00172             int index = 0;
00173             while (helptexts[index] && type != helptexts[index]) {
00174                 index += 2;
00175             }
00176             if (helptexts[index]) {
00177                 printf("%s - %s\n", helptexts[index], i18n(helptexts[index+1]).toLocal8Bit().data());
00178             } else {
00179                 printf("%s", i18n("%1 - unknown type\n", type).toLocal8Bit().data());
00180             }
00181         }
00182         return 0;
00183     }
00184 
00185     QString type = args->getOption("path");
00186     if (!type.isEmpty())
00187     {
00188         QString fileName = args->getOption("locate");
00189         if (!fileName.isEmpty())
00190         {
00191             QString result = KStandardDirs::locate(type.toLatin1(), fileName);
00192             if (!result.isEmpty())
00193                 printf("%s\n", result.toLocal8Bit().constData());
00194             return result.isEmpty() ? 1 : 0;
00195         }
00196 
00197         printResult(KGlobal::dirs()->resourceDirs(type.toLatin1()).join(QString(KPATH_SEPARATOR)));
00198         return 0;
00199     }
00200 
00201     type = args->getOption("userpath");
00202     if (!type.isEmpty())
00203     {
00204         //code duplicated with KGlobalSettings::initPath()
00205         if ( type == "desktop" )
00206         { // QDesktopServices is QtGui :-/
00207             QString path = readXdg( "DESKTOP" );
00208             if (path.isEmpty())
00209                 path = QDir::homePath() + QLatin1String("/Desktop");
00210             path=QDir::cleanPath( path );
00211             if ( !path.endsWith('/') )
00212               path.append(QLatin1Char('/'));
00213             printResult(path);
00214         }
00215         else if ( type == "autostart" )
00216         {
00217             KConfigGroup g( KGlobal::config(), "Paths" );
00218             QString path=QDir::homePath() + "/Autostart/";
00219             path=g.readPathEntry( "Autostart", path);
00220             path=QDir::cleanPath( path );
00221             if ( !path.endsWith('/') )
00222               path.append(QLatin1Char('/'));
00223             printResult(path);
00224 
00225         }
00226         else if ( type == "document" )
00227         {
00228             QString path = readXdg( "DOCUMENTS" );
00229             if ( path.isEmpty())
00230                 path = QDir::homePath() + QLatin1String("/Documents");
00231             path=QDir::cleanPath( path );
00232             if ( !path.endsWith('/') )
00233               path.append(QLatin1Char('/'));
00234             printResult(path);
00235         }
00236         else
00237             fprintf(stderr, "%s", i18n("%1 - unknown type of userpath\n", type).toLocal8Bit().data() );
00238         return 0;
00239     }
00240 
00241     type = args->getOption("install");
00242     if (!type.isEmpty())
00243     {
00244         printResult( KGlobal::dirs()->installPath(type.toLocal8Bit()) );
00245     }
00246 
00247     if (args->isSet("qt-prefix"))
00248     {
00249         printResult(QLibraryInfo::location(QLibraryInfo::PrefixPath));
00250         return 0;
00251     }
00252     if (args->isSet("qt-binaries"))
00253     {
00254         printResult(QLibraryInfo::location(QLibraryInfo::BinariesPath));
00255         return 0;
00256     }
00257     if (args->isSet("qt-libraries"))
00258     {
00259         printResult(QLibraryInfo::location(QLibraryInfo::LibrariesPath));
00260         return 0;
00261     }
00262     if (args->isSet("qt-plugins"))
00263     {
00264         printResult(QLibraryInfo::location(QLibraryInfo::PluginsPath));
00265         return 0;
00266     }
00267     return 0;
00268 }

KDECore

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

kdelibs

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