kde-config.cpp
// -*- c++ -*-
#include <kcmdlineargs.h>
#include <klocale.h>
#include <kinstance.h>
#include <kstandarddirs.h>
#include <kglobal.h>
#include <kglobalsettings.h>
#include <stdio.h>
#include <kaboutdata.h>
#include <config.h>
#include <kapplication.h>
static const char *description = I18N_NOOP("A little program to output installation paths");
static KCmdLineOptions options[] =
{
{ "expandvars", I18N_NOOP("expand ${prefix} and ${exec_prefix} in output"), 0 },
{ "prefix", I18N_NOOP("Compiled in prefix for KDE libraries"), 0 },
{ "exec-prefix", I18N_NOOP("Compiled in exec_prefix for KDE libraries"), 0 },
{ "libsuffix", I18N_NOOP("Compiled in library path suffix"), 0 },
{ "localprefix", I18N_NOOP("Prefix in $HOME used to write files"), 0},
{ "version", I18N_NOOP("Compiled in version string for KDE libraries"), 0 },
{ "types", I18N_NOOP("Available KDE resource types"), 0 },
{ "path type", I18N_NOOP("Search path for resource type"), 0 },
{ "userpath type", I18N_NOOP("User path: desktop|autostart|trash|document"), 0 },
{ "install type", I18N_NOOP("Prefix to install resource files to"), 0},
{ 0,0,0 }
};
bool _expandvars = false;
QString expandvars(const char *_input)
{
QString result = QString::fromLatin1(_input);
if (!_expandvars)
return result;
bool changed = false;
int index = result.find("${prefix}");
if (index >= 0) {
result = result.replace(index, 9, "/opt/local");
changed = true;
}
index = result.find("$(prefix)");
if (index >= 0) {
result = result.replace(index, 9, "/opt/local");
changed = true;
}
index = result.find("${datadir}");
if (index >= 0) {
result = result.replace(index, 10, "/opt/local/share/kde");
changed = true;
}
index = result.find("$(datadir)");
if (index >= 0) {
result = result.replace(index, 10, "/opt/local/share/kde");
changed = true;
}
index = result.find("${exec_prefix}");
if (index >= 0) {
result = result.replace(index, 14, "${prefix}");
changed = true;
}
index = result.find("$(exec_prefix)");
if (index >= 0) {
result = result.replace(index, 14, "${prefix}");
changed = true;
}
index = result.find("${libdir}");
if (index >= 0) {
result = result.replace(index, 9, "/opt/local/lib");
changed = true;
}
index = result.find("$(libdir)");
if (index >= 0) {
result = result.replace(index, 9, "/opt/local/lib");
changed = true;
}
index = result.find("${includedir}");
if (index >= 0) {
result = result.replace(index, 20, "${prefix}/include");
changed = true;
}
index = result.find("$(includedir)");
if (index >= 0) {
result = result.replace(index, 20, "${prefix}/include");
changed = true;
}
index = result.find("${sysconfdir}");
if (index >= 0) {
result = result.replace(index, 13, "/opt/local/etc");
changed = true;
}
index = result.find("$(sysconfdir)");
if (index >= 0) {
result = result.replace(index, 13, "/opt/local/etc");
changed = true;
}
if (changed)
return expandvars(result.latin1());
else
return result;
}
void printResult(const QString &s)
{
if (s.isEmpty())
printf("\n");
else
printf("%s\n", s.local8Bit().data());
}
int main(int argc, char **argv)
{
KLocale::setMainCatalogue("kdelibs");
KAboutData about("kde-config", "kde-config", "1.0", description, KAboutData::License_GPL, "(C) 2000 Stephan Kulow");
KCmdLineArgs::init( argc, argv, &about);
KCmdLineArgs::addCmdLineOptions( options ); // Add my own options.
KInstance a("kde-config");
(void)KGlobal::dirs(); // trigger the creation
(void)KGlobal::config();
// Get application specific arguments
KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
_expandvars = args->isSet("expandvars");
if (args->isSet("prefix"))
{
printResult(expandvars("/opt/local"));
return 0;
}
if (args->isSet("exec-prefix"))
{
printResult(expandvars("${prefix}"));
return 0;
}
if (args->isSet("libsuffix"))
{
QString tmp(KDELIBSUFF);
tmp.remove('"');
printResult(expandvars(tmp.local8Bit()));
return 0;
}
if (args->isSet("localprefix"))
{
printResult(KGlobal::dirs()->localkdedir());
return 0;
}
if (args->isSet("version"))
{
printf("%s\n", KDE_VERSION_STRING);
return 0;
}
if (args->isSet("types"))
{
QStringList types = KGlobal::dirs()->allTypes();
types.sort();
const char *helptexts[] = {
"apps", I18N_NOOP("Applications menu (.desktop files)"),
"cgi", I18N_NOOP("CGIs to run from kdehelp"),
"config", I18N_NOOP("Configuration files"),
"data", I18N_NOOP("Where applications store data"),
"exe", I18N_NOOP("Executables in $prefix/bin"),
"html", I18N_NOOP("HTML documentation"),
"icon", I18N_NOOP("Icons"),
"kcfg", I18N_NOOP("Configuration description files"),
"lib", I18N_NOOP("Libraries"),
"include", I18N_NOOP("Includes/Headers"),
"locale", I18N_NOOP("Translation files for KLocale"),
"mime", I18N_NOOP("Mime types"),
"module", I18N_NOOP("Loadable modules"),
"qtplugins", I18N_NOOP("Qt plugins"),
"services", I18N_NOOP("Services"),
"servicetypes", I18N_NOOP("Service types"),
"sound", I18N_NOOP("Application sounds"),
"templates", I18N_NOOP("Templates"),
"wallpaper", I18N_NOOP("Wallpapers"),
"xdgdata-apps", I18N_NOOP("XDG Application menu (.desktop files)"),
"xdgdata-dirs", I18N_NOOP("XDG Menu descriptions (.directory files)"),
"xdgconf-menu", I18N_NOOP("XDG Menu layout (.menu files)"),
"tmp", I18N_NOOP("Temporary files (specific for both current host and current user)"),
"socket", I18N_NOOP("UNIX Sockets (specific for both current host and current user)"),
0, 0
};
for (QStringList::ConstIterator it = types.begin(); it != types.end(); ++it)
{
int index = 0;
while (helptexts[index] && *it != helptexts[index]) {
index += 2;
}
if (helptexts[index]) {
printf("%s - %s\n", helptexts[index], i18n(helptexts[index+1]).local8Bit().data());
} else {
printf("%s", i18n("%1 - unknown type\n").arg(*it).local8Bit().data());
}
}
return 0;
}
QString type = args->getOption("path");
if (!type.isEmpty())
{
printResult(KGlobal::dirs()->resourceDirs(type.latin1()).join(":"));
return 0;
}
type = args->getOption("userpath");
if (!type.isEmpty())
{
if ( type == "desktop" )
printResult(KGlobalSettings::desktopPath());
else if ( type == "autostart" )
printResult(KGlobalSettings::autostartPath());
else if ( type == "trash" )
printResult(KGlobalSettings::trashPath());
else if ( type == "document" )
printResult(KGlobalSettings::documentPath());
else
fprintf(stderr, "%s", i18n("%1 - unknown type of userpath\n").arg(type).local8Bit().data() );
return 0;
}
type = args->getOption("install");
if (!type.isEmpty())
{
const char *installprefixes[] = {
"apps", "/opt/local/share/kde/applnk",
"config", "/opt/local/share/kde/config",
"kcfg", "${datadir}/config.kcfg",
"data", "/opt/local/share/kde/apps",
"exe", "${exec_prefix}/bin",
"html", "/opt/local/share/doc/kde/HTML",
"icon", "/opt/local/share/icons",
"lib", "/opt/local/lib",
"module", "${libdir}/kde3",
"qtplugins", "${libdir}/kde3/plugins",
"locale", "/opt/local/lib/locale",
"mime", "/opt/local/share/kde/mimelnk",
"services", "/opt/local/share/kde/services",
"servicetypes", "/opt/local/share/kde/servicetypes",
"sound", "/opt/local/share/kde/sounds",
"templates", "/opt/local/share/kde/templates",
"wallpaper", "/opt/local/share/kde/wallpapers",
"xdgconf-menu", "${sysconfdir}/xdg/menus",
"xdgdata-apps", "/opt/local/share/applications/kde",
"xdgdata-dirs", "/opt/local/share/desktop-directories",
"include", "${prefix}/include",
0, 0
};
int index = 0;
while (installprefixes[index] && type != installprefixes[index]) {
index += 2;
}
if (installprefixes[index]) {
printResult(expandvars(installprefixes[index+1]));
} else {
printResult("NONE"); // no i18n here as for scripts
}
}
return 0;
}
KCmdLineArgs::getOption
QCString getOption(const char *option) const
Read out a string option.
Definition: kcmdlineargs.cpp:1117
KGlobalSettings::desktopPath
static QString desktopPath()
The path to the desktop directory of the current user.
Definition: kglobalsettings.h:225
KCmdLineArgs
A class for command-line argument handling.
Definition: kcmdlineargs.h:222
KCmdLineArgs::parsedArgs
static KCmdLineArgs * parsedArgs(const char *id=0)
Access parsed arguments.
Definition: kcmdlineargs.cpp:310
KGlobalSettings::trashPath
static QString trashPath()
DEPRECATED (starting from kde-3.4).
Definition: kglobalsettings.h:238
klocale.h
KCmdLineOptions
Structure that holds command line options.
Definition: kcmdlineargs.h:40
KGlobal::dirs
static KStandardDirs * dirs()
Returns the application standard dirs object.
Definition: kglobal.cpp:54
KLocale::i18n
QString i18n(const char *text)
Definition: klocale.cpp:1961
KCmdLineArgs::isSet
bool isSet(const char *option) const
Read out a boolean option or check for the presence of string option.
Definition: kcmdlineargs.cpp:1179
KLocale::I18N_NOOP
#define I18N_NOOP(x)
Definition: klocale.h:52
KInstance
Access to KDE global objects for use in shared libraries.
Definition: kinstance.h:43
KAboutData
This class is used to store information about a program.
Definition: kaboutdata.h:182
KCmdLineArgs::init
static void init(int _argc, char **_argv, const char *_appname, const char *programName, const char *_description, const char *_version, bool noKApp=false)
Initialize class.
Definition: kcmdlineargs.cpp:127
KLocale::setMainCatalogue
static void setMainCatalogue(const char *catalog)
Use this as main catalog for all KLocales, if not the appname will be used.
Definition: klocale.cpp:1397
KCmdLineArgs::addCmdLineOptions
static void addCmdLineOptions(const KCmdLineOptions *options, const char *name=0, const char *id=0, const char *afterId=0)
Add options to your application.
Definition: kcmdlineargs.cpp:206
KGlobalSettings::documentPath
static QString documentPath()
The path where documents are stored of the current user.
Definition: kglobalsettings.h:246
KStandardDirs::allTypes
QStringList allTypes() const
This function will return a list of all the types that KStandardDirs supports.
Definition: kstandarddirs.cpp:158
KGlobal::config
static KConfig * config()
Returns the general config object.
Definition: kglobal.cpp:61
KGlobalSettings::autostartPath
static QString autostartPath()
The path to the autostart directory of the current user.
Definition: kglobalsettings.h:231

KDE Home | KDE Accessibility Home | Description of Access Keys