35 #include <kdeversion.h>
37 #include <QtCore/QLibraryInfo>
38 #include <QtCore/QCoreApplication>
41 #include <config-prefix.h>
51 QString path = QDir::toNativeSeparators( s );
52 printf(
"%s\n", path.toLocal8Bit().constData());
59 proc.start( QString::fromLatin1(
"xdg-user-dir"),
QStringList() << QString::fromLatin1(type) );
60 if (!proc.waitForStarted() || !proc.waitForFinished())
62 return QString::fromLocal8Bit( proc.readAll()).trimmed();
65 int main(
int argc,
char **argv)
67 QCoreApplication app(argc, argv);
68 KAboutData about(
"kde4-config",
"kdelibs4",
ki18n(
"kde4-config"),
"1.0",
69 ki18n(
"A little program to output installation paths"),
71 ki18n(
"(C) 2000 Stephan Kulow"));
75 options.
add(
"expandvars",
ki18n(
"Left for legacy support"));
76 options.
add(
"prefix",
ki18n(
"Compiled in prefix for KDE libraries"));
77 options.
add(
"exec-prefix",
ki18n(
"Compiled in exec_prefix for KDE libraries"));
78 options.
add(
"libsuffix",
ki18n(
"Compiled in library path suffix"));
79 options.
add(
"localprefix",
ki18n(
"Prefix in $HOME used to write files"));
80 options.
add(
"kde-version",
ki18n(
"Compiled in version string for KDE libraries"));
81 options.
add(
"types",
ki18n(
"Available KDE resource types"));
82 options.
add(
"path type",
ki18n(
"Search path for resource type"));
83 options.
add(
"locate filename",
ki18n(
"Find filename inside the resource type given to --path"));
84 options.
add(
"userpath type",
ki18n(
"User path: desktop|autostart|document"));
85 options.
add(
"install type",
ki18n(
"Prefix to install resource files to"));
86 options.
add(
"qt-prefix",
ki18n(
"Installation prefix for Qt"));
87 options.
add(
"qt-binaries",
ki18n(
"Location of installed Qt binaries"));
88 options.
add(
"qt-libraries",
ki18n(
"Location of installed Qt libraries"));
89 options.
add(
"qt-plugins",
ki18n(
"Location of installed Qt plugins"));
99 if (args->
isSet(
"prefix"))
105 if (args->
isSet(
"exec-prefix"))
107 printResult(QFile::decodeName(EXEC_INSTALL_PREFIX));
111 if (args->
isSet(
"libsuffix"))
113 QString tmp(QFile::decodeName(KDELIBSUFF));
114 tmp.remove(QLatin1Char(
'"'));
119 if (args->
isSet(
"localprefix"))
125 if (args->
isSet(
"kde-version"))
131 if (args->
isSet(
"types"))
135 const char *helptexts[] = {
136 "apps",
I18N_NOOP(
"Applications menu (.desktop files)"),
137 "autostart",
I18N_NOOP(
"Autostart directories"),
138 "cache",
I18N_NOOP(
"Cached information (e.g. favicons, web-pages)"),
139 "cgi",
I18N_NOOP(
"CGIs to run from kdehelp"),
140 "config",
I18N_NOOP(
"Configuration files"),
141 "data",
I18N_NOOP(
"Where applications store data"),
143 "exe",
I18N_NOOP(
"Executables in $prefix/bin"),
146 "kcfg",
I18N_NOOP(
"Configuration description files"),
148 "include",
I18N_NOOP(
"Includes/Headers"),
149 "locale",
I18N_NOOP(
"Translation files for KLocale"),
155 "servicetypes",
I18N_NOOP(
"Service types"),
156 "sound",
I18N_NOOP(
"Application sounds"),
159 "xdgdata-apps",
I18N_NOOP(
"XDG Application menu (.desktop files)"),
160 "xdgdata-dirs",
I18N_NOOP(
"XDG Menu descriptions (.directory files)"),
162 "xdgdata-pixmap",
I18N_NOOP(
"Legacy pixmaps"),
163 "xdgdata-mime",
I18N_NOOP(
"XDG Mime Types"),
164 "xdgconf-menu",
I18N_NOOP(
"XDG Menu layout (.menu files)"),
165 "xdgconf-autostart",
I18N_NOOP(
"XDG autostart directory"),
166 "tmp",
I18N_NOOP(
"Temporary files (specific for both current host and current user)"),
167 "socket",
I18N_NOOP(
"UNIX Sockets (specific for both current host and current user)"),
170 Q_FOREACH(
const QString &type, types)
173 while (helptexts[index] && type != QLatin1String(helptexts[index])) {
176 if (helptexts[index]) {
177 printf(
"%s - %s\n", helptexts[index],
i18n(helptexts[index+1]).toLocal8Bit().constData());
179 printf(
"%s",
i18n(
"%1 - unknown type\n", type).toLocal8Bit().constData());
189 if (!fileName.isEmpty())
192 if (!result.isEmpty())
193 printf(
"%s\n", result.toLocal8Bit().constData());
194 return result.isEmpty() ? 1 : 0;
205 if (type == QLatin1String(
"desktop"))
209 path = QDir::homePath() + QLatin1String(
"/Desktop");
210 path = QDir::cleanPath(path);
211 if (!path.endsWith(QLatin1Char(
'/')))
212 path.append(QLatin1Char(
'/'));
215 else if (type == QLatin1String(
"autostart"))
218 QString path = QDir::homePath() + QLatin1String(
"/Autostart/");
220 path = QDir::cleanPath( path );
221 if (!path.endsWith(QLatin1Char(
'/')))
222 path.append(QLatin1Char(QLatin1Char(
'/')));
226 else if (type == QLatin1String(
"document"))
230 path = QDir::homePath() + QLatin1String(
"/Documents");
231 path = QDir::cleanPath( path );
232 if (!path.endsWith(QLatin1Char(
'/')))
233 path.append(QLatin1Char(
'/'));
237 fprintf(stderr,
"%s",
i18n(
"%1 - unknown type of userpath\n", type).toLocal8Bit().data() );
247 if (args->
isSet(
"qt-prefix"))
249 printResult(QLibraryInfo::location(QLibraryInfo::PrefixPath));
252 if (args->
isSet(
"qt-binaries"))
254 printResult(QLibraryInfo::location(QLibraryInfo::BinariesPath));
257 if (args->
isSet(
"qt-libraries"))
259 printResult(QLibraryInfo::location(QLibraryInfo::LibrariesPath));
262 if (args->
isSet(
"qt-plugins"))
264 printResult(QLibraryInfo::location(QLibraryInfo::PluginsPath));
QString i18n(const char *text)
Returns a localized version of a string.
QString readPathEntry(const QString &pKey, const QString &aDefault) const
Reads a path.
static void addCmdLineOptions(const KCmdLineOptions &options, const KLocalizedString &name=KLocalizedString(), const QByteArray &id=QByteArray(), const QByteArray &afterId=QByteArray())
Add options to your application.
KCmdLineOptions & add(const QByteArray &name, const KLocalizedString &description=KLocalizedString(), const QByteArray &defaultValue=QByteArray())
Add command line option, by providing its name, description, and possibly a default value...
static QString readXdg(const char *type)
KLocalizedString ki18n(const char *msg)
Creates localized string from a given message.
static KCmdLineArgs * parsedArgs(const QByteArray &id=QByteArray())
Access parsed arguments.
static QString locate(const char *type, const QString &filename, const KComponentData &cData=KGlobal::mainComponent())
This function is just for convenience.
A class for command-line argument handling.
KStandardDirs * dirs()
Returns the application standard dirs object.
#define I18N_NOOP(x)
I18N_NOOP marks a string to be translated without translating it.
#define KDE_VERSION_STRING
Version of KDE as string, at compile time.
bool isSet(const QByteArray &option) const
Read out a boolean option or check for the presence of string option.
KSharedConfigPtr config()
Returns the general config object.
static void printResult(const QString &s)
This class is used to store information about a program.
A class for one specific group in a KConfig object.
int main(int argc, char **argv)
static void init(int argc, char **argv, const QByteArray &appname, const QByteArray &catalog, const KLocalizedString &programName, const QByteArray &version, const KLocalizedString &description=KLocalizedString(), StdCmdLineArgs stdargs=StdCmdLineArgs(CmdLineArgQt|CmdLineArgKDE))
Initialize class.
QString getOption(const QByteArray &option) const
Read out a string option.
QStringList allTypes() const
This function will return a list of all the types that KStandardDirs supports.
Class that holds command line options.