add more spacing
[personal-kdebase.git] / workspace / kcontrol / kfontinst / kcmfontinst / KCmFontInst.cpp
blob7a7e4f798329e23e4f98ce6db3724efef7dbf24d
1 /*
2 * KFontInst - KDE Font Installer
4 * Copyright 2003-2007 Craig Drummond <craig@kde.org>
6 * ----
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 "KCmFontInst.h"
25 #include "KfiConstants.h"
26 #include "PrintDialog.h"
27 #include "FcEngine.h"
28 #include "FontPreview.h"
29 #include "Misc.h"
30 #include "FontList.h"
31 #include "DuplicatesDialog.h"
32 #include "PreviewSelectAction.h"
33 #include "FontFilter.h"
34 #include <QtGui/QGridLayout>
35 #include <QtGui/QBoxLayout>
36 #include <QtGui/QLabel>
37 #include <QtGui/QSplitter>
38 #include <QtGui/QProgressBar>
39 #include <QtCore/QCoreApplication>
40 #include <QtGui/QApplication>
41 #include <QtCore/QTextStream>
42 #include <QtGui/QComboBox>
43 #include <QtCore/QProcess>
44 #include <QtGui/QPainter>
45 #include <KDE/KAboutData>
46 #include <KDE/KToolBar>
47 #include <KDE/KFileDialog>
48 #include <KDE/KMessageBox>
49 #include <KDE/KIO/Job>
50 #include <KDE/KIO/NetAccess>
51 #include <KDE/KPushButton>
52 #include <KDE/KGuiItem>
53 #include <KDE/KInputDialog>
54 #include <KDE/KIconLoader>
55 #include <KDE/KProgressDialog>
56 #include <KDE/KZip>
57 #include <KDE/KTempDir>
58 #include <KDE/KTemporaryFile>
59 #include <KDE/KIcon>
60 #include <KDE/KActionMenu>
61 #include <KDE/KToggleAction>
62 #include <KDE/KStandardDirs>
63 #include <KDE/KMenu>
64 #include <KDE/KPluginFactory>
65 #include <KDE/KPluginLoader>
66 #include <KDE/KStandardAction>
68 #define CFG_GROUP "Main Settings"
69 #define CFG_PREVIEW_SPLITTER_SIZES "PreviewSplitterSizes"
70 #define CFG_GROUP_SPLITTER_SIZES "GroupSplitterSizes"
71 #define CFG_FONT_SIZE "FontSize"
72 #define CFG_FONT_MGT_MODE "MgtMode"
73 #define CFG_SHOW_PREVIEW "ShowPreview"
75 K_PLUGIN_FACTORY(FontInstallFactory,
76 registerPlugin<KFI::CKCmFontInst>();
78 K_EXPORT_PLUGIN(FontInstallFactory("fontinst"))
80 namespace KFI
83 static int constModeList[]=
84 {CGroupListItem::ALL, CGroupListItem::PERSONAL, CGroupListItem::SYSTEM, -1};
86 inline CGroupListItem::EType modeToGrp(int mode)
88 return (CGroupListItem::EType)(constModeList[mode]);
91 static int grpToMode(CGroupListItem::EType type)
93 for(int i=0; i<3; ++i)
94 if(constModeList[i]==type)
95 return i;
96 return 0;
99 class CPushButton : public KPushButton
101 public:
103 CPushButton(const KGuiItem &item, QWidget *parent)
104 : KPushButton(item, parent)
106 theirHeight=qMax(theirHeight, height());
107 setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Maximum);
110 QSize sizeHint() const
112 QSize sh(KPushButton::sizeHint());
114 sh.setHeight(theirHeight);
115 if(sh.width()<sh.height())
116 sh.setWidth(sh.height());
117 else if(text().isEmpty())
118 sh.setWidth(theirHeight);
119 return sh;
122 private:
124 static int theirHeight;
127 class CToolBar : public KToolBar
129 public:
131 CToolBar(QWidget *parent)
132 : KToolBar(parent)
134 theirHeight=qMax(theirHeight, height());
135 setMovable(false);
136 setFloatable(false);
137 setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
138 setFont(QApplication::font());
141 void addSeparator()
143 addWidget(new QLabel(" ", this));
146 void link(CToolBar *l)
148 itsLinked=l;
151 QSize sizeHint() const
153 QSize sh(KToolBar::sizeHint());
155 sh.setHeight(theirHeight);
156 return sh;
159 void paintEvent(QPaintEvent *)
161 QColor col(palette().color(backgroundRole()));
163 col.setAlphaF(0.0);
164 QPainter(this).fillRect(rect(), col);
167 void resizeEvent(QResizeEvent *ev)
169 KToolBar::resizeEvent(ev);
170 if(height()>theirHeight)
172 theirHeight=height();
173 itsLinked->resize(itsLinked->width(), height());
177 private:
179 CToolBar *itsLinked;
180 static int theirHeight;
183 class CProgressBar : public QProgressBar
185 public:
187 CProgressBar(QWidget *p, int h) : QProgressBar(p), itsHeight((int)(h*0.6))
188 { setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); }
190 virtual ~CProgressBar() { }
192 int height() const { return itsHeight; }
193 QSize sizeHint() const { return QSize(100, itsHeight); }
195 private:
197 int itsHeight;
200 int CPushButton::theirHeight=0;
201 int CToolBar::theirHeight=0;
203 CKCmFontInst::CKCmFontInst(QWidget *parent, const QVariantList&)
204 : KCModule(FontInstallFactory::componentData(), parent),
205 itsPreview(NULL),
206 itsConfig(KFI_UI_CFG_FILE),
207 itsJob(NULL),
208 itsProgress(NULL),
209 itsUpdateDialog(NULL),
210 itsTempDir(NULL),
211 itsPrintProc(NULL),
212 itsExportFile(NULL)
214 setButtons(Help);
216 KGlobal::locale()->insertCatalog(KFI_CATALOGUE);
217 KIconLoader::global()->addAppDir(KFI_NAME);
218 KIconLoader::global()->reconfigure(KFI_NAME, KGlobal::dirs());
220 KAboutData *about = new KAboutData("fontinst", 0, ki18n("KDE Font Installer"), 0, KLocalizedString(),
221 KAboutData::License_GPL, ki18n("GUI front-end to the fonts:/ ioslave.\n"
222 "(c) Craig Drummond, 2000 - 2007"));
223 about->addAuthor(ki18n("Craig Drummond"), ki18n("Developer and maintainer"), "craig@kde.org");
224 setAboutData(about);
226 KConfigGroup cg(&itsConfig, CFG_GROUP);
228 itsRunner=new CJobRunner(this);
230 itsPreviewSplitter=new QSplitter(this);
231 itsPreviewSplitter->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
233 QWidget *controls=new QWidget(itsPreviewSplitter);
235 itsGroupSplitter=new QSplitter(controls);
236 itsGroupSplitter->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
238 QStringList items;
239 QBoxLayout *mainLayout=new QBoxLayout(QBoxLayout::TopToBottom, this),
240 *controlLayout=new QBoxLayout(QBoxLayout::TopToBottom, controls);
242 itsGroupsWidget=new QWidget(itsGroupSplitter);
243 itsFontsWidget=new QWidget(itsGroupSplitter);
244 itsPreviewWidget=new QWidget(itsPreviewSplitter);
246 CToolBar *toolbar=new CToolBar(this),
247 *previewToolbar=new CToolBar(itsPreviewWidget);
248 QGridLayout *groupsLayout=new QGridLayout(itsGroupsWidget),
249 *fontsLayout=new QGridLayout(itsFontsWidget);
250 QBoxLayout *previewLayout=new QBoxLayout(QBoxLayout::TopToBottom, itsPreviewWidget);
252 controlLayout->setMargin(0);
253 controlLayout->setSpacing(KDialog::spacingHint());
254 mainLayout->setMargin(0);
255 mainLayout->setSpacing(KDialog::spacingHint());
256 groupsLayout->setMargin(0);
257 groupsLayout->setSpacing(KDialog::spacingHint());
258 fontsLayout->setMargin(0);
259 fontsLayout->setSpacing(KDialog::spacingHint());
261 // Preview...
262 itsPreviewControl=new CPreviewSelectAction(itsPreviewWidget);
263 itsZoomInAction=KStandardAction::zoomIn(this, SLOT(zoomIn()), this);
264 itsZoomOutAction=KStandardAction::zoomOut(this, SLOT(zoomOut()), this);
265 previewToolbar->addAction(itsPreviewControl);
266 previewToolbar->addAction(itsZoomInAction);
267 previewToolbar->addAction(itsZoomOutAction);
268 previewToolbar->setToolButtonStyle(Qt::ToolButtonIconOnly);
270 previewLayout->setMargin(0);
271 previewLayout->setSpacing(KDialog::spacingHint());
273 QFrame *previewFrame=new QFrame(itsPreviewWidget);
274 QBoxLayout *previewFrameLayout=new QBoxLayout(QBoxLayout::LeftToRight, previewFrame);
276 previewFrameLayout->setMargin(0);
277 previewFrameLayout->setSpacing(0);
278 previewFrame->setFrameShape(QFrame::StyledPanel);
279 previewFrame->setFrameShadow(QFrame::Sunken);
280 previewFrame->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::MinimumExpanding);
282 itsPreview=new CFontPreview(previewFrame);
283 itsPreview->setWhatsThis(i18n("This displays a preview of the selected font."));
284 itsPreview->setContextMenuPolicy(Qt::CustomContextMenu);
285 previewFrameLayout->addWidget(itsPreview);
287 itsPreview->engine()->readConfig(itsConfig);
288 CFcEngine::setTextCol(QApplication::palette().color(QPalette::Active, QPalette::Text));
289 connect(itsPreview, SIGNAL(doZoomIn()), SLOT(zoomIn()));
290 connect(itsPreview, SIGNAL(doZoomOut()), SLOT(zoomOut()));
292 // Toolbar...
293 KActionMenu *settingsMenu=new KActionMenu(KIcon("configure"), i18n("Settings"), this);
294 KAction *changeTextAct=new KAction(KIcon("edit-rename"), i18n("Change Preview Text..."), this),
295 *duplicateFontsAct=new KAction(KIcon("system-search"), i18n("Scan for Duplicate Fonts..."), this);
296 //*validateFontsAct=new KAction(KIcon("checkmark"), i18n("Validate Fonts..."), this);
297 //*downloadFontsAct=new KAction(KIcon("go-down"), i18n("Download Fonts..."), this);
299 itsToolsMenu=new KActionMenu(KIcon("system-run"), i18n("Tools"), this);
300 itsMgtMode=new KToggleAction(KIcon("preferences-desktop-font-installer"),
301 i18n("Font Management Mode"), this),
302 itsShowPreview=new KToggleAction(KIcon("view-preview"), i18n("Show Large Preview"), this);
303 settingsMenu->addAction(itsMgtMode);
304 itsMgtMode->setChecked(true);
305 settingsMenu->addSeparator();
306 settingsMenu->addAction(itsShowPreview);
307 settingsMenu->addAction(changeTextAct);
308 settingsMenu->setDelayed(false);
309 itsToolsMenu->addAction(duplicateFontsAct);
310 //itsToolsMenu->addAction(validateFontsAct);
311 //itsToolsMenu->addAction(downloadFontsAct);
312 itsToolsMenu->setDelayed(false);
313 toolbar->addAction(settingsMenu);
314 toolbar->addAction(itsToolsMenu);
315 if(Misc::root())
316 itsModeControl=NULL;
317 else
319 itsModeControl=new QComboBox(toolbar);
320 itsModeAct=toolbar->addWidget(itsModeControl);
321 toolbar->addSeparator();
324 itsFilter=new CFontFilter(toolbar);
325 toolbar->addWidget(itsFilter);
327 // Details - Groups...
328 itsGroupList=new CGroupList(itsGroupsWidget);
329 itsGroupListView=new CGroupListView(itsGroupsWidget, itsGroupList);
331 if(itsModeControl)
332 for(int i=0; i<3; ++i)
333 itsModeControl->addItem(itsGroupList->group(modeToGrp(i))->name());
335 KPushButton *createGroup=new CPushButton(KGuiItem(QString(), "list-add",
336 i18n("Create a new group")),
337 itsGroupsWidget);
339 itsDeleteGroupControl=new CPushButton(KGuiItem(QString(), "edit-delete",
340 i18n("Remove group")),
341 itsGroupsWidget);
343 itsEnableGroupControl=new CPushButton(KGuiItem(QString(), "enablefont",
344 i18n("Enable all disabled fonts in the current group")),
345 itsGroupsWidget);
347 itsDisableGroupControl=new CPushButton(KGuiItem(QString(), "disablefont",
348 i18n("Disable all enabled fonts in the current group")),
349 itsGroupsWidget);
351 groupsLayout->addWidget(itsGroupListView, 0, 0, 1, 5);
352 groupsLayout->addWidget(createGroup, 1, 0);
353 groupsLayout->addWidget(itsDeleteGroupControl, 1, 1);
354 groupsLayout->addWidget(itsEnableGroupControl, 1, 2);
355 groupsLayout->addWidget(itsDisableGroupControl, 1, 3);
356 groupsLayout->addItem(new QSpacerItem(itsDisableGroupControl->width(), KDialog::spacingHint(),
357 QSizePolicy::Expanding, QSizePolicy::Fixed), 1, 4);
358 // Details - Fonts...
359 itsFontList=new CFontList(itsPreview->engine(), itsFontsWidget);
360 itsFontListView=new CFontListView(itsFontsWidget, itsFontList);
361 itsFontListView->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
362 itsFontListView->readConfig(cg);
364 itsAddFontControl=new CPushButton(KGuiItem(i18n("Add..."), "list-add",
365 i18n("Install fonts")),
366 itsFontsWidget);
368 itsDeleteFontControl=new CPushButton(KGuiItem(i18n("Delete"), "edit-delete",
369 i18n("Delete all selected fonts")),
370 itsFontsWidget);
372 itsEnableFontControl=new CPushButton(KGuiItem(i18n("Enable"), "enablefont",
373 i18n("Enable all selected fonts")),
374 itsFontsWidget);
376 itsDisableFontControl=new CPushButton(KGuiItem(i18n("Disable"), "disablefont",
377 i18n("Disable all selected fonts")),
378 itsFontsWidget);
380 fontsLayout->addWidget(itsFontListView, 0, 0, 1, 5);
381 fontsLayout->addWidget(itsAddFontControl, 1, 0);
382 fontsLayout->addWidget(itsDeleteFontControl, 1, 1);
383 fontsLayout->addWidget(itsEnableFontControl, 1, 2);
384 fontsLayout->addWidget(itsDisableFontControl, 1, 3);
385 fontsLayout->addItem(new QSpacerItem(KDialog::spacingHint(), KDialog::spacingHint(),
386 QSizePolicy::Expanding, QSizePolicy::Fixed), 1, 4);
388 // Details - Status...
389 QWidget *statusWidget=new QWidget(this);
390 QBoxLayout *statusLayout=new QBoxLayout(QBoxLayout::LeftToRight, statusWidget);
391 itsStatusLabel = new QLabel(statusWidget);
392 itsStatusLabel->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
393 itsListingProgress=new CProgressBar(statusWidget, itsStatusLabel->height());
394 itsListingProgress->setRange(0, 100);
395 statusLayout->setMargin(0);
396 statusLayout->setSpacing(KDialog::spacingHint());
397 statusLayout->addWidget(itsStatusLabel);
398 statusLayout->addItem(new QSpacerItem(0, itsListingProgress->height()+4,
399 QSizePolicy::Fixed, QSizePolicy::Fixed));
400 statusLayout->addWidget(itsListingProgress);
402 // Layout widgets...
403 controlLayout->addWidget(toolbar);
404 controlLayout->addWidget(itsGroupSplitter);
405 mainLayout->addWidget(itsPreviewSplitter);
406 mainLayout->addWidget(statusWidget);
407 previewLayout->addWidget(previewToolbar);
408 previewLayout->addWidget(previewFrame);
410 // Set size of widgets...
411 itsPreviewSplitter->setChildrenCollapsible(false);
412 itsGroupSplitter->setChildrenCollapsible(false);
413 itsGroupSplitter->setStretchFactor(0, 0);
414 itsGroupSplitter->setStretchFactor(1, 1);
415 itsPreviewSplitter->setStretchFactor(0, 1);
416 itsPreviewSplitter->setStretchFactor(1, 0);
418 toolbar->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
420 // Set sizes for 3 views...
421 QList<int> defaultSizes;
423 defaultSizes+=450;
424 defaultSizes+=150;
426 QList<int> sizes(cg.readEntry(CFG_PREVIEW_SPLITTER_SIZES, defaultSizes));
428 if(2!=sizes.count())
429 sizes=defaultSizes;
431 itsPreviewSplitter->setSizes(sizes);
433 defaultSizes=QList<int>();
434 defaultSizes+=100;
435 defaultSizes+=350;
436 sizes=cg.readEntry(CFG_GROUP_SPLITTER_SIZES, defaultSizes);
438 if(2!=sizes.count())
439 sizes=defaultSizes;
441 itsGroupSplitter->setSizes(sizes);
443 // Connect signals...
444 connect(itsFilter, SIGNAL(textChanged(const QString &)), itsFontListView, SLOT(filterText(const QString &)));
445 connect(itsFilter, SIGNAL(criteriaChanged(int, qulonglong)), itsFontListView, SLOT(filterCriteria(int, qulonglong)));
446 connect(itsGroupListView, SIGNAL(del()), SLOT(removeGroup()));
447 connect(itsGroupListView, SIGNAL(print()), SLOT(printGroup()));
448 connect(itsGroupListView, SIGNAL(enable()), SLOT(enableGroup()));
449 connect(itsGroupListView, SIGNAL(disable()), SLOT(disableGroup()));
450 connect(itsGroupListView, SIGNAL(copyFonts()), SLOT(copyFonts()));
451 connect(itsGroupListView, SIGNAL(moveFonts()), SLOT(moveFonts()));
452 connect(itsGroupListView, SIGNAL(itemSelected(const QModelIndex &)),
453 SLOT(groupSelected(const QModelIndex &)));
454 connect(itsGroupListView, SIGNAL(info(const QString &)),
455 SLOT(showInfo(const QString &)));
456 connect(itsGroupList, SIGNAL(refresh()), SLOT(refreshFontList()));
457 connect(itsFontList, SIGNAL(started()), SLOT(listingStarted()));
458 connect(itsFontList, SIGNAL(finished()), SLOT(listingCompleted()));
459 connect(itsFontList, SIGNAL(percent(int)), itsListingProgress, SLOT(setValue(int)));
460 connect(itsFontList, SIGNAL(status(const QString &)), itsStatusLabel,
461 SLOT(setText(const QString &)));
462 connect(itsFontListView, SIGNAL(del()), SLOT(deleteFonts()));
463 connect(itsFontListView, SIGNAL(print()), SLOT(print()));
464 connect(itsFontListView, SIGNAL(enable()), SLOT(enableFonts()));
465 connect(itsFontListView, SIGNAL(disable()), SLOT(disableFonts()));
466 connect(itsFontListView, SIGNAL(reload()), SLOT(reload()));
467 connect(itsFontListView, SIGNAL(fontsDropped(const QSet<KUrl> &)),
468 SLOT(addFonts(const QSet<KUrl> &)));
469 connect(itsFontListView, SIGNAL(itemSelected(const QModelIndex &, bool, bool)),
470 SLOT(fontSelected(const QModelIndex &, bool, bool)));
471 connect(itsFontListView, SIGNAL(refresh()), SLOT(setStatusBar()));
472 connect(itsGroupListView, SIGNAL(unclassifiedChanged()), itsFontListView, SLOT(refreshFilter()));
473 connect(createGroup, SIGNAL(clicked()), SLOT(addGroup()));
474 connect(itsDeleteGroupControl, SIGNAL(clicked()), SLOT(removeGroup()));
475 connect(itsEnableGroupControl, SIGNAL(clicked()), SLOT(enableGroup()));
476 connect(itsDisableGroupControl, SIGNAL(clicked()), SLOT(disableGroup()));
477 connect(itsAddFontControl, SIGNAL(clicked()), SLOT(addFonts()));
478 connect(itsDeleteFontControl, SIGNAL(clicked()), SLOT(deleteFonts()));
479 connect(itsEnableFontControl, SIGNAL(clicked()), SLOT(enableFonts()));
480 connect(itsDisableFontControl, SIGNAL(clicked()), SLOT(disableFonts()));
481 connect(itsMgtMode, SIGNAL(toggled(bool)), SLOT(toggleFontManagement(bool)));
482 connect(itsShowPreview, SIGNAL(toggled(bool)), SLOT(showPreview(bool)));
483 connect(changeTextAct, SIGNAL(triggered(bool)), SLOT(changeText()));
484 connect(itsPreviewControl, SIGNAL(range(const QList<CFcEngine::TRange> &)),
485 itsPreview, SLOT(setUnicodeRange(const QList<CFcEngine::TRange> &)));
486 connect(duplicateFontsAct, SIGNAL(triggered(bool)), SLOT(duplicateFonts()));
487 //connect(validateFontsAct, SIGNAL(triggered(bool)), SLOT(validateFonts()));
488 //connect(downloadFontsAct, SIGNAL(triggered(bool)), SLOT(downloadFonts()));
489 if(itsModeControl)
490 connect(itsModeControl, SIGNAL(activated(int)), SLOT(selectMode(int)));
492 itsMgtMode->setChecked(cg.readEntry(CFG_FONT_MGT_MODE, false));
493 itsShowPreview->setChecked(cg.readEntry(CFG_SHOW_PREVIEW, false));
494 showPreview(itsShowPreview->isChecked());
495 itsPreviewWidget->setVisible(itsShowPreview->isChecked());
496 toggleFontManagement(itsMgtMode->isChecked());
497 selectMainGroup();
498 itsFontList->scan();
500 toolbar->link(previewToolbar);
501 previewToolbar->link(toolbar);
504 CKCmFontInst::~CKCmFontInst()
506 KConfigGroup cg(&itsConfig, CFG_GROUP);
508 cg.writeEntry(CFG_PREVIEW_SPLITTER_SIZES, itsPreviewSplitter->sizes());
509 cg.writeEntry(CFG_GROUP_SPLITTER_SIZES, itsGroupSplitter->sizes());
510 cg.writeEntry(CFG_FONT_MGT_MODE, itsMgtMode->isChecked());
511 cg.writeEntry(CFG_SHOW_PREVIEW, itsShowPreview->isChecked());
512 itsFontListView->writeConfig(cg);
513 delete itsTempDir;
514 delete itsExportFile;
517 QString CKCmFontInst::quickHelp() const
519 return Misc::root()
520 ? i18n("<h1>Font Installer</h1><p> This module allows you to"
521 " install TrueType, Type1, and Bitmap"
522 " fonts.</p><p>You may also install fonts using Konqueror:"
523 " type fonts:/ into Konqueror's location bar"
524 " and this will display your installed fonts. To install a"
525 " font, simply copy one into the folder.</p>")
526 : i18n("<h1>Font Installer</h1><p> This module allows you to"
527 " install TrueType, Type1, and Bitmap"
528 " fonts.</p><p>You may also install fonts using Konqueror:"
529 " type fonts:/ into Konqueror's location bar"
530 " and this will display your installed fonts. To install a"
531 " font, simply copy it into the appropriate folder - "
532 " \"%1\" for fonts available to just yourself, or "
533 " \"%2\" for system-wide fonts (available to all).</p>",
534 i18n(KFI_KIO_FONTS_USER), i18n(KFI_KIO_FONTS_SYS));
537 void CKCmFontInst::fontSelected(const QModelIndex &index, bool en, bool dis)
539 itsDeleteFontControl->setEnabled(false);
540 itsDisableFontControl->setEnabled(en);
541 itsEnableFontControl->setEnabled(dis);
543 if(index.isValid())
545 CFontModelItem *mi=static_cast<CFontModelItem *>(index.internalPointer());
546 CFontItem *font=NULL;
548 if(mi->parent())
549 font=static_cast<CFontItem *>(index.internalPointer());
550 else
551 font=(static_cast<CFamilyItem *>(index.internalPointer()))->regularFont();
553 if(font)
555 if(itsShowPreview->isChecked())
557 KUrl url(font->isEnabled()
558 ? font->url()
559 : font->fileName().isEmpty()
560 ? font->url() : KUrl::fromPath(font->fileName()));
562 itsPreview->showFont(url, font->isEnabled() ? font->name() : QString(),
563 font->styleInfo(), font->isEnabled() ? 1 : font->index());
564 itsZoomInAction->setEnabled(!itsPreview->engine()->atMax());
565 itsZoomOutAction->setEnabled(!itsPreview->engine()->atMin());
567 itsDeleteFontControl->setEnabled(true);
572 void CKCmFontInst::reload()
574 if(!working(false))
576 listingStarted();
577 itsFontList->scan();
578 itsGroupList->rescan();
582 void CKCmFontInst::addFonts()
584 if(!working())
586 QString filter("application/x-font-ttf application/x-font-otf "
587 "application/x-font-type1");
589 if(itsMgtMode->isChecked() && FC::bitmapsEnabled())
590 filter+=" application/x-font-pcf application/x-font-bdf";
592 filter+=" fonts/package";
594 KUrl::List list=KFileDialog::getOpenUrls(KUrl(), filter, this, i18n("Add Fonts"));
596 if(list.count())
598 QSet<KUrl> urls;
599 KUrl::List::Iterator it(list.begin()),
600 end(list.end());
602 for(; it!=end; ++it)
604 if(KFI_KIO_FONTS_PROTOCOL!=(*it).protocol()) // Do not try to install from fonts:/ !!!
606 KUrl url(KIO::NetAccess::mostLocalUrl(*it, this));
608 if(url.isLocalFile())
610 QString file(url.path());
612 if(Misc::isPackage(file)) // If its a package we need to unzip 1st...
614 KZip zip(url.path());
616 delete itsTempDir;
617 itsTempDir=NULL;
619 if(zip.open(QIODevice::ReadOnly))
621 const KArchiveDirectory *zipDir=zip.directory();
623 if(zipDir)
625 QStringList fonts(zipDir->entries());
627 if(fonts.count())
629 QStringList::ConstIterator it(fonts.begin()),
630 end(fonts.end());
632 for(; it!=end; ++it)
634 const KArchiveEntry *entry=zipDir->entry(*it);
636 if(entry && entry->isFile())
638 if(!itsTempDir)
640 itsTempDir=new KTempDir(KStandardDirs::locateLocal("tmp",
641 KFI_TMP_DIR_PREFIX));
642 itsTempDir->setAutoRemove(true);
645 ((KArchiveFile *)entry)->copyTo(itsTempDir->name());
647 QString name(entry->name());
650 // Cant install hidden fonts, therefore need to
651 // unhide 1st!
652 if(Misc::isHidden(name))
654 ::rename(QFile::encodeName(itsTempDir->name()+name).data(),
655 QFile::encodeName(itsTempDir->name()+name.mid(1)).data());
656 name=name.mid(1);
659 KUrl url(itsTempDir->name()+name);
661 if(!Misc::isMetrics(name))
662 urls.insert(url);
669 else if(!Misc::isMetrics(url))
670 urls.insert(url);
672 else if(!Misc::isMetrics(url))
673 urls.insert(url);
676 if(urls.count())
677 addFonts(urls);
682 void CKCmFontInst::groupSelected(const QModelIndex &index)
684 CGroupListItem *grp=NULL;
686 if(index.isValid())
687 grp=static_cast<CGroupListItem *>(index.internalPointer());
689 itsFontListView->setFilterGroup(grp);
690 setStatusBar();
693 // Check fonts listed within group are still valid!
694 if(grp && grp->isCustom() && !grp->validated())
696 QSet<QString> remList;
697 QSet<QString>::Iterator it(grp->families().begin()),
698 end(grp->families().end());
700 for(; it!=end; ++it)
701 if(!itsFontList->hasFamily(*it))
702 remList.insert(*it);
703 it=remList.begin();
704 end=remList.end();
705 for(; it!=end; ++it)
706 itsGroupList->removeFromGroup(grp, *it);
707 grp->setValidated();
711 void CKCmFontInst::print(bool all)
714 // In order to support printing of newly installed/enabled fonts, the actual printing
715 // is carried out by the kfontinst helper app. This way we know Qt's font list will be
716 // up to date.
717 if(!working() && (!itsPrintProc || QProcess::NotRunning==itsPrintProc->state()))
719 QString exe(KStandardDirs::findExe(QLatin1String(KFI_PRINTER), KStandardDirs::installPath("libexec")));
721 if(exe.isEmpty())
722 KMessageBox::error(this, i18n("Failed to locate font printer."));
723 else
725 QSet<Misc::TFont> fonts;
727 itsFontListView->getPrintableFonts(fonts, !all);
729 if(fonts.count())
731 CPrintDialog dlg(this);
732 KConfigGroup cg(&itsConfig, CFG_GROUP);
734 if(dlg.exec(cg.readEntry(CFG_FONT_SIZE, 1)))
736 static const int constSizes[]={0, 12, 18, 24, 36, 48};
737 QSet<Misc::TFont>::ConstIterator it(fonts.begin()),
738 end(fonts.end());
739 KTemporaryFile tmpFile;
740 bool useFile(fonts.count()>16),
741 startProc(true);
742 QStringList args;
744 if(!itsPrintProc)
745 itsPrintProc=new QProcess(this);
746 else
747 itsPrintProc->kill();
750 // If we have lots of fonts to print, pass kfontinst a tempory groups file to print
751 // instead of passing font by font...
752 if(useFile)
754 if(tmpFile.open())
756 QTextStream str(&tmpFile);
758 for(; it!=end; ++it)
759 str << (*it).family << endl
760 << (*it).styleInfo << endl;
762 args << "--embed" << QString().sprintf("0x%x", (unsigned int)window()->winId())
763 << "--caption" << KGlobal::caption().toUtf8()
764 << "--icon" << "preferences-desktop-font-installer"
765 << "--size" << QString().setNum(constSizes[dlg.chosenSize() < 6 ? dlg.chosenSize() : 2])
766 << "--listfile" << tmpFile.fileName()
767 << "--deletefile";
769 else
771 KMessageBox::error(this, i18n("Failed to save list of fonts to print."));
772 startProc=false;
775 else
777 args << "--embed" << QString().sprintf("0x%x", (unsigned int)window()->winId())
778 << "--caption" << KGlobal::caption().toUtf8()
779 << "--icon" << "preferences-desktop-font-installer"
780 << "--size" << QString().setNum(constSizes[dlg.chosenSize()<6 ? dlg.chosenSize() : 2]);
782 for(; it!=end; ++it)
783 args << "--pfont" << QString((*it).family.toUtf8()+','+QString().setNum((*it).styleInfo));
786 if(startProc)
788 itsPrintProc->start(exe, args);
790 if(itsPrintProc->waitForStarted(1000))
792 if(useFile)
793 tmpFile.setAutoRemove(false);
795 else
796 KMessageBox::error(this, i18n("Failed to start font printer."));
798 cg.writeEntry(CFG_FONT_SIZE, dlg.chosenSize());
801 else
802 KMessageBox::information(this, i18n("There are no printable fonts.\n"
803 "You can only print non-bitmap and enabled fonts."),
804 i18n("Cannot Print"));
809 void CKCmFontInst::deleteFonts()
811 if(!working())
813 CJobRunner::ItemList urls;
814 QStringList fontNames;
815 QSet<Misc::TFont> fonts;
816 bool hasSys(false);
818 itsDeletedFonts.clear();
819 itsFontListView->getFonts(urls, fontNames, &fonts, &hasSys, true);
821 if(urls.isEmpty())
822 KMessageBox::information(this, i18n("You did not select anything to delete."),
823 i18n("Nothing to Delete"));
824 else
826 QSet<Misc::TFont>::ConstIterator it(fonts.begin()),
827 end(fonts.end());
828 bool doIt=false;
830 for(; it!=end; ++it)
831 itsDeletedFonts.insert((*it).family);
833 switch(fontNames.count())
835 case 0:
836 break;
837 case 1:
838 doIt = KMessageBox::Yes==KMessageBox::warningYesNo(this,
839 i18n("<p>Do you really want to "
840 "delete</p><p>\'<b>%1</b>\'?</p>", fontNames.first()),
841 i18n("Delete Font"), KStandardGuiItem::del());
842 break;
843 default:
844 doIt = KMessageBox::Yes==KMessageBox::warningYesNoList(this,
845 i18np("Do you really want to delete this font?",
846 "Do you really want to delete these %1 fonts?",
847 fontNames.count()),
848 fontNames, i18n("Delete Fonts"), KStandardGuiItem::del());
851 if(doIt && (!hasSys || itsRunner->getAdminPasswd(this)))
853 itsStatusLabel->setText(i18n("Deleting font(s)..."));
854 doCmd(CJobRunner::CMD_DELETE, urls, KUrl());
860 void CKCmFontInst::copyFonts()
862 if(!working())
864 CJobRunner::ItemList urls;
865 QStringList fontNames;
866 bool fromSys(itsGroupListView->isSystem());
868 itsDeletedFonts.clear();
869 itsFontListView->getFonts(urls, fontNames, NULL, NULL, true);
871 if(urls.isEmpty())
872 KMessageBox::information(this, i18n("You did not select anything to copy."),
873 i18n("Nothing to Copy"));
874 else
876 bool doIt=false;
878 switch(fontNames.count())
880 case 0:
881 break;
882 case 1:
883 doIt = KMessageBox::Yes==KMessageBox::warningYesNo(this,
884 i18n("<p>Do you really want to "
885 "copy</p><p>\'<b>%1</b>\'?</p>", fontNames.first()),
886 i18n("Copy Font"), KGuiItem(i18n("Copy")));
887 break;
888 default:
889 doIt = KMessageBox::Yes==KMessageBox::warningYesNoList(this,
890 i18np("Do you really want to copy this font?",
891 "Do you really want to copy these %1 fonts?",
892 fontNames.count()),
893 fontNames, i18n("Copy Fonts"), KGuiItem(i18n("Copy")));
896 if(doIt && (fromSys || itsRunner->getAdminPasswd(this)))
898 itsStatusLabel->setText(i18n("Copying font(s)..."));
899 doCmd(CJobRunner::CMD_COPY, urls, baseUrl(!fromSys));
905 void CKCmFontInst::moveFonts()
907 if(!working())
909 CJobRunner::ItemList urls;
910 QStringList fontNames;
912 itsDeletedFonts.clear();
913 itsFontListView->getFonts(urls, fontNames, NULL, NULL, true);
915 if(urls.isEmpty())
916 KMessageBox::information(this, i18n("You did not select anything to move."),
917 i18n("Nothing to Move"));
918 else
920 bool doIt=false;
922 switch(fontNames.count())
924 case 0:
925 break;
926 case 1:
927 doIt = KMessageBox::Yes==KMessageBox::warningYesNo(this,
928 i18n("<p>Do you really want to "
929 "move</p><p>\'<b>%1</b>\'?</p>", fontNames.first()),
930 i18n("Move Font"), KGuiItem(i18n("Move")));
931 break;
932 default:
933 doIt = KMessageBox::Yes==KMessageBox::warningYesNoList(this,
934 i18np("Do you really want to move this font?",
935 "Do you really want to move these %1 fonts?",
936 fontNames.count()),
937 fontNames, i18n("Move Fonts"), KGuiItem(i18n("Move")));
940 if(doIt && itsRunner->getAdminPasswd(this))
942 itsStatusLabel->setText(i18n("Moving font(s)..."));
943 doCmd(CJobRunner::CMD_MOVE, urls, baseUrl(!itsGroupListView->isSystem()));
949 void CKCmFontInst::enableFonts()
951 toggleFonts(true);
954 void CKCmFontInst::disableFonts()
956 toggleFonts(false);
959 void CKCmFontInst::addGroup()
961 bool ok;
962 QString name(KInputDialog::getText(i18n("Create New Group"),
963 i18n("Please enter the name of the new group:"),
964 i18n("New Group"), &ok, this));
966 if(ok && !name.isEmpty())
967 itsGroupList->createGroup(name);
970 void CKCmFontInst::removeGroup()
972 if(itsGroupList->removeGroup(itsGroupListView->currentIndex()))
973 selectMainGroup();
976 void CKCmFontInst::enableGroup()
978 toggleGroup(true);
981 void CKCmFontInst::disableGroup()
983 toggleGroup(false);
986 void CKCmFontInst::changeText()
988 if(!working())
990 bool status;
991 QRegExpValidator validator(QRegExp(".*"), 0L);
992 QString oldStr(itsPreview->engine()->getPreviewString()),
993 newStr(KInputDialog::getText(i18n("Preview Text"),
994 i18n("Please enter new text:"),
995 oldStr, &status, this, &validator));
997 if(status && oldStr!=newStr)
999 itsPreview->engine()->setPreviewString(newStr);
1000 itsFontList->forceNewPreviews();
1002 if(itsPreview->width()>6)
1003 itsPreview->showFont();
1008 void CKCmFontInst::showPreview(bool s)
1010 itsPreviewWidget->setVisible(s);
1013 void CKCmFontInst::duplicateFonts()
1015 CDuplicatesDialog dlg(this, itsRunner, itsFontList);
1016 CJobRunner::ItemList update;
1018 dlg.exec();
1020 if(dlg.modifiedUser())
1021 update.append(baseUrl(false));
1022 if(!Misc::root() && dlg.modifiedSys())
1023 update.append(baseUrl(true));
1025 if(update.count())
1026 doCmd(CJobRunner::CMD_UPDATE, update, KUrl());
1029 //void CKCmFontInst::validateFonts()
1033 //void CKCmFontInst::downloadFonts()
1037 void CKCmFontInst::print()
1039 print(false);
1042 void CKCmFontInst::printGroup()
1044 print(true);
1047 void CKCmFontInst::listingStarted()
1049 showInfo(i18n("Scanning font list..."));
1050 itsListingProgress->show();
1053 void CKCmFontInst::listingCompleted()
1055 if(itsDeletedFonts.count())
1057 QSet<QString>::Iterator it(itsDeletedFonts.begin()),
1058 end(itsDeletedFonts.end());
1060 for(; it!=end; ++it)
1061 if(!itsFontList->hasFamily(*it))
1062 itsGroupList->removeFamily(*it);
1064 itsDeletedFonts.clear();
1067 QSet<QString> foundries;
1069 itsFontList->getFoundries(foundries);
1070 itsFilter->setFoundries(foundries);
1071 refreshFamilies();
1072 itsListingProgress->hide();
1073 itsFontListView->selectFirstFont();
1076 void CKCmFontInst::refreshFontList()
1078 itsFontListView->refreshFilter();
1079 refreshFamilies();
1082 void CKCmFontInst::refreshFamilies()
1084 QSet<QString> enabledFamilies,
1085 disabledFamilies,
1086 partialFamilies;
1088 itsFontList->getFamilyStats(enabledFamilies, disabledFamilies, partialFamilies);
1089 itsGroupList->updateStatus(enabledFamilies, disabledFamilies, partialFamilies);
1090 setStatusBar();
1093 void CKCmFontInst::showInfo(const QString &info)
1095 if(info.isEmpty())
1096 if(itsLastStatusBarMsg.isEmpty())
1097 setStatusBar();
1098 else
1100 itsStatusLabel->setText(itsLastStatusBarMsg);
1101 itsLastStatusBarMsg=QString();
1103 else
1105 if(itsLastStatusBarMsg.isEmpty())
1106 itsLastStatusBarMsg=itsStatusLabel->text();
1107 itsStatusLabel->setText(info);
1111 void CKCmFontInst::setStatusBar()
1113 int enabled=0,
1114 disabled=0,
1115 partial=0;
1116 bool selectedEnabled=false,
1117 selectedDisabled=false;
1119 if(0==itsFontList->families().count())
1120 itsStatusLabel->setText(i18n("No fonts"));
1121 else
1123 itsFontListView->stats(enabled, disabled, partial);
1124 itsFontListView->selectedStatus(selectedEnabled, selectedDisabled);
1126 QString text(i18np("1 Font", "%1 Fonts", enabled+disabled+partial));
1128 if(disabled||partial)
1129 text+=i18n(" (%1 Enabled, %2 Disabled, %3 Partial)", enabled, disabled, partial);
1131 itsStatusLabel->setText(text);
1134 CGroupListItem::EType type(itsGroupListView->getType());
1136 bool isStd(CGroupListItem::CUSTOM==type);
1138 itsAddFontControl->setEnabled(CGroupListItem::ALL==type||CGroupListItem::UNCLASSIFIED==type||
1139 CGroupListItem::PERSONAL==type||CGroupListItem::SYSTEM==type);
1140 itsDeleteGroupControl->setEnabled(isStd);
1141 itsEnableGroupControl->setEnabled(disabled||partial);
1142 itsDisableGroupControl->setEnabled(isStd && (enabled||partial));
1144 itsGroupListView->controlMenu(itsDeleteGroupControl->isEnabled(),
1145 itsEnableGroupControl->isEnabled(),
1146 itsDisableGroupControl->isEnabled(), enabled||partial);
1148 itsEnableFontControl->setEnabled(selectedDisabled);
1149 itsDisableFontControl->setEnabled(selectedEnabled);
1150 itsDeleteFontControl->setEnabled(selectedEnabled||selectedDisabled);
1153 void CKCmFontInst::addFonts(const QSet<KUrl> &src)
1155 if(!working() && src.count() && !itsGroupListView->isCustom())
1157 KUrl dest;
1159 if(Misc::root())
1160 dest=baseUrl(true);
1161 else
1163 switch(getCurrentGroupType())
1165 case CGroupListItem::ALL:
1166 case CGroupListItem::UNCLASSIFIED:
1167 switch(KMessageBox::questionYesNoCancel(this,
1168 i18n("Do you wish to install the font(s) for personal use "
1169 "(only available to you), or "
1170 "system-wide (available to all users)?"),
1171 i18n("Where to Install"), KGuiItem(i18n(KFI_KIO_FONTS_USER)),
1172 KGuiItem(i18n(KFI_KIO_FONTS_SYS))))
1174 case KMessageBox::Yes:
1175 dest=baseUrl(false);
1176 break;
1177 case KMessageBox::No:
1178 if(itsRunner->getAdminPasswd(this))
1179 dest=baseUrl(true);
1180 else if(KMessageBox::Yes==KMessageBox::questionYesNo(this,
1181 i18n("Would you like to install the font(s) for personal use?"),
1182 i18n("Authorization Failed")))
1183 dest=baseUrl(false);
1184 else
1185 return;
1186 break;
1187 default:
1188 case KMessageBox::Cancel:
1189 return;
1191 break;
1192 case CGroupListItem::PERSONAL:
1193 dest=baseUrl(false);
1194 break;
1195 case CGroupListItem::SYSTEM:
1196 if(itsRunner->getAdminPasswd(this))
1197 dest=baseUrl(true);
1198 else if(KMessageBox::Yes==KMessageBox::questionYesNo(this,
1199 i18n("Would you like to install the font(s) for personal use?"),
1200 i18n("Authorization Failed")))
1201 dest=baseUrl(false);
1202 else
1203 return;
1204 break;
1205 default:
1206 return;
1210 QSet<KUrl> copy;
1211 QSet<KUrl>::ConstIterator it,
1212 end(src.end());
1215 // Check if font has any associated AFM or PFM file...
1216 itsStatusLabel->setText(i18n("Looking for any associated files..."));
1218 if(!itsProgress)
1220 itsProgress=new KProgressDialog(this, i18n("Scanning Files..."),
1221 i18n("Looking for additional files to install..."));
1222 itsProgress->setModal(true);
1223 itsProgress->setAutoReset(true);
1224 itsProgress->setAutoClose(true);
1227 itsProgress->setAllowCancel(false);
1228 itsProgress->setMinimumDuration(500);
1229 itsProgress->progressBar()->show();
1230 itsProgress->progressBar()->setRange(0, src.size());
1231 itsProgress->progressBar()->setValue(0);
1233 int steps=src.count()<200 ? 1 : src.count()/10;
1234 for(it=src.begin(); it!=end; ++it)
1236 KUrl::List associatedUrls;
1238 itsProgress->setLabelText(i18n("Looking for files associated with %1", (*it).prettyUrl()));
1239 itsProgress->progressBar()->setValue(itsProgress->progressBar()->value()+1);
1240 if(1==steps || 0==(itsProgress->progressBar()->value()%steps))
1242 bool dialogVisible(itsProgress->isVisible());
1243 QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
1244 if(dialogVisible && !itsProgress->isVisible()) // User closed dialog! re-open!!!
1245 itsProgress->show();
1248 CJobRunner::getAssociatedUrls(*it, associatedUrls, false, this);
1249 copy.insert(*it);
1251 KUrl::List::Iterator aIt(associatedUrls.begin()),
1252 aEnd(associatedUrls.end());
1254 for(; aIt!=aEnd; ++aIt)
1255 copy.insert(*aIt);
1257 itsProgress->close();
1259 CJobRunner::ItemList installUrls;
1261 end=copy.end();
1262 for(it=copy.begin(); it!=end; ++it)
1263 installUrls.append(*it);
1265 itsStatusLabel->setText(i18n("Installing font(s)..."));
1266 doCmd(CJobRunner::CMD_INSTALL, installUrls, dest);
1270 void CKCmFontInst::toggleFontManagement(bool on)
1272 if(working())
1273 itsMgtMode->setChecked(!on);
1274 else
1276 if(!on)
1277 itsPreviewControl->setStd();
1278 itsPreviewControl->setMode(on ? CPreviewSelectAction::ScriptsOnly : CPreviewSelectAction::Basic);
1279 itsToolsMenu->setVisible(on);
1280 itsFontListView->setMgtMode(on);
1281 itsFilter->setMgtMode(on);
1282 if(itsModeControl)
1284 itsModeAct->setVisible(!on);
1285 // The setEnabled() should not be required, as the widget is hidden. But, when the kcm switches
1286 // out of management mode, and re-shows the mode combo, the combo for some reason is disabled.
1287 // Calling setEnabled() here fixes this.
1288 itsModeAct->setEnabled(!on);
1290 itsEnableFontControl->setVisible(on);
1291 itsDisableFontControl->setVisible(on);
1292 selectMainGroup();
1293 itsGroupsWidget->setVisible(on);
1294 setStatusBar();
1298 void CKCmFontInst::selectMode(int mode)
1300 selectGroup(modeToGrp(mode));
1303 void CKCmFontInst::zoomIn()
1305 itsPreview->zoomIn();
1306 itsZoomInAction->setEnabled(!itsPreview->engine()->atMax());
1307 itsZoomOutAction->setEnabled(!itsPreview->engine()->atMin());
1310 void CKCmFontInst::zoomOut()
1312 itsPreview->zoomOut();
1313 itsZoomInAction->setEnabled(!itsPreview->engine()->atMax());
1314 itsZoomOutAction->setEnabled(!itsPreview->engine()->atMin());
1317 void CKCmFontInst::selectGroup(CGroupListItem::EType grp)
1319 QModelIndex current(itsGroupListView->currentIndex());
1321 if(current.isValid())
1323 CGroupListItem *grpItem=static_cast<CGroupListItem *>(current.internalPointer());
1325 if(grpItem && grp==grpItem->type())
1326 return;
1327 else
1328 itsGroupListView->selectionModel()->select(current,
1329 QItemSelectionModel::Deselect);
1332 QModelIndex idx(itsGroupList->index(grp));
1334 itsGroupListView->selectionModel()->select(idx, QItemSelectionModel::Select);
1335 itsGroupListView->setCurrentIndex(idx);
1336 groupSelected(idx);
1337 itsFontListView->refreshFilter();
1338 setStatusBar();
1341 void CKCmFontInst::toggleGroup(bool enable)
1343 QModelIndex idx(itsGroupListView->currentIndex());
1345 if(idx.isValid())
1347 CGroupListItem *grp=static_cast<CGroupListItem *>(idx.internalPointer());
1349 if(grp)
1350 toggleFonts(enable, grp->name());
1354 void CKCmFontInst::toggleFonts(bool enable, const QString &grp)
1356 if(!working())
1358 CJobRunner::ItemList urls;
1359 QStringList fonts;
1360 bool hasSys(false);
1362 itsFontListView->getFonts(urls, fonts, NULL, &hasSys, grp.isEmpty(), !enable, enable);
1364 if(urls.isEmpty())
1365 KMessageBox::information(this,
1366 enable ? i18n("You did not select anything to enable.")
1367 : i18n("You did not select anything to disable."),
1368 enable ? i18n("Nothing to Enable") : i18n("Nothing to Disable"));
1369 else
1370 toggleFonts(urls, fonts, enable, grp, hasSys);
1374 void CKCmFontInst::toggleFonts(CJobRunner::ItemList &urls, const QStringList &fonts, bool enable,
1375 const QString &grp, bool hasSys)
1377 bool doIt=false;
1379 switch(fonts.count())
1381 case 0:
1382 break;
1383 case 1:
1384 doIt = KMessageBox::Yes==KMessageBox::warningYesNo(this,
1385 grp.isEmpty()
1386 ? enable ? i18n("<p>Do you really want to "
1387 "enable</p><p>\'<b>%1</b>\'?</p>", fonts.first())
1388 : i18n("<p>Do you really want to "
1389 "disable</p><p>\'<b>%1</b>\'?</p>", fonts.first())
1390 : enable ? i18n("<p>Do you really want to "
1391 "enable</p><p>\'<b>%1</b>\', "
1392 "contained within group \'<b>%2</b>\'?</p>",
1393 fonts.first(), grp)
1394 : i18n("<p>Do you really want to "
1395 "disable</p><p>\'<b>%1</b>\', "
1396 "contained within group \'<b>%2</b>\'?</p>",
1397 fonts.first(), grp),
1398 enable ? i18n("Enable Font") : i18n("Disable Font"),
1399 enable ? KGuiItem(i18n("Enable"), "enablefont", i18n("Enable Font"))
1400 : KGuiItem(i18n("Disable"), "disablefont", i18n("Disable Font")));
1401 break;
1402 default:
1403 doIt = KMessageBox::Yes==KMessageBox::warningYesNoList(this,
1404 grp.isEmpty()
1405 ? enable ? i18np("Do you really want to enable this font?",
1406 "Do you really want to enable these %1 fonts?",
1407 urls.count())
1408 : i18np("Do you really want to disable this font?",
1409 "Do you really want to disable these %1 fonts?",
1410 urls.count())
1411 : enable ? i18np("<p>Do you really want to enable this font "
1412 "contained within group \'<b>%2</b>\'?</p>",
1413 "<p>Do you really want to enable these %1 fonts "
1414 "contained within group \'<b>%2</b>\'?</p>",
1415 urls.count(), grp)
1416 : i18np("<p>Do you really want to disable this font "
1417 "contained within group \'<b>%2</b>\'?</p>",
1418 "<p>Do you really want to disable these %1 fonts "
1419 "contained within group \'<b>%2</b>\'?</p>",
1420 urls.count(), grp),
1421 fonts,
1422 enable ? i18n("Enable Fonts") : i18n("Disable Fonts"),
1423 enable ? KGuiItem(i18n("Enable"), "enablefont", i18n("Enable Fonts"))
1424 : KGuiItem(i18n("Disable"), "disablefont", i18n("Disable Fonts")));
1427 if(doIt && (!hasSys || itsRunner->getAdminPasswd(this)))
1429 if(enable)
1430 itsStatusLabel->setText(i18n("Enabling font(s)..."));
1431 else
1432 itsStatusLabel->setText(i18n("Disabling font(s)..."));
1434 doCmd(enable ? CJobRunner::CMD_ENABLE : CJobRunner::CMD_DISABLE, urls, KUrl());
1438 bool CKCmFontInst::working(bool displayMsg)
1440 return false;
1441 if(NULL!=itsJob || itsFontList->active())
1443 if(displayMsg)
1444 KMessageBox::error(this, i18n("The installer is currently busy. Please wait for the "
1445 "current operation to terminate."));
1446 return true;
1449 return false;
1452 KUrl CKCmFontInst::baseUrl(bool sys)
1454 return Misc::root()
1455 ? KUrl(KFI_KIO_FONTS_PROTOCOL":/")
1456 : sys
1457 ? KUrl(KFI_KIO_FONTS_PROTOCOL":/"KFI_KIO_FONTS_SYS"/")
1458 : KUrl(KFI_KIO_FONTS_PROTOCOL":/"KFI_KIO_FONTS_USER"/");
1461 void CKCmFontInst::selectMainGroup()
1463 selectGroup(/*Misc::root() || itsMgtMode->isChecked()
1464 ? */CGroupListItem::ALL/* : CGroupListItem::PERSONAL*/);
1465 if(itsModeControl)
1466 itsModeControl->setCurrentIndex(grpToMode(/*Misc::root()
1467 ? */CGroupListItem::ALL
1468 /*: CGroupListItem::PERSONAL*/));
1471 void CKCmFontInst::doCmd(CJobRunner::ECommand cmd, const CJobRunner::ItemList &urls, const KUrl &dest)
1473 itsFontList->setAutoUpdate(false);
1474 itsRunner->exec(cmd, urls, dest);
1475 CFcEngine::setDirty();
1476 setStatusBar();
1477 itsFontList->scan();
1478 itsFontList->setAutoUpdate(true);
1479 delete itsTempDir;
1480 itsTempDir=NULL;
1483 CGroupListItem::EType CKCmFontInst::getCurrentGroupType()
1485 if(itsMgtMode->isChecked())
1486 return itsGroupListView->getType();
1487 else if(itsModeControl && itsModeControl->currentIndex() >= 0)
1488 return modeToGrp(itsModeControl->currentIndex());
1490 return CGroupListItem::ALL;
1495 #include "KCmFontInst.moc"