Skip to content

Commit

Permalink
Linux specific Qt5 port
Browse files Browse the repository at this point in the history
  • Loading branch information
wwmayer committed Dec 13, 2016
1 parent 5e375a6 commit 87f2866
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 5 deletions.
34 changes: 29 additions & 5 deletions src/Gui/Application.cpp
Expand Up @@ -1387,11 +1387,38 @@ _qt_msg_handler_old old_qtmsg_handler = 0;
#if QT_VERSION >= 0x050000
void messageHandler(QtMsgType type, const QMessageLogContext &context, const QString &qmsg)
{
Q_UNUSED(context);
const QChar *msg = qmsg.unicode();
#ifdef FC_DEBUG
switch (type)
{
case QtInfoMsg:
case QtDebugMsg:
Base::Console().Message("%s\n", msg);
break;
case QtWarningMsg:
Base::Console().Warning("%s\n", msg);
break;
case QtCriticalMsg:
Base::Console().Error("%s\n", msg);
break;
case QtFatalMsg:
Base::Console().Error("%s\n", msg);
abort(); // deliberately core dump
}
#ifdef FC_OS_WIN32
if (old_qtmsg_handler)
(*old_qtmsg_handler)(type, context, qmsg);
#endif
#else
// do not stress user with Qt internals but write to log file if enabled
Q_UNUSED(type);
Base::Console().Log("%s\n", msg);
#endif
}
#else
void messageHandler(QtMsgType type, const char *msg)
{
#endif
#ifdef FC_DEBUG
switch (type)
{
Expand All @@ -1410,18 +1437,15 @@ void messageHandler(QtMsgType type, const char *msg)
}
#ifdef FC_OS_WIN32
if (old_qtmsg_handler)
#if QT_VERSION >=0x050000
(*old_qtmsg_handler)(type, context, qmsg);
#else
(*old_qtmsg_handler)(type, msg);
#endif
#endif
#else
// do not stress user with Qt internals but write to log file if enabled
Q_UNUSED(type);
Base::Console().Log("%s\n", msg);
#endif
}
#endif

#ifdef FC_DEBUG // redirect Coin messages to FreeCAD
void messageHandlerCoin(const SoError * error, void * /*userdata*/)
Expand Down
30 changes: 30 additions & 0 deletions src/Gui/FileDialog.cpp
Expand Up @@ -151,12 +151,22 @@ QString FileDialog::getSaveFileName (QWidget * parent, const QString & caption,
// before showing the file dialog.
#if defined(FC_OS_LINUX)
QList<QUrl> urls;

#if QT_VERSION >= 0x050000
urls << QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::DesktopLocation));
urls << QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation));
urls << QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::HomeLocation));
urls << QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::MusicLocation));
urls << QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::PicturesLocation));
urls << QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::MoviesLocation));
#else
urls << QUrl::fromLocalFile(QDesktopServices::storageLocation(QDesktopServices::DesktopLocation));
urls << QUrl::fromLocalFile(QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation));
urls << QUrl::fromLocalFile(QDesktopServices::storageLocation(QDesktopServices::HomeLocation));
urls << QUrl::fromLocalFile(QDesktopServices::storageLocation(QDesktopServices::MusicLocation));
urls << QUrl::fromLocalFile(QDesktopServices::storageLocation(QDesktopServices::PicturesLocation));
urls << QUrl::fromLocalFile(QDesktopServices::storageLocation(QDesktopServices::MoviesLocation));
#endif
urls << QUrl::fromLocalFile(getWorkingDirectory());
urls << QUrl::fromLocalFile(restoreLocation());
urls << QUrl::fromLocalFile(QDir::currentPath());
Expand Down Expand Up @@ -232,12 +242,22 @@ QString FileDialog::getOpenFileName(QWidget * parent, const QString & caption, c

#if defined(FC_OS_LINUX)
QList<QUrl> urls;

#if QT_VERSION >= 0x050000
urls << QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::DesktopLocation));
urls << QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation));
urls << QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::HomeLocation));
urls << QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::MusicLocation));
urls << QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::PicturesLocation));
urls << QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::MoviesLocation));
#else
urls << QUrl::fromLocalFile(QDesktopServices::storageLocation(QDesktopServices::DesktopLocation));
urls << QUrl::fromLocalFile(QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation));
urls << QUrl::fromLocalFile(QDesktopServices::storageLocation(QDesktopServices::HomeLocation));
urls << QUrl::fromLocalFile(QDesktopServices::storageLocation(QDesktopServices::MusicLocation));
urls << QUrl::fromLocalFile(QDesktopServices::storageLocation(QDesktopServices::PicturesLocation));
urls << QUrl::fromLocalFile(QDesktopServices::storageLocation(QDesktopServices::MoviesLocation));
#endif
urls << QUrl::fromLocalFile(getWorkingDirectory());
urls << QUrl::fromLocalFile(restoreLocation());
urls << QUrl::fromLocalFile(QDir::currentPath());
Expand Down Expand Up @@ -292,12 +312,22 @@ QStringList FileDialog::getOpenFileNames (QWidget * parent, const QString & capt

#if defined(FC_OS_LINUX)
QList<QUrl> urls;

#if QT_VERSION >= 0x050000
urls << QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::DesktopLocation));
urls << QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation));
urls << QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::HomeLocation));
urls << QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::MusicLocation));
urls << QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::PicturesLocation));
urls << QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::MoviesLocation));
#else
urls << QUrl::fromLocalFile(QDesktopServices::storageLocation(QDesktopServices::DesktopLocation));
urls << QUrl::fromLocalFile(QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation));
urls << QUrl::fromLocalFile(QDesktopServices::storageLocation(QDesktopServices::HomeLocation));
urls << QUrl::fromLocalFile(QDesktopServices::storageLocation(QDesktopServices::MusicLocation));
urls << QUrl::fromLocalFile(QDesktopServices::storageLocation(QDesktopServices::PicturesLocation));
urls << QUrl::fromLocalFile(QDesktopServices::storageLocation(QDesktopServices::MoviesLocation));
#endif
urls << QUrl::fromLocalFile(getWorkingDirectory());
urls << QUrl::fromLocalFile(restoreLocation());
urls << QUrl::fromLocalFile(QDir::currentPath());
Expand Down
2 changes: 2 additions & 0 deletions src/Gui/WidgetFactory.cpp
Expand Up @@ -206,6 +206,8 @@ Py::Object PythonWrapper::fromQIcon(const QIcon* icon)
PyObject* pyobj = Shiboken::createWrapper<QIcon>(icon, true);
if (pyobj)
return Py::asObject(pyobj);
#else
Q_UNUSED(icon);
#endif
throw Py::RuntimeError("Failed to wrap icon");
}
Expand Down
2 changes: 2 additions & 0 deletions src/Main/MainGui.cpp
Expand Up @@ -91,11 +91,13 @@ int main( int argc, char ** argv )
// Make sure to setup the Qt locale system before setting LANG and LC_ALL to C.
// which is needed to use the system locale settings.
(void)QLocale::system();
#if QT_VERSION < 0x050000
// http://www.freecadweb.org/tracker/view.php?id=399
// Because of setting LANG=C the Qt automagic to use the correct encoding
// for file names is broken. This is a workaround to force the use of UTF-8 encoding
QFile::setEncodingFunction(myEncoderFunc);
QFile::setDecodingFunction(myDecoderFunc);
#endif
// Make sure that we use '.' as decimal point. See also
// http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=559846
putenv("LC_NUMERIC=C");
Expand Down

0 comments on commit 87f2866

Please sign in to comment.