Index: files/main.applescript
===================================================================
--- files/main.applescript	(revision 0)
+++ files/main.applescript	(revision 0)
@@ -0,0 +1,93 @@
+#---------------------------------------------------------------------------------------------------
+#
+# This program 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 3 of the License, or
+# (at your option) any later version.
+# 
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+#---------------------------------------------------------------------------------------------------
+#
+# GPL-licensed icons included in applet.icns are courtesy of KMyMoney's developers!
+#
+#---------------------------------------------------------------------------------------------------
+#
+# Authors:
+#  - Brad Giesbrecht <brad@pixilla.com>
+#  - Marko K"aning <MK-MacPorts@techno.ms>
+#
+########################################################
+
+try
+	
+	set userID to do shell script "stat -f '%Su' $HOME"
+	
+end try
+
+set kdedirID to ""
+set ICEauthorityID to ""
+set XauthorityID to ""
+
+set kdeDir to (POSIX path of (path to home folder) & ".kde/" as string)
+set ICEauthority to (POSIX path of (path to home folder) & ".ICEauthority" as string)
+set Xauthority to (POSIX path of (path to home folder) & ".Xauthority" as string)
+
+set kdeDirMessage to ""
+
+try
+	
+	POSIX file kdeDir as alias
+	set kdedirID to do shell script "stat -f '%Su' $HOME/.kde"
+	
+end try
+
+try
+	
+	POSIX file ICEauthority as alias
+	set ICEauthorityID to do shell script "stat -f '%Su' $HOME/.ICEauthority"
+	
+end try
+
+try
+	
+	POSIX file Xauthority as alias
+	set XauthorityID to do shell script "stat -f '%Su' $HOME/.Xauthority"
+	
+end try
+
+if ((not kdedirID is equal to "") and not kdedirID = userID) or not ICEauthorityID = userID or not XauthorityID = userID then
+	
+	if (not kdedirID is equal to "") then set kdeDirMessage to (kdeDir & return & " is owned by " & kdedirID & return & return)
+	
+	set fixPermissions to button returned of ¬
+		(display dialog (kdeDirMessage ¬
+			& ICEauthority & return & " is owned by " & ICEauthorityID & return & return ¬
+			& Xauthority & return & " is owned by " & XauthorityID & return & return ¬
+			& "They should be owned by " & userID & " for KMyMoney to run properly!") ¬
+			buttons {"Cancel", "Fix"} default button {"Fix"} with icon 2)
+	
+	if fixPermissions = "Fix" then
+		
+		if (not kdedirID is equal to "") then do shell script "chown -R " & userID & " " & kdeDir with administrator privileges
+		do shell script "chown " & userID & " " & ICEauthority with administrator privileges
+		do shell script "chown " & userID & " " & Xauthority with administrator privileges
+		
+	end if
+	
+end if
+
+try
+	do shell script "$SHELL -l -c __PREFIX__/bin/kmymoney > /dev/null 2>&1"
+on error
+	display alert "There was an error launching KMyMoney." & return & return & ¬
+		"Try 'port installed kmymoney' to verify kmymoney is installed." & return & return & ¬
+		"The command we tried to execute was:" & return & return & ¬
+		"'$SHELL -l -c __PREFIX__/bin/kmymoney > /dev/null 2>&1'" as warning
+end try
Index: Portfile
===================================================================
--- Portfile	(revision 66409)
+++ Portfile	(working copy)
@@ -4,9 +4,10 @@
 
 name              kmymoney
 version           1.0.4
+revision          1
 
 categories        kde finance
-maintainers       techno.ms:mk-macports
+maintainers       techno.ms:mk-macports pixilla.com:brad
 platforms         darwin
 
 description       a personal finance manager
@@ -17,15 +18,25 @@
                   QIF import/export, multiple currencies and initial online \
                   banking support. \
                   Released under the GNU General Public License. \
-                  KMyMoney is free software.
+                  KMyMoney is free software. \
+                  \
+                  NB: This port contains a starter .app which is located in \
+                  Applications/MacPorts and ensures that permissions of .kde \
+                  directory are set properly to run kmymoney.
 
 homepage          http://kmymoney2.sourceforge.net/index-home.html
-master_sites      sourceforge:kmymoney2
+master_sites      sourceforge:kmymoney2 \
+                  macports::icon
 distname          kmymoney2-${version}
 use_bzip2         yes
-checksums         md5     5971b8b2bc4107b967e267bc635d1b5c \
-                  sha1    c6d3bdceec354502d8dee24b88ee714aa29e80b4 \
-                  rmd160  71e5bbd4ddba7d6b5f71443f67eebba6ea26c20a
+distfiles         [suffix ${distname}] \
+                  applet.icns:icon
+checksums         [suffix ${distname}]  md5     5971b8b2bc4107b967e267bc635d1b5c \
+                                        sha1    c6d3bdceec354502d8dee24b88ee714aa29e80b4 \
+                                        rmd160  71e5bbd4ddba7d6b5f71443f67eebba6ea26c20a \
+                  applet.icns           md5     ff7199454889841b9188a39de417094f \
+                                        sha1    ed1d8510521d9b81c632d5bb70d99c3d8291adf3 \
+                                        rmd160  83369c68f66872e115291db1d25524e68468928e
 
 depends_build     port:libtool
 
@@ -37,7 +48,7 @@
 configure.ldflags-append   "-Wl,-dylib_file,/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib:/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib"
 configure.env     MKDIR_P="mkdir -p" \
                   QTDIR=${prefix}/lib/qt3 \
-                  HOME=${workpath}
+                  HOME=${worksrcpath}
 configure.args    --with-qt-dir=${prefix}/lib/qt3 \
                   --without-arts \
                   --enable-mac \
@@ -50,6 +61,13 @@
 
 post-configure {
     ln -sf ${prefix}/bin/glibtool ${worksrcpath}/libtool
+    system "cp ${filespath}/main.applescript ${worksrcpath}"
+    reinplace "s|__PREFIX__|${prefix}|" ${worksrcpath}/main.applescript
 }
 
-build.env         HOME=${workpath}
+build.env         HOME=${worksrcpath}
+
+post-destroot {
+    system "osacompile -o ${destroot}/Applications/MacPorts/KMyMoney.app ${worksrcpath}/main.applescript"
+    system "cp ${distpath}/applet.icns ${destroot}/Applications/MacPorts/KMyMoney.app/Contents/Resources/"
+}
