Skip to content

Commit

Permalink
refactor(GUI): Remove GUI setWindowTitle
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
anthonybilinski committed Mar 24, 2022
1 parent 94d0f29 commit b57e6c6
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 31 deletions.
27 changes: 0 additions & 27 deletions src/widget/gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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());
Expand Down
2 changes: 0 additions & 2 deletions src/widget/gui.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -46,7 +45,6 @@ class GUI : public QObject

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);
Expand Down
19 changes: 17 additions & 2 deletions src/widget/widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 change: 1 addition & 0 deletions src/widget/widget.h
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ private slots:
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;
Expand Down

0 comments on commit b57e6c6

Please sign in to comment.