argdox for stdockConvert; locale detection
[xcurtheme.git] / tools / stdockConvert / main.cpp
blob4403dfcca059e973fae485fcd4dadb923781b2f0
1 /* coded by Ketmar // Vampire Avalon (psyc://ketmar.no-ip.org/~Ketmar)
3 * This program is free software. It comes without any warranty, to
4 * the extent permitted by applicable law. You can redistribute it
5 * and/or modify it under the terms of the Do What The Fuck You Want
6 * To Public License, Version 2, as published by Sam Hocevar. See
7 * http://sam.zoy.org/wtfpl/COPYING for more details.
8 */
9 #include <QDebug>
10 //#include <QtCore>
12 #include "main.h"
14 #include <QApplication>
15 #include <QStringList>
16 #include <QTextCodec>
17 #include <QTextStream>
19 #include <QDir>
22 #include "xcrimg.h"
23 #include "xcrxcur.h"
24 #include "xcrtheme.h"
25 #include "xcrthemefx.h"
26 #include "xcrthemexp.h"
29 ///////////////////////////////////////////////////////////////////////////////
30 static XCursorTheme *loadTheme (const QString &fname) {
31 XCursorTheme *ct = 0;
33 if (fname.endsWith(".CursorFX", Qt::CaseInsensitive)) {
34 ct = new XCursorThemeFX(fname);
35 } else if (fname.endsWith(".CurXPTheme", Qt::CaseInsensitive)) {
36 ct = new XCursorThemeXP(fname);
39 if (ct && !ct->count()) { delete ct; ct = 0; }
40 return ct;
44 static void fixTextCodec () {
45 QTextCodec *kc;
46 const char *ll = getenv("LANG");
48 if (!ll || !ll[0]) ll = getenv("LC_CTYPE");
49 if (ll && ll[0] && (strcasestr(ll, "utf-8") || strcasestr(ll, "utf8"))) return;
50 kc = QTextCodec::codecForName("koi8-r");
51 if (!kc) return;
52 QTextCodec::setCodecForCStrings(kc);
53 QTextCodec::setCodecForLocale(kc);
57 ///////////////////////////////////////////////////////////////////////////////
58 int main (int argc, char *argv[]) {
59 fixTextCodec();
61 QApplication app(argc, argv);
63 bool doPack = false, doRemove = false;
64 int argNo = 1;
66 while (argNo < argc) {
67 if (!strcmp(argv[argNo], "-p")) doPack = true;
68 else if (!strcmp(argv[argNo], "-P")) doPack = doRemove = true;
69 else break;
70 ++argNo;
73 if (argNo >= argc) {
74 fprintf(stderr,
75 "usage: %s [-p] [-P] file [file...]\n"
76 " -p: pack converted theme\n"
77 " -P: pack converted theme and remove source\n"
78 "",
79 argv[0]);
80 return 1;
83 QStringList flist;
85 while (argNo < argc) {
86 QString fn(argv[argNo++]);
87 QFileInfo fi(fn);
88 if (fi.exists() && fi.isReadable()) flist << fn;
90 flist.removeDuplicates();
92 foreach (const QString &fn, flist) {
93 XCursorTheme *ct = loadTheme(fn);
94 if (!ct) continue;
96 //FIXME: use /tmp ?
97 QString outFName(fn);
98 outFName.truncate(outFName.lastIndexOf('.'));
100 // write theme
101 QDir dd(".");
102 dd.mkdir(outFName);
103 if (dd.cd(outFName)) {
104 ct->writeToDir(dd);
105 dd.cd("..");
106 // pack theme?
107 if (doPack) {
108 if (!packXCursorTheme(outFName+".tgz", dd, outFName, doRemove)) {
109 fprintf(stderr, "ERROR: can't pack theme %s!\n", outFName.toLocal8Bit().constData());
110 } else {
111 printf("theme %s.tgz sucessfully created.\n", outFName.toLocal8Bit().constData());
115 delete ct;
118 return 0;