Working notification.

Also, fixes #6.
This commit is contained in:
Black Hat 2018-08-19 14:32:18 +08:00
parent aa8f50a6c2
commit 4383dfa5a1
9 changed files with 45 additions and 51 deletions

View File

@ -16,7 +16,7 @@ Page {
connection: page.connection connection: page.connection
onRoomAdded: setting.lazyLoad ? {} : room.getPreviousContent(20) onRoomAdded: setting.lazyLoad ? {} : room.getPreviousContent(20)
onNewMessage: trayIcon.showMessage("New message", "New message for room " + room.displayName) onNewMessage: matriqueController.showMessage(roomName, content, icon)
} }
RowLayout { RowLayout {

View File

@ -318,6 +318,9 @@ Item {
bottomPadding: 0 bottomPadding: 0
selectByMouse: true selectByMouse: true
text: currentRoom ? currentRoom.cachedInput : ""
onTextChanged: currentRoom.cachedInput = text
Keys.onReturnPressed: { Keys.onReturnPressed: {
if (inputField.text) { if (inputField.text) {
inputField.postMessage(inputField.text) inputField.postMessage(inputField.text)

View File

@ -30,13 +30,15 @@ Item {
id: searchField id: searchField
width: parent.width - 18 width: parent.width - 18
height: 36 height: 36
color: "black" color: "white"
leftPadding: mini ? 4 : 16 leftPadding: mini ? 4 : 32
topPadding: 0 topPadding: 0
bottomPadding: 0 bottomPadding: 0
anchors.centerIn: parent anchors.centerIn: parent
background: Row { background: Row {
visible: !parent.text
MaterialIcon { MaterialIcon {
icon: "\ue8b6" icon: "\ue8b6"
color: "white" color: "white"
@ -55,17 +57,6 @@ Item {
verticalAlignment: Text.AlignVCenter verticalAlignment: Text.AlignVCenter
} }
} }
Rectangle {
z: -2
width: searchField.activeFocus || searchField.text ? parent.width : 0
height: parent.height
color: "white"
Behavior on width {
PropertyAnimation { easing.type: Easing.InOutCubic; duration: 200 }
}
}
} }
} }

View File

@ -4,7 +4,6 @@ import QtQuick.Layouts 1.3
import QtQuick.Controls.Material 2.2 import QtQuick.Controls.Material 2.2
import QtGraphicalEffects 1.0 import QtGraphicalEffects 1.0
import Qt.labs.settings 1.0 as Settings import Qt.labs.settings 1.0 as Settings
import Qt.labs.platform 1.0 as Platform
import Matrique 0.1 import Matrique 0.1
import "component" import "component"
@ -40,21 +39,6 @@ ApplicationWindow {
property alias miniMode: settingPage.miniMode property alias miniMode: settingPage.miniMode
} }
Platform.SystemTrayIcon {
id: trayIcon
visible: true
iconSource: "qrc:/asset/img/icon.png"
onActivated: window.active ? window.hide() : raiseWindow()
function raiseWindow() {
window.show()
window.raise()
window.requestActivate()
}
}
Controller { Controller {
id: matriqueController id: matriqueController
} }
@ -87,7 +71,7 @@ ApplicationWindow {
parent: null parent: null
connection: window.connection connection: matriqueController.isLogin ? window.connection : undefined
} }
Setting { Setting {

View File

@ -8,8 +8,15 @@
#include "csapi/joining.h" #include "csapi/joining.h"
#include <QClipboard> #include <QClipboard>
#include <QSystemTrayIcon>
Controller::Controller(QObject* parent) : QObject(parent) { Controller::Controller(QObject* parent) : QObject(parent) {
tray->setIcon(QIcon(":/asset/img/icon.png"));
tray->setToolTip("Matrique");
trayMenu->addAction("Quit", [=] { QApplication::quit(); });
tray->setContextMenu(trayMenu);
tray->show();
Connection::setRoomType<MatriqueRoom>(); Connection::setRoomType<MatriqueRoom>();
connect(m_connection, &Connection::connected, this, &Controller::connected); connect(m_connection, &Connection::connected, this, &Controller::connected);
@ -102,3 +109,8 @@ void Controller::playAudio(QUrl localFile) {
player->play(); player->play();
connect(player, &QMediaPlayer::stateChanged, [=] { player->deleteLater(); }); connect(player, &QMediaPlayer::stateChanged, [=] { player->deleteLater(); });
} }
void Controller::showMessage(const QString& title, const QString& msg,
const QIcon& icon) {
tray->showMessage(title, msg, icon);
}

View File

@ -7,6 +7,8 @@
#include <QApplication> #include <QApplication>
#include <QMediaPlayer> #include <QMediaPlayer>
#include <QObject> #include <QObject>
#include <QSystemTrayIcon>
#include <QMenu>
using namespace QMatrixClient; using namespace QMatrixClient;
@ -78,6 +80,8 @@ class Controller : public QObject {
private: private:
QClipboard* m_clipboard = QApplication::clipboard(); QClipboard* m_clipboard = QApplication::clipboard();
QSystemTrayIcon* tray = new QSystemTrayIcon();
QMenu* trayMenu = new QMenu();
bool m_isLogin = false; bool m_isLogin = false;
QString m_userID; QString m_userID;
@ -104,6 +108,7 @@ class Controller : public QObject {
void createDirectChat(const QString& userID); void createDirectChat(const QString& userID);
void copyToClipboard(const QString& text); void copyToClipboard(const QString& text);
void playAudio(QUrl localFile); void playAudio(QUrl localFile);
void showMessage(const QString& title, const QString& msg, const QIcon& icon);
}; };
#endif // CONTROLLER_H #endif // CONTROLLER_H

View File

@ -24,7 +24,7 @@ class MatriqueRoom : public Room {
} }
private: private:
QString m_cachedInput = ""; QString m_cachedInput;
QString getMIME(const QUrl& fileUrl) const; QString getMIME(const QUrl& fileUrl) const;
void postFile(const QUrl& localFile, const QUrl& mxcUrl); void postFile(const QUrl& localFile, const QUrl& mxcUrl);

View File

@ -1,5 +1,7 @@
#include "roomlistmodel.h" #include "roomlistmodel.h"
#include "user.h"
#include "events/roomevent.h" #include "events/roomevent.h"
#include <QtCore/QDebug> #include <QtCore/QDebug>
@ -14,10 +16,12 @@ RoomListModel::~RoomListModel() {}
void RoomListModel::setConnection(Connection* connection) { void RoomListModel::setConnection(Connection* connection) {
Q_ASSERT(connection); Q_ASSERT(connection);
if (connection == m_connection) return;
using QMatrixClient::Room; using QMatrixClient::Room;
m_connection = connection; m_connection = connection;
if (!connection->accessToken().isEmpty()) doResetModel(); doResetModel();
connect(connection, &Connection::connected, this, connect(connection, &Connection::connected, this,
&RoomListModel::doResetModel); &RoomListModel::doResetModel);
@ -43,7 +47,6 @@ void RoomListModel::doAddRoom(Room* r) {
if (auto* room = static_cast<MatriqueRoom*>(r)) { if (auto* room = static_cast<MatriqueRoom*>(r)) {
m_rooms.append(room); m_rooms.append(room);
connectRoomSignals(room); connectRoomSignals(room);
// qCritical() << room->cachedInput();
emit roomAdded(room); emit roomAdded(room);
} else { } else {
qCritical() << "Attempt to add nullptr to the room list"; qCritical() << "Attempt to add nullptr to the room list";
@ -61,21 +64,16 @@ void RoomListModel::connectRoomSignals(MatriqueRoom* room) {
connect(room, &Room::joinStateChanged, this, [=] { refresh(room); }); connect(room, &Room::joinStateChanged, this, [=] { refresh(room); });
connect(room, &Room::avatarChanged, this, connect(room, &Room::avatarChanged, this,
[=] { refresh(room, {AvatarRole}); }); [=] { refresh(room, {AvatarRole}); });
connect(room, &QMatrixClient::Room::aboutToAddNewMessages, this,
connect(room, &Room::unreadMessagesChanged, this, [=](Room* r) { [=](QMatrixClient::RoomEventsRange eventsRange) {
if (r->hasUnreadMessages()) emit newMessage(static_cast<MatriqueRoom*>(r)); RoomEvent* event = (eventsRange.end() - 1)->get();
}); User* sender = room->user(event->senderId());
// connect( if (sender == room->localUser()) return;
// room, &QMatrixClient::Room::aboutToAddNewMessages, this, emit newMessage(room->displayName(),
// [=](QMatrixClient::RoomEventsRange eventsRange) { sender->displayname() + ": " +
// for (QMatrixClient::RoomEvents events : eventsRange.const_iterator) event->contentJson().value("body").toString(),
// { QPixmap::fromImage(room->avatar(64)));
// for (QMatrixClient::RoomEvent event : events) { });
// qDebug() << event.fullJson();
// }
// }
// emit newMessage(room);
// });
} }
void RoomListModel::updateRoom(Room* room, Room* prev) { void RoomListModel::updateRoom(Room* room, Room* prev) {

View File

@ -2,8 +2,9 @@
#define ROOMLISTMODEL_H #define ROOMLISTMODEL_H
#include "connection.h" #include "connection.h"
#include "room.h" #include "events/roomevent.h"
#include "matriqueroom.h" #include "matriqueroom.h"
#include "room.h"
#include <QtCore/QAbstractListModel> #include <QtCore/QAbstractListModel>
@ -69,7 +70,7 @@ class RoomListModel : public QAbstractListModel {
signals: signals:
void connectionChanged(); void connectionChanged();
void roomAdded(MatriqueRoom* room); void roomAdded(MatriqueRoom* room);
void newMessage(MatriqueRoom* room); void newMessage(const QString& roomName, const QString& content, const QIcon& icon);
}; };
#endif // ROOMLISTMODEL_H #endif // ROOMLISTMODEL_H