2014-07-07 00:19:45 +08:00
|
|
|
/*
|
2015-06-06 09:40:08 +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.
|
|
|
|
|
2015-06-06 09:40:08 +08:00
|
|
|
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.
|
2015-06-06 09:40:08 +08:00
|
|
|
|
|
|
|
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
|
2015-06-06 09:40:08 +08:00
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
2014-07-07 00:19:45 +08:00
|
|
|
|
2015-06-06 09:40:08 +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
|
|
|
|
|
2014-08-11 16:00:08 +08:00
|
|
|
#include <QMainWindow>
|
2014-10-21 02:03:44 +08:00
|
|
|
#include <QSystemTrayIcon>
|
2015-02-20 03:14:19 +08:00
|
|
|
#include <QFileInfo>
|
2015-04-24 08:32:09 +08:00
|
|
|
#include "src/core/corestructs.h"
|
2015-06-07 11:20:06 +08:00
|
|
|
#include "genericchatitemwidget.h"
|
2014-06-25 04:11:11 +08:00
|
|
|
|
2014-07-05 14:50:18 +08:00
|
|
|
#define PIXELS_TO_ACT 7
|
2014-07-01 10:12:17 +08:00
|
|
|
|
2014-06-25 04:11:11 +08:00
|
|
|
namespace Ui {
|
2014-08-11 16:00:08 +08:00
|
|
|
class MainWindow;
|
2014-06-25 04:11:11 +08:00
|
|
|
}
|
|
|
|
|
2014-09-02 00:20:28 +08:00
|
|
|
class GenericChatroomWidget;
|
2015-06-08 02:25:05 +08:00
|
|
|
class FriendWidget;
|
2014-06-25 04:11:11 +08:00
|
|
|
class Group;
|
2015-04-20 05:12:44 +08:00
|
|
|
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;
|
2014-09-26 22:39:29 +08:00
|
|
|
class MaskablePixmapWidget;
|
2014-10-16 17:47:58 +08:00
|
|
|
class QTimer;
|
2015-01-29 21:56:53 +08:00
|
|
|
class SystemTrayIcon;
|
2015-06-08 02:24:55 +08:00
|
|
|
class FilesForm;
|
|
|
|
class ProfileForm;
|
|
|
|
class SettingsWidget;
|
|
|
|
class AddFriendForm;
|
2015-06-07 11:20:06 +08:00
|
|
|
class CircleWidget;
|
2015-06-13 00:09:01 +08:00
|
|
|
class QActionGroup;
|
2015-06-17 02:25:19 +08:00
|
|
|
class ContentLayout;
|
2015-06-23 02:01:50 +08:00
|
|
|
class ContentDialog;
|
2014-06-25 04:11:11 +08:00
|
|
|
|
2015-06-09 02:08:24 +08:00
|
|
|
class Widget final : public QMainWindow
|
2014-06-25 04:11:11 +08:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
explicit Widget(QWidget *parent = 0);
|
2015-06-09 02:08:24 +08:00
|
|
|
~Widget();
|
2015-02-19 04:22:03 +08:00
|
|
|
void init();
|
2014-07-01 10:12:17 +08:00
|
|
|
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();
|
2015-06-23 02:01:50 +08:00
|
|
|
void addFriendDialog(Friend* frnd, ContentDialog* dialog);
|
|
|
|
void addGroupDialog(Group* group, ContentDialog* dialog);
|
2015-10-24 08:26:32 +08:00
|
|
|
bool newFriendMessageAlert(int friendId, bool sound=true);
|
2015-07-30 21:37:52 +08:00
|
|
|
bool newGroupMessageAlert(int groupId, bool notify);
|
2014-09-01 00:29:55 +08:00
|
|
|
bool getIsWindowMinimized();
|
2015-03-12 02:04:29 +08:00
|
|
|
void updateIcons();
|
2015-06-04 22:36:08 +08:00
|
|
|
void clearContactsList();
|
2015-07-03 02:38:18 +08:00
|
|
|
|
|
|
|
enum DialogType
|
|
|
|
{
|
|
|
|
AddDialog,
|
|
|
|
TransferDialog,
|
|
|
|
SettingDialog,
|
|
|
|
ProfileDialog
|
|
|
|
};
|
|
|
|
|
|
|
|
static QString fromDialogType(DialogType type);
|
2015-07-01 00:29:09 +08:00
|
|
|
ContentDialog* createContentDialog() const;
|
2015-07-30 07:46:19 +08:00
|
|
|
ContentLayout* createContentDialog(DialogType type);
|
2014-11-28 17:16:37 +08:00
|
|
|
|
2015-10-14 04:21:20 +08:00
|
|
|
static void confirmExecutableOpen(const QFileInfo &file);
|
2015-02-20 03:14:19 +08:00
|
|
|
|
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();
|
2015-02-12 20:18:04 +08:00
|
|
|
static QString getStatusIconPath(Status status);
|
2015-11-07 04:53:26 +08:00
|
|
|
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);
|
2015-02-12 20:18:04 +08:00
|
|
|
static QString getStatusTitle(Status status);
|
|
|
|
static Status getStatusFromString(QString status);
|
2014-11-16 04:30:20 +08:00
|
|
|
|
2015-06-07 11:20:06 +08:00
|
|
|
void searchCircle(CircleWidget* circleWidget);
|
|
|
|
void searchItem(GenericChatItemWidget* chatItem, GenericChatItemWidget::ItemType type);
|
|
|
|
bool groupsVisible() const;
|
|
|
|
|
2014-10-20 11:07:51 +08:00
|
|
|
public slots:
|
|
|
|
void onSettingsClicked();
|
2015-06-17 02:25:19 +08:00
|
|
|
void onSeparateWindowClicked(bool separate);
|
|
|
|
void onSeparateWindowChanged(bool separate, bool clicked);
|
2014-11-15 08:28:44 +08:00
|
|
|
void setWindowTitle(const QString& title);
|
2015-01-26 18:43:34 +08:00
|
|
|
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);
|
2014-11-10 03:23:43 +08:00
|
|
|
void addFriendFailed(const QString& userId, const QString& errorInfo = QString());
|
2015-06-15 21:48:34 +08:00
|
|
|
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);
|
2015-06-08 02:25:05 +08:00
|
|
|
void onFriendDisplayChanged(FriendWidget* friendWidget, Status s);
|
2014-10-02 14:01:23 +08:00
|
|
|
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);
|
2015-06-12 21:53:44 +08:00
|
|
|
void updateFriendActivity(Friend* frnd);
|
2015-04-20 05:12:44 +08:00
|
|
|
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);
|
2014-11-13 07:13:11 +08:00
|
|
|
void onGroupInviteReceived(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);
|
2015-03-13 14:00:12 +08:00
|
|
|
void onGroupPeerAudioPlaying(int groupnumber, int peernumber);
|
2015-04-20 05:12:44 +08:00
|
|
|
void onGroupSendResult(int groupId, const QString& message, int result);
|
2015-02-06 19:28:49 +08:00
|
|
|
void onFriendTypingChanged(int friendId, bool isTyping);
|
2015-02-28 01:56:47 +08:00
|
|
|
void nextContact();
|
|
|
|
void previousContact();
|
2015-02-06 19:28:49 +08:00
|
|
|
|
|
|
|
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();
|
2015-07-30 07:46:19 +08:00
|
|
|
#ifdef Q_OS_MAC
|
|
|
|
void windowStateChanged(Qt::WindowStates states);
|
|
|
|
#endif
|
2015-02-06 19:28:49 +08:00
|
|
|
|
2015-06-09 02:08:24 +08:00
|
|
|
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;
|
2015-10-06 21:13:47 +08:00
|
|
|
virtual void moveEvent(QMoveEvent *event) final override;
|
2015-06-09 02:08:24 +08:00
|
|
|
|
2015-02-06 19:28:49 +08:00
|
|
|
private slots:
|
|
|
|
void onAddClicked();
|
|
|
|
void onGroupClicked();
|
|
|
|
void onTransferClicked();
|
2015-03-11 10:01:13 +08:00
|
|
|
void showProfile();
|
2015-02-06 19:28:49 +08:00
|
|
|
void onUsernameChanged(const QString& newUsername, const QString& oldUsername);
|
2015-06-23 02:01:50 +08:00
|
|
|
void onChatroomWidgetClicked(GenericChatroomWidget *, bool group);
|
2015-06-08 02:25:05 +08:00
|
|
|
void onStatusMessageChanged(const QString& newStatusMessage);
|
2014-06-25 04:11:11 +08:00
|
|
|
void removeFriend(int friendId);
|
2014-07-02 05:50:07 +08:00
|
|
|
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();
|
2015-02-20 18:56:20 +08:00
|
|
|
void onTryCreateTrayIcon();
|
2014-11-14 04:33:11 +08:00
|
|
|
void onSetShowSystemTray(bool newValue);
|
2014-11-28 17:16:37 +08:00
|
|
|
void onSplitterMoved(int pos, int index);
|
2015-02-13 13:27:49 +08:00
|
|
|
void processOfflineMsgs();
|
2015-05-28 01:17:12 +08:00
|
|
|
void friendListContextMenu(const QPoint &pos);
|
2014-07-01 10:12:17 +08:00
|
|
|
|
2015-08-29 21:40:55 +08:00
|
|
|
private:
|
2015-08-30 00:06:22 +08:00
|
|
|
int icon_size;
|
2015-08-29 21:40:55 +08:00
|
|
|
|
2014-06-25 04:11:11 +08:00
|
|
|
private:
|
2015-04-01 16:01:25 +08:00
|
|
|
enum ActiveToolMenuButton {
|
|
|
|
AddButton,
|
|
|
|
GroupButton,
|
|
|
|
TransferButton,
|
|
|
|
SettingButton,
|
|
|
|
None,
|
|
|
|
};
|
2015-06-09 02:08:24 +08:00
|
|
|
|
|
|
|
enum FilterCriteria
|
|
|
|
{
|
|
|
|
All=0,
|
|
|
|
Online,
|
|
|
|
Offline,
|
|
|
|
Friends,
|
|
|
|
Groups
|
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
2015-10-24 08:26:32 +08:00
|
|
|
bool newMessageAlert(QWidget* currentWindow, bool isActive, bool sound = true, bool notify = true);
|
2015-04-01 16:01:25 +08:00
|
|
|
void setActiveToolMenuButton(ActiveToolMenuButton newActiveButton);
|
2015-06-17 02:25:19 +08:00
|
|
|
void hideMainForms(GenericChatroomWidget* chatroomWidget);
|
2015-02-28 01:56:47 +08:00
|
|
|
Group *createGroup(int groupId);
|
2014-11-12 07:00:24 +08:00
|
|
|
void removeFriend(Friend* f, bool fake = false);
|
|
|
|
void removeGroup(Group* g, bool fake = false);
|
2014-11-28 17:16:37 +08:00
|
|
|
void saveWindowGeometry();
|
|
|
|
void saveSplitterGeometry();
|
2015-06-07 11:20:06 +08:00
|
|
|
void cycleContacts(bool forward);
|
|
|
|
void searchContacts();
|
2015-06-13 00:09:01 +08:00
|
|
|
void changeDisplayMode();
|
|
|
|
void updateFilterText();
|
|
|
|
int getFilterCriteria() const;
|
2015-06-07 11:20:06 +08:00
|
|
|
static bool filterGroups(int index);
|
|
|
|
static bool filterOnline(int index);
|
|
|
|
static bool filterOffline(int index);
|
2015-06-06 03:37:01 +08:00
|
|
|
void retranslateUi();
|
2015-06-09 02:08:24 +08:00
|
|
|
|
|
|
|
private:
|
2015-01-29 21:56:53 +08:00
|
|
|
SystemTrayIcon *icon;
|
2014-10-21 02:03:44 +08:00
|
|
|
QMenu *trayMenu;
|
2015-06-13 00:09:01 +08:00
|
|
|
QAction *statusOnline;
|
|
|
|
QAction *statusAway;
|
|
|
|
QAction *statusBusy;
|
2015-08-30 19:25:46 +08:00
|
|
|
QAction *actionLogout;
|
2015-06-13 00:09:01 +08:00
|
|
|
QAction *actionQuit;
|
|
|
|
|
|
|
|
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
|
|
|
|
2014-08-11 16:00:08 +08:00
|
|
|
Ui::MainWindow *ui;
|
2014-07-03 14:43:23 +08:00
|
|
|
QSplitter *centralLayout;
|
2014-07-01 10:12:17 +08:00
|
|
|
QPoint dragPosition;
|
2015-06-17 02:25:19 +08:00
|
|
|
ContentLayout* contentLayout;
|
2015-02-28 01:56:47 +08:00
|
|
|
AddFriendForm *addFriendForm;
|
2015-03-05 03:43:46 +08:00
|
|
|
ProfileForm *profileForm;
|
2015-02-28 01:56:47 +08:00
|
|
|
SettingsWidget *settingsWidget;
|
|
|
|
FilesForm *filesForm;
|
|
|
|
static Widget *instance;
|
|
|
|
GenericChatroomWidget *activeChatroomWidget;
|
|
|
|
FriendListWidget *contactListWidget;
|
|
|
|
MaskablePixmapWidget *profilePicture;
|
2014-07-03 14:43:23 +08:00
|
|
|
bool notify(QObject *receiver, QEvent *event);
|
2014-10-16 17:47:58 +08:00
|
|
|
bool autoAwayActive = false;
|
2015-02-28 01:56:47 +08:00
|
|
|
QTimer *timer, *offlineMsgTimer;
|
2015-01-23 01:43:44 +08:00
|
|
|
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;
|
2015-07-02 01:12:50 +08:00
|
|
|
|
|
|
|
#ifdef Q_OS_MAC
|
2015-07-30 07:46:19 +08:00
|
|
|
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
|
|
|
};
|
|
|
|
|
2015-02-20 20:26:41 +08:00
|
|
|
bool toxActivateEventHandler(const QByteArray& data);
|
2014-11-26 01:11:05 +08:00
|
|
|
|
2014-06-25 04:11:11 +08:00
|
|
|
#endif // WIDGET_H
|