kde-config.cpp
00001
00002
00003
#include <kcmdlineargs.h>
00004
#include <klocale.h>
00005
#include <kinstance.h>
00006
#include <kstandarddirs.h>
00007
#include <kglobal.h>
00008
#include <kglobalsettings.h>
00009
#include <stdio.h>
00010
#include <kaboutdata.h>
00011
#include <config.h>
00012
#include <kapplication.h>
00013
00014
static const char *description = I18N_NOOP(
"A little program to output installation paths");
00015
00016
static KCmdLineOptions options[] =
00017 {
00018 {
"expandvars", I18N_NOOP(
"expand ${prefix} and ${exec_prefix} in output"), 0 },
00019 {
"prefix", I18N_NOOP(
"Compiled in prefix for KDE libraries"), 0 },
00020 {
"exec-prefix", I18N_NOOP(
"Compiled in exec_prefix for KDE libraries"), 0 },
00021 {
"localprefix", I18N_NOOP(
"Prefix in $HOME used to write files"), 0},
00022 {
"version", I18N_NOOP(
"Compiled in version string for KDE libraries"), 0 },
00023 {
"types", I18N_NOOP(
"Available KDE resource types"), 0 },
00024 {
"path type", I18N_NOOP(
"Search path for resource type"), 0 },
00025 {
"userpath type", I18N_NOOP(
"User path: desktop|autostart|trash|document"), 0 },
00026 {
"install type", I18N_NOOP(
"Prefix to install resource files to"), 0},
00027 { 0,0,0 }
00028 };
00029
00030
bool _expandvars =
false;
00031
00032
QString expandvars(
const char *_input)
00033 {
00034
QString result = QString::fromLatin1(_input);
00035
if (!_expandvars)
00036
return result;
00037
00038
bool changed =
false;
00039
int index = result.find(
"${prefix}");
00040
if (index >= 0) {
00041 result = result.replace(index, 9,
"/usr");
00042 changed =
true;
00043 }
00044 index = result.find(
"$(prefix)");
00045
if (index >= 0) {
00046 result = result.replace(index, 9,
"/usr");
00047 changed =
true;
00048 }
00049 index = result.find(
"${datadir}");
00050
if (index >= 0) {
00051 result = result.replace(index, 10,
"/usr/share");
00052 changed =
true;
00053 }
00054 index = result.find(
"$(datadir)");
00055
if (index >= 0) {
00056 result = result.replace(index, 10,
"/usr/share");
00057 changed =
true;
00058 }
00059 index = result.find(
"${exec_prefix}");
00060
if (index >= 0) {
00061 result = result.replace(index, 14,
"/usr");
00062 changed =
true;
00063 }
00064 index = result.find(
"$(exec_prefix)");
00065
if (index >= 0) {
00066 result = result.replace(index, 14,
"/usr");
00067 changed =
true;
00068 }
00069 index = result.find(
"${libdir}");
00070
if (index >= 0) {
00071 result = result.replace(index, 9,
"/usr/lib");
00072 changed =
true;
00073 }
00074 index = result.find(
"$(libdir)");
00075
if (index >= 0) {
00076 result = result.replace(index, 9,
"/usr/lib");
00077 changed =
true;
00078 }
00079 index = result.find(
"${sysconfdir}");
00080
if (index >= 0) {
00081 result = result.replace(index, 13,
"/etc");
00082 changed =
true;
00083 }
00084 index = result.find(
"$(sysconfdir)");
00085
if (index >= 0) {
00086 result = result.replace(index, 13,
"/etc");
00087 changed =
true;
00088 }
00089
if (changed)
00090
return expandvars(result.latin1());
00091
else
00092
return result;
00093 }
00094
00095
void printResult(
const QString &s)
00096 {
00097
if (s.isEmpty())
00098 printf(
"\n");
00099
else
00100 printf(
"%s\n", s.local8Bit().data());
00101 }
00102
00103
int main(
int argc,
char **argv)
00104 {
00105
KLocale::setMainCatalogue(
"kdelibs");
00106
KAboutData about(
"kde-config",
"kde-config",
"1.0", description, KAboutData::License_GPL,
"(C) 2000 Stephan Kulow");
00107
KCmdLineArgs::init( argc, argv, &about);
00108
00109
KCmdLineArgs::addCmdLineOptions( options );
00110
00111
KInstance a(
"kde-config");
00112 (
void)
KGlobal::dirs();
00113 (
void)
KGlobal::config();
00114
00115
00116
KCmdLineArgs *args =
KCmdLineArgs::parsedArgs();
00117
00118 _expandvars = args->
isSet(
"expandvars");
00119
00120
if (args->
isSet(
"prefix"))
00121 {
00122 printResult(expandvars(
"/usr"));
00123
return 0;
00124 }
00125
00126
if (args->
isSet(
"exec-prefix"))
00127 {
00128 printResult(expandvars(
"/usr"));
00129
return 0;
00130 }
00131
00132
if (args->
isSet(
"localprefix"))
00133 {
00134 printResult(KGlobal::dirs()->localkdedir());
00135
return 0;
00136 }
00137
00138
if (args->
isSet(
"version"))
00139 {
00140 printf(
"%s\n", KDE_VERSION_STRING);
00141
return 0;
00142 }
00143
00144
if (args->
isSet(
"types"))
00145 {
00146
QStringList types =
KGlobal::dirs()->
allTypes();
00147 types.sort();
00148
const char *helptexts[] = {
00149
"apps", I18N_NOOP(
"Applications menu (.desktop files)"),
00150
"cgi", I18N_NOOP(
"CGIs to run from kdehelp"),
00151
"config", I18N_NOOP(
"Configuration files"),
00152
"data", I18N_NOOP(
"Where applications store data"),
00153
"exe", I18N_NOOP(
"Executables in $prefix/bin"),
00154
"html", I18N_NOOP(
"HTML documentation"),
00155
"icon", I18N_NOOP(
"Icons"),
00156
"kcfg", I18N_NOOP(
"Configuration description files"),
00157
"lib", I18N_NOOP(
"Libraries"),
00158
"locale", I18N_NOOP(
"Translation files for KLocale"),
00159
"mime", I18N_NOOP(
"Mime types"),
00160
"module", I18N_NOOP(
"Loadable modules"),
00161
"qtplugins", I18N_NOOP(
"Qt plugins"),
00162
"services", I18N_NOOP(
"Services"),
00163
"servicetypes", I18N_NOOP(
"Service types"),
00164
"sound", I18N_NOOP(
"Application sounds"),
00165
"templates", I18N_NOOP(
"Templates"),
00166
"wallpaper", I18N_NOOP(
"Wallpapers"),
00167
"xdgdata-apps", I18N_NOOP(
"XDG Application menu (.desktop files)"),
00168
"xdgdata-dirs", I18N_NOOP(
"XDG Menu descriptions (.directory files)"),
00169
"xdgconf-menu", I18N_NOOP(
"XDG Menu layout (.menu files)"),
00170
"tmp", I18N_NOOP(
"Temporary files (specific for both current host and current user)"),
00171
"socket", I18N_NOOP(
"UNIX Sockets (specific for both current host and current user)"),
00172 0, 0
00173 };
00174
for (QStringList::ConstIterator it = types.begin(); it != types.end(); ++it)
00175 {
00176
int index = 0;
00177
while (helptexts[index] && *it != helptexts[index]) {
00178 index += 2;
00179 }
00180
if (helptexts[index]) {
00181 printf(
"%s - %s\n", helptexts[index], i18n(helptexts[index+1]).local8Bit().data());
00182 }
else {
00183 printf(
"%s", i18n(
"%1 - unknown type\n").arg(*it).local8Bit().data());
00184 }
00185 }
00186
return 0;
00187 }
00188
00189
QString type = args->
getOption(
"path");
00190
if (!type.isEmpty())
00191 {
00192 printResult(KGlobal::dirs()->resourceDirs(type.latin1()).join(
":"));
00193
return 0;
00194 }
00195
00196 type = args->
getOption(
"userpath");
00197
if (!type.isEmpty())
00198 {
00199
if ( type ==
"desktop" )
00200 printResult(KGlobalSettings::desktopPath());
00201
else if ( type ==
"autostart" )
00202 printResult(KGlobalSettings::autostartPath());
00203
else if ( type ==
"trash" )
00204 printResult(KGlobalSettings::trashPath());
00205
else if ( type ==
"document" )
00206 printResult(KGlobalSettings::documentPath());
00207
else
00208 fprintf(stderr,
"%s", i18n(
"%1 - unknown type of userpath\n").arg(type).local8Bit().data() );
00209
return 0;
00210 }
00211
00212 type = args->
getOption(
"install");
00213
if (!type.isEmpty())
00214 {
00215
const char *installprefixes[] = {
00216
"apps",
"${datadir}/applnk",
00217
"config",
"${datadir}/config",
00218
"kcfg",
"${datadir}/config.kcfg",
00219
"data",
"${datadir}/apps",
00220
"exe",
"${exec_prefix}/bin",
00221
"html",
"${datadir}/doc/HTML",
00222
"icon",
"${datadir}/icons",
00223
"lib",
"/usr/lib",
00224
"module",
"${libdir}/kde3",
00225
"qtplugins",
"${libdir}/kde3/plugins",
00226
"locale",
"${datadir}/locale",
00227
"mime",
"${datadir}/mimelnk",
00228
"services",
"${datadir}/services",
00229
"servicetypes",
"${datadir}/servicetypes",
00230
"sound",
"${datadir}/sounds",
00231
"templates",
"${datadir}/templates",
00232
"wallpaper",
"${datadir}/wallpapers",
00233
"xdgconf-menu",
"${sysconfdir}/xdg/menus",
00234
"xdgdata-apps",
"${datadir}/applications/kde",
00235
"xdgdata-dirs",
"${datadir}/desktop-directories",
00236 0, 0
00237 };
00238
int index = 0;
00239
while (installprefixes[index] && type != installprefixes[index]) {
00240 index += 2;
00241 }
00242
if (installprefixes[index]) {
00243 printResult(expandvars(installprefixes[index+1]));
00244 }
else {
00245 printResult(
"NONE");
00246 }
00247 }
00248
return 0;
00249 }
This file is part of the documentation for kdecore Library Version 3.2.3.