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

299 lines
9.5 KiB
C
Raw Normal View History

2014-07-07 00:19:45 +08:00
/*
Copyright © 2014-2015 by The qTox Project
2014-07-07 00:19:45 +08:00
This file is part of qTox, a Qt-based graphical interface for Tox.
qTox is libre software: you can redistribute it and/or modify
2014-07-07 00:19:45 +08:00
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,
2014-07-07 00:19:45 +08:00
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.
2014-07-07 00:19:45 +08:00
You should have received a copy of the GNU General Public License
along with qTox. If not, see <http://www.gnu.org/licenses/>.
2014-07-07 00:19:45 +08:00
*/
2014-06-25 04:11:11 +08:00
#ifndef WIDGET_H
#define WIDGET_H
#include <QMainWindow>
2014-10-21 02:03:44 +08:00
#include <QSystemTrayIcon>
#include <QFileInfo>
#include "src/core/corestructs.h"
#include "genericchatitemwidget.h"
2014-06-25 04:11:11 +08:00
#define PIXELS_TO_ACT 7
2014-06-25 04:11:11 +08:00
namespace Ui {
class MainWindow;
2014-06-25 04:11:11 +08:00
}
class GenericChatroomWidget;
class FriendWidget;
2014-06-25 04:11:11 +08:00
class Group;
class Friend;
2014-09-11 21:44:34 +08:00
class QSplitter;
2014-10-08 22:42:09 +08:00
class VideoSurface;
2014-09-11 21:44:34 +08:00
class QMenu;
class Core;
class Camera;
class FriendListWidget;
class MaskablePixmapWidget;
2014-10-16 17:47:58 +08:00
class QTimer;
class SystemTrayIcon;
2015-06-08 02:24:55 +08:00
class FilesForm;
class ProfileForm;
class SettingsWidget;
class AddFriendForm;
class GroupInviteForm;
class CircleWidget;
class QActionGroup;
class ContentLayout;
class ContentDialog;
class QPushButton;
2014-06-25 04:11:11 +08:00
class Widget final : public QMainWindow
2014-06-25 04:11:11 +08:00
{
Q_OBJECT
public:
explicit Widget(QWidget *parent = 0);
~Widget();
2015-02-19 04:22:03 +08:00
void init();
void setCentralWidget(QWidget *widget, const QString &widgetName);
2014-06-25 04:11:11 +08:00
QString getUsername();
2014-06-30 20:49:42 +08:00
Camera* getCamera();
2014-06-25 04:11:11 +08:00
static Widget* getInstance();
void showUpdateDownloadProgress(); ///< Switches to the About settings page
void addFriendDialog(Friend* frnd, ContentDialog* dialog);
void addGroupDialog(Group* group, ContentDialog* dialog);
bool newFriendMessageAlert(int friendId, bool sound=true);
bool newGroupMessageAlert(int groupId, bool notify);
bool getIsWindowMinimized();
void updateIcons();
2015-06-04 22:36:08 +08:00
void clearContactsList();
void updateScroll(GenericChatroomWidget *widget);
enum DialogType
{
AddDialog,
TransferDialog,
SettingDialog,
2016-02-21 07:45:18 +08:00
ProfileDialog,
GroupDialog
};
static QString fromDialogType(DialogType type);
ContentDialog* createContentDialog() const;
ContentLayout* createContentDialog(DialogType type);
static void confirmExecutableOpen(const QFileInfo &file);
2014-11-10 21:06:35 +08:00
void clearAllReceipts();
2015-02-03 07:56:51 +08:00
void reloadHistory();
2014-06-25 04:11:11 +08:00
2014-11-16 04:30:20 +08:00
void reloadTheme();
static QString getStatusIconPath(Status status);
static inline QIcon prepareIcon(QString path, uint32_t w=0, uint32_t h=0);
static QPixmap getStatusIconPixmap(QString path, uint32_t w, uint32_t h);
static QString getStatusTitle(Status status);
static Status getStatusFromString(QString status);
2014-11-16 04:30:20 +08:00
void searchCircle(CircleWidget* circleWidget);
void searchItem(GenericChatItemWidget* chatItem, GenericChatItemWidget::ItemType type);
bool groupsVisible() const;
// Used to reset the blinking icon
void resetIcon();
public slots:
void onSettingsClicked();
void onSeparateWindowClicked(bool separate);
void onSeparateWindowChanged(bool separate, bool clicked);
2014-11-15 08:28:44 +08:00
void setWindowTitle(const QString& title);
void forceShow();
2014-06-25 04:11:11 +08:00
void onConnected();
void onDisconnected();
void onStatusSet(Status status);
void onFailedToStartCore();
2014-10-06 04:49:44 +08:00
void onBadProxyCore();
2014-09-24 22:51:16 +08:00
void onSelfAvatarLoaded(const QPixmap &pic);
2014-06-25 04:11:11 +08:00
void setUsername(const QString& username);
void setStatusMessage(const QString &statusMessage);
void addFriend(int friendId, const QString& userId);
void addFriendFailed(const QString& userId, const QString& errorInfo = QString());
void onFriendshipChanged(int friendId);
2014-06-25 04:11:11 +08:00
void onFriendStatusChanged(int friendId, Status status);
void onFriendStatusMessageChanged(int friendId, const QString& message);
void onFriendUsernameChanged(int friendId, const QString& username);
void onFriendDisplayChanged(FriendWidget* friendWidget, Status s);
void onFriendMessageReceived(int friendId, const QString& message, bool isAction);
2014-06-25 04:11:11 +08:00
void onFriendRequestReceived(const QString& userId, const QString& message);
void updateFriendActivity(Friend* frnd);
void onMessageSendResult(uint32_t friendId, const QString& message, int messageId);
2014-11-01 22:19:11 +08:00
void onReceiptRecieved(int friendId, int receipt);
2014-06-30 05:38:48 +08:00
void onEmptyGroupCreated(int groupId);
void onGroupInviteReceived(int32_t friendId, uint8_t type, QByteArray invite);
void onGroupInviteAccepted(int32_t friendId, uint8_t type, QByteArray invite);
2014-11-23 23:55:49 +08:00
void onGroupMessageReceived(int groupnumber, int peernumber, const QString& message, bool isAction);
2014-06-25 04:11:11 +08:00
void onGroupNamelistChanged(int groupnumber, int peernumber, uint8_t change);
2014-11-06 08:22:50 +08:00
void onGroupTitleChanged(int groupnumber, const QString& author, const QString& title);
void onGroupPeerAudioPlaying(int groupnumber, int peernumber);
void onGroupSendResult(int groupId, const QString& message, int result);
void onFriendTypingChanged(int friendId, bool isTyping);
void nextContact();
void previousContact();
signals:
void friendRequestAccepted(const QString& userId);
void friendRequested(const QString& friendAddress, const QString& message);
void statusSet(Status status);
void statusSelected(Status status);
void usernameChanged(const QString& username);
void statusMessageChanged(const QString& statusMessage);
void resized();
#ifdef Q_OS_MAC
void windowStateChanged(Qt::WindowStates states);
#endif
protected:
virtual bool eventFilter(QObject *obj, QEvent *event) final override;
virtual bool event(QEvent * e) final override;
virtual void closeEvent(QCloseEvent *event) final override;
virtual void changeEvent(QEvent *event) final override;
virtual void resizeEvent(QResizeEvent *event) final override;
virtual void moveEvent(QMoveEvent *event) final override;
private slots:
void onAddClicked();
void onGroupClicked();
void onTransferClicked();
void showProfile();
void onChatroomWidgetClicked(GenericChatroomWidget *, bool group);
void onStatusMessageChanged(const QString& newStatusMessage);
2014-06-25 04:11:11 +08:00
void removeFriend(int friendId);
void copyFriendIdToClipboard(int friendId);
2014-06-25 04:11:11 +08:00
void removeGroup(int groupId);
2014-07-06 04:54:27 +08:00
void setStatusOnline();
void setStatusAway();
void setStatusBusy();
2014-10-21 02:03:44 +08:00
void onIconClick(QSystemTrayIcon::ActivationReason);
2014-11-26 20:34:08 +08:00
void onUserAwayCheck();
2014-12-12 00:49:11 +08:00
void onEventIconTick();
void onTryCreateTrayIcon();
void onSetShowSystemTray(bool newValue);
void onSplitterMoved(int pos, int index);
void processOfflineMsgs();
2015-05-28 01:17:12 +08:00
void friendListContextMenu(const QPoint &pos);
void friendRequestsUpdate();
void groupInvitesUpdate();
void groupInvitesClear();
private:
int icon_size;
2014-06-25 04:11:11 +08:00
private:
enum ActiveToolMenuButton {
AddButton,
GroupButton,
TransferButton,
SettingButton,
None,
};
enum FilterCriteria
{
All=0,
Online,
Offline,
Friends,
Groups
};
private:
bool newMessageAlert(QWidget* currentWindow, bool isActive, bool sound = true, bool notify = true);
void setActiveToolMenuButton(ActiveToolMenuButton newActiveButton);
void hideMainForms(GenericChatroomWidget* chatroomWidget);
Group *createGroup(int groupId);
void removeFriend(Friend* f, bool fake = false);
void removeGroup(Group* g, bool fake = false);
void saveWindowGeometry();
void saveSplitterGeometry();
void cycleContacts(bool forward);
void searchContacts();
void changeDisplayMode();
void updateFilterText();
int getFilterCriteria() const;
static bool filterGroups(int index);
static bool filterOnline(int index);
static bool filterOffline(int index);
void retranslateUi();
void focusChatInput();
private:
2016-06-09 00:46:20 +08:00
SystemTrayIcon *icon = nullptr;
2014-10-21 02:03:44 +08:00
QMenu *trayMenu;
QAction *statusOnline;
QAction *statusAway;
QAction *statusBusy;
2015-08-30 19:25:46 +08:00
QAction *actionLogout;
QAction *actionQuit;
QAction *actionShow;
QMenu* filterMenu;
QActionGroup* filterGroup;
QAction* filterAllAction;
QAction* filterOnlineAction;
QAction* filterOfflineAction;
QAction* filterFriendsAction;
QAction* filterGroupsAction;
QActionGroup* filterDisplayGroup;
QAction* filterDisplayName;
QAction* filterDisplayActivity;
2014-06-25 04:11:11 +08:00
Ui::MainWindow *ui;
QSplitter *centralLayout;
QPoint dragPosition;
ContentLayout* contentLayout;
AddFriendForm *addFriendForm;
GroupInviteForm* groupInviteForm;
ProfileForm *profileForm;
SettingsWidget *settingsWidget;
FilesForm *filesForm;
static Widget *instance;
GenericChatroomWidget *activeChatroomWidget;
FriendListWidget *contactListWidget;
MaskablePixmapWidget *profilePicture;
bool notify(QObject *receiver, QEvent *event);
2014-10-16 17:47:58 +08:00
bool autoAwayActive = false;
QTimer *timer, *offlineMsgTimer;
QRegExp nameMention, sanitizedNameMention;
2014-12-12 00:49:11 +08:00
bool eventFlag;
bool eventIcon;
2015-03-20 03:24:06 +08:00
bool wasMaximized = false;
QPushButton* friendRequestsButton;
QPushButton* groupInvitesButton;
unsigned int unreadGroupInvites;
2015-07-02 01:12:50 +08:00
#ifdef Q_OS_MAC
QAction* fileMenu;
QAction* editMenu;
QAction* contactMenu;
QMenu* changeStatusMenu;
QAction* editProfileAction;
QAction* logoutAction;
QAction* addContactAction;
QAction* nextConversationAction;
QAction* previousConversationAction;
2015-07-02 01:12:50 +08:00
#endif
2014-06-25 04:11:11 +08:00
};
bool toxActivateEventHandler(const QByteArray& data);
2014-06-25 04:11:11 +08:00
#endif // WIDGET_H