[Gtk-sharp-list] Need help .parsing desktop files!

Alex Launi alex.launi at gmail.com
Thu May 8 20:38:20 EDT 2008


Hi everyone, I'm having an issue parsing .desktop files, I'm not exactly
sure how to open the file so that I can write back to it. At the moment I
can read the file fine, getting any data I want out of it, but I can't make
changes. When I try to save, I get an exception. I've included the relevant
code snippets, and the exception it throws. Thanks for any help guys.

[CODE]
        ...
            ditem = OpenDesktopFile (desktop_file);

            if (auto_start_chk.Active) {
                Console.Error.WriteLine ("ENABLED");
                ditem.SetBoolean ("X-GNOME-Autostart-enabled",true);
                ditem.Save(desktop_file,true);
            }
            else {
                Console.Error.WriteLine ("DISABLED");
                ditem.SetBoolean ("X-GNOME-Autostart-enabled",false);
                ditem.Save(desktop_file,true);
            }
        ...
        private DesktopItem OpenDesktopFile (string desktopFile)
        {
            DesktopItem item;
            IntPtr desktopFileP;

            desktopFileP = gnome_desktop_item_new_from_file (
                desktopFile, 0, IntPtr.Zero);

            if (desktopFileP == IntPtr.Zero)
                throw new FileNotFoundException (desktopFile);

            item = new DesktopItem (desktopFileP);

            // We may need to call this depending on how DesktopItem works.
            gnome_desktop_item_unref (desktopFileP);
            return item;
        }

        [DllImport ("libgnome-desktop-2.so.2")]
        private static extern IntPtr gnome_desktop_item_new_from_file
(string file, int flags, IntPtr error);

        [DllImport ("libgnome-desktop-2.so.2")]
        private static extern void gnome_desktop_item_unref (IntPtr item);

[/CODE]

[EXCEPTION]

Exception in Gtk# callback delegate
  Note: Applications can use GLib.ExceptionManager.UnhandledException to
handle the exception.
GLib.GException: Operation not supported
  at Gnome.DesktopItem.Save (System.String under, Boolean force) [0x00000]
  at Do.UI.SettingsWindow.OnAutoStartChkClicked (System.Object sender,
System.EventArgs e) [0x001d4] in
/home/alex/Do/Do/src/Do.UI/SettingsWindow.cs:188
  at GLib.Signal.voidObjectCallback (IntPtr handle, IntPtr data) [0x00000]
   at GLib.ExceptionManager.RaiseUnhandledException(System.Exception e,
Boolean is_terminal)
   at GLib.Signal.voidObjectCallback(IntPtr handle, IntPtr data)
   at GLib.Signal.voidObjectCallback(IntPtr , IntPtr )
   at Gtk.Application.gtk_main()
   at Gtk.Application.gtk_main()
   at Gtk.Application.Run()
   at Do.Do.Main(System.String[] args) in /home/alex/Do/Do/src/Do.cs:line 78

[/EXCEPTION]

I've tried not dereferencing the pointer, the same exception is thrown. I've
also tried opening the Desktop item like
item = new DesktopItem (desktopFile,DesktopItemLoadFlags.OnlyIfExists);
It throws the exception here: http://www.paste2.org/p/26450.
Thanks for any help people, I really appreciate it.
-- 
--Alex Launi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/gtk-sharp-list/attachments/20080508/9c7e4437/attachment.html 


More information about the Gtk-sharp-list mailing list