From c8b8daf110a3fe728f25c0fdcb2284e2789322d6 Mon Sep 17 00:00:00 2001 From: thunder2 Date: Sat, 19 Oct 2013 23:41:23 +0000 Subject: [PATCH] Code maintenance for Qt 5: - Changed qInstallMsgHandler to qInstallMessageHandler - Changed qt_use_native_dialogs to filedialog_hook (Windows only) Removed unused method Rshare::winEventFilter and signal Rshare::shutdown (Windows only) git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@6852 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- .../src/gui/FileTransfer/ULListDelegate.cpp | 2 +- retroshare-gui/src/gui/MainWindow.cpp | 2 +- retroshare-gui/src/gui/RemoteDirModel.cpp | 1 - .../src/gui/channels/EditChanDetails.cpp | 2 - retroshare-gui/src/main.cpp | 47 +++++++++++++++++++ retroshare-gui/src/rshare.cpp | 33 +++++-------- retroshare-gui/src/rshare.h | 9 ---- 7 files changed, 62 insertions(+), 34 deletions(-) diff --git a/retroshare-gui/src/gui/FileTransfer/ULListDelegate.cpp b/retroshare-gui/src/gui/FileTransfer/ULListDelegate.cpp index e3de93e70..069443994 100644 --- a/retroshare-gui/src/gui/FileTransfer/ULListDelegate.cpp +++ b/retroshare-gui/src/gui/FileTransfer/ULListDelegate.cpp @@ -19,7 +19,7 @@ * Boston, MA 02110-1301, USA. ****************************************************************/ -#include +#include #include "ULListDelegate.h" #include "xprogressbar.h" diff --git a/retroshare-gui/src/gui/MainWindow.cpp b/retroshare-gui/src/gui/MainWindow.cpp index 84a0ed501..8c59c0e24 100644 --- a/retroshare-gui/src/gui/MainWindow.cpp +++ b/retroshare-gui/src/gui/MainWindow.cpp @@ -758,7 +758,7 @@ void SetForegroundWindowInternal(HWND hWnd) _instance->raise(); #ifdef WINDOWS_SYS - SetForegroundWindowInternal(_instance->winId()); + SetForegroundWindowInternal((HWND) _instance->winId()); #endif } diff --git a/retroshare-gui/src/gui/RemoteDirModel.cpp b/retroshare-gui/src/gui/RemoteDirModel.cpp index b12eeb655..0d04b0c0a 100644 --- a/retroshare-gui/src/gui/RemoteDirModel.cpp +++ b/retroshare-gui/src/gui/RemoteDirModel.cpp @@ -24,7 +24,6 @@ #include #include #include -#include #include #include diff --git a/retroshare-gui/src/gui/channels/EditChanDetails.cpp b/retroshare-gui/src/gui/channels/EditChanDetails.cpp index f0cc39d78..d311cccc4 100644 --- a/retroshare-gui/src/gui/channels/EditChanDetails.cpp +++ b/retroshare-gui/src/gui/channels/EditChanDetails.cpp @@ -20,8 +20,6 @@ ****************************************************************/ #include "EditChanDetails.h" -#include - #include #include "util/misc.h" diff --git a/retroshare-gui/src/main.cpp b/retroshare-gui/src/main.cpp index 80213f834..7b8f15f7f 100644 --- a/retroshare-gui/src/main.cpp +++ b/retroshare-gui/src/main.cpp @@ -47,6 +47,12 @@ #include "lang/languagesupport.h" #include "util/RsGxsUpdateBroadcast.h" +#if QT_VERSION >= QT_VERSION_CHECK (5, 0, 0) +#ifdef WINDOWS_SYS +#include +#endif +#endif + /*** WINDOWS DON'T LIKE THIS - REDEFINES VER numbers. #include ****/ @@ -88,13 +94,54 @@ static void displayWarningAboutDSAKeys() msgBox.exec(); } +#if QT_VERSION >= QT_VERSION_CHECK (5, 0, 0) +#ifdef WINDOWS_SYS +QStringList filedialog_open_filenames_hook(QWidget * parent, const QString &caption, const QString &dir, const QString &filter, QString *selectedFilter, QFileDialog::Options options) +{ + return QFileDialog::getOpenFileNames(parent, caption, dir, filter, selectedFilter, options | QFileDialog::DontUseNativeDialog); +} + +QString filedialog_open_filename_hook(QWidget * parent, const QString &caption, const QString &dir, const QString &filter, QString *selectedFilter, QFileDialog::Options options) +{ + return QFileDialog::getOpenFileName(parent, caption, dir, filter, selectedFilter, options | QFileDialog::DontUseNativeDialog); +} + +QString filedialog_save_filename_hook(QWidget * parent, const QString &caption, const QString &dir, const QString &filter, QString *selectedFilter, QFileDialog::Options options) +{ + return QFileDialog::getSaveFileName(parent, caption, dir, filter, selectedFilter, options | QFileDialog::DontUseNativeDialog); +} + +QString filedialog_existing_directory_hook(QWidget *parent, const QString &caption, const QString &dir, QFileDialog::Options options) +{ + return QFileDialog::getExistingDirectory(parent, caption, dir, options | QFileDialog::DontUseNativeDialog); +} +#endif +#endif + int main(int argc, char *argv[]) { #ifdef WINDOWS_SYS // The current directory of the application is changed when using the native dialog on Windows // This is a quick fix until libretroshare is using a absolute path in the portable Version +#if QT_VERSION >= QT_VERSION_CHECK (5, 0, 0) + typedef QStringList (*_qt_filedialog_open_filenames_hook)(QWidget * parent, const QString &caption, const QString &dir, const QString &filter, QString *selectedFilter, QFileDialog::Options options); + typedef QString (*_qt_filedialog_open_filename_hook) (QWidget * parent, const QString &caption, const QString &dir, const QString &filter, QString *selectedFilter, QFileDialog::Options options); + typedef QString (*_qt_filedialog_save_filename_hook) (QWidget * parent, const QString &caption, const QString &dir, const QString &filter, QString *selectedFilter, QFileDialog::Options options); + typedef QString (*_qt_filedialog_existing_directory_hook)(QWidget *parent, const QString &caption, const QString &dir, QFileDialog::Options options); + + extern Q_GUI_EXPORT _qt_filedialog_open_filename_hook qt_filedialog_open_filename_hook; + extern Q_GUI_EXPORT _qt_filedialog_open_filenames_hook qt_filedialog_open_filenames_hook; + extern Q_GUI_EXPORT _qt_filedialog_save_filename_hook qt_filedialog_save_filename_hook; + extern Q_GUI_EXPORT _qt_filedialog_existing_directory_hook qt_filedialog_existing_directory_hook; + + qt_filedialog_open_filename_hook = filedialog_open_filename_hook; + qt_filedialog_open_filenames_hook = filedialog_open_filenames_hook; + qt_filedialog_save_filename_hook = filedialog_save_filename_hook; + qt_filedialog_existing_directory_hook = filedialog_existing_directory_hook; +#else extern bool Q_GUI_EXPORT qt_use_native_dialogs; qt_use_native_dialogs = false; +#endif { /* Set the current directory to the application dir, diff --git a/retroshare-gui/src/rshare.cpp b/retroshare-gui/src/rshare.cpp index 6427d6ef4..fcc3d6b99 100644 --- a/retroshare-gui/src/rshare.cpp +++ b/retroshare-gui/src/rshare.cpp @@ -66,22 +66,24 @@ QDateTime Rshare::mStartupTime; /** Catches debugging messages from Qt and sends them to RetroShare's logs. If Qt * emits a QtFatalMsg, we will write the message to the log and then abort(). */ -void -Rshare::qt_msg_handler(QtMsgType type, const char *s) +#if QT_VERSION >= QT_VERSION_CHECK (5, 0, 0) +void qt_msg_handler(QtMsgType type, const QMessageLogContext &, const QString &msg) +#else +void qt_msg_handler(QtMsgType type, const char *msg) +#endif { - QString msg(s); switch (type) { case QtDebugMsg: - rDebug("QtDebugMsg: %1").arg(msg); + rDebug(QString("QtDebugMsg: %1").arg(msg)); break; case QtWarningMsg: - rNotice("QtWarningMsg: %1").arg(msg); + rNotice(QString("QtWarningMsg: %1").arg(msg)); break; case QtCriticalMsg: - rWarn("QtCriticalMsg: %1").arg(msg); + rWarn(QString("QtCriticalMsg: %1").arg(msg)); break; case QtFatalMsg: - rError("QtFatalMsg: %1").arg(msg); + rError(QString("QtFatalMsg: %1").arg(msg)); break; } if (type == QtFatalMsg) { @@ -98,7 +100,11 @@ Rshare::Rshare(QStringList args, int &argc, char **argv, const QString &dir) { mStartupTime = QDateTime::currentDateTime(); +#if QT_VERSION >= QT_VERSION_CHECK (5, 0, 0) + qInstallMessageHandler(qt_msg_handler); +#else qInstallMsgHandler(qt_msg_handler); +#endif #ifndef __APPLE__ @@ -179,19 +185,6 @@ Rshare::onEventLoopStarted() emit running(); } -#if defined(Q_OS_WIN) -/** On Windows, we need to catch the WM_QUERYENDSESSION message - * so we know that it is time to shutdown. */ -bool -Rshare::winEventFilter(MSG *msg, long *result) -{ - if (msg->message == WM_QUERYENDSESSION) { - emit shutdown(); - } - return QApplication::winEventFilter(msg, result); -} -#endif - /** Display usage information regarding command-line arguments. */ /*void Rshare::printUsage(QString errmsg) diff --git a/retroshare-gui/src/rshare.h b/retroshare-gui/src/rshare.h index bcc956ef9..2d7766cdf 100644 --- a/retroshare-gui/src/rshare.h +++ b/retroshare-gui/src/rshare.h @@ -144,12 +144,6 @@ signals: /** Global timer every second */ void secondTick(); -protected: -#if defined(Q_OS_WIN) - /** Filters Windows events, looking for events of interest */ - bool winEventFilter(MSG *msg, long *result); -#endif - private slots: /** Called when the application's main event loop has started. This method * will emit the running() signal to indicate that the application's event @@ -160,9 +154,6 @@ private slots: private: /** customize the date format (defaultlongformat) */ static void customizeDateFormat(); - /** Catches debugging messages from Qt and sends them to - * RetroShare's logs. */ - static void qt_msg_handler(QtMsgType type, const char *msg); /** Parse the list of command-line arguments. */ void parseArguments(QStringList args);