gnustep-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Desktop links for GNUstep apps


From: Fred Kiefer
Subject: Re: Desktop links for GNUstep apps
Date: Sat, 08 Dec 2001 00:02:22 +0100

Fred Kiefer wrote:
> 
> In an attempt to make GNUstep programs more aware to the outside world I
> wrote a little program that converts a GNUstep Info property list into a
> desktop link. This format is a common agreement of KDE and Gnome to
> store information about runable programs. To be honest it is a lot less
> useful than the Info files, but as long as only Apple and we are using
> them (and even we use different entries in the file) it should be good
> to support this format also.
> 
> We could add the pl2link program to the make process of an application,
> it would convert the Info-gnustep.plist file into an .desktop file for
> that application, which could be placed at the right spot for the
> running window manager (for KDE this is somewhere below
> /opt/kde2/share/applnk/, for Gnome /opt/gnome/share/gnome/apps/, but
> this might be system specific). That way a GNUstep application would fit
> in better for those window managers.
> 
> Speaking of different window managers. Is there anybody about to
> implement NET or EWMH, as Adam now calls it, support into our X back
> ends? If not I might take that task. It looks like I am the only GNUstep
> developer who is not using WindowMaker as his default window manager
> (although I try it from time to time).
> 
> Fred

Only now did I notice that I did forget to add the file I wrote about.
Sorry, here it comes.
/* 
   This tool produces a desktop link file for KDE and Gnome out of a GNUstep 
   property list.
   Copyright (C) 20010 Free Software Foundation, Inc.

   Written by:  Fred Kiefer <address@hidden>
   Created: December 2001

   This file is part of the GNUstep Project

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU General Public License
   as published by the Free Software Foundation; either version 2
   of the License, or (at your option) any later version.

   You should have received a copy of the GNU General Public
   License along with this library; see the file COPYING.LIB.
   If not, write to the Free Software Foundation,
   59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

   */

#include        <Foundation/Foundation.h>
#include        <Foundation/NSArray.h>
#include        <Foundation/NSAutoreleasePool.h>
#include        <Foundation/NSData.h>
#include        <Foundation/NSDictionary.h>
#include        <Foundation/NSException.h>
#include        <Foundation/NSFileManager.h>
#include        <Foundation/NSProcessInfo.h>
#include        <Foundation/NSString.h>

int
main(int argc, char** argv, char **env)
{
  NSAutoreleasePool     *pool;
  NSProcessInfo         *procinfo;
  NSArray               *args;
  NSString              *sourceName;
  NSString              *destName;
  NSMutableString       *fileContents;
  NSDictionary          *plist;
  NSArray               *list;
  NSString              *entry;

#ifdef GS_PASS_ARGUMENTS
  [NSProcessInfo initializeWithArguments:argv count:argc environment:env];
#endif
  pool = [NSAutoreleasePool new];
  procinfo = [NSProcessInfo processInfo];
  if (procinfo == nil)
    {
      NSLog(@"plmerge: unable to get process information!");
      [pool release];
      exit(0);
    }

  args = [procinfo arguments];

  if ([args count] < 2)
    {
      NSLog(@"Usage: %@ input-file [destination-file]",
              [procinfo processName]);
      [pool release];
      exit(0);
    }

  sourceName = [args objectAtIndex: 1];
  destName = [args objectAtIndex: 2];
  NS_DURING
    {
      fileContents = [NSString stringWithContentsOfFile: sourceName];
      plist = [fileContents propertyList];
    }
  NS_HANDLER
    {
      NSLog(@"Parsing '%@' - %@", sourceName, [localException reason]);
    }
  NS_ENDHANDLER

  if ((plist == nil) || ![plist isKindOfClass: [NSDictionary class]])
    {
      NSLog(@"The source property list must contain an NSDictionary.");
      [pool release];
      exit(1);
    }

  fileContents = [NSMutableString stringWithCapacity: 200];
  [fileContents appendString: @"[Desktop 
Entry]\nEncoding=UTF-8\nType=Application\n"];
  entry = [plist objectForKey: @"ApplicationRelease"];
  if (entry != nil)
    [fileContents appendFormat: @"address@hidden", entry];
  entry = [plist objectForKey: @"ApplicationName"];
  if (entry != nil)
    [fileContents appendFormat: @"address@hidden", entry];
  entry = [plist objectForKey: @"NSIcon"];
  if (entry != nil)
  {
    if ([[entry pathExtension] isEqualToString: @""])
      [fileContents appendFormat: @"address@hidden", entry];
    else
      [fileContents appendFormat: @"address@hidden", entry];
  }
  entry = [plist objectForKey: @"NSExecutable"];
  if (entry != nil)
    {
      [fileContents appendFormat: @"Exec=openapp address@hidden", entry];
      [fileContents appendFormat: @"address@hidden", entry];
    }

  list = [plist objectForKey: @"Types"];
  if (list != nil)
  {
    int i;

    [fileContents appendString: @"MimeType="];
    for (i = 0; i < [list count]; i++)
    {
      plist = [list objectAtIndex: i];
      entry = [plist objectForKey: @"NSMIMETypes"];
      if (entry != nil)
        [fileContents appendFormat: @"%@;", entry];
    }
    [fileContents appendString: @"\n"];
  }

  if ([[fileContents dataUsingEncoding: NSUTF8StringEncoding] 
          writeToFile: destName atomically: YES] == NO)
    NSLog(@"Error writing property list to '%@'", destName);

  [pool release];
  exit(0);
}

reply via email to

[Prev in Thread] Current Thread [Next in Thread]