3 #include <kcmdlineargs.h>
5 #include <kcomponentdata.h>
6 #include <kstandarddirs.h>
11 #include <kaboutdata.h>
12 #include <kdeversion.h>
15 #include <kconfiggroup.h>
18 #include <win32_utils.h>
21 static const char *description
= I18N_NOOP("A little program to output installation paths");
23 static KCmdLineOptions options
[] =
25 { "expandvars", I18N_NOOP("expand ${prefix} and ${exec_prefix} in output"), 0 },
26 { "prefix", I18N_NOOP("Compiled in prefix for KDE libraries"), 0 },
27 { "exec-prefix", I18N_NOOP("Compiled in exec_prefix for KDE libraries"), 0 },
28 { "libsuffix", I18N_NOOP("Compiled in library path suffix"), 0 },
29 { "localprefix", I18N_NOOP("Prefix in $HOME used to write files"), 0},
30 { "version", I18N_NOOP("Compiled in version string for KDE libraries"), 0 },
31 { "types", I18N_NOOP("Available KDE resource types"), 0 },
32 { "path type", I18N_NOOP("Search path for resource type"), 0 },
33 { "locate filename", I18N_NOOP("Find filename inside the resource type given to --path"), 0},
34 { "userpath type", I18N_NOOP("User path: desktop|autostart|document"), 0 },
35 { "install type", I18N_NOOP("Prefix to install resource files to"), 0},
39 bool _expandvars
= false;
41 QString
expandvars(const char *_input
)
43 QString result
= QLatin1String(_input
);
48 int index
= result
.indexOf("${prefix}");
50 result
= result
.replace(index
, 9, "@prefix@");
53 index
= result
.indexOf("$(prefix)");
55 result
= result
.replace(index
, 9, "@prefix@");
58 index
= result
.indexOf("${datadir}");
60 result
= result
.replace(index
, 10, "@datadir@");
63 index
= result
.indexOf("$(datadir)");
65 result
= result
.replace(index
, 10, "@datadir@");
68 index
= result
.indexOf("${exec_prefix}");
70 result
= result
.replace(index
, 14, "@exec_prefix@");
73 index
= result
.indexOf("$(exec_prefix)");
75 result
= result
.replace(index
, 14, "@exec_prefix@");
78 index
= result
.indexOf("${libdir}");
80 result
= result
.replace(index
, 9, "@libdir@");
83 index
= result
.indexOf("$(libdir)");
85 result
= result
.replace(index
, 9, "@libdir@");
88 index
= result
.indexOf("${includedir}");
90 result
= result
.replace(index
, 20, "@includedir@");
93 index
= result
.indexOf("$(includedir)");
95 result
= result
.replace(index
, 20, "@includedir@");
98 index
= result
.indexOf("${sysconfdir}");
100 result
= result
.replace(index
, 13, "@sysconfdir@");
103 index
= result
.indexOf("$(sysconfdir)");
105 result
= result
.replace(index
, 13, "@sysconfdir@");
109 return expandvars(result
.toLatin1());
114 void printResult(const QString
&s
)
119 QString path
= QDir::convertSeparators( s
);
120 printf("%s\n", path
.toLocal8Bit().constData());
124 int main(int argc
, char **argv
)
126 KLocale::setMainCatalog("kdelibs");
127 KAboutData
about("kde4-config", "kde4-config", "1.0", description
, KAboutData::License_GPL
, "(C) 2000 Stephan Kulow");
128 KCmdLineArgs::init( argc
, argv
, &about
);
130 KCmdLineArgs::addCmdLineOptions( options
); // Add my own options.
132 KComponentData
a("kde4-config");
133 (void)KGlobal::dirs(); // trigger the creation
134 (void)KGlobal::config();
136 // Get application specific arguments
137 KCmdLineArgs
*args
= KCmdLineArgs::parsedArgs();
139 _expandvars
= args
->isSet("expandvars");
141 if (args
->isSet("prefix"))
143 printResult(expandvars("@prefix@"));
147 if (args
->isSet("exec-prefix"))
149 printResult(expandvars("@exec_prefix@"));
153 if (args
->isSet("libsuffix"))
155 QString
tmp(KDELIBSUFF
);
157 printResult(expandvars(tmp
.toLocal8Bit()));
161 if (args
->isSet("localprefix"))
163 printResult(KGlobal::dirs()->localkdedir());
167 if (args
->isSet("version"))
169 printf("%s\n", KDE_VERSION_STRING
);
173 if (args
->isSet("types"))
175 QStringList types
= KGlobal::dirs()->allTypes();
177 const char *helptexts
[] = {
178 "apps", I18N_NOOP("Applications menu (.desktop files)"),
179 "cgi", I18N_NOOP("CGIs to run from kdehelp"),
180 "config", I18N_NOOP("Configuration files"),
181 "data", I18N_NOOP("Where applications store data"),
182 "emoticons", I18N_NOOP("Emoticons"),
183 "exe", I18N_NOOP("Executables in $prefix/bin"),
184 "html", I18N_NOOP("HTML documentation"),
185 "icon", I18N_NOOP("Icons"),
186 "kcfg", I18N_NOOP("Configuration description files"),
187 "lib", I18N_NOOP("Libraries"),
188 "include", I18N_NOOP("Includes/Headers"),
189 "locale", I18N_NOOP("Translation files for KLocale"),
190 "mime", I18N_NOOP("Mime types"),
191 "module", I18N_NOOP("Loadable modules"),
192 "pixmap", I18N_NOOP("Legacy pixmaps"),
193 "qtplugins", I18N_NOOP("Qt plugins"),
194 "services", I18N_NOOP("Services"),
195 "servicetypes", I18N_NOOP("Service types"),
196 "sound", I18N_NOOP("Application sounds"),
197 "templates", I18N_NOOP("Templates"),
198 "wallpaper", I18N_NOOP("Wallpapers"),
199 "xdgdata-apps", I18N_NOOP("XDG Application menu (.desktop files)"),
200 "xdgdata-dirs", I18N_NOOP("XDG Menu descriptions (.directory files)"),
201 "xdgdata-icon", I18N_NOOP("XDG Icons"),
202 "xdgdata-pixmaps", I18N_NOOP("Legacy pixmaps"),
203 "xdgdata-mime", I18N_NOOP("XDG Mime Types"),
204 "xdgconf-menu", I18N_NOOP("XDG Menu layout (.menu files)"),
205 "tmp", I18N_NOOP("Temporary files (specific for both current host and current user)"),
206 "socket", I18N_NOOP("UNIX Sockets (specific for both current host and current user)"),
209 for (QStringList::ConstIterator it
= types
.begin(); it
!= types
.end(); ++it
)
212 while (helptexts
[index
] && *it
!= helptexts
[index
]) {
215 if (helptexts
[index
]) {
216 printf("%s - %s\n", helptexts
[index
], i18n(helptexts
[index
+1]).toLocal8Bit().data());
218 printf("%s", i18n("%1 - unknown type\n", *it
).toLocal8Bit().data());
224 QString type
= args
->getOption("path");
227 QString fileName
= args
->getOption("locate");
228 if (!fileName
.isEmpty())
230 QString result
= KStandardDirs::locate(type
.toLatin1(), fileName
);
231 if (!result
.isEmpty())
232 printf("%s\n", result
.toLocal8Bit().constData());
233 return result
.isEmpty() ? 1 : 0;
236 printResult(KGlobal::dirs()->resourceDirs(type
.toLatin1()).join(QString(KPATH_SEPARATOR
)));
240 type
= args
->getOption("userpath");
243 //code duplicated with KGlobalSettings::initPath()
244 if ( type
== "desktop" )
246 KConfigGroup
g( KGlobal::config(), "Paths" );
247 QString path
=QDir::homePath() + "/Desktop/";
248 path
=g
.readPathEntry( "Desktop", path
);
249 path
=QDir::cleanPath( path
);
250 if ( !path
.endsWith("/") )
251 path
.append(QLatin1Char('/'));
254 else if ( type
== "autostart" )
256 KConfigGroup
g( KGlobal::config(), "Paths" );
257 QString path
=QDir::homePath() + "/Autostart/";
258 path
=g
.readPathEntry( "Autostart", path
);
259 path
=QDir::cleanPath( path
);
260 if ( !path
.endsWith("/") )
261 path
.append(QLatin1Char('/'));
265 else if ( type
== "document" )
267 KConfigGroup
g( KGlobal::config(), "Paths" );
269 QString path
=getWin32ShellFoldersPath("Personal");
271 QString path
=QDir::homePath();
273 path
=g
.readPathEntry( "Desktop", path
);
274 path
=QDir::cleanPath( path
);
275 if ( !path
.endsWith("/") )
276 path
.append(QLatin1Char('/'));
280 fprintf(stderr
, "%s", i18n("%1 - unknown type of userpath\n", type
).toLocal8Bit().data() );
284 type
= args
->getOption("install");
287 const char *installprefixes
[] = {
288 "apps", "@kde_appsdir@",
289 "config", "@kde_confdir@",
290 "kcfg", "@kde_kcfgdir@",
291 "data", "@kde_datadir@",
292 "exe", "@kde_bindir@",
293 "html", "@kde_htmldir@",
294 "icon", "@kde_icondir@",
296 "module", "@kde_moduledir@",
297 "qtplugins", "@kde_moduledir@/plugins",
298 "locale", "@kde_locale@",
299 "mime", "@kde_mimedir@",
300 "services", "@kde_servicesdir@",
301 "servicetypes", "@kde_servicetypesdir@",
302 "sound", "@kde_sounddir@",
303 "templates", "@kde_templatesdir@",
304 "wallpaper", "@kde_wallpaperdir@",
305 "xdgconf-menu", "@xdg_menudir@",
306 "xdgdata-apps", "@xdg_appsdir@",
307 "xdgdata-dirs", "@xdg_directorydir@",
308 "include", "@includedir@",
312 while (installprefixes
[index
] && type
!= installprefixes
[index
]) {
315 if (installprefixes
[index
]) {
316 printResult(expandvars(installprefixes
[index
+1]));
318 printResult("NONE"); // no i18n here as for scripts