2 * KFontInst - KDE Font Installer
4 * Copyright 2003-2007 Craig Drummond <craig@kde.org>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; see the file COPYING. If not, write to
20 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
24 #include "Installer.h"
26 #include <QtCore/QFile>
27 #include <KDE/KCmdLineArgs>
28 #include <KDE/KAboutData>
29 #include <KDE/KApplication>
31 #include <KDE/KTempDir>
32 #include <KDE/KMessageBox>
33 #include <KDE/KStandardDirs>
34 #include <KDE/KIO/NetAccess>
35 #include "JobRunner.h"
36 #include "CreateParent.h"
41 int CInstaller::install(const QSet
<KUrl
> &urls
)
43 QSet
<KUrl
>::ConstIterator
it(urls
.begin()),
45 bool sysInstall(false);
46 CJobRunner
*jobRunner
=new CJobRunner(itsParent
);
50 switch(KMessageBox::questionYesNoCancel(itsParent
,
51 i18n("Do you wish to install the font(s) for personal use "
52 "(only available to you), or "
53 "system-wide (available to all users)?"),
54 i18n("Where to Install"), KGuiItem(i18n(KFI_KIO_FONTS_USER
)),
55 KGuiItem(i18n(KFI_KIO_FONTS_SYS
))))
58 if(!jobRunner
->getAdminPasswd(itsParent
))
61 case KMessageBox::Cancel
:
72 KUrl
local(KIO::NetAccess::mostLocalUrl(*it
, NULL
));
75 if(local
.isLocalFile())
77 QString
localFile(local
.path());
79 if(Misc::isPackage(localFile
))
84 if(zip
.open(QIODevice::ReadOnly
))
86 const KArchiveDirectory
*zipDir
=zip
.directory();
90 QStringList
fonts(zipDir
->entries());
94 QStringList::ConstIterator
it(fonts
.begin()),
99 itsTempDir
=new KTempDir(KStandardDirs::locateLocal("tmp", KFI_TMP_DIR_PREFIX
));
100 itsTempDir
->setAutoRemove(true);
105 const KArchiveEntry
*entry
=zipDir
->entry(*it
);
107 if(entry
&& entry
->isFile())
109 ((KArchiveFile
*)entry
)->copyTo(itsTempDir
->name());
111 QString
name(entry
->name());
114 // Cant install hidden fonts, therefore need to unhide 1st!
115 if(Misc::isHidden(name
))
117 ::rename(QFile::encodeName(itsTempDir
->name()+name
).data(),
118 QFile::encodeName(itsTempDir
->name()+name
.mid(1)).data());
121 instUrls
.insert(KUrl(itsTempDir
->name()+name
));
131 KUrl::List associatedUrls
;
133 CJobRunner::getAssociatedUrls(*it
, associatedUrls
, false, itsParent
);
134 instUrls
.insert(*it
);
136 KUrl::List::Iterator
aIt(associatedUrls
.begin()),
137 aEnd(associatedUrls
.end());
139 for(; aIt
!=aEnd
; ++aIt
)
140 instUrls
.insert(*aIt
);
146 CJobRunner::ItemList list
;
147 QSet
<KUrl
>::ConstIterator
it(instUrls
.begin()),
153 return jobRunner
->exec(CJobRunner::CMD_INSTALL
, list
,
155 ? KFI_KIO_FONTS_PROTOCOL
":/"
157 ? KFI_KIO_FONTS_PROTOCOL
":/"KFI_KIO_FONTS_SYS
"/"
158 : KFI_KIO_FONTS_PROTOCOL
":/"KFI_KIO_FONTS_USER
"/"));
164 CInstaller::~CInstaller()
171 static KAboutData
aboutData("kfontinst", 0, ki18n("Font Installer"), "1.0", ki18n("Simple font installer"),
172 KAboutData::License_GPL
, ki18n("(C) Craig Drummond, 2007"));
174 int main(int argc
, char **argv
)
177 // Do a quick check to see if we're just being run to configure X...
178 if(3==argc
&& 0==strcmp(argv
[1], "-x"))
180 QString
dir(KFI::Misc::dirSyntax(QFile::decodeName(argv
[2])));
182 return KFI::Misc::dExists(dir
) && KFI::Misc::configureForX11(dir
) ? 0 : -1;
186 KCmdLineArgs::init(argc
, argv
, &aboutData
);
188 KCmdLineOptions options
;
189 options
.add("x <folder>", ki18n("Configure folder for X11 - create fonts.dir and fonts.scale, plus remove hidden entries."
190 " (NOTE: Use this option on its own.)"));
191 options
.add("embed <winid>", ki18n("Makes the dialog transient for an X app specified by winid"));
192 options
.add("+[URL]", ki18n("URL to install"));
193 KCmdLineArgs::addCmdLineOptions(options
);
196 KCmdLineArgs
*args(KCmdLineArgs::parsedArgs());
198 for(int i
=0; i
< args
->count(); i
++)
199 urls
.insert(args
->url(i
));
203 KLocale::setMainCatalog(KFI_CATALOGUE
);
206 QString
opt(args
->getOption("embed"));
207 KFI::CInstaller
inst(createParent(opt
.size() ? opt
.toInt(0, 16) : 0));
209 return inst
.install(urls
);