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/local/kde");
00042 changed = true;
00043 }
00044 index = result.find("${exec_prefix}");
00045 if (index >= 0) {
00046 result = result.replace(index, 14, "${prefix}");
00047 changed = true;
00048 }
00049 index = result.find("$(exec_prefix)");
00050 if (index >= 0) {
00051 result = result.replace(index, 14, "${prefix}");
00052 changed = true;
00053 }
00054 index = result.find("$(prefix");
00055 if (index >= 0) {
00056 result = result.replace(index, 9, "/usr/local/kde");
00057 changed = true;
00058 }
00059 if (changed)
00060 return expandvars(result.latin1());
00061 else
00062 return result;
00063 }
00064
00065 void printResult(const QString &s)
00066 {
00067 if (s.isEmpty())
00068 printf("\n");
00069 else
00070 printf("%s\n", s.local8Bit().data());
00071 }
00072
00073 int main(int argc, char **argv)
00074 {
00075 KLocale::setMainCatalogue("kdelibs");
00076 KAboutData about("kde-config", "kde-config", "1.0", description, KAboutData::License_GPL, "(C) 2000 Stephan Kulow");
00077 KCmdLineArgs::init( argc, argv, &about);
00078
00079 KCmdLineArgs::addCmdLineOptions( options );
00080
00081 KInstance a("kde-config");
00082 (void)KGlobal::dirs();
00083 (void)KGlobal::config();
00084
00085
00086 KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
00087
00088 _expandvars = args->isSet("expandvars");
00089
00090 if (args->isSet("prefix"))
00091 {
00092 printResult(expandvars("/usr/local/kde"));
00093 return 0;
00094 }
00095
00096 if (args->isSet("exec-prefix"))
00097 {
00098 printResult(expandvars("${prefix}"));
00099 return 0;
00100 }
00101
00102 if (args->isSet("localprefix"))
00103 {
00104 printResult(KGlobal::dirs()->localkdedir());
00105 return 0;
00106 }
00107
00108 if (args->isSet("version"))
00109 {
00110 printf("%s\n", KDE_VERSION_STRING);
00111 return 0;
00112 }
00113
00114 if (args->isSet("types"))
00115 {
00116 QStringList types = KGlobal::dirs()->allTypes();
00117 types.sort();
00118 const char *helptexts[] = {
00119 "apps", I18N_NOOP("Applications menu (.desktop files)"),
00120 "cgi", I18N_NOOP("CGIs to run from kdehelp"),
00121 "config", I18N_NOOP("Configuration files"),
00122 "data", I18N_NOOP("Where applications store data"),
00123 "exe", I18N_NOOP("Executables in $prefix/bin"),
00124 "html", I18N_NOOP("HTML documentation"),
00125 "icon", I18N_NOOP("Icons"),
00126 "lib", I18N_NOOP("Libraries"),
00127 "locale", I18N_NOOP("Translation files for KLocale"),
00128 "mime", I18N_NOOP("Mime types"),
00129 "services", I18N_NOOP("Services"),
00130 "servicetypes", I18N_NOOP("Service types"),
00131 "sound", I18N_NOOP("Application sounds"),
00132 "templates", I18N_NOOP("Templates"),
00133 "wallpaper", I18N_NOOP("Wallpapers"),
00134 "tmp", I18N_NOOP("Temporary files (specfic for both current host and current user)"),
00135 "socket", I18N_NOOP("UNIX Sockets (specific for both current host and current user)"),
00136 0, 0
00137 };
00138 for (QStringList::ConstIterator it = types.begin(); it != types.end(); ++it)
00139 {
00140 int index = 0;
00141 while (helptexts[index] && *it != helptexts[index]) {
00142 index += 2;
00143 }
00144 if (helptexts[index]) {
00145 printf("%s - %s\n", helptexts[index], i18n(helptexts[index+1]).local8Bit().data());
00146 } else {
00147 printf("%s", i18n("%1 - unknown type\n").arg(*it).local8Bit().data());
00148 }
00149 }
00150 return 0;
00151 }
00152
00153 QString type = args->getOption("path");
00154 if (!type.isEmpty())
00155 {
00156 printResult(KGlobal::dirs()->resourceDirs(type.latin1()).join(":"));
00157 return 0;
00158 }
00159
00160 type = args->getOption("userpath");
00161 if (!type.isEmpty())
00162 {
00163 if ( type == "desktop" )
00164 printResult(KGlobalSettings::desktopPath());
00165 else if ( type == "autostart" )
00166 printResult(KGlobalSettings::autostartPath());
00167 else if ( type == "trash" )
00168 printResult(KGlobalSettings::trashPath());
00169 else if ( type == "document" )
00170 printResult(KGlobalSettings::documentPath());
00171 else
00172 fprintf(stderr, "%s", i18n("%1 - unknown type of userpath\n").arg(type).local8Bit().data() );
00173 return 0;
00174 }
00175
00176 type = args->getOption("install");
00177 if (!type.isEmpty())
00178 {
00179 const char *installprefixes[] = {
00180 "apps", "${prefix}/share/applnk",
00181 "config", "${prefix}/share/config",
00182 "data", "${prefix}/share/apps",
00183 "exe", "${exec_prefix}/bin",
00184 "html", "${prefix}/share/doc/HTML",
00185 "icon", "${prefix}/share/icons",
00186 "lib", "${exec_prefix}/lib",
00187 "locale", "${prefix}/share/locale",
00188 "mime", "${prefix}/share/mimelnk",
00189 "services", "${prefix}/share/services",
00190 "servicetypes", "${prefix}/share/servicetypes",
00191 "sound", "${prefix}/share/sounds",
00192 "templates", "${prefix}/share/templates",
00193 "wallpaper", "${prefix}/share/wallpapers",
00194 0, 0
00195 };
00196 int index = 0;
00197 while (installprefixes[index] && type != installprefixes[index]) {
00198 index += 2;
00199 }
00200 if (installprefixes[index]) {
00201 printResult(expandvars(installprefixes[index+1]));
00202 } else {
00203 printResult("NONE");
00204 }
00205 }
00206 return 0;
00207 }