1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

refactor(status): move Status out of Widget

This commit is contained in:
Anthony Bilinski 2019-04-22 00:54:15 -07:00
parent 51835851b9
commit dd007877a9
No known key found for this signature in database
GPG Key ID: 2AA8E0DA1B31FB3C
26 changed files with 262 additions and 176 deletions

View File

@ -323,6 +323,8 @@ set(${PROJECT_NAME}_SOURCES
src/model/groupinvite.h src/model/groupinvite.h
src/model/group.cpp src/model/group.cpp
src/model/group.h src/model/group.h
src/model/status.cpp
src/model/status.h
src/model/interface.h src/model/interface.h
src/model/profile/iprofileinfo.h src/model/profile/iprofileinfo.h
src/model/profile/profileinfo.cpp src/model/profile/profileinfo.cpp

View File

@ -27,6 +27,7 @@
#include "src/core/toxoptions.h" #include "src/core/toxoptions.h"
#include "src/core/toxstring.h" #include "src/core/toxstring.h"
#include "src/model/groupinvite.h" #include "src/model/groupinvite.h"
#include "src/model/status.h"
#include "src/nexus.h" #include "src/nexus.h"
#include "src/net/bootstrapnodeupdater.h" #include "src/net/bootstrapnodeupdater.h"
#include "src/persistence/profile.h" #include "src/persistence/profile.h"
@ -506,18 +507,18 @@ void Core::onStatusMessageChanged(Tox*, uint32_t friendId, const uint8_t* cMessa
void Core::onUserStatusChanged(Tox*, uint32_t friendId, Tox_User_Status userstatus, void* core) void Core::onUserStatusChanged(Tox*, uint32_t friendId, Tox_User_Status userstatus, void* core)
{ {
Status status; Status::Status status;
switch (userstatus) { switch (userstatus) {
case TOX_USER_STATUS_AWAY: case TOX_USER_STATUS_AWAY:
status = Status::Away; status = Status::Status::Away;
break; break;
case TOX_USER_STATUS_BUSY: case TOX_USER_STATUS_BUSY:
status = Status::Busy; status = Status::Status::Busy;
break; break;
default: default:
status = Status::Online; status = Status::Status::Online;
break; break;
} }
@ -527,9 +528,9 @@ void Core::onUserStatusChanged(Tox*, uint32_t friendId, Tox_User_Status userstat
void Core::onConnectionStatusChanged(Tox*, uint32_t friendId, Tox_Connection status, void* vCore) void Core::onConnectionStatusChanged(Tox*, uint32_t friendId, Tox_Connection status, void* vCore)
{ {
Core* core = static_cast<Core*>(vCore); Core* core = static_cast<Core*>(vCore);
Status friendStatus = status != TOX_CONNECTION_NONE ? Status::Online : Status::Offline; Status::Status friendStatus = status != TOX_CONNECTION_NONE ? Status::Status::Online : Status::Status::Offline;
// Ignore Online because it will be emited from onUserStatusChanged // Ignore Online because it will be emited from onUserStatusChanged
bool isOffline = friendStatus == Status::Offline; bool isOffline = friendStatus == Status::Status::Offline;
if (isOffline) { if (isOffline) {
emit core->friendStatusChanged(friendId, friendStatus); emit core->friendStatusChanged(friendId, friendStatus);
core->checkLastOnline(friendId); core->checkLastOnline(friendId);
@ -908,11 +909,11 @@ QString Core::getStatusMessage() const
/** /**
* @brief Returns our user status * @brief Returns our user status
*/ */
Status Core::getStatus() const Status::Status Core::getStatus() const
{ {
QMutexLocker ml{&coreLoopLock}; QMutexLocker ml{&coreLoopLock};
return static_cast<Status>(tox_self_get_status(tox.get())); return static_cast<Status::Status>(tox_self_get_status(tox.get()));
} }
void Core::setStatusMessage(const QString& message) void Core::setStatusMessage(const QString& message)
@ -933,21 +934,21 @@ void Core::setStatusMessage(const QString& message)
emit statusMessageSet(message); emit statusMessageSet(message);
} }
void Core::setStatus(Status status) void Core::setStatus(Status::Status status)
{ {
QMutexLocker ml{&coreLoopLock}; QMutexLocker ml{&coreLoopLock};
Tox_User_Status userstatus; Tox_User_Status userstatus;
switch (status) { switch (status) {
case Status::Online: case Status::Status::Online:
userstatus = TOX_USER_STATUS_NONE; userstatus = TOX_USER_STATUS_NONE;
break; break;
case Status::Away: case Status::Status::Away:
userstatus = TOX_USER_STATUS_AWAY; userstatus = TOX_USER_STATUS_AWAY;
break; break;
case Status::Busy: case Status::Status::Busy:
userstatus = TOX_USER_STATUS_BUSY; userstatus = TOX_USER_STATUS_BUSY;
break; break;

View File

@ -27,6 +27,7 @@
#include "groupid.h" #include "groupid.h"
#include "src/util/strongtype.h" #include "src/util/strongtype.h"
#include "src/model/status.h"
#include <tox/tox.h> #include <tox/tox.h>
#include <QMutex> #include <QMutex>
@ -42,16 +43,6 @@ class CoreFile;
class ICoreSettings; class ICoreSettings;
class GroupInvite; class GroupInvite;
class Profile; class Profile;
enum class Status
{
Online = 0,
Away,
Busy,
Offline,
Blocked
};
class Core; class Core;
using ToxCorePtr = std::unique_ptr<Core>; using ToxCorePtr = std::unique_ptr<Core>;
@ -97,7 +88,7 @@ public:
void quitGroupChat(int groupId) const; void quitGroupChat(int groupId) const;
QString getUsername() const; QString getUsername() const;
Status getStatus() const; Status::Status getStatus() const;
QString getStatusMessage() const; QString getStatusMessage() const;
ToxId getSelfId() const; ToxId getSelfId() const;
ToxPk getSelfPublicKey() const; ToxPk getSelfPublicKey() const;
@ -118,7 +109,7 @@ public slots:
void removeFriend(uint32_t friendId); void removeFriend(uint32_t friendId);
void removeGroup(int groupId); void removeGroup(int groupId);
void setStatus(Status status); void setStatus(Status::Status status);
void setUsername(const QString& username); void setUsername(const QString& username);
void setStatusMessage(const QString& message); void setStatusMessage(const QString& message);
@ -144,12 +135,12 @@ signals:
void usernameSet(const QString& username); void usernameSet(const QString& username);
void statusMessageSet(const QString& message); void statusMessageSet(const QString& message);
void statusSet(Status status); void statusSet(Status::Status status);
void idSet(const ToxId& id); void idSet(const ToxId& id);
void failedToSetUsername(const QString& username); void failedToSetUsername(const QString& username);
void failedToSetStatusMessage(const QString& message); void failedToSetStatusMessage(const QString& message);
void failedToSetStatus(Status status); void failedToSetStatus(Status::Status status);
void failedToSetTyping(bool typing); void failedToSetTyping(bool typing);
void avReady(); void avReady();
@ -165,7 +156,7 @@ signals:
void friendMessageReceived(uint32_t friendId, const QString& message, bool isAction); void friendMessageReceived(uint32_t friendId, const QString& message, bool isAction);
void friendAdded(uint32_t friendId, const ToxPk& friendPk); void friendAdded(uint32_t friendId, const ToxPk& friendPk);
void friendStatusChanged(uint32_t friendId, Status status); void friendStatusChanged(uint32_t friendId, Status::Status status);
void friendStatusMessageChanged(uint32_t friendId, const QString& message); void friendStatusMessageChanged(uint32_t friendId, const QString& message);
void friendUsernameChanged(uint32_t friendId, const QString& username); void friendUsernameChanged(uint32_t friendId, const QString& username);
void friendTypingChanged(uint32_t friendId, bool isTyping); void friendTypingChanged(uint32_t friendId, bool isTyping);

View File

@ -23,6 +23,7 @@
#include "toxfile.h" #include "toxfile.h"
#include "toxstring.h" #include "toxstring.h"
#include "src/persistence/settings.h" #include "src/persistence/settings.h"
#include "src/model/status.h"
#include <QDebug> #include <QDebug>
#include <QDir> #include <QDir>
#include <QFile> #include <QFile>
@ -528,9 +529,9 @@ void CoreFile::onFileRecvChunkCallback(Tox* tox, uint32_t friendId, uint32_t fil
} }
} }
void CoreFile::onConnectionStatusChanged(uint32_t friendId, Status state) void CoreFile::onConnectionStatusChanged(uint32_t friendId, Status::Status state)
{ {
bool isOffline = state == Status::Offline; bool isOffline = state == Status::Status::Offline;
// TODO: Actually resume broken file transfers // TODO: Actually resume broken file transfers
// We need to: // We need to:
// - Start a new file transfer with the same 32byte file ID with toxcore // - Start a new file transfer with the same 32byte file ID with toxcore

View File

@ -21,20 +21,22 @@
#ifndef COREFILE_H #ifndef COREFILE_H
#define COREFILE_H #define COREFILE_H
#include <cstddef>
#include <cstdint>
#include <memory>
#include <tox/tox.h> #include <tox/tox.h>
#include "toxfile.h" #include "toxfile.h"
#include "src/core/core.h" #include "src/core/core.h"
#include "src/core/toxpk.h" #include "src/core/toxpk.h"
#include "src/model/status.h"
#include <QHash> #include <QHash>
#include <QMutex> #include <QMutex>
#include <QObject> #include <QObject>
#include <QString> #include <QString>
#include <cstddef>
#include <cstdint>
#include <memory>
struct Tox; struct Tox;
class CoreFile; class CoreFile;
@ -100,7 +102,7 @@ private:
static QString getCleanFileName(QString filename); static QString getCleanFileName(QString filename);
private slots: private slots:
void onConnectionStatusChanged(uint32_t friendId, Status state); void onConnectionStatusChanged(uint32_t friendId, Status::Status state);
private: private:
QHash<uint64_t, ToxFile> fileMap; QHash<uint64_t, ToxFile> fileMap;

View File

@ -20,6 +20,7 @@
#include "friend.h" #include "friend.h"
#include "src/model/group.h" #include "src/model/group.h"
#include "src/model/status.h"
#include "src/grouplist.h" #include "src/grouplist.h"
#include "src/persistence/profile.h" #include "src/persistence/profile.h"
#include "src/widget/form/chatform.h" #include "src/widget/form/chatform.h"
@ -30,7 +31,7 @@ Friend::Friend(uint32_t friendId, const ToxPk& friendPk, const QString& userAlia
, friendPk{friendPk} , friendPk{friendPk}
, friendId{friendId} , friendId{friendId}
, hasNewEvents{false} , hasNewEvents{false}
, friendStatus{Status::Offline} , friendStatus{Status::Status::Offline}
{ {
if (userName.isEmpty()) { if (userName.isEmpty()) {
this->userName = friendPk.toString(); this->userName = friendPk.toString();
@ -152,7 +153,7 @@ bool Friend::getEventFlag() const
return hasNewEvents; return hasNewEvents;
} }
void Friend::setStatus(Status s) void Friend::setStatus(Status::Status s)
{ {
if (friendStatus != s) { if (friendStatus != s) {
friendStatus = s; friendStatus = s;
@ -160,12 +161,12 @@ void Friend::setStatus(Status s)
} }
} }
Status Friend::getStatus() const Status::Status Friend::getStatus() const
{ {
return friendStatus; return friendStatus;
} }
bool Friend::isOnline() const bool Friend::isOnline() const
{ {
return friendStatus != Status::Offline && friendStatus != Status::Blocked; return friendStatus != Status::Status::Offline && friendStatus != Status::Status::Blocked;
} }

View File

@ -24,6 +24,7 @@
#include "src/core/core.h" #include "src/core/core.h"
#include "src/core/toxid.h" #include "src/core/toxid.h"
#include "src/core/contactid.h" #include "src/core/contactid.h"
#include "src/model/status.h"
#include <QObject> #include <QObject>
#include <QString> #include <QString>
@ -50,14 +51,14 @@ public:
uint32_t getId() const override; uint32_t getId() const override;
const ContactId& getPersistentId() const override; const ContactId& getPersistentId() const override;
void setStatus(Status s); void setStatus(Status::Status s);
Status getStatus() const; Status::Status getStatus() const;
bool isOnline() const; bool isOnline() const;
signals: signals:
void nameChanged(const ToxPk& friendId, const QString& name); void nameChanged(const ToxPk& friendId, const QString& name);
void aliasChanged(const ToxPk& friendId, QString alias); void aliasChanged(const ToxPk& friendId, QString alias);
void statusChanged(const ToxPk& friendId, Status status); void statusChanged(const ToxPk& friendId, Status::Status status);
void statusMessageChanged(const ToxPk& friendId, const QString& message); void statusMessageChanged(const ToxPk& friendId, const QString& message);
void loadChatHistory(); void loadChatHistory();
@ -70,7 +71,7 @@ private:
ToxPk friendPk; ToxPk friendPk;
uint32_t friendId; uint32_t friendId;
bool hasNewEvents; bool hasNewEvents;
Status friendStatus; Status::Status friendStatus;
}; };
#endif // FRIEND_H #endif // FRIEND_H

95
src/model/status.cpp Normal file
View File

@ -0,0 +1,95 @@
/*
Copyright © 2019 by The qTox Project Contributors
This file is part of qTox, a Qt-based graphical interface for Tox.
qTox is libre software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
qTox is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with qTox. If not, see <http://www.gnu.org/licenses/>.
*/
#include <src/model/status.h>
#include <QString>
#include <QPixmap>
#include <QDebug>
#include <QObject>
#include <cassert>
namespace Status
{
QPixmap getIconPixmap(QString path, uint32_t w, uint32_t h)
{
QPixmap pix(w, h);
pix.load(path);
return pix;
}
QString getTitle(Status status)
{
switch (status) {
case Status::Online:
return QObject::tr("online", "contact status");
case Status::Away:
return QObject::tr("away", "contact status");
case Status::Busy:
return QObject::tr("busy", "contact status");
case Status::Offline:
return QObject::tr("offline", "contact status");
case Status::Blocked:
return QObject::tr("blocked", "contact status");
}
assert(false);
return QStringLiteral("");
}
Status getFromString(QString status)
{
if (status == QStringLiteral("online"))
return Status::Online;
else if (status == QStringLiteral("away"))
return Status::Away;
else if (status == QStringLiteral("busy"))
return Status::Busy;
else if (status == QStringLiteral("offline"))
return Status::Offline;
else if (status == QStringLiteral("blocked"))
return Status::Blocked;
else {
assert(false);
return Status::Offline;
}
}
QString getIconPath(Status status, bool event)
{
const QString eventSuffix = event ? QStringLiteral("_notification") : QString();
switch (status) {
case Status::Online:
return ":/img/status/online" + eventSuffix + ".svg";
case Status::Away:
return ":/img/status/away" + eventSuffix + ".svg";
case Status::Busy:
return ":/img/status/busy" + eventSuffix + ".svg";
case Status::Offline:
return ":/img/status/offline" + eventSuffix + ".svg";
case Status::Blocked:
return ":/img/status/blocked.svg";
}
qWarning() << "Status unknown";
assert(false);
return QString{};
}
} // namespace Status

44
src/model/status.h Normal file
View File

@ -0,0 +1,44 @@
/*
Copyright © 2019 by The qTox Project Contributors
This file is part of qTox, a Qt-based graphical interface for Tox.
qTox is libre software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
qTox is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with qTox. If not, see <http://www.gnu.org/licenses/>.
*/
#include <QString>
#include <QPixmap>
#ifndef STATUS_H
#define STATUS_H
namespace Status
{
// Status::Status is weird, but Status is a fitting name for both the namespace and enum class..
enum class Status
{
Online = 0,
Away,
Busy,
Offline,
Blocked
};
QString getIconPath(Status status, bool event = false);
QPixmap getIconPixmap(QString path, uint32_t w, uint32_t h);
QString getTitle(Status status);
Status getFromString(QString status);
}
#endif // STATUS_H

View File

@ -21,6 +21,7 @@
#include "avatarbroadcaster.h" #include "avatarbroadcaster.h"
#include "src/core/core.h" #include "src/core/core.h"
#include "src/core/corefile.h" #include "src/core/corefile.h"
#include "src/model/status.h"
#include <QDebug> #include <QDebug>
#include <QObject> #include <QObject>
@ -36,7 +37,7 @@ QByteArray AvatarBroadcaster::avatarData;
QMap<uint32_t, bool> AvatarBroadcaster::friendsSentTo; QMap<uint32_t, bool> AvatarBroadcaster::friendsSentTo;
static QMetaObject::Connection autoBroadcastConn; static QMetaObject::Connection autoBroadcastConn;
static auto autoBroadcast = [](uint32_t friendId, Status) { static auto autoBroadcast = [](uint32_t friendId, Status::Status) {
AvatarBroadcaster::sendAvatarTo(friendId); AvatarBroadcaster::sendAvatarTo(friendId);
}; };

View File

@ -23,6 +23,7 @@
#include "src/core/core.h" #include "src/core/core.h"
#include "src/core/coreav.h" #include "src/core/coreav.h"
#include "src/model/groupinvite.h" #include "src/model/groupinvite.h"
#include "src/model/status.h"
#include "src/persistence/profile.h" #include "src/persistence/profile.h"
#include "src/widget/widget.h" #include "src/widget/widget.h"
#include "video/camerasource.h" #include "video/camerasource.h"
@ -83,7 +84,7 @@ void Nexus::start()
qDebug() << "Starting up"; qDebug() << "Starting up";
// Setup the environment // Setup the environment
qRegisterMetaType<Status>("Status"); qRegisterMetaType<Status::Status>("Status::Status");
qRegisterMetaType<vpx_image>("vpx_image"); qRegisterMetaType<vpx_image>("vpx_image");
qRegisterMetaType<uint8_t>("uint8_t"); qRegisterMetaType<uint8_t>("uint8_t");
qRegisterMetaType<uint16_t>("uint16_t"); qRegisterMetaType<uint16_t>("uint16_t");

View File

@ -21,6 +21,7 @@
#include "friendlistlayout.h" #include "friendlistlayout.h"
#include "friendlistwidget.h" #include "friendlistwidget.h"
#include "friendwidget.h" #include "friendwidget.h"
#include "src/model/status.h"
#include "src/widget/style.h" #include "src/widget/style.h"
#include "tool/croppinglabel.h" #include "tool/croppinglabel.h"
#include <QBoxLayout> #include <QBoxLayout>
@ -126,7 +127,7 @@ void CategoryWidget::editName()
nameLabel->setMaximumWidth(QWIDGETSIZE_MAX); nameLabel->setMaximumWidth(QWIDGETSIZE_MAX);
} }
void CategoryWidget::addFriendWidget(FriendWidget* w, Status s) void CategoryWidget::addFriendWidget(FriendWidget* w, Status::Status s)
{ {
listLayout->addFriendWidget(w, s); listLayout->addFriendWidget(w, s);
updateStatus(); updateStatus();
@ -134,7 +135,7 @@ void CategoryWidget::addFriendWidget(FriendWidget* w, Status s)
w->reloadTheme(); // Otherwise theme will change when moving to another circle. w->reloadTheme(); // Otherwise theme will change when moving to another circle.
} }
void CategoryWidget::removeFriendWidget(FriendWidget* w, Status s) void CategoryWidget::removeFriendWidget(FriendWidget* w, Status::Status s)
{ {
listLayout->removeFriendWidget(w, s); listLayout->removeFriendWidget(w, s);
updateStatus(); updateStatus();

View File

@ -22,6 +22,7 @@
#include "genericchatitemwidget.h" #include "genericchatitemwidget.h"
#include "src/core/core.h" #include "src/core/core.h"
#include "src/model/status.h"
class FriendListLayout; class FriendListLayout;
class FriendListWidget; class FriendListWidget;
@ -39,8 +40,8 @@ public:
void setExpanded(bool isExpanded, bool save = true); void setExpanded(bool isExpanded, bool save = true);
void setName(const QString& name, bool save = true); void setName(const QString& name, bool save = true);
void addFriendWidget(FriendWidget* w, Status s); void addFriendWidget(FriendWidget* w, Status::Status s);
void removeFriendWidget(FriendWidget* w, Status s); void removeFriendWidget(FriendWidget* w, Status::Status s);
void updateStatus(); void updateStatus();
bool hasChatrooms() const; bool hasChatrooms() const;

View File

@ -34,6 +34,7 @@
#include "src/model/chatroom/friendchatroom.h" #include "src/model/chatroom/friendchatroom.h"
#include "src/model/friend.h" #include "src/model/friend.h"
#include "src/model/group.h" #include "src/model/group.h"
#include "src/model/status.h"
#include "src/persistence/settings.h" #include "src/persistence/settings.h"
#include "src/widget/contentlayout.h" #include "src/widget/contentlayout.h"
#include "src/widget/friendwidget.h" #include "src/widget/friendwidget.h"
@ -196,8 +197,8 @@ void ContentDialog::removeFriend(const ToxPk& friendPk)
cycleContacts(/* forward = */ true, /* inverse = */ false); cycleContacts(/* forward = */ true, /* inverse = */ false);
} }
friendLayout->removeFriendWidget(chatroomWidget, Status::Offline); friendLayout->removeFriendWidget(chatroomWidget, Status::Status::Offline);
friendLayout->removeFriendWidget(chatroomWidget, Status::Online); friendLayout->removeFriendWidget(chatroomWidget, Status::Status::Online);
chatroomWidget->deleteLater(); chatroomWidget->deleteLater();
@ -385,8 +386,8 @@ void ContentDialog::updateTitleAndStatusIcon()
return; return;
} }
Status currentStatus = activeChatroomWidget->getFriend()->getStatus(); Status::Status currentStatus = activeChatroomWidget->getFriend()->getStatus();
setWindowIcon(QIcon{Widget::getStatusIconPath(currentStatus)}); setWindowIcon(QIcon{Status::getIconPath(currentStatus)});
} }
/** /**
@ -590,7 +591,7 @@ bool ContentDialog::containsContact(const ContactId& contactId) const
return contactWidgets.contains(contactId); return contactWidgets.contains(contactId);
} }
void ContentDialog::updateFriendStatus(const ToxPk& friendPk, Status status) void ContentDialog::updateFriendStatus(const ToxPk& friendPk, Status::Status status)
{ {
auto widget = qobject_cast<FriendWidget*>(contactWidgets.value(friendPk)); auto widget = qobject_cast<FriendWidget*>(contactWidgets.value(friendPk));
addFriendWidget(widget, status); addFriendWidget(widget, status);
@ -633,7 +634,7 @@ void ContentDialog::updateFriendWidget(const ToxPk& friendPk, QString alias)
Friend* f = FriendList::findFriend(friendPk); Friend* f = FriendList::findFriend(friendPk);
FriendWidget* friendWidget = qobject_cast<FriendWidget*>(contactWidgets[friendPk]); FriendWidget* friendWidget = qobject_cast<FriendWidget*>(contactWidgets[friendPk]);
Status status = f->getStatus(); Status::Status status = f->getStatus();
friendLayout->addFriendWidget(friendWidget, status); friendLayout->addFriendWidget(friendWidget, status);
} }
@ -698,7 +699,7 @@ QLayout* ContentDialog::nextLayout(QLayout* layout, bool forward) const
return layouts[next]; return layouts[next];
} }
void ContentDialog::addFriendWidget(FriendWidget* widget, Status status) void ContentDialog::addFriendWidget(FriendWidget* widget, Status::Status status)
{ {
friendLayout->addFriendWidget(widget, status); friendLayout->addFriendWidget(widget, status);
} }

View File

@ -22,7 +22,9 @@
#include "src/widget/genericchatitemlayout.h" #include "src/widget/genericchatitemlayout.h"
#include "src/widget/tool/activatedialog.h" #include "src/widget/tool/activatedialog.h"
#include "src/core/core.h" // Status #include "src/model/status.h"
#include "src/core/groupid.h"
#include "src/core/toxpk.h"
#include <memory> #include <memory>
#include <tuple> #include <tuple>
@ -68,13 +70,13 @@ public:
void onVideoShow(QSize size); void onVideoShow(QSize size);
void onVideoHide(); void onVideoHide();
void addFriendWidget(FriendWidget* widget, Status status); void addFriendWidget(FriendWidget* widget, Status::Status status);
bool isActiveWidget(GenericChatroomWidget* widget); bool isActiveWidget(GenericChatroomWidget* widget);
bool hasContactWidget(const ContactId& contactId) const; bool hasContactWidget(const ContactId& contactId) const;
void focusContact(const ContactId& friendPk); void focusContact(const ContactId& friendPk);
bool containsContact(const ContactId& friendPk) const; bool containsContact(const ContactId& friendPk) const;
void updateFriendStatus(const ToxPk& friendPk, Status status); void updateFriendStatus(const ToxPk& friendPk, Status::Status status);
void updateContactStatusLight(const ContactId& contactId); void updateContactStatusLight(const ContactId& contactId);
bool isContactWidgetActive(const ContactId& contactId); bool isContactWidgetActive(const ContactId& contactId);

View File

@ -27,6 +27,7 @@
#include "src/core/coreav.h" #include "src/core/coreav.h"
#include "src/core/corefile.h" #include "src/core/corefile.h"
#include "src/model/friend.h" #include "src/model/friend.h"
#include "src/model/status.h"
#include "src/nexus.h" #include "src/nexus.h"
#include "src/persistence/history.h" #include "src/persistence/history.h"
#include "src/persistence/offlinemsgengine.h" #include "src/persistence/offlinemsgengine.h"
@ -40,10 +41,12 @@
#include "src/widget/style.h" #include "src/widget/style.h"
#include "src/widget/tool/callconfirmwidget.h" #include "src/widget/tool/callconfirmwidget.h"
#include "src/widget/tool/chattextedit.h" #include "src/widget/tool/chattextedit.h"
#include "src/widget/tool/croppinglabel.h"
#include "src/widget/tool/screenshotgrabber.h" #include "src/widget/tool/screenshotgrabber.h"
#include "src/widget/translator.h" #include "src/widget/translator.h"
#include "src/widget/widget.h" #include "src/widget/widget.h"
#include <QApplication>
#include <QClipboard> #include <QClipboard>
#include <QFileDialog> #include <QFileDialog>
#include <QFileInfo> #include <QFileInfo>
@ -51,6 +54,7 @@
#include <QMimeData> #include <QMimeData>
#include <QPushButton> #include <QPushButton>
#include <QScrollBar> #include <QScrollBar>
#include <QSplitter>
#include <QStringBuilder> #include <QStringBuilder>
#include <cassert> #include <cassert>
@ -612,7 +616,7 @@ void ChatForm::onFileSendFailed(uint32_t friendId, const QString& fname)
QDateTime::currentDateTime()); QDateTime::currentDateTime());
} }
void ChatForm::onFriendStatusChanged(uint32_t friendId, Status status) void ChatForm::onFriendStatusChanged(uint32_t friendId, Status::Status status)
{ {
// Disable call buttons if friend is offline // Disable call buttons if friend is offline
if (friendId != f->getId()) { if (friendId != f->getId()) {
@ -629,7 +633,7 @@ void ChatForm::onFriendStatusChanged(uint32_t friendId, Status status)
updateCallButtons(); updateCallButtons();
if (Settings::getInstance().getStatusChangeNotificationEnabled()) { if (Settings::getInstance().getStatusChangeNotificationEnabled()) {
QString fStatus = Widget::getStatusTitle(status); QString fStatus = Status::getTitle(status);
addSystemInfoMessage(tr("%1 is now %2", "e.g. \"Dubslow is now online\"") addSystemInfoMessage(tr("%1 is now %2", "e.g. \"Dubslow is now online\"")
.arg(f->getDisplayedName()) .arg(f->getDisplayedName())
.arg(fStatus), .arg(fStatus),

View File

@ -28,6 +28,7 @@
#include "genericchatform.h" #include "genericchatform.h"
#include "src/core/core.h" #include "src/core/core.h"
#include "src/persistence/history.h" #include "src/persistence/history.h"
#include "src/model/status.h"
#include "src/widget/tool/screenshotgrabber.h" #include "src/widget/tool/screenshotgrabber.h"
class CallConfirmWidget; class CallConfirmWidget;
@ -99,7 +100,7 @@ private slots:
void onVolMuteToggle(); void onVolMuteToggle();
void onFileSendFailed(uint32_t friendId, const QString& fname); void onFileSendFailed(uint32_t friendId, const QString& fname);
void onFriendStatusChanged(quint32 friendId, Status status); void onFriendStatusChanged(quint32 friendId, Status::Status status);
void onFriendTypingChanged(quint32 friendId, bool isTyping); void onFriendTypingChanged(quint32 friendId, bool isTyping);
void onFriendNameChanged(const QString& name); void onFriendNameChanged(const QString& name);
void onFriendMessageReceived(quint32 friendId, const QString& message, bool isAction); void onFriendMessageReceived(quint32 friendId, const QString& message, bool isAction);

View File

@ -30,6 +30,7 @@
#include "src/core/core.h" #include "src/core/core.h"
#include "src/core/coreav.h" #include "src/core/coreav.h"
#include "src/nexus.h" #include "src/nexus.h"
#include "src/model/status.h"
#include "src/persistence/profile.h" #include "src/persistence/profile.h"
#include "src/persistence/settings.h" #include "src/persistence/settings.h"
#include "src/widget/gui.h" #include "src/widget/gui.h"
@ -222,7 +223,7 @@ void AdvancedForm::on_reconnectButton_clicked()
return; return;
} }
emit Core::getInstance()->statusSet(Status::Offline); emit Core::getInstance()->statusSet(Status::Status::Offline);
Nexus::getProfile()->restartCore(); Nexus::getProfile()->restartCore();
} }

View File

@ -16,6 +16,7 @@
#include "friendlistwidget.h" #include "friendlistwidget.h"
#include "friendwidget.h" #include "friendwidget.h"
#include "src/model/friend.h" #include "src/model/friend.h"
#include "src/model/status.h"
#include "src/friendlist.h" #include "src/friendlist.h"
#include <cassert> #include <cassert>
@ -46,12 +47,12 @@ void FriendListLayout::init()
addLayout(friendOfflineLayout.getLayout()); addLayout(friendOfflineLayout.getLayout());
} }
void FriendListLayout::addFriendWidget(FriendWidget* w, Status s) void FriendListLayout::addFriendWidget(FriendWidget* w, Status::Status s)
{ {
friendOfflineLayout.removeSortedWidget(w); friendOfflineLayout.removeSortedWidget(w);
friendOnlineLayout.removeSortedWidget(w); friendOnlineLayout.removeSortedWidget(w);
if (s == Status::Offline) { if (s == Status::Status::Offline) {
friendOfflineLayout.addSortedWidget(w); friendOfflineLayout.addSortedWidget(w);
return; return;
} }
@ -59,9 +60,9 @@ void FriendListLayout::addFriendWidget(FriendWidget* w, Status s)
friendOnlineLayout.addSortedWidget(w); friendOnlineLayout.addSortedWidget(w);
} }
void FriendListLayout::removeFriendWidget(FriendWidget* widget, Status s) void FriendListLayout::removeFriendWidget(FriendWidget* widget, Status::Status s)
{ {
if (s == Status::Offline) if (s == Status::Status::Offline)
friendOfflineLayout.removeSortedWidget(widget); friendOfflineLayout.removeSortedWidget(widget);
else else
friendOnlineLayout.removeSortedWidget(widget); friendOnlineLayout.removeSortedWidget(widget);
@ -123,7 +124,7 @@ QLayout* FriendListLayout::getLayoutOffline() const
return friendOfflineLayout.getLayout(); return friendOfflineLayout.getLayout();
} }
QLayout* FriendListLayout::getFriendLayout(Status s) const QLayout* FriendListLayout::getFriendLayout(Status::Status s) const
{ {
return s == Status::Offline ? friendOfflineLayout.getLayout() : friendOnlineLayout.getLayout(); return s == Status::Status::Offline ? friendOfflineLayout.getLayout() : friendOnlineLayout.getLayout();
} }

View File

@ -16,6 +16,7 @@
#define FRIENDLISTLAYOUT_H #define FRIENDLISTLAYOUT_H
#include "genericchatitemlayout.h" #include "genericchatitemlayout.h"
#include "src/model/status.h"
#include "src/core/core.h" #include "src/core/core.h"
#include <QBoxLayout> #include <QBoxLayout>
@ -29,8 +30,8 @@ public:
explicit FriendListLayout(); explicit FriendListLayout();
explicit FriendListLayout(QWidget* parent); explicit FriendListLayout(QWidget* parent);
void addFriendWidget(FriendWidget* widget, Status s); void addFriendWidget(FriendWidget* widget, Status::Status s);
void removeFriendWidget(FriendWidget* widget, Status s); void removeFriendWidget(FriendWidget* widget, Status::Status s);
int indexOfFriendWidget(GenericChatItemWidget* widget, bool online) const; int indexOfFriendWidget(GenericChatItemWidget* widget, bool online) const;
void moveFriendWidgets(FriendListWidget* listWidget); void moveFriendWidgets(FriendListWidget* listWidget);
int friendOnlineCount() const; int friendOnlineCount() const;
@ -45,7 +46,7 @@ public:
private: private:
void init(); void init();
QLayout* getFriendLayout(Status s) const; QLayout* getFriendLayout(Status::Status s) const;
GenericChatItemLayout friendOnlineLayout; GenericChatItemLayout friendOnlineLayout;
GenericChatItemLayout friendOfflineLayout; GenericChatItemLayout friendOfflineLayout;

View File

@ -26,6 +26,7 @@
#include "src/friendlist.h" #include "src/friendlist.h"
#include "src/model/friend.h" #include "src/model/friend.h"
#include "src/model/group.h" #include "src/model/group.h"
#include "src/model/status.h"
#include "src/persistence/settings.h" #include "src/persistence/settings.h"
#include <QDragEnterEvent> #include <QDragEnterEvent>
#include <QDragLeaveEvent> #include <QDragLeaveEvent>
@ -289,7 +290,7 @@ void FriendListWidget::addGroupWidget(GroupWidget* widget)
}); });
} }
void FriendListWidget::addFriendWidget(FriendWidget* w, Status s, int circleIndex) void FriendListWidget::addFriendWidget(FriendWidget* w, Status::Status s, int circleIndex)
{ {
CircleWidget* circleWidget = CircleWidget::getFromID(circleIndex); CircleWidget* circleWidget = CircleWidget::getFromID(circleIndex);
if (circleWidget == nullptr) if (circleWidget == nullptr)
@ -609,7 +610,7 @@ void FriendListWidget::dayTimeout()
dayTimer->start(timeUntilTomorrow()); dayTimer->start(timeUntilTomorrow());
} }
void FriendListWidget::moveWidget(FriendWidget* widget, Status s, bool add) void FriendListWidget::moveWidget(FriendWidget* widget, Status::Status s, bool add)
{ {
if (mode == Name) { if (mode == Name) {
const Friend* f = widget->getFriend(); const Friend* f = widget->getFriend();

View File

@ -22,6 +22,7 @@
#include "genericchatitemlayout.h" #include "genericchatitemlayout.h"
#include "src/core/core.h" #include "src/core/core.h"
#include "src/model/status.h"
#include <QWidget> #include <QWidget>
class QVBoxLayout; class QVBoxLayout;
@ -50,7 +51,7 @@ public:
Mode getMode() const; Mode getMode() const;
void addGroupWidget(GroupWidget* widget); void addGroupWidget(GroupWidget* widget);
void addFriendWidget(FriendWidget* w, Status s, int circleIndex); void addFriendWidget(FriendWidget* w, Status::Status s, int circleIndex);
void removeGroupWidget(GroupWidget* w); void removeGroupWidget(GroupWidget* w);
void removeFriendWidget(FriendWidget* w); void removeFriendWidget(FriendWidget* w);
void addCircleWidget(int id); void addCircleWidget(int id);
@ -72,7 +73,7 @@ public slots:
void renameCircleWidget(CircleWidget* circleWidget, const QString& newName); void renameCircleWidget(CircleWidget* circleWidget, const QString& newName);
void onFriendWidgetRenamed(FriendWidget* friendWidget); void onFriendWidgetRenamed(FriendWidget* friendWidget);
void onGroupchatPositionChanged(bool top); void onGroupchatPositionChanged(bool top);
void moveWidget(FriendWidget* w, Status s, bool add = false); void moveWidget(FriendWidget* w, Status::Status s, bool add = false);
protected: protected:
void dragEnterEvent(QDragEnterEvent* event) override; void dragEnterEvent(QDragEnterEvent* event) override;

View File

@ -29,6 +29,7 @@
#include "src/model/chatroom/friendchatroom.h" #include "src/model/chatroom/friendchatroom.h"
#include "src/model/friend.h" #include "src/model/friend.h"
#include "src/model/group.h" #include "src/model/group.h"
#include "src/model/status.h"
#include "src/persistence/settings.h" #include "src/persistence/settings.h"
#include "src/widget/about/aboutfriendform.h" #include "src/widget/about/aboutfriendform.h"
#include "src/widget/contentdialogmanager.h" #include "src/widget/contentdialogmanager.h"
@ -62,7 +63,7 @@ FriendWidget::FriendWidget(std::shared_ptr<FriendChatroom> chatroom, bool compac
, isDefaultAvatar{true} , isDefaultAvatar{true}
{ {
avatar->setPixmap(QPixmap(":/img/contact.svg")); avatar->setPixmap(QPixmap(":/img/contact.svg"));
statusPic.setPixmap(QPixmap(Widget::getStatusIconPath(Status::Offline))); statusPic.setPixmap(QPixmap(Status::getIconPath(Status::Status::Offline)));
statusPic.setMargin(3); statusPic.setMargin(3);
auto frnd = chatroom->getFriend(); auto frnd = chatroom->getFriend();
@ -324,7 +325,7 @@ void FriendWidget::updateStatusLight()
{ {
const auto frnd = chatroom->getFriend(); const auto frnd = chatroom->getFriend();
const bool event = frnd->getEventFlag(); const bool event = frnd->getEventFlag();
statusPic.setPixmap(QPixmap(Widget::getStatusIconPath(frnd->getStatus(), event))); statusPic.setPixmap(QPixmap(Status::getIconPath(frnd->getStatus(), event)));
if (event) { if (event) {
const Settings& s = Settings::getInstance(); const Settings& s = Settings::getInstance();

View File

@ -34,6 +34,7 @@
#include "src/model/friend.h" #include "src/model/friend.h"
#include "src/friendlist.h" #include "src/friendlist.h"
#include "src/model/group.h" #include "src/model/group.h"
#include "src/model/status.h"
#include "src/grouplist.h" #include "src/grouplist.h"
#include "src/widget/contentdialogmanager.h" #include "src/widget/contentdialogmanager.h"
#include "src/widget/friendwidget.h" #include "src/widget/friendwidget.h"
@ -48,7 +49,7 @@ GroupWidget::GroupWidget(std::shared_ptr<GroupChatroom> chatroom, bool compact)
, chatroom{chatroom} , chatroom{chatroom}
{ {
avatar->setPixmap(Style::scaleSvgImage(":img/group.svg", avatar->width(), avatar->height())); avatar->setPixmap(Style::scaleSvgImage(":img/group.svg", avatar->width(), avatar->height()));
statusPic.setPixmap(QPixmap(Widget::getStatusIconPath(Status::Online))); statusPic.setPixmap(QPixmap(Status::getIconPath(Status::Status::Online)));
statusPic.setMargin(3); statusPic.setMargin(3);
Group* g = chatroom->getGroup(); Group* g = chatroom->getGroup();
@ -181,7 +182,7 @@ void GroupWidget::updateStatusLight()
Group* g = chatroom->getGroup(); Group* g = chatroom->getGroup();
const bool event = g->getEventFlag(); const bool event = g->getEventFlag();
statusPic.setPixmap(QPixmap(Widget::getStatusIconPath(Status::Online, event))); statusPic.setPixmap(QPixmap(Status::getIconPath(Status::Status::Online, event)));
statusPic.setMargin(event ? 1 : 3); statusPic.setMargin(event ? 1 : 3);
} }

View File

@ -60,6 +60,7 @@
#include "src/model/friend.h" #include "src/model/friend.h"
#include "src/model/group.h" #include "src/model/group.h"
#include "src/model/groupinvite.h" #include "src/model/groupinvite.h"
#include "src/model/status.h"
#include "src/model/profile/profileinfo.h" #include "src/model/profile/profileinfo.h"
#include "src/net/updatecheck.h" #include "src/net/updatecheck.h"
#include "src/nexus.h" #include "src/nexus.h"
@ -128,15 +129,15 @@ void Widget::init()
// Preparing icons and set their size // Preparing icons and set their size
statusOnline = new QAction(this); statusOnline = new QAction(this);
statusOnline->setIcon(prepareIcon(getStatusIconPath(Status::Online), icon_size, icon_size)); statusOnline->setIcon(prepareIcon(Status::getIconPath(Status::Status::Online), icon_size, icon_size));
connect(statusOnline, &QAction::triggered, this, &Widget::setStatusOnline); connect(statusOnline, &QAction::triggered, this, &Widget::setStatusOnline);
statusAway = new QAction(this); statusAway = new QAction(this);
statusAway->setIcon(prepareIcon(getStatusIconPath(Status::Away), icon_size, icon_size)); statusAway->setIcon(prepareIcon(Status::getIconPath(Status::Status::Away), icon_size, icon_size));
connect(statusAway, &QAction::triggered, this, &Widget::setStatusAway); connect(statusAway, &QAction::triggered, this, &Widget::setStatusAway);
statusBusy = new QAction(this); statusBusy = new QAction(this);
statusBusy->setIcon(prepareIcon(getStatusIconPath(Status::Busy), icon_size, icon_size)); statusBusy->setIcon(prepareIcon(Status::getIconPath(Status::Status::Busy), icon_size, icon_size));
connect(statusBusy, &QAction::triggered, this, &Widget::setStatusBusy); connect(statusBusy, &QAction::triggered, this, &Widget::setStatusBusy);
actionLogout = new QAction(this); actionLogout = new QAction(this);
@ -215,7 +216,7 @@ void Widget::init()
ui->mainSplitter->setStretchFactor(0, 0); ui->mainSplitter->setStretchFactor(0, 0);
ui->mainSplitter->setStretchFactor(1, 1); ui->mainSplitter->setStretchFactor(1, 1);
onStatusSet(Status::Offline); onStatusSet(Status::Status::Offline);
// 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);
@ -575,7 +576,7 @@ void Widget::closeEvent(QCloseEvent* event)
QWidget::closeEvent(event); QWidget::closeEvent(event);
} else { } else {
if (autoAwayActive) { if (autoAwayActive) {
emit statusSet(Status::Online); emit statusSet(Status::Status::Online);
autoAwayActive = false; autoAwayActive = false;
} }
saveWindowGeometry(); saveWindowGeometry();
@ -620,7 +621,7 @@ void Widget::onConnected()
void Widget::onDisconnected() void Widget::onDisconnected()
{ {
ui->statusButton->setEnabled(false); ui->statusButton->setEnabled(false);
emit core->statusSet(Status::Offline); emit core->statusSet(Status::Status::Offline);
} }
void Widget::onFailedToStartCore() void Widget::onFailedToStartCore()
@ -646,10 +647,10 @@ void Widget::onBadProxyCore()
onShowSettings(); onShowSettings();
} }
void Widget::onStatusSet(Status status) void Widget::onStatusSet(Status::Status status)
{ {
ui->statusButton->setProperty("status", getStatusTitle(status)); ui->statusButton->setProperty("status", getTitle(status));
ui->statusButton->setIcon(prepareIcon(getStatusIconPath(status), icon_size, icon_size)); ui->statusButton->setIcon(prepareIcon(getIconPath(status), icon_size, icon_size));
updateIcons(); updateIcons();
} }
@ -991,7 +992,7 @@ void Widget::addFriend(uint32_t friendId, const ToxPk& friendPk)
settings.setFriendActivity(friendPk, chatDate); settings.setFriendActivity(friendPk, chatDate);
} }
contactListWidget->addFriendWidget(widget, Status::Offline, settings.getFriendCircleID(friendPk)); contactListWidget->addFriendWidget(widget, Status::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);
@ -1037,7 +1038,7 @@ void Widget::addFriendFailed(const ToxPk&, const QString& errorInfo)
QMessageBox::critical(nullptr, "Error", info); QMessageBox::critical(nullptr, "Error", info);
} }
void Widget::onFriendStatusChanged(int friendId, Status status) void Widget::onFriendStatusChanged(int friendId, Status::Status status)
{ {
const auto& friendPk = FriendList::id2Key(friendId); const auto& friendPk = FriendList::id2Key(friendId);
Friend* f = FriendList::findFriend(friendPk); Friend* f = FriendList::findFriend(friendPk);
@ -1050,9 +1051,9 @@ void Widget::onFriendStatusChanged(int friendId, Status status)
FriendWidget* widget = friendWidgets[f->getPublicKey()]; FriendWidget* widget = friendWidgets[f->getPublicKey()];
if (isActualChange) { if (isActualChange) {
if (!f->isOnline()) { if (!f->isOnline()) {
contactListWidget->moveWidget(widget, Status::Online); contactListWidget->moveWidget(widget, Status::Status::Online);
} else if (status == Status::Offline) { } else if (status == Status::Status::Offline) {
contactListWidget->moveWidget(widget, Status::Offline); contactListWidget->moveWidget(widget, Status::Status::Offline);
} }
} }
@ -1110,10 +1111,10 @@ void Widget::onFriendAliasChanged(const ToxPk& friendId, const QString& alias)
// TODO(sudden6): don't update the contact list here, make it update itself // TODO(sudden6): don't update the contact list here, make it update itself
FriendWidget* friendWidget = friendWidgets[friendId]; FriendWidget* friendWidget = friendWidgets[friendId];
Status status = f->getStatus(); Status::Status status = f->getStatus();
contactListWidget->moveWidget(friendWidget, status); contactListWidget->moveWidget(friendWidget, status);
FilterCriteria criteria = getFilterCriteria(); FilterCriteria criteria = getFilterCriteria();
bool filter = status == Status::Offline ? filterOffline(criteria) : filterOnline(criteria); bool filter = status == Status::Status::Offline ? filterOffline(criteria) : filterOnline(criteria);
friendWidget->searchName(ui->searchContactText->text(), filter); friendWidget->searchName(ui->searchContactText->text(), filter);
settings.setFriendAlias(friendId, alias); settings.setFriendAlias(friendId, alias);
@ -1446,7 +1447,7 @@ bool Widget::newMessageAlert(QWidget* currentWindow, bool isActive, bool sound,
#endif #endif
eventFlag = true; eventFlag = true;
} }
bool isBusy = core->getStatus() == Status::Busy; bool isBusy = core->getStatus() == Status::Status::Busy;
bool busySound = settings.getBusySound(); bool busySound = settings.getBusySound();
bool notifySound = settings.getNotifySound(); bool notifySound = settings.getNotifySound();
@ -1972,11 +1973,11 @@ void Widget::onUserAwayCheck()
if (online && away) { if (online && away) {
qDebug() << "auto away activated at" << QTime::currentTime().toString(); qDebug() << "auto away activated at" << QTime::currentTime().toString();
emit statusSet(Status::Away); emit statusSet(Status::Status::Away);
autoAwayActive = true; autoAwayActive = true;
} else if (autoAwayActive && !away) { } else if (autoAwayActive && !away) {
qDebug() << "auto away deactivated at" << QTime::currentTime().toString(); qDebug() << "auto away deactivated at" << QTime::currentTime().toString();
emit statusSet(Status::Online); emit statusSet(Status::Status::Online);
autoAwayActive = false; autoAwayActive = false;
} }
#endif #endif
@ -2042,7 +2043,7 @@ void Widget::setStatusOnline()
return; return;
} }
core->setStatus(Status::Online); core->setStatus(Status::Status::Online);
} }
void Widget::setStatusAway() void Widget::setStatusAway()
@ -2051,7 +2052,7 @@ void Widget::setStatusAway()
return; return;
} }
core->setStatus(Status::Away); core->setStatus(Status::Status::Away);
} }
void Widget::setStatusBusy() void Widget::setStatusBusy()
@ -2060,7 +2061,7 @@ void Widget::setStatusBusy()
return; return;
} }
core->setStatus(Status::Busy); core->setStatus(Status::Status::Busy);
} }
void Widget::onGroupSendFailed(uint32_t groupnumber) void Widget::onGroupSendFailed(uint32_t groupnumber)
@ -2204,30 +2205,6 @@ void Widget::previousContact()
cycleContacts(false); cycleContacts(false);
} }
QString Widget::getStatusIconPath(Status status, bool event)
{
QString eventSuffix{""};
if (event) {
eventSuffix = "_notification";
}
switch (status) {
case Status::Online:
return ":/img/status/online" + eventSuffix + ".svg";
case Status::Away:
return ":/img/status/away" + eventSuffix + ".svg";
case Status::Busy:
return ":/img/status/busy" + eventSuffix + ".svg";
case Status::Offline:
return ":/img/status/offline" + eventSuffix + ".svg";
case Status::Blocked:
return ":/img/status/blocked.svg";
}
qWarning() << "Status unknown";
assert(false);
return QString{};
}
// Preparing needed to set correct size of icons for GTK tray backend // Preparing needed to set correct size of icons for GTK tray backend
inline QIcon Widget::prepareIcon(QString path, int w, int h) inline QIcon Widget::prepareIcon(QString path, int w, int h)
{ {
@ -2255,50 +2232,6 @@ inline QIcon Widget::prepareIcon(QString path, int w, int h)
return QIcon(path); return QIcon(path);
} }
QPixmap Widget::getStatusIconPixmap(QString path, uint32_t w, uint32_t h)
{
QPixmap pix(w, h);
pix.load(path);
return pix;
}
QString Widget::getStatusTitle(Status status)
{
switch (status) {
case Status::Online:
return tr("online", "contact status");
case Status::Away:
return tr("away", "contact status");
case Status::Busy:
return tr("busy", "contact status");
case Status::Offline:
return tr("offline", "contact status");
case Status::Blocked:
return tr("blocked", "contact status");
}
assert(false);
return QStringLiteral("");
}
Status Widget::getStatusFromString(QString status)
{
if (status == QStringLiteral("online"))
return Status::Online;
else if (status == QStringLiteral("away"))
return Status::Away;
else if (status == QStringLiteral("busy"))
return Status::Busy;
else if (status == QStringLiteral("offline"))
return Status::Offline;
else if (status == QStringLiteral("blocked"))
return Status::Blocked;
else {
assert(false);
return Status::Offline;
}
}
void Widget::searchContacts() void Widget::searchContacts()
{ {
QString searchString = ui->searchContactText->text(); QString searchString = ui->searchContactText->text();

View File

@ -135,11 +135,7 @@ public:
void reloadHistory(); void reloadHistory();
void reloadTheme(); void reloadTheme();
static QString getStatusIconPath(Status status, bool event = false);
static inline QIcon prepareIcon(QString path, int w = 0, int h = 0); static inline QIcon prepareIcon(QString path, int w = 0, int h = 0);
static QPixmap getStatusIconPixmap(QString path, uint32_t w, uint32_t h);
static QString getStatusTitle(Status status);
static Status getStatusFromString(QString status);
void searchCircle(CircleWidget* circleWidget); void searchCircle(CircleWidget* circleWidget);
bool groupsVisible() const; bool groupsVisible() const;
@ -154,7 +150,7 @@ public slots:
void forceShow(); void forceShow();
void onConnected(); void onConnected();
void onDisconnected(); void onDisconnected();
void onStatusSet(Status status); void onStatusSet(Status::Status status);
void onFailedToStartCore(); void onFailedToStartCore();
void onBadProxyCore(); void onBadProxyCore();
void onSelfAvatarLoaded(const QPixmap& pic); void onSelfAvatarLoaded(const QPixmap& pic);
@ -162,7 +158,7 @@ public slots:
void setStatusMessage(const QString& statusMessage); void setStatusMessage(const QString& statusMessage);
void addFriend(uint32_t friendId, const ToxPk& friendPk); void addFriend(uint32_t friendId, const ToxPk& friendPk);
void addFriendFailed(const ToxPk& userId, const QString& errorInfo = QString()); void addFriendFailed(const ToxPk& userId, const QString& errorInfo = QString());
void onFriendStatusChanged(int friendId, Status status); void onFriendStatusChanged(int friendId, Status::Status status);
void onFriendStatusMessageChanged(int friendId, const QString& message); void onFriendStatusMessageChanged(int friendId, const QString& message);
void onFriendDisplayedNameChanged(const QString& displayed); void onFriendDisplayedNameChanged(const QString& displayed);
void onFriendUsernameChanged(int friendId, const QString& username); void onFriendUsernameChanged(int friendId, const QString& username);
@ -193,8 +189,8 @@ public slots:
signals: signals:
void friendRequestAccepted(const ToxPk& friendPk); void friendRequestAccepted(const ToxPk& friendPk);
void friendRequested(const ToxId& friendAddress, const QString& message); void friendRequested(const ToxId& friendAddress, const QString& message);
void statusSet(Status status); void statusSet(Status::Status status);
void statusSelected(Status status); void statusSelected(Status::Status status);
void usernameChanged(const QString& username); void usernameChanged(const QString& username);
void changeGroupTitle(uint32_t groupnumber, const QString& title); void changeGroupTitle(uint32_t groupnumber, const QString& title);
void statusMessageChanged(const QString& statusMessage); void statusMessageChanged(const QString& statusMessage);