KParts

htmlsettingsinterface.cpp
1 /*
2  This file is part of the KDE project
3  SPDX-FileCopyrightText: 2010 David Faure <[email protected]>
4 
5  SPDX-License-Identifier: LGPL-2.0-or-later
6 */
7 
8 #include "htmlsettingsinterface.h"
9 
10 #include <KLazyLocalizedString>
11 
12 using namespace KParts;
13 
15 {
16  // NOTE: The use of kli18n below is intended to allow GUI code to call
17  // i18n on the returned text without affecting use of untranslated text in
18  // config files.
19  switch (advice) {
20  case JavaScriptAccept:
21  return kli18n("Accept").untranslatedText();
22  case JavaScriptReject:
23  return kli18n("Reject").untranslatedText();
24  default:
25  break;
26  }
27 
28  return nullptr;
29 }
30 
32 {
33  JavaScriptAdvice ret = JavaScriptDunno;
34 
35  if (!text.isEmpty()) {
36  if (text.compare(QLatin1String("accept"), Qt::CaseInsensitive) == 0) {
37  ret = JavaScriptAccept;
38  } else if (text.compare(QLatin1String("reject"), Qt::CaseInsensitive) == 0) {
39  ret = JavaScriptReject;
40  }
41  }
42 
43  return ret;
44 }
45 
47  QString &domain,
50 {
51  const QString tmp(adviceStr);
52  const int splitIndex = tmp.indexOf(QLatin1Char(':'));
53 
54  if (splitIndex == -1) {
55  domain = adviceStr.toLower();
56  javaAdvice = JavaScriptDunno;
57  javaScriptAdvice = JavaScriptDunno;
58  } else {
59  domain = tmp.left(splitIndex).toLower();
60  const QString adviceString = tmp.mid(splitIndex + 1, tmp.length());
61  const int splitIndex2 = adviceString.indexOf(QLatin1Char(':'));
62  if (splitIndex2 == -1) {
63  // Java advice only
64  javaAdvice = textToJavascriptAdvice(adviceString);
65  javaScriptAdvice = JavaScriptDunno;
66  } else {
67  // Java and JavaScript advice
68  javaAdvice = textToJavascriptAdvice(adviceString.left(splitIndex2));
69  javaScriptAdvice = textToJavascriptAdvice(adviceString.mid(splitIndex2 + 1, adviceString.length()));
70  }
71  }
72 }
int indexOf(QChar ch, int from, Qt::CaseSensitivity cs) const const
static void splitDomainAdvice(const QString &text, QString &domain, JavaScriptAdvice &javaAdvice, JavaScriptAdvice &javaScriptAdvice)
A convenience function that splits text into domain, javaAdvice and jScriptAdvice.
JavaScriptAdvice
This enum specifies whether Java/JavaScript execution is allowed.
CaseInsensitive
bool isEmpty() const const
QString toLower() const const
static JavaScriptAdvice textToJavascriptAdvice(const QString &text)
A convenience function that returns the javascript advice for text.
QString mid(int position, int n) const const
int length() const const
QString left(int n) const const
static const char * javascriptAdviceToText(JavaScriptAdvice advice)
A convenience function Returns the text for the given JavascriptAdvice advice.
The KParts namespace,.
int compare(const QString &other, Qt::CaseSensitivity cs) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Mon Dec 6 2021 22:49:15 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.