[PC-BSD Commits] r2239 - pbibuild/pbi-source/PBItext
svn at pcbsd.org
svn at pcbsd.org
Wed Jul 2 09:23:59 PDT 2008
Author: kris
Date: 2008-07-02 09:23:54 -0700 (Wed, 02 Jul 2008)
New Revision: 2239
Modified:
pbibuild/pbi-source/PBItext/main.cpp
Log:
Updated PBItext to use the new mime system for KDE4
Modified: pbibuild/pbi-source/PBItext/main.cpp
===================================================================
--- pbibuild/pbi-source/PBItext/main.cpp 2008-07-02 16:21:46 UTC (rev 2238)
+++ pbibuild/pbi-source/PBItext/main.cpp 2008-07-02 16:23:54 UTC (rev 2239)
@@ -23,6 +23,7 @@
void CreateMimeSlot( int MimeNum );
void acceptLicense(void);
void MassageGTKFiles(void);
+void slotSetupCustomRemoveScript();
QString ProgramName;
QString ProgramVer;
@@ -56,11 +57,12 @@
QString ProgUpdateURL;
int GTKFound = 0;
int acceptlic = 0;
+int createdMimeFiles = 0;
int main( int argc, char ** argv )
{
- QApplication a( argc, argv, FALSE );
+ QCoreApplication a( argc, argv);
QString command = "whoami";
QString inputLine = getLineFromCommandOutput(command);
@@ -572,20 +574,17 @@
}
+
// Check if we need to create any mime icons
- i = 0;
- while ( ! MimeExt[i].isEmpty() )
+ if ( ! MimeExt[0].isEmpty() )
{
- CreateMimeSlot(i);
- i++;
+ createdMimeFiles=1;
+ CreateMimeSlot(0);
+ } else {
+ // Check if there is a custom script to be run
+ CheckScriptSlot();
}
-
-
-
- // Check if there is a custom script to be run
- CheckScriptSlot();
-
}
@@ -1039,12 +1038,76 @@
system("sh ./.PBIwrapper.sh");
//runCommand(command);
}
+
+ // Now setup our custom removal script
+ slotSetupCustomRemoveScript();
}
+void slotSetupCustomRemoveScript()
+{
+ QString cmd;
+ // Setup our custom removal script
+ if ( QFile::exists( "/Programs/" + ProgDirName + "/PBI.RemoveScript.sh" ) )
+ {
+
+ cmd = "mv /Programs/" + ProgDirName + "/PBI.RemoveScript.sh /Programs/" + ProgDirName + "/PBI.RemoveScript2.sh";
+ system(cmd.toLatin1());
+ }
+
+ QFile file( "/Programs/" + ProgDirName + "/PBI.RemoveScript.sh" );
+ if ( file.open( QIODevice::WriteOnly ) ) {
+ QTextStream stream( &file );
+ stream << "#!/bin/sh\n";
+ stream << "if [ -e '/Programs/" + ProgDirName + "/PBI.RemoveScript2.sh' ]\n";
+ stream << "then\n";
+ stream << " sh /Programs/" + ProgDirName + "/PBI.RemoveScript2.sh \"${@}\"\n";
+ stream << "fi\n";
+
+ // Check if we need to put any Mime removal code into the uninstall script
+ if ( createdMimeFiles == 1 )
+ {
+ int i = 0;
+ while ( ! MimeExt[i].isEmpty() )
+ {
+ // Remove the xml files from the mime package database
+ stream << "rm -f '/usr/local/share/mime/packages/" << ProgramName << i << "-'*\n";
+
+ // Remove the hidden applnk files
+ stream << "rm -f '/usr/local/share/applnk/.hidden/" << ProgramName << i << "-'*\n";
+
+ // Remove any mentions of this entry from mimeapps.list
+ stream << "cat /usr/local/share/applications/mimeapps.list | grep -v '=" << ProgramName << i << "-' >/tmp/.mimeapps.list\n";
+ stream << "mv /tmp/.mimeapps.list /usr/local/share/applications/mimeapps.list\n";
+
+ i++;
+ }
+
+ // Recreate the mime database
+ stream << "update-mime-database /usr/local/share/mime";
+
+ }
+
+ file.close();
+ }
+
+
+ cmd = "chmod 755 /Programs/" + ProgDirName + "/PBI.RemoveScript.sh";
+ system(cmd.toLatin1());
+
+}
+
+
void CreateMimeSlot( int MimeNum )
{
+
+ if ( MimeExt[MimeNum].isEmpty() )
+ {
+ // All finished with Mime Files, lets move on to checking for custom scripts now
+ CheckScriptSlot();
+ return;
+ }
QString MimeNumString;
MimeNumString.setNum(MimeNum);
@@ -1073,48 +1136,31 @@
} else {
Icon = "/Programs/" + ProgDirName + "/" + MimeIcon[MimeProg[MimeNum]];
}
-
- QFile file( "/usr/local/share/mimelnk/application/" + ProgramName + MimeNumString + ".desktop");
- if ( file.open( QIODevice::WriteOnly) ) {
- QTextStream stream( &file );
- stream << "[Desktop Entry]\n";
- stream << "Comment=" + ProgramName + " File\n";
- stream << "Hidden=false\n";
- stream << "Icon=" + Icon + "\n";
- stream << "MimeType=application/" << ProgramName << MimeNum << "\n";
- stream << "Patterns=" + MimeExt[MimeNum] + "\n";
- stream << "Type=MimeType\n";
-
- file.close();
- }
-
- QFile file2( "/usr/local/share/applnk/.hidden/" + ProgramName + MimeNumString + ".desktop");
- if ( file2.open( QIODevice::WriteOnly) ) {
- QTextStream stream2( &file2 );
- stream2 << "[Desktop Entry]\n";
- stream2 << "Exec=/Programs/" + ProgDirName + "/.sbin/" +Binary + "\n";
- stream2 << "Icon=" + Icon + "\n";
- stream2 << "InitialPreference=1\n";
- stream2 << "MimeType=application/" << ProgramName << MimeNum << "\n";
- stream2 << "Name=" + Binary + "\n";
- if ( RunShell[MimeProg[MimeNum]] == "1" )
- {
- stream2 << "Terminal=true\n";
- }
-
- stream2 << "Type=Application\n";
-
- file2.close();
- }
-
- // Chmod the new file
- QString command = "chmod 755 '/usr/local/share/applnk/.hidden/" + ProgramName + MimeNumString + ".desktop'";
- runCommand(command);
-
- // Chmod the new file
- command = "chmod 755 '/usr/local/share/mimelnk/application/" + ProgramName + MimeNumString + ".desktop'";
- runCommand(command);
+ // Setup our variables we will use for the argument list
+ QString MimeName = ProgramName + MimeNumString;
+ QString ProgEXE = "/Programs/" + ProgDirName + "/.sbin/" + Binary;
+ QString Terminal = "0";
+ if ( RunShell[MimeProg[MimeNum]] == "1" )
+ {
+ Terminal = "1";
+ }
+ QString Location;
+ if ( RealUserName == "root" )
+ {
+ Location="/root/.PBItmp";
+ } else {
+ Location = "/home/" + RealUserName + "/.PBItmp";
+ }
+
+ // Create the mime entry by calling addpbimime.sh
+ QString command="bash '" + Location + "/addpbimime.sh' '" + MimeName + "' '" +MimeExt[MimeNum] + "' '" + ProgEXE + "' '" + Icon + "' '" + Terminal + "'" ;
+ system(command.toLatin1());
+
+ // Create the next Mime entry now
+ MimeNum++;
+ CreateMimeSlot(MimeNum);
+
}
More information about the Commits
mailing list