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
bb600dd3
Verified
Commit
bb600dd3
authored
3 years ago
by
Nicolas Werner
Browse files
Options
Downloads
Patches
Plain Diff
Show some avatar for image packs
parent
dae03217
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Pipeline
#2277
passed
3 years ago
Stage: build
Stage: deploy
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
resources/qml/dialogs/ImagePackEditorDialog.qml
+21
-0
21 additions, 0 deletions
resources/qml/dialogs/ImagePackEditorDialog.qml
src/SingleImagePackModel.cpp
+44
-0
44 additions, 0 deletions
src/SingleImagePackModel.cpp
src/SingleImagePackModel.h
+3
-1
3 additions, 1 deletion
src/SingleImagePackModel.h
with
68 additions
and
1 deletion
resources/qml/dialogs/ImagePackEditorDialog.qml
+
21
−
0
View file @
bb600dd3
...
...
@@ -148,6 +148,27 @@ ApplicationWindow {
width
:
130
crop
:
false
Layout.alignment
:
Qt
.
AlignHCenter
ImageButton
{
hoverEnabled
:
true
ToolTip.visible
:
hovered
ToolTip.text
:
qsTr
(
"
Change the overview image for this pack
"
)
anchors.left
:
parent
.
left
anchors.top
:
parent
.
top
anchors.leftMargin
:
Nheko
.
paddingMedium
anchors.topMargin
:
Nheko
.
paddingMedium
image
:
"
:/icons/icons/ui/edit.svg
"
onClicked
:
addAvatarDialog
.
open
()
FileDialog
{
id
:
addAvatarDialog
folder
:
StandardPaths
.
writableLocation
(
StandardPaths
.
PicturesLocation
)
fileMode
:
FileDialog
.
OpenFile
nameFilters
:
[
qsTr
(
"
Overview Image (*.png *.webp *.jpg *.jpeg)
"
)]
onAccepted
:
imagePack
.
setAvatar
(
file
)
}
}
}
MatrixText
{
...
...
This diff is collapsed.
Click to expand it.
src/SingleImagePackModel.cpp
+
44
−
0
View file @
bb600dd3
...
...
@@ -33,6 +33,7 @@ SingleImagePackModel::SingleImagePackModel(ImagePackInfo pack_, QObject *parent)
shortcodes
.
push_back
(
e
.
first
);
connect
(
this
,
&
SingleImagePackModel
::
addImage
,
this
,
&
SingleImagePackModel
::
addImageCb
);
connect
(
this
,
&
SingleImagePackModel
::
avatarUploaded
,
this
,
&
SingleImagePackModel
::
setAvatarUrl
);
}
int
...
...
@@ -215,6 +216,17 @@ SingleImagePackModel::setAvatarUrl(QString val)
}
}
QString
SingleImagePackModel
::
avatarUrl
()
const
{
if
(
!
pack
.
pack
->
avatar_url
.
empty
())
return
QString
::
fromStdString
(
pack
.
pack
->
avatar_url
);
else
if
(
!
pack
.
images
.
empty
())
return
QString
::
fromStdString
(
pack
.
images
.
begin
()
->
second
.
url
);
else
return
""
;
}
void
SingleImagePackModel
::
setStatekey
(
QString
val
)
{
...
...
@@ -331,6 +343,35 @@ SingleImagePackModel::addStickers(QList<QUrl> files)
}
}
void
SingleImagePackModel
::
setAvatar
(
QUrl
f
)
{
auto
file
=
QFile
(
f
.
toLocalFile
());
if
(
!
file
.
open
(
QFile
::
ReadOnly
))
{
ChatPage
::
instance
()
->
showNotification
(
tr
(
"Failed to open image: %1"
).
arg
(
f
.
toLocalFile
()));
return
;
}
auto
bytes
=
file
.
readAll
();
auto
img
=
utils
::
readImage
(
bytes
);
auto
filename
=
f
.
fileName
().
toStdString
();
http
::
client
()
->
upload
(
bytes
.
toStdString
(),
QMimeDatabase
().
mimeTypeForFile
(
f
.
toLocalFile
()).
name
().
toStdString
(),
filename
,
[
this
,
filename
](
const
mtx
::
responses
::
ContentURI
&
uri
,
mtx
::
http
::
RequestErr
e
)
{
if
(
e
)
{
ChatPage
::
instance
()
->
showNotification
(
tr
(
"Failed to upload image: %1"
)
.
arg
(
QString
::
fromStdString
(
e
->
matrix_error
.
error
)));
return
;
}
emit
avatarUploaded
(
QString
::
fromStdString
(
uri
.
content_uri
));
});
}
void
SingleImagePackModel
::
remove
(
int
idx
)
{
...
...
@@ -356,4 +397,7 @@ SingleImagePackModel::addImageCb(std::string uri, std::string filename, mtx::com
shortcodes
.
push_back
(
filename
);
endInsertRows
();
if
(
this
->
pack
.
pack
->
avatar_url
.
empty
())
this
->
setAvatarUrl
(
QString
::
fromStdString
(
uri
));
}
This diff is collapsed.
Click to expand it.
src/SingleImagePackModel.h
+
3
−
1
View file @
bb600dd3
...
...
@@ -49,7 +49,7 @@ public:
QString
statekey
()
const
{
return
QString
::
fromStdString
(
statekey_
);
}
QString
packname
()
const
{
return
QString
::
fromStdString
(
pack
.
pack
->
display_name
);
}
QString
attribution
()
const
{
return
QString
::
fromStdString
(
pack
.
pack
->
attribution
);
}
QString
avatarUrl
()
const
{
return
QString
::
fromStdString
(
pack
.
pack
->
avatar_url
);
}
QString
avatarUrl
()
const
;
bool
isStickerPack
()
const
{
return
pack
.
pack
->
is_sticker
();
}
bool
isEmotePack
()
const
{
return
pack
.
pack
->
is_emoji
();
}
...
...
@@ -67,6 +67,7 @@ public:
Q_INVOKABLE
void
save
();
Q_INVOKABLE
void
addStickers
(
QList
<
QUrl
>
files
);
Q_INVOKABLE
void
remove
(
int
index
);
Q_INVOKABLE
void
setAvatar
(
QUrl
file
);
signals
:
void
globallyEnabledChanged
();
...
...
@@ -78,6 +79,7 @@ signals:
void
isStickerPackChanged
();
void
addImage
(
std
::
string
uri
,
std
::
string
filename
,
mtx
::
common
::
ImageInfo
info
);
void
avatarUploaded
(
QString
uri
);
private
slots
:
void
addImageCb
(
std
::
string
uri
,
std
::
string
filename
,
mtx
::
common
::
ImageInfo
info
);
...
...
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