2011-03-03 18:29:20 +01:00
|
|
|
/* ============================================================
|
|
|
|
* QupZilla - WebKit based browser
|
2014-01-11 16:11:42 +01:00
|
|
|
* Copyright (C) 2010-2014 David Rosca <nowrep@gmail.com>
|
2011-03-03 18:29:20 +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/>.
|
|
|
|
* ============================================================ */
|
2011-03-02 16:57:41 +01:00
|
|
|
#include "mainapplication.h"
|
2012-03-31 21:36:27 +02:00
|
|
|
#include "proxystyle.h"
|
2014-03-09 21:51:42 +01:00
|
|
|
#include "datapaths.h"
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2012-07-03 22:57:31 +02:00
|
|
|
#include <QMessageBox> // For QT_REQUIRE_VERSION
|
2014-01-02 10:45:22 +01:00
|
|
|
#include <iostream>
|
2012-07-03 22:57:31 +02:00
|
|
|
|
2014-02-13 20:16:20 +01:00
|
|
|
#if defined(Q_OS_LINUX) || defined(__GLIBC__) || defined(__FreeBSD__)
|
2012-01-23 19:28:47 +01:00
|
|
|
#include <signal.h>
|
2012-07-03 22:57:31 +02:00
|
|
|
#include <execinfo.h>
|
|
|
|
|
|
|
|
#include <QDir>
|
|
|
|
#include <QDateTime>
|
|
|
|
#include <QTextStream>
|
|
|
|
|
2012-12-20 14:45:35 +01:00
|
|
|
#if QT_VERSION >= 0x050000
|
|
|
|
#include <QWebPage>
|
|
|
|
#else
|
|
|
|
#include "qwebkitversion.h"
|
|
|
|
#endif
|
|
|
|
|
2012-07-03 22:57:31 +02:00
|
|
|
void qupzilla_signal_handler(int s)
|
2012-01-23 19:28:47 +01:00
|
|
|
{
|
2014-03-07 18:57:42 +01:00
|
|
|
if (s != SIGSEGV) {
|
|
|
|
return;
|
|
|
|
}
|
2012-07-03 22:57:31 +02:00
|
|
|
|
2014-03-07 18:57:42 +01:00
|
|
|
static bool sigSegvServed = false;
|
|
|
|
if (sigSegvServed) {
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
sigSegvServed = true;
|
2012-07-03 22:57:31 +02:00
|
|
|
|
2014-03-15 19:16:58 +01:00
|
|
|
std::cout << "QupZilla: Crashed :( Saving backtrace in " << qPrintable(DataPaths::path(DataPaths::Config)) << "/crashlog ..." << std::endl;
|
2012-01-23 19:28:47 +01:00
|
|
|
|
2014-03-07 18:57:42 +01:00
|
|
|
void* array[100];
|
|
|
|
int size = backtrace(array, 100);
|
|
|
|
char** strings = backtrace_symbols(array, size);
|
2012-07-03 22:57:31 +02:00
|
|
|
|
2014-03-07 18:57:42 +01:00
|
|
|
if (size < 0 || !strings) {
|
|
|
|
std::cout << "Cannot get backtrace!" << std::endl;
|
|
|
|
abort();
|
|
|
|
}
|
2012-07-03 22:57:31 +02:00
|
|
|
|
2014-03-09 21:51:42 +01:00
|
|
|
QDir dir(DataPaths::path(DataPaths::Config));
|
2014-03-07 18:57:42 +01:00
|
|
|
if (!dir.exists()) {
|
2014-03-09 21:51:42 +01:00
|
|
|
std::cout << qPrintable(DataPaths::path(DataPaths::Config)) << " does not exist" << std::endl;
|
2014-03-07 18:57:42 +01:00
|
|
|
abort();
|
|
|
|
}
|
2012-07-03 22:57:31 +02:00
|
|
|
|
2014-03-07 18:57:42 +01:00
|
|
|
if (!dir.cd("crashlog")) {
|
|
|
|
if (!dir.mkdir("crashlog")) {
|
2014-03-09 21:51:42 +01:00
|
|
|
std::cout << "Cannot create " << qPrintable(DataPaths::path(DataPaths::Config)) << "crashlog directory!" << std::endl;
|
2012-07-03 22:57:31 +02:00
|
|
|
abort();
|
|
|
|
}
|
|
|
|
|
2014-03-07 18:57:42 +01:00
|
|
|
dir.cd("crashlog");
|
|
|
|
}
|
2012-07-03 22:57:31 +02:00
|
|
|
|
2014-03-07 18:57:42 +01:00
|
|
|
const QDateTime currentDateTime = QDateTime::currentDateTime();
|
2012-07-03 22:57:31 +02:00
|
|
|
|
2014-03-07 18:57:42 +01:00
|
|
|
QFile file(dir.absoluteFilePath("Crash-" + currentDateTime.toString(Qt::ISODate) + ".txt"));
|
|
|
|
if (!file.open(QFile::WriteOnly | QFile::Truncate)) {
|
|
|
|
std::cout << "Cannot open file " << qPrintable(file.fileName()) << " for writing!" << std::endl;
|
|
|
|
abort();
|
2012-07-03 22:57:31 +02:00
|
|
|
}
|
|
|
|
|
2014-03-07 18:57:42 +01:00
|
|
|
QTextStream stream(&file);
|
|
|
|
stream << "Time: " << currentDateTime.toString() << endl;
|
|
|
|
stream << "Qt version: " << qVersion() << " (compiled with " << QT_VERSION_STR << ")" << endl;
|
|
|
|
stream << "QupZilla version: " << Qz::VERSION << endl;
|
|
|
|
stream << "WebKit version: " << qWebKitVersion() << endl;
|
|
|
|
stream << endl;
|
|
|
|
stream << "============== BACKTRACE ==============" << endl;
|
|
|
|
|
|
|
|
for (int i = 0; i < size; ++i) {
|
|
|
|
stream << "#" << i << ": " << strings[i] << endl;
|
2012-07-03 22:57:31 +02:00
|
|
|
}
|
2014-03-07 18:57:42 +01:00
|
|
|
|
|
|
|
file.close();
|
|
|
|
|
|
|
|
std::cout << "Backtrace successfuly saved in " << qPrintable(dir.absoluteFilePath(file.fileName())) << std::endl;
|
2012-01-23 19:28:47 +01:00
|
|
|
}
|
2014-02-13 20:16:20 +01:00
|
|
|
#endif // defined(Q_OS_LINUX) || defined(__GLIBC__) || defined(__FreeBSD__)
|
2012-01-23 19:28:47 +01:00
|
|
|
|
2013-11-09 19:54:39 +01:00
|
|
|
#ifndef Q_OS_WIN
|
2013-02-18 13:37:12 +01:00
|
|
|
#if (QT_VERSION < 0x050000)
|
2013-02-16 11:19:00 +01:00
|
|
|
void msgHandler(QtMsgType type, const char* msg)
|
|
|
|
{
|
|
|
|
// Skip this debug message as it may occur in a large amount over time
|
|
|
|
if (strcmp("QFont::setPixelSize: Pixel size <= 0 (0)", msg) == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case QtDebugMsg:
|
|
|
|
case QtWarningMsg:
|
|
|
|
case QtCriticalMsg:
|
2013-11-03 15:11:26 +01:00
|
|
|
std::cerr << msg << std::endl;
|
2013-02-16 11:19:00 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case QtFatalMsg:
|
2013-11-03 15:11:26 +01:00
|
|
|
std::cerr << "Fatal: " << msg << std::endl;
|
2013-02-16 11:19:00 +01:00
|
|
|
abort();
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2013-02-18 13:37:12 +01:00
|
|
|
#else
|
|
|
|
void msgHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg)
|
|
|
|
{
|
|
|
|
QByteArray localMsg = msg.toLocal8Bit();
|
|
|
|
switch (type) {
|
|
|
|
case QtDebugMsg:
|
|
|
|
case QtWarningMsg:
|
|
|
|
case QtCriticalMsg:
|
2013-11-03 15:11:26 +01:00
|
|
|
std::cerr << localMsg.constData() << " (" << context.file << ":" << context.line << ", " << context.function << ")" << std::endl;
|
2013-02-18 13:37:12 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case QtFatalMsg:
|
2013-11-03 15:11:26 +01:00
|
|
|
std::cerr << "Fatal: " << localMsg.constData() << " (" << context.file << ":" << context.line << ", " << context.function << ")" << std::endl;
|
2013-02-18 13:37:12 +01:00
|
|
|
abort();
|
2013-02-16 11:19:00 +01:00
|
|
|
|
2013-02-18 13:37:12 +01:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2013-11-09 19:54:39 +01:00
|
|
|
#endif
|
2013-02-16 11:19:00 +01:00
|
|
|
|
2011-11-06 17:01:23 +01:00
|
|
|
int main(int argc, char* argv[])
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2012-07-03 22:57:31 +02:00
|
|
|
QT_REQUIRE_VERSION(argc, argv, "4.7.0");
|
2013-02-18 13:37:12 +01:00
|
|
|
|
2013-02-22 01:13:59 +01:00
|
|
|
#ifndef Q_OS_WIN
|
2013-02-18 13:37:12 +01:00
|
|
|
#if (QT_VERSION < 0x050000)
|
2013-02-16 11:19:00 +01:00
|
|
|
qInstallMsgHandler(&msgHandler);
|
2013-02-18 13:37:12 +01:00
|
|
|
#else
|
|
|
|
qInstallMessageHandler(&msgHandler);
|
|
|
|
#endif
|
2013-02-22 01:13:59 +01:00
|
|
|
#endif
|
2012-07-03 22:57:31 +02:00
|
|
|
|
2012-12-22 12:47:45 +01:00
|
|
|
#if defined(QZ_WS_X11) && QT_VERSION < 0x050000
|
2011-03-02 16:57:41 +01:00
|
|
|
QApplication::setGraphicsSystem("raster"); // Better overall performance on X11
|
2012-08-13 16:00:14 +02:00
|
|
|
#endif
|
2012-01-23 19:28:47 +01:00
|
|
|
|
2014-02-13 20:16:20 +01:00
|
|
|
#if defined(Q_OS_LINUX) || defined(__GLIBC__) || defined(__FreeBSD__)
|
2012-07-03 22:57:31 +02:00
|
|
|
signal(SIGSEGV, qupzilla_signal_handler);
|
|
|
|
signal(SIGPIPE, qupzilla_signal_handler);
|
2011-03-02 16:57:41 +01:00
|
|
|
#endif
|
|
|
|
|
2014-03-24 16:08:33 +01:00
|
|
|
if (!QIcon::hasThemeIcon(QSL("document-open"))) {
|
|
|
|
QIcon::setThemeSearchPaths(QStringList() << QL1S(":/oxygen-fallback"));
|
|
|
|
QIcon::setThemeName(QSL("oxygen-fallback"));
|
|
|
|
}
|
|
|
|
|
2012-03-24 22:08:17 +01:00
|
|
|
MainApplication app(argc, argv);
|
2012-01-15 12:35:29 +01:00
|
|
|
|
2012-03-14 14:04:20 +01:00
|
|
|
if (app.isClosing()) {
|
2011-11-09 16:58:25 +01:00
|
|
|
return 0;
|
2011-03-24 16:51:19 +01:00
|
|
|
}
|
2011-04-25 15:06:59 +02:00
|
|
|
|
2012-09-03 13:24:29 +02:00
|
|
|
app.setProxyStyle(new ProxyStyle);
|
2012-03-31 21:36:27 +02:00
|
|
|
|
2012-03-24 22:08:17 +01:00
|
|
|
return app.exec();
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|