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