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

179 lines
5.9 KiB
C
Raw Normal View History

2014-07-07 00:19:45 +08:00
/*
Copyright (C) 2014 by Project Tox <https://tox.im>
This file is part of qTox, a Qt-based graphical interface for Tox.
This program 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.
This program 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 COPYING file for more details.
*/
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 <QMessageBox>
#include <QFileInfo>
2014-10-08 12:26:25 +08:00
#include "form/addfriendform.h"
#include "form/settingswidget.h"
#include "form/settings/identityform.h"
#include "form/filesform.h"
#include "src/corestructs.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;
2014-06-25 04:11:11 +08:00
class Group;
2014-07-01 04:52:03 +08:00
struct 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 QTranslator;
class SystemTrayIcon;
2014-06-25 04:11:11 +08:00
class Widget : public QMainWindow
2014-06-25 04:11:11 +08:00
{
Q_OBJECT
public:
explicit Widget(QWidget *parent = 0);
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 newMessageAlert(GenericChatroomWidget* chat);
2014-07-01 03:14:51 +08:00
bool isFriendWidgetCurActiveWidget(Friend* f);
bool getIsWindowMinimized();
void clearContactsList();
void setTranslation();
void updateTrayIcon();
2014-06-25 04:11:11 +08:00
~Widget();
virtual void closeEvent(QCloseEvent *event);
2014-10-20 19:50:12 +08:00
virtual void changeEvent(QEvent *event);
virtual void resizeEvent(QResizeEvent *event);
static bool 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();
public slots:
void onSettingsClicked();
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());
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 onFriendMessageReceived(int friendId, const QString& message, bool isAction);
2014-06-25 04:11:11 +08:00
void onFriendRequestReceived(const QString& userId, const QString& message);
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);
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 playRingtone();
void onFriendTypingChanged(int friendId, bool isTyping);
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 changeProfile(const QString& profile);
void resized();
private slots:
void onAddClicked();
void onGroupClicked();
void onTransferClicked();
void onAvatarClicked();
void onUsernameChanged(const QString& newUsername, const QString& oldUsername);
void onStatusMessageChanged(const QString& newStatusMessage, const QString& oldStatusMessage);
void onChatroomWidgetClicked(GenericChatroomWidget *);
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();
void onMessageSendResult(int friendId, const QString& message, int messageId);
void onGroupSendResult(int groupId, const QString& message, int result);
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 onSetShowSystemTray(bool newValue);
void onSplitterMoved(int pos, int index);
void processOfflineMsgs();
2014-06-25 04:11:11 +08:00
private:
void hideMainForms();
virtual bool event(QEvent * e);
2014-06-25 04:11:11 +08:00
Group* createGroup(int groupId);
void removeFriend(Friend* f, bool fake = false);
void removeGroup(Group* g, bool fake = false);
void saveWindowGeometry();
void saveSplitterGeometry();
SystemTrayIcon *icon;
2014-10-21 02:03:44 +08:00
QMenu *trayMenu;
QAction *statusOnline,
*statusAway,
*statusBusy,
*actionQuit;
2014-06-25 04:11:11 +08:00
Ui::MainWindow *ui;
QSplitter *centralLayout;
QPoint dragPosition;
AddFriendForm* addFriendForm;
SettingsWidget* settingsWidget;
FilesForm* filesForm;
2014-06-25 04:11:11 +08:00
static Widget* instance;
GenericChatroomWidget* activeChatroomWidget;
2014-08-22 23:19:16 +08:00
FriendListWidget* contactListWidget;
MaskablePixmapWidget* profilePicture;
bool notify(QObject *receiver, QEvent *event);
2014-10-16 17:47:58 +08:00
bool autoAwayActive = false;
Status beforeDisconnect = Status::Offline;
QTimer* timer, *offlineMsgTimer;
QTranslator* translator;
QRegExp nameMention, sanitizedNameMention;
2014-12-12 00:49:11 +08:00
bool eventFlag;
bool eventIcon;
2014-06-25 04:11:11 +08:00
};
void toxActivateEventHandler(const QByteArray& data);
2014-06-25 04:11:11 +08:00
#endif // WIDGET_H