API version checking

Peter Zhou peterzhoulei at gmail.com
Sat May 30 19:05:22 CEST 2009


Hi all,

here's the patch for version checking:


Index: src/dialogs/ScriptManager.cpp
===================================================================
--- src/dialogs/ScriptManager.cpp	(revision 975566)
+++ src/dialogs/ScriptManager.cpp	(working copy)
@@ -566,6 +566,9 @@
 {
     DEBUG_BLOCK

+	QStringList SupportAPIVersion;
+	SupportAPIVersion << "API V1.0.0" << "API V1.0.1";
+	QString ScriptVersion;
     if( !path.isEmpty() )
     {
         QFileInfo info( path );
@@ -578,8 +581,21 @@
             item.info = KPluginInfo( specPath );
             if ( !item.info.isValid() ) return false;
             if ( ( item.info.name() == "" ) || ( item.info.version()
== "" ) || ( item.info.category() == "" ) ) return false;
+			
+			//assume it is API V1.0.0 if there is no "API V" prefix found
+			if ( !item.info.dependencies().at(0).startsWith("API V") )
+				ScriptVersion = "API V1.0.0";
+			else
+				ScriptVersion = item.info.dependencies().at(0);
+			
+			if ( !SupportAPIVersion.contains( ScriptVersion ) )
+			{
+				KMessageBox::sorry( item.info.name() );
+				return false;
+			}
+
             if ( m_scripts.contains( item.info.name() ) ) return
false; //check if script is already loaded...
-            debug() << "script info:" << item.info.name() << " " <<
item.info.version() << " " << item.info.category();
+            debug() << "script info:" << item.info.name() << " " <<
item.info.version() << " " << item.info.category() << " " <<
item.info.dependencies().at(0);
             item.info.setConfig( KGlobal::config()->group(
item.info.name() ) );
             item.url = url;
             item.running = false;


and the script.spec file should look like this:

[Desktop Entry]
Icon=preferences-other-amarok
Type=script
ServiceTypes=KPluginInfo

Name=test
Comment=Amarok Script Tests

X-KDE-PluginInfo-Name=Amarok Script Tests
X-KDE-PluginInfo-Version=1.0
X-KDE-PluginInfo-Category=Generic
X-KDE-PluginInfo-Website=http://amarok.kde.org/
X-KDE-PluginInfo-Depends=API V1.0.1
X-KDE-PluginInfo-License=GPL
X-KDE-PluginInfo-EnabledByDefault=false



We are more or less updating our APIs which makes the old Amarok not
compatible with the latest scripts. 2.0.0 version cannot use
Amarok.PlayList.addMediaList(), the DataDownloader for example.

The problem is KNewStuff doesn't support versioning, and alert can be
shown only after downloading the script. The script writer yet need to
have the sense of referring to a right version.

Any comments?

-- 
Cheers,
Peter ZHOU


More information about the Amarok-devel mailing list