2013-11-15 13:41:26 +01:00
|
|
|
/************************************************************************
|
2013-09-18 21:16:19 +02:00
|
|
|
**
|
2013-11-15 13:50:05 +01:00
|
|
|
** @file main.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-18 21:16:19 +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.
|
|
|
|
** Copyright (C) 2013 Valentina project
|
|
|
|
** <https://bitbucket.org/dismine/valentina> All Rights Reserved.
|
2013-09-18 21:16:19 +02:00
|
|
|
**
|
2013-11-15 13:41:26 +01:00
|
|
|
** Valentina is free software: you can redistribute it and/or modify
|
2013-09-18 21:16:19 +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-18 21:16:19 +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-18 21:16:19 +02:00
|
|
|
|
2013-06-20 16:09:50 +02:00
|
|
|
#include "mainwindow.h"
|
2013-10-01 20:15:59 +02:00
|
|
|
#include "widgets/vapplication.h"
|
2013-07-03 14:29:26 +02:00
|
|
|
#include <QTextCodec>
|
2013-11-21 13:05:26 +01:00
|
|
|
#include <QtCore>
|
2014-03-27 12:41:00 +01:00
|
|
|
#include <QMessageBox>
|
|
|
|
#include <QThread>
|
2013-08-29 12:31:50 +02:00
|
|
|
#include "tablewindow.h"
|
2014-04-16 17:32:41 +02:00
|
|
|
#include "version.h"
|
2013-06-20 16:09:50 +02:00
|
|
|
|
2014-03-27 12:41:00 +01:00
|
|
|
void noisyFailureMsgHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg)
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2014-03-27 12:41:00 +01:00
|
|
|
// Why on earth didn't Qt want to make failed signal/slot connections qWarning?
|
|
|
|
if ((type == QtDebugMsg) && msg.contains("::connect"))
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2014-03-27 12:41:00 +01:00
|
|
|
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)
|
|
|
|
{
|
|
|
|
QByteArray localMsg = msg.toLocal8Bit();
|
|
|
|
QMessageBox messageBox;
|
2014-05-01 13:33:40 +02:00
|
|
|
switch (type)
|
|
|
|
{
|
2014-03-27 12:41:00 +01:00
|
|
|
case QtDebugMsg:
|
|
|
|
fprintf(stderr, "Debug: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line,
|
|
|
|
context.function);
|
|
|
|
return;
|
|
|
|
case QtWarningMsg:
|
|
|
|
messageBox.setIcon(QMessageBox::Warning);
|
|
|
|
messageBox.setInformativeText(msg);
|
|
|
|
messageBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
|
|
|
|
fprintf(stderr, "Warning: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line,
|
|
|
|
context.function);
|
|
|
|
break;
|
|
|
|
case QtCriticalMsg:
|
|
|
|
messageBox.setIcon(QMessageBox::Critical);
|
|
|
|
messageBox.setInformativeText(msg);
|
|
|
|
messageBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
|
|
|
|
fprintf(stderr, "Critical: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line,
|
|
|
|
context.function);
|
|
|
|
break;
|
|
|
|
case QtFatalMsg:
|
|
|
|
messageBox.setIcon(QMessageBox::Critical);
|
|
|
|
messageBox.setInformativeText(msg);
|
|
|
|
messageBox.setStandardButtons(QMessageBox::Cancel);
|
|
|
|
fprintf(stderr, "Fatal: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line,
|
|
|
|
context.function);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
const int ret = messageBox.exec();
|
|
|
|
if (ret == QMessageBox::Cancel)
|
|
|
|
{
|
2013-11-04 21:35:15 +01:00
|
|
|
abort();
|
2014-03-27 12:41:00 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (type != QtDebugMsg)
|
|
|
|
{
|
|
|
|
abort(); // be NOISY unless overridden!
|
|
|
|
}
|
2013-07-25 14:00:51 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-04 21:35:15 +01:00
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
2014-02-07 17:12:18 +01:00
|
|
|
Q_INIT_RESOURCE(cursor);
|
|
|
|
Q_INIT_RESOURCE(icon);
|
|
|
|
Q_INIT_RESOURCE(schema);
|
|
|
|
Q_INIT_RESOURCE(theme);
|
|
|
|
|
2013-10-01 20:15:59 +02:00
|
|
|
VApplication app(argc, argv);
|
2014-03-27 12:41:00 +01:00
|
|
|
#ifdef QT_DEBUG
|
|
|
|
// Because our "noisy" message handler uses the GUI subsystem for message
|
|
|
|
// boxes, we can't install it until after the QApplication is constructed. But it
|
|
|
|
// is good to be the very next thing to run, to start catching warnings ASAP.
|
|
|
|
{
|
|
|
|
qInstallMessageHandler(noisyFailureMsgHandler);
|
|
|
|
}
|
|
|
|
#endif
|
2014-04-16 17:32:41 +02:00
|
|
|
app.setApplicationDisplayName(VER_PRODUCTNAME_STR);
|
|
|
|
app.setApplicationName(VER_INTERNALNAME_STR);
|
|
|
|
app.setOrganizationName(VER_COMPANYNAME_STR);
|
|
|
|
app.setOrganizationDomain(VER_COMPANYDOMAIN_STR);
|
|
|
|
// Setting the Application version
|
|
|
|
app.setApplicationVersion(APP_VERSION);
|
2014-02-14 12:29:04 +01:00
|
|
|
|
|
|
|
QSettings settings(QSettings::IniFormat, QSettings::UserScope, QApplication::organizationName(),
|
|
|
|
QApplication::applicationName());
|
|
|
|
QString defaultLocale = QLocale::system().name(); // e.g. "de_DE"
|
|
|
|
defaultLocale.truncate(defaultLocale.lastIndexOf('_')); // e.g. "de"
|
|
|
|
QString checkedLocale = settings.value("configuration/locale", defaultLocale).toString();
|
2013-09-18 18:52:49 +02:00
|
|
|
|
|
|
|
QTranslator qtTranslator;
|
2014-02-14 12:29:04 +01:00
|
|
|
qtTranslator.load("qt_" + checkedLocale, QLibraryInfo::location(QLibraryInfo::TranslationsPath));
|
2013-09-18 18:52:49 +02:00
|
|
|
app.installTranslator(&qtTranslator);
|
|
|
|
|
|
|
|
QTranslator appTranslator;
|
2014-02-21 15:58:07 +01:00
|
|
|
#ifdef Q_OS_WIN
|
2014-03-23 15:36:34 +01:00
|
|
|
appTranslator.load("valentina_" + checkedLocale, qApp->translationsPath());
|
2014-02-19 17:26:03 +01:00
|
|
|
#else
|
|
|
|
#ifdef QT_DEBUG
|
2014-03-23 15:36:34 +01:00
|
|
|
appTranslator.load("valentina_" + checkedLocale, qApp->translationsPath());
|
2014-02-19 17:26:03 +01:00
|
|
|
#else
|
2014-03-19 19:27:11 +01:00
|
|
|
appTranslator.load("valentina_" + checkedLocale, qApp->translationsPath());
|
2014-02-19 17:26:03 +01:00
|
|
|
#endif
|
|
|
|
#endif
|
2014-02-17 19:31:49 +01:00
|
|
|
app.installTranslator(&appTranslator);
|
2014-02-10 17:10:20 +01:00
|
|
|
|
2014-02-19 22:34:57 +01:00
|
|
|
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");
|
|
|
|
}
|
|
|
|
|
2013-06-20 16:09:50 +02:00
|
|
|
MainWindow w;
|
2013-10-14 13:49:01 +02:00
|
|
|
w.setWindowState(w.windowState() ^ Qt::WindowMaximized);
|
2013-07-03 14:29:26 +02:00
|
|
|
app.setWindowIcon(QIcon(":/icon/64x64/icon64x64.png"));
|
2013-08-29 12:31:50 +02:00
|
|
|
TableWindow table;
|
|
|
|
QObject::connect(&w, &MainWindow::ModelChosen, &table, &TableWindow::ModelChosen);
|
|
|
|
QObject::connect(&table, &TableWindow::closed, &w, &MainWindow::tableClosed);
|
2013-09-23 15:17:15 +02:00
|
|
|
|
|
|
|
const QStringList args = app.arguments();
|
|
|
|
QString fileName;
|
|
|
|
QRegExp rxArgOpenFile("-o");//parameter open file
|
|
|
|
|
2013-11-04 21:35:15 +01:00
|
|
|
if (args.size()>1)
|
|
|
|
{
|
|
|
|
for (int i = 1; i < args.size(); ++i)
|
|
|
|
{
|
|
|
|
if (rxArgOpenFile.indexIn(args.at(i)) != -1 )
|
|
|
|
{
|
|
|
|
if (args.at(i+1).isEmpty() == false)
|
|
|
|
{
|
2013-09-23 15:17:15 +02:00
|
|
|
fileName = args.at(i+1);
|
|
|
|
qDebug() << args.at(i)<< ":" << fileName;
|
2014-02-10 17:10:20 +01:00
|
|
|
w.LoadPattern(fileName);
|
2013-09-23 15:17:15 +02:00
|
|
|
}
|
|
|
|
w.show();
|
|
|
|
break;
|
2013-11-04 21:35:15 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-09-23 15:17:15 +02:00
|
|
|
qDebug() << "Uknown arg:" << args.at(i);
|
|
|
|
w.show();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2013-11-04 21:35:15 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-09-23 15:17:15 +02:00
|
|
|
w.show();
|
|
|
|
}
|
2013-07-03 14:29:26 +02:00
|
|
|
return app.exec();
|
2013-06-20 16:09:50 +02:00
|
|
|
}
|