After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 709591 - Create better object/applet names
Create better object/applet names
Status: RESOLVED FIXED
Product: gnome-panel
Classification: Other
Component: general
git master
Other Linux
: Normal normal
: ---
Assigned To: Panel Maintainers
Panel Maintainers
Depends on:
Blocks:
 
 
Reported: 2013-10-07 18:33 UTC by Alberts Muktupāvels
Modified: 2015-03-24 13:01 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
create better object/apllet names (4.73 KB, patch)
2013-10-07 18:33 UTC, Alberts Muktupāvels
none Details | Review
create better object/applet names (5.41 KB, patch)
2013-10-08 08:38 UTC, Alberts Muktupāvels
none Details | Review
Add comment and fix memory issue (5.89 KB, patch)
2013-10-08 10:15 UTC, Sebastian
needs-work Details | Review
Create better object/applet names (2.88 KB, patch)
2013-11-17 17:00 UTC, Alberts Muktupāvels
committed Details | Review

Description Alberts Muktupāvels 2013-10-07 18:33:52 UTC
Created attachment 256657 [details] [review]
create better object/apllet names

Patch to create better object/applet names which are stored in dconf. It also removes unneeded variable and two defines.
Comment 1 Sebastian 2013-10-07 22:57:55 UTC
In the if(details) block you allocate a new string with g_strndup():

   applet = g_strndup (applet, strlen (applet) - strlen (detail));

but you never free it. Except that the patch is great.
Comment 2 Alberts Muktupāvels 2013-10-08 08:38:14 UTC
Created attachment 256694 [details] [review]
create better object/applet names

Created new patch. Tested on default applets + gnome-applets.
Comment 3 Sebastian 2013-10-08 08:48:16 UTC
Can you give an example for a string that needs the while loop?

Also now you allocate new strings with g_strdup in a while loop but only free it once outside the loop, I think that can potentially lead to not freed strings.
Comment 4 Sebastian 2013-10-08 08:58:02 UTC
Ok I understand it now. I would suggest to add the following comment to this function:

+/**
+ * This function takes the applet name from the iid which looks like this: 
+ * 'ClockAppletFactory::ClockApplet' and converts it into a lower case,
+ * hyphen-delimited string which looks like this 'clock-applet'. To
+ * maintain readability of camel-case names a hyphen is inserted before
+ * each upper case character.
+ */
static char *
panel_layout_object_generate_id (const char *iid)
Comment 5 Alberts Muktupāvels 2013-10-08 09:40:58 UTC
Feel free to do it. You can update and post new patch here. I have no time to do it. :(

iid can be:
1) ClockAppletFactory::ClockApplet
2) ClockAppletFactory::ClockApplet:something

I am ignoring first part, we don't need it. Next step is to add dashes before next word, not before each upper case character.

There is CPUFreqApplet. We don't want name c-p-u-freq-applet, but cpu-freq-applet. 

There is extra check for iid like this ClockAppletFactory::ClockApplet:Something. we don't want add dash before S. but maybe it is not needed. At least in default applets there is no such iid.
Comment 6 Sebastian 2013-10-08 10:15:32 UTC
Created attachment 256716 [details] [review]
Add comment and fix memory issue

I have added the comment and also added another free in the while loop to free the newly allocated strings.
Comment 7 Philipp 2013-10-24 18:52:30 UTC
Review of attachment 256716 [details] [review]:

Overall I like it.

As this will aid debugging (at least for newly added applets), I'd even consider inclusion in 3.8.

::: gnome-panel/panel-layout.c
@@ -351,3 @@
                                   const char                *schema,
                                   const char                *path_prefix,
-                                  const char                *default_prefix,

better to split out the unused vars into another patch ?

@@ +761,3 @@
+    char        old;
+
+    applet = g_strrstr (iid, "::");

If the iid doesn't actually contain a "::", this will crash or create a security bug. Never know what context this function might be called in.

@@ +768,3 @@
+            dashed = g_strdup_printf("%c", applet[0]);
+        } else {
+            char* tmp = dashed;

The loop looks like tmp is never actually used (although it is saved for freeing). Maybe better to name it "dashed_old" or similar and reference it in the g_strdup_printf-s below.

Alternatively, introduce dashed_new and do the assignment at the end, after freeing.

@@ +781,3 @@
+    }
+
+    detail = g_strrstr (dashed, ":");

dito.

@@ +791,3 @@
+    } else {
+        return_id = g_ascii_strdown (dashed, -1);
+    }

I somehow feel the whole thing could be implemented prettier (and maybe simpler) with a scatter-gather approach. Then again, you'd need to manage the array memory.

Alternatively, we could just not bother with inserting -'s before in-word upper case characters, and simplify this to a character replacement / reduction loop without a lot of reallocations.

::: gnome-panel/panel-schemas.h
@@ -33,2 @@
 #define PANEL_LAYOUT_OBJECT_PATH             "/org/gnome/gnome-panel/layout/objects/"
-#define PANEL_LAYOUT_OBJECT_DEFAULT_PREFIX   "object"

undefined
Comment 8 Alberts Muktupāvels 2013-11-17 17:00:25 UTC
Created attachment 260054 [details] [review]
Create better object/applet names
Comment 9 Alberts Muktupāvels 2013-11-17 17:07:43 UTC
(In reply to comment #7)
> better to split out the unused vars into another patch ?

This I already committed to master so this is removed from new patch.

> @@ +761,3 @@
> +    char        old;
> +
> +    applet = g_strrstr (iid, "::");
> 
> If the iid doesn't actually contain a "::", this will crash or create a
> security bug. Never know what context this function might be called in.

Added extra check to make sure we are using correct iid as parameter. Also rewrote this function to be simpler keeping previous functionality. 

Is it good now?