Skip to content

Commit

Permalink
Modernize and clean up code across the board
Browse files Browse the repository at this point in the history
  • Loading branch information
KitsuneRal committed Oct 28, 2024
1 parent 8d25512 commit 14140d9
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 114 deletions.
2 changes: 1 addition & 1 deletion client/htmlfilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,7 @@ Processor::rewrite_t Processor::filterTag(QStringView tag,
continue;
if (ff[0] == '\'' || ff[0] == '"')
ff = ff.mid(1, ff.length() - 2);
if (QFontDatabase().isFixedPitch(ff.toString())) {
if (QFontDatabase::isFixedPitch(ff.toString())) {
rewrite.emplace_back().first = "code";
break;
}
Expand Down
28 changes: 13 additions & 15 deletions client/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,21 +145,19 @@ int main( int argc, char* argv[] )
// Extract a number from another macro and turn it to a const char[]
#define ITOA(i) #i

loadTranslations(
{ { { "qt", "qtbase", "qtnetwork", "qtdeclarative", "qtmultimedia",
"qtquickcontrols", "qtquickcontrols2",
// QtKeychain tries to install its translations to Qt's path;
// try to look there, just in case (see also below)
"qtkeychain" },
QLibraryInfo::location(QLibraryInfo::TranslationsPath) },
{ { "qtkeychain" },
QStandardPaths::locate(QStandardPaths::GenericDataLocation,
"qt" ITOA(QT_VERSION_MAJOR) "keychain/translations",
QStandardPaths::LocateDirectory) },
{ { "qt", "qtkeychain", "quotient", "quaternion" },
QStandardPaths::locate(QStandardPaths::AppLocalDataLocation,
"translations",
QStandardPaths::LocateDirectory) } });
loadTranslations({ { { "qt", "qtbase", "qtnetwork", "qtdeclarative", "qtmultimedia",
"qtquickcontrols", "qtquickcontrols2",
// QtKeychain tries to install its translations to Qt's path;
// try to look there, just in case (see also below)
"qtkeychain" },
QLibraryInfo::path(QLibraryInfo::TranslationsPath) },
{ { "qtkeychain" },
QStandardPaths::locate(QStandardPaths::GenericDataLocation,
"qt" ITOA(QT_VERSION_MAJOR) "keychain/translations",
QStandardPaths::LocateDirectory) },
{ { "qt", "qtkeychain", "quotient", "quaternion" },
QStandardPaths::locate(QStandardPaths::AppLocalDataLocation, "translations",
QStandardPaths::LocateDirectory) } });

#undef ITOA

Expand Down
11 changes: 5 additions & 6 deletions client/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ MainWindow::MainWindow()
MainWindow::~MainWindow()
{
saveSettings();
for (auto* acc: qAsConst(logoutOnExit))
for (auto* acc: std::as_const(logoutOnExit))
logout(acc);
accountRegistry->disconnect(this);
}
Expand Down Expand Up @@ -193,8 +193,8 @@ void MainWindow::createMenu()
static const auto quitShortcut = QSysInfo::productType() == "windows"
? QKeySequence(Qt::CTRL | Qt::Key_Q)
: QKeySequence::Quit;
connectionMenu->addAction(QIcon::fromTheme("application-exit"),
tr("&Quit"), qApp, &QApplication::quit, quitShortcut);
connectionMenu->addAction(QIcon::fromTheme("application-exit"), tr("&Quit"), quitShortcut, qApp,
&QApplication::quit);

// View menu
auto viewMenu = menuBar()->addMenu(tr("&View"));
Expand Down Expand Up @@ -347,9 +347,8 @@ void MainWindow::createMenu()
openRoomAction->setStatusTip(tr("Open a room from the room list"));
openRoomAction->setShortcut(QKeySequence::Open);
openRoomAction->setDisabled(true);
roomMenu->addAction(QIcon::fromTheme("window-close"),
tr("&Close current room"), [this] { selectRoom(nullptr); },
QKeySequence::Close);
roomMenu->addAction(QIcon::fromTheme("window-close"), tr("&Close current room"),
QKeySequence::Close, [this] { selectRoom(nullptr); });

// Settings menu
auto settingsMenu = menuBar()->addMenu(tr("&Settings"));
Expand Down
2 changes: 1 addition & 1 deletion client/models/messageeventmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -860,7 +860,7 @@ QVariant MessageEventModel::data(const QModelIndex& idx, int role) const
const auto& annotations =
m_currentRoom->relatedEvents(evt, EventRelation::AnnotationType);
for (const auto& a: annotations)
if (const auto e = eventCast<const ReactionEvent>(a)) {
if (const auto *const e = eventCast<const ReactionEvent>(a)) {
auto rIt = std::find_if(reactions.begin(), reactions.end(),
[&e] (const Reaction& r) {
return r.key == e->key();
Expand Down
3 changes: 1 addition & 2 deletions client/models/roomlistmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -490,8 +490,7 @@ QVariant RoomListModel::data(const QModelIndex& index, int role) const
for (const auto& m: directChatMembers)
userNames.push_back(m.htmlSafeDisplayName());
result += "<br>"
% tr("Direct chat with %1")
.arg(QLocale().createSeparatedList(userNames));
% tr("Direct chat with %1").arg(QLocale().createSeparatedList(userNames));
}

if (room->usesEncryption())
Expand Down
72 changes: 27 additions & 45 deletions client/qml/Timeline.qml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Quotient 1.0
Page {
id: root

property var room: messageModel ? messageModel.room : undefined
property Room room: messageModel?.room

readonly property Logger lc: Logger { }
TimelineSettings {
Expand Down Expand Up @@ -50,9 +50,8 @@ Page {
height: headerText.height
// implicitWidth on its own doesn't respect the scale down of
// the received image (that almost always happens)
width: Math.min(implicitHeight > 0
? headerText.height / implicitHeight * implicitWidth
: 0,
width: Math.min(implicitHeight > 0 ? headerText.height / implicitHeight * implicitWidth
: 0,
parent.width / 2.618) // Golden ratio - just for fun

// Safe upper limit (see also topicField)
Expand Down Expand Up @@ -87,7 +86,7 @@ Page {
font: roomName.font
elide: Text.ElideRight
elideWidth: headerText.width
text: room ? room.displayName : ""
text: room?.displayName ?? ""
}

text: roomNameMetrics.elidedText
Expand All @@ -110,10 +109,9 @@ Page {
width: parent.width
leftPadding: headerText.innerLeftPadding

text: !room ? "" :
room.successorId !== ""
? qsTr("This room has been upgraded.") :
room.isUnstable ? qsTr("Unstable room version!") : ""
text: room?.successorId !== "" ? qsTr("This room has been upgraded.")
: room?.isUnstable ? qsTr("Unstable room version!")
: ""
elide: Text.ElideRight
font.italic: true
renderType: settings.render_type
Expand Down Expand Up @@ -175,8 +173,7 @@ Page {
MouseArea {
anchors.fill: headerText
acceptedButtons: Qt.MiddleButton | Qt.RightButton
cursorShape: topicText.hoveredLink
? Qt.PointingHandCursor : Qt.IBeamCursor
cursorShape: topicText.hoveredLink ? Qt.PointingHandCursor : Qt.IBeamCursor

onClicked: (mouse) => {
if (topicText.hoveredLink)
Expand All @@ -188,8 +185,7 @@ Page {
Menu {
id: headerContextMenu
MenuItem {
text: roomHeader.showTopic ? qsTr("Hide topic")
: qsTr("Show topic")
text: roomHeader.showTopic ? qsTr("Hide topic") : qsTr("Show topic")
onTriggered: roomHeader.showTopic = !roomHeader.showTopic
}
}
Expand All @@ -201,8 +197,7 @@ Page {
anchors.verticalCenter: headerText.verticalCenter
anchors.right: parent.right
width: visible * implicitWidth
text: !room ? "" : room.successorId !== ""
? qsTr("Go to\nnew room") : qsTr("Room\nsettings")
text: room?.successorId !== "" ? qsTr("Go to\nnew room") : qsTr("Room\nsettings")

onClicked:
if (room.successorId !== "")
Expand Down Expand Up @@ -232,8 +227,7 @@ Page {

clip: true
ScrollBar.vertical: ScrollBar {
policy: settings.use_shuttle_dial ? ScrollBar.AlwaysOff
: ScrollBar.AsNeeded
policy: settings.use_shuttle_dial ? ScrollBar.AlwaysOff : ScrollBar.AsNeeded
interactive: true
active: true
// background: Item { /* TODO: timeline map */ }
Expand Down Expand Up @@ -276,10 +270,9 @@ Page {
return

// Take the current speed, or assume we can scroll 8 screens/s
var velocity = moving ? -verticalVelocity :
cruisingAnimation.running ?
cruisingAnimation.velocity :
chatView.height * 8
var velocity = moving ? -verticalVelocity
: cruisingAnimation.running ? cruisingAnimation.velocity
: chatView.height * 8
// Check if we're about to bump into the ceiling in
// 2 seconds and if yes, request the amount of messages
// enough to scroll at this rate for 3 more seconds
Expand Down Expand Up @@ -457,8 +450,7 @@ Page {
font.bold: true
opacity: 0.8
renderType: settings.render_type
text: chatView.underlayingItem ?
chatView.underlayingItem.ListView.section : ""
text: chatView.underlayingItem?.ListView.section ?? ""
}
}
}
Expand All @@ -471,27 +463,20 @@ Page {

// A proxy property for animation
property int requestedHistoryEventsCount: room?.requestedHistorySize ?? 0
AnimationBehavior on requestedHistoryEventsCount {
NormalNumberAnimation { }
}
AnimationBehavior on requestedHistoryEventsCount { NormalNumberAnimation { } }

property real averageEvtHeight:
chatView.count + requestedHistoryEventsCount > 0
? chatView.height
/ (chatView.count + requestedHistoryEventsCount)
: 0
AnimationBehavior on averageEvtHeight {
FastNumberAnimation { }
}
? chatView.height / (chatView.count + requestedHistoryEventsCount) : 0
AnimationBehavior on averageEvtHeight { FastNumberAnimation { } }

anchors.horizontalCenter: shuttleDial.horizontalCenter
anchors.bottom: chatView.bottom
anchors.bottomMargin:
averageEvtHeight * chatView.bottommostVisibleIndex
width: shuttleDial.backgroundWidth / 2
height: chatView.bottommostVisibleIndex < 0 ? 0 :
averageEvtHeight
* (chatView.count - chatView.bottommostVisibleIndex)
height: chatView.bottommostVisibleIndex < 0
? 0 : averageEvtHeight * (chatView.count - chatView.bottommostVisibleIndex)
visible: shuttleDial.visible

color: palette.mid
Expand Down Expand Up @@ -593,9 +578,8 @@ Page {
anchors.top: chatView.top
anchors.bottom: chatView.bottom
anchors.right: parent.right
width: settings.use_shuttle_dial
? shuttleDial.backgroundWidth
: chatView.ScrollBar.vertical.width
width: settings.use_shuttle_dial ? shuttleDial.backgroundWidth
: chatView.ScrollBar.vertical.width
acceptedButtons: Qt.NoButton

hoverEnabled: true
Expand All @@ -608,10 +592,9 @@ Page {
width: childrenRect.width + 3
height: childrenRect.height + 3
color: palette.alternateBase
property bool shown:
(chatView.bottommostVisibleIndex >= 0
&& (scrollerArea.containsMouse || scrollAnimation.running))
|| (room && room.requestedEventsCount > 0)
property bool shown: (chatView.bottommostVisibleIndex >= 0
&& (scrollerArea.containsMouse || scrollAnimation.running))
|| (room?.requestedHistorySize > 0)

onShownChanged: {
if (shown) {
Expand All @@ -635,9 +618,8 @@ Page {
text: (chatView.count > 0
? (chatView.bottommostVisibleIndex === 0
? qsTr("Latest events")
: qsTr("%Ln events back from now","",
chatView.bottommostVisibleIndex))
+ "\n" + qsTr("%Ln events cached", "", chatView.count)
: qsTr("%Ln events back from now","", chatView.bottommostVisibleIndex))
+ "\n" + qsTr("%Ln events cached", "", chatView.count)
: "")
+ (room?.requestedHistorySize > 0
? (chatView.count > 0 ? "\n" : "")
Expand Down
Loading

0 comments on commit 14140d9

Please sign in to comment.