File indexing completed on 2024-04-21 14:56:13
0001 // -*- c++ -*- 0002 /* 0003 * This file is part of the KDE libraries 0004 * 0005 * Copyright (c) 2008 David Jarvie <djarvie@kde.org> 0006 * Copyright (c) 2006-2007 Christian Ehrlicher <Ch.Ehrlicher@gmx.de> 0007 * Copyright (c) 2000-2007 Stephan Kulow <coolo@kde.org> 0008 * 0009 * This library is free software; you can redistribute it and/or 0010 * modify it under the terms of the GNU Library General Public 0011 * License as published by the Free Software Foundation; either 0012 * version 2 of the License, or (at your option) any later version. 0013 * 0014 * This library is distributed in the hope that it will be useful, 0015 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0017 * Library General Public License for more details. 0018 * 0019 * You should have received a copy of the GNU Library General Public License 0020 * along with this library; see the file COPYING.LIB. If not, write to 0021 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0022 * Boston, MA 02110-1301, USA. 0023 */ 0024 0025 #include <kcmdlineargs.h> 0026 #include <klocalizedstring.h> 0027 #include <ksharedconfig.h> 0028 #include <kstandarddirs.h> 0029 #include <kglobal.h> 0030 #include <kconfig.h> 0031 #include <qdir.h> 0032 #include <stdio.h> 0033 #include <k4aboutdata.h> 0034 #include <kdeversion.h> 0035 #include <QDir> 0036 #include <QLibraryInfo> 0037 #include <QCoreApplication> 0038 #include <config-kstandarddirs.h> 0039 #include <kconfiggroup.h> 0040 #include <kkernel_win.h> 0041 #include <qstandardpaths.h> 0042 0043 static void printResult(const QString &s) 0044 { 0045 if (s.isEmpty()) { 0046 printf("\n"); 0047 } else { 0048 const QString path = QDir::toNativeSeparators(s); 0049 printf("%s\n", path.toLocal8Bit().constData()); 0050 } 0051 } 0052 0053 int main(int argc, char **argv) 0054 { 0055 QCoreApplication app(argc, argv); 0056 K4AboutData about("kf5-config", "kdelibs4", ki18n("kf5-config"), "1.0", 0057 ki18n("A little program to output installation paths"), 0058 K4AboutData::License_GPL, 0059 ki18n("(C) 2000 Stephan Kulow")); 0060 KCmdLineArgs::init(argc, argv, &about); 0061 0062 KCmdLineOptions options; 0063 options.add("expandvars", ki18n("Left for legacy support")); 0064 options.add("prefix", ki18n("Compiled in prefix for KDE libraries")); 0065 options.add("exec-prefix", ki18n("Compiled in exec_prefix for KDE libraries")); 0066 options.add("libsuffix", ki18n("Compiled in library path suffix")); 0067 //options.add("localprefix", ki18n("Prefix in $HOME used to write files")); 0068 options.add("kde-version", ki18n("Compiled in version string for KDE libraries")); 0069 options.add("types", ki18n("Available KDE resource types")); 0070 options.add("path type", ki18n("Search path for resource type")); 0071 options.add("locate filename", ki18n("Find filename inside the resource type given to --path")); 0072 options.add("userpath type", ki18n("User path: desktop|autostart|document")); 0073 options.add("install type", ki18n("Prefix to install resource files to")); 0074 options.add("qt-prefix", ki18n("Installation prefix for Qt")); 0075 options.add("qt-binaries", ki18n("Location of installed Qt binaries")); 0076 options.add("qt-libraries", ki18n("Location of installed Qt libraries")); 0077 options.add("qt-plugins", ki18n("Location of installed Qt plugins")); 0078 KCmdLineArgs::addCmdLineOptions(options); // Add my own options. 0079 0080 (void)KGlobal::dirs(); // trigger the creation 0081 (void)KSharedConfig::openConfig(); 0082 0083 // Get application specific arguments 0084 KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); 0085 0086 if (args->isSet("prefix")) { 0087 printResult(QFile::decodeName(CMAKE_INSTALL_PREFIX)); 0088 return 0; 0089 } 0090 0091 if (args->isSet("exec-prefix")) { 0092 printResult(QFile::decodeName(EXEC_INSTALL_PREFIX)); 0093 return 0; 0094 } 0095 0096 #if 0 0097 if (args->isSet("libsuffix")) { 0098 QString tmp(QFile::decodeName(KDELIBSUFF)); 0099 tmp.remove(QLatin1Char('"')); 0100 printResult(tmp); 0101 return 0; 0102 } 0103 #endif 0104 0105 #if 0 0106 if (args->isSet("localprefix")) { 0107 printResult(KGlobal::dirs()->localkdedir()); 0108 return 0; 0109 } 0110 #endif 0111 0112 if (args->isSet("kde-version")) { 0113 printf("%s\n", KDE_VERSION_STRING); 0114 return 0; 0115 } 0116 0117 if (args->isSet("types")) { 0118 QStringList types = KGlobal::dirs()->allTypes(); 0119 types.sort(); 0120 const char *helptexts[] = { 0121 "apps", I18N_NOOP("Applications menu (.desktop files)"), 0122 "autostart", I18N_NOOP("Autostart directories"), 0123 "cache", I18N_NOOP("Cached information (e.g. favicons, web-pages)"), 0124 "config", I18N_NOOP("Configuration files"), 0125 "data", I18N_NOOP("Where applications store data"), 0126 "emoticons", I18N_NOOP("Emoticons"), 0127 "exe", I18N_NOOP("Executables in $prefix/bin"), 0128 "html", I18N_NOOP("HTML documentation"), 0129 "icon", I18N_NOOP("Icons"), 0130 "kcfg", I18N_NOOP("Configuration description files"), 0131 "lib", I18N_NOOP("Libraries"), 0132 "include", I18N_NOOP("Includes/Headers"), 0133 "locale", I18N_NOOP("Translation files for KLocale"), 0134 "module", I18N_NOOP("Loadable modules"), 0135 "pixmap", I18N_NOOP("Legacy pixmaps"), 0136 "qtplugins", I18N_NOOP("Qt plugins"), 0137 "services", I18N_NOOP("Services"), 0138 "servicetypes", I18N_NOOP("Service types"), 0139 "sound", I18N_NOOP("Application sounds"), 0140 "templates", I18N_NOOP("Templates"), 0141 "wallpaper", I18N_NOOP("Wallpapers"), 0142 "xdgdata", I18N_NOOP("XDG Shared Data"), 0143 "xdgdata-apps", I18N_NOOP("XDG Application menu (.desktop files)"), 0144 "xdgdata-dirs", I18N_NOOP("XDG Menu descriptions (.directory files)"), 0145 "xdgdata-icon", I18N_NOOP("XDG Icons"), 0146 "xdgdata-pixmap", I18N_NOOP("Legacy pixmaps"), 0147 "xdgdata-mime", I18N_NOOP("XDG Mime Types"), 0148 "xdgconf", I18N_NOOP("XDG Configuration Files"), 0149 "xdgconf-menu", I18N_NOOP("XDG Menu layout (.menu files)"), 0150 "xdgconf-autostart", I18N_NOOP("XDG autostart directory"), 0151 "tmp", I18N_NOOP("Temporary files (specific for both current host and current user)"), 0152 "socket", I18N_NOOP("UNIX Sockets (specific for both current host and current user)"), 0153 nullptr, nullptr 0154 }; 0155 Q_FOREACH (const QString &type, types) { 0156 int index = 0; 0157 while (helptexts[index] && type != QLatin1String(helptexts[index])) { 0158 index += 2; 0159 } 0160 if (helptexts[index]) { 0161 printf("%s - %s\n", helptexts[index], i18n(helptexts[index + 1]).toLocal8Bit().constData()); 0162 } else { 0163 printf("%s", i18n("%1 - unknown type\n", type).toLocal8Bit().constData()); 0164 } 0165 } 0166 return 0; 0167 } 0168 0169 QString type = args->getOption("path"); 0170 if (!type.isEmpty()) { 0171 QString fileName = args->getOption("locate"); 0172 if (!fileName.isEmpty()) { 0173 QString result = KStandardDirs::locate(type.toLatin1(), fileName); 0174 if (!result.isEmpty()) { 0175 printf("%s\n", result.toLocal8Bit().constData()); 0176 } 0177 return result.isEmpty() ? 1 : 0; 0178 } 0179 0180 // ### maybe Qt should have a QDir::pathSeparator() to avoid ifdefs.. 0181 #ifdef Q_OS_WIN 0182 #define KPATH_SEPARATOR ';' 0183 #else 0184 #define KPATH_SEPARATOR ':' 0185 #endif 0186 0187 printResult(KGlobal::dirs()->resourceDirs(type.toLatin1()).join(QString(QChar::fromLatin1(KPATH_SEPARATOR)))); 0188 return 0; 0189 } 0190 0191 type = args->getOption("userpath"); 0192 if (!type.isEmpty()) { 0193 //code duplicated with KGlobalSettings 0194 if (type == QLatin1String("desktop")) { 0195 QString path = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation); 0196 printResult(path.isEmpty() ? QDir::homePath() : path); 0197 } 0198 #if 0 // See KGlobalSettings::autostartPath 0199 else if (type == QLatin1String("autostart")) { 0200 KConfigGroup g(KSharedConfig::openConfig(), "Paths"); 0201 QString path = QDir::homePath() + QLatin1String("/Autostart/"); 0202 path = g.readPathEntry("Autostart", path); 0203 path = QDir::cleanPath(path); 0204 if (!path.endsWith(QLatin1Char('/'))) { 0205 path.append(QLatin1Char(QLatin1Char('/'))); 0206 } 0207 printResult(path); 0208 0209 } 0210 #endif 0211 else if (type == QLatin1String("document")) { 0212 QString path = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation); 0213 printResult(path.isEmpty() ? QDir::homePath() : path); 0214 } else { 0215 fprintf(stderr, "%s", i18n("%1 - unknown type of userpath\n", type).toLocal8Bit().data()); 0216 } 0217 return 0; 0218 } 0219 0220 type = args->getOption("install"); 0221 if (!type.isEmpty()) { 0222 printResult(KGlobal::dirs()->installPath(type.toLocal8Bit())); 0223 } 0224 0225 if (args->isSet("qt-prefix")) { 0226 printResult(QLibraryInfo::location(QLibraryInfo::PrefixPath)); 0227 return 0; 0228 } 0229 if (args->isSet("qt-binaries")) { 0230 printResult(QLibraryInfo::location(QLibraryInfo::BinariesPath)); 0231 return 0; 0232 } 0233 if (args->isSet("qt-libraries")) { 0234 printResult(QLibraryInfo::location(QLibraryInfo::LibrariesPath)); 0235 return 0; 0236 } 0237 if (args->isSet("qt-plugins")) { 0238 printResult(QLibraryInfo::location(QLibraryInfo::PluginsPath)); 0239 return 0; 0240 } 0241 return 0; 0242 }