3 * This file is part of the KDE libraries
5 * Copyright (c) 2008 David Jarvie <djarvie@kde.org>
6 * Copyright (c) 2006-2007 Christian Ehrlicher <Ch.Ehrlicher@gmx.de>
7 * Copyright (c) 2000-2007 Stephan Kulow <coolo@kde.org>
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Library General Public
11 * License as published by the Free Software Foundation; either
12 * version 2 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Library General Public License for more details.
19 * You should have received a copy of the GNU Library General Public License
20 * along with this library; see the file COPYING.LIB. If not, write to
21 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22 * Boston, MA 02110-1301, USA.
26 #include <kcmdlineargs.h>
28 #include <kcomponentdata.h>
29 #include <kstandarddirs.h>
34 #include <kaboutdata.h>
35 #include <kdeversion.h>
37 #include <QtCore/QLibraryInfo>
38 #include <QtCore/QCoreApplication>
40 #include <config-prefix.h>
41 #include <kconfiggroup.h>
42 #include <kkernel_win.h>
45 static void printResult(const QString
&s
)
50 QString path
= QDir::convertSeparators( s
);
51 printf("%s\n", path
.toLocal8Bit().constData());
55 int main(int argc
, char **argv
)
57 QCoreApplication
app(argc
, argv
);
58 KAboutData
about("kde4-config", "kdelibs4", ki18n("kde4-config"), "1.0",
59 ki18n("A little program to output installation paths"),
60 KAboutData::License_GPL
,
61 ki18n("(C) 2000 Stephan Kulow"));
62 KCmdLineArgs::init( argc
, argv
, &about
);
64 KCmdLineOptions options
;
65 options
.add("expandvars", ki18n("Left for legacy support"));
66 options
.add("prefix", ki18n("Compiled in prefix for KDE libraries"));
67 options
.add("exec-prefix", ki18n("Compiled in exec_prefix for KDE libraries"));
68 options
.add("libsuffix", ki18n("Compiled in library path suffix"));
69 options
.add("localprefix", ki18n("Prefix in $HOME used to write files"));
70 options
.add("version", ki18n("Compiled in version string for KDE libraries"));
71 options
.add("types", ki18n("Available KDE resource types"));
72 options
.add("path type", ki18n("Search path for resource type"));
73 options
.add("locate filename", ki18n("Find filename inside the resource type given to --path"));
74 options
.add("userpath type", ki18n("User path: desktop|autostart|document"));
75 options
.add("install type", ki18n("Prefix to install resource files to"));
76 options
.add("qt-prefix", ki18n("Installation prefix for Qt"));
77 options
.add("qt-binaries", ki18n("Location of installed Qt binaries"));
78 options
.add("qt-libraries", ki18n("Location of installed Qt libraries"));
79 options
.add("qt-plugins", ki18n("Location of installed Qt plugins"));
80 KCmdLineArgs::addCmdLineOptions( options
); // Add my own options.
82 KComponentData
a(&about
);
83 (void)KGlobal::dirs(); // trigger the creation
84 (void)KGlobal::config();
86 // Get application specific arguments
87 KCmdLineArgs
*args
= KCmdLineArgs::parsedArgs();
89 if (args
->isSet("prefix"))
95 if (args
->isSet("exec-prefix"))
97 printResult(EXEC_INSTALL_PREFIX
);
101 if (args
->isSet("libsuffix"))
103 QString
tmp(KDELIBSUFF
);
105 printResult(tmp
.toLocal8Bit());
109 if (args
->isSet("localprefix"))
111 printResult(KGlobal::dirs()->localkdedir());
115 if (args
->isSet("version"))
117 printf("%s\n", KDE_VERSION_STRING
);
121 if (args
->isSet("types"))
123 QStringList types
= KGlobal::dirs()->allTypes();
125 const char *helptexts
[] = {
126 "apps", I18N_NOOP("Applications menu (.desktop files)"),
127 "cache", I18N_NOOP("Cached information (e.g. favicons, web-pages)"),
128 "cgi", I18N_NOOP("CGIs to run from kdehelp"),
129 "config", I18N_NOOP("Configuration files"),
130 "data", I18N_NOOP("Where applications store data"),
131 "emoticons", I18N_NOOP("Emoticons"),
132 "exe", I18N_NOOP("Executables in $prefix/bin"),
133 "html", I18N_NOOP("HTML documentation"),
134 "icon", I18N_NOOP("Icons"),
135 "kcfg", I18N_NOOP("Configuration description files"),
136 "lib", I18N_NOOP("Libraries"),
137 "include", I18N_NOOP("Includes/Headers"),
138 "locale", I18N_NOOP("Translation files for KLocale"),
139 "mime", I18N_NOOP("Mime types"),
140 "module", I18N_NOOP("Loadable modules"),
141 "pixmap", I18N_NOOP("Legacy pixmaps"),
142 "qtplugins", I18N_NOOP("Qt plugins"),
143 "services", I18N_NOOP("Services"),
144 "servicetypes", I18N_NOOP("Service types"),
145 "sound", I18N_NOOP("Application sounds"),
146 "templates", I18N_NOOP("Templates"),
147 "wallpaper", I18N_NOOP("Wallpapers"),
148 "xdgdata-apps", I18N_NOOP("XDG Application menu (.desktop files)"),
149 "xdgdata-dirs", I18N_NOOP("XDG Menu descriptions (.directory files)"),
150 "xdgdata-icon", I18N_NOOP("XDG Icons"),
151 "xdgdata-pixmap", I18N_NOOP("Legacy pixmaps"),
152 "xdgdata-mime", I18N_NOOP("XDG Mime Types"),
153 "xdgconf-menu", I18N_NOOP("XDG Menu layout (.menu files)"),
154 "tmp", I18N_NOOP("Temporary files (specific for both current host and current user)"),
155 "socket", I18N_NOOP("UNIX Sockets (specific for both current host and current user)"),
158 Q_FOREACH(const QString
&type
, types
)
161 while (helptexts
[index
] && type
!= helptexts
[index
]) {
164 if (helptexts
[index
]) {
165 printf("%s - %s\n", helptexts
[index
], i18n(helptexts
[index
+1]).toLocal8Bit().data());
167 printf("%s", i18n("%1 - unknown type\n", type
).toLocal8Bit().data());
173 QString type
= args
->getOption("path");
176 QString fileName
= args
->getOption("locate");
177 if (!fileName
.isEmpty())
179 QString result
= KStandardDirs::locate(type
.toLatin1(), fileName
);
180 if (!result
.isEmpty())
181 printf("%s\n", result
.toLocal8Bit().constData());
182 return result
.isEmpty() ? 1 : 0;
185 printResult(KGlobal::dirs()->resourceDirs(type
.toLatin1()).join(QString(KPATH_SEPARATOR
)));
189 type
= args
->getOption("userpath");
192 //code duplicated with KGlobalSettings::initPath()
193 if ( type
== "desktop" )
195 KConfigGroup
g( KGlobal::config(), "Paths" );
196 QString path
=QDir::homePath() + "/Desktop/";
197 path
=g
.readPathEntry( "Desktop", path
);
198 path
=QDir::cleanPath( path
);
199 if ( !path
.endsWith('/') )
200 path
.append(QLatin1Char('/'));
203 else if ( type
== "autostart" )
205 KConfigGroup
g( KGlobal::config(), "Paths" );
206 QString path
=QDir::homePath() + "/Autostart/";
207 path
=g
.readPathEntry( "Autostart", path
);
208 path
=QDir::cleanPath( path
);
209 if ( !path
.endsWith('/') )
210 path
.append(QLatin1Char('/'));
214 else if ( type
== "document" )
216 KConfigGroup
g( KGlobal::config(), "Paths" );
218 QString path
=getWin32ShellFoldersPath(QLatin1String("Personal"));
220 QString path
=QDir::homePath();
222 path
=g
.readPathEntry( "Desktop", path
);
223 path
=QDir::cleanPath( path
);
224 if ( !path
.endsWith('/') )
225 path
.append(QLatin1Char('/'));
229 fprintf(stderr
, "%s", i18n("%1 - unknown type of userpath\n", type
).toLocal8Bit().data() );
233 type
= args
->getOption("install");
236 printResult( KGlobal::dirs()->installPath(type
.toLocal8Bit()) );
239 if (args
->isSet("qt-prefix"))
241 printResult(QLibraryInfo::location(QLibraryInfo::PrefixPath
));
244 if (args
->isSet("qt-binaries"))
246 printResult(QLibraryInfo::location(QLibraryInfo::BinariesPath
));
249 if (args
->isSet("qt-libraries"))
251 printResult(QLibraryInfo::location(QLibraryInfo::LibrariesPath
));
254 if (args
->isSet("qt-plugins"))
256 printResult(QLibraryInfo::location(QLibraryInfo::PluginsPath
));