1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-19 18:26:34 +01:00

[Code] qz_ prefixed functions moved to QzTools namespace.

This commit is contained in:
nowrep 2013-01-22 19:04:22 +01:00
parent 9f2de4b73a
commit e28f9d438e
46 changed files with 256 additions and 253 deletions

View File

@ -21,7 +21,7 @@
#include "adblockblockednetworkreply.h"
#include "mainapplication.h"
#include "webpage.h"
#include "globalfunctions.h"
#include "qztools.h"
#include "networkmanager.h"
#include "qupzilla.h"
#include "settings.h"
@ -128,8 +128,8 @@ AdBlockSubscription* AdBlockManager::addSubscription(const QString &title, const
return 0;
}
QString fileName = qz_filterCharsFromFilename(title.toLower()) + ".txt";
QString filePath = qz_ensureUniqueFilename(mApp->currentProfilePath() + "adblock/" + fileName);
QString fileName = QzTools::filterCharsFromFilename(title.toLower()) + ".txt";
QString filePath = QzTools::ensureUniqueFilename(mApp->currentProfilePath() + "adblock/" + fileName);
QByteArray data = QString("Title: %1\nUrl: %2\n[Adblock Plus 1.1.1]").arg(title, url).toLatin1();

View File

@ -46,7 +46,7 @@
#include "adblockmanager.h"
#include "mainapplication.h"
#include "networkmanager.h"
#include "globalfunctions.h"
#include "qztools.h"
#include "followredirectreply.h"
#include <QFile>
@ -257,7 +257,7 @@ QString AdBlockSubscription::elementHidingRulesForDomain(const QString &domain)
const AdBlockRule* AdBlockSubscription::rule(int offset) const
{
if (!qz_listContainsIndex(m_rules, offset)) {
if (!QzTools::listContainsIndex(m_rules, offset)) {
return 0;
}
@ -271,7 +271,7 @@ QList<AdBlockRule> AdBlockSubscription::allRules() const
const AdBlockRule* AdBlockSubscription::enableRule(int offset)
{
if (!qz_listContainsIndex(m_rules, offset)) {
if (!QzTools::listContainsIndex(m_rules, offset)) {
return 0;
}
@ -289,7 +289,7 @@ const AdBlockRule* AdBlockSubscription::enableRule(int offset)
const AdBlockRule* AdBlockSubscription::disableRule(int offset)
{
if (!qz_listContainsIndex(m_rules, offset)) {
if (!QzTools::listContainsIndex(m_rules, offset)) {
return 0;
}
@ -479,7 +479,7 @@ int AdBlockCustomList::addRule(const AdBlockRule &rule)
bool AdBlockCustomList::removeRule(int offset)
{
if (!qz_listContainsIndex(m_rules, offset)) {
if (!QzTools::listContainsIndex(m_rules, offset)) {
return false;
}
@ -497,7 +497,7 @@ bool AdBlockCustomList::removeRule(int offset)
const AdBlockRule* AdBlockCustomList::replaceRule(const AdBlockRule &rule, int offset)
{
if (!qz_listContainsIndex(m_rules, offset)) {
if (!QzTools::listContainsIndex(m_rules, offset)) {
return 0;
}

View File

@ -37,7 +37,7 @@
#include "qtwin.h"
#include "mainapplication.h"
#include "webhistoryinterface.h"
#include "globalfunctions.h"
#include "qztools.h"
#include "profileupdater.h"
#include "searchenginesmanager.h"
#include "databasewriter.h"
@ -1057,7 +1057,7 @@ void MainApplication::clearTempPath()
QDir dir(path);
if (dir.exists()) {
qz_removeDir(path);
QzTools::removeDir(path);
}
}

View File

@ -18,7 +18,7 @@
#include "profileupdater.h"
#include "qupzilla.h"
#include "updater.h"
#include "globalfunctions.h"
#include "qztools.h"
#include "mainapplication.h"
#include <QDir>
@ -112,8 +112,8 @@ void ProfileUpdater::copyDataToProfile()
QFile browseData(m_profilePath + "browsedata.db");
if (browseData.exists()) {
const QString &browseDataBackup = qz_ensureUniqueFilename(m_profilePath + "browsedata-backup.db");
const QString &settingsBackup = qz_ensureUniqueFilename(m_profilePath + "settings-backup.ini");
const QString &browseDataBackup = QzTools::ensureUniqueFilename(m_profilePath + "browsedata-backup.db");
const QString &settingsBackup = QzTools::ensureUniqueFilename(m_profilePath + "settings-backup.ini");
browseData.copy(browseDataBackup);
QFile(m_profilePath + "settings.ini").copy(settingsBackup);
const QString &text = "Incompatible profile version has been detected. To avoid losing your profile data, they were "

View File

@ -56,7 +56,7 @@
#include "pagescreen.h"
#include "webinspectordockwidget.h"
#include "bookmarksimportdialog.h"
#include "globalfunctions.h"
#include "qztools.h"
#include "reloadstopbutton.h"
#include "enhancedmenu.h"
#include "settings.h"
@ -1286,7 +1286,7 @@ void QupZilla::showSource(QWebFrame* frame, const QString &selectedHtml)
}
SourceViewer* source = new SourceViewer(frame, selectedHtml);
qz_centerWidgetToParent(source, this);
QzTools::centerWidgetToParent(source, this);
source->show();
}
@ -1953,7 +1953,7 @@ bool QupZilla::restoreState(const QByteArray &state, int version)
#ifdef QZ_WS_X11
int QupZilla::getCurrentVirtualDesktop() const
{
Display* display = static_cast<Display*>(qz_X11Display(this));
Display* display = static_cast<Display*>(QzTools::X11Display(this));
Atom actual_type;
int actual_format;
unsigned long nitems;
@ -1986,7 +1986,7 @@ void QupZilla::moveToVirtualDesktop(int desktopId)
return;
}
Display* display = static_cast<Display*>(qz_X11Display(this));
Display* display = static_cast<Display*>(QzTools::X11Display(this));
Atom net_wm_desktop = XInternAtom(display, "_NET_WM_DESKTOP", False);
if (net_wm_desktop == None) {

View File

@ -25,7 +25,7 @@
#include "bookmarksmodel.h"
#include "iconprovider.h"
#include "browsinglibrary.h"
#include "globalfunctions.h"
#include "qztools.h"
#include "bookmarksimportdialog.h"
#include "iconchooser.h"
#include "webtab.h"

View File

@ -16,7 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* ============================================================ */
#include "chromeimporter.h"
#include "globalfunctions.h"
#include "qztools.h"
#include "bookmarksimportdialog.h"
#include <QScriptEngine>

View File

@ -20,7 +20,7 @@
#include "qupzilla.h"
#include "cookiejar.h"
#include "mainapplication.h"
#include "globalfunctions.h"
#include "qztools.h"
#include "settings.h"
#include <QNetworkCookie>
@ -37,7 +37,7 @@ CookieManager::CookieManager(QWidget* parent)
, m_refreshCookieJar(true)
{
ui->setupUi(this);
qz_centerWidgetOnScreen(this);
QzTools::centerWidgetOnScreen(this);
// Stored Cookies
connect(ui->cookieTree, SIGNAL(currentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*)), this, SLOT(currentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*)));

View File

@ -23,7 +23,7 @@
#include "qupzilla.h"
#include "downloaditem.h"
#include "downloadmanager.h"
#include "globalfunctions.h"
#include "qztools.h"
#include "settings.h"
#include <QFileIconProvider>
@ -78,7 +78,7 @@ void DownloadFileHelper::handleUnsupportedContent(QNetworkReply* reply, const Do
m_fileSize = m_reply->header(QNetworkRequest::ContentLengthHeader).toLongLong();
if (m_fileSize > 0) {
mimeType.append(QString(" (%1)").arg(qz_fileSizeToString(m_fileSize)));
mimeType.append(QString(" (%1)").arg(QzTools::fileSizeToString(m_fileSize)));
}
// Close Empty Tab
@ -222,7 +222,7 @@ void DownloadFileHelper::fileNameChoosed(const QString &name, bool fileNameAutoG
}
if (fileNameAutoGenerated) {
m_fileName = qz_ensureUniqueFilename(m_fileName);
m_fileName = QzTools::ensureUniqueFilename(m_fileName);
}
if (!m_path.contains(mApp->tempPath())) {
@ -291,7 +291,7 @@ QString DownloadFileHelper::getFileName(QNetworkReply* reply)
name.remove(QLatin1String("\";"));
}
return qz_filterCharsFromFilename(name);
return QzTools::filterCharsFromFilename(name);
}
DownloadFileHelper::~DownloadFileHelper()

View File

@ -24,7 +24,7 @@
#include "downloadmanager.h"
#include "iconprovider.h"
#include "networkmanager.h"
#include "globalfunctions.h"
#include "qztools.h"
#include <QMenu>
#include <QClipboard>
@ -255,8 +255,8 @@ void DownloadItem::updateDownloadInfo(double currSpeed, qint64 received, qint64
QString remTime = remaingTimeToString(time);
m_remTime = time;
QString currSize = qz_fileSizeToString(received);
QString fileSize = qz_fileSizeToString(total);
QString currSize = QzTools::fileSizeToString(received);
QString fileSize = QzTools::fileSizeToString(total);
if (fileSize == tr("Unknown size")) {
ui->downloadInfo->setText(tr("%2 - unknown size (%3)").arg(currSize, speed));

View File

@ -25,7 +25,7 @@
#include "networkmanager.h"
#include "qtwin.h"
#include "desktopnotificationsfactory.h"
#include "globalfunctions.h"
#include "qztools.h"
#include "webpage.h"
#include "downloadfilehelper.h"
#include "settings.h"
@ -48,7 +48,7 @@ DownloadManager::DownloadManager(QWidget* parent)
}
#endif
ui->clearButton->setIcon(QIcon::fromTheme("edit-clear"));
qz_centerWidgetOnScreen(this);
QzTools::centerWidgetOnScreen(this);
m_networkManager = mApp->networkManager();

View File

@ -16,7 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* ============================================================ */
#include "historyitem.h"
#include "globalfunctions.h"
#include "qztools.h"
HistoryItem::HistoryItem(HistoryItem* parent)
: canFetchMore(false)
@ -82,7 +82,7 @@ void HistoryItem::insertChild(int row, HistoryItem* child)
void HistoryItem::removeChild(int row)
{
if (qz_listContainsIndex(m_children, row)) {
if (QzTools::listContainsIndex(m_children, row)) {
removeChild(m_children.at(row));
}
}
@ -94,7 +94,7 @@ void HistoryItem::removeChild(HistoryItem* child)
HistoryItem* HistoryItem::child(int row) const
{
if (qz_listContainsIndex(m_children, row)) {
if (QzTools::listContainsIndex(m_children, row)) {
return m_children.at(row);
}

View File

@ -127,7 +127,7 @@ SOURCES += \
navigation/navigationbar.cpp \
navigation/reloadstopbutton.cpp \
preferences/thememanager.cpp \
tools/globalfunctions.cpp \
tools/qztools.cpp \
other/pagescreen.cpp \
downloads/downloadfilehelper.cpp \
tools/certificateinfowidget.cpp \
@ -286,7 +286,7 @@ HEADERS += \
navigation/navigationbar.h \
navigation/reloadstopbutton.h \
preferences/thememanager.h \
tools/globalfunctions.h \
tools/qztools.h \
other/pagescreen.h \
downloads/downloadfilehelper.h \
tools/certificateinfowidget.h \

View File

@ -35,7 +35,7 @@
#include "goicon.h"
#include "rssicon.h"
#include "downicon.h"
#include "globalfunctions.h"
#include "qztools.h"
#include "iconprovider.h"
#include "qzsettings.h"
#include "colors.h"
@ -162,7 +162,7 @@ QUrl LocationBar::createUrl()
QString LocationBar::convertUrlToText(const QUrl &url) const
{
QString stringUrl = qz_urlEncodeQueryString(url);
QString stringUrl = QzTools::urlEncodeQueryString(url);
if (stringUrl == QLatin1String("qupzilla:speeddial") || stringUrl == QLatin1String("about:blank")) {
stringUrl = "";

View File

@ -18,7 +18,7 @@
#include "siteicon.h"
#include "locationbar.h"
#include "tabbedwebview.h"
#include "globalfunctions.h"
#include "qztools.h"
#include <QDrag>
#include <QMimeData>
@ -82,7 +82,7 @@ void SiteIcon::mouseMoveEvent(QMouseEvent* e)
mime->setImageData(icon().pixmap(16, 16).toImage());
drag->setMimeData(mime);
drag->setPixmap(qz_createPixmapForSite(icon(), title, url.toString()));
drag->setPixmap(QzTools::createPixmapForSite(icon(), title, url.toString()));
drag->exec();
}

View File

@ -19,7 +19,7 @@
#include "mainapplication.h"
#include "networkmanager.h"
#include "qupzilla.h"
#include "globalfunctions.h"
#include "qztools.h"
#include <QTimer>
#include <QDateTime>
@ -79,7 +79,7 @@ void CaBundleUpdater::replyFinished()
}
m_latestBundleVersion = response.toInt();
int currentBundleVersion = qz_readAllFileContents(m_bundleVersionFileName).trimmed().toInt();
int currentBundleVersion = QzTools::readAllFileContents(m_bundleVersionFileName).trimmed().toInt();
if (m_latestBundleVersion == 0) {
return;

View File

@ -25,7 +25,7 @@
#include "adblockmanager.h"
#include "networkproxyfactory.h"
#include "certificateinfowidget.h"
#include "globalfunctions.h"
#include "qztools.h"
#include "acceptlanguage.h"
#include "cabundleupdater.h"
#include "settings.h"
@ -53,7 +53,7 @@ static QString fileNameForCert(const QSslCertificate &cert)
QString certFileName = CertificateInfoWidget::certificateItemText(cert);
certFileName.remove(QLatin1Char(' '));
certFileName.append(QLatin1String(".crt"));
certFileName = qz_filterCharsFromFilename(certFileName);
certFileName = QzTools::filterCharsFromFilename(certFileName);
while (certFileName.startsWith(QLatin1Char('.'))) {
certFileName = certFileName.mid(1);
@ -134,7 +134,7 @@ void NetworkManager::setSSLConfiguration(QNetworkReply* reply)
{
if (!reply->sslConfiguration().isNull()) {
QSslCertificate cert = reply->sslConfiguration().peerCertificate();
if (!qz_isCertificateValid(cert) || reply->property("downReply").toBool()) {
if (!QzTools::isCertificateValid(cert) || reply->property("downReply").toBool()) {
return;
}
@ -273,7 +273,7 @@ void NetworkManager::authentication(QNetworkReply* reply, QAuthenticator* auth)
connect(box, SIGNAL(accepted()), dialog, SLOT(accept()));
label->setText(tr("A username and password are being requested by %1. "
"The site says: \"%2\"").arg(reply->url().toEncoded(), qz_escape(auth->realm())));
"The site says: \"%2\"").arg(reply->url().toEncoded(), QzTools::escape(auth->realm())));
formLa->addRow(label);
formLa->addRow(userLab, user);
@ -455,7 +455,7 @@ void NetworkManager::addLocalCertificate(const QSslCertificate &cert)
}
QString certFileName = fileNameForCert(cert);
QString fileName = qz_ensureUniqueFilename(mApp->currentProfilePath() + "certificates/" + certFileName);
QString fileName = QzTools::ensureUniqueFilename(mApp->currentProfilePath() + "certificates/" + certFileName);
QFile file(fileName);
if (file.open(QFile::WriteOnly)) {

View File

@ -16,7 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* ============================================================ */
#include "fileschemehandler.h"
#include "globalfunctions.h"
#include "qztools.h"
#include "iconprovider.h"
#include "downloadoptionsdialog.h"
#include "mainapplication.h"
@ -81,7 +81,7 @@ void FileSchemeHandler::handleUrl(const QUrl &url)
// Save
const QString &savePath = QFileDialog::getSaveFileName(mApp->getWindow(),
QObject::tr("Save file as..."),
QDir::homePath() + "/" + qz_getFileNameFromUrl(url));
QDir::homePath() + "/" + QzTools::getFileNameFromUrl(url));
if (!savePath.isEmpty()) {
file.copy(savePath);
@ -143,15 +143,15 @@ QString FileSchemeReply::loadDirectory()
static QString sPage;
if (sPage.isEmpty()) {
sPage = qz_readAllFileContents(":/html/dirlist.html");
sPage = QzTools::readAllFileContents(":/html/dirlist.html");
sPage.replace(QLatin1String("%BOX-BORDER%"), QLatin1String("qrc:html/box-border.png"));
sPage.replace(QLatin1String("%UP-IMG%"), qz_pixmapToByteArray(qIconProvider->standardIcon(QStyle::SP_FileDialogToParent).pixmap(22)));
sPage.replace(QLatin1String("%UP-IMG%"), QzTools::pixmapToByteArray(qIconProvider->standardIcon(QStyle::SP_FileDialogToParent).pixmap(22)));
sPage.replace(QLatin1String("%UP-DIR-TEXT%"), tr("Up to higher level directory"));
sPage.replace(QLatin1String("%SHOW-HIDDEN-TEXT%"), tr("Show hidden files"));
sPage.replace(QLatin1String("%NAME%"), tr("Name"));
sPage.replace(QLatin1String("%SIZE%"), tr("Size"));
sPage.replace(QLatin1String("%MODIFIED%"), tr("Last modified"));
sPage = qz_applyDirectionToPage(sPage);
sPage = QzTools::applyDirectionToPage(sPage);
}
QString page = sPage;
@ -182,14 +182,14 @@ QString FileSchemeReply::loadDirectory()
}
line += QLatin1String("><td class=\"td-name\" style=\"background-image:url(data:image/png;base64,");
line += qz_pixmapToByteArray(QFileIconProvider().icon(info).pixmap(16));
line += QzTools::pixmapToByteArray(QFileIconProvider().icon(info).pixmap(16));
line += QLatin1String(");\">");
line += QLatin1String("<a href=\"");
line += QUrl::fromLocalFile(info.absoluteFilePath()).toEncoded();
line += QLatin1String("\">");
line += info.fileName();
line += QLatin1String("</a></td><td class=\"td-size\">");
line += info.isDir() ? QString() : qz_fileSizeToString(info.size());
line += info.isDir() ? QString() : QzTools::fileSizeToString(info.size());
line += QLatin1String("</td><td>");
line += info.lastModified().toString("dd.MM.yyyy");
line += QLatin1String("</td><td>");

View File

@ -16,7 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* ============================================================ */
#include "qupzillaschemehandler.h"
#include "globalfunctions.h"
#include "qztools.h"
#include "qupzilla.h"
#include "mainapplication.h"
#include "tabbedwebview.h"
@ -138,7 +138,7 @@ QString QupZillaSchemeReply::reportbugPage()
return bPage;
}
bPage.append(qz_readAllFileContents(":html/reportbug.html"));
bPage.append(QzTools::readAllFileContents(":html/reportbug.html"));
bPage.replace(QLatin1String("%FAVICON%"), QLatin1String("qrc:icons/qupzilla.png"));
bPage.replace(QLatin1String("%BOX-BORDER%"), QLatin1String("qrc:html/box-border.png"));
@ -152,7 +152,7 @@ QString QupZillaSchemeReply::reportbugPage()
bPage.replace(QLatin1String("%SEND%"), tr("Send"));
bPage.replace(QLatin1String("%E-MAIL-OPTIONAL%"), tr("E-mail is optional<br/><b>Note: </b>Please read how to make a bug report <a href=%1>here</a> first.").arg("https://github.com/QupZilla/qupzilla/wiki/Bug-Reports target=_blank"));
bPage.replace(QLatin1String("%FIELDS-ARE-REQUIRED%"), tr("Please fill out all required fields!"));
bPage = qz_applyDirectionToPage(bPage);
bPage = QzTools::applyDirectionToPage(bPage);
return bPage;
}
@ -165,7 +165,7 @@ QString QupZillaSchemeReply::startPage()
return sPage;
}
sPage.append(qz_readAllFileContents(":html/start.html"));
sPage.append(QzTools::readAllFileContents(":html/start.html"));
sPage.replace(QLatin1String("%FAVICON%"), QLatin1String("qrc:icons/qupzilla.png"));
sPage.replace(QLatin1String("%BOX-BORDER%"), QLatin1String("qrc:html/box-border.png"));
sPage.replace(QLatin1String("%ABOUT-IMG%"), QLatin1String("qrc:icons/other/about.png"));
@ -176,7 +176,7 @@ QString QupZillaSchemeReply::startPage()
sPage.replace(QLatin1String("%WWW%"), QupZilla::WIKIADDRESS);
sPage.replace(QLatin1String("%ABOUT-QUPZILLA%"), tr("About QupZilla"));
sPage.replace(QLatin1String("%PRIVATE-BROWSING%"), mApp->isPrivateSession() ? tr("<h1>Private Browsing</h1>") : QString());
sPage = qz_applyDirectionToPage(sPage);
sPage = QzTools::applyDirectionToPage(sPage);
return sPage;
}
@ -186,11 +186,11 @@ QString QupZillaSchemeReply::aboutPage()
static QString aPage;
if (aPage.isEmpty()) {
aPage.append(qz_readAllFileContents(":html/about.html"));
aPage.append(QzTools::readAllFileContents(":html/about.html"));
aPage.replace(QLatin1String("%FAVICON%"), QLatin1String("qrc:icons/qupzilla.png"));
aPage.replace(QLatin1String("%BOX-BORDER%"), QLatin1String("qrc:html/box-border.png"));
aPage.replace(QLatin1String("%ABOUT-IMG%"), QLatin1String("qrc:icons/other/about.png"));
aPage.replace(QLatin1String("%COPYRIGHT-INCLUDE%"), qz_escape(qz_readAllFileContents(":html/copyright")));
aPage.replace(QLatin1String("%COPYRIGHT-INCLUDE%"), QzTools::escape(QzTools::readAllFileContents(":html/copyright")));
aPage.replace(QLatin1String("%TITLE%"), tr("About QupZilla"));
aPage.replace(QLatin1String("%ABOUT-QUPZILLA%"), tr("About QupZilla"));
@ -247,7 +247,7 @@ QString QupZillaSchemeReply::aboutPage()
authorString("Stanislav Kuznietsov", "stanislav_kuznetsov@ukr.net") + " (Ukrainian)<br/>" +
authorString("Seyyed Razi Alavizadeh", "s.r.alavizadeh@gmail.com") + " (Persian)"
);
aPage = qz_applyDirectionToPage(aPage);
aPage = QzTools::applyDirectionToPage(aPage);
}
return aPage;
@ -258,7 +258,7 @@ QString QupZillaSchemeReply::speeddialPage()
static QString dPage;
if (dPage.isEmpty()) {
dPage.append(qz_readAllFileContents(":html/speeddial.html"));
dPage.append(QzTools::readAllFileContents(":html/speeddial.html"));
dPage.replace(QLatin1String("%FAVICON%"), QLatin1String("qrc:icons/qupzilla.png"));
dPage.replace(QLatin1String("%IMG_PLUS%"), QLatin1String("qrc:html/plus.png"));
dPage.replace(QLatin1String("%BOX-BORDER%"), QLatin1String("qrc:html/box-border-small.png"));
@ -294,7 +294,7 @@ QString QupZillaSchemeReply::speeddialPage()
dPage.replace(QLatin1String("%TXT_NRROWS%"), tr("Maximum pages in a row:"));
dPage.replace(QLatin1String("%TXT_SDSIZE%"), tr("Change size of pages:"));
dPage.replace(QLatin1String("%TXT_CNTRDLS%"), tr("Center speed dials"));
dPage = qz_applyDirectionToPage(dPage);
dPage = QzTools::applyDirectionToPage(dPage);
}
QString page = dPage;
@ -315,10 +315,10 @@ QString QupZillaSchemeReply::restorePage()
static QString rPage;
if (rPage.isEmpty()) {
rPage.append(qz_readAllFileContents(":html/restore.html"));
rPage.append(QzTools::readAllFileContents(":html/restore.html"));
rPage.replace(QLatin1String("%FAVICON%"), QLatin1String("qrc:icons/qupzilla.png"));
rPage.replace(QLatin1String("%BOX-BORDER%"), QLatin1String("qrc:html/box-border.png"));
rPage.replace(QLatin1String("%IMAGE%"), qz_pixmapToByteArray(qIconProvider->standardIcon(QStyle::SP_MessageBoxWarning).pixmap(45, 45)));
rPage.replace(QLatin1String("%IMAGE%"), QzTools::pixmapToByteArray(qIconProvider->standardIcon(QStyle::SP_MessageBoxWarning).pixmap(45, 45)));
rPage.replace(QLatin1String("%TITLE%"), tr("Restore Session"));
@ -326,7 +326,7 @@ QString QupZillaSchemeReply::restorePage()
rPage.replace(QLatin1String("%APOLOGIZE%"), tr("We apologize for this. Would you like to restore the last saved state?"));
rPage.replace(QLatin1String("%TRY-REMOVING%"), tr("Try removing one or more tabs that you think cause troubles"));
rPage.replace(QLatin1String("%START-NEW%"), tr("Or you can start completely new session"));
rPage = qz_applyDirectionToPage(rPage);
rPage = QzTools::applyDirectionToPage(rPage);
}
return rPage;
@ -337,7 +337,7 @@ QString QupZillaSchemeReply::configPage()
static QString cPage;
if (cPage.isEmpty()) {
cPage.append(qz_readAllFileContents(":html/config.html"));
cPage.append(QzTools::readAllFileContents(":html/config.html"));
cPage.replace(QLatin1String("%FAVICON%"), QLatin1String("qrc:icons/qupzilla.png"));
cPage.replace(QLatin1String("%BOX-BORDER%"), QLatin1String("qrc:html/box-border.png"));
cPage.replace(QLatin1String("%ABOUT-IMG%"), QLatin1String("qrc:icons/other/about.png"));
@ -367,7 +367,7 @@ QString QupZillaSchemeReply::configPage()
QString("<dt>%1</dt><dd>%2<dd>").arg(tr("Qt version"), QT_VERSION_STR) +
QString("<dt>%1</dt><dd>%2<dd>").arg(tr("WebKit version"), QupZilla::WEBKITVERSION) +
QString("<dt>%1</dt><dd>%2<dd>").arg(tr("Build time"), QupZilla::BUILDTIME) +
QString("<dt>%1</dt><dd>%2<dd>").arg(tr("Platform"), qz_buildSystem()));
QString("<dt>%1</dt><dd>%2<dd>").arg(tr("Platform"), QzTools::buildSystem()));
cPage.replace(QLatin1String("%PATHS-TEXT%"),
QString("<dt>%1</dt><dd>%2<dd>").arg(tr("Profile"), mApp->currentProfilePath()) +
@ -407,7 +407,7 @@ QString QupZillaSchemeReply::configPage()
QString("<dt>%1</dt><dd>%2<dd>").arg(tr("KDE integration"), KDEIntegration) +
QString("<dt>%1</dt><dd>%2<dd>").arg(tr("Portable build"), portableBuild));
cPage = qz_applyDirectionToPage(cPage);
cPage = QzTools::applyDirectionToPage(cPage);
}
QString page = cPage;
@ -419,7 +419,7 @@ QString QupZillaSchemeReply::configPage()
foreach(const Plugins::Plugin & plugin, availablePlugins) {
PluginSpec spec = plugin.pluginSpec;
pluginsString.append(QString("<tr><td>%1</td><td>%2</td><td>%3</td><td>%4</td></tr>").arg(
spec.name, spec.version, qz_escape(spec.author), spec.description));
spec.name, spec.version, QzTools::escape(spec.author), spec.description));
}
if (pluginsString.isEmpty()) {
@ -461,7 +461,7 @@ QString QupZillaSchemeReply::configPage()
keyString = QLatin1String("\"empty\"");
}
groupString.append(QString("<tr><td>%1</td><td>%2</td></tr>").arg(key, qz_escape(keyString)));
groupString.append(QString("<tr><td>%1</td><td>%2</td></tr>").arg(key, QzTools::escape(keyString)));
}
settings->endGroup();

View File

@ -22,7 +22,7 @@
#include "rssmanager.h"
#include "mainapplication.h"
#include "downloaditem.h"
#include "globalfunctions.h"
#include "qztools.h"
#include "settings.h"
#include "history.h"
@ -47,7 +47,7 @@ BrowsingLibrary::BrowsingLibrary(QupZilla* mainClass, QWidget* parent)
m_historyManager->restoreState(settings.value("historyState", QByteArray()).toByteArray());
settings.endGroup();
qz_centerWidgetOnScreen(this);
QzTools::centerWidgetOnScreen(this);
ui->tabs->AddTab(m_historyManager, QIcon(":/icons/other/bighistory.png"), tr("History"));
ui->tabs->AddTab(m_bookmarksManager, QIcon(":/icons/other/bigstar.png"), tr("Bookmarks"));
@ -141,9 +141,9 @@ void BrowsingLibrary::optimizeDatabase()
{
mApp->setOverrideCursor(Qt::WaitCursor);
QString profilePath = mApp->currentProfilePath();
QString sizeBefore = qz_fileSizeToString(QFileInfo(profilePath + "browsedata.db").size());
QString sizeBefore = QzTools::fileSizeToString(QFileInfo(profilePath + "browsedata.db").size());
mApp->history()->optimizeHistory();
QString sizeAfter = qz_fileSizeToString(QFileInfo(profilePath + "browsedata.db").size());
QString sizeAfter = QzTools::fileSizeToString(QFileInfo(profilePath + "browsedata.db").size());
mApp->restoreOverrideCursor();
QMessageBox::information(this, tr("Database Optimized"), tr("Database successfully optimized.<br/><br/><b>Database Size Before: </b>%1<br/><b>Database Size After: </b>%2").arg(sizeBefore, sizeAfter));
}

View File

@ -26,7 +26,7 @@
#include "clickablelabel.h"
#include "ui_clearprivatedata.h"
#include "iconprovider.h"
#include "globalfunctions.h"
#include "qztools.h"
#include <QNetworkCookie>
#include <QWebDatabase>
@ -65,7 +65,7 @@ void ClearPrivateData::clearLocalStorage()
{
const QString &profile = mApp->currentProfilePath();
qz_removeDir(profile + "LocalStorage");
QzTools::removeDir(profile + "LocalStorage");
}
void ClearPrivateData::clearWebDatabases()
@ -73,7 +73,7 @@ void ClearPrivateData::clearWebDatabases()
const QString &profile = mApp->currentProfilePath();
QWebDatabase::removeAllDatabases();
qz_removeDir(profile + "Databases");
QzTools::removeDir(profile + "Databases");
}
void ClearPrivateData::clearCache()

View File

@ -16,7 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* ============================================================ */
#include "licenseviewer.h"
#include "globalfunctions.h"
#include "qztools.h"
LicenseViewer::LicenseViewer(QWidget* parent)
: QTextBrowser()
@ -26,10 +26,10 @@ LicenseViewer::LicenseViewer(QWidget* parent)
resize(450, 500);
qz_centerWidgetToParent(this, parent);
QzTools::centerWidgetToParent(this, parent);
}
void LicenseViewer::setLicenseFile(const QString &fileName)
{
setText(qz_readAllFileContents(fileName));
setText(QzTools::readAllFileContents(fileName));
}

View File

@ -19,7 +19,7 @@
#include "ui_pagescreen.h"
#include "tabbedwebview.h"
#include "webpage.h"
#include "globalfunctions.h"
#include "qztools.h"
#include <QFileDialog>
#include <QWebFrame>
@ -61,7 +61,7 @@ PageScreen::PageScreen(WebView* view, QWidget* parent)
void PageScreen::dialogAccepted()
{
const QString &suggestedPath = QString("%1/%2.png").arg(QDir::homePath(),
qz_filterCharsFromFilename(m_pageTitle));
QzTools::filterCharsFromFilename(m_pageTitle));
m_filePath = QFileDialog::getSaveFileName(this, tr("Save Page Screen..."), suggestedPath);
if (!m_filePath.isEmpty()) {

View File

@ -19,7 +19,7 @@
#include "tabbedwebview.h"
#include "htmlhighlighter.h"
#include "sourceviewersearch.h"
#include "globalfunctions.h"
#include "qztools.h"
#include "iconprovider.h"
#include "enhancedmenu.h"
#include "plaineditwithlines.h"
@ -65,7 +65,7 @@ SourceViewer::SourceViewer(QWebFrame* frame, const QString &selectedHtml)
new HtmlHighlighter(m_sourceEdit->document());
resize(650, 600);
qz_centerWidgetToParent(this, frame->page()->view());
QzTools::centerWidgetToParent(this, frame->page()->view());
QMenu* menuFile = new QMenu(tr("File"));
menuFile->addAction(QIcon::fromTheme("document-save"), tr("Save as..."), this, SLOT(save()))->setShortcut(QKeySequence("Ctrl+S"));

View File

@ -17,14 +17,14 @@
* ============================================================ */
#include "useragentmanager.h"
#include "qupzilla.h"
#include "globalfunctions.h"
#include "qztools.h"
#include "settings.h"
#include <QWebPage> // QTWEBKIT_VERSION_CHECK macro
UserAgentManager::UserAgentManager()
{
m_fakeUserAgent = QString("Mozilla/5.0 (%1) AppleWebKit/%2 (KHTML, like Gecko) Chrome/10.0 Safari/%2").arg(qz_buildSystem(), QupZilla::WEBKITVERSION);
m_fakeUserAgent = QString("Mozilla/5.0 (%1) AppleWebKit/%2 (KHTML, like Gecko) Chrome/10.0 Safari/%2").arg(QzTools::buildSystem(), QupZilla::WEBKITVERSION);
}
void UserAgentManager::loadSettings()

View File

@ -43,7 +43,7 @@
#include "pluginproxy.h"
#include "squeezelabelv2.h"
#include "webpage.h"
#include "globalfunctions.h"
#include "qztools.h"
#include "qupzilla.h"
#include <QHBoxLayout>
@ -228,17 +228,17 @@ void ClickToFlash::load()
So asynchronous JavaScript code is used to remove element from page and then substitute
it with unblocked Flash. The JavaScript code is:
var qz_c2f_clone = this.cloneNode(true);
var qz_c2f_parentNode = this.parentNode;
var qz_c2f_substituteElement = document.createElement(this.tagName);
var QzTools::c2f_clone = this.cloneNode(true);
var QzTools::c2f_parentNode = this.parentNode;
var QzTools::c2f_substituteElement = document.createElement(this.tagName);
qz_c2f_substituteElement.width = this.width;
qz_c2f_substituteElement.height = this.height;
QzTools::c2f_substituteElement.width = this.width;
QzTools::c2f_substituteElement.height = this.height;
this.parentNode.replaceChild(qz_c2f_substituteElement, this);
this.parentNode.replaceChild(QzTools::c2f_substituteElement, this);
setTimeout(function(){
qz_c2f_parentNode.replaceChild(qz_c2f_clone, qz_c2f_substituteElement);
QzTools::c2f_parentNode.replaceChild(QzTools::c2f_clone, QzTools::c2f_substituteElement);
}, 250);
*/
@ -249,11 +249,11 @@ void ClickToFlash::load()
m_element.setAttribute("type", "application/futuresplash");
QString js = "var qz_c2f_clone=this.cloneNode(true);var qz_c2f_parentNode=this.parentNode;"
"var qz_c2f_substituteElement=document.createElement(this.tagName);"
"qz_c2f_substituteElement.width=this.width;qz_c2f_substituteElement.height=this.height;"
"this.parentNode.replaceChild(qz_c2f_substituteElement,this);setTimeout(function(){"
"qz_c2f_parentNode.replaceChild(qz_c2f_clone,qz_c2f_substituteElement);},250);";
QString js = "var QzTools::c2f_clone=this.cloneNode(true);var QzTools::c2f_parentNode=this.parentNode;"
"var QzTools::c2f_substituteElement=document.createElement(this.tagName);"
"QzTools::c2f_substituteElement.width=this.width;QzTools::c2f_substituteElement.height=this.height;"
"this.parentNode.replaceChild(QzTools::c2f_substituteElement,this);setTimeout(function(){"
"QzTools::c2f_parentNode.replaceChild(QzTools::c2f_clone,QzTools::c2f_substituteElement);},250);";
m_element.evaluateJavaScript(js);
}
@ -312,6 +312,6 @@ void ClickToFlash::showInfo()
}
widg->setMaximumHeight(500);
qz_centerWidgetToParent(widg, m_page->view());
QzTools::centerWidgetToParent(widg, m_page->view());
widg->show();
}

View File

@ -18,7 +18,7 @@
#include "popuplocationbar.h"
#include "popupwebview.h"
#include "toolbutton.h"
#include "globalfunctions.h"
#include "qztools.h"
#include "iconprovider.h"
#include <QMovie>
@ -86,7 +86,7 @@ void PopupLocationBar::stopLoading()
void PopupLocationBar::showUrl(const QUrl &url)
{
setText(qz_urlEncodeQueryString(url));
setText(QzTools::urlEncodeQueryString(url));
setCursorPosition(0);
}

View File

@ -23,7 +23,7 @@
#include "qupzilla.h"
#include "qzsettings.h"
#include "popuplocationbar.h"
#include "globalfunctions.h"
#include "qztools.h"
#include <QVBoxLayout>
#include <QStatusBar>
@ -174,7 +174,7 @@ void PopupWindow::setWindowGeometry(const QRect &newRect)
resize(newSize);
if (newRect.topLeft() == QPoint(0, 0) && oldRect.topLeft() == QPoint(0, 0)) {
qz_centerWidgetOnScreen(this);
QzTools::centerWidgetOnScreen(this);
}
}
}

View File

@ -21,7 +21,7 @@
#include "mainapplication.h"
#include "plugininterface.h"
#include "pluginlistdelegate.h"
#include "globalfunctions.h"
#include "qztools.h"
#include "settings.h"
#include <QInputDialog>
@ -177,7 +177,7 @@ void PluginsManager::refresh()
}
item->setIcon(icon);
QString pluginInfo = QString("<b>%1</b> %2<br/><i>%3</i><br/>%4").arg(spec.name, spec.version, qz_escape(spec.author), spec.info);
QString pluginInfo = QString("<b>%1</b> %2<br/><i>%3</i><br/>%4").arg(spec.name, spec.version, QzTools::escape(spec.author), spec.info);
item->setToolTip(pluginInfo);
item->setText(spec.name);

View File

@ -38,7 +38,7 @@
#include "navigationbar.h"
#include "thememanager.h"
#include "acceptlanguage.h"
#include "globalfunctions.h"
#include "qztools.h"
#include "autofillmodel.h"
#include "settings.h"
#include "tabbedwebview.h"
@ -722,7 +722,7 @@ void Preferences::buttonClicked(QAbstractButton* button)
void Preferences::createProfile()
{
QString name = QInputDialog::getText(this, tr("New Profile"), tr("Enter the new profile's name:"));
name = qz_filterCharsFromFilename(name);
name = QzTools::filterCharsFromFilename(name);
if (name.isEmpty()) {
return;
}
@ -758,7 +758,7 @@ void Preferences::deleteProfile()
return;
}
qz_removeDir(mApp->PROFILEDIR + "profiles/" + name);
QzTools::removeDir(mApp->PROFILEDIR + "profiles/" + name);
ui->startProfile->removeItem(ui->startProfile->currentIndex());
}

View File

@ -19,7 +19,7 @@
#include "ui_sslmanager.h"
#include "networkmanager.h"
#include "mainapplication.h"
#include "globalfunctions.h"
#include "qztools.h"
#include "certificateinfowidget.h"
#include <QFileDialog>
@ -166,7 +166,7 @@ void SSLManager::showCertificateInfo(const QSslCertificate &cert)
connect(b, SIGNAL(clicked(QAbstractButton*)), w, SLOT(close()));
w->layout()->addWidget(b);
w->resize(w->sizeHint());
qz_centerWidgetToParent(w, this);
QzTools::centerWidgetToParent(w, this);
w->show();
}

View File

@ -18,7 +18,7 @@
#include "thememanager.h"
#include "ui_thememanager.h"
#include "mainapplication.h"
#include "globalfunctions.h"
#include "qztools.h"
#include "settings.h"
#include "licenseviewer.h"
#include "preferences.h"
@ -114,10 +114,10 @@ ThemeManager::Theme ThemeManager::parseTheme(const QString &name)
}
if (QFile(path + "theme.license").exists()) {
info.license = qz_readAllFileContents(path + "theme.license");
info.license = QzTools::readAllFileContents(path + "theme.license");
}
QString theme_info = qz_readAllFileContents(path + "theme.info");
QString theme_info = QzTools::readAllFileContents(path + "theme.info");
QRegExp rx("Name:(.*)\\n");
rx.setMinimal(true);

View File

@ -18,7 +18,7 @@
#include "useragentdialog.h"
#include "ui_useragentdialog.h"
#include "useragentmanager.h"
#include "globalfunctions.h"
#include "qztools.h"
#include "mainapplication.h"
#include "settings.h"
@ -33,7 +33,7 @@ UserAgentDialog::UserAgentDialog(QWidget* parent)
{
ui->setupUi(this);
const QString &os = qz_buildSystem();
const QString &os = QzTools::buildSystem();
m_knownUserAgents << QString("Opera/9.80 (%1) Presto/2.10.229 Version/11.61").arg(os)
<< QString("Mozilla/5.0 (%1) AppleWebKit/535.7 (KHTML, like Gecko) Chrome/16.0.912.77 Safari/535.7").arg(os)
<< QString("Mozilla/5.0 (%1) AppleWebKit/533.21.1 (KHTML, like Gecko) Version/5.0.5 Safari/533.21.1").arg(os)

View File

@ -23,7 +23,7 @@
#include "treewidget.h"
#include "iconprovider.h"
#include "browsinglibrary.h"
#include "globalfunctions.h"
#include "qztools.h"
#include "followredirectreply.h"
#include "networkmanager.h"
#include "qzsettings.h"

View File

@ -18,7 +18,7 @@
#include "certificateinfowidget.h"
#include "ui_certificateinfowidget.h"
#include "mainapplication.h"
#include "globalfunctions.h"
#include "qztools.h"
#include <QSslCertificate>
#include <QDateTime>
@ -42,7 +42,7 @@ QString CertificateInfoWidget::certificateItemText(const QSslCertificate &cert)
QString CertificateInfoWidget::clearCertSpecialSymbols(const QString &string)
{
QString n = qz_escape(string);
QString n = QzTools::escape(string);
if (!n.contains(QLatin1String("\\"))) {
return n;

View File

@ -1,74 +0,0 @@
/* ============================================================
* QupZilla - WebKit based browser
* Copyright (C) 2010-2012 David Rosca <nowrep@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 3 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. If not, see <http://www.gnu.org/licenses/>.
* ============================================================ */
#ifndef GLOBALFUNCTIONS_H
#define GLOBALFUNCTIONS_H
#include <QList>
#include <QString>
#include "qz_namespace.h"
class QSslCertificate;
class QFontMetrics;
class QPixmap;
class QIcon;
class QWidget;
class QUrl;
QByteArray QT_QUPZILLA_EXPORT qz_pixmapToByteArray(const QPixmap &pix);
QPixmap QT_QUPZILLA_EXPORT qz_pixmapFromByteArray(const QByteArray &data);
QString QT_QUPZILLA_EXPORT qz_readAllFileContents(const QString &filename);
void QT_QUPZILLA_EXPORT qz_centerWidgetOnScreen(QWidget* w);
void QT_QUPZILLA_EXPORT qz_centerWidgetToParent(QWidget* w, QWidget* parent);
bool QT_QUPZILLA_EXPORT qz_removeFile(const QString &fullFileName);
void QT_QUPZILLA_EXPORT qz_removeDir(const QString &d);
QString QT_QUPZILLA_EXPORT qz_samePartOfStrings(const QString &one, const QString &other);
QUrl QT_QUPZILLA_EXPORT qz_makeRelativeUrl(const QUrl &baseUrl, const QUrl &rUrl);
QString QT_QUPZILLA_EXPORT qz_urlEncodeQueryString(const QUrl &url);
QString QT_QUPZILLA_EXPORT qz_ensureUniqueFilename(const QString &name, const QString &appendFormat = QString("(%1)"));
QString QT_QUPZILLA_EXPORT qz_getFileNameFromUrl(const QUrl &url);
QString QT_QUPZILLA_EXPORT qz_filterCharsFromFilename(const QString &name);
QString QT_QUPZILLA_EXPORT qz_alignTextToWidth(const QString &string, const QString &text, const QFontMetrics &metrics, int width);
QString QT_QUPZILLA_EXPORT qz_fileSizeToString(qint64 size);
QPixmap QT_QUPZILLA_EXPORT qz_createPixmapForSite(const QIcon &icon, const QString &title, const QString &url);
QString QT_QUPZILLA_EXPORT qz_applyDirectionToPage(QString &pageContents);
QString QT_QUPZILLA_EXPORT qz_buildSystem();
// Qt5 migration help functions
bool QT_QUPZILLA_EXPORT qz_isCertificateValid(const QSslCertificate &cert);
QString QT_QUPZILLA_EXPORT qz_escape(const QString &string);
#ifdef QZ_WS_X11
void QT_QUPZILLA_EXPORT* qz_X11Display(const QWidget* widget);
#endif
template <typename T>
bool qz_listContainsIndex(const QList<T> &list, int index)
{
return (index >= 0 && list.count() > index);
}
#endif // GLOBALFUNCTIONS_H

View File

@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* ============================================================ */
#include "globalfunctions.h"
#include "qztools.h"
#include <QTextDocument>
#include <QDateTime>
@ -39,7 +39,7 @@
#include <QX11Info>
#endif
QByteArray qz_pixmapToByteArray(const QPixmap &pix)
QByteArray QzTools::pixmapToByteArray(const QPixmap &pix)
{
QByteArray bytes;
QBuffer buffer(&bytes);
@ -51,7 +51,7 @@ QByteArray qz_pixmapToByteArray(const QPixmap &pix)
return QByteArray();
}
QPixmap qz_pixmapFromByteArray(const QByteArray &data)
QPixmap QzTools::pixmapFromByteArray(const QByteArray &data)
{
QPixmap image;
QByteArray bArray = QByteArray::fromBase64(data);
@ -60,7 +60,7 @@ QPixmap qz_pixmapFromByteArray(const QByteArray &data)
return image;
}
QString qz_readAllFileContents(const QString &filename)
QString QzTools::readAllFileContents(const QString &filename)
{
QFile file(filename);
if (file.open(QFile::ReadOnly)) {
@ -72,7 +72,7 @@ QString qz_readAllFileContents(const QString &filename)
return QByteArray();
}
void qz_centerWidgetOnScreen(QWidget* w)
void QzTools::centerWidgetOnScreen(QWidget* w)
{
const QRect screen = QApplication::desktop()->screenGeometry();
const QRect &size = w->geometry();
@ -80,7 +80,7 @@ void qz_centerWidgetOnScreen(QWidget* w)
}
// Very, very, very simplified QDialog::adjustPosition from qdialog.cpp
void qz_centerWidgetToParent(QWidget* w, QWidget* parent)
void QzTools::centerWidgetToParent(QWidget* w, QWidget* parent)
{
if (!parent || !w) {
return;
@ -95,7 +95,7 @@ void qz_centerWidgetToParent(QWidget* w, QWidget* parent)
w->move(p);
}
bool qz_removeFile(const QString &fullFileName)
bool QzTools::removeFile(const QString &fullFileName)
{
QFile f(fullFileName);
if (f.exists()) {
@ -106,7 +106,7 @@ bool qz_removeFile(const QString &fullFileName)
}
}
void qz_removeDir(const QString &d)
void QzTools::removeDir(const QString &d)
{
QDir dir(d);
if (dir.exists()) {
@ -115,10 +115,10 @@ void qz_removeDir(const QString &d)
for (int l = 0; l < list.size(); l++) {
fi = list.at(l);
if (fi.isDir() && fi.fileName() != QLatin1String(".") && fi.fileName() != QLatin1String("..")) {
qz_removeDir(fi.absoluteFilePath());
QzTools::removeDir(fi.absoluteFilePath());
}
else if (fi.isFile()) {
qz_removeFile(fi.absoluteFilePath());
QzTools::removeFile(fi.absoluteFilePath());
}
}
@ -126,7 +126,7 @@ void qz_removeDir(const QString &d)
}
}
QString qz_samePartOfStrings(const QString &one, const QString &other)
QString QzTools::samePartOfStrings(const QString &one, const QString &other)
{
int i = 0;
int maxSize = qMin(one.size(), other.size());
@ -139,12 +139,12 @@ QString qz_samePartOfStrings(const QString &one, const QString &other)
return one.left(i);
}
QUrl qz_makeRelativeUrl(const QUrl &baseUrl, const QUrl &rUrl)
QUrl QzTools::makeRelativeUrl(const QUrl &baseUrl, const QUrl &rUrl)
{
QString baseUrlPath = baseUrl.path();
QString rUrlPath = rUrl.path();
QString samePart = qz_samePartOfStrings(baseUrlPath, rUrlPath);
QString samePart = QzTools::samePartOfStrings(baseUrlPath, rUrlPath);
QUrl returnUrl;
if (samePart.isEmpty()) {
@ -171,7 +171,7 @@ QUrl qz_makeRelativeUrl(const QUrl &baseUrl, const QUrl &rUrl)
return returnUrl;
}
QString qz_urlEncodeQueryString(const QUrl &url)
QString QzTools::urlEncodeQueryString(const QUrl &url)
{
QString returnString = url.toString(QUrl::RemoveQuery | QUrl::RemoveFragment);
@ -196,7 +196,7 @@ QString qz_urlEncodeQueryString(const QUrl &url)
return returnString;
}
QString qz_ensureUniqueFilename(const QString &name, const QString &appendFormat)
QString QzTools::ensureUniqueFilename(const QString &name, const QString &appendFormat)
{
if (!QFile::exists(name)) {
return name;
@ -220,7 +220,7 @@ QString qz_ensureUniqueFilename(const QString &name, const QString &appendFormat
return tmpFileName;
}
QString qz_getFileNameFromUrl(const QUrl &url)
QString QzTools::getFileNameFromUrl(const QUrl &url)
{
QString fileName = url.toString(QUrl::RemoveFragment | QUrl::RemoveQuery | QUrl::RemoveScheme | QUrl::RemovePort);
if (fileName.indexOf(QLatin1Char('/')) != -1) {
@ -229,16 +229,16 @@ QString qz_getFileNameFromUrl(const QUrl &url)
fileName.remove(QLatin1Char('/'));
}
fileName = qz_filterCharsFromFilename(fileName);
fileName = filterCharsFromFilename(fileName);
if (fileName.isEmpty()) {
fileName = qz_filterCharsFromFilename(url.host().replace(QLatin1Char('.'), QLatin1Char('-')));
fileName = filterCharsFromFilename(url.host().replace(QLatin1Char('.'), QLatin1Char('-')));
}
return fileName;
}
QString qz_filterCharsFromFilename(const QString &name)
QString QzTools::filterCharsFromFilename(const QString &name)
{
QString value = name;
@ -255,7 +255,7 @@ QString qz_filterCharsFromFilename(const QString &name)
return value;
}
QString qz_alignTextToWidth(const QString &string, const QString &text, const QFontMetrics &metrics, int width)
QString QzTools::alignTextToWidth(const QString &string, const QString &text, const QFontMetrics &metrics, int width)
{
int pos = 0;
QString returnString;
@ -283,7 +283,7 @@ QString qz_alignTextToWidth(const QString &string, const QString &text, const QF
return returnString;
}
QString qz_fileSizeToString(qint64 size)
QString QzTools::fileSizeToString(qint64 size)
{
if (size < 0) {
return QObject::tr("Unknown size");
@ -305,7 +305,7 @@ QString qz_fileSizeToString(qint64 size)
}
QPixmap qz_createPixmapForSite(const QIcon &icon, const QString &title, const QString &url)
QPixmap QzTools::createPixmapForSite(const QIcon &icon, const QString &title, const QString &url)
{
const QFontMetrics fontMetrics = QApplication::fontMetrics();
const int padding = 4;
@ -341,7 +341,7 @@ QPixmap qz_createPixmapForSite(const QIcon &icon, const QString &title, const QS
return pixmap;
}
QString QT_QUPZILLA_EXPORT qz_applyDirectionToPage(QString &pageContents)
QString QzTools::applyDirectionToPage(QString &pageContents)
{
QString direction = QLatin1String("ltr");
QString right_str = QLatin1String("right");
@ -361,7 +361,7 @@ QString QT_QUPZILLA_EXPORT qz_applyDirectionToPage(QString &pageContents)
}
// Qt5 migration help functions
bool QT_QUPZILLA_EXPORT qz_isCertificateValid(const QSslCertificate &cert)
bool QzTools::isCertificateValid(const QSslCertificate &cert)
{
#if QT_VERSION >= 0x050000
const QDateTime currentTime = QDateTime::currentDateTime();
@ -373,7 +373,7 @@ bool QT_QUPZILLA_EXPORT qz_isCertificateValid(const QSslCertificate &cert)
#endif
}
QString QT_QUPZILLA_EXPORT qz_escape(const QString &string)
QString QzTools::escape(const QString &string)
{
#if QT_VERSION >= 0x050000
return string.toHtmlEscaped();
@ -383,7 +383,7 @@ QString QT_QUPZILLA_EXPORT qz_escape(const QString &string)
}
#ifdef QZ_WS_X11
void QT_QUPZILLA_EXPORT* qz_X11Display(const QWidget* widget)
void* QzTools::X11Display(const QWidget* widget)
{
Q_UNUSED(widget)
@ -395,7 +395,7 @@ void QT_QUPZILLA_EXPORT* qz_X11Display(const QWidget* widget)
}
#endif
QString qz_buildSystem()
QString QzTools::buildSystem()
{
#ifdef Q_OS_LINUX
return "Linux";

77
src/lib/tools/qztools.h Normal file
View File

@ -0,0 +1,77 @@
/* ============================================================
* QupZilla - WebKit based browser
* Copyright (C) 2010-2012 David Rosca <nowrep@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 3 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. If not, see <http://www.gnu.org/licenses/>.
* ============================================================ */
#ifndef GLOBALFUNCTIONS_H
#define GLOBALFUNCTIONS_H
#include <QList>
#include <QString>
#include "qz_namespace.h"
class QSslCertificate;
class QFontMetrics;
class QPixmap;
class QIcon;
class QWidget;
class QUrl;
namespace QzTools {
QByteArray QT_QUPZILLA_EXPORT pixmapToByteArray(const QPixmap &pix);
QPixmap QT_QUPZILLA_EXPORT pixmapFromByteArray(const QByteArray &data);
QString QT_QUPZILLA_EXPORT readAllFileContents(const QString &filename);
void QT_QUPZILLA_EXPORT centerWidgetOnScreen(QWidget* w);
void QT_QUPZILLA_EXPORT centerWidgetToParent(QWidget* w, QWidget* parent);
bool QT_QUPZILLA_EXPORT removeFile(const QString &fullFileName);
void QT_QUPZILLA_EXPORT removeDir(const QString &d);
QString QT_QUPZILLA_EXPORT samePartOfStrings(const QString &one, const QString &other);
QUrl QT_QUPZILLA_EXPORT makeRelativeUrl(const QUrl &baseUrl, const QUrl &rUrl);
QString QT_QUPZILLA_EXPORT urlEncodeQueryString(const QUrl &url);
QString QT_QUPZILLA_EXPORT ensureUniqueFilename(const QString &name, const QString &appendFormat = QString("(%1)"));
QString QT_QUPZILLA_EXPORT getFileNameFromUrl(const QUrl &url);
QString QT_QUPZILLA_EXPORT filterCharsFromFilename(const QString &name);
QString QT_QUPZILLA_EXPORT alignTextToWidth(const QString &string, const QString &text, const QFontMetrics &metrics, int width);
QString QT_QUPZILLA_EXPORT fileSizeToString(qint64 size);
QPixmap QT_QUPZILLA_EXPORT createPixmapForSite(const QIcon &icon, const QString &title, const QString &url);
QString QT_QUPZILLA_EXPORT applyDirectionToPage(QString &pageContents);
QString QT_QUPZILLA_EXPORT buildSystem();
// Qt5 migration help functions
bool QT_QUPZILLA_EXPORT isCertificateValid(const QSslCertificate &cert);
QString QT_QUPZILLA_EXPORT escape(const QString &string);
#ifdef QZ_WS_X11
void QT_QUPZILLA_EXPORT* X11Display(const QWidget* widget);
#endif
template <typename T>
bool listContainsIndex(const QList<T> &list, int index)
{
return (index >= 0 && list.count() > index);
}
} // namespace
#endif // GLOBALFUNCTIONS_H

View File

@ -23,7 +23,7 @@
#include "mainapplication.h"
#include "downloaditem.h"
#include "certificateinfowidget.h"
#include "globalfunctions.h"
#include "qztools.h"
#include "iconprovider.h"
#include <QMenu>
@ -74,7 +74,7 @@ SiteInfo::SiteInfo(WebView* view, QWidget* parent)
//GENERAL
ui->heading->setText(QString("<b>%1</b>:").arg(title));
ui->siteAddress->setText(view->url().toString());
ui->sizeLabel->setText(qz_fileSizeToString(webPage->totalBytes()));
ui->sizeLabel->setText(QzTools::fileSizeToString(webPage->totalBytes()));
QString encoding;
//Meta
@ -152,7 +152,7 @@ SiteInfo::SiteInfo(WebView* view, QWidget* parent)
}
//SECURITY
if (qz_isCertificateValid(cert)) {
if (QzTools::isCertificateValid(cert)) {
ui->securityLabel->setText(tr("<b>Connection is Encrypted.</b>"));
ui->certLabel->setText(tr("<b>Your connection to this page is secured with this certificate: </b>"));
m_certWidget = new CertificateInfoWidget(cert);
@ -212,7 +212,7 @@ void SiteInfo::databaseItemChanged(QListWidgetItem* item)
ui->databaseName->setText(QString("%1 (%2)").arg(db.displayName(), db.name()));
ui->databasePath->setText(db.fileName());
ui->databaseSize->setText(qz_fileSizeToString(db.size()));
ui->databaseSize->setText(QzTools::fileSizeToString(db.size()));
}
void SiteInfo::copyActionData()
@ -234,7 +234,7 @@ void SiteInfo::downloadImage()
return;
}
QString imageFileName = qz_getFileNameFromUrl(QUrl(item->text(1)));
QString imageFileName = QzTools::getFileNameFromUrl(QUrl(item->text(1)));
QString filePath = QFileDialog::getSaveFileName(this, tr("Save image..."), QDir::homePath() + "/" + imageFileName);
if (filePath.isEmpty()) {
@ -268,7 +268,7 @@ void SiteInfo::showImagePreview(QTreeWidgetItem* item)
if (imageUrl.scheme() == QLatin1String("data")) {
QByteArray encodedUrl = item->text(1).toUtf8();
QByteArray imageData = encodedUrl.mid(encodedUrl.indexOf(',') + 1);
m_activePixmap = qz_pixmapFromByteArray(imageData);
m_activePixmap = QzTools::pixmapFromByteArray(imageData);
}
else if (imageUrl.scheme() == QLatin1String("file")) {
m_activePixmap = QPixmap(imageUrl.toLocalFile());

View File

@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* ============================================================ */
#include "globalfunctions.h"
#include "qztools.h"
#include "siteinfowidget.h"
#include "ui_siteinfowidget.h"
#include "qupzilla.h"
@ -40,7 +40,7 @@ SiteInfoWidget::SiteInfoWidget(QupZilla* mainClass, QWidget* parent)
WebPage* webPage = view->page();
QUrl url = view->url();
if (qz_isCertificateValid(webPage->sslCertificate())) {
if (QzTools::isCertificateValid(webPage->sslCertificate())) {
ui->secureLabel->setText(tr("Your connection to this site is <b>secured</b>."));
ui->secureIcon->setPixmap(QPixmap(":/icons/locationbar/accept.png"));
}

View File

@ -25,7 +25,7 @@
#include "mainapplication.h"
#include "checkboxdialog.h"
#include "widget.h"
#include "globalfunctions.h"
#include "qztools.h"
#include "speeddial.h"
#include "popupwebpage.h"
#include "popupwebview.h"
@ -197,11 +197,11 @@ void WebPage::progress(int prog)
{
m_loadProgress = prog;
bool secStatus = qz_isCertificateValid(sslCertificate());
bool secStatus = QzTools::isCertificateValid(sslCertificate());
if (secStatus != m_secureStatus) {
m_secureStatus = secStatus;
emit privacyChanged(qz_isCertificateValid(sslCertificate()));
emit privacyChanged(QzTools::isCertificateValid(sslCertificate()));
}
}
@ -328,7 +328,7 @@ void WebPage::handleUnknownProtocol(const QUrl &url)
CheckBoxDialog dialog(QDialogButtonBox::Yes | QDialogButtonBox::No, view());
const QString &wrappedUrl = qz_alignTextToWidth(url.toString(), "<br/>", dialog.fontMetrics(), 450);
const QString &wrappedUrl = QzTools::alignTextToWidth(url.toString(), "<br/>", dialog.fontMetrics(), 450);
const QString &text = tr("QupZilla cannot handle <b>%1:</b> links. The requested link "
"is <ul><li>%2</li></ul>Do you want QupZilla to try "
"open this link in system application?").arg(protocol, wrappedUrl);
@ -451,7 +451,7 @@ void WebPage::setSSLCertificate(const QSslCertificate &cert)
QSslCertificate WebPage::sslCertificate()
{
if (url().scheme() == QLatin1String("https") && qz_isCertificateValid(m_sslCert)) {
if (url().scheme() == QLatin1String("https") && QzTools::isCertificateValid(m_sslCert)) {
return m_sslCert;
}
@ -703,13 +703,13 @@ bool WebPage::extension(Extension extension, const ExtensionOption* option, Exte
QString rule = exOption->errorString;
rule.remove(QLatin1String("AdBlock: "));
QString errString = qz_readAllFileContents(":/html/adblockPage.html");
QString errString = QzTools::readAllFileContents(":/html/adblockPage.html");
errString.replace(QLatin1String("%TITLE%"), tr("AdBlocked Content"));
errString.replace(QLatin1String("%IMAGE%"), QLatin1String("qrc:html/adblock_big.png"));
errString.replace(QLatin1String("%FAVICON%"), QLatin1String("qrc:html/adblock_big.png"));
errString.replace(QLatin1String("%RULE%"), tr("Blocked by <i>%1</i>").arg(rule));
errString = qz_applyDirectionToPage(errString);
errString = QzTools::applyDirectionToPage(errString);
exReturn->baseUrl = exOption->url;
exReturn->content = QString(errString + "<span id=\"qupzilla-error-page\"></span>").toUtf8();
@ -754,8 +754,8 @@ bool WebPage::extension(Extension extension, const ExtensionOption* option, Exte
QString errString = file.readAll();
errString.replace(QLatin1String("%TITLE%"), tr("Failed loading page"));
errString.replace(QLatin1String("%IMAGE%"), qz_pixmapToByteArray(qIconProvider->standardIcon(QStyle::SP_MessageBoxWarning).pixmap(45, 45)));
errString.replace(QLatin1String("%FAVICON%"), qz_pixmapToByteArray(qIconProvider->standardIcon(QStyle::SP_MessageBoxWarning).pixmap(16, 16)));
errString.replace(QLatin1String("%IMAGE%"), QzTools::pixmapToByteArray(qIconProvider->standardIcon(QStyle::SP_MessageBoxWarning).pixmap(45, 45)));
errString.replace(QLatin1String("%FAVICON%"), QzTools::pixmapToByteArray(qIconProvider->standardIcon(QStyle::SP_MessageBoxWarning).pixmap(16, 16)));
errString.replace(QLatin1String("%BOX-BORDER%"), QLatin1String("qrc:html/box-border.png"));
QString heading2 = loadedUrl.host().isEmpty() ? tr("QupZilla can't load page.") : tr("QupZilla can't load page from %1.").arg(loadedUrl.host());
@ -766,7 +766,7 @@ bool WebPage::extension(Extension extension, const ExtensionOption* option, Exte
errString.replace(QLatin1String("%LI-2%"), tr("If you are unable to load any pages, check your computer's network connection."));
errString.replace(QLatin1String("%LI-3%"), tr("If your computer or network is protected by a firewall or proxy, make sure that QupZilla is permitted to access the Web."));
errString.replace(QLatin1String("%TRY-AGAIN%"), tr("Try Again"));
errString = qz_applyDirectionToPage(errString);
errString = QzTools::applyDirectionToPage(errString);
exReturn->content = QString(errString + "<span id=\"qupzilla-error-page\"></span>").toUtf8();
return true;

View File

@ -22,7 +22,7 @@
#include "tabbar.h"
#include "tabwidget.h"
#include "locationbar.h"
#include "globalfunctions.h"
#include "qztools.h"
#include "qzsettings.h"
#include <QVBoxLayout>

View File

@ -19,7 +19,7 @@
#include "webview.h"
#include "webpage.h"
#include "mainapplication.h"
#include "globalfunctions.h"
#include "qztools.h"
#include "iconprovider.h"
#include "history.h"
#include "autofillmodel.h"
@ -440,7 +440,7 @@ void WebView::copyLinkToClipboard()
void WebView::savePageAs()
{
QNetworkRequest request(url());
QString suggestedFileName = qz_getFileNameFromUrl(url());
QString suggestedFileName = QzTools::getFileNameFromUrl(url());
if (!suggestedFileName.contains(QLatin1Char('.'))) {
suggestedFileName.append(QLatin1String(".html"));
}
@ -490,7 +490,7 @@ void WebView::showSource(QWebFrame* frame, const QString &selectedHtml)
}
SourceViewer* source = new SourceViewer(frame, selectedHtml);
qz_centerWidgetToParent(source, this);
QzTools::centerWidgetToParent(source, this);
source->show();
}

View File

@ -25,7 +25,7 @@
#include "qupzilla.h"
#include "tabwidget.h"
#include "tabbedwebview.h"
#include "globalfunctions.h"
#include "qztools.h"
#include <QFile>
#include <QDir>
@ -66,7 +66,7 @@ void GM_AddScriptDialog::showSource()
return;
}
const QString &tmpFileName = qz_ensureUniqueFilename(mApp->tempPath() + "/tmp-userscript.js");
const QString &tmpFileName = QzTools::ensureUniqueFilename(mApp->tempPath() + "/tmp-userscript.js");
if (QFile::copy(m_script->fileName(), tmpFileName)) {
int index = qz->tabWidget()->addView(QUrl::fromLocalFile(tmpFileName), Qz::NT_SelectedTabAtTheEnd);

View File

@ -24,7 +24,7 @@
#include "followredirectreply.h"
#include "mainapplication.h"
#include "networkmanager.h"
#include "globalfunctions.h"
#include "qztools.h"
#include <QFile>
#include <QSettings>
@ -55,8 +55,8 @@ void GM_Downloader::scriptDownloaded()
QByteArray response = QString::fromUtf8(m_reply->readAll()).toUtf8();
if (m_reply->error() == QNetworkReply::NoError && response.contains("// ==UserScript==")) {
const QString &filePath = m_manager->scriptsDirectory() + qz_getFileNameFromUrl(m_reply->url());
m_fileName = qz_ensureUniqueFilename(filePath);
const QString &filePath = m_manager->scriptsDirectory() + QzTools::getFileNameFromUrl(m_reply->url());
m_fileName = QzTools::ensureUniqueFilename(filePath);
QFile file(m_fileName);
@ -101,7 +101,7 @@ void GM_Downloader::requireDownloaded()
if (m_reply->error() == QNetworkReply::NoError && !response.isEmpty()) {
const QString &filePath = m_manager->settinsPath() + "/greasemonkey/requires/require.js";
const QString &fileName = qz_ensureUniqueFilename(filePath, "%1");
const QString &fileName = QzTools::ensureUniqueFilename(filePath, "%1");
QFile file(fileName);

View File

@ -21,7 +21,7 @@
#include "settings/gm_settings.h"
#include "webpage.h"
#include "globalfunctions.h"
#include "qztools.h"
#include "mainapplication.h"
#include "desktopnotificationsfactory.h"
@ -78,7 +78,7 @@ QString GM_Manager::requireScripts(const QStringList &urlList) const
foreach(const QString & url, urlList) {
if (settings.contains(url)) {
const QString &fileName = settings.value(url).toString();
script.append(qz_readAllFileContents(fileName).trimmed() + '\n');
script.append(QzTools::readAllFileContents(fileName).trimmed() + '\n');
}
}
@ -240,7 +240,7 @@ void GM_Manager::load()
}
}
m_bootstrap = qz_readAllFileContents(":gm/data/bootstrap.min.js");
m_bootstrap = QzTools::readAllFileContents(":gm/data/bootstrap.min.js");
}
bool GM_Manager::canRunOnScheme(const QString &scheme)