Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
R
rugby
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Joseph Walton-Rivers
rugby
Commits
fdec9f82
Commit
fdec9f82
authored
3 years ago
by
Bruce Cowan
Browse files
Options
Downloads
Patches
Plain Diff
Use a GListStore directly and simplify
parent
c3e5eb35
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
meson.build
+3
-3
3 additions, 3 deletions
meson.build
src/rugby-list-store.c
+24
-40
24 additions, 40 deletions
src/rugby-list-store.c
with
27 additions
and
43 deletions
meson.build
+
3
−
3
View file @
fdec9f82
...
...
@@ -11,7 +11,7 @@ datadir = get_option('datadir')
gnome
=
import
(
'gnome'
)
gio_dep
=
dependency
(
'gio-2.0'
,
version
:
'>= 2.4
4
'
)
gio_dep
=
dependency
(
'gio-2.0'
,
version
:
'>= 2.4
6
'
)
gtk_dep
=
dependency
(
'gtk4'
,
version
:
'>= 4.0'
)
conf
=
configuration_data
()
...
...
@@ -28,8 +28,8 @@ config_h = declare_dependency(
)
cflags
=
[]
cflags
+=
[
'-DGLIB_VERSION_MIN_REQUIRED=GLIB_VERSION_2_4
4
'
,
'-DGLIB_VERSION_MAX_ALLOWED=GLIB_VERSION_2_4
4
'
]
cflags
+=
[
'-DGLIB_VERSION_MIN_REQUIRED=GLIB_VERSION_2_4
6
'
,
'-DGLIB_VERSION_MAX_ALLOWED=GLIB_VERSION_2_4
6
'
]
cflags
+=
[
'-DGDK_VERSION_MIN_REQUIRED=GDK_VERSION_4_0'
,
'-DGDK_VERSION_MAX_ALLOWED=GDK_VERSION_4_0'
]
...
...
This diff is collapsed.
Click to expand it.
src/rugby-list-store.c
+
24
−
40
View file @
fdec9f82
...
...
@@ -14,10 +14,10 @@ struct _RugbyListStore
{
GObject
parent_instance
;
GSettings
*
settings
;
GPtrArray
*
items
;
int
score
;
GListStore
*
items
;
GSettings
*
settings
;
};
static
void
rugby_list_store_list_model_iface_init
(
GListModelInterface
*
iface
);
...
...
@@ -28,8 +28,7 @@ G_DEFINE_TYPE_WITH_CODE (RugbyListStore, rugby_list_store, G_TYPE_OBJECT,
enum
{
PROP_0
,
PROP_SCORE
,
PROP_SCORE
=
1
,
N_PROPS
};
...
...
@@ -38,17 +37,18 @@ static GParamSpec *properties[N_PROPS];
// Helper functions
static
int
sort_func
(
gconstpointer
a
,
gconstpointer
b
)
sort_func
(
gconstpointer
a
,
gconstpointer
b
,
G_GNUC_UNUSED
gpointer
user_data
)
{
int
atries
,
autries
;
int
btries
,
butries
;
g_object_get
(
*
((
gpointer
*
)
a
)
,
g_object_get
((
gpointer
)
a
,
"tries"
,
&
atries
,
"utries"
,
&
autries
,
NULL
);
g_object_get
(
*
((
gpointer
*
)
b
)
,
g_object_get
((
gpointer
)
b
,
"tries"
,
&
btries
,
"utries"
,
&
butries
,
NULL
);
...
...
@@ -69,12 +69,12 @@ process_data (RugbyListStore *self)
int
utry_points
=
g_settings_get_int
(
self
->
settings
,
"utry-points"
);
int
kick_points
=
g_settings_get_int
(
self
->
settings
,
"kick-points"
);
unsigned
old_length
=
g_list_model_get_n_items
(
G_LIST_MODEL
(
self
->
items
));
g_list_store_remove_all
(
self
->
items
);
int
max_tries
=
self
->
score
/
try_points
;
int
max_utries
=
self
->
score
/
utry_points
;
unsigned
old_length
=
self
->
items
->
len
;
g_ptr_array_remove_range
(
self
->
items
,
0
,
self
->
items
->
len
);
for
(
int
tries
=
0
;
tries
<=
max_tries
;
tries
++
)
{
for
(
int
utries
=
0
;
utries
<=
max_utries
;
utries
++
)
...
...
@@ -91,24 +91,20 @@ process_data (RugbyListStore *self)
RugbyPossibility
*
possibility
=
rugby_possibility_new
(
tries
,
utries
,
kicks
);
g_ptr_array_add
(
self
->
items
,
possibility
);
g_list_store_append
(
self
->
items
,
possibility
);
g_object_unref
(
possibility
);
}
}
}
g_ptr_array_sort
(
self
->
items
,
sort_func
);
g_list_model_items_changed
(
G_LIST_MODEL
(
self
),
0
,
old_length
,
self
->
items
->
len
);
}
static
void
on_score_changed
(
RugbyListStore
*
self
)
{
process_data
(
self
);
g_list_store_sort
(
self
->
items
,
sort_func
,
NULL
);
g_list_model_items_changed
(
G_LIST_MODEL
(
self
),
0
,
old_length
,
g_list_model_get_n_items
(
G_LIST_MODEL
(
self
->
items
)));
}
static
void
on_settings_changed
(
GSettings
G_GNUC_UNUSED
*
settings
,
char
G_GNUC_UNUSED
*
key
,
on_settings_changed
(
G_GNUC_UNUSED
GSettings
*
settings
,
G_GNUC_UNUSED
char
*
key
,
gpointer
user_data
)
{
process_data
(
RUGBY_LIST_STORE
(
user_data
));
...
...
@@ -127,7 +123,7 @@ rugby_list_store_get_n_items (GListModel *list)
{
RugbyListStore
*
self
=
RUGBY_LIST_STORE
(
list
);
return
self
->
items
->
len
;
return
g_list_model_get_n_items
(
G_LIST_MODEL
(
self
->
items
))
;
}
static
gpointer
...
...
@@ -136,9 +132,7 @@ rugby_list_store_get_item (GListModel *list,
{
RugbyListStore
*
self
=
RUGBY_LIST_STORE
(
list
);
g_assert
(
position
<
self
->
items
->
len
);
return
g_object_ref
(
g_ptr_array_index
(
self
->
items
,
position
));
return
g_list_model_get_item
(
G_LIST_MODEL
(
self
->
items
),
position
);
}
static
void
...
...
@@ -157,20 +151,11 @@ rugby_list_store_dispose (GObject *object)
RugbyListStore
*
self
=
RUGBY_LIST_STORE
(
object
);
g_clear_object
(
&
self
->
settings
);
g_clear_object
(
&
self
->
items
);
G_OBJECT_CLASS
(
rugby_list_store_parent_class
)
->
dispose
(
object
);
}
static
void
rugby_list_store_finalize
(
GObject
*
object
)
{
RugbyListStore
*
self
=
RUGBY_LIST_STORE
(
object
);
g_ptr_array_unref
(
self
->
items
);
G_OBJECT_CLASS
(
rugby_list_store_parent_class
)
->
finalize
(
object
);
}
static
void
rugby_list_store_get_property
(
GObject
*
object
,
unsigned
prop_id
,
...
...
@@ -213,7 +198,6 @@ rugby_list_store_class_init (RugbyListStoreClass *klass)
GObjectClass
*
object_class
=
G_OBJECT_CLASS
(
klass
);
object_class
->
dispose
=
rugby_list_store_dispose
;
object_class
->
finalize
=
rugby_list_store_finalize
;
object_class
->
get_property
=
rugby_list_store_get_property
;
object_class
->
set_property
=
rugby_list_store_set_property
;
...
...
@@ -234,7 +218,7 @@ rugby_list_store_init (RugbyListStore *self)
G_CALLBACK
(
on_settings_changed
),
self
);
self
->
score
=
0
;
self
->
items
=
g_
ptr_array_new_with_free_func
(
g_object_unref
);
self
->
items
=
g_
list_store_new
(
RUGBY_TYPE_POSSIBILITY
);
}
// Public functions
...
...
@@ -256,7 +240,7 @@ rugby_list_store_set_score (RugbyListStore *self,
if
(
score
!=
self
->
score
)
{
self
->
score
=
score
;
on_score_changed
(
self
);
process_data
(
self
);
g_object_notify_by_pspec
(
G_OBJECT
(
self
),
properties
[
PROP_SCORE
]);
}
}
...
...
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