Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
X
ximper-shell-notification-center
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Ximper Linux
ximper-shell-notification-center
Commits
b8ef6181
Unverified
Commit
b8ef6181
authored
May 14, 2023
by
Erik Reider
Committed by
GitHub
May 14, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Replace config HashTable with OrderedHashTable (#258)
parent
9b3c147e
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
71 additions
and
28 deletions
+71
-28
configModel.vala
src/configModel/configModel.vala
+27
-24
baseWidget.vala
src/controlCenter/widgets/baseWidget.vala
+1
-1
meson.build
src/meson.build
+1
-0
notiDaemon.vala
src/notiDaemon/notiDaemon.vala
+4
-3
orderedHashTable.vala
src/orderedHashTable/orderedHashTable.vala
+38
-0
No files found.
src/configModel/configModel.vala
View file @
b8ef6181
...
...
@@ -479,26 +479,28 @@ namespace SwayNotificationCenter {
}
/** Categories settings */
public
HashTable
<
string
,
Category
>
categories_settings
{
public
OrderedHashTable
<
Category
>
categories_settings
{
get
;
set
;
default
=
new
HashTable
<
string
,
Category
>
(
str_hash
,
str_equal
);
default
=
new
OrderedHashTable
<
Category
>
(
);
}
/** Notification Status */
public
HashTable
<
string
,
NotificationVisibility
>
notification_visibility
{
public
OrderedHashTable
<
NotificationVisibility
>
notification_visibility
{
get
;
set
;
default
=
new
HashTable
<
string
,
NotificationVisibility
>
(
str_hash
,
str_equal
);
default
=
new
OrderedHashTable
<
NotificationVisibility
>
(
);
}
#if WANT_SCRIPTING
/** Scripts */
public
HashTable
<
string
,
Script
>
scripts
{
public
OrderedHashTable
<
Script
>
scripts
{
get
;
set
;
default
=
new
HashTable
<
string
,
Script
>
(
str_hash
,
str_equal
);
default
=
new
OrderedHashTable
<
Script
>
(
);
}
/** Show notification if script fails */
public
bool
script_fail_notify
{
get
;
set
;
default
=
true
;
}
#endif
...
...
@@ -597,12 +599,13 @@ namespace SwayNotificationCenter {
}
/** Widgets to show in ControlCenter */
public
HashTable
<
string
,
Json
.
Object
>
widget_config
{
public
OrderedHashTable
<
Json
.
Object
>
widget_config
{
get
;
set
;
default
=
new
HashTable
<
string
,
Json
.
Object
>
(
str_hash
,
str_equal
);
default
=
new
OrderedHashTable
<
Json
.
Object
>
(
);
}
/* Methods */
/**
...
...
@@ -617,7 +620,7 @@ namespace SwayNotificationCenter {
switch
(
property_name
)
{
case
"categories-settings"
:
bool
status
;
HashTable
<
string
,
Category
>
result
=
OrderedHashTable
<
Category
>
result
=
extract_hashtable
<
Category
>
(
property_name
,
property_node
,
...
...
@@ -626,7 +629,7 @@ namespace SwayNotificationCenter {
return
status
;
case
"notification-visibility"
:
bool
status
;
HashTable
<
string
,
NotificationVisibility
>
result
=
OrderedHashTable
<
NotificationVisibility
>
result
=
extract_hashtable
<
NotificationVisibility
>
(
property_name
,
property_node
,
...
...
@@ -636,7 +639,7 @@ namespace SwayNotificationCenter {
#if WANT_SCRIPTING
case
"scripts"
:
bool
status
;
HashTable
<
string
,
Script
>
result
=
OrderedHashTable
<
Script
>
result
=
extract_hashtable
<
Script
>
(
property_name
,
property_node
,
...
...
@@ -653,8 +656,8 @@ namespace SwayNotificationCenter {
value
=
result
;
return
status
;
case
"widget-config"
:
HashTable
<
string
,
Json
.
Object
>
result
=
new
HashTable
<
string
,
Json
.
Object
>
(
str_hash
,
str_equal
);
OrderedHashTable
<
Json
.
Object
>
result
=
new
OrderedHashTable
<
Json
.
Object
>
(
);
if
(
property_node
.
get_value_type
().
name
()
!=
"JsonObject"
)
{
value
=
result
;
return
true
;
...
...
@@ -668,7 +671,7 @@ namespace SwayNotificationCenter {
Json
.
Node
?
node
=
obj
.
get_member
(
key
);
if
(
node
.
get_node_type
()
!=
Json
.
NodeType
.
OBJECT
)
continue
;
Json
.
Object
?
o
=
node
.
get_object
();
if
(
o
!=
null
)
result
.
se
t
(
key
,
o
);
if
(
o
!=
null
)
result
.
inser
t
(
key
,
o
);
}
value
=
result
;
return
true
;
...
...
@@ -701,29 +704,29 @@ namespace SwayNotificationCenter {
switch
(
property_name
)
{
case
"categories-settings"
:
node
=
new
Json
.
Node
(
Json
.
NodeType
.
OBJECT
);
var
table
=
(
HashTable
<
string
,
Category
>)
value
.
get_boxed
()
;
var
table
=
(
OrderedHashTable
<
Category
>)
value
;
node
.
set_object
(
serialize_hashtable
<
Category
>
(
table
));
break
;
case
"notification-visibility"
:
node
=
new
Json
.
Node
(
Json
.
NodeType
.
OBJECT
);
var
table
=
(
HashTable
<
string
,
NotificationVisibility
>)
value
.
get_boxed
()
;
var
table
=
(
OrderedHashTable
<
NotificationVisibility
>)
value
;
node
.
set_object
(
serialize_hashtable
<
NotificationVisibility
>
(
table
));
break
;
#if WANT_SCRIPTING
case
"scripts"
:
node
=
new
Json
.
Node
(
Json
.
NodeType
.
OBJECT
);
var
table
=
(
HashTable
<
string
,
Script
>)
value
.
get_boxed
()
;
var
table
=
(
OrderedHashTable
<
Script
>)
value
;
node
.
set_object
(
serialize_hashtable
<
Script
>
(
table
));
break
;
#endif
case
"widgets"
:
node
=
new
Json
.
Node
(
Json
.
NodeType
.
ARRAY
);
var
table
=
(
GenericArray
<
string
>)
value
.
get_boxed
()
;
var
table
=
(
GenericArray
<
string
>)
value
;
node
.
set_array
(
serialize_array
<
string
>
(
table
));
break
;
case
"widget-config"
:
node
=
new
Json
.
Node
(
Json
.
NodeType
.
OBJECT
);
var
table
=
(
HashTable
<
string
,
Json
.
Object
>)
value
.
get_boxed
()
;
var
table
=
(
OrderedHashTable
<
Json
.
Object
>)
value
;
node
.
set_object
(
serialize_hashtable
<
Json
.
Object
>
(
table
));
break
;
default
:
...
...
@@ -739,7 +742,7 @@ namespace SwayNotificationCenter {
}
/**
* Extracts and returns a
HashTable<string,
GLib.Object>
* Extracts and returns a
OrderedHashTable<
GLib.Object>
* from a nested JSON Object.
*
* Can only accept these types:
...
...
@@ -748,11 +751,11 @@ namespace SwayNotificationCenter {
* - int64
* - GLib.Object
*/
private
HashTable
<
string
,
T
>
extract_hashtable
<
T
>
(
string
property_name
,
private
OrderedHashTable
<
T
>
extract_hashtable
<
T
>
(
string
property_name
,
Json
.
Node
node
,
out
bool
status
)
{
status
=
false
;
var
tmp_table
=
new
HashTable
<
string
,
T
>
(
str_hash
,
str_equal
);
var
tmp_table
=
new
OrderedHashTable
<
T
>
(
);
if
(
node
.
get_node_type
()
!=
Json
.
NodeType
.
OBJECT
)
{
stderr
.
printf
(
"Node %s is not a json object!...\n"
,
...
...
@@ -833,12 +836,12 @@ namespace SwayNotificationCenter {
return
tmp_table
;
}
private
Json
.
Object
serialize_hashtable
<
T
>
(
HashTable
<
string
,
T
>
table
)
{
private
Json
.
Object
serialize_hashtable
<
T
>
(
OrderedHashTable
<
T
>
table
)
{
var
json_object
=
new
Json
.
Object
();
if
(
table
==
null
)
return
json_object
;
foreach
(
string
*
key
in
table
.
get_keys
())
{
foreach
(
string
key
in
table
.
get_keys
())
{
unowned
T
item
=
table
.
get
(
key
);
if
(
item
==
null
)
continue
;
...
...
src/controlCenter/widgets/baseWidget.vala
View file @
b8ef6181
...
...
@@ -27,7 +27,7 @@ namespace SwayNotificationCenter.Widgets {
}
protected
Json
.
Object
?
get_config
(
Gtk
.
Widget
widget
)
{
unowned
HashTable
<
string
,
Json
.
Object
>
config
unowned
OrderedHashTable
<
Json
.
Object
>
config
=
ConfigModel
.
instance
.
widget_config
;
string
?
orig_key
=
null
;
Json
.
Object
?
props
=
null
;
...
...
src/meson.build
View file @
b8ef6181
...
...
@@ -55,6 +55,7 @@ widget_sources = [
app_sources = [
'main.vala',
'orderedHashTable/orderedHashTable.vala',
'configModel/configModel.vala',
'swayncDaemon/swayncDaemon.vala',
'notiDaemon/notiDaemon.vala',
...
...
src/notiDaemon/notiDaemon.vala
View file @
b8ef6181
...
...
@@ -154,7 +154,8 @@ namespace SwayNotificationCenter {
// The notification visibility state
NotificationStatusEnum
state
=
NotificationStatusEnum
.
ENABLED
;
var
visibilities
=
ConfigModel
.
instance
.
notification_visibility
;
unowned
OrderedHashTable
<
NotificationVisibility
>
visibilities
=
ConfigModel
.
instance
.
notification_visibility
;
foreach
(
string
key
in
visibilities
.
get_keys
())
{
unowned
NotificationVisibility
vis
=
visibilities
[
key
];
if
(!
vis
.
matches_notification
(
param
))
continue
;
...
...
@@ -211,7 +212,7 @@ namespace SwayNotificationCenter {
return
id
;
}
// Run the first script if notification meets requirements
HashTable
<
string
,
Script
>
scripts
=
ConfigModel
.
instance
.
scripts
;
OrderedHashTable
<
Script
>
scripts
=
ConfigModel
.
instance
.
scripts
;
if
(
scripts
.
length
==
0
)
return
id
;
this
.
run_scripts
(
param
,
ScriptRunOnType
.
RECEIVE
);
#endif
...
...
@@ -229,7 +230,7 @@ namespace SwayNotificationCenter {
return
;
}
// Run the first script if notification meets requirements
HashTable
<
string
,
Script
>
scripts
=
ConfigModel
.
instance
.
scripts
;
OrderedHashTable
<
Script
>
scripts
=
ConfigModel
.
instance
.
scripts
;
if
(
scripts
.
length
==
0
)
return
;
foreach
(
string
key
in
scripts
.
get_keys
())
{
unowned
Script
script
=
scripts
[
key
];
...
...
src/orderedHashTable/orderedHashTable.vala
0 → 100644
View file @
b8ef6181
namespace
SwayNotificationCenter
{
/** A regular GLib HashTable but preserves the order of inserted keys and values */
public
class
OrderedHashTable
<
T
>
{
private
HashTable
<
string
,
T
>
hash_table
;
private
List
<
string
>
order
;
public
uint
length
{
get
{
return
hash_table
.
length
;
}
}
public
OrderedHashTable
()
{
hash_table
=
new
HashTable
<
string
,
T
>
(
str_hash
,
str_equal
);
order
=
new
List
<
string
>
();
}
public
unowned
T
@get
(
string
key
)
{
return
hash_table
.
get
(
key
);
}
public
void
insert
(
owned
string
key
,
owned
T
value
)
{
if
(!
hash_table
.
contains
(
key
))
{
order
.
append
(
key
);
}
hash_table
.
insert
(
key
,
value
);
}
public
List
<
weak
string
>
get_keys
()
{
return
order
.
copy
();
}
public
bool
lookup_extended
(
string
lookup_key
,
out
unowned
string
orig_key
,
out
unowned
T
value
)
{
return
hash_table
.
lookup_extended
(
lookup_key
,
out
orig_key
,
out
value
);
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment