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
onRoomAdded: setting.lazyLoad ? {} : room.getPreviousContent(20)
onNewMessage: trayIcon.showMessage("New message", "New message for room " + room.displayName)
onNewMessage: matriqueController.showMessage(roomName, content, icon)
}
RowLayout {

View File

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

View File

@ -30,13 +30,15 @@ Item {
id: searchField
width: parent.width - 18
height: 36
color: "black"
leftPadding: mini ? 4 : 16
color: "white"
leftPadding: mini ? 4 : 32
topPadding: 0
bottomPadding: 0
anchors.centerIn: parent
background: Row {
visible: !parent.text
MaterialIcon {
icon: "\ue8b6"
color: "white"
@ -55,17 +57,6 @@ Item {
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 QtGraphicalEffects 1.0
import Qt.labs.settings 1.0 as Settings
import Qt.labs.platform 1.0 as Platform
import Matrique 0.1
import "component"
@ -40,21 +39,6 @@ ApplicationWindow {
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 {
id: matriqueController
}
@ -87,7 +71,7 @@ ApplicationWindow {
parent: null
connection: window.connection
connection: matriqueController.isLogin ? window.connection : undefined
}
Setting {

View File

@ -8,8 +8,15 @@
#include "csapi/joining.h"
#include <QClipboard>
#include <QSystemTrayIcon>
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>();
connect(m_connection, &Connection::connected, this, &Controller::connected);
@ -102,3 +109,8 @@ void Controller::playAudio(QUrl localFile) {
player->play();
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 <QMediaPlayer>
#include <QObject>
#include <QSystemTrayIcon>
#include <QMenu>
using namespace QMatrixClient;
@ -78,6 +80,8 @@ class Controller : public QObject {
private:
QClipboard* m_clipboard = QApplication::clipboard();
QSystemTrayIcon* tray = new QSystemTrayIcon();
QMenu* trayMenu = new QMenu();
bool m_isLogin = false;
QString m_userID;
@ -104,6 +108,7 @@ class Controller : public QObject {
void createDirectChat(const QString& userID);
void copyToClipboard(const QString& text);
void playAudio(QUrl localFile);
void showMessage(const QString& title, const QString& msg, const QIcon& icon);
};
#endif // CONTROLLER_H

View File

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

View File

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

View File

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