Browse Source

refactor(GUI): Remove GUI setWindowTitle

Widget is the only caller, let it set its own title. Wrap inherited setTitle to
prepend "qTox". Check for thread is not needed since it is only called
from Widget's slots.
reviewable/pr6566/r18
Anthony Bilinski 3 years ago
parent
commit
b57e6c6fc4
No known key found for this signature in database
GPG Key ID: 2AA8E0DA1B31FB3C
  1. 27
      src/widget/gui.cpp
  2. 2
      src/widget/gui.h
  3. 19
      src/widget/widget.cpp
  4. 1
      src/widget/widget.h

27
src/widget/gui.cpp

@ -62,22 +62,6 @@ GUI& GUI::getInstance() @@ -62,22 +62,6 @@ GUI& GUI::getInstance()
// Implementation of the public clean interface
/**
* @brief Change the title of the main window.
* @param title Titile to set.
*
* This is usually always visible to the user.
*/
void GUI::setWindowTitle(const QString& title)
{
if (QThread::currentThread() == qApp->thread()) {
getInstance()._setWindowTitle(title);
} else {
QMetaObject::invokeMethod(&getInstance(), "_setWindowTitle", Qt::BlockingQueuedConnection,
Q_ARG(const QString&, title));
}
}
/*
* @brief Show some text to the user.
* @param title Title of information window.
* @param msg Text in information window.
@ -179,17 +163,6 @@ bool GUI::askQuestion(const QString& title, const QString& msg, const QString& b @@ -179,17 +163,6 @@ bool GUI::askQuestion(const QString& title, const QString& msg, const QString& b
// Private implementations
void GUI::_setWindowTitle(const QString& title)
{
QWidget* w = getMainWidget();
if (!w)
return;
if (title.isEmpty())
w->setWindowTitle("qTox");
else
w->setWindowTitle(title + " - qTox");
}
void GUI::_showInfo(const QString& title, const QString& msg)
{
QMessageBox messageBox(QMessageBox::Information, title, msg, QMessageBox::Ok, getMainWidget());

2
src/widget/gui.h

@ -30,7 +30,6 @@ class GUI : public QObject @@ -30,7 +30,6 @@ class GUI : public QObject
public:
static GUI& getInstance();
static QWidget* getMainWidget();
static void setWindowTitle(const QString& title);
static void showInfo(const QString& title, const QString& msg);
static void showWarning(const QString& title, const QString& msg);
static void showError(const QString& title, const QString& msg);
@ -46,7 +45,6 @@ private: @@ -46,7 +45,6 @@ private:
private slots:
// Private implementation, those must be called from the GUI thread
void _setWindowTitle(const QString& title);
void _showInfo(const QString& title, const QString& msg);
void _showWarning(const QString& title, const QString& msg);
void _showError(const QString& title, const QString& msg);

19
src/widget/widget.cpp

@ -1342,7 +1342,7 @@ void Widget::onFriendDisplayedNameChanged(const QString& displayed) @@ -1342,7 +1342,7 @@ void Widget::onFriendDisplayedNameChanged(const QString& displayed)
FriendWidget* friendWidget = friendWidgets[f->getPublicKey()];
if (friendWidget->isActive()) {
GUI::setWindowTitle(displayed);
formatWindowTitle(displayed);
}
chatListWidget->itemsChanged();
@ -2059,7 +2059,7 @@ void Widget::onGroupTitleChanged(uint32_t groupnumber, const QString& author, co @@ -2059,7 +2059,7 @@ void Widget::onGroupTitleChanged(uint32_t groupnumber, const QString& author, co
GroupWidget* widget = groupWidgets[groupId];
if (widget->isActive()) {
GUI::setWindowTitle(title);
formatWindowTitle(title);
}
g->setTitle(author, title);
@ -2751,3 +2751,18 @@ void Widget::connectFriendWidget(FriendWidget& friendWidget) @@ -2751,3 +2751,18 @@ void Widget::connectFriendWidget(FriendWidget& friendWidget)
{
connect(&friendWidget, &FriendWidget::updateFriendActivity, this, &Widget::updateFriendActivity);
}
/**
* @brief Change the title of the main window.
* @param title Title to set.
*
* This is usually always visible to the user.
*/
void Widget::formatWindowTitle(const QString& content)
{
if (content.isEmpty()) {
setWindowTitle("qTox");
} else {
setWindowTitle(content + " - qTox");
}
}

1
src/widget/widget.h

@ -283,6 +283,7 @@ private: @@ -283,6 +283,7 @@ private:
void playNotificationSound(IAudioSink::Sound sound, bool loop = false);
void cleanupNotificationSound();
void acceptFileTransfer(const ToxFile &file, const QString &path);
void formatWindowTitle(const QString& content);
private:
Profile& profile;

Loading…
Cancel
Save