Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
nheko
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Nheko Reborn
nheko
Commits
45e91a7e
Unverified
Commit
45e91a7e
authored
4 years ago
by
Nicolas Werner
Committed by
GitHub
4 years ago
Browse files
Options
Downloads
Plain Diff
Merge pull request #334 from Kirillpt/issue_292
fix #292
parents
40a48710
d13a1c64
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
src/LoginPage.cpp
+55
-7
55 additions, 7 deletions
src/LoginPage.cpp
src/LoginPage.h
+2
-0
2 additions, 0 deletions
src/LoginPage.h
src/ui/TextField.cpp
+13
-1
13 additions, 1 deletion
src/ui/TextField.cpp
src/ui/TextField.h
+3
-0
3 additions, 0 deletions
src/ui/TextField.h
with
73 additions
and
8 deletions
src/LoginPage.cpp
+
55
−
7
View file @
45e91a7e
...
...
@@ -16,9 +16,11 @@
*/
#include
<QDesktopServices>
#include
<QFontMetrics>
#include
<QLabel>
#include
<QPainter>
#include
<QStyleOption>
#include
<QtMath>
#include
<mtx/identifiers.hpp>
#include
<mtx/requests.hpp>
...
...
@@ -95,8 +97,6 @@ LoginPage::LoginPage(QWidget *parent)
"address there, if your server doesn't support .well-known lookup.
\n
Example: "
"@user:server.my
\n
If Nheko fails to discover your homeserver, it will show you a "
"field to enter the server manually."
));
matrixid_input_
->
setValidator
(
new
QRegularExpressionValidator
(
QRegularExpression
(
"@.+?:.{3,}"
),
this
));
spinner_
=
new
LoadingIndicator
(
this
);
spinner_
->
setFixedHeight
(
40
);
...
...
@@ -110,6 +110,12 @@ LoginPage::LoginPage(QWidget *parent)
matrixidLayout_
=
new
QHBoxLayout
();
matrixidLayout_
->
addWidget
(
matrixid_input_
,
0
,
Qt
::
AlignVCenter
);
QFont
font
;
error_matrixid_label_
=
new
QLabel
(
this
);
error_matrixid_label_
->
setFont
(
font
);
error_matrixid_label_
->
setWordWrap
(
true
);
password_input_
=
new
TextField
(
this
);
password_input_
->
setLabel
(
tr
(
"Password"
));
password_input_
->
setEchoMode
(
QLineEdit
::
Password
);
...
...
@@ -132,10 +138,13 @@ LoginPage::LoginPage(QWidget *parent)
serverLayout_
->
addWidget
(
serverInput_
,
0
,
Qt
::
AlignVCenter
);
form_layout_
->
addLayout
(
matrixidLayout_
);
form_layout_
->
addWidget
(
error_matrixid_label_
,
0
,
Qt
::
AlignHCenter
);
form_layout_
->
addWidget
(
password_input_
);
form_layout_
->
addWidget
(
deviceName_
,
Qt
::
AlignHCenter
);
form_layout_
->
addLayout
(
serverLayout_
);
error_matrixid_label_
->
hide
();
button_layout_
=
new
QHBoxLayout
();
button_layout_
->
setSpacing
(
0
);
button_layout_
->
setContentsMargins
(
0
,
0
,
0
,
30
);
...
...
@@ -149,8 +158,6 @@ LoginPage::LoginPage(QWidget *parent)
button_layout_
->
addWidget
(
login_button_
);
button_layout_
->
addStretch
(
1
);
QFont
font
;
error_label_
=
new
QLabel
(
this
);
error_label_
->
setFont
(
font
);
error_label_
->
setWordWrap
(
true
);
...
...
@@ -183,9 +190,30 @@ LoginPage::LoginPage(QWidget *parent)
void
LoginPage
::
loginError
(
const
QString
&
msg
)
{
auto
rect
=
QFontMetrics
(
font
()).
boundingRect
(
msg
);
int
width
=
rect
.
width
();
int
height
=
rect
.
height
();
error_label_
->
setFixedHeight
(
qCeil
(
width
/
200
)
*
height
);
error_label_
->
setText
(
msg
);
}
void
LoginPage
::
matrixIdError
(
const
QString
&
msg
)
{
error_matrixid_label_
->
show
();
error_matrixid_label_
->
setText
(
msg
);
matrixid_input_
->
setValid
(
false
);
}
bool
LoginPage
::
isMatrixIdValid
()
{
QRegularExpressionValidator
v
(
QRegularExpression
(
"@.+?:.{3,}"
),
this
);
QString
s
=
matrixid_input_
->
text
();
int
pos
=
0
;
return
v
.
validate
(
s
,
pos
)
==
QValidator
::
Acceptable
;
}
void
LoginPage
::
onMatrixIdEntered
()
{
...
...
@@ -193,10 +221,20 @@ LoginPage::onMatrixIdEntered()
User
user
;
if
(
!
isMatrixIdValid
())
{
matrixIdError
(
"You have entered an invalid Matrix ID e.g @joe:matrix.org"
);
return
;
}
else
{
error_matrixid_label_
->
setText
(
""
);
error_matrixid_label_
->
hide
();
matrixid_input_
->
setValid
(
true
);
}
try
{
user
=
parse
<
User
>
(
matrixid_input_
->
text
().
toStdString
());
}
catch
(
const
std
::
exception
&
e
)
{
return
loginError
(
"You have entered an invalid Matrix ID e.g @joe:matrix.org"
);
matrixIdError
(
"You have entered an invalid Matrix ID e.g @joe:matrix.org"
);
return
;
}
QString
homeServer
=
QString
::
fromStdString
(
user
.
hostname
());
...
...
@@ -307,7 +345,7 @@ LoginPage::onServerAddressEntered()
void
LoginPage
::
versionError
(
const
QString
&
error
)
{
error_label_
->
setText
(
error
);
loginError
(
error
);
serverInput_
->
show
();
spinner_
->
stop
();
...
...
@@ -345,10 +383,20 @@ LoginPage::onLoginButtonClicked()
User
user
;
if
(
!
isMatrixIdValid
())
{
matrixIdError
(
"You have entered an invalid Matrix ID e.g @joe:matrix.org"
);
return
;
}
else
{
error_matrixid_label_
->
setText
(
""
);
error_matrixid_label_
->
hide
();
matrixid_input_
->
setValid
(
true
);
}
try
{
user
=
parse
<
User
>
(
matrixid_input_
->
text
().
toStdString
());
}
catch
(
const
std
::
exception
&
e
)
{
return
loginError
(
"You have entered an invalid Matrix ID e.g @joe:matrix.org"
);
matrixIdError
(
"You have entered an invalid Matrix ID e.g @joe:matrix.org"
);
return
;
}
if
(
loginMethod
==
LoginMethod
::
Password
)
{
...
...
This diff is collapsed.
Click to expand it.
src/LoginPage.h
+
2
−
0
View file @
45e91a7e
...
...
@@ -67,6 +67,7 @@ protected:
public
slots
:
// Displays errors produced during the login.
void
loginError
(
const
QString
&
msg
);
void
matrixIdError
(
const
QString
&
msg
);
private
slots
:
// Callback for the back button.
...
...
@@ -112,6 +113,7 @@ private:
QLabel
*
logo_
;
QLabel
*
error_label_
;
QLabel
*
error_matrixid_label_
;
QHBoxLayout
*
serverLayout_
;
QHBoxLayout
*
matrixidLayout_
;
...
...
This diff is collapsed.
Click to expand it.
src/ui/TextField.cpp
+
13
−
1
View file @
45e91a7e
...
...
@@ -69,6 +69,18 @@ TextField::hasLabel() const
return
show_label_
;
}
bool
TextField
::
isValid
()
const
{
return
is_valid_
;
}
void
TextField
::
setValid
(
bool
valid
)
{
is_valid_
=
valid
;
}
void
TextField
::
setLabelFontSize
(
qreal
size
)
{
...
...
@@ -147,7 +159,7 @@ QColor
TextField
::
underlineColor
()
const
{
if
(
!
underline_color_
.
isValid
())
{
if
(
hasAcceptableInput
()
||
!
isModified
())
if
(
(
hasAcceptableInput
()
&&
isValid
())
||
!
isModified
())
return
QPalette
().
color
(
QPalette
::
Highlight
);
else
return
Qt
::
red
;
...
...
This diff is collapsed.
Click to expand it.
src/ui/TextField.h
+
3
−
0
View file @
45e91a7e
...
...
@@ -30,6 +30,7 @@ public:
void
setLabelFontSize
(
qreal
size
);
void
setShowLabel
(
bool
value
);
void
setUnderlineColor
(
const
QColor
&
color
);
void
setValid
(
bool
valid
);
QColor
inkColor
()
const
;
QColor
labelColor
()
const
;
...
...
@@ -37,6 +38,7 @@ public:
QColor
backgroundColor
()
const
;
QString
label
()
const
;
bool
hasLabel
()
const
;
bool
isValid
()
const
;
qreal
labelFontSize
()
const
;
protected:
...
...
@@ -54,6 +56,7 @@ private:
TextFieldLabel
*
label_
;
TextFieldStateMachine
*
state_machine_
;
bool
show_label_
;
bool
is_valid_
;
qreal
label_font_size_
;
};
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment