Browse Source

refactor(widget): call Settings::getInstance only once in Widget

reviewable/pr5346/r8
Anthony Bilinski 7 years ago
parent
commit
51cf712a78
No known key found for this signature in database
GPG Key ID: 2AA8E0DA1B31FB3C
  1. 136
      src/widget/widget.cpp
  2. 2
      src/widget/widget.h

136
src/widget/widget.cpp

@ -99,9 +99,10 @@ Widget::Widget(QWidget* parent)
, activeChatroomWidget{nullptr} , activeChatroomWidget{nullptr}
, eventFlag(false) , eventFlag(false)
, eventIcon(false) , eventIcon(false)
, settings(Settings::getInstance())
{ {
installEventFilter(this); installEventFilter(this);
QString locale = Settings::getInstance().getTranslation(); QString locale = settings.getTranslation();
Translator::translate(locale); Translator::translate(locale);
} }
@ -201,7 +202,7 @@ void Widget::init()
ui->statusHead->setStyleSheet(Style::getStylesheet("window/statusPanel.css")); ui->statusHead->setStyleSheet(Style::getStylesheet("window/statusPanel.css"));
#endif #endif
contactListWidget = new FriendListWidget(this, Settings::getInstance().getGroupchatPosition()); contactListWidget = new FriendListWidget(this, settings.getGroupchatPosition());
ui->friendList->setWidget(contactListWidget); ui->friendList->setWidget(contactListWidget);
ui->friendList->setLayoutDirection(Qt::RightToLeft); ui->friendList->setLayoutDirection(Qt::RightToLeft);
ui->friendList->setContextMenuPolicy(Qt::CustomContextMenu); ui->friendList->setContextMenuPolicy(Qt::CustomContextMenu);
@ -225,7 +226,7 @@ void Widget::init()
// Disable some widgets until we're connected to the DHT // Disable some widgets until we're connected to the DHT
ui->statusButton->setEnabled(false); ui->statusButton->setEnabled(false);
Style::setThemeColor(Settings::getInstance().getThemeColor()); Style::setThemeColor(settings.getThemeColor());
reloadTheme(); reloadTheme();
updateIcons(); updateIcons();
@ -233,7 +234,7 @@ void Widget::init()
addFriendForm = new AddFriendForm; addFriendForm = new AddFriendForm;
groupInviteForm = new GroupInviteForm; groupInviteForm = new GroupInviteForm;
#if UPDATE_CHECK_ENABLED #if UPDATE_CHECK_ENABLED
updateCheck = std::unique_ptr<UpdateCheck>(new UpdateCheck(Settings::getInstance())); updateCheck = std::unique_ptr<UpdateCheck>(new UpdateCheck(settings));
connect(updateCheck.get(), &UpdateCheck::updateAvailable, this, &Widget::onUpdateAvailable); connect(updateCheck.get(), &UpdateCheck::updateAvailable, this, &Widget::onUpdateAvailable);
#endif #endif
settingsWidget = new SettingsWidget(updateCheck.get(), this); settingsWidget = new SettingsWidget(updateCheck.get(), this);
@ -251,8 +252,6 @@ void Widget::init()
connect(profile, &Profile::selfAvatarChanged, profileForm, &ProfileForm::onSelfAvatarLoaded); connect(profile, &Profile::selfAvatarChanged, profileForm, &ProfileForm::onSelfAvatarLoaded);
const Settings& s = Settings::getInstance();
connect(core, &Core::fileDownloadFinished, filesForm, &FilesForm::onFileDownloadComplete); connect(core, &Core::fileDownloadFinished, filesForm, &FilesForm::onFileDownloadComplete);
connect(core, &Core::fileUploadFinished, filesForm, &FilesForm::onFileUploadComplete); connect(core, &Core::fileUploadFinished, filesForm, &FilesForm::onFileUploadComplete);
connect(ui->addButton, &QPushButton::clicked, this, &Widget::onAddClicked); connect(ui->addButton, &QPushButton::clicked, this, &Widget::onAddClicked);
@ -360,7 +359,7 @@ void Widget::init()
#endif #endif
contentLayout = nullptr; contentLayout = nullptr;
onSeparateWindowChanged(s.getSeparateWindow(), false); onSeparateWindowChanged(settings.getSeparateWindow(), false);
ui->addButton->setCheckable(true); ui->addButton->setCheckable(true);
ui->groupButton->setCheckable(true); ui->groupButton->setCheckable(true);
@ -372,10 +371,10 @@ void Widget::init()
} }
// restore window state // restore window state
restoreGeometry(s.getWindowGeometry()); restoreGeometry(settings.getWindowGeometry());
restoreState(s.getWindowState()); restoreState(settings.getWindowState());
SplitterRestorer restorer(ui->mainSplitter); SplitterRestorer restorer(ui->mainSplitter);
restorer.restore(s.getSplitterState(), size()); restorer.restore(settings.getSplitterState(), size());
friendRequestsButton = nullptr; friendRequestsButton = nullptr;
groupInvitesButton = nullptr; groupInvitesButton = nullptr;
@ -389,17 +388,17 @@ void Widget::init()
&Widget::onGroupInviteAccepted); &Widget::onGroupInviteAccepted);
// settings // settings
connect(&s, &Settings::showSystemTrayChanged, this, &Widget::onSetShowSystemTray); connect(&settings, &Settings::showSystemTrayChanged, this, &Widget::onSetShowSystemTray);
connect(&s, &Settings::separateWindowChanged, this, &Widget::onSeparateWindowClicked); connect(&settings, &Settings::separateWindowChanged, this, &Widget::onSeparateWindowClicked);
connect(&s, &Settings::compactLayoutChanged, contactListWidget, connect(&settings, &Settings::compactLayoutChanged, contactListWidget,
&FriendListWidget::onCompactChanged); &FriendListWidget::onCompactChanged);
connect(&s, &Settings::groupchatPositionChanged, contactListWidget, connect(&settings, &Settings::groupchatPositionChanged, contactListWidget,
&FriendListWidget::onGroupchatPositionChanged); &FriendListWidget::onGroupchatPositionChanged);
retranslateUi(); retranslateUi();
Translator::registerHandler(std::bind(&Widget::retranslateUi, this), this); Translator::registerHandler(std::bind(&Widget::retranslateUi, this), this);
if (!s.getShowSystemTray()) { if (!settings.getShowSystemTray()) {
show(); show();
} }
@ -482,7 +481,7 @@ void Widget::updateIcons()
if (!hasThemeIconBug && QIcon::hasThemeIcon("qtox-" + status)) { if (!hasThemeIconBug && QIcon::hasThemeIcon("qtox-" + status)) {
ico = QIcon::fromTheme("qtox-" + status); ico = QIcon::fromTheme("qtox-" + status);
} else { } else {
QString color = Settings::getInstance().getLightTrayIcon() ? "light" : "dark"; QString color = settings.getLightTrayIcon() ? "light" : "dark";
QString path = ":/img/taskbar/" + color + "/taskbar_" + status + ".svg"; QString path = ":/img/taskbar/" + color + "/taskbar_" + status + ".svg";
QSvgRenderer renderer(path); QSvgRenderer renderer(path);
@ -577,7 +576,7 @@ void Widget::moveEvent(QMoveEvent* event)
void Widget::closeEvent(QCloseEvent* event) void Widget::closeEvent(QCloseEvent* event)
{ {
if (Settings::getInstance().getShowSystemTray() && Settings::getInstance().getCloseToTray()) { if (settings.getShowSystemTray() && settings.getCloseToTray()) {
QWidget::closeEvent(event); QWidget::closeEvent(event);
} else { } else {
if (autoAwayActive) { if (autoAwayActive) {
@ -594,8 +593,8 @@ void Widget::closeEvent(QCloseEvent* event)
void Widget::changeEvent(QEvent* event) void Widget::changeEvent(QEvent* event)
{ {
if (event->type() == QEvent::WindowStateChange) { if (event->type() == QEvent::WindowStateChange) {
if (isMinimized() && Settings::getInstance().getShowSystemTray() if (isMinimized() && settings.getShowSystemTray()
&& Settings::getInstance().getMinimizeToTray()) { && settings.getMinimizeToTray()) {
this->hide(); this->hide();
} }
} }
@ -641,7 +640,7 @@ void Widget::onFailedToStartCore()
void Widget::onBadProxyCore() void Widget::onBadProxyCore()
{ {
Settings::getInstance().setProxyType(Settings::ProxyType::ptNone); settings.setProxyType(Settings::ProxyType::ptNone);
QMessageBox critical(this); QMessageBox critical(this);
critical.setText(tr("toxcore failed to start with your proxy settings. " critical.setText(tr("toxcore failed to start with your proxy settings. "
"qTox cannot run; please modify your " "qTox cannot run; please modify your "
@ -682,7 +681,7 @@ void Widget::onSeparateWindowChanged(bool separate, bool clicked)
setMinimumWidth(775); setMinimumWidth(775);
SplitterRestorer restorer(ui->mainSplitter); SplitterRestorer restorer(ui->mainSplitter);
restorer.restore(Settings::getInstance().getSplitterState(), size()); restorer.restore(settings.getSplitterState(), size());
onShowSettings(); onShowSettings();
} else { } else {
@ -745,7 +744,7 @@ void Widget::forceShow()
void Widget::onAddClicked() void Widget::onAddClicked()
{ {
if (Settings::getInstance().getSeparateWindow()) { if (settings.getSeparateWindow()) {
if (!addFriendForm->isShown()) { if (!addFriendForm->isShown()) {
addFriendForm->show(createContentDialog(DialogType::AddDialog)); addFriendForm->show(createContentDialog(DialogType::AddDialog));
} }
@ -761,7 +760,7 @@ void Widget::onAddClicked()
void Widget::onGroupClicked() void Widget::onGroupClicked()
{ {
if (Settings::getInstance().getSeparateWindow()) { if (settings.getSeparateWindow()) {
if (!groupInviteForm->isShown()) { if (!groupInviteForm->isShown()) {
groupInviteForm->show(createContentDialog(DialogType::GroupDialog)); groupInviteForm->show(createContentDialog(DialogType::GroupDialog));
} }
@ -777,7 +776,7 @@ void Widget::onGroupClicked()
void Widget::onTransferClicked() void Widget::onTransferClicked()
{ {
if (Settings::getInstance().getSeparateWindow()) { if (settings.getSeparateWindow()) {
if (!filesForm->isShown()) { if (!filesForm->isShown()) {
filesForm->show(createContentDialog(DialogType::TransferDialog)); filesForm->show(createContentDialog(DialogType::TransferDialog));
} }
@ -848,7 +847,7 @@ void Widget::onIconClick(QSystemTrayIcon::ActivationReason reason)
void Widget::onShowSettings() void Widget::onShowSettings()
{ {
if (Settings::getInstance().getSeparateWindow()) { if (settings.getSeparateWindow()) {
if (!settingsWidget->isShown()) { if (!settingsWidget->isShown()) {
settingsWidget->show(createContentDialog(DialogType::SettingDialog)); settingsWidget->show(createContentDialog(DialogType::SettingDialog));
} }
@ -864,7 +863,7 @@ void Widget::onShowSettings()
void Widget::showProfile() // onAvatarClicked, onUsernameClicked void Widget::showProfile() // onAvatarClicked, onUsernameClicked
{ {
if (Settings::getInstance().getSeparateWindow()) { if (settings.getSeparateWindow()) {
if (!profileForm->isShown()) { if (!profileForm->isShown()) {
profileForm->show(createContentDialog(DialogType::ProfileDialog)); profileForm->show(createContentDialog(DialogType::ProfileDialog));
} }
@ -975,12 +974,11 @@ void Widget::onRejectCall(uint32_t friendId)
void Widget::addFriend(uint32_t friendId, const ToxPk& friendPk) void Widget::addFriend(uint32_t friendId, const ToxPk& friendPk)
{ {
Settings& s = Settings::getInstance(); settings.updateFriendAddress(friendPk.toString());
s.updateFriendAddress(friendPk.toString());
Friend* newfriend = FriendList::addFriend(friendId, friendPk); Friend* newfriend = FriendList::addFriend(friendId, friendPk);
std::shared_ptr<FriendChatroom> chatroom(new FriendChatroom(newfriend)); std::shared_ptr<FriendChatroom> chatroom(new FriendChatroom(newfriend));
const auto compact = Settings::getInstance().getCompactLayout(); const auto compact = settings.getCompactLayout();
auto widget = new FriendWidget(chatroom, compact); auto widget = new FriendWidget(chatroom, compact);
auto history = Nexus::getProfile()->getHistory(); auto history = Nexus::getProfile()->getHistory();
auto friendForm = new ChatForm(newfriend, history); auto friendForm = new ChatForm(newfriend, history);
@ -989,13 +987,13 @@ void Widget::addFriend(uint32_t friendId, const ToxPk& friendPk)
friendWidgets[friendId] = widget; friendWidgets[friendId] = widget;
chatForms[friendId] = friendForm; chatForms[friendId] = friendForm;
QDate activityDate = s.getFriendActivity(friendPk); QDate activityDate = settings.getFriendActivity(friendPk);
QDate chatDate = friendForm->getLatestDate(); QDate chatDate = friendForm->getLatestDate();
if (chatDate > activityDate && chatDate.isValid()) { if (chatDate > activityDate && chatDate.isValid()) {
s.setFriendActivity(friendPk, chatDate); settings.setFriendActivity(friendPk, chatDate);
} }
contactListWidget->addFriendWidget(widget, Status::Offline, s.getFriendCircleID(friendPk)); contactListWidget->addFriendWidget(widget, Status::Offline, settings.getFriendCircleID(friendPk));
connect(newfriend, &Friend::aliasChanged, this, &Widget::onFriendAliasChanged); connect(newfriend, &Friend::aliasChanged, this, &Widget::onFriendAliasChanged);
connect(newfriend, &Friend::displayedNameChanged, this, &Widget::onFriendDisplayedNameChanged); connect(newfriend, &Friend::displayedNameChanged, this, &Widget::onFriendDisplayedNameChanged);
@ -1118,9 +1116,8 @@ void Widget::onFriendAliasChanged(uint32_t friendId, const QString& alias)
friendWidget->searchName(ui->searchContactText->text(), filter); friendWidget->searchName(ui->searchContactText->text(), filter);
const ToxPk& pk = f->getPublicKey(); const ToxPk& pk = f->getPublicKey();
Settings& s = Settings::getInstance(); settings.setFriendAlias(pk, alias);
s.setFriendAlias(pk, alias); settings.savePersonal();
s.savePersonal();
} }
void Widget::onChatroomWidgetClicked(GenericChatroomWidget* widget) void Widget::onChatroomWidgetClicked(GenericChatroomWidget* widget)
@ -1163,10 +1160,10 @@ void Widget::openDialog(GenericChatroomWidget* widget, bool newWindow)
return; return;
} }
if (Settings::getInstance().getSeparateWindow() || newWindow) { if (settings.getSeparateWindow() || newWindow) {
ContentDialog* dialog = nullptr; ContentDialog* dialog = nullptr;
if (!Settings::getInstance().getDontGroupWindows() && !newWindow) { if (!settings.getDontGroupWindows() && !newWindow) {
dialog = ContentDialogManager::getInstance()->current(); dialog = ContentDialogManager::getInstance()->current();
} }
@ -1233,7 +1230,7 @@ void Widget::addFriendDialog(const Friend* frnd, ContentDialog* dialog)
{ {
uint32_t friendId = frnd->getId(); uint32_t friendId = frnd->getId();
ContentDialog* contentDialog = ContentDialogManager::getInstance()->getFriendDialog(friendId); ContentDialog* contentDialog = ContentDialogManager::getInstance()->getFriendDialog(friendId);
bool isSeparate = Settings::getInstance().getSeparateWindow(); bool isSeparate = settings.getSeparateWindow();
FriendWidget* widget = friendWidgets[friendId]; FriendWidget* widget = friendWidgets[friendId];
bool isCurrent = activeChatroomWidget == widget; bool isCurrent = activeChatroomWidget == widget;
if (!contentDialog && !isSeparate && isCurrent) { if (!contentDialog && !isSeparate && isCurrent) {
@ -1289,7 +1286,7 @@ void Widget::addGroupDialog(Group* group, ContentDialog* dialog)
{ {
int groupId = group->getId(); int groupId = group->getId();
ContentDialog* groupDialog = ContentDialogManager::getInstance()->getGroupDialog(groupId); ContentDialog* groupDialog = ContentDialogManager::getInstance()->getGroupDialog(groupId);
bool separated = Settings::getInstance().getSeparateWindow(); bool separated = settings.getSeparateWindow();
GroupWidget* widget = groupWidgets[groupId]; GroupWidget* widget = groupWidgets[groupId];
bool isCurrentWindow = activeChatroomWidget == widget; bool isCurrentWindow = activeChatroomWidget == widget;
if (!groupDialog && !separated && isCurrentWindow) { if (!groupDialog && !separated && isCurrentWindow) {
@ -1340,8 +1337,8 @@ bool Widget::newFriendMessageAlert(int friendId, bool sound)
currentWindow = contentDialog->window(); currentWindow = contentDialog->window();
hasActive = ContentDialogManager::getInstance()->isFriendWidgetActive(friendId); hasActive = ContentDialogManager::getInstance()->isFriendWidgetActive(friendId);
} else { } else {
if (Settings::getInstance().getSeparateWindow() && Settings::getInstance().getShowWindow()) { if (settings.getSeparateWindow() && settings.getShowWindow()) {
if (Settings::getInstance().getDontGroupWindows()) { if (settings.getDontGroupWindows()) {
contentDialog = createContentDialog(); contentDialog = createContentDialog();
} else { } else {
contentDialog = ContentDialogManager::getInstance()->current(); contentDialog = ContentDialogManager::getInstance()->current();
@ -1442,18 +1439,18 @@ bool Widget::newMessageAlert(QWidget* currentWindow, bool isActive, bool sound,
} }
if (notify) { if (notify) {
if (Settings::getInstance().getShowWindow()) { if (settings.getShowWindow()) {
currentWindow->show(); currentWindow->show();
} }
if (Settings::getInstance().getNotify()) { if (settings.getNotify()) {
if (inactiveWindow) { if (inactiveWindow) {
QApplication::alert(currentWindow); QApplication::alert(currentWindow);
eventFlag = true; eventFlag = true;
} }
bool isBusy = Nexus::getCore()->getStatus() == Status::Busy; bool isBusy = Nexus::getCore()->getStatus() == Status::Busy;
bool busySound = Settings::getInstance().getBusySound(); bool busySound = settings.getBusySound();
bool notifySound = Settings::getInstance().getNotifySound(); bool notifySound = settings.getNotifySound();
if (notifySound && sound && (!isBusy || busySound)) { if (notifySound && sound && (!isBusy || busySound)) {
QString soundPath = Audio::getSound(Audio::Sound::NewMessage); QString soundPath = Audio::getSound(Audio::Sound::NewMessage);
@ -1476,11 +1473,11 @@ void Widget::onFriendRequestReceived(const ToxPk& friendPk, const QString& messa
void Widget::updateFriendActivity(const Friend* frnd) void Widget::updateFriendActivity(const Friend* frnd)
{ {
const ToxPk& pk = frnd->getPublicKey(); const ToxPk& pk = frnd->getPublicKey();
QDate date = Settings::getInstance().getFriendActivity(pk); QDate date = settings.getFriendActivity(pk);
if (date != QDate::currentDate()) { if (date != QDate::currentDate()) {
// Update old activity before after new one. Store old date first. // Update old activity before after new one. Store old date first.
QDate oldDate = Settings::getInstance().getFriendActivity(pk); QDate oldDate = settings.getFriendActivity(pk);
Settings::getInstance().setFriendActivity(pk, QDate::currentDate()); settings.setFriendActivity(pk, QDate::currentDate());
FriendWidget* widget = friendWidgets[frnd->getId()]; FriendWidget* widget = friendWidgets[frnd->getId()];
contactListWidget->moveWidget(widget, frnd->getStatus()); contactListWidget->moveWidget(widget, frnd->getStatus());
contactListWidget->updateActivityDate(oldDate); contactListWidget->updateActivityDate(oldDate);
@ -1600,9 +1597,7 @@ ContentDialog* Widget::createContentDialog() const
connect(contentDialog, &ContentDialog::friendDialogShown, this, &Widget::onFriendDialogShown); connect(contentDialog, &ContentDialog::friendDialogShown, this, &Widget::onFriendDialogShown);
connect(contentDialog, &ContentDialog::groupDialogShown, this, &Widget::onGroupDialogShown); connect(contentDialog, &ContentDialog::groupDialogShown, this, &Widget::onGroupDialogShown);
connect(Core::getInstance(), &Core::usernameSet, contentDialog, &ContentDialog::setUsername); connect(Core::getInstance(), &Core::usernameSet, contentDialog, &ContentDialog::setUsername);
connect(&settings, &Settings::groupchatPositionChanged, contentDialog, &ContentDialog::reorderLayouts);
Settings& s = Settings::getInstance();
connect(&s, &Settings::groupchatPositionChanged, contentDialog, &ContentDialog::reorderLayouts);
#ifdef Q_OS_MAC #ifdef Q_OS_MAC
Nexus& n = Nexus::getInstance(); Nexus& n = Nexus::getInstance();
@ -1620,11 +1615,12 @@ ContentLayout* Widget::createContentDialog(DialogType type) const
class Dialog : public ActivateDialog class Dialog : public ActivateDialog
{ {
public: public:
explicit Dialog(DialogType type) explicit Dialog(DialogType type, Settings& settings)
: ActivateDialog(nullptr, Qt::Window) : ActivateDialog(nullptr, Qt::Window)
, type(type) , type(type)
, settings(settings)
{ {
restoreGeometry(Settings::getInstance().getDialogSettingsGeometry()); restoreGeometry(settings.getDialogSettingsGeometry());
Translator::registerHandler(std::bind(&Dialog::retranslateUi, this), this); Translator::registerHandler(std::bind(&Dialog::retranslateUi, this), this);
retranslateUi(); retranslateUi();
setWindowIcon(QIcon(":/img/icons/qtox.svg")); setWindowIcon(QIcon(":/img/icons/qtox.svg"));
@ -1648,21 +1644,22 @@ ContentLayout* Widget::createContentDialog(DialogType type) const
protected: protected:
void resizeEvent(QResizeEvent* event) override void resizeEvent(QResizeEvent* event) override
{ {
Settings::getInstance().setDialogSettingsGeometry(saveGeometry()); settings.setDialogSettingsGeometry(saveGeometry());
QDialog::resizeEvent(event); QDialog::resizeEvent(event);
} }
void moveEvent(QMoveEvent* event) override void moveEvent(QMoveEvent* event) override
{ {
Settings::getInstance().setDialogSettingsGeometry(saveGeometry()); settings.setDialogSettingsGeometry(saveGeometry());
QDialog::moveEvent(event); QDialog::moveEvent(event);
} }
private: private:
DialogType type; DialogType type;
Settings& settings;
}; };
Dialog* dialog = new Dialog(type); Dialog* dialog = new Dialog(type, settings);
dialog->setAttribute(Qt::WA_DeleteOnClose); dialog->setAttribute(Qt::WA_DeleteOnClose);
ContentLayout* contentLayoutDialog = new ContentLayout(dialog); ContentLayout* contentLayoutDialog = new ContentLayout(dialog);
@ -1704,7 +1701,7 @@ void Widget::onGroupInviteReceived(const GroupInvite& inviteInfo)
const uint8_t confType = inviteInfo.getType(); const uint8_t confType = inviteInfo.getType();
if (confType == TOX_CONFERENCE_TYPE_TEXT || confType == TOX_CONFERENCE_TYPE_AV) { if (confType == TOX_CONFERENCE_TYPE_TEXT || confType == TOX_CONFERENCE_TYPE_AV) {
if (Settings::getInstance().getAutoGroupInvite(f->getPublicKey())) { if (settings.getAutoGroupInvite(f->getPublicKey())) {
onGroupInviteAccepted(inviteInfo); onGroupInviteAccepted(inviteInfo);
} else { } else {
if (!groupInviteForm->addGroupInvite(inviteInfo)) { if (!groupInviteForm->addGroupInvite(inviteInfo)) {
@ -1742,8 +1739,7 @@ void Widget::onGroupMessageReceived(int groupnumber, int peernumber, const QStri
ToxPk author = core->getGroupPeerPk(groupnumber, peernumber); ToxPk author = core->getGroupPeerPk(groupnumber, peernumber);
bool isSelf = author == core->getSelfId().getPublicKey(); bool isSelf = author == core->getSelfId().getPublicKey();
const Settings& s = Settings::getInstance(); if (settings.getBlackList().contains(author.toString())) {
if (s.getBlackList().contains(author.toString())) {
qDebug() << "onGroupMessageReceived: Filtered:" << author.toString(); qDebug() << "onGroupMessageReceived: Filtered:" << author.toString();
return; return;
} }
@ -1760,7 +1756,7 @@ void Widget::onGroupMessageReceived(int groupnumber, int peernumber, const QStri
form->addMessage(author, message, date, isAction, true); form->addMessage(author, message, date, isAction, true);
} }
newGroupMessageAlert(groupId, targeted || Settings::getInstance().getGroupAlwaysNotify()); newGroupMessageAlert(groupId, targeted || settings.getGroupAlwaysNotify());
} }
void Widget::onGroupPeerlistChanged(int groupnumber) void Widget::onGroupPeerlistChanged(int groupnumber)
@ -1882,7 +1878,7 @@ Group* Widget::createGroup(int groupId)
bool enabled = core->getGroupAvEnabled(groupId); bool enabled = core->getGroupAvEnabled(groupId);
Group* newgroup = GroupList::addGroup(groupId, groupName, enabled, core->getUsername()); Group* newgroup = GroupList::addGroup(groupId, groupName, enabled, core->getUsername());
std::shared_ptr<GroupChatroom> chatroom(new GroupChatroom(newgroup)); std::shared_ptr<GroupChatroom> chatroom(new GroupChatroom(newgroup));
const auto compact = Settings::getInstance().getCompactLayout(); const auto compact = settings.getCompactLayout();
auto widget = new GroupWidget(chatroom, compact); auto widget = new GroupWidget(chatroom, compact);
auto form = new GroupChatForm(newgroup); auto form = new GroupChatForm(newgroup);
groupWidgets[groupId] = widget; groupWidgets[groupId] = widget;
@ -1980,7 +1976,7 @@ bool Widget::event(QEvent* e)
void Widget::onUserAwayCheck() void Widget::onUserAwayCheck()
{ {
#ifdef QTOX_PLATFORM_EXT #ifdef QTOX_PLATFORM_EXT
uint32_t autoAwayTime = Settings::getInstance().getAutoAwayTime() * 60 * 1000; uint32_t autoAwayTime = settings.getAutoAwayTime() * 60 * 1000;
bool online = ui->statusButton->property("status").toString() == "online"; bool online = ui->statusButton->property("status").toString() == "online";
bool away = autoAwayTime && Platform::getIdleTime() >= autoAwayTime; bool away = autoAwayTime && Platform::getIdleTime() >= autoAwayTime;
@ -2028,9 +2024,9 @@ void Widget::onTryCreateTrayIcon()
if (icon->backend() != SystrayBackendType::Unity) if (icon->backend() != SystrayBackendType::Unity)
connect(icon, &SystemTrayIcon::activated, this, &Widget::onIconClick); connect(icon, &SystemTrayIcon::activated, this, &Widget::onIconClick);
if (Settings::getInstance().getShowSystemTray()) { if (settings.getShowSystemTray()) {
icon->show(); icon->show();
setHidden(Settings::getInstance().getAutostartInTray()); setHidden(settings.getAutostartInTray());
} else { } else {
show(); show();
} }
@ -2119,14 +2115,14 @@ void Widget::onSetShowSystemTray(bool newValue)
void Widget::saveWindowGeometry() void Widget::saveWindowGeometry()
{ {
Settings::getInstance().setWindowGeometry(saveGeometry()); settings.setWindowGeometry(saveGeometry());
Settings::getInstance().setWindowState(saveState()); settings.setWindowState(saveState());
} }
void Widget::saveSplitterGeometry() void Widget::saveSplitterGeometry()
{ {
if (!Settings::getInstance().getSeparateWindow()) { if (!settings.getSeparateWindow()) {
Settings::getInstance().setSplitterState(ui->mainSplitter->saveState()); settings.setSplitterState(ui->mainSplitter->saveState());
} }
} }
@ -2392,7 +2388,7 @@ void Widget::friendListContextMenu(const QPoint& pos)
void Widget::friendRequestsUpdate() void Widget::friendRequestsUpdate()
{ {
unsigned int unreadFriendRequests = Settings::getInstance().getUnreadFriendRequests(); unsigned int unreadFriendRequests = settings.getUnreadFriendRequests();
if (unreadFriendRequests == 0) { if (unreadFriendRequests == 0) {
delete friendRequestsButton; delete friendRequestsButton;
@ -2474,7 +2470,7 @@ void Widget::retranslateUi()
actionQuit->setText(tr("Exit", "Tray action menu to exit tox")); actionQuit->setText(tr("Exit", "Tray action menu to exit tox"));
actionShow->setText(tr("Show", "Tray action menu to show qTox window")); actionShow->setText(tr("Show", "Tray action menu to show qTox window"));
if (!Settings::getInstance().getSeparateWindow() && (settingsWidget && settingsWidget->isShown())) { if (!settings.getSeparateWindow() && (settingsWidget && settingsWidget->isShown())) {
setWindowTitle(fromDialogType(DialogType::SettingDialog)); setWindowTitle(fromDialogType(DialogType::SettingDialog));
} }

2
src/widget/widget.h

@ -70,6 +70,7 @@ class SettingsWidget;
class SystemTrayIcon; class SystemTrayIcon;
class VideoSurface; class VideoSurface;
class UpdateCheck; class UpdateCheck;
class Settings;
class Widget final : public QMainWindow class Widget final : public QMainWindow
{ {
@ -307,6 +308,7 @@ private:
QPushButton* groupInvitesButton; QPushButton* groupInvitesButton;
unsigned int unreadGroupInvites; unsigned int unreadGroupInvites;
int icon_size; int icon_size;
Settings& settings;
QMap<uint32_t, FriendWidget*> friendWidgets; QMap<uint32_t, FriendWidget*> friendWidgets;
QMap<uint32_t, std::shared_ptr<FriendChatroom>> friendChatrooms; QMap<uint32_t, std::shared_ptr<FriendChatroom>> friendChatrooms;

Loading…
Cancel
Save