add more spacing
[personal-kdebase.git] / workspace / kwin / clients / kwmtheme / cli_installer / main.cpp
blob58f7f245be5d2a06f7bbbf80aefbc1c9170fe243
1 /********************************************************************
2 This program is free software; you can redistribute it and/or modify
3 it under the terms of the GNU General Public License as published by
4 the Free Software Foundation; either version 2 of the License, or
5 (at your option) any later version.
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 GNU General Public License for more details.
12 You should have received a copy of the GNU General Public License
13 along with this program. If not, see <http://www.gnu.org/licenses/>.
14 *********************************************************************/
16 #include <QFile>
17 #include <QDir>
18 #include <kapplication.h>
19 #include <ksimpleconfig.h>
20 #include <kglobal.h>
21 #include <kdebug.h>
22 #include <kstandarddirs.h>
23 #include <kcmdlineargs.h>
24 #include <klocale.h>
26 static const char description[] =
27 I18N_NOOP("Installs a KWM theme");
29 void copy(const QString &src, const QString &dest)
31 QFile copyInput(src);
32 QFile copyOutput(dest);
33 if(!copyInput.open(QIODevice::ReadOnly)){
34 kWarning(1212) << "Couldn't open " << src ;
35 return;
37 if(!copyOutput.open(QIODevice::WriteOnly)){
38 kWarning(1212) << "Couldn't open " << dest ;
39 copyInput.close();
40 return;
42 while(!copyInput.atEnd()){
43 copyOutput.putch(copyInput.getch());
45 copyInput.close();
46 copyOutput.close();
49 int main(int argc, char **argv)
51 KCmdLineArgs::init(argc, argv, "kwmtheme", description, "0.1");
53 KCmdLineOptions options;
54 options.add("+[file]", ki18n("Path to a theme config file"));
55 KCmdLineArgs::addCmdLineOptions( options );
56 KApplication app(argc, argv);
57 KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
58 if(!args->count()){
59 kWarning(1212) << "You need to specify the path to a theme config file!" ;
60 return(1);
63 QString srcStr = QString(args->arg(0));
64 QFile f(srcStr);
65 QString tmpStr;
67 if(!f.exists()){
68 kWarning(1212) << "Specified theme config file doesn't exist!" ;
69 return(2);
72 QStringList appDirs = KGlobal::dirs()->findDirs("data", "kwin");
73 QString localDirStr = *(appDirs.end());
74 if(localDirStr.isEmpty()){
75 localDirStr = KGlobal::dirs()->saveLocation("data", "kwin");
77 localDirStr += "/pics/";
78 if(!QFile::exists(localDirStr))
79 QDir().mkdir(localDirStr);
81 QFileInfo fi(f);
82 KSimpleConfig input(fi.absoluteFilePath());
83 srcStr = fi.dirPath(true) + '/';
84 KSharedConfig::Ptr output = KGlobal::config();
85 input.setGroup("Window Border");
86 output->setGroup("General");
88 tmpStr = input.readEntry("shapePixmapTop");
89 if(!tmpStr.isEmpty()){
90 copy(srcStr+tmpStr, localDirStr+tmpStr);
92 output->writeEntry("wm_top", tmpStr, KConfig::Normal|KConfig::Global);
93 tmpStr = input.readEntry("shapePixmapBottom");
94 if(!tmpStr.isEmpty())
95 copy(srcStr+tmpStr, localDirStr+tmpStr);
96 output->writeEntry("wm_bottom", tmpStr, KConfig::Normal|KConfig::Global);
97 tmpStr = input.readEntry("shapePixmapLeft");
98 if(!tmpStr.isEmpty())
99 copy(srcStr+tmpStr, localDirStr+tmpStr);
100 output->writeEntry("wm_left", tmpStr, KConfig::Normal|KConfig::Global);
101 tmpStr = input.readEntry("shapePixmapRight");
102 if(!tmpStr.isEmpty())
103 copy(srcStr+tmpStr, localDirStr+tmpStr);
104 output->writeEntry("wm_right", tmpStr, KConfig::Normal|KConfig::Global);
105 tmpStr = input.readEntry("shapePixmapTopLeft");
106 if(!tmpStr.isEmpty())
107 copy(srcStr+tmpStr, localDirStr+tmpStr);
108 output->writeEntry("wm_topleft", tmpStr, KConfig::Normal|KConfig::Global);
109 tmpStr = input.readEntry("shapePixmapTopRight");
110 if(!tmpStr.isEmpty())
111 copy(srcStr+tmpStr, localDirStr+tmpStr);
112 output->writeEntry("wm_topright", tmpStr, KConfig::Normal|KConfig::Global);
113 tmpStr = input.readEntry("shapePixmapBottomLeft");
114 if(!tmpStr.isEmpty())
115 copy(srcStr+tmpStr, localDirStr+tmpStr);
116 output->writeEntry("wm_bottomleft", tmpStr, KConfig::Normal|KConfig::Global);
117 tmpStr = input.readEntry("shapePixmapBottomRight");
118 if(!tmpStr.isEmpty())
119 copy(srcStr+tmpStr, localDirStr+tmpStr);
120 output->writeEntry("wm_bottomright", tmpStr, KConfig::Normal|KConfig::Global);
123 input.setGroup("Window Titlebar");
124 output->writeEntry("TitleAlignment", input.readEntry("TitleAlignment"), KConfig::Normal|KConfig::Global);
125 output->writeEntry("PixmapUnderTitleText", input.readEntry("PixmapUnderTitleText"), KConfig::Normal|KConfig::Global);
126 output->writeEntry("TitleFrameShaded", input.readEntry("TitleFrameShaded"), KConfig::Normal|KConfig::Global);
128 tmpStr = input.readEntry("MenuButton");
129 if(!tmpStr.isEmpty())
130 copy(srcStr+tmpStr, localDirStr+tmpStr);
131 output->writeEntry("menu", tmpStr, KConfig::Normal|KConfig::Global);
132 tmpStr = input.readEntry("PinUpButton");
133 if(!tmpStr.isEmpty())
134 copy(srcStr+tmpStr, localDirStr+tmpStr);
135 output->writeEntry("pinup", tmpStr, KConfig::Normal|KConfig::Global);
136 tmpStr = input.readEntry("PinDownButton");
137 if(!tmpStr.isEmpty())
138 copy(srcStr+tmpStr, localDirStr+tmpStr);
139 output->writeEntry("pindown", tmpStr, KConfig::Normal|KConfig::Global);
140 tmpStr = input.readEntry("CloseButton");
141 if(!tmpStr.isEmpty())
142 copy(srcStr+tmpStr, localDirStr+tmpStr);
143 output->writeEntry("close", tmpStr, KConfig::Normal|KConfig::Global);
144 tmpStr = input.readEntry("MaximizeButton");
145 if(!tmpStr.isEmpty())
146 copy(srcStr+tmpStr, localDirStr+tmpStr);
147 output->writeEntry("maximize", tmpStr, KConfig::Normal|KConfig::Global);
148 tmpStr = input.readEntry("MaximizeDownButton");
149 if(!tmpStr.isEmpty())
150 copy(srcStr+tmpStr, localDirStr+tmpStr);
151 output->writeEntry("maximizedown", tmpStr, KConfig::Normal|KConfig::Global);
152 tmpStr = input.readEntry("MinimizeButton");
153 if(!tmpStr.isEmpty())
154 copy(srcStr+tmpStr, localDirStr+tmpStr);
155 output->writeEntry("iconify", tmpStr, KConfig::Normal|KConfig::Global);
156 tmpStr = input.readEntry("TitlebarPixmapActive");
157 if(!tmpStr.isEmpty())
158 copy(srcStr+tmpStr, localDirStr+tmpStr);
159 output->writeEntry("TitlebarPixmapActive", tmpStr, KConfig::Normal|KConfig::Global);
160 tmpStr = input.readEntry("TitlebarPixmapInactive");
161 if(!tmpStr.isEmpty())
162 copy(srcStr+tmpStr, localDirStr+tmpStr);
163 output->writeEntry("TitlebarPixmapInactive", tmpStr, KConfig::Normal|KConfig::Global);
165 input.setGroup("Window Button Layout");
166 output->setGroup("Buttons");
167 output->writeEntry("ButtonA", input.readEntry("ButtonA"), KConfig::Normal|KConfig::Global);
168 output->writeEntry("ButtonB", input.readEntry("ButtonB"), KConfig::Normal|KConfig::Global);
169 output->writeEntry("ButtonC", input.readEntry("ButtonC"), KConfig::Normal|KConfig::Global);
170 output->writeEntry("ButtonD", input.readEntry("ButtonD"), KConfig::Normal|KConfig::Global);
171 output->writeEntry("ButtonE", input.readEntry("ButtonE"), KConfig::Normal|KConfig::Global);
172 output->writeEntry("ButtonF", input.readEntry("ButtonF"), KConfig::Normal|KConfig::Global);
174 output->sync();
176 return(0);