2013-11-15 13:41:26 +01:00
|
|
|
/************************************************************************
|
2013-09-23 14:08:06 +02:00
|
|
|
**
|
2013-11-15 13:50:05 +01:00
|
|
|
** @file vapplication.cpp
|
2014-04-30 07:38:52 +02:00
|
|
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
2013-11-15 13:50:05 +01:00
|
|
|
** @date November 15, 2013
|
2013-09-23 14:08:06 +02:00
|
|
|
**
|
2013-11-15 13:41:26 +01:00
|
|
|
** @brief
|
|
|
|
** @copyright
|
|
|
|
** This source code is part of the Valentine project, a pattern making
|
|
|
|
** program, whose allow create and modeling patterns of clothing.
|
2015-02-27 11:27:48 +01:00
|
|
|
** Copyright (C) 2013-2015 Valentina project
|
2013-11-15 13:41:26 +01:00
|
|
|
** <https://bitbucket.org/dismine/valentina> All Rights Reserved.
|
2013-09-23 14:08:06 +02:00
|
|
|
**
|
2013-11-15 13:41:26 +01:00
|
|
|
** Valentina is free software: you can redistribute it and/or modify
|
2013-09-23 14:08:06 +02:00
|
|
|
** 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.
|
|
|
|
**
|
2013-10-27 13:36:29 +01:00
|
|
|
** Valentina is distributed in the hope that it will be useful,
|
2013-09-23 14:08:06 +02:00
|
|
|
** 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 Valentina. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
**
|
2013-11-15 13:41:26 +01:00
|
|
|
*************************************************************************/
|
2013-09-23 14:08:06 +02:00
|
|
|
|
|
|
|
#include "vapplication.h"
|
2015-07-10 11:24:47 +02:00
|
|
|
#include "..//ifc/exception/vexceptionobjecterror.h"
|
|
|
|
#include "../ifc/exception/vexceptionbadid.h"
|
|
|
|
#include "../ifc/exception/vexceptionconversionerror.h"
|
|
|
|
#include "../ifc/exception/vexceptionemptyparameter.h"
|
|
|
|
#include "../ifc/exception/vexceptionwrongid.h"
|
|
|
|
#include "../vwidgets/vmaingraphicsview.h"
|
2014-11-15 16:52:27 +01:00
|
|
|
#include "../version.h"
|
2015-06-15 13:43:41 +02:00
|
|
|
#include "../vmisc/logging.h"
|
2013-09-23 14:08:06 +02:00
|
|
|
|
2013-11-21 13:05:26 +01:00
|
|
|
#include <QDebug>
|
2014-05-12 11:35:33 +02:00
|
|
|
#include <QDir>
|
2014-07-04 16:52:11 +02:00
|
|
|
#include <QProcess>
|
2014-10-23 23:44:50 +02:00
|
|
|
#include <QTemporaryFile>
|
2014-06-08 20:10:57 +02:00
|
|
|
#include <QUndoStack>
|
2014-10-03 12:32:12 +02:00
|
|
|
#include <QtCore/qmath.h>
|
2014-10-23 21:16:40 +02:00
|
|
|
#include <QTemporaryFile>
|
2014-11-20 13:18:43 +01:00
|
|
|
#include <QFile>
|
|
|
|
#include <QStandardPaths>
|
|
|
|
#include <QMessageBox>
|
2014-11-28 19:33:28 +01:00
|
|
|
#include <QThread>
|
|
|
|
#include <QDateTime>
|
2014-11-29 13:12:43 +01:00
|
|
|
#include <QtXmlPatterns>
|
2014-11-20 18:52:51 +01:00
|
|
|
|
|
|
|
Q_LOGGING_CATEGORY(vApp, "v.application")
|
2014-11-20 13:18:43 +01:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline void noisyFailureMsgHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg)
|
|
|
|
{
|
|
|
|
// Why on earth didn't Qt want to make failed signal/slot connections qWarning?
|
|
|
|
if ((type == QtDebugMsg) && msg.contains("::connect"))
|
|
|
|
{
|
|
|
|
type = QtWarningMsg;
|
|
|
|
}
|
|
|
|
|
|
|
|
// this is another one that doesn't make sense as just a debug message. pretty serious
|
|
|
|
// sign of a problem
|
|
|
|
// http://www.developer.nokia.com/Community/Wiki/QPainter::begin:Paint_device_returned_engine_%3D%3D_0_(Known_Issue)
|
|
|
|
if ((type == QtDebugMsg) && msg.contains("QPainter::begin") && msg.contains("Paint device returned engine"))
|
|
|
|
{
|
|
|
|
type = QtWarningMsg;
|
|
|
|
}
|
|
|
|
|
|
|
|
// This qWarning about "Cowardly refusing to send clipboard message to hung application..."
|
|
|
|
// is something that can easily happen if you are debugging and the application is paused.
|
|
|
|
// As it is so common, not worth popping up a dialog.
|
|
|
|
if ((type == QtWarningMsg) && QString(msg).contains("QClipboard::event")
|
|
|
|
&& QString(msg).contains("Cowardly refusing"))
|
|
|
|
{
|
|
|
|
type = QtDebugMsg;
|
|
|
|
}
|
|
|
|
|
|
|
|
// only the GUI thread should display message boxes. If you are
|
|
|
|
// writing a multithreaded application and the error happens on
|
|
|
|
// a non-GUI thread, you'll have to queue the message to the GUI
|
|
|
|
QCoreApplication *instance = QCoreApplication::instance();
|
|
|
|
const bool isGuiThread = instance && (QThread::currentThread() == instance->thread());
|
|
|
|
|
|
|
|
if (isGuiThread)
|
|
|
|
{
|
2014-11-28 14:49:06 +01:00
|
|
|
QString debugdate = "[" + QDateTime::currentDateTime().toString("yyyy.MM.dd hh:mm:ss");
|
2014-11-20 13:18:43 +01:00
|
|
|
QMessageBox messageBox;
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case QtDebugMsg:
|
2014-11-28 14:49:06 +01:00
|
|
|
debugdate += QString(":DEBUG:%1(%2)] %3: %4: %5").arg(context.file).arg(context.line)
|
|
|
|
.arg(context.function).arg(context.category).arg(msg);
|
2014-11-20 13:18:43 +01:00
|
|
|
break;
|
|
|
|
case QtWarningMsg:
|
2014-11-28 14:49:06 +01:00
|
|
|
debugdate += QString(":WARNING:%1(%2)] %3: %4: %5").arg(context.file).arg(context.line)
|
|
|
|
.arg(context.function).arg(context.category).arg(msg);
|
2014-11-20 13:18:43 +01:00
|
|
|
messageBox.setIcon(QMessageBox::Warning);
|
|
|
|
break;
|
|
|
|
case QtCriticalMsg:
|
2014-11-28 14:49:06 +01:00
|
|
|
debugdate += QString(":CRITICAL:%1(%2)] %3: %4: %5").arg(context.file).arg(context.line)
|
|
|
|
.arg(context.function).arg(context.category).arg(msg);
|
2014-11-20 13:18:43 +01:00
|
|
|
messageBox.setIcon(QMessageBox::Critical);
|
|
|
|
break;
|
|
|
|
case QtFatalMsg:
|
2014-11-28 14:49:06 +01:00
|
|
|
debugdate += QString(":FATAL:%1(%2)] %3: %4: %5").arg(context.file).arg(context.line)
|
|
|
|
.arg(context.function).arg(context.category).arg(msg);
|
2014-11-20 13:18:43 +01:00
|
|
|
messageBox.setIcon(QMessageBox::Critical);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
(*qApp->LogFile()) << debugdate << endl;
|
|
|
|
|
2014-11-28 18:55:27 +01:00
|
|
|
if (type == QtWarningMsg || type == QtCriticalMsg || type == QtFatalMsg)
|
|
|
|
{
|
|
|
|
messageBox.setInformativeText(msg);
|
|
|
|
messageBox.setStandardButtons(QMessageBox::Ok);
|
|
|
|
messageBox.setWindowModality(Qt::ApplicationModal);
|
|
|
|
messageBox.setModal(true);
|
|
|
|
messageBox.exec();
|
|
|
|
}
|
|
|
|
|
2014-11-20 13:18:43 +01:00
|
|
|
if (QtFatalMsg == type)
|
|
|
|
{
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (type != QtDebugMsg)
|
|
|
|
{
|
|
|
|
abort(); // be NOISY unless overridden!
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2013-11-21 13:05:26 +01:00
|
|
|
|
2014-11-15 17:29:10 +01:00
|
|
|
#if defined(Q_OS_WIN) && defined(Q_CC_GNU)
|
2014-11-15 16:52:27 +01:00
|
|
|
const QString VApplication::GistFileName = QStringLiteral("gist.json");
|
2014-11-15 17:29:10 +01:00
|
|
|
#endif // defined(Q_OS_WIN) && defined(Q_CC_GNU)
|
2014-03-19 19:27:11 +01:00
|
|
|
|
2014-03-26 05:39:07 +01:00
|
|
|
#define DefWidth 1.2//mm
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-13 19:02:41 +02:00
|
|
|
/**
|
|
|
|
* @brief VApplication constructor.
|
|
|
|
* @param argc number arguments.
|
|
|
|
* @param argv command line.
|
|
|
|
*/
|
2014-03-19 19:27:11 +01:00
|
|
|
VApplication::VApplication(int &argc, char **argv)
|
2015-06-18 19:23:24 +02:00
|
|
|
: VAbstractApplication(argc, argv),
|
|
|
|
trVars(nullptr), autoSaveTimer(nullptr),
|
|
|
|
log(nullptr),
|
2015-04-05 16:31:28 +02:00
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 1, 0)
|
|
|
|
out(nullptr), logLock(nullptr)
|
|
|
|
#else
|
|
|
|
out(nullptr)
|
|
|
|
#endif
|
2014-03-19 19:27:11 +01:00
|
|
|
{
|
2014-06-04 13:30:45 +02:00
|
|
|
undoStack = new QUndoStack(this);
|
2014-03-19 19:27:11 +01:00
|
|
|
}
|
|
|
|
|
2014-11-20 13:18:43 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VApplication::~VApplication()
|
|
|
|
{
|
2015-04-01 19:08:35 +02:00
|
|
|
qCDebug(vApp, "Application closing.");
|
2014-11-20 13:18:43 +01:00
|
|
|
qInstallMessageHandler(0); // Resore the message handler
|
|
|
|
delete out;
|
|
|
|
|
|
|
|
if (log != nullptr)
|
|
|
|
{
|
|
|
|
log->close();
|
|
|
|
delete log;
|
2015-04-05 16:31:28 +02:00
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 1, 0)
|
2014-11-28 14:49:06 +01:00
|
|
|
delete logLock;
|
2015-04-05 16:31:28 +02:00
|
|
|
#endif
|
2014-11-20 13:18:43 +01:00
|
|
|
}
|
2015-06-11 12:15:57 +02:00
|
|
|
|
|
|
|
delete trVars;
|
2014-11-20 13:18:43 +01:00
|
|
|
}
|
|
|
|
|
2014-07-04 16:52:11 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* @brief NewValentina start Valentina in new process, send path to pattern file in argument.
|
|
|
|
* @param fileName path to pattern file.
|
|
|
|
*/
|
|
|
|
void VApplication::NewValentina(const QString &fileName)
|
|
|
|
{
|
2015-04-01 19:08:35 +02:00
|
|
|
qCDebug(vApp, "Open new detached process.");
|
2014-10-23 11:13:18 +02:00
|
|
|
if (fileName.isEmpty())
|
|
|
|
{
|
2015-04-01 19:08:35 +02:00
|
|
|
qCDebug(vApp, "New process without arguments. program = %s", qApp->applicationFilePath().toUtf8().constData());
|
2014-11-26 19:34:43 +01:00
|
|
|
// Path can contain spaces.
|
2014-11-28 16:16:39 +01:00
|
|
|
if (QProcess::startDetached("\""+qApp->applicationFilePath()+"\""))
|
2014-11-26 19:34:43 +01:00
|
|
|
{
|
2015-04-01 19:08:35 +02:00
|
|
|
qCDebug(vApp, "The process was started successfully.");
|
2014-11-26 19:34:43 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-04-01 19:08:35 +02:00
|
|
|
qCWarning(vApp, "Could not run process. The operation timed out or an error occurred.");
|
2014-11-26 19:34:43 +01:00
|
|
|
}
|
2014-10-23 11:13:18 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-11-28 16:16:39 +01:00
|
|
|
const QString run = QString("\"%1\" \"%2\"").arg(qApp->applicationFilePath()).arg(fileName);
|
2015-04-01 19:08:35 +02:00
|
|
|
qCDebug(vApp, "New process with arguments. program = %s", run.toUtf8().constData());
|
2015-03-02 18:11:43 +01:00
|
|
|
if (QProcess::startDetached(run))
|
2014-11-26 19:34:43 +01:00
|
|
|
{
|
2015-04-01 19:08:35 +02:00
|
|
|
qCDebug(vApp, "The process was started successfully.");
|
2014-11-26 19:34:43 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-04-01 19:08:35 +02:00
|
|
|
qCWarning(vApp, "Could not run process. The operation timed out or an error occurred.");
|
2014-11-26 19:34:43 +01:00
|
|
|
}
|
2014-10-23 11:13:18 +02:00
|
|
|
}
|
2014-07-04 16:52:11 +02:00
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-13 19:02:41 +02:00
|
|
|
/**
|
|
|
|
* @brief notify Reimplemented from QApplication::notify().
|
|
|
|
* @param receiver receiver.
|
|
|
|
* @param event event.
|
|
|
|
* @return value that is returned from the receiver's event handler.
|
|
|
|
*/
|
2014-03-26 05:39:07 +01:00
|
|
|
// reimplemented from QApplication so we can throw exceptions in slots
|
2013-11-04 21:35:15 +01:00
|
|
|
bool VApplication::notify(QObject *receiver, QEvent *event)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2014-03-19 19:27:11 +01:00
|
|
|
return QApplication::notify(receiver, event);
|
2013-09-23 14:08:06 +02:00
|
|
|
}
|
2013-11-04 21:35:15 +01:00
|
|
|
catch (const VExceptionObjectError &e)
|
|
|
|
{
|
2014-07-08 12:59:50 +02:00
|
|
|
e.CriticalMessageBox(tr("Error parsing file. Program will be terminated."), mainWindow);
|
2013-09-23 14:08:06 +02:00
|
|
|
abort();
|
|
|
|
}
|
2013-11-04 21:35:15 +01:00
|
|
|
catch (const VExceptionBadId &e)
|
|
|
|
{
|
2014-07-08 12:59:50 +02:00
|
|
|
e.CriticalMessageBox(tr("Error bad id. Program will be terminated."), mainWindow);
|
2013-09-23 14:08:06 +02:00
|
|
|
abort();
|
|
|
|
}
|
2013-11-04 21:35:15 +01:00
|
|
|
catch (const VExceptionConversionError &e)
|
|
|
|
{
|
2014-07-08 12:59:50 +02:00
|
|
|
e.CriticalMessageBox(tr("Error can't convert value. Program will be terminated."), mainWindow);
|
2013-09-23 14:08:06 +02:00
|
|
|
abort();
|
|
|
|
}
|
2013-11-04 21:35:15 +01:00
|
|
|
catch (const VExceptionEmptyParameter &e)
|
|
|
|
{
|
2014-07-08 12:59:50 +02:00
|
|
|
e.CriticalMessageBox(tr("Error empty parameter. Program will be terminated."), mainWindow);
|
2013-09-23 14:08:06 +02:00
|
|
|
abort();
|
|
|
|
}
|
2014-03-03 18:32:38 +01:00
|
|
|
catch (const VExceptionWrongId &e)
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2014-07-08 12:59:50 +02:00
|
|
|
e.CriticalMessageBox(tr("Error wrong id. Program will be terminated."), mainWindow);
|
2013-09-23 14:08:06 +02:00
|
|
|
abort();
|
|
|
|
}
|
2013-11-04 21:35:15 +01:00
|
|
|
catch (const VException &e)
|
|
|
|
{
|
2014-07-08 12:59:50 +02:00
|
|
|
e.CriticalMessageBox(tr("Something's wrong!!"), mainWindow);
|
2014-03-03 16:42:14 +01:00
|
|
|
return true;
|
2013-10-10 20:45:58 +02:00
|
|
|
}
|
2013-11-04 21:35:15 +01:00
|
|
|
catch (std::exception& e)
|
|
|
|
{
|
2013-09-23 14:08:06 +02:00
|
|
|
qCritical() << "Exception thrown:" << e.what();
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2014-03-19 19:27:11 +01:00
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-03-19 19:27:11 +01:00
|
|
|
QString VApplication::translationsPath() const
|
|
|
|
{
|
2014-10-24 16:23:41 +02:00
|
|
|
const QString trPath = QStringLiteral("/translations");
|
2014-03-26 05:39:07 +01:00
|
|
|
#ifdef Q_OS_WIN
|
2014-10-24 16:23:41 +02:00
|
|
|
return QApplication::applicationDirPath() + trPath;
|
2014-03-26 05:39:07 +01:00
|
|
|
#else
|
|
|
|
#ifdef QT_DEBUG
|
2014-10-24 16:23:41 +02:00
|
|
|
return QApplication::applicationDirPath() + trPath;
|
2014-05-12 11:35:33 +02:00
|
|
|
#else
|
2014-10-24 16:23:41 +02:00
|
|
|
QDir dir(QApplication::applicationDirPath() + trPath);
|
2014-06-10 22:14:16 +02:00
|
|
|
if (dir.exists())
|
2014-05-12 11:35:33 +02:00
|
|
|
{
|
|
|
|
return dir.absolutePath();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-03-19 19:27:11 +01:00
|
|
|
return QStringLiteral("/usr/share/valentina/translations");
|
2014-05-12 11:35:33 +02:00
|
|
|
}
|
2014-03-19 19:27:11 +01:00
|
|
|
#endif
|
2014-05-12 11:35:33 +02:00
|
|
|
#endif
|
2014-03-19 19:27:11 +01:00
|
|
|
}
|
2014-03-26 05:39:07 +01:00
|
|
|
|
2014-11-20 13:18:43 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QString VApplication::LogDirPath() const
|
|
|
|
{
|
|
|
|
#if defined(Q_OS_WIN) || defined(Q_OS_OSX)
|
|
|
|
const QString logDirPath = QStandardPaths::locate(QStandardPaths::GenericDataLocation, QString(),
|
|
|
|
QStandardPaths::LocateDirectory) + "Valentina";
|
|
|
|
#else
|
|
|
|
const QString logDirPath = QStandardPaths::locate(QStandardPaths::ConfigLocation, QString(),
|
|
|
|
QStandardPaths::LocateDirectory) + organizationName();
|
|
|
|
#endif
|
|
|
|
return logDirPath;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QString VApplication::LogPath() const
|
|
|
|
{
|
2014-11-28 14:49:06 +01:00
|
|
|
return QString("%1/valentina-pid%2.log").arg(LogDirPath()).arg(qApp->applicationPid());
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VApplication::CreateLogDir() const
|
|
|
|
{
|
|
|
|
QDir logDir(LogDirPath());
|
|
|
|
if (logDir.exists() == false)
|
|
|
|
{
|
|
|
|
logDir.mkpath("."); // Create directory for log if need
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VApplication::BeginLogging()
|
|
|
|
{
|
|
|
|
log = new QFile(LogPath());
|
|
|
|
if (log->open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text))
|
|
|
|
{
|
|
|
|
out = new QTextStream(log);
|
|
|
|
qInstallMessageHandler(noisyFailureMsgHandler);
|
2015-04-05 16:31:28 +02:00
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 1, 0)
|
2014-11-28 14:49:06 +01:00
|
|
|
logLock = new QLockFile(LogPath()+".lock");
|
|
|
|
logLock->setStaleLockTime(0);
|
2015-01-26 16:02:57 +01:00
|
|
|
if (TryLock(logLock))
|
2014-11-28 14:49:06 +01:00
|
|
|
{
|
2015-04-01 19:08:35 +02:00
|
|
|
qCDebug(vApp, "Log file %s was locked.", LogPath().toUtf8().constData());
|
2014-11-28 14:49:06 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-04-01 19:08:35 +02:00
|
|
|
qCDebug(vApp, "Failed to lock %s", LogPath().toUtf8().constData());
|
|
|
|
qCDebug(vApp, "Error type: %d", logLock->error());
|
2014-11-28 14:49:06 +01:00
|
|
|
}
|
2015-04-05 16:31:28 +02:00
|
|
|
#endif //QT_VERSION >= QT_VERSION_CHECK(5, 1, 0)
|
2014-11-28 14:49:06 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
delete log;
|
2014-12-18 11:52:39 +01:00
|
|
|
log = nullptr;
|
2015-04-01 19:08:35 +02:00
|
|
|
qCDebug(vApp, "Error opening log file \'%s\'. All debug output redirected to console.",
|
|
|
|
LogPath().toUtf8().constData());
|
2014-11-28 14:49:06 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VApplication::ClearOldLogs() const
|
|
|
|
{
|
|
|
|
QStringList filters{"*.log"};
|
|
|
|
QDir logsDir(LogDirPath());
|
|
|
|
logsDir.setNameFilters(filters);
|
|
|
|
logsDir.setCurrent(LogDirPath());
|
|
|
|
|
|
|
|
const QStringList allFiles = logsDir.entryList(QDir::NoDotAndDotDot | QDir::Files);
|
|
|
|
if (allFiles.isEmpty() == false)
|
|
|
|
{
|
2015-04-01 19:08:35 +02:00
|
|
|
qCDebug(vApp, "Clearing old logs");
|
2014-11-28 14:49:06 +01:00
|
|
|
for (int i = 0; i < allFiles.size(); ++i)
|
|
|
|
{
|
|
|
|
QFileInfo info(allFiles.at(i));
|
2015-04-05 16:31:28 +02:00
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 1, 0)
|
2014-11-28 14:49:06 +01:00
|
|
|
QLockFile *lock = new QLockFile(info.absoluteFilePath() + ".lock");
|
2015-01-26 16:02:57 +01:00
|
|
|
if (TryLock(lock))
|
2014-11-28 14:49:06 +01:00
|
|
|
{
|
2015-04-01 19:08:35 +02:00
|
|
|
qCDebug(vApp, "Locked file %s", info.absoluteFilePath().toUtf8().constData());
|
2014-11-28 14:49:06 +01:00
|
|
|
QFile oldLog(allFiles.at(i));
|
|
|
|
if (oldLog.remove())
|
|
|
|
{
|
2015-04-01 19:08:35 +02:00
|
|
|
qCDebug(vApp, "Deleted %s", info.absoluteFilePath().toUtf8().constData());
|
2014-11-28 14:49:06 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-04-01 19:08:35 +02:00
|
|
|
qCDebug(vApp, "Could not delete %s", info.absoluteFilePath().toUtf8().constData());
|
2014-11-28 14:49:06 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-04-01 19:08:35 +02:00
|
|
|
qCDebug(vApp, "Failed to lock %s", info.absoluteFilePath().toUtf8().constData());
|
2014-11-28 14:49:06 +01:00
|
|
|
}
|
2015-04-05 16:31:28 +02:00
|
|
|
|
2014-11-28 14:49:06 +01:00
|
|
|
delete lock;
|
2014-12-17 13:57:17 +01:00
|
|
|
lock = nullptr;
|
2015-04-05 16:31:28 +02:00
|
|
|
#else
|
|
|
|
if (info.created().daysTo(QDateTime::currentDateTime()) >= 3)
|
|
|
|
{
|
|
|
|
QFile oldLog(allFiles.at(i));
|
|
|
|
if (oldLog.remove())
|
|
|
|
{
|
|
|
|
qCDebug(vApp, "Deleted %s", info.absoluteFilePath().toUtf8().constData());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
qCDebug(vApp, "Could not delete %s", info.absoluteFilePath().toUtf8().constData());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif //QT_VERSION >= QT_VERSION_CHECK(5, 1, 0)
|
2014-11-28 14:49:06 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-04-01 19:08:35 +02:00
|
|
|
qCDebug(vApp, "There are no old logs.");
|
2014-11-28 14:49:06 +01:00
|
|
|
}
|
2014-11-20 13:18:43 +01:00
|
|
|
}
|
|
|
|
|
2015-06-11 14:24:38 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VApplication::InitOptions()
|
|
|
|
{
|
|
|
|
setApplicationDisplayName(VER_PRODUCTNAME_STR);
|
|
|
|
setApplicationName(VER_INTERNALNAME_STR);
|
|
|
|
setOrganizationName(VER_COMPANYNAME_STR);
|
|
|
|
setOrganizationDomain(VER_COMPANYDOMAIN_STR);
|
|
|
|
// Setting the Application version
|
|
|
|
setApplicationVersion(APP_VERSION_STR);
|
|
|
|
|
|
|
|
OpenSettings();
|
|
|
|
|
|
|
|
#if defined(Q_OS_WIN) && defined(Q_CC_GNU)
|
|
|
|
// Catch and send report
|
|
|
|
VApplication::DrMingw();
|
|
|
|
this->CollectReports();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Run creation log after sending crash report
|
|
|
|
StartLogging();
|
|
|
|
|
|
|
|
qDebug()<<"Version:"<<APP_VERSION_STR;
|
|
|
|
qDebug()<<"Build revision:"<<BUILD_REVISION;
|
|
|
|
qDebug()<<buildCompatibilityString();
|
|
|
|
qDebug()<<"Built on"<<__DATE__<<"at"<<__TIME__;
|
|
|
|
qDebug()<<"Command-line arguments:"<<this->arguments();
|
|
|
|
qDebug()<<"Process ID:"<<this->applicationPid();
|
|
|
|
|
2015-07-24 14:06:53 +02:00
|
|
|
const QString checkedLocale = ValentinaSettings()->GetLocale();
|
2015-06-11 14:24:38 +02:00
|
|
|
qDebug()<<"Checked locale:"<<checkedLocale;
|
|
|
|
|
|
|
|
QTranslator *qtTranslator = new QTranslator(this);
|
|
|
|
#if defined(Q_OS_WIN)
|
|
|
|
qtTranslator->load("qt_" + checkedLocale, translationsPath());
|
|
|
|
#else
|
|
|
|
qtTranslator->load("qt_" + checkedLocale, QLibraryInfo::location(QLibraryInfo::TranslationsPath));
|
|
|
|
#endif
|
|
|
|
installTranslator(qtTranslator);
|
|
|
|
|
|
|
|
QTranslator *qtxmlTranslator = new QTranslator(this);
|
|
|
|
#if defined(Q_OS_WIN)
|
|
|
|
qtxmlTranslator->load("qtxmlpatterns_" + checkedLocale, translationsPath());
|
|
|
|
#else
|
|
|
|
qtxmlTranslator->load("qtxmlpatterns_" + checkedLocale, QLibraryInfo::location(QLibraryInfo::TranslationsPath));
|
|
|
|
#endif
|
|
|
|
installTranslator(qtxmlTranslator);
|
|
|
|
|
|
|
|
QTranslator *appTranslator = new QTranslator(this);
|
|
|
|
appTranslator->load("valentina_" + checkedLocale, translationsPath());
|
|
|
|
installTranslator(appTranslator);
|
|
|
|
|
|
|
|
InitTrVars();//Very important do it after load QM files.
|
|
|
|
|
|
|
|
static const char * GENERIC_ICON_TO_CHECK = "document-open";
|
|
|
|
if (QIcon::hasThemeIcon(GENERIC_ICON_TO_CHECK) == false)
|
|
|
|
{
|
|
|
|
//If there is no default working icon theme then we should
|
|
|
|
//use an icon theme that we provide via a .qrc file
|
|
|
|
//This case happens under Windows and Mac OS X
|
|
|
|
//This does not happen under GNOME or KDE
|
|
|
|
QIcon::setThemeName("win.icon.theme");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-09 15:11:50 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QStringList VApplication::LabelLanguages()
|
|
|
|
{
|
2014-10-17 22:26:30 +02:00
|
|
|
QStringList list = QStringList() << "de" // German
|
|
|
|
<< "en" // English
|
|
|
|
<< "fr" // French
|
|
|
|
<< "ru" // Russian
|
|
|
|
<< "uk" // Ukrainian
|
|
|
|
<< "hr" // Croatian
|
|
|
|
<< "sr" // Serbian
|
|
|
|
<< "bs"; // Bosnian
|
2014-09-09 15:11:50 +02:00
|
|
|
return list;
|
|
|
|
}
|
2014-09-18 11:30:33 +02:00
|
|
|
|
2014-11-20 13:18:43 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VApplication::StartLogging()
|
|
|
|
{
|
2015-04-02 16:01:05 +02:00
|
|
|
#if QT_VERSION < QT_VERSION_CHECK(5, 3, 0)
|
|
|
|
|
|
|
|
#if QT_VERSION < QT_VERSION_CHECK(5, 2, 0)
|
|
|
|
// Qt < 5.2 didn't feature categorized logging
|
|
|
|
// Do nothing
|
|
|
|
#else
|
2014-11-26 17:54:17 +01:00
|
|
|
// In Qt 5.2 need manualy enable debug information for categories. This work
|
|
|
|
// because Qt doesn't provide debug information for categories itself. And in this
|
|
|
|
// case will show our messages. Another situation with Qt 5.3 that has many debug
|
|
|
|
// messages itself. We don't need this information and can turn on later if need.
|
|
|
|
// But here Qt already show our debug messages without enabling.
|
2014-11-20 18:52:51 +01:00
|
|
|
QLoggingCategory::setFilterRules("*.debug=true\n");
|
2015-04-02 16:01:05 +02:00
|
|
|
#endif // QT_VERSION < QT_VERSION_CHECK(5, 2, 0)
|
|
|
|
|
|
|
|
#endif // QT_VERSION < QT_VERSION_CHECK(5, 3, 0)
|
2014-11-20 18:52:51 +01:00
|
|
|
|
2014-11-28 14:49:06 +01:00
|
|
|
CreateLogDir();
|
|
|
|
BeginLogging();
|
|
|
|
ClearOldLogs();
|
2014-11-29 13:12:43 +01:00
|
|
|
#if defined(Q_OS_WIN) && defined(Q_CC_GNU)
|
|
|
|
ClearOldReports();
|
|
|
|
#endif // defined(Q_OS_WIN) && defined(Q_CC_GNU)
|
2014-11-20 13:18:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QTextStream *VApplication::LogFile()
|
|
|
|
{
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
2015-06-11 12:15:57 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
const VTranslateVars *VApplication::TrVars()
|
|
|
|
{
|
|
|
|
return trVars;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VApplication::InitTrVars()
|
|
|
|
{
|
2015-07-24 14:06:53 +02:00
|
|
|
trVars = new VTranslateVars(ValentinaSettings()->GetOsSeparator());
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* @brief OpenSettings get acsses to application settings.
|
|
|
|
*
|
|
|
|
* Because we can create object in constructor we open file separately.
|
|
|
|
*/
|
|
|
|
void VApplication::OpenSettings()
|
|
|
|
{
|
|
|
|
settings = new VSettings(QSettings::IniFormat, QSettings::UserScope, QApplication::organizationName(),
|
|
|
|
QApplication::applicationName(), this);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VSettings *VApplication::ValentinaSettings()
|
|
|
|
{
|
|
|
|
SCASSERT(settings != nullptr);
|
|
|
|
return qobject_cast<VSettings *>(settings);
|
2015-06-11 12:15:57 +02:00
|
|
|
}
|
|
|
|
|
2014-11-15 16:52:27 +01:00
|
|
|
#if defined(Q_OS_WIN) && defined(Q_CC_GNU)
|
2014-11-29 13:12:43 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VApplication::ClearOldReports() const
|
|
|
|
{
|
|
|
|
const QString reportsDir = QString("%1/reports").arg(qApp->applicationDirPath());
|
|
|
|
QDir reports(reportsDir);
|
|
|
|
if (reports.exists())
|
|
|
|
{
|
|
|
|
QStringList filters{"*.log", "*.RPT"};
|
|
|
|
QDir logsDir(reportsDir);
|
|
|
|
logsDir.setNameFilters(filters);
|
|
|
|
logsDir.setCurrent(reportsDir);
|
|
|
|
|
|
|
|
const QStringList allFiles = logsDir.entryList(QDir::NoDotAndDotDot | QDir::Files);
|
|
|
|
if (allFiles.isEmpty() == false)
|
|
|
|
{
|
|
|
|
const QDateTime now = QDateTime::currentDateTime();
|
|
|
|
for (int i = 0; i < allFiles.size(); ++i)
|
|
|
|
{
|
|
|
|
QFileInfo info(allFiles.at(i));
|
|
|
|
if (info.created().daysTo(now) > 30)
|
|
|
|
{
|
|
|
|
QFile(allFiles.at(i)).remove();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-30 16:30:47 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VApplication::GatherLogs() const
|
|
|
|
{
|
|
|
|
QTextStream *out = nullptr;
|
|
|
|
QFile *log = new QFile(QString("%1/valentina.log").arg(LogDirPath()));
|
|
|
|
if (log->open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text))
|
|
|
|
{
|
|
|
|
out = new QTextStream(log);
|
|
|
|
|
|
|
|
QStringList filters{"*.log"};
|
|
|
|
QDir logsDir(LogDirPath());
|
|
|
|
logsDir.setNameFilters(filters);
|
|
|
|
logsDir.setCurrent(LogDirPath());
|
|
|
|
|
|
|
|
const QStringList allFiles = logsDir.entryList(QDir::NoDotAndDotDot | QDir::Files);
|
|
|
|
if (allFiles.isEmpty() == false)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < allFiles.size(); ++i)
|
|
|
|
{
|
|
|
|
QFileInfo info(allFiles.at(i));
|
|
|
|
if (info.fileName() == "valentina.log")
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
QLockFile *logLock = new QLockFile(info.absoluteFilePath()+".lock");
|
|
|
|
logLock->setStaleLockTime(0);
|
2015-01-26 16:02:57 +01:00
|
|
|
if (TryLock(logLock))
|
2014-11-30 16:30:47 +01:00
|
|
|
{
|
|
|
|
*out <<"--------------------------" << endl;
|
|
|
|
QFile logFile(info.absoluteFilePath());
|
|
|
|
if (logFile.open(QIODevice::ReadOnly | QIODevice::Text))
|
|
|
|
{
|
|
|
|
QTextStream in(&logFile);
|
|
|
|
while (!in.atEnd())
|
|
|
|
{
|
|
|
|
*out << in.readLine() << endl;
|
|
|
|
}
|
|
|
|
logFile.close();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*out << "Log file error:" + logFile.errorString() << endl;
|
|
|
|
}
|
|
|
|
}
|
2014-12-25 16:50:46 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
*out << "Could not lock" << info.absoluteFilePath() << ".";
|
|
|
|
}
|
2014-11-30 16:30:47 +01:00
|
|
|
delete logLock;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*out << "Could not find logs.";
|
|
|
|
}
|
|
|
|
log->close();
|
|
|
|
}
|
|
|
|
delete out;
|
|
|
|
delete log;
|
|
|
|
}
|
|
|
|
|
2014-11-15 16:52:27 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
// Catch exception and create report. Use if program build with Mingw compiler.
|
|
|
|
// See more about catcher https://github.com/jrfonseca/drmingw/blob/master/README.md
|
|
|
|
void VApplication::DrMingw()
|
|
|
|
{
|
|
|
|
QFile drmingw("exchndl.dll");
|
2015-03-02 18:11:43 +01:00
|
|
|
if (drmingw.exists())
|
2014-11-15 16:52:27 +01:00
|
|
|
{// If don't want create reports just delete exchndl.dll from installer
|
|
|
|
LoadLibrary(L"exchndl.dll");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VApplication::CollectReports() const
|
|
|
|
{
|
|
|
|
// Seek file "binary_name.RPT"
|
|
|
|
const QString reportName = QString("%1/%2.RPT").arg(applicationDirPath())
|
|
|
|
.arg(QFileInfo(arguments().at(0)).baseName());
|
|
|
|
QFile reportFile(reportName);
|
|
|
|
if (reportFile.exists())
|
|
|
|
{ // Hooray we have found crash
|
|
|
|
if (settings == nullptr)
|
|
|
|
{
|
|
|
|
return;// Settings was not opened.
|
|
|
|
}
|
|
|
|
|
2014-11-22 17:15:47 +01:00
|
|
|
if (settings->GetSendReportState())
|
2014-11-15 16:52:27 +01:00
|
|
|
{ // Try send report
|
|
|
|
// Remove gist.json file before close app.
|
|
|
|
connect(this, &VApplication::aboutToQuit, this, &VApplication::CleanGist, Qt::UniqueConnection);
|
|
|
|
SendReport(reportName);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{ // Just collect report to /reports directory
|
|
|
|
CollectReport(reportName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VApplication::CollectReport(const QString &reportName) const
|
|
|
|
{
|
|
|
|
const QString reportsDir = QString("%1/reports").arg(qApp->applicationDirPath());
|
|
|
|
QDir reports(reportsDir);
|
|
|
|
if (reports.exists() == false)
|
|
|
|
{
|
|
|
|
reports.mkpath("."); // Create directory for reports if need
|
|
|
|
}
|
|
|
|
|
|
|
|
const QDateTime now = QDateTime::currentDateTime();
|
2014-11-20 13:18:43 +01:00
|
|
|
const QString timestamp = now.toString(QLatin1String("yyyy.MM.dd-hh_mm_ss"));
|
|
|
|
QString filename = QString("%1/reports/crash-%2.RPT").arg(qApp->applicationDirPath()).arg(timestamp);
|
2014-11-15 16:52:27 +01:00
|
|
|
|
|
|
|
QFile reportFile(reportName);
|
|
|
|
reportFile.copy(filename); // Collect new crash
|
|
|
|
reportFile.remove(); // Clear after yourself
|
2014-11-20 13:18:43 +01:00
|
|
|
|
|
|
|
filename = QString("%1/reports/log-%2.log").arg(qApp->applicationDirPath()).arg(timestamp);
|
2014-11-30 16:30:47 +01:00
|
|
|
GatherLogs();
|
|
|
|
QFile logFile(QString("%1/valentina.log").arg(LogDirPath()));
|
2014-11-20 13:18:43 +01:00
|
|
|
logFile.copy(filename); // Collect log
|
2014-11-15 16:52:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VApplication::CleanGist() const
|
|
|
|
{
|
|
|
|
QFile gistFile(GistFileName);
|
|
|
|
if (gistFile.exists())
|
|
|
|
{
|
|
|
|
gistFile.remove();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VApplication::SendReport(const QString &reportName) const
|
|
|
|
{
|
|
|
|
QString content;
|
|
|
|
QFile reportFile(reportName);
|
2014-11-20 13:18:43 +01:00
|
|
|
if (reportFile.open(QIODevice::ReadOnly | QIODevice::Text))
|
2014-11-15 16:52:27 +01:00
|
|
|
{
|
2014-11-20 13:18:43 +01:00
|
|
|
content = ReadFileForSending(reportFile);
|
|
|
|
reportFile.close();
|
2014-11-15 16:52:27 +01:00
|
|
|
}
|
2014-11-20 13:18:43 +01:00
|
|
|
else
|
2014-11-15 16:52:27 +01:00
|
|
|
{
|
2014-11-26 18:02:34 +01:00
|
|
|
content = "RPT file error:" + reportFile.errorString() + "\r\n";
|
2014-11-15 16:52:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Additional information
|
|
|
|
content.append(QString("-------------------------------")+"\r\n");
|
|
|
|
content.append(QString("Version:%1").arg(APP_VERSION)+"\r\n");
|
2015-02-18 11:17:56 +01:00
|
|
|
content.append(QString("Build revision:%1").arg(BUILD_REVISION)+"\r\n");
|
2014-11-15 16:52:27 +01:00
|
|
|
content.append(QString("Based on Qt %2 (32 bit)").arg(QT_VERSION_STR)+"\r\n");
|
|
|
|
content.append(QString("Built on %3 at %4").arg(__DATE__).arg(__TIME__)+"\r\n");
|
2015-02-18 14:29:44 +01:00
|
|
|
content.append(QString("Web site:http://www.valentina-project.org/ ")+"\r\n");
|
2014-11-20 13:18:43 +01:00
|
|
|
content.append("\r\n");
|
2014-11-15 16:52:27 +01:00
|
|
|
|
|
|
|
// Creating json with report
|
|
|
|
// Example:
|
|
|
|
//{
|
|
|
|
// "description":"Crash report",
|
|
|
|
// "public":"true",
|
|
|
|
// "files":{
|
2014-11-20 13:18:43 +01:00
|
|
|
// "valentina.RPT":{
|
2014-11-15 16:52:27 +01:00
|
|
|
// "content":"Report text here"
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
//}
|
|
|
|
|
|
|
|
// Useful to know when crash was created
|
|
|
|
const QDateTime now = QDateTime::currentDateTime();
|
|
|
|
const QString timestamp = now.toString(QLatin1String("yyyy/MM/dd hh:mm:ss:zzz"));
|
|
|
|
const QString report = QString("Crash report was created %2").arg(timestamp);
|
|
|
|
|
|
|
|
QJsonObject reportObject;
|
|
|
|
reportObject.insert(QStringLiteral("description"), QJsonValue(report));
|
|
|
|
reportObject.insert(QStringLiteral("public"), QJsonValue(QString("true")));
|
|
|
|
|
2014-11-26 18:02:34 +01:00
|
|
|
content.append(QString("\r\n-------------------------------\r\n"));
|
2014-11-20 13:18:43 +01:00
|
|
|
content.append(QString("Log:")+"\r\n");
|
|
|
|
|
2014-11-30 16:30:47 +01:00
|
|
|
GatherLogs();
|
|
|
|
QFile logFile(QString("%1/valentina.log").arg(LogDirPath()));
|
2014-11-20 13:18:43 +01:00
|
|
|
if (logFile.open(QIODevice::ReadOnly | QIODevice::Text))
|
|
|
|
{
|
2014-12-27 20:12:45 +01:00
|
|
|
const QString logContent = ReadFileForSending(logFile);
|
|
|
|
if (logContent.isEmpty())
|
|
|
|
{
|
|
|
|
content.append("Log file is empty.");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
content.append(logContent);
|
|
|
|
}
|
2014-11-20 13:18:43 +01:00
|
|
|
logFile.close();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-11-26 18:02:34 +01:00
|
|
|
content.append("\r\n Log file error:" + logFile.errorString() + "\r\n");
|
2014-11-20 13:18:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
const QString contentSection = QStringLiteral("content");
|
2014-11-15 16:52:27 +01:00
|
|
|
QJsonObject contentObject;
|
2014-11-20 13:18:43 +01:00
|
|
|
contentObject.insert(contentSection, QJsonValue(content));
|
2014-11-15 16:52:27 +01:00
|
|
|
|
2014-11-20 13:18:43 +01:00
|
|
|
const QString filesSection = QStringLiteral("files");
|
2014-11-15 16:52:27 +01:00
|
|
|
QJsonObject fileObject;
|
|
|
|
fileObject.insert(QFileInfo(reportName).fileName(), QJsonValue(contentObject));
|
2014-11-20 13:18:43 +01:00
|
|
|
reportObject.insert(filesSection, QJsonValue(fileObject));
|
2014-11-15 16:52:27 +01:00
|
|
|
|
|
|
|
QFile gistFile(GistFileName);
|
|
|
|
if (!gistFile.open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text))
|
|
|
|
{
|
|
|
|
qDebug("Couldn't open gist file.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Save data to file
|
|
|
|
QJsonDocument saveRep(reportObject);
|
|
|
|
gistFile.write(saveRep.toJson());
|
|
|
|
gistFile.close();
|
|
|
|
|
2015-02-22 19:46:08 +01:00
|
|
|
const QString curl = QString("%1/curl.exe").arg(qApp->applicationDirPath());
|
|
|
|
QFile curlFile(curl);
|
2014-11-15 16:52:27 +01:00
|
|
|
if (curlFile.exists())
|
|
|
|
{// Trying send report
|
2015-02-22 19:46:08 +01:00
|
|
|
// Change token if need
|
2015-03-23 14:03:12 +01:00
|
|
|
const QStringList token = QStringList()<<"78"<<"5e"<<"02"<<"bd"<<"41"<<"e9"<<"6a"<<"63"<<"ab"<<"18"<<"09"<<"2f"
|
|
|
|
<<"13"<<"cf"<<"48"<<"b4"<<"75"<<"6a"<<"42"<<"39";
|
2015-02-22 19:46:08 +01:00
|
|
|
|
|
|
|
const QString arg = QString("curl.exe -k -H \"Authorization: bearer ")+token.join("")+
|
|
|
|
QString("\" -H \"Accept: application/json\" -H \"Content-type: application/json\" -X POST "
|
|
|
|
"--data @gist.json https://api.github.com/gists");
|
2014-11-15 16:52:27 +01:00
|
|
|
QProcess::startDetached(arg);
|
|
|
|
reportFile.remove();// Clear after yourself
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{// We can not send than just collect
|
|
|
|
CollectReport(reportName);
|
|
|
|
}
|
2015-02-22 19:46:08 +01:00
|
|
|
curlFile.close();
|
2014-11-15 16:52:27 +01:00
|
|
|
}
|
2014-11-20 13:18:43 +01:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QString VApplication::ReadFileForSending(QFile &file) const
|
|
|
|
{
|
|
|
|
QString content;
|
|
|
|
QTextStream in(&file);
|
|
|
|
while (!in.atEnd())
|
|
|
|
{
|
|
|
|
content.append(in.readLine()+"\r\n");// Windows end of line
|
|
|
|
}
|
|
|
|
return content;
|
|
|
|
}
|
2014-11-15 16:52:27 +01:00
|
|
|
#endif //defined(Q_OS_WIN) && defined(Q_CC_GNU)
|