kwin Library API Documentation

main.cpp

00001 #include <qfile.h>
00002 #include <qdir.h>
00003 #include <kapplication.h>
00004 #include <ksimpleconfig.h>
00005 #include <kglobal.h>
00006 #include <kdebug.h>
00007 #include <kstandarddirs.h>
00008 #include <kcmdlineargs.h>
00009 #include <klocale.h>
00010 
00011 static const char *description =
00012         I18N_NOOP("Installs a KWM theme");
00013 
00014 static KCmdLineOptions options[] =
00015 {
00016     { "+[file]", I18N_NOOP("Path to a theme config file"), 0 },
00017     KCmdLineLastOption
00018 };
00019 
00020 void copy(const QString &src, const QString &dest)
00021 {
00022     QFile copyInput(src);
00023     QFile copyOutput(dest);
00024     if(!copyInput.open(IO_ReadOnly)){
00025         kdWarning() << "Couldn't open " << src << endl;
00026         return;
00027     }
00028     if(!copyOutput.open(IO_WriteOnly)){
00029         kdWarning() << "Couldn't open " << dest << endl;
00030         copyInput.close();
00031         return;
00032     }
00033     while(!copyInput.atEnd()){
00034         copyOutput.putch(copyInput.getch());
00035     }
00036     copyInput.close();
00037     copyOutput.close();
00038 }
00039 
00040 int main(int argc, char **argv)
00041 {
00042     KCmdLineArgs::init(argc, argv, "kwmtheme", description, "0.1");
00043     KCmdLineArgs::addCmdLineOptions( options );
00044     KApplication app(argc, argv);
00045     KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
00046     if(!args->count()){
00047         kdWarning() << "You need to specify the path to a theme config file!" << endl;
00048         return(1);
00049     }
00050 
00051     QString srcStr = QString(QFile::decodeName(args->arg(0)));
00052     QFile f(srcStr);
00053     QString tmpStr;
00054 
00055     if(!f.exists()){
00056         kdWarning() << "Specified theme config file doesn't exist!" << endl;
00057         return(2);
00058     }
00059 
00060     QStringList appDirs = KGlobal::dirs()->findDirs("data", "kwin");
00061     QString localDirStr = *(appDirs.end());
00062     if(localDirStr.isEmpty()){
00063         localDirStr = KGlobal::dirs()->saveLocation("data", "kwin");
00064     }
00065     localDirStr += "/pics/";
00066     if(!QFile::exists(localDirStr))
00067         QDir().mkdir(localDirStr);
00068 
00069     QFileInfo fi(f);
00070     KSimpleConfig input(fi.absFilePath());
00071     srcStr = fi.dirPath(true) + "/";
00072     KConfig *output = KGlobal::config();
00073     input.setGroup("Window Border");
00074     output->setGroup("General");
00075 
00076     tmpStr = input.readEntry("shapePixmapTop");
00077     if(!tmpStr.isEmpty()){
00078         copy(srcStr+tmpStr, localDirStr+tmpStr);
00079     }
00080     output->writeEntry("wm_top", tmpStr, true, true);
00081     tmpStr = input.readEntry("shapePixmapBottom");
00082     if(!tmpStr.isEmpty())
00083         copy(srcStr+tmpStr, localDirStr+tmpStr);
00084     output->writeEntry("wm_bottom", tmpStr, true, true);
00085     tmpStr = input.readEntry("shapePixmapLeft");
00086     if(!tmpStr.isEmpty())
00087         copy(srcStr+tmpStr, localDirStr+tmpStr);
00088     output->writeEntry("wm_left", tmpStr, true, true);
00089     tmpStr = input.readEntry("shapePixmapRight");
00090     if(!tmpStr.isEmpty())
00091         copy(srcStr+tmpStr, localDirStr+tmpStr);
00092     output->writeEntry("wm_right", tmpStr, true, true);
00093     tmpStr = input.readEntry("shapePixmapTopLeft");
00094     if(!tmpStr.isEmpty())
00095         copy(srcStr+tmpStr, localDirStr+tmpStr);
00096     output->writeEntry("wm_topleft", tmpStr, true, true);
00097     tmpStr = input.readEntry("shapePixmapTopRight");
00098     if(!tmpStr.isEmpty())
00099         copy(srcStr+tmpStr, localDirStr+tmpStr);
00100     output->writeEntry("wm_topright", tmpStr, true, true);
00101     tmpStr = input.readEntry("shapePixmapBottomLeft");
00102     if(!tmpStr.isEmpty())
00103         copy(srcStr+tmpStr, localDirStr+tmpStr);
00104     output->writeEntry("wm_bottomleft", tmpStr, true, true);
00105     tmpStr = input.readEntry("shapePixmapBottomRight");
00106     if(!tmpStr.isEmpty())
00107         copy(srcStr+tmpStr, localDirStr+tmpStr);
00108     output->writeEntry("wm_bottomright", tmpStr, true, true);
00109 
00110 
00111     input.setGroup("Window Titlebar");
00112     output->writeEntry("TitleAlignment", input.readEntry("TitleAlignment"), true, true);
00113     output->writeEntry("PixmapUnderTitleText", input.readEntry("PixmapUnderTitleText"), true, true);
00114     output->writeEntry("TitleFrameShaded", input.readEntry("TitleFrameShaded"), true, true);
00115 
00116     tmpStr = input.readEntry("MenuButton");
00117     if(!tmpStr.isEmpty())
00118         copy(srcStr+tmpStr, localDirStr+tmpStr);
00119     output->writeEntry("menu", tmpStr, true, true);
00120     tmpStr = input.readEntry("PinUpButton");
00121     if(!tmpStr.isEmpty())
00122         copy(srcStr+tmpStr, localDirStr+tmpStr);
00123     output->writeEntry("pinup", tmpStr, true, true);
00124     tmpStr = input.readEntry("PinDownButton");
00125     if(!tmpStr.isEmpty())
00126         copy(srcStr+tmpStr, localDirStr+tmpStr);
00127     output->writeEntry("pindown", tmpStr, true, true);
00128     tmpStr = input.readEntry("CloseButton");
00129     if(!tmpStr.isEmpty())
00130         copy(srcStr+tmpStr, localDirStr+tmpStr);
00131     output->writeEntry("close", tmpStr, true, true);
00132     tmpStr = input.readEntry("MaximizeButton");
00133     if(!tmpStr.isEmpty())
00134         copy(srcStr+tmpStr, localDirStr+tmpStr);
00135     output->writeEntry("maximize", tmpStr, true, true);
00136     tmpStr = input.readEntry("MaximizeDownButton");
00137     if(!tmpStr.isEmpty())
00138         copy(srcStr+tmpStr, localDirStr+tmpStr);
00139     output->writeEntry("maximizedown", tmpStr, true, true);
00140     tmpStr = input.readEntry("MinimizeButton");
00141     if(!tmpStr.isEmpty())
00142         copy(srcStr+tmpStr, localDirStr+tmpStr);
00143     output->writeEntry("iconify", tmpStr, true, true);
00144     tmpStr = input.readEntry("TitlebarPixmapActive");
00145     if(!tmpStr.isEmpty())
00146         copy(srcStr+tmpStr, localDirStr+tmpStr);
00147     output->writeEntry("TitlebarPixmapActive", tmpStr, true, true);
00148     tmpStr = input.readEntry("TitlebarPixmapInactive");
00149     if(!tmpStr.isEmpty())
00150         copy(srcStr+tmpStr, localDirStr+tmpStr);
00151     output->writeEntry("TitlebarPixmapInactive", tmpStr, true, true);
00152 
00153     input.setGroup("Window Button Layout");
00154     output->setGroup("Buttons");
00155     output->writeEntry("ButtonA", input.readEntry("ButtonA"), true, true);
00156     output->writeEntry("ButtonB", input.readEntry("ButtonB"), true, true);
00157     output->writeEntry("ButtonC", input.readEntry("ButtonC"), true, true);
00158     output->writeEntry("ButtonD", input.readEntry("ButtonD"), true, true);
00159     output->writeEntry("ButtonE", input.readEntry("ButtonE"), true, true);
00160     output->writeEntry("ButtonF", input.readEntry("ButtonF"), true, true);
00161 
00162     output->sync();
00163 
00164     return(0);
00165 }
00166 
KDE Logo
This file is part of the documentation for kwin Library Version 3.2.1.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Fri Mar 5 04:41:14 2004 by doxygen 1.3.6-20040222 written by Dimitri van Heesch, © 1997-2003