2013-01-22 19:04:22 +01:00
|
|
|
/* ============================================================
|
|
|
|
* QupZilla - WebKit based browser
|
2016-06-14 10:38:49 +02:00
|
|
|
* Copyright (C) 2010-2016 David Rosca <nowrep@gmail.com>
|
2013-01-22 19:04:22 +01:00
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
* ============================================================ */
|
2014-03-07 22:54:50 +01:00
|
|
|
#ifndef QZTOOLS_H
|
|
|
|
#define QZTOOLS_H
|
2013-01-22 19:04:22 +01:00
|
|
|
|
2013-12-25 19:06:58 +01:00
|
|
|
#include <QFileDialog>
|
2013-01-22 19:04:22 +01:00
|
|
|
|
2014-02-26 20:03:20 +01:00
|
|
|
#include "qzcommon.h"
|
2013-01-22 19:04:22 +01:00
|
|
|
|
|
|
|
class QSslCertificate;
|
|
|
|
class QFontMetrics;
|
|
|
|
class QPixmap;
|
|
|
|
class QIcon;
|
|
|
|
class QWidget;
|
|
|
|
class QUrl;
|
|
|
|
|
2014-03-07 22:54:50 +01:00
|
|
|
class QUPZILLA_EXPORT QzTools
|
2013-01-23 01:34:15 +01:00
|
|
|
{
|
2014-03-07 22:54:50 +01:00
|
|
|
public:
|
|
|
|
static QByteArray pixmapToByteArray(const QPixmap &pix);
|
|
|
|
static QPixmap pixmapFromByteArray(const QByteArray &data);
|
2015-09-25 16:04:12 +02:00
|
|
|
static QUrl pixmapToDataUrl(const QPixmap &pix);
|
2013-01-22 19:04:22 +01:00
|
|
|
|
2014-03-07 22:54:50 +01:00
|
|
|
static QString readAllFileContents(const QString &filename);
|
|
|
|
static QByteArray readAllFileByteContents(const QString &filename);
|
2013-01-22 19:04:22 +01:00
|
|
|
|
2014-03-07 22:54:50 +01:00
|
|
|
static void centerWidgetOnScreen(QWidget* w);
|
|
|
|
static void centerWidgetToParent(QWidget* w, QWidget* parent);
|
2013-01-22 19:04:22 +01:00
|
|
|
|
2014-03-07 22:54:50 +01:00
|
|
|
static bool removeFile(const QString &fullFileName);
|
|
|
|
static void removeDir(const QString &d);
|
2013-01-22 19:04:22 +01:00
|
|
|
|
2014-03-07 22:54:50 +01:00
|
|
|
static QString samePartOfStrings(const QString &one, const QString &other);
|
|
|
|
static QString urlEncodeQueryString(const QUrl &url);
|
2014-06-15 23:30:29 +02:00
|
|
|
static QString fromPunycode(const QString &str);
|
2016-12-20 14:19:58 +01:00
|
|
|
static QString escapeSqlGlobString(QString urlString);
|
2013-01-22 19:04:22 +01:00
|
|
|
|
2014-03-07 22:54:50 +01:00
|
|
|
static QString ensureUniqueFilename(const QString &name, const QString &appendFormat = QString("(%1)"));
|
|
|
|
static QString getFileNameFromUrl(const QUrl &url);
|
|
|
|
static QString filterCharsFromFilename(const QString &name);
|
2013-01-22 19:04:22 +01:00
|
|
|
|
2014-03-07 22:54:50 +01:00
|
|
|
static QString lastPathForFileDialog(const QString &dialogName, const QString &fallbackPath);
|
|
|
|
static void saveLastPathForFileDialog(const QString &dialogName, const QString &path);
|
2013-12-25 19:06:58 +01:00
|
|
|
|
2014-03-07 22:54:50 +01:00
|
|
|
static QString alignTextToWidth(const QString &string, const QString &text, const QFontMetrics &metrics, int width);
|
|
|
|
static QString fileSizeToString(qint64 size);
|
2013-01-22 19:04:22 +01:00
|
|
|
|
2014-03-07 22:54:50 +01:00
|
|
|
static QPixmap createPixmapForSite(const QIcon &icon, const QString &title, const QString &url);
|
|
|
|
static QString applyDirectionToPage(QString &pageContents);
|
2014-03-17 15:01:28 +01:00
|
|
|
static QString truncatedText(const QString &text, int size);
|
2013-01-22 19:04:22 +01:00
|
|
|
|
2014-03-07 22:54:50 +01:00
|
|
|
static QString resolveFromPath(const QString &name);
|
|
|
|
static QStringList splitCommandArguments(const QString &command);
|
|
|
|
static bool startExternalProcess(const QString &executable, const QString &args);
|
2013-02-13 21:48:06 +01:00
|
|
|
|
2014-03-07 22:54:50 +01:00
|
|
|
static QRegion roundedRect(const QRect &rect, int radius);
|
|
|
|
static QIcon iconFromFileName(const QString &fileName);
|
|
|
|
static bool isUtf8(const char* string);
|
2013-01-22 19:04:22 +01:00
|
|
|
|
2015-04-16 17:28:04 +02:00
|
|
|
static bool containsSpace(const QString &str);
|
|
|
|
|
2014-03-07 22:54:50 +01:00
|
|
|
// QFileDialog static functions that remembers last used directory
|
|
|
|
static QString getExistingDirectory(const QString &name, QWidget* parent = 0, const QString &caption = QString(), const QString &dir = QString(), QFileDialog::Options options = QFileDialog::ShowDirsOnly);
|
|
|
|
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);
|
|
|
|
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);
|
|
|
|
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);
|
2013-12-25 19:06:58 +01:00
|
|
|
|
2014-03-07 22:54:50 +01:00
|
|
|
static bool matchDomain(const QString &pattern, const QString &domain);
|
2015-11-12 16:53:09 +01:00
|
|
|
static QKeySequence actionShortcut(QKeySequence shortcut, QKeySequence fallBack, QKeySequence shortcutRtl = QKeySequence(), QKeySequence fallbackRtl = QKeySequence());
|
2013-02-26 15:48:47 +01:00
|
|
|
|
2014-03-07 22:54:50 +01:00
|
|
|
static QString operatingSystem();
|
2016-06-14 10:38:49 +02:00
|
|
|
static QString cpuArchitecture();
|
2016-06-14 11:01:22 +02:00
|
|
|
static QString operatingSystemLong();
|
2013-01-29 19:55:09 +01:00
|
|
|
|
2014-03-07 22:54:50 +01:00
|
|
|
static void setWmClass(const QString &name, const QWidget* widget);
|
2013-01-22 19:04:22 +01:00
|
|
|
|
2014-03-07 22:54:50 +01:00
|
|
|
template <typename T>
|
2014-06-15 23:30:29 +02:00
|
|
|
static bool containsIndex(const T &container, int index)
|
|
|
|
{
|
2014-03-07 22:54:50 +01:00
|
|
|
return (index >= 0 && container.count() > index);
|
|
|
|
}
|
|
|
|
};
|
2013-07-08 00:08:05 +02:00
|
|
|
|
2014-03-07 22:54:50 +01:00
|
|
|
#endif // QZTOOLS_H
|