From a554ee0fa891b292c41787bdf6f61c493418c18f Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Tue, 30 Aug 2011 00:53:29 +0200 Subject: [PATCH] * Fixed TWK-451: Properly parent the friends auth / add dialog. --- src/libtomahawk/utils/tomahawkutils.cpp | 158 +++++++++--------- src/libtomahawk/utils/tomahawkutils.h | 1 + .../jabber/googlewrapper/googlewrapper.cpp | 7 +- src/sip/jabber/jabber.cpp | 7 +- 4 files changed, 85 insertions(+), 88 deletions(-) diff --git a/src/libtomahawk/utils/tomahawkutils.cpp b/src/libtomahawk/utils/tomahawkutils.cpp index 14df50094..ea023e6c9 100644 --- a/src/libtomahawk/utils/tomahawkutils.cpp +++ b/src/libtomahawk/utils/tomahawkutils.cpp @@ -537,93 +537,89 @@ setNam( QNetworkAccessManager* nam ) s_nam = QWeakPointer< QNetworkAccessManager >( nam ); } + #ifndef TOMAHAWK_HEADLESS - #if defined(Q_WS_X11) - void - bringToFront() - { - qDebug() << Q_FUNC_INFO; - QWidgetList widgetList = qApp->topLevelWidgets(); - int i = 0; - while( i < widgetList.count() && widgetList.at( i )->objectName() != "TH_Main_Window" ) - i++; - if ( i == widgetList.count() ) - { - qDebug() << Q_FUNC_INFO << " could not find main TH window"; - return; - } - - QWidget *widget = widgetList.at( i ); - widget->show(); - widget->activateWindow(); - widget->raise(); +QWidget* +tomahawkWindow() +{ + QWidgetList widgetList = qApp->topLevelWidgets(); + int i = 0; + while( i < widgetList.count() && widgetList.at( i )->objectName() != "TH_Main_Window" ) + i++; - WId wid = widget->winId(); - - NETWM::init(); - - XEvent e; - - e.xclient.type = ClientMessage; - e.xclient.message_type = NETWM::NET_ACTIVE_WINDOW; - e.xclient.display = QX11Info::display(); - e.xclient.window = wid; - e.xclient.format = 32; - e.xclient.data.l[0] = 2; - e.xclient.data.l[1] = QX11Info::appTime(); - e.xclient.data.l[2] = 0; - e.xclient.data.l[3] = 0l; - e.xclient.data.l[4] = 0l; - - XSendEvent( QX11Info::display(), RootWindow( QX11Info::display(), DefaultScreen( QX11Info::display() ) ), False, SubstructureRedirectMask | SubstructureNotifyMask, &e ); - } - #elif defined(Q_WS_WIN) - void - bringToFront() - { - qDebug() << Q_FUNC_INFO; - QWidgetList widgetList = qApp->topLevelWidgets(); - int i = 0; - while( i < widgetList.count() && widgetList.at( i )->objectName() != "TH_Main_Window" ) - i++; - if ( i == widgetList.count() ) - { - qDebug() << Q_FUNC_INFO << " could not find main TH window"; - return; - } - - QWidget *widget = widgetList.at( i ); - - widget->show(); - widget->activateWindow(); - widget->raise(); - - WId wid = widget->winId(); - - HWND hwndActiveWin = GetForegroundWindow(); - int idActive = GetWindowThreadProcessId(hwndActiveWin, NULL); - if ( AttachThreadInput(GetCurrentThreadId(), idActive, TRUE) ) - { - SetForegroundWindow( wid ); - SetFocus( wid ); - AttachThreadInput(GetCurrentThreadId(), idActive, FALSE); - } - } - #else - #ifndef Q_OS_MAC - void - bringToFront() - { - } - #endif - #endif -#else - void - bringToFront() + if ( i == widgetList.count() ) { + qDebug() << Q_FUNC_INFO << "could not find main Tomahawk mainwindow"; + Q_ASSERT( false ); + return 0; + } + + QWidget *widget = widgetList.at( i ); + return widget; +} + + +void +bringToFront() +{ +#if defined(Q_WS_X11) + { + qDebug() << Q_FUNC_INFO; + + QWidget* widget = tomahawkWindow(); + if ( !widget ) + return; + + widget->show(); + widget->activateWindow(); + widget->raise(); + + WId wid = widget->winId(); + NETWM::init(); + + XEvent e; + e.xclient.type = ClientMessage; + e.xclient.message_type = NETWM::NET_ACTIVE_WINDOW; + e.xclient.display = QX11Info::display(); + e.xclient.window = wid; + e.xclient.format = 32; + e.xclient.data.l[0] = 2; + e.xclient.data.l[1] = QX11Info::appTime(); + e.xclient.data.l[2] = 0; + e.xclient.data.l[3] = 0l; + e.xclient.data.l[4] = 0l; + + XSendEvent( QX11Info::display(), RootWindow( QX11Info::display(), DefaultScreen( QX11Info::display() ) ), False, SubstructureRedirectMask | SubstructureNotifyMask, &e ); + } +#elif defined(Q_WS_WIN) + { + qDebug() << Q_FUNC_INFO; + + QWidget* widget = tomahawkWindow(); + if ( !widget ) + return; + + widget->show(); + widget->activateWindow(); + widget->raise(); + + WId wid = widget->winId(); + + HWND hwndActiveWin = GetForegroundWindow(); + int idActive = GetWindowThreadProcessId(hwndActiveWin, NULL); + if ( AttachThreadInput(GetCurrentThreadId(), idActive, TRUE) ) + { + SetForegroundWindow( wid ); + SetFocus( wid ); + AttachThreadInput(GetCurrentThreadId(), idActive, FALSE); + } } #endif +} + +#endif + QPixmap createAvatarFrame( const QPixmap &avatar ) diff --git a/src/libtomahawk/utils/tomahawkutils.h b/src/libtomahawk/utils/tomahawkutils.h index 3b3d5ea39..2e6c93987 100644 --- a/src/libtomahawk/utils/tomahawkutils.h +++ b/src/libtomahawk/utils/tomahawkutils.h @@ -93,6 +93,7 @@ namespace TomahawkUtils DLLEXPORT void setProxyFactory( TomahawkUtils::NetworkProxyFactory* factory ); DLLEXPORT void setNam( QNetworkAccessManager* nam ); + DLLEXPORT QWidget* tomahawkWindow(); /// Platform-specific bringing tomahawk mainwindow to front, b/c qt's activate() and such don't seem to work well enough for us DLLEXPORT void bringToFront(); diff --git a/src/sip/jabber/googlewrapper/googlewrapper.cpp b/src/sip/jabber/googlewrapper/googlewrapper.cpp index 79911fe24..1e7c107f4 100644 --- a/src/sip/jabber/googlewrapper/googlewrapper.cpp +++ b/src/sip/jabber/googlewrapper/googlewrapper.cpp @@ -20,6 +20,8 @@ #include "googlewrapper.h" #include "ui_configwidget.h" +#include "utils/tomahawkutils.h" + #include #include @@ -69,9 +71,8 @@ void GoogleWrapper::showAddFriendDialog() { bool ok; - QString id = QInputDialog::getText( 0, tr( "Add Friend" ), - tr( "Enter Google Address:" ), QLineEdit::Normal, - "", &ok ); + QString id = QInputDialog::getText( TomahawkUtils::tomahawkWindow(), tr( "Add Friend" ), + tr( "Enter Google Address:" ), QLineEdit::Normal, "", &ok ); if ( !ok ) return; diff --git a/src/sip/jabber/jabber.cpp b/src/sip/jabber/jabber.cpp index 886edb647..d352419b3 100644 --- a/src/sip/jabber/jabber.cpp +++ b/src/sip/jabber/jabber.cpp @@ -455,9 +455,8 @@ void JabberPlugin::showAddFriendDialog() { bool ok; - QString id = QInputDialog::getText( 0, tr( "Add Friend" ), - tr( "Enter Jabber ID:" ), QLineEdit::Normal, - "", &ok ); + QString id = QInputDialog::getText( TomahawkUtils::tomahawkWindow(), tr( "Add Friend" ), + tr( "Enter Jabber ID:" ), QLineEdit::Normal, "", &ok ); if ( !ok ) return; @@ -692,7 +691,7 @@ void JabberPlugin::onSubscriptionReceived(const Jreen::RosterItem::Ptr& item, co tr( "Authorize User" ), QString( tr( "Do you want to grant %1 access to your Collection?" ) ).arg(presence.from().bare()), QMessageBox::Yes | QMessageBox::No, - 0 + TomahawkUtils::tomahawkWindow() ); // add confirmBox to m_subscriptionConfirmBoxes