1
mirror of https://invent.kde.org/network/falkon.git synced 2024-11-11 01:22:10 +01:00

[QzTools] Make QzTools class and export only the class

Also fixed building on Windows
This commit is contained in:
nowrep 2014-03-07 22:54:50 +01:00
parent fdf4fcc54e
commit 417da146e5
6 changed files with 61 additions and 71 deletions

View File

@ -301,7 +301,7 @@ QString AdBlockSubscription::elementHidingRulesForDomain(const QString &domain)
const AdBlockRule* AdBlockSubscription::rule(int offset) const const AdBlockRule* AdBlockSubscription::rule(int offset) const
{ {
if (!QzTools::vectorContainsIndex(m_rules, offset)) { if (!QzTools::containsIndex(m_rules, offset)) {
return 0; return 0;
} }
@ -315,7 +315,7 @@ QVector<AdBlockRule*> AdBlockSubscription::allRules() const
const AdBlockRule* AdBlockSubscription::enableRule(int offset) const AdBlockRule* AdBlockSubscription::enableRule(int offset)
{ {
if (!QzTools::vectorContainsIndex(m_rules, offset)) { if (!QzTools::containsIndex(m_rules, offset)) {
return 0; return 0;
} }
@ -333,7 +333,7 @@ const AdBlockRule* AdBlockSubscription::enableRule(int offset)
const AdBlockRule* AdBlockSubscription::disableRule(int offset) const AdBlockRule* AdBlockSubscription::disableRule(int offset)
{ {
if (!QzTools::vectorContainsIndex(m_rules, offset)) { if (!QzTools::containsIndex(m_rules, offset)) {
return 0; return 0;
} }
@ -528,7 +528,7 @@ int AdBlockCustomList::addRule(AdBlockRule* rule)
bool AdBlockCustomList::removeRule(int offset) bool AdBlockCustomList::removeRule(int offset)
{ {
if (!QzTools::vectorContainsIndex(m_rules, offset)) { if (!QzTools::containsIndex(m_rules, offset)) {
return false; return false;
} }
@ -548,7 +548,7 @@ bool AdBlockCustomList::removeRule(int offset)
const AdBlockRule* AdBlockCustomList::replaceRule(AdBlockRule* rule, int offset) const AdBlockRule* AdBlockCustomList::replaceRule(AdBlockRule* rule, int offset)
{ {
if (!QzTools::vectorContainsIndex(m_rules, offset)) { if (!QzTools::containsIndex(m_rules, offset)) {
return 0; return 0;
} }

View File

@ -1100,7 +1100,7 @@ bool MainApplication::checkDefaultWebBrowser()
dialog.setCheckBoxText(tr("Always perform this check when starting QupZilla.")); dialog.setCheckBoxText(tr("Always perform this check when starting QupZilla."));
dialog.setDefaultCheckState(Qt::Checked); dialog.setDefaultCheckState(Qt::Checked);
dialog.setWindowTitle(tr("Default Browser")); dialog.setWindowTitle(tr("Default Browser"));
dialog.setIcon(qIconProvider->standardIcon(QStyle::SP_MessageBoxWarning)); dialog.setIcon(IconProvider::standardIcon(QStyle::SP_MessageBoxWarning));
if (dialog.exec() == QDialog::Accepted) { if (dialog.exec() == QDialog::Accepted) {
associationManager()->registerAllAssociation(); associationManager()->registerAllAssociation();

View File

@ -65,7 +65,7 @@ void AutoFillWidget::loginToPage()
bool ok; bool ok;
int index = button->property("data-index").toInt(&ok); int index = button->property("data-index").toInt(&ok);
if (ok && QzTools::vectorContainsIndex(m_data, index)) { if (ok && QzTools::containsIndex(m_data, index)) {
const PasswordEntry entry = m_data.at(index); const PasswordEntry entry = m_data.at(index);
PageFormCompleter completer(m_view->page()); PageFormCompleter completer(m_view->page());

View File

@ -82,7 +82,7 @@ void HistoryItem::insertChild(int row, HistoryItem* child)
void HistoryItem::removeChild(int row) void HistoryItem::removeChild(int row)
{ {
if (QzTools::listContainsIndex(m_children, row)) { if (QzTools::containsIndex(m_children, row)) {
removeChild(m_children.at(row)); removeChild(m_children.at(row));
} }
} }
@ -94,7 +94,7 @@ void HistoryItem::removeChild(HistoryItem* child)
HistoryItem* HistoryItem::child(int row) const HistoryItem* HistoryItem::child(int row) const
{ {
if (QzTools::listContainsIndex(m_children, row)) { if (QzTools::containsIndex(m_children, row)) {
return m_children.at(row); return m_children.at(row);
} }

View File

@ -787,19 +787,21 @@ QString QzTools::escape(const QString &string)
#endif #endif
} }
#ifdef QZ_WS_X11
void* QzTools::X11Display(const QWidget* widget) void* QzTools::X11Display(const QWidget* widget)
{ {
Q_UNUSED(widget) Q_UNUSED(widget)
#ifdef QZ_WS_X11
#if QT_VERSION >= 0x050000 #if QT_VERSION >= 0x050000
return qApp->platformNativeInterface()->nativeResourceForWindow("display", widget->windowHandle()); return qApp->platformNativeInterface()->nativeResourceForWindow("display", widget->windowHandle());
#else #else
return QX11Info::display(); return QX11Info::display();
#endif #endif
}
#endif #endif
return 0;
}
void QzTools::setWmClass(const QString &name, const QWidget* widget) void QzTools::setWmClass(const QString &name, const QWidget* widget)
{ {
#ifdef QZ_WS_X11 #ifdef QZ_WS_X11

View File

@ -15,12 +15,9 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
* ============================================================ */ * ============================================================ */
#ifndef GLOBALFUNCTIONS_H #ifndef QZTOOLS_H
#define GLOBALFUNCTIONS_H #define QZTOOLS_H
#include <QList>
#include <QString>
#include <QRegion>
#include <QFileDialog> #include <QFileDialog>
#include "qzcommon.h" #include "qzcommon.h"
@ -32,76 +29,67 @@ class QIcon;
class QWidget; class QWidget;
class QUrl; class QUrl;
namespace QzTools class QUPZILLA_EXPORT QzTools
{ {
QByteArray QUPZILLA_EXPORT pixmapToByteArray(const QPixmap &pix); public:
QPixmap QUPZILLA_EXPORT pixmapFromByteArray(const QByteArray &data); static QByteArray pixmapToByteArray(const QPixmap &pix);
static QPixmap pixmapFromByteArray(const QByteArray &data);
QString QUPZILLA_EXPORT readAllFileContents(const QString &filename); static QString readAllFileContents(const QString &filename);
QByteArray QUPZILLA_EXPORT readAllFileByteContents(const QString &filename); static QByteArray readAllFileByteContents(const QString &filename);
void QUPZILLA_EXPORT centerWidgetOnScreen(QWidget* w); static void centerWidgetOnScreen(QWidget* w);
void QUPZILLA_EXPORT centerWidgetToParent(QWidget* w, QWidget* parent); static void centerWidgetToParent(QWidget* w, QWidget* parent);
bool QUPZILLA_EXPORT removeFile(const QString &fullFileName); static bool removeFile(const QString &fullFileName);
void QUPZILLA_EXPORT removeDir(const QString &d); static void removeDir(const QString &d);
QString QUPZILLA_EXPORT samePartOfStrings(const QString &one, const QString &other); static QString samePartOfStrings(const QString &one, const QString &other);
QString QUPZILLA_EXPORT urlEncodeQueryString(const QUrl &url); static QString urlEncodeQueryString(const QUrl &url);
QString QUPZILLA_EXPORT ensureUniqueFilename(const QString &name, const QString &appendFormat = QString("(%1)")); static QString ensureUniqueFilename(const QString &name, const QString &appendFormat = QString("(%1)"));
QString QUPZILLA_EXPORT getFileNameFromUrl(const QUrl &url); static QString getFileNameFromUrl(const QUrl &url);
QString QUPZILLA_EXPORT filterCharsFromFilename(const QString &name); static QString filterCharsFromFilename(const QString &name);
QString QUPZILLA_EXPORT lastPathForFileDialog(const QString &dialogName, const QString &fallbackPath); static QString lastPathForFileDialog(const QString &dialogName, const QString &fallbackPath);
void QUPZILLA_EXPORT saveLastPathForFileDialog(const QString &dialogName, const QString &path); static void saveLastPathForFileDialog(const QString &dialogName, const QString &path);
QString QUPZILLA_EXPORT alignTextToWidth(const QString &string, const QString &text, const QFontMetrics &metrics, int width); static QString alignTextToWidth(const QString &string, const QString &text, const QFontMetrics &metrics, int width);
QString QUPZILLA_EXPORT fileSizeToString(qint64 size); static QString fileSizeToString(qint64 size);
QPixmap QUPZILLA_EXPORT createPixmapForSite(const QIcon &icon, const QString &title, const QString &url); static QPixmap createPixmapForSite(const QIcon &icon, const QString &title, const QString &url);
QString QUPZILLA_EXPORT applyDirectionToPage(QString &pageContents); static QString applyDirectionToPage(QString &pageContents);
QString QUPZILLA_EXPORT resolveFromPath(const QString &name); static QString resolveFromPath(const QString &name);
QStringList QUPZILLA_EXPORT splitCommandArguments(const QString &command); static QStringList splitCommandArguments(const QString &command);
bool QUPZILLA_EXPORT startExternalProcess(const QString &executable, const QString &args); static bool startExternalProcess(const QString &executable, const QString &args);
QRegion QUPZILLA_EXPORT roundedRect(const QRect &rect, int radius); static QRegion roundedRect(const QRect &rect, int radius);
QIcon QUPZILLA_EXPORT iconFromFileName(const QString &fileName); static QIcon iconFromFileName(const QString &fileName);
bool QUPZILLA_EXPORT isUtf8(const char* string); static bool isUtf8(const char* string);
// QFileDialog static functions that remembers last used directory // QFileDialog static functions that remembers last used directory
QString QUPZILLA_EXPORT getExistingDirectory(const QString &name, QWidget* parent = 0, const QString &caption = QString(), const QString &dir = QString(), QFileDialog::Options options = QFileDialog::ShowDirsOnly); static QString getExistingDirectory(const QString &name, QWidget* parent = 0, const QString &caption = QString(), const QString &dir = QString(), QFileDialog::Options options = QFileDialog::ShowDirsOnly);
QString QUPZILLA_EXPORT getOpenFileName(const QString &name, QWidget* parent = 0, const QString &caption = QString(), const QString &dir = QString(), const QString &filter = QString(), QString* selectedFilter = 0, QFileDialog::Options options = 0); static QString getOpenFileName(const QString &name, QWidget* parent = 0, const QString &caption = QString(), const QString &dir = QString(), const QString &filter = QString(), QString* selectedFilter = 0, QFileDialog::Options options = 0);
QStringList QUPZILLA_EXPORT getOpenFileNames(const QString &name, QWidget* parent = 0, const QString &caption = QString(), const QString &dir = QString(), const QString &filter = QString(), QString* selectedFilter = 0, QFileDialog::Options options = 0); static QStringList getOpenFileNames(const QString &name, QWidget* parent = 0, const QString &caption = QString(), const QString &dir = QString(), const QString &filter = QString(), QString* selectedFilter = 0, QFileDialog::Options options = 0);
QString QUPZILLA_EXPORT getSaveFileName(const QString &name, QWidget* parent = 0, const QString &caption = QString(), const QString &dir = QString(), const QString &filter = QString(), QString* selectedFilter = 0, QFileDialog::Options options = 0); static QString getSaveFileName(const QString &name, QWidget* parent = 0, const QString &caption = QString(), const QString &dir = QString(), const QString &filter = QString(), QString* selectedFilter = 0, QFileDialog::Options options = 0);
bool QUPZILLA_EXPORT matchDomain(const QString &pattern, const QString &domain); static bool matchDomain(const QString &pattern, const QString &domain);
QString QUPZILLA_EXPORT operatingSystem(); static QString operatingSystem();
// Qt5 migration help functions // Qt5 migration help functions
bool QUPZILLA_EXPORT isCertificateValid(const QSslCertificate &cert); static bool isCertificateValid(const QSslCertificate &cert);
QString QUPZILLA_EXPORT escape(const QString &string); static QString escape(const QString &string);
#ifdef QZ_WS_X11 static void* X11Display(const QWidget* widget);
void* X11Display(const QWidget* widget); static void setWmClass(const QString &name, const QWidget* widget);
#endif
void QUPZILLA_EXPORT setWmClass(const QString &name, const QWidget* widget); template <typename T>
static bool containsIndex(const T &container, int index)
{
return (index >= 0 && container.count() > index);
}
};
template <typename T> #endif // QZTOOLS_H
bool listContainsIndex(const QList<T> &list, int index)
{
return (index >= 0 && list.count() > index);
}
template <typename T>
bool vectorContainsIndex(const QVector<T> &list, int index)
{
return (index >= 0 && list.count() > index);
}
} // namespace
#endif // GLOBALFUNCTIONS_H