Initial qml root window

This commit is contained in:
Nicolas Werner 2022-01-12 19:09:46 +01:00
parent 9a2e07cbce
commit b106eafb0e
No known key found for this signature in database
GPG key ID: C8D75E610773F2D9
21 changed files with 426 additions and 397 deletions

View file

@ -44,8 +44,8 @@ Q_DECLARE_METATYPE(mtx::presence::PresenceState)
Q_DECLARE_METATYPE(mtx::secret_storage::AesHmacSha2KeyDescription)
Q_DECLARE_METATYPE(SecretsToDecrypt)
ChatPage::ChatPage(QSharedPointer<UserSettings> userSettings, QWidget *parent)
: QWidget(parent)
ChatPage::ChatPage(QSharedPointer<UserSettings> userSettings, QObject *parent)
: QObject(parent)
, isConnected_(true)
, userSettings_{userSettings}
, notificationsManager(this)
@ -61,14 +61,8 @@ ChatPage::ChatPage(QSharedPointer<UserSettings> userSettings, QWidget *parent)
qRegisterMetaType<mtx::secret_storage::AesHmacSha2KeyDescription>();
qRegisterMetaType<SecretsToDecrypt>();
topLayout_ = new QHBoxLayout(this);
topLayout_->setSpacing(0);
topLayout_->setContentsMargins(0, 0, 0, 0);
view_manager_ = new TimelineViewManager(callManager_, this);
topLayout_->addWidget(view_manager_->getWidget());
connect(this,
&ChatPage::downloadedSecrets,
this,
@ -154,7 +148,7 @@ ChatPage::ChatPage(QSharedPointer<UserSettings> userSettings, QWidget *parent)
[this](const QString &roomid, const QString &eventid) {
Q_UNUSED(eventid)
view_manager_->rooms()->setCurrentRoom(roomid);
activateWindow();
MainWindow::instance()->requestActivate();
});
connect(&notificationsManager,
&NotificationsManager::sendNotificationReply,
@ -162,15 +156,13 @@ ChatPage::ChatPage(QSharedPointer<UserSettings> userSettings, QWidget *parent)
[this](const QString &roomid, const QString &eventid, const QString &body) {
view_manager_->rooms()->setCurrentRoom(roomid);
view_manager_->queueReply(roomid, eventid, body);
activateWindow();
MainWindow::instance()->requestActivate();
});
connect(QCoreApplication::instance(), &QCoreApplication::aboutToQuit, this, [this]() {
// ensure the qml context is shutdown before we destroy all other singletons
// Otherwise Qml will try to access the room list or settings, after they have been
// destroyed
topLayout_->removeWidget(view_manager_->getWidget());
delete view_manager_->getWidget();
});
connect(
@ -201,7 +193,7 @@ ChatPage::ChatPage(QSharedPointer<UserSettings> userSettings, QWidget *parent)
// TODO: Replace this once we have proper pushrules support. This is a horrible hack
if (prevNotificationCount < notificationCount) {
if (userSettings_->hasAlertOnNotification())
QApplication::alert(this);
MainWindow::instance()->alert(0);
}
prevNotificationCount = notificationCount;
@ -331,7 +323,7 @@ ChatPage::bootstrap(QString userid, QString homeserver, QString token)
} else if (cacheVersion == cache::CacheVersion::Older) {
if (!cache::runMigrations()) {
QMessageBox::critical(
this,
nullptr,
tr("Cache migration failed!"),
tr("Migrating the cache to the current version failed. "
"This can have different reasons. Please open an "
@ -344,7 +336,7 @@ ChatPage::bootstrap(QString userid, QString homeserver, QString token)
return;
} else if (cacheVersion == cache::CacheVersion::Newer) {
QMessageBox::critical(
this,
nullptr,
tr("Incompatible cache version"),
tr("The cache on your disk is newer than this version of Nheko "
"supports. Please update Nheko or clear your cache."));
@ -690,7 +682,7 @@ ChatPage::joinRoomVia(const std::string &room_id,
if (promptForConfirmation &&
QMessageBox::Yes !=
QMessageBox::question(
this,
nullptr,
tr("Confirm join"),
tr("Do you really want to join %1?").arg(QString::fromStdString(room_id))))
return;
@ -776,7 +768,7 @@ ChatPage::inviteUser(QString userid, QString reason)
{
auto room = currentRoom();
if (QMessageBox::question(this,
if (QMessageBox::question(nullptr,
tr("Confirm invite"),
tr("Do you really want to invite %1 (%2)?")
.arg(cache::displayName(room, userid), userid)) != QMessageBox::Yes)
@ -800,7 +792,7 @@ ChatPage::kickUser(QString userid, QString reason)
{
auto room = currentRoom();
if (QMessageBox::question(this,
if (QMessageBox::question(nullptr,
tr("Confirm kick"),
tr("Do you really want to kick %1 (%2)?")
.arg(cache::displayName(room, userid), userid)) != QMessageBox::Yes)
@ -825,7 +817,7 @@ ChatPage::banUser(QString userid, QString reason)
auto room = currentRoom();
if (QMessageBox::question(
this,
nullptr,
tr("Confirm ban"),
tr("Do you really want to ban %1 (%2)?").arg(cache::displayName(room, userid), userid)) !=
QMessageBox::Yes)
@ -849,7 +841,7 @@ ChatPage::unbanUser(QString userid, QString reason)
{
auto room = currentRoom();
if (QMessageBox::question(this,
if (QMessageBox::question(nullptr,
tr("Confirm unban"),
tr("Do you really want to unban %1 (%2)?")
.arg(cache::displayName(room, userid), userid)) != QMessageBox::Yes)
@ -1083,7 +1075,7 @@ ChatPage::decryptDownloadedSecrets(mtx::secret_storage::AesHmacSha2KeyDescriptio
const SecretsToDecrypt &secrets)
{
QString text = QInputDialog::getText(
ChatPage::instance(),
nullptr,
QCoreApplication::translate("CrossSigningSecrets", "Decrypt secrets"),
keyDesc.name.empty()
? QCoreApplication::translate(
@ -1115,7 +1107,7 @@ ChatPage::decryptDownloadedSecrets(mtx::secret_storage::AesHmacSha2KeyDescriptio
if (!decryptionKey) {
QMessageBox::information(
ChatPage::instance(),
nullptr,
QCoreApplication::translate("CrossSigningSecrets", "Decryption failed"),
QCoreApplication::translate("CrossSigningSecrets",
"Failed to decrypt secrets with the "
@ -1209,7 +1201,7 @@ ChatPage::startChat(QString userid)
if (QMessageBox::Yes !=
QMessageBox::question(
this,
nullptr,
tr("Confirm invite"),
tr("Do you really want to start a private chat with %1?").arg(userid)))
return;
@ -1395,7 +1387,7 @@ ChatPage::handleMatrixUri(const QUrl &uri)
bool
ChatPage::isRoomActive(const QString &room_id)
{
return isActiveWindow() && currentRoom() == room_id;
return MainWindow::instance()->isActive() && currentRoom() == room_id;
}
QString