Commit 4dcb4309 authored by Ronan Abhamon's avatar Ronan Abhamon

feat(app): show correctly windows on mac/GNU Linux/windows

parent 4d4bcf85
...@@ -20,10 +20,18 @@ ...@@ -20,10 +20,18 @@
* Author: Ronan Abhamon * Author: Ronan Abhamon
*/ */
#include "Utils.hpp" #include <QQuickWindow>
#include "Utils.hpp"
// ============================================================================= // =============================================================================
void Utils::smartShowWindow (QQuickWindow *window) {
window->show();
window->raise();
window->requestActivate();
}
char *Utils::rstrstr (const char *a, const char *b) { char *Utils::rstrstr (const char *a, const char *b) {
size_t a_len = strlen(a); size_t a_len = strlen(a);
size_t b_len = strlen(b); size_t b_len = strlen(b);
......
...@@ -28,6 +28,8 @@ ...@@ -28,6 +28,8 @@
// ============================================================================= // =============================================================================
class QQuickWindow;
namespace Utils { namespace Utils {
inline QString linphoneStringToQString (const std::string &string) { inline QString linphoneStringToQString (const std::string &string) {
return QString::fromLocal8Bit(string.c_str(), static_cast<int>(string.size())); return QString::fromLocal8Bit(string.c_str(), static_cast<int>(string.size()));
...@@ -50,6 +52,11 @@ namespace Utils { ...@@ -50,6 +52,11 @@ namespace Utils {
return findParentType<T>(parent); return findParentType<T>(parent);
} }
// Bring a window to front.
// See: http://stackoverflow.com/questions/6087887/bring-window-to-front-raise-show-activatewindow-don-t-work
void smartShowWindow (QQuickWindow *window);
// Reverse function of strstr.
char *rstrstr (const char *a, const char *b); char *rstrstr (const char *a, const char *b);
} }
......
...@@ -163,7 +163,7 @@ void App::initContentApp () { ...@@ -163,7 +163,7 @@ void App::initContentApp () {
QObject::connect( QObject::connect(
this, &App::receivedMessage, this, [this](int, QByteArray message) { this, &App::receivedMessage, this, [this](int, QByteArray message) {
if (message == "show") if (message == "show")
getMainWindow()->showNormal(); Utils::smartShowWindow(getMainWindow());
} }
); );
} }
...@@ -338,7 +338,9 @@ void App::setTrayIcon () { ...@@ -338,7 +338,9 @@ void App::setTrayIcon () {
root->connect(quitAction, &QAction::triggered, this, &App::quit); root->connect(quitAction, &QAction::triggered, this, &App::quit);
QAction *restoreAction = new QAction("Restore", root); QAction *restoreAction = new QAction("Restore", root);
root->connect(restoreAction, &QAction::triggered, root, &QQuickWindow::showNormal); root->connect(restoreAction, &QAction::triggered, root, [root] {
Utils::smartShowWindow(root);
});
// trayIcon: Left click actions. // trayIcon: Left click actions.
QMenu *menu = new QMenu(); QMenu *menu = new QMenu();
...@@ -348,7 +350,7 @@ void App::setTrayIcon () { ...@@ -348,7 +350,7 @@ void App::setTrayIcon () {
) { ) {
if (reason == QSystemTrayIcon::Trigger) { if (reason == QSystemTrayIcon::Trigger) {
if (root->visibility() == QWindow::Hidden) if (root->visibility() == QWindow::Hidden)
root->showNormal(); Utils::smartShowWindow(root);
else else
root->hide(); root->hide();
} }
...@@ -404,9 +406,9 @@ void App::openAppAfterInit () { ...@@ -404,9 +406,9 @@ void App::openAppAfterInit () {
setTrayIcon(); setTrayIcon();
if (!mParser.isSet("iconified")) if (!mParser.isSet("iconified"))
getMainWindow()->showNormal(); Utils::smartShowWindow(getMainWindow());
#else #else
getMainWindow()->showNormal(); Utils::smartShowWindow(getMainWindow());
#endif // ifndef __APPLE__ #endif // ifndef __APPLE__
} }
......
...@@ -148,7 +148,7 @@ void CallModel::accept () { ...@@ -148,7 +148,7 @@ void CallModel::accept () {
params->enableVideo(false); params->enableVideo(false);
setRecordFile(params); setRecordFile(params);
App::getInstance()->getCallsWindow()->show(); Utils::smartShowWindow(App::getInstance()->getCallsWindow());
mLinphoneCall->acceptWithParams(params); mLinphoneCall->acceptWithParams(params);
} }
...@@ -160,7 +160,7 @@ void CallModel::acceptWithVideo () { ...@@ -160,7 +160,7 @@ void CallModel::acceptWithVideo () {
params->enableVideo(true); params->enableVideo(true);
setRecordFile(params); setRecordFile(params);
App::getInstance()->getCallsWindow()->show(); Utils::smartShowWindow(App::getInstance()->getCallsWindow());
mLinphoneCall->acceptWithParams(params); mLinphoneCall->acceptWithParams(params);
} }
......
...@@ -172,7 +172,7 @@ bool CallsListModel::removeRows (int row, int count, const QModelIndex &parent) ...@@ -172,7 +172,7 @@ bool CallsListModel::removeRows (int row, int count, const QModelIndex &parent)
void CallsListModel::addCall (const shared_ptr<linphone::Call> &linphoneCall) { void CallsListModel::addCall (const shared_ptr<linphone::Call> &linphoneCall) {
if (linphoneCall->getDir() == linphone::CallDirOutgoing) if (linphoneCall->getDir() == linphone::CallDirOutgoing)
App::getInstance()->getCallsWindow()->show(); Utils::smartShowWindow(App::getInstance()->getCallsWindow());
CallModel *call = new CallModel(linphoneCall); CallModel *call = new CallModel(linphoneCall);
......
...@@ -205,6 +205,16 @@ function setTimeout (parent, delay, cb) { ...@@ -205,6 +205,16 @@ function setTimeout (parent, delay, cb) {
return timer return timer
} }
// -----------------------------------------------------------------------------
// Bring a window to front.
// See: http://stackoverflow.com/questions/6087887/bring-window-to-front-raise-show-activatewindow-don-t-work
function smartShowWindow (window) {
window.show()
window.raise()
window.requestActivate()
}
// ============================================================================= // =============================================================================
// GENERIC. // GENERIC.
// ============================================================================= // =============================================================================
......
...@@ -28,11 +28,7 @@ function unlockView () { ...@@ -28,11 +28,7 @@ function unlockView () {
function setView (view, props) { function setView (view, props) {
function apply (view, props) { function apply (view, props) {
if (window.visibility === Window.Minimized) { Utils.smartShowWindow(window)
window.visibility = Window.AutomaticVisibility
} else {
window.setVisible(true)
}
var item = mainLoader.item var item = mainLoader.item
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment