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 {
...
@@ -479,26 +479,28 @@ namespace SwayNotificationCenter {
}
}
/** Categories settings */
/** Categories settings */
public
HashTable
<
string
,
Category
>
categories_settings
{
public
OrderedHashTable
<
Category
>
categories_settings
{
get
;
get
;
set
;
set
;
default
=
new
HashTable
<
string
,
Category
>
(
str_hash
,
str_equal
);
default
=
new
OrderedHashTable
<
Category
>
(
);
}
}
/** Notification Status */
/** Notification Status */
public
HashTable
<
string
,
NotificationVisibility
>
notification_visibility
{
public
OrderedHashTable
<
NotificationVisibility
>
notification_visibility
{
get
;
get
;
set
;
set
;
default
=
new
HashTable
<
string
,
NotificationVisibility
>
(
str_hash
,
str_equal
);
default
=
new
OrderedHashTable
<
NotificationVisibility
>
(
);
}
}
#if WANT_SCRIPTING
#if WANT_SCRIPTING
/** Scripts */
/** Scripts */
public
HashTable
<
string
,
Script
>
scripts
{
public
OrderedHashTable
<
Script
>
scripts
{
get
;
get
;
set
;
set
;
default
=
new
HashTable
<
string
,
Script
>
(
str_hash
,
str_equal
);
default
=
new
OrderedHashTable
<
Script
>
(
);
}
}
/** Show notification if script fails */
/** Show notification if script fails */
public
bool
script_fail_notify
{
get
;
set
;
default
=
true
;
}
public
bool
script_fail_notify
{
get
;
set
;
default
=
true
;
}
#endif
#endif
...
@@ -597,12 +599,13 @@ namespace SwayNotificationCenter {
...
@@ -597,12 +599,13 @@ namespace SwayNotificationCenter {
}
}
/** Widgets to show in ControlCenter */
/** Widgets to show in ControlCenter */
public
HashTable
<
string
,
Json
.
Object
>
widget_config
{
public
OrderedHashTable
<
Json
.
Object
>
widget_config
{
get
;
get
;
set
;
set
;
default
=
new
HashTable
<
string
,
Json
.
Object
>
(
str_hash
,
str_equal
);
default
=
new
OrderedHashTable
<
Json
.
Object
>
(
);
}
}
/* Methods */
/* Methods */
/**
/**
...
@@ -617,7 +620,7 @@ namespace SwayNotificationCenter {
...
@@ -617,7 +620,7 @@ namespace SwayNotificationCenter {
switch
(
property_name
)
{
switch
(
property_name
)
{
case
"categories-settings"
:
case
"categories-settings"
:
bool
status
;
bool
status
;
HashTable
<
string
,
Category
>
result
=
OrderedHashTable
<
Category
>
result
=
extract_hashtable
<
Category
>
(
extract_hashtable
<
Category
>
(
property_name
,
property_name
,
property_node
,
property_node
,
...
@@ -626,7 +629,7 @@ namespace SwayNotificationCenter {
...
@@ -626,7 +629,7 @@ namespace SwayNotificationCenter {
return
status
;
return
status
;
case
"notification-visibility"
:
case
"notification-visibility"
:
bool
status
;
bool
status
;
HashTable
<
string
,
NotificationVisibility
>
result
=
OrderedHashTable
<
NotificationVisibility
>
result
=
extract_hashtable
<
NotificationVisibility
>
(
extract_hashtable
<
NotificationVisibility
>
(
property_name
,
property_name
,
property_node
,
property_node
,
...
@@ -636,7 +639,7 @@ namespace SwayNotificationCenter {
...
@@ -636,7 +639,7 @@ namespace SwayNotificationCenter {
#if WANT_SCRIPTING
#if WANT_SCRIPTING
case
"scripts"
:
case
"scripts"
:
bool
status
;
bool
status
;
HashTable
<
string
,
Script
>
result
=
OrderedHashTable
<
Script
>
result
=
extract_hashtable
<
Script
>
(
extract_hashtable
<
Script
>
(
property_name
,
property_name
,
property_node
,
property_node
,
...
@@ -653,8 +656,8 @@ namespace SwayNotificationCenter {
...
@@ -653,8 +656,8 @@ namespace SwayNotificationCenter {
value
=
result
;
value
=
result
;
return
status
;
return
status
;
case
"widget-config"
:
case
"widget-config"
:
HashTable
<
string
,
Json
.
Object
>
result
OrderedHashTable
<
Json
.
Object
>
result
=
new
HashTable
<
string
,
Json
.
Object
>
(
str_hash
,
str_equal
);
=
new
OrderedHashTable
<
Json
.
Object
>
(
);
if
(
property_node
.
get_value_type
().
name
()
!=
"JsonObject"
)
{
if
(
property_node
.
get_value_type
().
name
()
!=
"JsonObject"
)
{
value
=
result
;
value
=
result
;
return
true
;
return
true
;
...
@@ -668,7 +671,7 @@ namespace SwayNotificationCenter {
...
@@ -668,7 +671,7 @@ namespace SwayNotificationCenter {
Json
.
Node
?
node
=
obj
.
get_member
(
key
);
Json
.
Node
?
node
=
obj
.
get_member
(
key
);
if
(
node
.
get_node_type
()
!=
Json
.
NodeType
.
OBJECT
)
continue
;
if
(
node
.
get_node_type
()
!=
Json
.
NodeType
.
OBJECT
)
continue
;
Json
.
Object
?
o
=
node
.
get_object
();
Json
.
Object
?
o
=
node
.
get_object
();
if
(
o
!=
null
)
result
.
se
t
(
key
,
o
);
if
(
o
!=
null
)
result
.
inser
t
(
key
,
o
);
}
}
value
=
result
;
value
=
result
;
return
true
;
return
true
;
...
@@ -701,29 +704,29 @@ namespace SwayNotificationCenter {
...
@@ -701,29 +704,29 @@ namespace SwayNotificationCenter {
switch
(
property_name
)
{
switch
(
property_name
)
{
case
"categories-settings"
:
case
"categories-settings"
:
node
=
new
Json
.
Node
(
Json
.
NodeType
.
OBJECT
);
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
));
node
.
set_object
(
serialize_hashtable
<
Category
>
(
table
));
break
;
break
;
case
"notification-visibility"
:
case
"notification-visibility"
:
node
=
new
Json
.
Node
(
Json
.
NodeType
.
OBJECT
);
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
));
node
.
set_object
(
serialize_hashtable
<
NotificationVisibility
>
(
table
));
break
;
break
;
#if WANT_SCRIPTING
#if WANT_SCRIPTING
case
"scripts"
:
case
"scripts"
:
node
=
new
Json
.
Node
(
Json
.
NodeType
.
OBJECT
);
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
));
node
.
set_object
(
serialize_hashtable
<
Script
>
(
table
));
break
;
break
;
#endif
#endif
case
"widgets"
:
case
"widgets"
:
node
=
new
Json
.
Node
(
Json
.
NodeType
.
ARRAY
);
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
));
node
.
set_array
(
serialize_array
<
string
>
(
table
));
break
;
break
;
case
"widget-config"
:
case
"widget-config"
:
node
=
new
Json
.
Node
(
Json
.
NodeType
.
OBJECT
);
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
));
node
.
set_object
(
serialize_hashtable
<
Json
.
Object
>
(
table
));
break
;
break
;
default
:
default
:
...
@@ -739,7 +742,7 @@ namespace SwayNotificationCenter {
...
@@ -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.
* from a nested JSON Object.
*
*
* Can only accept these types:
* Can only accept these types:
...
@@ -748,11 +751,11 @@ namespace SwayNotificationCenter {
...
@@ -748,11 +751,11 @@ namespace SwayNotificationCenter {
* - int64
* - int64
* - GLib.Object
* - GLib.Object
*/
*/
private
HashTable
<
string
,
T
>
extract_hashtable
<
T
>
(
string
property_name
,
private
OrderedHashTable
<
T
>
extract_hashtable
<
T
>
(
string
property_name
,
Json
.
Node
node
,
Json
.
Node
node
,
out
bool
status
)
{
out
bool
status
)
{
status
=
false
;
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
)
{
if
(
node
.
get_node_type
()
!=
Json
.
NodeType
.
OBJECT
)
{
stderr
.
printf
(
"Node %s is not a json object!...\n"
,
stderr
.
printf
(
"Node %s is not a json object!...\n"
,
...
@@ -833,12 +836,12 @@ namespace SwayNotificationCenter {
...
@@ -833,12 +836,12 @@ namespace SwayNotificationCenter {
return
tmp_table
;
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
();
var
json_object
=
new
Json
.
Object
();
if
(
table
==
null
)
return
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
);
unowned
T
item
=
table
.
get
(
key
);
if
(
item
==
null
)
continue
;
if
(
item
==
null
)
continue
;
...
...
src/controlCenter/widgets/baseWidget.vala
View file @
b8ef6181
...
@@ -27,7 +27,7 @@ namespace SwayNotificationCenter.Widgets {
...
@@ -27,7 +27,7 @@ namespace SwayNotificationCenter.Widgets {
}
}
protected
Json
.
Object
?
get_config
(
Gtk
.
Widget
widget
)
{
protected
Json
.
Object
?
get_config
(
Gtk
.
Widget
widget
)
{
unowned
HashTable
<
string
,
Json
.
Object
>
config
unowned
OrderedHashTable
<
Json
.
Object
>
config
=
ConfigModel
.
instance
.
widget_config
;
=
ConfigModel
.
instance
.
widget_config
;
string
?
orig_key
=
null
;
string
?
orig_key
=
null
;
Json
.
Object
?
props
=
null
;
Json
.
Object
?
props
=
null
;
...
...
src/meson.build
View file @
b8ef6181
...
@@ -55,6 +55,7 @@ widget_sources = [
...
@@ -55,6 +55,7 @@ widget_sources = [
app_sources = [
app_sources = [
'main.vala',
'main.vala',
'orderedHashTable/orderedHashTable.vala',
'configModel/configModel.vala',
'configModel/configModel.vala',
'swayncDaemon/swayncDaemon.vala',
'swayncDaemon/swayncDaemon.vala',
'notiDaemon/notiDaemon.vala',
'notiDaemon/notiDaemon.vala',
...
...
src/notiDaemon/notiDaemon.vala
View file @
b8ef6181
...
@@ -154,7 +154,8 @@ namespace SwayNotificationCenter {
...
@@ -154,7 +154,8 @@ namespace SwayNotificationCenter {
// The notification visibility state
// The notification visibility state
NotificationStatusEnum
state
=
NotificationStatusEnum
.
ENABLED
;
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
())
{
foreach
(
string
key
in
visibilities
.
get_keys
())
{
unowned
NotificationVisibility
vis
=
visibilities
[
key
];
unowned
NotificationVisibility
vis
=
visibilities
[
key
];
if
(!
vis
.
matches_notification
(
param
))
continue
;
if
(!
vis
.
matches_notification
(
param
))
continue
;
...
@@ -211,7 +212,7 @@ namespace SwayNotificationCenter {
...
@@ -211,7 +212,7 @@ namespace SwayNotificationCenter {
return
id
;
return
id
;
}
}
// Run the first script if notification meets requirements
// 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
;
if
(
scripts
.
length
==
0
)
return
id
;
this
.
run_scripts
(
param
,
ScriptRunOnType
.
RECEIVE
);
this
.
run_scripts
(
param
,
ScriptRunOnType
.
RECEIVE
);
#endif
#endif
...
@@ -229,7 +230,7 @@ namespace SwayNotificationCenter {
...
@@ -229,7 +230,7 @@ namespace SwayNotificationCenter {
return
;
return
;
}
}
// Run the first script if notification meets requirements
// 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
;
if
(
scripts
.
length
==
0
)
return
;
foreach
(
string
key
in
scripts
.
get_keys
())
{
foreach
(
string
key
in
scripts
.
get_keys
())
{
unowned
Script
script
=
scripts
[
key
];
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