universal theme converter added
[xcurtheme.git] / tools / stdockConvert / main.cpp
blob1ee9acc64da00a0c62f7e692735b473bd0071370
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 ///////////////////////////////////////////////////////////////////////////////
45 int main (int argc, char *argv[]) {
46 QTextCodec::setCodecForCStrings(QTextCodec::codecForName("koi8-r"));
47 QTextCodec::setCodecForLocale(QTextCodec::codecForName("koi8-r"));
49 QApplication app(argc, argv);
51 bool doPack = false, doRemove = false;
52 int argNo = 1;
53 while (argNo < argc) {
54 if (!strcmp(argv[argNo], "-p")) doPack = true;
55 else if (!strcmp(argv[argNo], "-P")) doPack = doRemove = true;
56 else break;
57 argNo++;
60 if (argNo >= argc) {
61 fprintf(stderr, "usage: %s [-p] [-P] file [file...]\n", argv[0]);
62 return 1;
65 QStringList flist;
67 while (argNo < argc) {
68 QString fn(argv[argNo++]);
69 QFileInfo fi(fn);
70 if (fi.exists() && fi.isReadable()) flist << fn;
72 flist.removeDuplicates();
74 foreach (const QString &fn, flist) {
75 XCursorTheme *ct = loadTheme(fn);
76 if (!ct) continue;
78 //FIXME: use /tmp ?
79 QString outFName(fn);
80 outFName.truncate(outFName.lastIndexOf('.'));
82 // write theme
83 QDir dd(".");
84 dd.mkdir(outFName);
85 if (dd.cd(outFName)) {
86 ct->writeToDir(dd);
87 dd.cd("..");
88 // pack theme?
89 if (doPack) {
90 if (!packXCursorTheme(outFName+".tgz", dd, outFName, doRemove)) {
91 fprintf(stderr, "ERROR: can't pack theme %s!\n", outFName.toLocal8Bit().constData());
92 } else {
93 printf("theme %s.tgz sucessfully created.\n", outFName.toLocal8Bit().constData());
97 delete ct;
100 return 0;