mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-23 09:04:13 +00:00
New program to generate desktop link
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@11749 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
c1812b56f5
commit
3eef7da2af
3 changed files with 151 additions and 1 deletions
|
@ -1,3 +1,7 @@
|
|||
2001-12-13 Adam Fedor <fedor@gnu.org>
|
||||
|
||||
* Tools/pl2link.m: New file (from FredKiefer@gmx.de).
|
||||
|
||||
2001-12-12 Adam Fedor <fedor@gnu.org>
|
||||
|
||||
* Headers/gnustep/base/NSDebug.h: Include NSDebugLog functions
|
||||
|
|
|
@ -41,7 +41,7 @@ DOCTEMPLATES_FILES = indextemplate.gsdoc AutoDocTemplate.gsdoc
|
|||
|
||||
# The application to be compiled
|
||||
TOOL_NAME = autogsdoc gdnc gsdoc defaults plmerge \
|
||||
plparse sfparse pldes plser
|
||||
plparse sfparse pldes plser pl2link
|
||||
CTOOL_NAME = gdomap
|
||||
|
||||
TEST_TOOL_NAME = locale_alias
|
||||
|
@ -60,6 +60,7 @@ plser_OBJC_FILES = plser.m
|
|||
plmerge_OBJC_FILES = plmerge.m
|
||||
plparse_OBJC_FILES = plparse.m
|
||||
sfparse_OBJC_FILES = sfparse.m
|
||||
pl2link_OBJC_FILES = pl2link.m
|
||||
|
||||
locale_alias_OBJC_FILES = locale_alias.m
|
||||
|
||||
|
|
145
Tools/pl2link.m
Normal file
145
Tools/pl2link.m
Normal file
|
@ -0,0 +1,145 @@
|
|||
/*
|
||||
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 <FredKiefer@gmx.de>
|
||||
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];
|
||||
if ([args count] > 2)
|
||||
{
|
||||
destName = [args objectAtIndex: 2];
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Filled in later */
|
||||
destName = nil;
|
||||
}
|
||||
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: @"Version=%@\n", entry];
|
||||
entry = [plist objectForKey: @"ApplicationName"];
|
||||
if (entry != nil)
|
||||
{
|
||||
[fileContents appendFormat: @"Name=%@\n", entry];
|
||||
if (destName == nil)
|
||||
destName = [entry stringByAppendingString: @".desktop"];
|
||||
}
|
||||
entry = [plist objectForKey: @"NSIcon"];
|
||||
if (entry != nil)
|
||||
{
|
||||
if ([[entry pathExtension] isEqualToString: @""])
|
||||
[fileContents appendFormat: @"Icon=%@.tiff\n", entry];
|
||||
else
|
||||
[fileContents appendFormat: @"Icon=%@\n", entry];
|
||||
}
|
||||
entry = [plist objectForKey: @"NSExecutable"];
|
||||
if (entry != nil)
|
||||
{
|
||||
[fileContents appendFormat: @"Exec=openapp %@.app\n", entry];
|
||||
[fileContents appendFormat: @"#TryExec=%@.app\n", 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);
|
||||
}
|
Loading…
Reference in a new issue