1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
|
/***************************************************************************
* Copyright (C) 2009-2011 by Daniel Nicoletti *
* dantti12@gmail.com *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; see the file COPYING. If not, write to *
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, *
* Boston, MA 02110-1301, USA. *
***************************************************************************/
#include "PkInstallFontconfigResources.h"
#include "IntroDialog.h"
#include <Daemon>
#include <PkStrings.h>
#include <QStandardItemModel>
#include <QXmlQuery>
#include <QFile>
#include <KLocalizedString>
#include <QLoggingCategory>
Q_DECLARE_LOGGING_CATEGORY(APPER_SESSION)
PkInstallFontconfigResources::PkInstallFontconfigResources(uint xid,
const QStringList &resources,
const QString &interaction,
const QDBusMessage &message,
QWidget *parent)
: SessionTask(xid, interaction, message, parent)
{
setWindowTitle(i18n("Installs new Fonts"));
auto introDialog = new IntroDialog(this);
auto model = new QStandardItemModel(this);
introDialog->setModel(model);
connect(introDialog, &IntroDialog::continueChanged, this, &PkInstallFontconfigResources::enableButtonOk);
setMainWidget(introDialog);
// This will only validate fields
QStringList errors;
QStringList iso639;
for (const QString &font : resources) {
// TODO never return in here
// TODO add name field from /usr/share/xml/iso-codes/iso_639.xml into model
if (!font.startsWith(QLatin1String(":lang="))) {
errors << QString(QLatin1String("not recognised prefix: '%1'")).arg(font);
qCWarning(APPER_SESSION) << QString(QLatin1String("not recognised prefix: '%1'")).arg(font);
continue;
}
int size = font.size();
if (size < 7 || size > 20) {
errors << QString(QLatin1String("lang tag malformed: '%1'")).arg(font);
qCWarning(APPER_SESSION) << QString(QLatin1String("lang tag malformed: '%1'")).arg(font);
continue;
}
m_resources << font;
iso639 << font.mid(6);
}
if (m_resources.isEmpty()) {
setError(i18n("Could interpret request"), i18n("Please verify if the request was valid"));
sendErrorFinished(InternalError, errors.join(QLatin1Char('\n')));
return;
}
enableButtonOk(true);
// Search for the iso 639 names to present it nicely to the user
QStringList niceNames;
QFile file(QLatin1String("/usr/share/xml/iso-codes/iso_639.xml"));
file.open(QFile::ReadOnly);
QXmlQuery query;
query.bindVariable(QLatin1String("path"), &file);
for (const QString &font : iso639) {
QString queryTxt;
queryTxt = QString(QLatin1String("declare variable $path external;"
"doc($path)/iso_639_entries/"
"iso_639_entry[@iso_639_2B_code=\"%1\" or "
"@iso_639_2T_code=\"%1\" or "
"@iso_639_1_code=\"%1\"]/string(@name)")).arg(font);
query.setQuery(queryTxt);
QStringList result;
query.evaluateTo(&result);
niceNames.append(result);
}
// kDebug() << "result" << niceNames << iso639;
for (const QString &name : niceNames) {
auto item = new QStandardItem(name);
item->setIcon(QIcon::fromTheme(QLatin1String("fonts-package")).pixmap(32, 32));
item->setFlags(Qt::ItemIsEnabled);
model->appendRow(item);
}
QString description;
description = i18np("An additional font is required to view this document correctly.\n"
"Do you want to search for a suitable package now?",
"Additional fonts are required to view this document correctly.\n"
"Do you want to search for suitable packages now?",
m_resources.size());
introDialog->setDescription(description);
QString title;
// this will come from DBus interface
if (parentTitle.isNull()) {
title = i18np("A program wants to install a font",
"A program wants to install fonts",
m_resources.size());
} else {
title = i18np("The application %2 wants to install a font",
"The application %2 wants to install fonts",
m_resources.size(),
parentTitle);
}
setTitle(title);
}
PkInstallFontconfigResources::~PkInstallFontconfigResources()
{
}
void PkInstallFontconfigResources::search()
{
auto transaction = new PkTransaction(this);
Transaction *t;
t = Daemon::whatProvides(m_resources,
Transaction::FilterNotInstalled | Transaction::FilterArch | Transaction::FilterNewest);
transaction->setupTransaction(t);
setTransaction(Transaction::RoleWhatProvides, transaction);
connect(transaction, &PkTransaction::finished, this, &PkInstallFontconfigResources::searchFinished, Qt::UniqueConnection);
connect(transaction, &PkTransaction::package, this, &PkInstallFontconfigResources::addPackage);
}
void PkInstallFontconfigResources::notFound()
{
QString msg = i18n("Failed to find font");
if (showWarning()) {
setInfo(msg, i18n("No new fonts could be found for this document"));
}
sendErrorFinished(NoPackagesFound, msg);
}
void PkInstallFontconfigResources::searchFailed()
{
QString msg = i18n("Failed to find font");
if (showWarning()) {
setError(msg, i18n("Failed to search for provides"));
}
sendErrorFinished(Failed, QLatin1String("failed to search for provides"));
}
#include "moc_PkInstallFontconfigResources.cpp"
|