00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
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 <config.h>
00039 #include <config-prefix.h>
00040 #include <kconfiggroup.h>
00041 #include <kkernel_win.h>
00042 #include <kde_file.h>
00043
00044 static void printResult(const QString &s)
00045 {
00046 if (s.isEmpty())
00047 printf("\n");
00048 else {
00049 QString path = QDir::convertSeparators( s );
00050 printf("%s\n", path.toLocal8Bit().constData());
00051 }
00052 }
00053
00054 int main(int argc, char **argv)
00055 {
00056 KAboutData about("kde4-config", "kdelibs4", ki18n("kde4-config"), "1.0",
00057 ki18n("A little program to output installation paths"),
00058 KAboutData::License_GPL,
00059 ki18n("(C) 2000 Stephan Kulow"));
00060 KCmdLineArgs::init( argc, argv, &about);
00061
00062 KCmdLineOptions options;
00063 options.add("expandvars", ki18n("Left for legacy support"));
00064 options.add("prefix", ki18n("Compiled in prefix for KDE libraries"));
00065 options.add("exec-prefix", ki18n("Compiled in exec_prefix for KDE libraries"));
00066 options.add("libsuffix", ki18n("Compiled in library path suffix"));
00067 options.add("localprefix", ki18n("Prefix in $HOME used to write files"));
00068 options.add("version", ki18n("Compiled in version string for KDE libraries"));
00069 options.add("types", ki18n("Available KDE resource types"));
00070 options.add("path type", ki18n("Search path for resource type"));
00071 options.add("locate filename", ki18n("Find filename inside the resource type given to --path"));
00072 options.add("userpath type", ki18n("User path: desktop|autostart|document"));
00073 options.add("install type", ki18n("Prefix to install resource files to"));
00074 options.add("qt-prefix", ki18n("Installation prefix for Qt"));
00075 options.add("qt-binaries", ki18n("Location of installed Qt binaries"));
00076 options.add("qt-libraries", ki18n("Location of installed Qt libraries"));
00077 options.add("qt-plugins", ki18n("Location of installed Qt plugins"));
00078 KCmdLineArgs::addCmdLineOptions( options );
00079
00080 KComponentData a(&about);
00081 (void)KGlobal::dirs();
00082 (void)KGlobal::config();
00083
00084
00085 KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
00086
00087 if (args->isSet("prefix"))
00088 {
00089 printResult(KDEDIR);
00090 return 0;
00091 }
00092
00093 if (args->isSet("exec-prefix"))
00094 {
00095 printResult(EXEC_INSTALL_PREFIX);
00096 return 0;
00097 }
00098
00099 if (args->isSet("libsuffix"))
00100 {
00101 QString tmp(KDELIBSUFF);
00102 tmp.remove('"');
00103 printResult(tmp.toLocal8Bit());
00104 return 0;
00105 }
00106
00107 if (args->isSet("localprefix"))
00108 {
00109 printResult(KGlobal::dirs()->localkdedir());
00110 return 0;
00111 }
00112
00113 if (args->isSet("version"))
00114 {
00115 printf("%s\n", KDE_VERSION_STRING);
00116 return 0;
00117 }
00118
00119 if (args->isSet("types"))
00120 {
00121 QStringList types = KGlobal::dirs()->allTypes();
00122 types.sort();
00123 const char *helptexts[] = {
00124 "apps", I18N_NOOP("Applications menu (.desktop files)"),
00125 "cgi", I18N_NOOP("CGIs to run from kdehelp"),
00126 "config", I18N_NOOP("Configuration files"),
00127 "data", I18N_NOOP("Where applications store data"),
00128 "emoticons", I18N_NOOP("Emoticons"),
00129 "exe", I18N_NOOP("Executables in $prefix/bin"),
00130 "html", I18N_NOOP("HTML documentation"),
00131 "icon", I18N_NOOP("Icons"),
00132 "kcfg", I18N_NOOP("Configuration description files"),
00133 "lib", I18N_NOOP("Libraries"),
00134 "include", I18N_NOOP("Includes/Headers"),
00135 "locale", I18N_NOOP("Translation files for KLocale"),
00136 "mime", I18N_NOOP("Mime types"),
00137 "module", I18N_NOOP("Loadable modules"),
00138 "pixmap", I18N_NOOP("Legacy pixmaps"),
00139 "qtplugins", I18N_NOOP("Qt plugins"),
00140 "services", I18N_NOOP("Services"),
00141 "servicetypes", I18N_NOOP("Service types"),
00142 "sound", I18N_NOOP("Application sounds"),
00143 "templates", I18N_NOOP("Templates"),
00144 "wallpaper", I18N_NOOP("Wallpapers"),
00145 "xdgdata-apps", I18N_NOOP("XDG Application menu (.desktop files)"),
00146 "xdgdata-dirs", I18N_NOOP("XDG Menu descriptions (.directory files)"),
00147 "xdgdata-icon", I18N_NOOP("XDG Icons"),
00148 "xdgdata-pixmaps", I18N_NOOP("Legacy pixmaps"),
00149 "xdgdata-mime", I18N_NOOP("XDG Mime Types"),
00150 "xdgconf-menu", I18N_NOOP("XDG Menu layout (.menu files)"),
00151 "tmp", I18N_NOOP("Temporary files (specific for both current host and current user)"),
00152 "socket", I18N_NOOP("UNIX Sockets (specific for both current host and current user)"),
00153 0, 0
00154 };
00155 for (QStringList::ConstIterator it = types.begin(); it != types.end(); ++it)
00156 {
00157 int index = 0;
00158 while (helptexts[index] && *it != helptexts[index]) {
00159 index += 2;
00160 }
00161 if (helptexts[index]) {
00162 printf("%s - %s\n", helptexts[index], i18n(helptexts[index+1]).toLocal8Bit().data());
00163 } else {
00164 printf("%s", i18n("%1 - unknown type\n", *it).toLocal8Bit().data());
00165 }
00166 }
00167 return 0;
00168 }
00169
00170 QString type = args->getOption("path");
00171 if (!type.isEmpty())
00172 {
00173 QString fileName = args->getOption("locate");
00174 if (!fileName.isEmpty())
00175 {
00176 QString result = KStandardDirs::locate(type.toLatin1(), fileName);
00177 if (!result.isEmpty())
00178 printf("%s\n", result.toLocal8Bit().constData());
00179 return result.isEmpty() ? 1 : 0;
00180 }
00181
00182 printResult(KGlobal::dirs()->resourceDirs(type.toLatin1()).join(QString(KPATH_SEPARATOR)));
00183 return 0;
00184 }
00185
00186 type = args->getOption("userpath");
00187 if (!type.isEmpty())
00188 {
00189
00190 if ( type == "desktop" )
00191 {
00192 KConfigGroup g( KGlobal::config(), "Paths" );
00193 QString path=QDir::homePath() + "/Desktop/";
00194 path=g.readPathEntry( "Desktop", path);
00195 path=QDir::cleanPath( path );
00196 if ( !path.endsWith('/') )
00197 path.append(QLatin1Char('/'));
00198 printResult(path);
00199 }
00200 else if ( type == "autostart" )
00201 {
00202 KConfigGroup g( KGlobal::config(), "Paths" );
00203 QString path=QDir::homePath() + "/Autostart/";
00204 path=g.readPathEntry( "Autostart", path);
00205 path=QDir::cleanPath( path );
00206 if ( !path.endsWith('/') )
00207 path.append(QLatin1Char('/'));
00208 printResult(path);
00209
00210 }
00211 else if ( type == "document" )
00212 {
00213 KConfigGroup g( KGlobal::config(), "Paths" );
00214 #ifdef Q_WS_WIN
00215 QString path=getWin32ShellFoldersPath(QLatin1String("Personal"));
00216 #else
00217 QString path=QDir::homePath();
00218 #endif
00219 path=g.readPathEntry( "Desktop", path);
00220 path=QDir::cleanPath( path );
00221 if ( !path.endsWith('/') )
00222 path.append(QLatin1Char('/'));
00223 printResult(path);
00224 }
00225 else
00226 fprintf(stderr, "%s", i18n("%1 - unknown type of userpath\n", type).toLocal8Bit().data() );
00227 return 0;
00228 }
00229
00230 type = args->getOption("install");
00231 if (!type.isEmpty())
00232 {
00233 printResult( KGlobal::dirs()->installPath(type.toLocal8Bit()) );
00234 }
00235
00236 if (args->isSet("qt-prefix"))
00237 {
00238 printResult(QLibraryInfo::location(QLibraryInfo::PrefixPath));
00239 return 0;
00240 }
00241 if (args->isSet("qt-binaries"))
00242 {
00243 printResult(QLibraryInfo::location(QLibraryInfo::BinariesPath));
00244 return 0;
00245 }
00246 if (args->isSet("qt-libraries"))
00247 {
00248 printResult(QLibraryInfo::location(QLibraryInfo::LibrariesPath));
00249 return 0;
00250 }
00251 if (args->isSet("qt-plugins"))
00252 {
00253 printResult(QLibraryInfo::location(QLibraryInfo::PluginsPath));
00254 return 0;
00255 }
00256 return 0;
00257 }