2011-09-23 22:06:21 +02:00
|
|
|
/* ============================================================
|
|
|
|
* QupZilla - WebKit based browser
|
2014-01-11 16:11:42 +01:00
|
|
|
* Copyright (C) 2010-2014 David Rosca <nowrep@gmail.com>
|
2011-09-23 22:06:21 +02: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/>.
|
|
|
|
* ============================================================ */
|
2013-01-22 19:04:22 +01:00
|
|
|
#include "qztools.h"
|
2014-03-09 21:51:42 +01:00
|
|
|
#include "datapaths.h"
|
2013-12-25 19:06:58 +01:00
|
|
|
#include "settings.h"
|
2011-09-18 15:35:44 +02:00
|
|
|
|
2012-12-20 14:45:35 +01:00
|
|
|
#include <QTextDocument>
|
|
|
|
#include <QDateTime>
|
2012-02-29 18:33:50 +01:00
|
|
|
#include <QByteArray>
|
|
|
|
#include <QPixmap>
|
2012-05-27 14:05:28 +02:00
|
|
|
#include <QPainter>
|
2012-02-29 18:33:50 +01:00
|
|
|
#include <QBuffer>
|
|
|
|
#include <QFile>
|
|
|
|
#include <QDir>
|
|
|
|
#include <QWidget>
|
|
|
|
#include <QApplication>
|
2012-12-20 14:45:35 +01:00
|
|
|
#include <QSslCertificate>
|
2012-02-29 18:33:50 +01:00
|
|
|
#include <QDesktopWidget>
|
|
|
|
#include <QUrl>
|
|
|
|
#include <QIcon>
|
2013-01-28 10:52:55 +01:00
|
|
|
#include <QFileIconProvider>
|
|
|
|
#include <QTemporaryFile>
|
2013-01-29 19:55:09 +01:00
|
|
|
#include <QHash>
|
2013-02-04 13:07:21 +01:00
|
|
|
#include <QSysInfo>
|
2013-02-15 12:29:13 +01:00
|
|
|
#include <QProcess>
|
|
|
|
#include <QMessageBox>
|
2014-09-29 16:03:22 +02:00
|
|
|
#include <QWebFrame>
|
2012-02-29 18:33:50 +01:00
|
|
|
|
2012-12-20 14:45:35 +01:00
|
|
|
#if QT_VERSION >= 0x050000
|
|
|
|
#include <QUrlQuery>
|
2012-12-22 15:01:55 +01:00
|
|
|
#include <qpa/qplatformnativeinterface.h>
|
2013-07-17 16:06:10 +02:00
|
|
|
#else
|
2012-12-22 15:01:55 +01:00
|
|
|
#include <QX11Info>
|
2013-07-17 16:06:10 +02:00
|
|
|
#endif
|
2014-03-03 14:47:47 +01:00
|
|
|
#ifdef QZ_WS_X11
|
2013-07-07 12:32:55 +02:00
|
|
|
#include <X11/Xlib.h>
|
|
|
|
#include <X11/Xutil.h>
|
2012-12-20 14:45:35 +01:00
|
|
|
#endif
|
|
|
|
|
2013-02-24 23:02:55 +01:00
|
|
|
#ifdef Q_OS_WIN
|
|
|
|
#include <windows.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef Q_OS_MAC
|
|
|
|
#include <CoreServices/CoreServices.h>
|
|
|
|
#endif
|
|
|
|
|
2013-01-22 19:04:22 +01:00
|
|
|
QByteArray QzTools::pixmapToByteArray(const QPixmap &pix)
|
2011-09-18 15:35:44 +02:00
|
|
|
{
|
|
|
|
QByteArray bytes;
|
|
|
|
QBuffer buffer(&bytes);
|
|
|
|
buffer.open(QIODevice::WriteOnly);
|
2011-11-06 17:01:23 +01:00
|
|
|
if (pix.save(&buffer, "PNG")) {
|
2011-09-18 15:35:44 +02:00
|
|
|
return buffer.buffer().toBase64();
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-09-18 15:35:44 +02:00
|
|
|
|
|
|
|
return QByteArray();
|
|
|
|
}
|
|
|
|
|
2013-01-22 19:04:22 +01:00
|
|
|
QPixmap QzTools::pixmapFromByteArray(const QByteArray &data)
|
2011-11-05 11:51:46 +01:00
|
|
|
{
|
|
|
|
QPixmap image;
|
|
|
|
QByteArray bArray = QByteArray::fromBase64(data);
|
|
|
|
image.loadFromData(bArray);
|
|
|
|
|
|
|
|
return image;
|
|
|
|
}
|
|
|
|
|
2013-01-22 19:04:22 +01:00
|
|
|
QString QzTools::readAllFileContents(const QString &filename)
|
2014-02-09 18:55:11 +01:00
|
|
|
{
|
|
|
|
return QString::fromUtf8(readAllFileByteContents(filename));
|
|
|
|
}
|
|
|
|
|
|
|
|
QByteArray QzTools::readAllFileByteContents(const QString &filename)
|
2011-09-18 15:35:44 +02:00
|
|
|
{
|
|
|
|
QFile file(filename);
|
2014-02-09 18:55:11 +01:00
|
|
|
|
2014-03-10 00:47:07 +01:00
|
|
|
if (!filename.isEmpty() && file.open(QFile::ReadOnly)) {
|
2014-02-09 18:55:11 +01:00
|
|
|
const QByteArray a = file.readAll();
|
2012-07-08 00:15:03 +02:00
|
|
|
file.close();
|
|
|
|
return a;
|
|
|
|
}
|
2011-09-18 15:35:44 +02:00
|
|
|
|
2014-02-09 18:55:11 +01:00
|
|
|
return QByteArray();
|
2011-09-18 15:35:44 +02:00
|
|
|
}
|
2011-09-21 14:20:49 +02:00
|
|
|
|
2013-01-22 19:04:22 +01:00
|
|
|
void QzTools::centerWidgetOnScreen(QWidget* w)
|
2011-09-21 14:20:49 +02:00
|
|
|
{
|
|
|
|
const QRect screen = QApplication::desktop()->screenGeometry();
|
2013-12-30 13:43:48 +01:00
|
|
|
const QRect size = w->geometry();
|
2011-11-06 17:01:23 +01:00
|
|
|
w->move((screen.width() - size.width()) / 2, (screen.height() - size.height()) / 2);
|
2011-09-21 14:20:49 +02:00
|
|
|
}
|
2011-10-07 15:37:49 +02:00
|
|
|
|
2011-10-26 19:23:50 +02:00
|
|
|
// Very, very, very simplified QDialog::adjustPosition from qdialog.cpp
|
2013-01-22 19:04:22 +01:00
|
|
|
void QzTools::centerWidgetToParent(QWidget* w, QWidget* parent)
|
2011-10-26 19:23:50 +02:00
|
|
|
{
|
2011-11-06 17:01:23 +01:00
|
|
|
if (!parent || !w) {
|
2011-10-26 19:23:50 +02:00
|
|
|
return;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-10-26 19:23:50 +02:00
|
|
|
|
|
|
|
QPoint p;
|
|
|
|
parent = parent->window();
|
2011-11-06 17:01:23 +01:00
|
|
|
QPoint pp = parent->mapToGlobal(QPoint(0, 0));
|
|
|
|
p = QPoint(pp.x() + parent->width() / 2, pp.y() + parent->height() / 2);
|
|
|
|
p = QPoint(p.x() - w->width() / 2, p.y() - w->height() / 2 - 20);
|
2011-10-26 19:23:50 +02:00
|
|
|
|
|
|
|
w->move(p);
|
|
|
|
}
|
|
|
|
|
2013-01-22 19:04:22 +01:00
|
|
|
bool QzTools::removeFile(const QString &fullFileName)
|
2012-01-26 18:23:35 +01:00
|
|
|
{
|
|
|
|
QFile f(fullFileName);
|
|
|
|
if (f.exists()) {
|
|
|
|
return f.remove();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-22 19:04:22 +01:00
|
|
|
void QzTools::removeDir(const QString &d)
|
2012-01-26 18:23:35 +01:00
|
|
|
{
|
|
|
|
QDir dir(d);
|
|
|
|
if (dir.exists()) {
|
|
|
|
const QFileInfoList list = dir.entryInfoList();
|
|
|
|
QFileInfo fi;
|
|
|
|
for (int l = 0; l < list.size(); l++) {
|
|
|
|
fi = list.at(l);
|
2012-09-05 19:57:36 +02:00
|
|
|
if (fi.isDir() && fi.fileName() != QLatin1String(".") && fi.fileName() != QLatin1String("..")) {
|
2013-01-22 19:04:22 +01:00
|
|
|
QzTools::removeDir(fi.absoluteFilePath());
|
2012-01-26 18:23:35 +01:00
|
|
|
}
|
|
|
|
else if (fi.isFile()) {
|
2013-01-22 19:04:22 +01:00
|
|
|
QzTools::removeFile(fi.absoluteFilePath());
|
2012-01-26 18:23:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
dir.rmdir(d);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-24 14:25:26 +01:00
|
|
|
/* Finds same part of @one in @other from the beginning */
|
2013-01-22 19:04:22 +01:00
|
|
|
QString QzTools::samePartOfStrings(const QString &one, const QString &other)
|
2011-10-09 14:51:25 +02:00
|
|
|
{
|
|
|
|
int maxSize = qMin(one.size(), other.size());
|
2013-01-24 14:25:26 +01:00
|
|
|
if (maxSize <= 0) {
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
|
|
|
int i = 0;
|
2011-10-09 14:51:25 +02:00
|
|
|
while (one.at(i) == other.at(i)) {
|
|
|
|
i++;
|
2011-11-06 17:01:23 +01:00
|
|
|
if (i == maxSize) {
|
2011-10-09 14:51:25 +02:00
|
|
|
break;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-10-09 14:51:25 +02:00
|
|
|
}
|
|
|
|
return one.left(i);
|
|
|
|
}
|
|
|
|
|
2013-01-22 19:04:22 +01:00
|
|
|
QString QzTools::urlEncodeQueryString(const QUrl &url)
|
2012-02-21 21:28:19 +01:00
|
|
|
{
|
|
|
|
QString returnString = url.toString(QUrl::RemoveQuery | QUrl::RemoveFragment);
|
2012-02-22 19:12:22 +01:00
|
|
|
|
|
|
|
if (url.hasQuery()) {
|
2012-12-20 14:45:35 +01:00
|
|
|
#if QT_VERSION >= 0x050000
|
|
|
|
returnString += QLatin1Char('?') + url.query(QUrl::FullyEncoded);
|
|
|
|
#else
|
2012-09-04 12:42:45 +02:00
|
|
|
returnString += QLatin1Char('?') + url.encodedQuery();
|
2012-12-20 14:45:35 +01:00
|
|
|
#endif
|
2012-02-22 19:12:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (url.hasFragment()) {
|
2012-12-20 14:45:35 +01:00
|
|
|
#if QT_VERSION >= 0x050000
|
|
|
|
returnString += QLatin1Char('#') + url.fragment(QUrl::FullyEncoded);
|
|
|
|
#else
|
2012-09-04 12:42:45 +02:00
|
|
|
returnString += QLatin1Char('#') + url.encodedFragment();
|
2012-12-20 14:45:35 +01:00
|
|
|
#endif
|
2012-02-22 19:12:22 +01:00
|
|
|
}
|
2012-02-21 21:28:19 +01:00
|
|
|
|
2012-09-04 12:42:45 +02:00
|
|
|
returnString.replace(QLatin1Char(' '), QLatin1String("%20"));
|
2012-03-15 19:35:37 +01:00
|
|
|
|
2012-02-21 21:28:19 +01:00
|
|
|
return returnString;
|
|
|
|
}
|
|
|
|
|
2014-06-15 23:30:29 +02:00
|
|
|
QString QzTools::fromPunycode(const QString &str)
|
|
|
|
{
|
|
|
|
if (!str.startsWith(QL1S("xn--")))
|
|
|
|
return str;
|
|
|
|
|
|
|
|
// QUrl::fromAce will only decode domains from idn whitelist
|
|
|
|
const QString decoded = QUrl::fromAce(str.toUtf8() + QByteArray(".org"));
|
|
|
|
return decoded.left(decoded.size() - 4);
|
|
|
|
}
|
|
|
|
|
2014-06-13 21:22:44 +02:00
|
|
|
QString QzTools::escapeSqlString(QString urlString)
|
|
|
|
{
|
|
|
|
const static QString &escapeString = QL1S("!");
|
|
|
|
urlString.replace(escapeString, escapeString + escapeString);
|
|
|
|
urlString.replace(QL1S("_"), escapeString + QL1S("_"));
|
|
|
|
urlString.replace(QL1S("%"), escapeString + QL1S("%"));
|
|
|
|
|
|
|
|
return urlString;
|
|
|
|
}
|
|
|
|
|
2014-09-29 16:03:22 +02:00
|
|
|
QUrl QzTools::frameUrl(QWebFrame* frame)
|
|
|
|
{
|
|
|
|
return frame->url().isEmpty() ? frame->baseUrl() : frame->url();
|
|
|
|
}
|
|
|
|
|
2013-01-22 19:04:22 +01:00
|
|
|
QString QzTools::ensureUniqueFilename(const QString &name, const QString &appendFormat)
|
2011-10-12 22:28:41 +02:00
|
|
|
{
|
2012-07-08 00:15:03 +02:00
|
|
|
if (!QFile::exists(name)) {
|
|
|
|
return name;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-10-12 22:28:41 +02:00
|
|
|
|
2012-07-08 00:15:03 +02:00
|
|
|
QString tmpFileName = name;
|
2011-10-12 22:28:41 +02:00
|
|
|
int i = 1;
|
|
|
|
while (QFile::exists(tmpFileName)) {
|
2012-07-08 00:15:03 +02:00
|
|
|
tmpFileName = name;
|
2012-09-04 12:42:45 +02:00
|
|
|
int index = tmpFileName.lastIndexOf(QLatin1Char('.'));
|
2011-10-12 22:28:41 +02:00
|
|
|
|
2012-07-08 00:15:03 +02:00
|
|
|
QString appendString = appendFormat.arg(i);
|
2011-10-12 22:28:41 +02:00
|
|
|
if (index == -1) {
|
2012-07-08 00:15:03 +02:00
|
|
|
tmpFileName.append(appendString);
|
2011-11-05 11:51:46 +01:00
|
|
|
}
|
|
|
|
else {
|
2012-07-08 00:15:03 +02:00
|
|
|
tmpFileName = tmpFileName.left(index) + appendString + tmpFileName.mid(index);
|
2011-10-12 22:28:41 +02:00
|
|
|
}
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
return tmpFileName;
|
|
|
|
}
|
|
|
|
|
2013-01-22 19:04:22 +01:00
|
|
|
QString QzTools::getFileNameFromUrl(const QUrl &url)
|
2011-11-05 11:51:46 +01:00
|
|
|
{
|
|
|
|
QString fileName = url.toString(QUrl::RemoveFragment | QUrl::RemoveQuery | QUrl::RemoveScheme | QUrl::RemovePort);
|
2013-01-24 14:25:26 +01:00
|
|
|
|
|
|
|
if (fileName.endsWith(QLatin1Char('/'))) {
|
2013-01-24 17:47:50 +01:00
|
|
|
fileName = fileName.mid(0, fileName.length() - 1);
|
2013-01-24 14:25:26 +01:00
|
|
|
}
|
|
|
|
|
2012-09-04 12:42:45 +02:00
|
|
|
if (fileName.indexOf(QLatin1Char('/')) != -1) {
|
|
|
|
int pos = fileName.lastIndexOf(QLatin1Char('/'));
|
2011-11-05 11:51:46 +01:00
|
|
|
fileName = fileName.mid(pos);
|
2012-09-04 12:42:45 +02:00
|
|
|
fileName.remove(QLatin1Char('/'));
|
2011-11-05 11:51:46 +01:00
|
|
|
}
|
2012-03-07 12:19:54 +01:00
|
|
|
|
2013-01-22 19:04:22 +01:00
|
|
|
fileName = filterCharsFromFilename(fileName);
|
2012-03-23 13:58:31 +01:00
|
|
|
|
|
|
|
if (fileName.isEmpty()) {
|
2013-01-24 14:25:26 +01:00
|
|
|
fileName = filterCharsFromFilename(url.host());
|
2012-03-23 13:58:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return fileName;
|
2011-11-05 11:51:46 +01:00
|
|
|
}
|
|
|
|
|
2013-01-22 19:04:22 +01:00
|
|
|
QString QzTools::filterCharsFromFilename(const QString &name)
|
2011-11-28 19:17:48 +01:00
|
|
|
{
|
|
|
|
QString value = name;
|
2012-06-24 23:46:32 +02:00
|
|
|
|
2012-09-04 12:42:45 +02:00
|
|
|
value.replace(QLatin1Char('/'), QLatin1Char('-'));
|
|
|
|
value.remove(QLatin1Char('\\'));
|
|
|
|
value.remove(QLatin1Char(':'));
|
|
|
|
value.remove(QLatin1Char('*'));
|
|
|
|
value.remove(QLatin1Char('?'));
|
|
|
|
value.remove(QLatin1Char('"'));
|
|
|
|
value.remove(QLatin1Char('<'));
|
|
|
|
value.remove(QLatin1Char('>'));
|
|
|
|
value.remove(QLatin1Char('|'));
|
2011-11-28 19:17:48 +01:00
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2013-12-25 19:06:58 +01:00
|
|
|
QString QzTools::lastPathForFileDialog(const QString &dialogName, const QString &fallbackPath)
|
|
|
|
{
|
|
|
|
Settings settings;
|
|
|
|
settings.beginGroup("LastFileDialogsPaths");
|
|
|
|
QString path = settings.value("FileDialogs/" + dialogName).toString();
|
|
|
|
settings.endGroup();
|
|
|
|
|
|
|
|
return path.isEmpty() ? fallbackPath : path;
|
|
|
|
}
|
|
|
|
|
|
|
|
void QzTools::saveLastPathForFileDialog(const QString &dialogName, const QString &path)
|
|
|
|
{
|
|
|
|
if (path.isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Settings settings;
|
|
|
|
settings.beginGroup("LastFileDialogsPaths");
|
|
|
|
settings.setValue(dialogName, path);
|
|
|
|
settings.endGroup();
|
|
|
|
}
|
|
|
|
|
2013-01-22 19:04:22 +01:00
|
|
|
QString QzTools::alignTextToWidth(const QString &string, const QString &text, const QFontMetrics &metrics, int width)
|
2012-05-13 17:01:35 +02:00
|
|
|
{
|
|
|
|
int pos = 0;
|
|
|
|
QString returnString;
|
|
|
|
|
|
|
|
while (pos <= string.size()) {
|
|
|
|
QString part = string.mid(pos);
|
|
|
|
QString elidedLine = metrics.elidedText(part, Qt::ElideRight, width);
|
|
|
|
|
|
|
|
if (elidedLine.isEmpty()) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (elidedLine.size() != part.size()) {
|
2012-07-01 18:11:43 +02:00
|
|
|
elidedLine = elidedLine.left(elidedLine.size() - 3);
|
2012-05-13 17:01:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!returnString.isEmpty()) {
|
|
|
|
returnString += text;
|
|
|
|
}
|
|
|
|
|
|
|
|
returnString += elidedLine;
|
|
|
|
pos += elidedLine.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
return returnString;
|
|
|
|
}
|
|
|
|
|
2013-01-22 19:04:22 +01:00
|
|
|
QString QzTools::fileSizeToString(qint64 size)
|
2012-08-23 15:40:10 +02:00
|
|
|
{
|
|
|
|
if (size < 0) {
|
|
|
|
return QObject::tr("Unknown size");
|
|
|
|
}
|
|
|
|
|
2013-01-24 14:25:26 +01:00
|
|
|
double _size = size / 1024.0; // KB
|
2012-08-23 15:40:10 +02:00
|
|
|
if (_size < 1000) {
|
2013-10-10 10:36:01 +02:00
|
|
|
return QString::number(_size > 1 ? _size : 1, 'f', 0) + " " + QObject::tr("KB");
|
2012-08-23 15:40:10 +02:00
|
|
|
}
|
|
|
|
|
2013-01-24 14:25:26 +01:00
|
|
|
_size /= 1024; // MB
|
2012-08-23 15:40:10 +02:00
|
|
|
if (_size < 1000) {
|
2013-10-10 10:36:01 +02:00
|
|
|
return QString::number(_size, 'f', 1) + " " + QObject::tr("MB");
|
2012-08-23 15:40:10 +02:00
|
|
|
}
|
|
|
|
|
2013-01-24 14:25:26 +01:00
|
|
|
_size /= 1024; // GB
|
2013-10-10 10:36:01 +02:00
|
|
|
return QString::number(_size, 'f', 2) + " " + QObject::tr("GB");
|
2012-08-23 15:40:10 +02:00
|
|
|
}
|
|
|
|
|
2013-01-22 19:04:22 +01:00
|
|
|
QPixmap QzTools::createPixmapForSite(const QIcon &icon, const QString &title, const QString &url)
|
2012-05-27 14:05:28 +02:00
|
|
|
{
|
|
|
|
const QFontMetrics fontMetrics = QApplication::fontMetrics();
|
|
|
|
const int padding = 4;
|
|
|
|
const int maxWidth = fontMetrics.width(title.length() > url.length() ? title : url) + 3 * padding + 16;
|
|
|
|
|
|
|
|
const int width = qMin(maxWidth, 150);
|
|
|
|
const int height = fontMetrics.height() * 2 + fontMetrics.leading() + 2 * padding;
|
|
|
|
|
|
|
|
QPixmap pixmap(width, height);
|
|
|
|
QPainter painter(&pixmap);
|
|
|
|
|
|
|
|
// Draw background
|
|
|
|
QPen pen(Qt::black);
|
|
|
|
pen.setWidth(1);
|
|
|
|
painter.setPen(pen);
|
|
|
|
|
|
|
|
painter.fillRect(QRect(0, 0, width, height), Qt::white);
|
|
|
|
painter.drawRect(0, 0, width - 1, height - 1);
|
|
|
|
|
|
|
|
// Draw icon
|
|
|
|
QRect iconRect(0, 0, 16 + 2 * padding, height);
|
|
|
|
icon.paint(&painter, iconRect);
|
|
|
|
|
|
|
|
// Draw title
|
|
|
|
QRect titleRect(iconRect.width(), padding, width - padding - iconRect.width(), fontMetrics.height());
|
|
|
|
painter.drawText(titleRect, fontMetrics.elidedText(title, Qt::ElideRight, titleRect.width()));
|
|
|
|
|
|
|
|
// Draw url
|
|
|
|
QRect urlRect(titleRect.x(), titleRect.bottom() + fontMetrics.leading(), titleRect.width(), titleRect.height());
|
|
|
|
painter.setPen(QApplication::palette().color(QPalette::Link));
|
|
|
|
painter.drawText(urlRect, fontMetrics.elidedText(url, Qt::ElideRight, urlRect.width()));
|
|
|
|
|
|
|
|
return pixmap;
|
|
|
|
}
|
|
|
|
|
2013-01-22 19:04:22 +01:00
|
|
|
QString QzTools::applyDirectionToPage(QString &pageContents)
|
2012-08-19 19:47:28 +02:00
|
|
|
{
|
2012-09-04 12:42:45 +02:00
|
|
|
QString direction = QLatin1String("ltr");
|
|
|
|
QString right_str = QLatin1String("right");
|
|
|
|
QString left_str = QLatin1String("left");
|
2012-08-19 19:47:28 +02:00
|
|
|
|
|
|
|
if (QApplication::isRightToLeft()) {
|
2012-09-04 12:42:45 +02:00
|
|
|
direction = QLatin1String("rtl");
|
|
|
|
right_str = QLatin1String("left");
|
|
|
|
left_str = QLatin1String("right");
|
2012-08-19 19:47:28 +02:00
|
|
|
}
|
|
|
|
|
2012-09-04 12:42:45 +02:00
|
|
|
pageContents.replace(QLatin1String("%DIRECTION%"), direction);
|
|
|
|
pageContents.replace(QLatin1String("%RIGHT_STR%"), right_str);
|
|
|
|
pageContents.replace(QLatin1String("%LEFT_STR%"), left_str);
|
2012-08-19 19:47:28 +02:00
|
|
|
|
|
|
|
return pageContents;
|
|
|
|
}
|
|
|
|
|
2014-03-17 15:01:28 +01:00
|
|
|
QString QzTools::truncatedText(const QString &text, int size)
|
|
|
|
{
|
|
|
|
if (text.length() > size) {
|
|
|
|
return text.left(size) + QL1S("..");
|
|
|
|
}
|
|
|
|
return text;
|
|
|
|
}
|
|
|
|
|
2013-04-21 01:24:24 +02:00
|
|
|
// Thanks to http://www.qtcentre.org/threads/3205-Toplevel-widget-with-rounded-corners?p=17492#post17492
|
|
|
|
QRegion QzTools::roundedRect(const QRect &rect, int radius)
|
|
|
|
{
|
|
|
|
QRegion region;
|
|
|
|
|
|
|
|
// middle and borders
|
|
|
|
region += rect.adjusted(radius, 0, -radius, 0);
|
|
|
|
region += rect.adjusted(0, radius, 0, -radius);
|
|
|
|
|
|
|
|
// top left
|
|
|
|
QRect corner(rect.topLeft(), QSize(radius * 2, radius * 2));
|
|
|
|
region += QRegion(corner, QRegion::Ellipse);
|
|
|
|
|
|
|
|
// top right
|
|
|
|
corner.moveTopRight(rect.topRight());
|
|
|
|
region += QRegion(corner, QRegion::Ellipse);
|
|
|
|
|
|
|
|
// bottom left
|
|
|
|
corner.moveBottomLeft(rect.bottomLeft());
|
|
|
|
region += QRegion(corner, QRegion::Ellipse);
|
|
|
|
|
|
|
|
// bottom right
|
|
|
|
corner.moveBottomRight(rect.bottomRight());
|
|
|
|
region += QRegion(corner, QRegion::Ellipse);
|
|
|
|
|
|
|
|
return region;
|
|
|
|
}
|
|
|
|
|
2013-01-29 19:55:09 +01:00
|
|
|
QIcon QzTools::iconFromFileName(const QString &fileName)
|
|
|
|
{
|
|
|
|
static QHash<QString, QIcon> iconCache;
|
|
|
|
|
|
|
|
QFileInfo tempInfo(fileName);
|
|
|
|
if (iconCache.contains(tempInfo.suffix())) {
|
|
|
|
return iconCache.value(tempInfo.suffix());
|
|
|
|
}
|
|
|
|
|
|
|
|
QFileIconProvider iconProvider;
|
2014-03-09 21:51:42 +01:00
|
|
|
QTemporaryFile tempFile(DataPaths::path(DataPaths::Temp) + "/XXXXXX." + tempInfo.suffix());
|
2013-01-29 19:55:09 +01:00
|
|
|
tempFile.open();
|
|
|
|
tempInfo.setFile(tempFile.fileName());
|
|
|
|
|
|
|
|
QIcon icon(iconProvider.icon(tempInfo));
|
|
|
|
iconCache.insert(tempInfo.suffix(), icon);
|
|
|
|
|
|
|
|
return icon;
|
|
|
|
}
|
|
|
|
|
2013-02-14 18:07:50 +01:00
|
|
|
QString QzTools::resolveFromPath(const QString &name)
|
2013-02-13 21:48:06 +01:00
|
|
|
{
|
2013-12-30 13:43:48 +01:00
|
|
|
const QString path = qgetenv("PATH").trimmed();
|
2013-02-13 21:48:06 +01:00
|
|
|
|
|
|
|
if (path.isEmpty()) {
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
|
|
|
QStringList dirs = path.split(QLatin1Char(':'), QString::SkipEmptyParts);
|
|
|
|
|
2013-03-06 09:05:41 +01:00
|
|
|
foreach (const QString &dir, dirs) {
|
2013-02-13 21:48:06 +01:00
|
|
|
QDir d(dir);
|
|
|
|
if (d.exists(name)) {
|
|
|
|
return d.absoluteFilePath(name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
2013-02-13 17:19:29 +01:00
|
|
|
// http://stackoverflow.com/questions/1031645/how-to-detect-utf-8-in-plain-c
|
|
|
|
bool QzTools::isUtf8(const char* string)
|
|
|
|
{
|
|
|
|
if (!string) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
const unsigned char* bytes = (const unsigned char*)string;
|
|
|
|
while (*bytes) {
|
|
|
|
if ((// ASCII
|
2014-04-05 14:42:19 +02:00
|
|
|
bytes[0] == 0x09 ||
|
|
|
|
bytes[0] == 0x0A ||
|
|
|
|
bytes[0] == 0x0D ||
|
|
|
|
(0x20 <= bytes[0] && bytes[0] <= 0x7F)
|
|
|
|
)
|
2013-02-13 17:19:29 +01:00
|
|
|
) {
|
|
|
|
bytes += 1;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((// non-overlong 2-byte
|
2014-04-05 14:42:19 +02:00
|
|
|
(0xC2 <= bytes[0] && bytes[0] <= 0xDF) &&
|
|
|
|
(0x80 <= bytes[1] && bytes[1] <= 0xBF)
|
|
|
|
)
|
2013-02-13 17:19:29 +01:00
|
|
|
) {
|
|
|
|
bytes += 2;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((// excluding overlongs
|
2014-04-05 14:42:19 +02:00
|
|
|
bytes[0] == 0xE0 &&
|
|
|
|
(0xA0 <= bytes[1] && bytes[1] <= 0xBF) &&
|
|
|
|
(0x80 <= bytes[2] && bytes[2] <= 0xBF)
|
|
|
|
) ||
|
|
|
|
(// straight 3-byte
|
|
|
|
((0xE1 <= bytes[0] && bytes[0] <= 0xEC) ||
|
|
|
|
bytes[0] == 0xEE ||
|
|
|
|
bytes[0] == 0xEF) &&
|
|
|
|
(0x80 <= bytes[1] && bytes[1] <= 0xBF) &&
|
|
|
|
(0x80 <= bytes[2] && bytes[2] <= 0xBF)
|
|
|
|
) ||
|
|
|
|
(// excluding surrogates
|
|
|
|
bytes[0] == 0xED &&
|
|
|
|
(0x80 <= bytes[1] && bytes[1] <= 0x9F) &&
|
|
|
|
(0x80 <= bytes[2] && bytes[2] <= 0xBF)
|
|
|
|
)
|
2013-02-13 17:19:29 +01:00
|
|
|
) {
|
|
|
|
bytes += 3;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((// planes 1-3
|
2014-04-05 14:42:19 +02:00
|
|
|
bytes[0] == 0xF0 &&
|
|
|
|
(0x90 <= bytes[1] && bytes[1] <= 0xBF) &&
|
|
|
|
(0x80 <= bytes[2] && bytes[2] <= 0xBF) &&
|
|
|
|
(0x80 <= bytes[3] && bytes[3] <= 0xBF)
|
|
|
|
) ||
|
|
|
|
(// planes 4-15
|
|
|
|
(0xF1 <= bytes[0] && bytes[0] <= 0xF3) &&
|
|
|
|
(0x80 <= bytes[1] && bytes[1] <= 0xBF) &&
|
|
|
|
(0x80 <= bytes[2] && bytes[2] <= 0xBF) &&
|
|
|
|
(0x80 <= bytes[3] && bytes[3] <= 0xBF)
|
|
|
|
) ||
|
|
|
|
(// plane 16
|
|
|
|
bytes[0] == 0xF4 &&
|
|
|
|
(0x80 <= bytes[1] && bytes[1] <= 0x8F) &&
|
|
|
|
(0x80 <= bytes[2] && bytes[2] <= 0xBF) &&
|
|
|
|
(0x80 <= bytes[3] && bytes[3] <= 0xBF)
|
|
|
|
)
|
2013-02-13 17:19:29 +01:00
|
|
|
) {
|
|
|
|
bytes += 4;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-12-25 19:06:58 +01:00
|
|
|
QString QzTools::getExistingDirectory(const QString &name, QWidget* parent, const QString &caption, const QString &dir, QFileDialog::Options options)
|
|
|
|
{
|
|
|
|
Settings settings;
|
|
|
|
settings.beginGroup("FileDialogPaths");
|
2013-12-26 20:49:59 +01:00
|
|
|
|
2013-12-25 19:06:58 +01:00
|
|
|
QString lastDir = settings.value(name, dir).toString();
|
|
|
|
|
|
|
|
QString path = QFileDialog::getExistingDirectory(parent, caption, lastDir, options);
|
|
|
|
|
|
|
|
if (!path.isEmpty()) {
|
|
|
|
settings.setValue(name, QFileInfo(path).absolutePath());
|
|
|
|
}
|
|
|
|
|
2013-12-26 20:49:59 +01:00
|
|
|
settings.endGroup();
|
2013-12-25 19:06:58 +01:00
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
2013-12-30 13:15:20 +01:00
|
|
|
static QString getFilename(const QString &path)
|
|
|
|
{
|
|
|
|
QFileInfo info(path);
|
|
|
|
|
|
|
|
if (info.isFile()) {
|
|
|
|
return info.fileName();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (info.isDir()) {
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (info.dir().exists()) {
|
|
|
|
return info.fileName();
|
|
|
|
}
|
|
|
|
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
2013-12-25 19:06:58 +01:00
|
|
|
QString QzTools::getOpenFileName(const QString &name, QWidget* parent, const QString &caption, const QString &dir, const QString &filter, QString* selectedFilter, QFileDialog::Options options)
|
|
|
|
{
|
|
|
|
Settings settings;
|
|
|
|
settings.beginGroup("FileDialogPaths");
|
2013-12-26 20:49:59 +01:00
|
|
|
|
|
|
|
QString lastDir = settings.value(name, QString()).toString();
|
2013-12-30 13:15:20 +01:00
|
|
|
QString fileName = getFilename(dir);
|
2013-12-26 20:49:59 +01:00
|
|
|
|
|
|
|
if (lastDir.isEmpty()) {
|
|
|
|
lastDir = dir;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
lastDir.append(QDir::separator() + fileName);
|
|
|
|
}
|
2013-12-25 19:06:58 +01:00
|
|
|
|
|
|
|
QString path = QFileDialog::getOpenFileName(parent, caption, lastDir, filter, selectedFilter, options);
|
|
|
|
|
|
|
|
if (!path.isEmpty()) {
|
|
|
|
settings.setValue(name, QFileInfo(path).absolutePath());
|
|
|
|
}
|
|
|
|
|
2013-12-26 20:49:59 +01:00
|
|
|
settings.endGroup();
|
2013-12-25 19:06:58 +01:00
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
|
|
|
QStringList QzTools::getOpenFileNames(const QString &name, QWidget* parent, const QString &caption, const QString &dir, const QString &filter, QString* selectedFilter, QFileDialog::Options options)
|
|
|
|
{
|
|
|
|
Settings settings;
|
|
|
|
settings.beginGroup("FileDialogPaths");
|
2013-12-26 20:49:59 +01:00
|
|
|
|
|
|
|
QString lastDir = settings.value(name, QString()).toString();
|
2013-12-30 13:15:20 +01:00
|
|
|
QString fileName = getFilename(dir);
|
2013-12-26 20:49:59 +01:00
|
|
|
|
|
|
|
if (lastDir.isEmpty()) {
|
|
|
|
lastDir = dir;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
lastDir.append(QDir::separator() + fileName);
|
|
|
|
}
|
2013-12-25 19:06:58 +01:00
|
|
|
|
|
|
|
QStringList paths = QFileDialog::getOpenFileNames(parent, caption, lastDir, filter, selectedFilter, options);
|
|
|
|
|
|
|
|
if (!paths.isEmpty()) {
|
|
|
|
settings.setValue(name, QFileInfo(paths.first()).absolutePath());
|
|
|
|
}
|
|
|
|
|
2013-12-26 20:49:59 +01:00
|
|
|
settings.endGroup();
|
2013-12-25 19:06:58 +01:00
|
|
|
return paths;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString QzTools::getSaveFileName(const QString &name, QWidget* parent, const QString &caption, const QString &dir, const QString &filter, QString* selectedFilter, QFileDialog::Options options)
|
|
|
|
{
|
|
|
|
Settings settings;
|
|
|
|
settings.beginGroup("FileDialogPaths");
|
2013-12-26 20:49:59 +01:00
|
|
|
|
|
|
|
QString lastDir = settings.value(name, QString()).toString();
|
2013-12-30 13:15:20 +01:00
|
|
|
QString fileName = getFilename(dir);
|
2013-12-26 20:49:59 +01:00
|
|
|
|
|
|
|
if (lastDir.isEmpty()) {
|
|
|
|
lastDir = dir;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
lastDir.append(QDir::separator() + fileName);
|
|
|
|
}
|
2013-12-25 19:06:58 +01:00
|
|
|
|
|
|
|
QString path = QFileDialog::getSaveFileName(parent, caption, lastDir, filter, selectedFilter, options);
|
|
|
|
|
|
|
|
if (!path.isEmpty()) {
|
|
|
|
settings.setValue(name, QFileInfo(path).absolutePath());
|
|
|
|
}
|
|
|
|
|
2013-12-26 20:49:59 +01:00
|
|
|
settings.endGroup();
|
2013-12-25 19:06:58 +01:00
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
2013-02-26 15:48:47 +01:00
|
|
|
// Matches domain (assumes both pattern and domain not starting with dot)
|
|
|
|
// pattern = domain to be matched
|
|
|
|
// domain = site domain
|
|
|
|
bool QzTools::matchDomain(const QString &pattern, const QString &domain)
|
|
|
|
{
|
|
|
|
if (pattern == domain) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!domain.endsWith(pattern)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
int index = domain.indexOf(pattern);
|
|
|
|
|
|
|
|
return index > 0 && domain[index - 1] == QLatin1Char('.');
|
|
|
|
}
|
|
|
|
|
2013-02-15 10:47:34 +01:00
|
|
|
static inline bool isQuote(const QChar &c)
|
|
|
|
{
|
|
|
|
return (c == QLatin1Char('"') || c == QLatin1Char('\''));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Function splits command line into arguments
|
|
|
|
// eg. /usr/bin/foo -o test -b "bar bar" -s="sed sed"
|
|
|
|
// => '/usr/bin/foo' '-o' 'test' '-b' 'bar bar' '-s=sed sed'
|
|
|
|
QStringList QzTools::splitCommandArguments(const QString &command)
|
|
|
|
{
|
|
|
|
QString line = command.trimmed();
|
|
|
|
|
|
|
|
if (line.isEmpty()) {
|
|
|
|
return QStringList();
|
|
|
|
}
|
|
|
|
|
|
|
|
QChar SPACE(' ');
|
|
|
|
QChar EQUAL('=');
|
|
|
|
QChar BSLASH('\\');
|
|
|
|
QChar QUOTE('"');
|
|
|
|
QStringList r;
|
|
|
|
|
|
|
|
int equalPos = -1; // Position of = in opt="value"
|
|
|
|
int startPos = isQuote(line.at(0)) ? 1 : 0;
|
|
|
|
bool inWord = !isQuote(line.at(0));
|
|
|
|
bool inQuote = !inWord;
|
|
|
|
|
|
|
|
if (inQuote) {
|
|
|
|
QUOTE = line.at(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
const int strlen = line.length();
|
|
|
|
for (int i = 0; i < strlen; ++i) {
|
2013-12-30 13:43:48 +01:00
|
|
|
const QChar c = line.at(i);
|
2013-02-15 10:47:34 +01:00
|
|
|
|
|
|
|
if (inQuote && c == QUOTE && i > 0 && line.at(i - 1) != BSLASH) {
|
|
|
|
QString str = line.mid(startPos, i - startPos);
|
|
|
|
if (equalPos > -1) {
|
|
|
|
str.remove(equalPos - startPos + 1, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
inQuote = false;
|
|
|
|
if (!str.isEmpty()) {
|
|
|
|
r.append(str);
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else if (!inQuote && isQuote(c)) {
|
|
|
|
inQuote = true;
|
|
|
|
QUOTE = c;
|
|
|
|
|
|
|
|
if (!inWord) {
|
|
|
|
startPos = i + 1;
|
|
|
|
}
|
|
|
|
else if (i > 0 && line.at(i - 1) == EQUAL) {
|
|
|
|
equalPos = i - 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (inQuote) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (inWord && (c == SPACE || i == strlen - 1)) {
|
|
|
|
int len = (i == strlen - 1) ? -1 : i - startPos;
|
2013-12-30 13:43:48 +01:00
|
|
|
const QString str = line.mid(startPos, len);
|
2013-02-15 10:47:34 +01:00
|
|
|
|
|
|
|
inWord = false;
|
|
|
|
if (!str.isEmpty()) {
|
|
|
|
r.append(str);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (!inWord && c != SPACE) {
|
|
|
|
inWord = true;
|
|
|
|
startPos = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Unmatched quote
|
|
|
|
if (inQuote) {
|
|
|
|
return QStringList();
|
|
|
|
}
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2013-02-15 12:29:13 +01:00
|
|
|
bool QzTools::startExternalProcess(const QString &executable, const QString &args)
|
|
|
|
{
|
2013-12-30 13:43:48 +01:00
|
|
|
const QStringList arguments = splitCommandArguments(args);
|
2013-02-15 12:29:13 +01:00
|
|
|
|
|
|
|
bool success = QProcess::startDetached(executable, arguments);
|
|
|
|
|
|
|
|
if (!success) {
|
|
|
|
QString info = "<ul><li><b>%1</b>%2</li><li><b>%3</b>%4</li></ul>";
|
|
|
|
info = info.arg(QObject::tr("Executable: "), executable,
|
|
|
|
QObject::tr("Arguments: "), arguments.join(QLatin1String(" ")));
|
|
|
|
|
|
|
|
QMessageBox::critical(0, QObject::tr("Cannot start external program"),
|
|
|
|
QObject::tr("Cannot start external program! %1").arg(info));
|
|
|
|
}
|
|
|
|
|
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
2012-12-20 14:45:35 +01:00
|
|
|
// Qt5 migration help functions
|
2013-01-22 19:04:22 +01:00
|
|
|
bool QzTools::isCertificateValid(const QSslCertificate &cert)
|
2012-12-20 14:45:35 +01:00
|
|
|
{
|
|
|
|
#if QT_VERSION >= 0x050000
|
|
|
|
const QDateTime currentTime = QDateTime::currentDateTime();
|
|
|
|
return currentTime >= cert.effectiveDate() &&
|
|
|
|
currentTime <= cert.expiryDate() &&
|
|
|
|
!cert.isBlacklisted();
|
|
|
|
#else
|
|
|
|
return cert.isValid();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2013-01-22 19:04:22 +01:00
|
|
|
QString QzTools::escape(const QString &string)
|
2012-12-20 14:45:35 +01:00
|
|
|
{
|
|
|
|
#if QT_VERSION >= 0x050000
|
|
|
|
return string.toHtmlEscaped();
|
|
|
|
#else
|
2012-12-27 11:31:10 +01:00
|
|
|
return Qt::escape(string);
|
2012-12-20 14:45:35 +01:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2013-07-29 17:55:35 +02:00
|
|
|
void* QzTools::X11Display(const QWidget* widget)
|
2012-12-22 15:01:55 +01:00
|
|
|
{
|
|
|
|
Q_UNUSED(widget)
|
|
|
|
|
2014-03-07 22:54:50 +01:00
|
|
|
#ifdef QZ_WS_X11
|
2012-12-22 15:01:55 +01:00
|
|
|
#if QT_VERSION >= 0x050000
|
|
|
|
return qApp->platformNativeInterface()->nativeResourceForWindow("display", widget->windowHandle());
|
|
|
|
#else
|
|
|
|
return QX11Info::display();
|
|
|
|
#endif
|
2013-07-08 00:08:05 +02:00
|
|
|
#endif
|
2013-07-07 12:32:55 +02:00
|
|
|
|
2014-03-07 22:54:50 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-07-07 12:32:55 +02:00
|
|
|
void QzTools::setWmClass(const QString &name, const QWidget* widget)
|
|
|
|
{
|
2014-03-03 14:47:47 +01:00
|
|
|
#ifdef QZ_WS_X11
|
2013-07-07 15:29:41 +02:00
|
|
|
QByteArray nameData = name.toUtf8();
|
2013-07-07 12:32:55 +02:00
|
|
|
|
|
|
|
XClassHint classHint;
|
2013-07-07 15:29:41 +02:00
|
|
|
classHint.res_name = const_cast<char*>(nameData.constData());
|
2013-07-07 12:32:55 +02:00
|
|
|
classHint.res_class = const_cast<char*>("QupZilla");
|
2013-07-17 16:06:10 +02:00
|
|
|
XSetClassHint((Display*)X11Display(widget), widget->winId(), &classHint);
|
2013-07-08 00:08:05 +02:00
|
|
|
#else
|
|
|
|
Q_UNUSED(name)
|
|
|
|
Q_UNUSED(widget)
|
2012-12-29 08:58:11 +01:00
|
|
|
#endif
|
2013-07-08 00:08:05 +02:00
|
|
|
}
|
2012-12-22 15:01:55 +01:00
|
|
|
|
2013-02-24 23:02:55 +01:00
|
|
|
QString QzTools::operatingSystem()
|
2011-10-07 15:37:49 +02:00
|
|
|
{
|
2013-02-26 12:58:04 +01:00
|
|
|
#ifdef Q_OS_MAC
|
|
|
|
QString str = "Mac OS X";
|
|
|
|
|
|
|
|
SInt32 majorVersion;
|
|
|
|
SInt32 minorVersion;
|
|
|
|
|
|
|
|
if (Gestalt(gestaltSystemVersionMajor, &majorVersion) == noErr && Gestalt(gestaltSystemVersionMinor, &minorVersion) == noErr) {
|
|
|
|
str.append(QString(" %1.%2").arg(majorVersion).arg(minorVersion));
|
|
|
|
}
|
|
|
|
|
|
|
|
return str;
|
|
|
|
#endif
|
2011-10-07 15:37:49 +02:00
|
|
|
#ifdef Q_OS_LINUX
|
|
|
|
return "Linux";
|
|
|
|
#endif
|
|
|
|
#ifdef Q_OS_BSD4
|
|
|
|
return "BSD 4.4";
|
|
|
|
#endif
|
|
|
|
#ifdef Q_OS_BSDI
|
|
|
|
return "BSD/OS";
|
|
|
|
#endif
|
|
|
|
#ifdef Q_OS_FREEBSD
|
|
|
|
return "FreeBSD";
|
|
|
|
#endif
|
|
|
|
#ifdef Q_OS_HPUX
|
|
|
|
return "HP-UX";
|
|
|
|
#endif
|
|
|
|
#ifdef Q_OS_HURD
|
|
|
|
return "GNU Hurd";
|
|
|
|
#endif
|
|
|
|
#ifdef Q_OS_LYNX
|
|
|
|
return "LynxOS";
|
|
|
|
#endif
|
|
|
|
#ifdef Q_OS_NETBSD
|
|
|
|
return "NetBSD";
|
|
|
|
#endif
|
|
|
|
#ifdef Q_OS_OS2
|
|
|
|
return "OS/2";
|
|
|
|
#endif
|
|
|
|
#ifdef Q_OS_OPENBSD
|
|
|
|
return "OpenBSD";
|
|
|
|
#endif
|
|
|
|
#ifdef Q_OS_OSF
|
|
|
|
return "HP Tru64 UNIX";
|
|
|
|
#endif
|
|
|
|
#ifdef Q_OS_SOLARIS
|
|
|
|
return "Sun Solaris";
|
|
|
|
#endif
|
|
|
|
#ifdef Q_OS_UNIXWARE
|
|
|
|
return "UnixWare 7 / Open UNIX 8";
|
|
|
|
#endif
|
2013-02-24 23:02:55 +01:00
|
|
|
#ifdef Q_OS_UNIX
|
|
|
|
return "Unix";
|
|
|
|
#endif
|
|
|
|
#ifdef Q_OS_HAIKU
|
|
|
|
return "Haiku";
|
|
|
|
#endif
|
2011-10-07 15:37:49 +02:00
|
|
|
#ifdef Q_OS_WIN32
|
2013-02-04 13:07:21 +01:00
|
|
|
QString str = "Windows";
|
|
|
|
|
|
|
|
switch (QSysInfo::windowsVersion()) {
|
|
|
|
case QSysInfo::WV_NT:
|
|
|
|
str.append(" NT");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case QSysInfo::WV_2000:
|
|
|
|
str.append(" 2000");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case QSysInfo::WV_XP:
|
|
|
|
str.append(" XP");
|
|
|
|
break;
|
|
|
|
case QSysInfo::WV_2003:
|
|
|
|
str.append(" XP Pro x64");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case QSysInfo::WV_VISTA:
|
|
|
|
str.append(" Vista");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case QSysInfo::WV_WINDOWS7:
|
|
|
|
str.append(" 7");
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2013-02-24 23:02:55 +01:00
|
|
|
OSVERSIONINFO osvi;
|
|
|
|
ZeroMemory(&osvi, sizeof(OSVERSIONINFO));
|
|
|
|
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
|
|
|
|
GetVersionEx(&osvi);
|
|
|
|
|
|
|
|
if (osvi.dwMajorVersion == 6 && osvi.dwMinorVersion == 2) {
|
|
|
|
str.append(" 8");
|
|
|
|
}
|
2013-02-04 13:07:21 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return str;
|
2011-10-07 15:37:49 +02:00
|
|
|
#endif
|
|
|
|
}
|
2014-02-09 18:55:11 +01:00
|
|
|
|